[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Validators - LinkValidator.py:1.1.4.2

Jim Fulton jim@zope.com
Thu, 23 May 2002 14:01:39 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Validators
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/Formulator/Validators

Modified Files:
      Tag: Zope-3x-branch
	LinkValidator.py 
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)

That lead me to:

- Massive traversal refactoring.

  Namespace handling is now centralized in Zope.App.Traversing. 

- ZPT refactoring, including some renaming that touches pretty much everything. :)

  - The application specific ZPT support was moved into
    Zope.App.PageTemplate. 

  - To get page template files (for use in views):

    from Zope.App.PageTemplate import ViewPageTemplateFile

  - Fixed up security so that ZPT expressions only have access to 
    safe builtins and so that modules namespace does imports safely.

  - Got ZPTPage working!

- renaming url to absolute_url and got absolute_url to work in paths.

- Cleaned up the (as yet unused) RestrictedInterpreter module in
  Zope.Security. In particular, changed to use a separate
  RestrictedBuiltins module.



=== Zope3/lib/python/Zope/App/Formulator/Validators/LinkValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringValidator import StringValidator
-
-
-class LinkHelper:
-    """A helper class to check if links are openable.
-    """
-    status = 0
-
-    def __init__(self, link):
-        self.link = link
-        
-    def open(self):
-        try:
-            urlopen(self.link)
-        except:
-            # all errors will definitely result in a failure
-            pass
-        else:
-            # FIXME: would like to check for 404 errors and such?
-            self.status = 1
-
-
-class LinkValidator(StringValidator):
-    """ """
-
-    propertyNames = StringValidator.propertyNames +\
-                     ['checkLink', 'checkTimeout', 'linkType']
-    
-    checkLink = 0
-    checkTimeout = 7.0
-    linkType = "external"
-    
-    messageNames = StringValidator.messageNames + ['notLink']
-    
-    notLink = 'The specified link is broken.'
-    
-    def validate(self, field, value):
-        value = StringValidator.validate(self, field, value)
-        if value == "" and not field.get_value('required'):
-            return value
-        
-        linkType = field.get_value('linkType')
-        if linkType == 'internal':
-            value = urljoin(REQUEST['BASE0'], value)
-        elif linkType == 'relative':
-            value = urljoin(REQUEST.URL[-1], value)
-        # otherwise must be external
-
-        # FIXME: should try regular expression to do some more checking here?
-        
-        # if we don't need to check the link, we're done now
-        if not field.get_value('checkLink'):
-            return value
-
-        # check whether we can open the link
-        link = LinkHelper(value)
-        thread = Thread(target=link.open)
-        thread.start()
-        thread.join(field.get_value('checkTimeout'))
-        del thread
-        if not link.status:
-            self.raise_error('notLink', field)
-            
-        return value
+"""
+
+$Id$
+"""
+
+from StringValidator import StringValidator
+
+
+class LinkHelper:
+    """A helper class to check if links are openable.
+    """
+    status = 0
+
+    def __init__(self, link):
+        self.link = link
+        
+    def open(self):
+        try:
+            urlopen(self.link)
+        except:
+            # all errors will definitely result in a failure
+            pass
+        else:
+            # FIXME: would like to check for 404 errors and such?
+            self.status = 1
+
+
+class LinkValidator(StringValidator):
+    """ """
+
+    propertyNames = StringValidator.propertyNames +\
+                     ['checkLink', 'checkTimeout', 'linkType']
+    
+    checkLink = 0
+    checkTimeout = 7.0
+    linkType = "external"
+    
+    messageNames = StringValidator.messageNames + ['notLink']
+    
+    notLink = 'The specified link is broken.'
+    
+    def validate(self, field, value):
+        value = StringValidator.validate(self, field, value)
+        if value == "" and not field.get_value('required'):
+            return value
+        
+        linkType = field.get_value('linkType')
+        if linkType == 'internal':
+            value = urljoin(REQUEST['BASE0'], value)
+        elif linkType == 'relative':
+            value = urljoin(REQUEST.URL[-1], value)
+        # otherwise must be external
+
+        # FIXME: should try regular expression to do some more checking here?
+        
+        # if we don't need to check the link, we're done now
+        if not field.get_value('checkLink'):
+            return value
+
+        # check whether we can open the link
+        link = LinkHelper(value)
+        thread = Thread(target=link.open)
+        thread.start()
+        thread.join(field.get_value('checkTimeout'))
+        del thread
+        if not link.status:
+            self.raise_error('notLink', field)
+            
+        return value