1.1 --- a/micropython/inspect.py Tue Oct 08 22:44:44 2013 +0200
1.2 +++ b/micropython/inspect.py Tue Oct 08 22:59:10 2013 +0200
1.3 @@ -72,7 +72,7 @@
1.4 benefits in considering a local to be constant within a single invocation.
1.5 """
1.6
1.7 -from micropython.common import ASTVisitor, operator_functions
1.8 +from micropython.common import ASTVisitor, operator_functions, get_module_name
1.9 from micropython.data import *
1.10 from micropython.errors import *
1.11 import compiler.ast
1.12 @@ -224,7 +224,7 @@
1.13 # Module import declarations.
1.14
1.15 elif isinstance(n, compiler.ast.From):
1.16 - modname, names = self.get_module_name(n)
1.17 + modname, names = get_module_name(n, self)
1.18
1.19 # Perform whole module relative imports.
1.20
1.21 @@ -262,45 +262,6 @@
1.22 else:
1.23 self.process_structure(n)
1.24
1.25 - def get_module_name(self, node):
1.26 -
1.27 - """
1.28 - Using the given From 'node', calculate any relative import information,
1.29 - returning a tuple containing a module to import along with any names to
1.30 - import based on the node's name information.
1.31 -
1.32 - Where the returned module is given as None, whole module imports should
1.33 - be performed for the returned modules using the returned names.
1.34 - """
1.35 -
1.36 - # Absolute import.
1.37 -
1.38 - if node.level == 0:
1.39 - return node.modname, node.names
1.40 -
1.41 - # Relative to this module.
1.42 -
1.43 - elif node.level == 1:
1.44 - basename = self.full_name()
1.45 -
1.46 - # Relative to an ancestor of this module.
1.47 -
1.48 - else:
1.49 - path = self.full_name().split(".")
1.50 - if node.level > len(path):
1.51 - raise InspectError("Relative import %r involves too many levels up from module %r" % (("." * node.level + node.modname), self.full_name()))
1.52 - basename = ".".join(path[:-node.level+1])
1.53 -
1.54 - # Name imports from a module.
1.55 -
1.56 - if node.modname:
1.57 - return "%s.%s" % (basename, node.modname), node.names
1.58 -
1.59 - # Relative whole module imports.
1.60 -
1.61 - else:
1.62 - return None, [("%s.%s" % (basename, name), alias) for name, alias in node.names]
1.63 -
1.64 def get_module_paths(self, name):
1.65
1.66 """
1.67 @@ -1174,7 +1135,7 @@
1.68 self.resume_broken_branches()
1.69
1.70 def visitFrom(self, node):
1.71 - modname, names = self.get_module_name(node)
1.72 + modname, names = get_module_name(node, self)
1.73
1.74 if not modname:
1.75 return self._visitImport(names)