Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented from ... import *, issue #615

  • Loading branch information...
commit b3424c5616899394260027997526fe79b2daaf63 1 parent f2e7568
Daniel Kluev authored
Showing with 30 additions and 6 deletions.
  1. +10 −0 pyjs/src/pyjs/builtin/pyjslib.py
  2. +20 −6 pyjs/src/pyjs/translator.py
10 pyjs/src/pyjs/builtin/pyjslib.py
View
@@ -952,6 +952,16 @@ def __dynamic_load__(importName):
__nondynamic_modules__[importName] = 1.0
return module
+def __import_all__(path, context, namespace, module_name=None, get_base=True):
+ module = ___import___(path, context, module_name, get_base)
+ if JS("""typeof @{{module}}['__all__'] == 'undefined'"""):
+ for name in dir(module):
+ if not name.startswith('_'):
+ JS("""@{{namespace}}[@{{name}}] = @{{module}}[@{{name}}];""")
+ else:
+ for name in module.__all__:
+ JS("""@{{namespace}}[@{{name}}] = @{{module}}[@{{name}}];""")
+
class BaseException:
def __init__(self, *args):
26 pyjs/src/pyjs/translator.py
View
@@ -332,6 +332,7 @@
"slice",
"__delslice",
"___import___",
+ "__import_all__",
"_handle_exception",
))
@@ -1970,7 +1971,8 @@ def _import(self, node, current_klass, root_level = False):
# object to check our scope
self._doImport(node.names, current_klass, root_level, True)
- def _doImport(self, names, current_klass, root_level, assignBase, absPath=False):
+ def _doImport(self, names, current_klass, root_level, assignBase,
+ absPath=False, all=False):
if root_level:
modtype = 'root-module'
else:
@@ -2013,12 +2015,20 @@ def _doImport(self, names, current_klass, root_level, assignBase, absPath=False)
context = 'null'
else:
context = self.import_context
- import_stmt = "@{{___import___}}('%s', %s" % (
- importName,
- context,
- )
+ if not all:
+ import_stmt = "@{{___import___}}('%s', %s" % (
+ importName,
+ context,
+ )
+ else:
+ import_stmt = "@{{__import_all__}}('%s', %s, %s" %(
+ importName,
+ context,
+ self.modpfx()[:-1],
+ )
+
if not assignBase:
- self.w( self.spacing() + import_stmt + 'null, false);')
+ self.w( self.spacing() + import_stmt + ', null, false);')
self._lhsFromName(importName, current_klass, modtype)
self.add_imported_module(importName)
if assignBase:
@@ -2104,6 +2114,10 @@ def _from(self, node, current_klass, root_level = False):
if modname[0] == '.':
modname = modname[1:]
for name in node.names:
+ if name[0] == "*":
+ self._doImport(((modname, name[0]),), current_klass,
+ root_level, False, absPath, True)
+ continue
sub = modname + '.' + name[0]
ass_name = name[1] or name[0]
self._doImport(((sub, ass_name),), current_klass, root_level, True, absPath)
Please sign in to comment.
Something went wrong with that request. Please try again.