Решение на Регулярни изрази от Йосиф Цветков

Обратно към всички решения

Към профила на Йосиф Цветков

Резултати

  • 7 точки от тестове
  • 0 бонус точки
  • 7 точки общо
  • 29 успешни тест(а)
  • 10 неуспешни тест(а)

Код

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def __filter_local_phones(self, text):
return sub(r'\b(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}\b',
'[PHONE]', text)
def __filter_phones_preserving_country_code(self, text):
return sub(r'((\b00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
r'\1 [FILTERED]', text)
def __filter_partially_preserve_username(self, text):
hosts = findall(r'\b([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', text)
new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
for host in new_hosts:
text = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', host +
r'[FILTERED]@\g<2>\g<3>', text, 1)
return text
def __filter_preserve_hostname(self, text):
return sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', r'[FILTERED]@\g<2>\g<3>', text)
def filtered(self):
crypto = self.text_to_validate
if self.partially_preserve_email_username:
crypto = self.__filter_partially_preserve_username(crypto)
elif self.preserve_email_hostname:
crypto = self.__filter_preserve_hostname(crypto)
else: # default filtering for emails
crypto = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}\b'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
crypto = self.__filter_local_phones(crypto)
if self.preserve_phone_country_code:
crypto = self.__filter_phones_preserving_country_code(crypto)
else: # default filtering for international-format phones
crypto = sub(r'(\b00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
'[PHONE]', crypto)
return crypto
class Validations:
@classmethod
def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex is not None and regex.group() == value
@classmethod
def is_phone(cls, value):
regex = match(r'(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}'
'|(00|\+)[1-9]\d{,2}([ ()-]{,2}\d){6,11}$', value)
return regex is not None and regex.group() == value
@classmethod
def is_hostname(cls, value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex is not None and regex.group() == value
@classmethod
def is_ip_address(cls, value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$', value)
return regex is not None and regex.group() == value
@classmethod
def is_number(cls, value):
regex = match(r'-?(0|0\.\d*|[1-9]\d*\.?\d*)$', value)
return regex is not None and regex.group() == value
@classmethod
def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex is not None and regex.group() == value
@classmethod
def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex is not None and regex.group() == value
@classmethod
def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex is not None and regex.group() == value
@classmethod
def is_datetime(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[\sT]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex is not None and regex.group() == value

Лог от изпълнението

FFF.FFFFF.......F...............F......
======================================================================
FAIL: test_allows_email_hostname_to_be_preserved (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 54, in test_allows_email_hostname_to_be_preserved
    self.assertEqual('[FILTERED]@example.com', self.filter_email_usernames('someone@example.com'))
AssertionError: '[FILTERED]@example.com' != 'someone@example.com'
- [FILTERED]@example.com
+ someone@example.com


======================================================================
FAIL: test_allows_email_usernames_to_be_partially_preserved (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 58, in test_allows_email_usernames_to_be_partially_preserved
    self.assertEqual('som[FILTERED]@example.com', self.partially_filter_email_usernames('someone@example.com'))
AssertionError: 'som[FILTERED]@example.com' != 'someone@example.com'
- som[FILTERED]@example.com
+ someone@example.com


======================================================================
FAIL: test_does_not_brake_with_unicode (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 64, in test_does_not_brake_with_unicode
    self.assertEqual('За връзка: [FILTERED]@example.com', self.partially_filter_email_usernames('За връзка: me@example.com'))
AssertionError: 'За връзка: [FILTERED]@example.com' != 'За връзка: me@example.com'
- За връзка: [FILTERED]@example.com
?            ^^^^^^^^^^
+ За връзка: me@example.com
?            ^^


======================================================================
FAIL: test_does_not_filter_invalid_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 86, in test_does_not_filter_invalid_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: 'Reach me at: 0885123' != 'Reach me at: [PHONE]'
- Reach me at: 0885123
+ Reach me at: [PHONE]


======================================================================
FAIL: test_filters_more_complex_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 76, in test_filters_more_complex_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: '[PHONE]' != '+1 (555) 123-456-99'
- [PHONE]
+ +1 (555) 123-456-99


======================================================================
FAIL: test_filters_whole_email_usernames_if_too_short (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 61, in test_filters_whole_email_usernames_if_too_short
    self.assertEqual('[FILTERED]@example.com', self.partially_filter_email_usernames('me@example.com'))
AssertionError: '[FILTERED]@example.com' != 'me@example.com'
- [FILTERED]@example.com
+ me@example.com


======================================================================
FAIL: test_obfuscates_more_complicated_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 37, in test_obfuscates_more_complicated_emails
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: '[EMAIL]' != 'larodi@x.com'
- [EMAIL]
+ larodi@x.com


======================================================================
FAIL: test_obfuscates_simple_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 24, in test_obfuscates_simple_emails
    self.assertEqual('Contact: [EMAIL]', solution.PrivacyFilter('Contact: someone@example.com').filtered())
AssertionError: 'Contact: [EMAIL]' != 'Contact: someone@example.com'
- Contact: [EMAIL]
+ Contact: someone@example.com


======================================================================
FAIL: test_can_validate_more_complex_phone_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 160, in test_can_validate_more_complex_phone_numbers
    self.assertIs(solution.Validations.is_phone(phone), valid)
AssertionError: True is not False

======================================================================
FAIL: test_validates_hostnames (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-1r1361i/test.py", line 174, in test_validates_hostnames
    self.assertFalse(solution.Validations.is_hostname('not-a-hostname-.com'))
AssertionError: True is not false

----------------------------------------------------------------------
Ran 39 tests in 0.065s

FAILED (failures=10)

История (7 версии и 2 коментара)

Йосиф обнови решението на 17.04.2014 20:32 (преди над 10 години)

+from re import match, sub, search
+
+
+class PrivacyFilter:
+
+ def __init__(self, text_to_validate):
+ self.text_to_validate = text_to_validate
+ self.preserve_phone_country_code = False
+ self.preserve_email_hostname = False
+ self.partially_preserve_email_username = False
+
+
+class Validations:
+
+ def is_email(value):
+ regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?$', value)
+ return regex != None and regex.group() == value
+
+ def is_phone(value):
+ regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{2}'
+ '([ ()-]{,2}\d){6,11}$', value)
+ return regex != None and regex.group() == value
+
+ def is_hostname(value):
+ regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
+ '[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
+ return regex != None and regex.group() == value
+
+ def is_ip_address(value):
+ regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
+ '(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
+ return regex != None and regex.group() == value
+
+ def is_number(value):
+ regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
+ return regex != None and regex.group() == value
+
+ def is_integer(value):
+ regex = match(r'-?(0|[1-9]\d*)', value)
+ return regex != None and regex.group() == value
+
+ def is_date(value):
+ regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
+ return regex != None and regex.group() == value
+
+ def is_time(value):
+ regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
+ return regex != None and regex.group() == value
+
+ def is_datetime(value):
+ regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
+ '([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
+ return regex != None and regex.group() == value

Йосиф обнови решението на 17.04.2014 22:26 (преди над 10 години)

-from re import match, sub, search
+from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
+
+ def filtered(self):
+ crypto = self.text_to_validate
+
+ if self.partially_preserve_email_username == True:
+ hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', crypto)
+ new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
+ for host in new_hosts:
+ crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', host +
+ r'[FILTERED]@\g<2>\g<3>', crypto, 1)
+ elif self.preserve_email_hostname == True:
+ crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', crypto)
+ else:
+ crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
+
+ crypto = sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', crypto)
+ if self.preserve_phone_country_code == True:
+ crypto = sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
+ r'\g<1> [FILTERED]', crypto)
+ else:
+ crypto = sub(r'(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}',
+ '[PHONE]', crypto)
+
+ return crypto
class Validations:
def is_email(value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
def is_phone(value):
regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{2}'
'([ ()-]{,2}\d){6,11}$', value)
return regex != None and regex.group() == value
def is_hostname(value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
def is_ip_address(value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
return regex != None and regex.group() == value
def is_number(value):
regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
return regex != None and regex.group() == value
def is_integer(value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex != None and regex.group() == value
def is_date(value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex != None and regex.group() == value
def is_time(value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value
def is_datetime(value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value

Йосиф обнови решението на 18.04.2014 22:31 (преди над 10 години)

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
+ def __filter_local_phones(self, text):
+ return sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', text)
+
+ def __filter_phones_preserving_country_code(self, text):
+ return sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
+ r'\g<1> [FILTERED]', text)
+
+ def __filter_partial_mail(self, text):
+ hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', text)
+ new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
+ for host in new_hosts:
+ text = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', host +
+ r'[FILTERED]@\g<2>\g<3>', text, 1)
+ return text
+
+ def __filter_preserve_hostname(self, text):
+ return sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', text)
+
def filtered(self):
crypto = self.text_to_validate
if self.partially_preserve_email_username == True:
- hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', crypto)
- new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
- for host in new_hosts:
- crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', host +
- r'[FILTERED]@\g<2>\g<3>', crypto, 1)
+ crypto = self.__filter_partial_mail(crypto)
elif self.preserve_email_hostname == True:
+ crypto = self.__filter_preserve_hostname(crypto)
+ else: # default filtering for emails
crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', crypto)
- else:
- crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
- crypto = sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', crypto)
+ # crypto = self.filter_local_phones(crypto)
if self.preserve_phone_country_code == True:
- crypto = sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
- r'\g<1> [FILTERED]', crypto)
- else:
+ crypto = self.__filter_phones_preserving_country_code(crypto)
+ else: # default filtering for international-format phones
crypto = sub(r'(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}',
'[PHONE]', crypto)
return crypto
class Validations:
- def is_email(value):
+ @classmethod
+ def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
- def is_phone(value):
+ @classmethod
+ def is_phone(cls, value):
regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{2}'
'([ ()-]{,2}\d){6,11}$', value)
return regex != None and regex.group() == value
- def is_hostname(value):
+ @classmethod
+ def is_hostname(cls, value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
- def is_ip_address(value):
+ @classmethod
+ def is_ip_address(cls, value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
return regex != None and regex.group() == value
- def is_number(value):
+ @classmethod
+ def is_number(cls, value):
regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
return regex != None and regex.group() == value
- def is_integer(value):
+ @classmethod
+ def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex != None and regex.group() == value
- def is_date(value):
+ @classmethod
+ def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex != None and regex.group() == value
- def is_time(value):
+ @classmethod
+ def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value
- def is_datetime(value):
+ @classmethod
+ def is_datetime(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value

Йосиф обнови решението на 18.04.2014 22:39 (преди над 10 години)

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def __filter_local_phones(self, text):
return sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', text)
def __filter_phones_preserving_country_code(self, text):
return sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
r'\g<1> [FILTERED]', text)
- def __filter_partial_mail(self, text):
+ def __filter_partially_preserve_username(self, text):
hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', text)
new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
for host in new_hosts:
text = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', host +
r'[FILTERED]@\g<2>\g<3>', text, 1)
return text
def __filter_preserve_hostname(self, text):
return sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', text)
def filtered(self):
crypto = self.text_to_validate
if self.partially_preserve_email_username == True:
- crypto = self.__filter_partial_mail(crypto)
+ crypto = self.__filter_partially_preserve_username(crypto)
elif self.preserve_email_hostname == True:
crypto = self.__filter_preserve_hostname(crypto)
else: # default filtering for emails
crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
# crypto = self.filter_local_phones(crypto)
if self.preserve_phone_country_code == True:
crypto = self.__filter_phones_preserving_country_code(crypto)
else: # default filtering for international-format phones
crypto = sub(r'(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}',
'[PHONE]', crypto)
return crypto
class Validations:
@classmethod
def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
@classmethod
def is_phone(cls, value):
regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{2}'
'([ ()-]{,2}\d){6,11}$', value)
return regex != None and regex.group() == value
@classmethod
def is_hostname(cls, value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
@classmethod
def is_ip_address(cls, value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
return regex != None and regex.group() == value
@classmethod
def is_number(cls, value):
regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
return regex != None and regex.group() == value
@classmethod
def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex != None and regex.group() == value
@classmethod
def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex != None and regex.group() == value
@classmethod
def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value
@classmethod
def is_datetime(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value

Йосиф обнови решението на 20.04.2014 19:46 (преди над 10 години)

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def __filter_local_phones(self, text):
return sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', text)
def __filter_phones_preserving_country_code(self, text):
return sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
r'\g<1> [FILTERED]', text)
def __filter_partially_preserve_username(self, text):
hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', text)
new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
for host in new_hosts:
text = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', host +
r'[FILTERED]@\g<2>\g<3>', text, 1)
return text
def __filter_preserve_hostname(self, text):
return sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', text)
def filtered(self):
crypto = self.text_to_validate
if self.partially_preserve_email_username == True:
crypto = self.__filter_partially_preserve_username(crypto)
elif self.preserve_email_hostname == True:
crypto = self.__filter_preserve_hostname(crypto)
else: # default filtering for emails
crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
# crypto = self.filter_local_phones(crypto)
if self.preserve_phone_country_code == True:
crypto = self.__filter_phones_preserving_country_code(crypto)
else: # default filtering for international-format phones
crypto = sub(r'(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}',
'[PHONE]', crypto)
return crypto
class Validations:
@classmethod
def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
@classmethod
def is_phone(cls, value):
- regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{2}'
+ regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{,2}'
'([ ()-]{,2}\d){6,11}$', value)
return regex != None and regex.group() == value
@classmethod
def is_hostname(cls, value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex != None and regex.group() == value
@classmethod
def is_ip_address(cls, value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
return regex != None and regex.group() == value
@classmethod
def is_number(cls, value):
regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
return regex != None and regex.group() == value
@classmethod
def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex != None and regex.group() == value
@classmethod
def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex != None and regex.group() == value
@classmethod
def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value
@classmethod
def is_datetime(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex != None and regex.group() == value

Йосиф обнови решението на 23.04.2014 02:21 (преди над 10 години)

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def __filter_local_phones(self, text):
- return sub(r'0[^0]([ ()-]{,2}\d){6,11}', '[PHONE]', text)
+ return sub(r'\b(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}\b',
+ '[PHONE]', text)
def __filter_phones_preserving_country_code(self, text):
- return sub(r'((00|\+)[1-9]\d{2})([ ()-]{,2}\d){6,11}',
- r'\g<1> [FILTERED]', text)
+ return sub(r'([\b\s])((00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
+ r'\1\2 [FILTERED]', text)
+ def __filter_phones_preserving_in_the_beginnig(self, text):
+ return sub(r'^((00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
+ r'\1 [FILTERED]', text)
+
def __filter_partially_preserve_username(self, text):
- hosts = findall(r'([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', text)
+ hosts = findall(r'\b([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)\b', text)
new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
for host in new_hosts:
- text = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', host +
+ text = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)\b', host +
r'[FILTERED]@\g<2>\g<3>', text, 1)
return text
def __filter_preserve_hostname(self, text):
- return sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
- '(\.[a-zA-Z]{2})?)', r'[FILTERED]@\g<2>\g<3>', text)
+ return sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
+ '(\.[a-zA-Z]{2})?)\b', r'[FILTERED]@\g<2>\g<3>', text)
def filtered(self):
crypto = self.text_to_validate
- if self.partially_preserve_email_username == True:
+ if self.partially_preserve_email_username:
crypto = self.__filter_partially_preserve_username(crypto)
- elif self.preserve_email_hostname == True:
+ elif self.preserve_email_hostname:
crypto = self.__filter_preserve_hostname(crypto)
else: # default filtering for emails
- crypto = sub(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
+ crypto = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
+ '[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}\b'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
- # crypto = self.filter_local_phones(crypto)
- if self.preserve_phone_country_code == True:
+ crypto = self.__filter_local_phones(crypto)
+ if self.preserve_phone_country_code:
crypto = self.__filter_phones_preserving_country_code(crypto)
+ crypto = self.__filter_phones_preserving_in_the_beginnig(crypto)
else: # default filtering for international-format phones
- crypto = sub(r'(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}',
+ crypto = sub(r'([\b\s])(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
+ r'\1[PHONE]', crypto)
+ crypto = sub(r'^(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
'[PHONE]', crypto)
return crypto
class Validations:
@classmethod
def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
- '[0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
+ '[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value
@classmethod
def is_phone(cls, value):
- regex = match(r'0[^0]([ ()-]{,2}\d){6,11}|(00|\+)[1-9]\d{,2}'
- '([ ()-]{,2}\d){6,11}$', value)
- return regex != None and regex.group() == value
+ regex = match(r'(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}'
+ '|(00|\+)[1-9]\d{,2}([ ()-]{,2}\d){6,11}$', value)
+ return regex is not None and regex.group() == value
@classmethod
def is_hostname(cls, value):
- regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,62}[0-9a-zA]?\.){1,}'
+ regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value
@classmethod
def is_ip_address(cls, value):
- regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])\.){3}'
- '(0|[1-9]|[1-9]\d|1\d\d|2[0-5][0-5])$', value)
- return regex != None and regex.group() == value
+ regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}'
+ '(0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$', value)
+ return regex is not None and regex.group() == value
@classmethod
def is_number(cls, value):
- regex = match(r'-?(0|[1-9]\d*)\.?\d*', value)
- return regex != None and regex.group() == value
+ regex = match(r'-?(0|0\.\d*|[1-9]\d*\.?\d*)$', value)
+ return regex is not None and regex.group() == value
@classmethod
def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value
@classmethod
def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value
@classmethod
def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value
@classmethod
def is_datetime(cls, value):
- regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[- :T]'
+ regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[\sT]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
- return regex != None and regex.group() == value
+ return regex is not None and regex.group() == value

