diff -r 19b3f383c9ce -r 1ac2439a68b5 iro/telnumber.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iro/telnumber.py Mon Jan 30 06:52:46 2012 +0100 @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +#Copyright (C) 2009 Sandro Knauß + +#This program is free software; you can redistribute it and/or modify it under the terms +#of the GNU General Public License as published by the Free Software Foundation; +#either version 3 of the License, or any later version. +#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +#See the GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, see . + +import re + +from .error import NotATelNumber + +class Telnumber: + re_telnum=re.compile(r'^\s*(\+)?([0-9\s\-/\(\)]){5,}\s*$') + re_land=re.compile(r'^\s*(\+|00)(?P[1-9]{2})') + re_number=re.compile(r'[^0-9]') + std_land="49" + + def __init__(self,number=None): + if not(number is None): + self.createNumber(number) + + def createNumber(self, number): + + if not self.re_telnum.match(number): + raise NotATelNumber(number) + + + self.land=self.std_land + land=self.re_land.match(number) + + if land: + self.land=land.group("land") + number=number[land.end("land"):] + + number=self.re_number.sub('',number) + + if number[0]=="0": + number=number[1:] + + self.number = number + + def __eq__(self, y): + return ((self.number == y.number) and ( self.land == y.land)) + + def __ne__(self, y): + return not self.__eq__(y)