I have what should be a simple newbie question. I need to validate an email address (just syntax for now). I found the following URL doing a Google search on "zope email": http://zope.nipltd.com/public/lists/zope-archive.nsf/0dec1f578f18f116802568a b003585d2/a1398ea9c177a77d80256b0e00647852?OpenDocument It includes sample Perl and Python code to validate email address syntax so I created the following file in the Extensions directory to be called from an external method and named it email_checker.py:
def valid_email(address, debug=None): import re rega = re.compile("^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$") #failure a regb = re.compile("^[^0-9a-zA-Z]|[^0-9a-zA-Z]$") #failure b regc = re.compile("([0-9a-zA-Z]{1})\@.") #failure c regd = re.compile(".\@([0-9a-zA-Z]{1})") #failure d rege = re.compile(".\.\-.|.\-\..|.\.\..|.\-\-.") #failure e regf = re.compile(".\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_.") #failure f regg = re.compile(".\.([a-zA-Z]{2,3})$|.\.([a-zA-Z]{2,4})$")#failure g fail = None if rega.search(address) is None: fail = 'a' elif regb.search(address) is not None: fail = 'b' elif regc.search(address) is None: fail = 'c' elif regd.search(address) is None: fail = 'd' elif rege.search(address) is not None: fail = 'e' elif regf.search(address) is not None: fail = 'f' elif regg.search(address) is None: fail = 'g' if fail is not None: if debug: return address,fail,None else: return None if debug: return address,1,1 else: return 1 <<< Then I tried to create an external method from the ZMI with the following definition:
Id: email_checker Title: Email Address Validator Module Name: email_checker Function Name: valid_email <<< When I tried to save it I get the following error:
Zope Error Zope has encountered an error while publishing this resource. Error Type: SyntaxError Error Value: invalid syntax (email_checker.py, line 1) ---------------------------------------------------------------------------- ---- Troubleshooting Suggestions The URL may be incorrect. The parameters passed to this resource may be incorrect. A resource that this resource relies on may be encountering an error. <<< I went through the Zope Book examples, but there is no assistance when errors occur. Just refers you to the Python web site for more details. First, is there a better way to validate email addresses (I am not using CMF)? If not, what am I doing wrong with the external method? Thanks in advance. ___________________ Tim Owen