Show More
@@ -126,9 +126,15 b' def fromlocalfunc(modulename, localmods)' | |||||
126 | False |
|
126 | False | |
127 | >>> fromlocal(None, 1) |
|
127 | >>> fromlocal(None, 1) | |
128 | ('foo', 'foo.__init__', True) |
|
128 | ('foo', 'foo.__init__', True) | |
|
129 | >>> fromlocal('foo1', 1) | |||
|
130 | ('foo.foo1', 'foo.foo1', False) | |||
129 | >>> fromlocal2 = fromlocalfunc('foo.xxx.yyy', localmods) |
|
131 | >>> fromlocal2 = fromlocalfunc('foo.xxx.yyy', localmods) | |
130 | >>> fromlocal2(None, 2) |
|
132 | >>> fromlocal2(None, 2) | |
131 | ('foo', 'foo.__init__', True) |
|
133 | ('foo', 'foo.__init__', True) | |
|
134 | >>> fromlocal2('bar2', 1) | |||
|
135 | False | |||
|
136 | >>> fromlocal2('bar', 2) | |||
|
137 | ('foo.bar', 'foo.bar.__init__', True) | |||
132 | """ |
|
138 | """ | |
133 | prefix = '.'.join(modulename.split('.')[:-1]) |
|
139 | prefix = '.'.join(modulename.split('.')[:-1]) | |
134 | if prefix: |
|
140 | if prefix: | |
@@ -140,8 +146,12 b' def fromlocalfunc(modulename, localmods)' | |||||
140 | assert level > 0 |
|
146 | assert level > 0 | |
141 | candidates = ['.'.join(modulename.split('.')[:-level])] |
|
147 | candidates = ['.'.join(modulename.split('.')[:-level])] | |
142 | else: |
|
148 | else: | |
143 | # Check relative name first. |
|
149 | if not level: | |
144 | candidates = [prefix + name, name] |
|
150 | # Check relative name first. | |
|
151 | candidates = [prefix + name, name] | |||
|
152 | else: | |||
|
153 | candidates = ['.'.join(modulename.split('.')[:-level]) + | |||
|
154 | '.' + name] | |||
145 |
|
155 | |||
146 | for n in candidates: |
|
156 | for n in candidates: | |
147 | if n in localmods: |
|
157 | if n in localmods: |
General Comments 0
You need to be logged in to leave comments.
Login now