1.1 --- a/translator.py Mon Dec 05 00:20:28 2016 +0100
1.2 +++ b/translator.py Mon Dec 05 01:04:01 2016 +0100
1.3 @@ -23,6 +23,7 @@
1.4 from encoders import *
1.5 from os.path import exists, join
1.6 from os import makedirs
1.7 +from referencing import Reference
1.8 import compiler
1.9 import results
1.10
1.11 @@ -451,6 +452,11 @@
1.12 expr = self.process_structure_node(n.expr)
1.13 self.statement(expr)
1.14
1.15 + # Module import declarations.
1.16 +
1.17 + elif isinstance(n, compiler.ast.From):
1.18 + self.process_from_node(n)
1.19 +
1.20 # Nodes using operator module functions.
1.21
1.22 elif isinstance(n, compiler.ast.Operator):
1.23 @@ -785,6 +791,33 @@
1.24 encode_path(parent), encode_symbol("pos", attrname)
1.25 ))
1.26
1.27 + def process_from_node(self, n):
1.28 +
1.29 + "Process the given node 'n', importing from another module."
1.30 +
1.31 + path = self.get_namespace_path()
1.32 +
1.33 + # Attempt to obtain the referenced objects.
1.34 +
1.35 + for name, alias in n.names:
1.36 + if name == "*":
1.37 + raise InspectError("Only explicitly specified names can be imported from modules.", path, n)
1.38 +
1.39 + # Obtain the path of the assigned name.
1.40 +
1.41 + objpath = self.get_object_path(alias or name)
1.42 +
1.43 + # Obtain the identity of the name.
1.44 +
1.45 + ref = self.importer.identify(objpath)
1.46 +
1.47 + # Where the name is not static, assign the value.
1.48 +
1.49 + if ref and not ref.static() and ref.get_name():
1.50 + self.writestmt("%s;" %
1.51 + TrResolvedNameRef(alias or name, Reference("<var>", None, objpath),
1.52 + expr=TrResolvedNameRef(name, ref)))
1.53 +
1.54 def process_function_body_node(self, n):
1.55
1.56 """