Changeset 495
- Timestamp:
- 12/30/07 04:19:04 (1 year ago)
- Files:
-
- cly/trunk/cly/builder.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/cly/builder.py
r492 r495 907 907 >>> parser = Parser(Grammar(foo=IP())) 908 908 >>> parser.parse('123.34.67.89').vars['foo'] 909 (123, 34, 67, 89)909 '123.34.67.89' 910 910 >>> parser.parse('123.34.67.256').remaining 911 911 '123.34.67.256' … … 913 913 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]?)' 914 914 915 def parse(self, context, match):916 return tuple(map(int, match.groups()))917 918 915 919 916 class Hostname(Variable): … … 926 923 >>> parser = Parser(Grammar(foo=Hostname())) 927 924 >>> parser.parse('www.example.com').vars['foo'] 928 ('www', 'example', 'com')925 'www.example.com' 929 926 """ 930 927 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('.'))934 928 935 929 … … 942 936 >>> parser = Parser(Grammar(foo=Host())) 943 937 >>> parser.parse('www.example.com').vars['foo'] 944 ('www', 'example', 'com')938 'www.example.com' 945 939 >>> parser.parse('123.34.67.89').vars['foo'] 946 (123, 34, 67, 89)940 '123.34.67.89' 947 941 """ 948 942 949 943 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)956 944 957 945