Йосиф обнови решението на 23.04.2014 15:06 (преди над 10 години)

from re import match, sub, findall
class PrivacyFilter:
def __init__(self, text_to_validate):
self.text_to_validate = text_to_validate
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def __filter_local_phones(self, text):
return sub(r'\b(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}\b',
'[PHONE]', text)
def __filter_phones_preserving_country_code(self, text):
- return sub(r'([\b\s])((00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
- r'\1\2 [FILTERED]', text)
-
- def __filter_phones_preserving_in_the_beginnig(self, text):
- return sub(r'^((00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
+ return sub(r'((\b00|\+)[1-9]\d{,2})([ ()-]{,2}\d){6,11}\b',
r'\1 [FILTERED]', text)
def __filter_partially_preserve_username(self, text):
hosts = findall(r'\b([a-zA-Z0-9](\w|\+|\.|-){,200})@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', text)
new_hosts = [i[0][0:3] if len(i[0]) >= 6 else '' for i in hosts]
for host in new_hosts:
text = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', host +
r'[FILTERED]@\g<2>\g<3>', text, 1)
return text
def __filter_preserve_hostname(self, text):
return sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}([a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?)\b', r'[FILTERED]@\g<2>\g<3>', text)
def filtered(self):
crypto = self.text_to_validate
-
if self.partially_preserve_email_username:
crypto = self.__filter_partially_preserve_username(crypto)
elif self.preserve_email_hostname:
crypto = self.__filter_preserve_hostname(crypto)
else: # default filtering for emails
crypto = sub(r'\b[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}\b'
'(\.[a-zA-Z]{2})?', '[EMAIL]', crypto)
crypto = self.__filter_local_phones(crypto)
if self.preserve_phone_country_code:
crypto = self.__filter_phones_preserving_country_code(crypto)
- crypto = self.__filter_phones_preserving_in_the_beginnig(crypto)
else: # default filtering for international-format phones
- crypto = sub(r'([\b\s])(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
- r'\1[PHONE]', crypto)
- crypto = sub(r'^(00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
+ crypto = sub(r'(\b00|\+)[1-9]\d{2}([ ()-]{,2}\d){6,11}\b',
'[PHONE]', crypto)
-
return crypto
class Validations:
@classmethod
def is_email(cls, value):
regex = match(r'[a-zA-Z0-9](\w|\+|\.|-){,200}@([0-9a-zA-Z]'
'[0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}[a-zA-Z]{2,3}'
'(\.[a-zA-Z]{2})?$', value)
return regex is not None and regex.group() == value
@classmethod
def is_phone(cls, value):
regex = match(r'(0[1-9]|0[() -]{1,2}\d)([() -]{,2}\d){5,10}'
'|(00|\+)[1-9]\d{,2}([ ()-]{,2}\d){6,11}$', value)
return regex is not None and regex.group() == value
@classmethod
def is_hostname(cls, value):
regex = match(r'([0-9a-zA-Z][0-9a-zA-Z-]{,61}[0-9a-zA]?\.){1,}'
'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?$', value)
return regex is not None and regex.group() == value
@classmethod
def is_ip_address(cls, value):
regex = match(r'((0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}'
'(0|[1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$', value)
return regex is not None and regex.group() == value
@classmethod
def is_number(cls, value):
regex = match(r'-?(0|0\.\d*|[1-9]\d*\.?\d*)$', value)
return regex is not None and regex.group() == value
@classmethod
def is_integer(cls, value):
regex = match(r'-?(0|[1-9]\d*)', value)
return regex is not None and regex.group() == value
@classmethod
def is_date(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])$', value)
return regex is not None and regex.group() == value
@classmethod
def is_time(cls, value):
regex = match(r'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex is not None and regex.group() == value
@classmethod
def is_datetime(cls, value):
regex = match(r'\d{4}-(0[1-9]|1[012])-([012][1-9]|3[01])[\sT]'
'([01]\d|2[0-3]):[0-5]\d:[0-5]\d$', value)
return regex is not None and regex.group() == value