1 # -*- coding: utf-8 -*- |
|
2 #Copyright (C) 2009 Sandro Knauß <bugs@sandroknauss.de> |
|
3 |
|
4 #This program is free software; you can redistribute it and/or modify it under the terms |
|
5 #of the GNU General Public License as published by the Free Software Foundation; |
|
6 #either version 3 of the License, or any later version. |
|
7 #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|
8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
9 #See the GNU General Public License for more details. |
|
10 |
|
11 #You should have received a copy of the GNU General Public License |
|
12 #along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
13 |
|
14 class anbieter: |
|
15 default_conf = '' # override this |
|
16 import re |
|
17 |
|
18 class NotATelNumber(Exception): |
|
19 def __init__(self, number): |
|
20 self.number= number |
|
21 |
|
22 def __str__(self): |
|
23 return ("This is not a telefonnumber:", selfnumber) |
|
24 |
|
25 class telnumber: |
|
26 re_telnum=re.compile(r'^\s*(\+)?([0-9\s\-/\(\)])+\s*$') |
|
27 re_land=re.compile(r'^\s*(\+|00)(?P<land>[1-9]{2})') |
|
28 re_number=re.compile(r'[^0-9]') |
|
29 std_land="49" |
|
30 |
|
31 def __init__(self,number=None): |
|
32 if not(number is None): |
|
33 self.createNumber(number) |
|
34 |
|
35 def createNumber(self, number): |
|
36 |
|
37 if not self.re_telnum.match(number): |
|
38 raise NotATelNumber(number) |
|
39 |
|
40 |
|
41 self.land=self.std_land |
|
42 land=self.re_land.match(number) |
|
43 |
|
44 if not(land is None): |
|
45 self.land=land.group("land") |
|
46 number=number[land.end("land"):] |
|
47 |
|
48 number=self.re_number.sub('',number) |
|
49 |
|
50 if number[0]=="0": |
|
51 number=number[1:] |
|
52 |
|
53 self.number = number |
|
54 |
|
55 def __eq__(self, y): |
|
56 return ((self.number == y.number) and ( self.land == y.land)) |
|
57 |
|
58 def __ne__(self, y): |
|
59 return not self.__eq__(y) |
|