Skip to content

Commit 8ef3824

Browse files
Marc-marc-marcfrodrigo
authored andcommitted
Update Phone.py to add belgium
1 parent 0597fd4 commit 8ef3824

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

plugins/Phone.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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}|{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,38 @@ 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+
("+32021231212", "+32 21231212"),
339+
("0032 21231212", "+32 21231212"),
340+
("12 / 13", "12; 13"),
341+
# Preserve formatting
342+
("+32 021231212", "+32 21231212"),
343+
("+32 02 123 12 12", "+32 2 123 12 12"),
344+
("+32 1307", "1307"),
345+
("021231212", "+32 21231212"),
346+
("-021231212", "+32 21231212"),
347+
("02 123 12 12", "+32 2 123 12 12"),
348+
):
349+
# Check the bad number's error and fix
350+
err = p.node(None, {"phone": bad})
351+
self.check_err(err, ("phone='{0}'".format(bad)))
352+
self.assertEqual(err[0]["fix"]["phone"], good)
353+
354+
# The correct number does not need fixing
355+
assert not p.node(None, {"phone": good}), ("phone='{0}'".format(good))
356+
357+
# Verify we got no error for other correct numbers
358+
for good in ("1307", "112", "1;2"):
359+
assert not p.node(None, {"phone": good}), ("phone='{0}'".format(good))
360+
361+
assert len(p.node(None, {"phone": "02.123.12.12", "fax": "02.123.12.12"})) == 2

0 commit comments

Comments
 (0)