| 
            Last change
 on this file since 10:d5329a2a05b7 was             1:421645ee4cd9, checked in by Francisco de Borja Lopez Rio <borja@…>, 13 years ago           | 
        
        
          | 
             
Moved the source code from src/ to postman/ 
 
Added tests (unittests) splitted into one testing module per app source 
file (tests/models.py for testing models.py, tests/storage.py for testing 
storage.py and so on). Currently only tests for models have been added. 
 
Added a script to run the tests 
 
           | 
        
        
          | 
            File size:
            758 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | # -*- coding: utf-8 -*-
 | 
|---|
| 2 | 
 | 
|---|
| 3 | import re
 | 
|---|
| 4 | 
 | 
|---|
| 5 | def validate_email_address(address):
 | 
|---|
| 6 | 
 | 
|---|
| 7 |     """
 | 
|---|
| 8 |     This function validates a given address, returning True
 | 
|---|
| 9 |     if it is a valid address, False otherwise.
 | 
|---|
| 10 | 
 | 
|---|
| 11 |     The function uses a regexp from the django project, and
 | 
|---|
| 12 |     it is inspired in this snippet:
 | 
|---|
| 13 | 
 | 
|---|
| 14 |     http://djangosnippets.org/snippets/1093/
 | 
|---|
| 15 |     """
 | 
|---|
| 16 | 
 | 
|---|
| 17 |     if not isinstance(address, str):
 | 
|---|
| 18 |         return False
 | 
|---|
| 19 | 
 | 
|---|
| 20 |     email_re = re.compile(
 | 
|---|
| 21 |     r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
 | 
|---|
| 22 |     r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
 | 
|---|
| 23 |     r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE)  # domain
 | 
|---|
| 24 |     return True if email_re.match(address) else False
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.