app/soc/logic/validate.py
changeset 251 8f23804302d0
parent 249 325fb70c61a9
child 298 c76a366c7ab4
equal deleted inserted replaced
250:4d7bf6bdcd8f 251:8f23804302d0
    26 
    26 
    27 from google.appengine.api import urlfetch
    27 from google.appengine.api import urlfetch
    28 
    28 
    29 import feedparser
    29 import feedparser
    30 
    30 
       
    31 from soc.logic import path_linkname
       
    32 
    31 
    33 
    32 def isFeedURLValid(feed_url=None):
    34 def isFeedURLValid(feed_url=None):
    33   """Returns True if provided url is valid ATOM or RSS.
    35   """Returns True if provided url is valid ATOM or RSS.
    34 
    36 
    35   Args:
    37   Args:
    42       if parsed_feed.version and (parsed_feed.version != ''):
    44       if parsed_feed.version and (parsed_feed.version != ''):
    43         return True
    45         return True
    44   return False
    46   return False
    45 
    47 
    46 
    48 
    47 LINKNAME_PATTERN = r'''(?x)
       
    48     ^
       
    49     [0-9a-z]   # start with ASCII digit or lowercase
       
    50     (
       
    51      [0-9a-z]  # additional ASCII digit or lowercase
       
    52      |         # -OR-
       
    53      _[0-9a-z] # underscore and ASCII digit or lowercase
       
    54     )*         # zero or more of OR group
       
    55     $
       
    56 '''
       
    57 
       
    58 LINKNAME_REGEX = re.compile(LINKNAME_PATTERN)
       
    59 
       
    60 def isLinkNameFormatValid(link_name):
    49 def isLinkNameFormatValid(link_name):
    61   """Returns True if link_name is in a valid format.
    50   """Returns True if link_name is in a valid format.
    62 
    51 
    63   Args:
    52   Args:
    64     link_name: link name used in URLs for identification
    53     link_name: link name used in URLs for identification
    65   """
    54   """
    66   if LINKNAME_REGEX.match(link_name):
    55   if path_linkname.LINKNAME_REGEX.match(link_name):
    67     return True
    56     return True
    68   return False
    57   return False