@@ -89,6 +89,12 @@ def init(self, logger):
8989 # short numbers this also skips special numbers starting with 08
9090 # or 09 since these may or may not be callable from abroad.
9191 self .MissingInternationalPrefix = re .compile (r"^{0}[- ./]*([1-7](:?[- ./]*[0-9]){{{1},{2}}})$" .format (self .local_prefix , min (self .size ) - 1 , max (self .size ) - 1 ))
92+ elif country and country .startswith ("BE" ):
93+ # Local numbers to internationalize. Note that in addition to
94+ # short numbers this also skips special numbers starting with 070,
95+ # 077, 078, 0800, or 090x since these may or may not be callable from abroad.
96+ # not merged into 07x 08x 09x because severals local numbers inside those prefix
97+ self .MissingInternationalPrefix = re .compile (r"^{0}[- ./]*(?!70|77|78|800|90[0-9])([1-9](:?[- ./]*[0-9]){{{1},{2}}})$" .format (self .local_prefix , min (self .size ) - 1 , max (self .size ) - 1 ))
9298 elif self .size :
9399 self .MissingInternationalPrefix = re .compile (r"^{0}[- ./]*((:?[0-9][- ./]*){{{1},{2}}}[0-9])$" .format (self .local_prefix , min (self .size ) - len (self .local_prefix ) - 1 , max (self .size ) - len (self .local_prefix ) - 1 ))
94100 else :
@@ -318,3 +324,37 @@ class father:
318324 # Verify we got no error for other correct numbers
319325 for good in (u"800 123" , u"112" , u"1515" ):
320326 assert not p .node (None , {"phone" : good }), ("phone='{0}'" .format (good ))
327+
328+ def test_BE (self ):
329+ p = Phone (None )
330+ class _config :
331+ options = {"country" : "BE" , "phone_code" : "32" , "phone_len" : 8 , "phone_len_short" : [3 , 4 ], "phone_format" : r"^([+]%s([- ./]*[0-9]){7}[0-9])|[0-9]{3,4}$" , "phone_international" : "00" , "phone_local_prefix" : "0" }
332+ class father :
333+ config = _config ()
334+ p .father = father ()
335+ p .init (None )
336+
337+ for (bad , good ) in (
338+ (u"+32021231212" , u"+32 21231212" ),
339+ (u"0032 21231212" , u"+32 21231212" ),
340+ (u"12 / 13" , u"12; 13" ),
341+ # Preserve formatting
342+ (u"+32 021231212" , u"+32 21231212" ),
343+ (u"+32 02 123 12 12" , u"+32 2 123 12 12" ),
344+ (u"+32 1307" , u"1307" ),
345+ (u"021231212" , u"+32 21231212" ),
346+ (u"02 123 12 12" , u"+32 2 123 12 12" ),
347+ ):
348+ # Check the bad number's error and fix
349+ err = p .node (None , {"phone" : bad })
350+ self .check_err (err , ("phone='{0}'" .format (bad )))
351+ self .assertEqual (err [0 ]["fix" ]["phone" ], good )
352+
353+ # The correct number does not need fixing
354+ assert not p .node (None , {"phone" : good }), ("phone='{0}'" .format (good ))
355+
356+ # Verify we got no error for other correct numbers
357+ for good in (u"1307" , u"112" , u"1;2" ):
358+ assert not p .node (None , {"phone" : good }), ("phone='{0}'" .format (good ))
359+
360+ assert len (p .node (None , {"phone" : "02.123.12.12" , "fax" : "02.123.12.12" })) == 2
0 commit comments