Changeset 495

Show
Ignore:
Timestamp:
12/30/07 04:19:04 (1 year ago)
Author:
athomas
Message:

cly: IP, Hostname and Host nodes now return strings as this is the most common
use-case.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/cly/builder.py

    r492 r495  
    907907    >>> parser = Parser(Grammar(foo=IP())) 
    908908    >>> parser.parse('123.34.67.89').vars['foo'] 
    909     (123, 34, 67, 89) 
     909    '123.34.67.89' 
    910910    >>> parser.parse('123.34.67.256').remaining 
    911911    '123.34.67.256' 
     
    913913    pattern = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' 
    914914 
    915     def parse(self, context, match): 
    916         return tuple(map(int, match.groups())) 
    917  
    918915 
    919916class Hostname(Variable): 
     
    926923    >>> parser = Parser(Grammar(foo=Hostname())) 
    927924    >>> parser.parse('www.example.com').vars['foo'] 
    928     ('www', 'example', 'com') 
     925    'www.example.com' 
    929926    """ 
    930927    pattern = r'(?i)([A-Z0-9][A-Z0-9_-]*)(?:\.([A-Z0-9][A-Z0-9_-]*))*' 
    931  
    932     def parse(self, context, match): 
    933         return tuple(match.group().split('.')) 
    934928 
    935929 
     
    942936    >>> parser = Parser(Grammar(foo=Host())) 
    943937    >>> parser.parse('www.example.com').vars['foo'] 
    944     ('www', 'example', 'com') 
     938    'www.example.com' 
    945939    >>> parser.parse('123.34.67.89').vars['foo'] 
    946     (123, 34, 67, 89) 
     940    '123.34.67.89' 
    947941    """ 
    948942 
    949943    pattern = r'(?i)(%s)|(%s)' % (IP.pattern, Hostname.pattern) 
    950  
    951     def parse(self, context, match): 
    952         components = match.string[match.start():match.end()].split('.') 
    953         if match.lastindex == 1: 
    954             return tuple(map(int, components)) 
    955         return tuple(components) 
    956944 
    957945