|
35 | 35 | 'owner', |
36 | 36 | ]) |
37 | 37 |
|
| 38 | +POSSIBLE_REGEXES = ( |
| 39 | + re.compile(r'^(?P<protocol>https?|git|ssh|rsync)\://' |
| 40 | + r'(?:(?P<user>.+)@)*' |
| 41 | + r'(?P<resource>[a-z0-9_.-]*)' |
| 42 | + r'[:/]*' |
| 43 | + r'(?P<port>[\d]+){0,1}' |
| 44 | + r'(?P<pathname>\/(?P<owner>.+)/(?P<name>.+).git)'), |
| 45 | + re.compile(r'(git\+)?' |
| 46 | + r'((?P<protocol>\w+)://)' |
| 47 | + r'((?P<user>\w+)@)?' |
| 48 | + r'((?P<resource>[\w\.\-]+))' |
| 49 | + r'(:(?P<port>\d+))?' |
| 50 | + r'(?P<pathname>(\/(?P<owner>\w+)/)?' |
| 51 | + r'(\/?(?P<name>[\w\-]+)(\.git)?)?)'), |
| 52 | + re.compile(r'^(?:(?P<user>.+)@)*' |
| 53 | + r'(?P<resource>[a-z0-9_.-]*)[:/]*' |
| 54 | + r'(?P<port>[\d]+){0,1}' |
| 55 | + r'[:](?P<pathname>\/?(?P<owner>.+)/(?P<name>.+).git)'), |
| 56 | + re.compile(r'((?P<user>\w+)@)?' |
| 57 | + r'((?P<resource>[\w\.\-]+))' |
| 58 | + r'[\:\/]{1,2}' |
| 59 | + r'(?P<pathname>((?P<owner>\w+)/)?' |
| 60 | + r'((?P<name>[\w\-]+)(\.git)?)?)'), |
| 61 | +) |
| 62 | + |
38 | 63 |
|
39 | 64 | class ParserError(Exception): |
40 | 65 | """ Error raised when a URL can't be parsed. """ |
@@ -68,34 +93,10 @@ def parse(self): |
68 | 93 | 'name': None, |
69 | 94 | 'owner': None, |
70 | 95 | } |
71 | | - regexes = [ |
72 | | - (r'^(?P<protocol>https?|git|ssh|rsync)\://' |
73 | | - r'(?:(?P<user>.+)@)*' |
74 | | - r'(?P<resource>[a-z0-9_.-]*)' |
75 | | - r'[:/]*' |
76 | | - r'(?P<port>[\d]+){0,1}' |
77 | | - r'(?P<pathname>\/(?P<owner>.+)/(?P<name>.+).git)'), |
78 | | - (r'(git\+)?' |
79 | | - r'((?P<protocol>\w+)://)' |
80 | | - r'((?P<user>\w+)@)?' |
81 | | - r'((?P<resource>[\w\.\-]+))' |
82 | | - r'(:(?P<port>\d+))?' |
83 | | - r'(?P<pathname>(\/(?P<owner>\w+)/)?' |
84 | | - r'(\/?(?P<name>[\w\-]+)(\.git)?)?)'), |
85 | | - (r'^(?:(?P<user>.+)@)*' |
86 | | - r'(?P<resource>[a-z0-9_.-]*)[:/]*' |
87 | | - r'(?P<port>[\d]+){0,1}' |
88 | | - r'[:](?P<pathname>\/?(?P<owner>.+)/(?P<name>.+).git)'), |
89 | | - (r'((?P<user>\w+)@)?' |
90 | | - r'((?P<resource>[\w\.\-]+))' |
91 | | - r'[\:\/]{1,2}' |
92 | | - r'(?P<pathname>((?P<owner>\w+)/)?' |
93 | | - r'((?P<name>[\w\-]+)(\.git)?)?)'), |
94 | | - ] |
95 | | - for regex in regexes: |
96 | | - if re.search(regex, self._url): |
97 | | - m = re.search(regex, self._url) |
98 | | - d.update(m.groupdict()) |
| 96 | + for regex in POSSIBLE_REGEXES: |
| 97 | + match = regex.search(self._url) |
| 98 | + if match: |
| 99 | + d.update(match.groupdict()) |
99 | 100 | break |
100 | 101 | else: |
101 | 102 | msg = "Invalid URL '{}'".format(self._url) |
|
0 commit comments