Closed jedie closed 9 years ago
That's a legitimate javascript error, doing undefined[0]
in JS will give the same thing. The _allModules
is a dict, not a list:
modules = js.globals.vm._allModules
print modules['BaseHTTPServer']
Hm. But not a real python dict, isn't it?
modules = js.globals.vm._allModules
print repr(modules) # -> <js.Object handle=9>
Using modules.keys() or modules.items() doesn't work.
dir(modules) returns the list: [<js.String 'BaseHTTPServer'>, <js.String 'Bastion'>, ...
solution for the initial problem:
modules = js.globals.vm._allModules
module_names = [str(m) for m in modules]
print module_names
will print:
['BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'ConfigParser', 'Cookie',...]
btw:
len(js.globals.vm._allModules) -> TypeError: 'Object' has no length
But not a real python dict, isn't it?
Correct; I should have said "javascript hash object", technically an instance of js.Object
which is dict-like but doesn't implement all the methods of standard python dictionaries.
len(js.globals.vm._allModules) -> TypeError: 'Object' has no length
Unfortunately this is the expected behavior, there's no easy way to tell the number of keys in a javascript hash object.
Thanks for the information... Now i have commit with https://github.com/jedie/pypyjs/commit/53cbf2a651817cdadcb8143175fca1d6c2a31e5a a fast, complete import test... ;)
Output is:
Traceback (most recent call last):
File "/home/jens/pypyjs_env/src/pypyjs/tests/test_editor.py", line 565, in test_imports2
self.fail(msg=msg)
AssertionError: ERROR: '1183 modules (unfiltered)\n203 modules (filtered)\n 0 - import BaseHTTPServer ERROR: No module named BaseHTTPServer\n 1 - import Bastion ERROR: No module named Bastion\n 2 - import CGIHTTPServer ERROR: No module named CGIHTTPServer\n 3 - import ConfigParser ERROR: No module named ConfigParser\n 4 - import Cookie ERROR: No module named Cookie\n 5 - import DocXMLRPCServer ERROR: No module named DocXMLRPCServer\n 6 - import HTMLParser ERROR: No module named HTMLParser\n 7 - import MimeWriter ERROR: No module named MimeWriter\n 8 - import Queue ERROR: No module named Queue\n 9 - import SimpleHTTPServer ERROR: No module named SimpleHTTPServer\n 10 - import SimpleXMLRPCServer ERROR: No module named SimpleXMLRPCServer\n 11 - import SocketServer ERROR: No module named SocketServer\n 12 - import StringIO ERROR: No module named StringIO\n 13 - import UserDict OK\n 14 - import UserList ERROR: No module named UserList\n 15 - import UserString ERROR: No module named UserString\n 16 - import abc OK\n 17 - import aifc ERROR: No module named aifc\n 18 - import antigravity ERROR: No module named antigravity\n 19 - import anydbm ERROR: No module named anydbm\n 20 - import argparse ERROR: No module named argparse\n 21 - import ast ERROR: No module named ast\n 22 - import asynchat ERROR: No module named asynchat\n 23 - import asyncore ERROR: No module named asyncore\n 24 - import atexit ERROR: No module named atexit\n 25 - import base64 OK\n 26 - import bdb ERROR: No module named bdb\n 27 - import binhex ERROR: No module named binhex\n 28 - import bisect ERROR: No module named bisect\n 29 - import cPickle ERROR: No module named cPickle\n 30 - import cProfile ERROR: No module named cProfile\n 31 - import cStringIO OK\n 32 - import calendar ERROR: No module named calendar\n 33 - import cgi ERROR: No module named cgi\n 34 - import cgitb ERROR: No module named cgitb\n 35 - import chunk ERROR: No module named chunk\n 36 - import cmd ERROR: No module named cmd\n 37 - import code OK\n 38 - import codecs OK\n 39 - import codeop OK\n 40 - import collections ERROR: No module named collections\n 41 - import colorsys ERROR: No module named colorsys\n 42 - import commands ERROR: No module named commands\n 43 - import compileall ERROR: No module named compileall\n 44 - import compiler ERROR: No module named compiler\n 45 - import contextlib ERROR: No module named contextlib\n 46 - import cookielib ERROR: No module named cookielib\n 47 - import copy OK\n 48 - import csv ERROR: No module named csv\n 49 - import datetime ERROR: No module named datetime\n 50 - import dbhash ERROR: No module named dbhash\n 51 - import dbm ERROR: No module named dbm\n 52 - import decimal ERROR: No module named decimal\n 53 - import difflib ERROR: No module named difflib\n 54 - import dircache ERROR: No module named dircache\n 55 - import dis ERROR: No module named dis\n 56 - import distutils ERROR: No module named distutils\n 57 - import doctest ERROR: No module named doctest\n 58 - import dumbdbm ERROR: No module named dumbdbm\n 59 - import email ERROR: No module named email\n 60 - import encodings OK\n 61 - import filecmp ERROR: No module named filecmp\n 62 - import fileinput ERROR: No module named fileinput\n 63 - import fnmatch ERROR: No module named fnmatch\n 64 - import formatter ERROR: No module named formatter\n 65 - import fpformat ERROR: No module named fpformat\n 66 - import fractions ERROR: No module named fractions\n 67 - import ftplib ERROR: No module named ftplib\n 68 - import functools ERROR: No module named functools\n 69 - import gdbm ERROR: No module named gdbm\n 70 - import genericpath OK\n 71 - import getopt OK\n 72 - import getpass ERROR: No module named getpass\n 73 - import gettext ERROR: No module named gettext\n 74 - import glob ERROR: No module named glob\n 75 - import greenlet ERROR: No module named greenlet\n 76 - import grp ERROR: No module named grp\n 77 - import gzip ERROR: No module named gzip\n 78 - import hashlib ERROR: No module named hashlib\n 79 - import heapq ERROR: No module named heapq\n 80 - import hmac ERROR: No module named hmac\n 81 - import htmlentitydefs ERROR: No module named htmlentitydefs\n 82 - import htmllib ERROR: No module named htmllib\n 83 - import httplib ERROR: No module named httplib\n 84 - import ihooks ERROR: No module named ihooks\n 85 - import imaplib ERROR: No module named imaplib\n 86 - import imghdr ERROR: No module named imghdr\n 87 - import importlib ERROR: No module named importlib\n 88 - import imputil ERROR: No module named imputil\n 89 - import inspect ERROR: No module named inspect\n 90 - import io ERROR: No module named io\n 91 - import json ERROR: No module named json\n 92 - import keyword ERROR: No module named keyword\n 93 - import lib2to3 ERROR: No module named lib2to3\n 94 - import linecache OK\n 95 - import locale ERROR: No module named locale\n 96 - import logging ERROR: No module named logging\n 97 - import macurl2path ERROR: No module named macurl2path\n 98 - import mailbox ERROR: No module named mailbox\n 99 - import mailcap ERROR: No module named mailcap\n100 - import markupbase ERROR: No module named markupbase\n101 - import marshal OK\n102 - import md5 ERROR: No module named md5\n103 - import mhlib ERROR: No module named mhlib\n104 - import mimetools ERROR: No module named mimetools\n105 - import mimetypes ERROR: No module named mimetypes\n106 - import mimify ERROR: No module named mimify\n107 - import modulefinder ERROR: No module named modulefinder\n108 - import multifile ERROR: No module named multifile\n109 - import mutex ERROR: No module named mutex\n110 - import netrc ERROR: No module named netrc\n111 - import new ERROR: No module named new\n112 - import nntplib ERROR: No module named nntplib\n113 - import nturl2path ERROR: No module named nturl2path\n114 - import numbers ERROR: No module named numbers\n115 - import opcode ERROR: No module named opcode\n116 - import optparse ERROR: No module named optparse\n117 - import os OK\n118 - import pdb ERROR: No module named pdb\n119 - import pickle ERROR: No module named pickle\n120 - import pickletools ERROR: No module named pickletools\n121 - import pipes ERROR: No module named pipes\n122 - import pkgutil ERROR: No module named pkgutil\n123 - import platform ERROR: No module named platform\n124 - import plistlib ERROR: No module named plistlib\n125 - import popen2 ERROR: No module named popen2\n126 - import poplib ERROR: No module named poplib\n127 - import posixfile ERROR: No module named posixfile\n128 - import posixpath OK\n129 - import pprint ERROR: No module named pprint\n130 - import profile ERROR: No module named profile\n131 - import pstats ERROR: No module named pstats\n132 - import pty ERROR: No module named pty\n133 - import pwd ERROR: No module named ctypes_support\n134 - import pyclbr ERROR: No module named pyclbr\n135 - import pydoc ERROR: No module named pydoc\n136 - import pyrepl ERROR: No module named pyrepl\n137 - import quopri ERROR: No module named quopri\n138 - import random ERROR: No module named random\n139 - import re OK\n140 - import repr OK\n141 - import resource ERROR: No module named resource\n142 - import rexec ERROR: No module named rexec\n143 - import rfc822 ERROR: No module named rfc822\n144 - import rlcompleter ERROR: No module named rlcompleter\n145 - import robotparser ERROR: No module named robotparser\n146 - import runpy ERROR: No module named runpy\n147 - import sched ERROR: No module named sched\n148 - import sets ERROR: No module named sets\n149 - import sgmllib ERROR: No module named sgmllib\n150 - import sha ERROR: No module named sha\n151 - import shelve ERROR: No module named shelve\n152 - import shlex ERROR: No module named shlex\n153 - import shutil ERROR: No module named shutil\n154 - import site ERROR: No module named site\n155 - import smtpd ERROR: No module named smtpd\n156 - import smtplib ERROR: No module named smtplib\n157 - import sndhdr ERROR: No module named sndhdr\n158 - import socket ERROR: No module named socket\n159 - import sre ERROR: No module named sre\n160 - import stackless ERROR: No module named stackless\n161 - import stat OK\n162 - import statvfs ERROR: No module named statvfs\n163 - import string ERROR: No module named string\n164 - import stringold ERROR: No module named stringold\n165 - import stringprep ERROR: No module named stringprep\n166 - import struct OK\n167 - import symbol OK\n168 - import sysconfig ERROR: No module named sysconfig\n169 - import syslog ERROR: No module named syslog\n170 - import tabnanny ERROR: No module named tabnanny\n171 - import tarfile ERROR: No module named tarfile\n172 - import telnetlib ERROR: No module named telnetlib\n173 - import tempfile ERROR: No module named tempfile\n174 - import test ERROR: No module named test\n175 - import textwrap ERROR: No module named textwrap\n176 - import this ERROR: No module named this\n177 - import timeit ERROR: No module named timeit\n178 - import toaiff ERROR: No module named toaiff\n179 - import token OK\n180 - import tokenize ERROR: No module named tokenize\n181 - import tputil ERROR: No module named tputil\n182 - import trace ERROR: No module named trace\n183 - import traceback OK\n184 - import tty ERROR: No module named tty\n185 - import types OK\n186 - import unittest ERROR: No module named unittest\n187 - import urllib ERROR: No module named urllib\n188 - import urllib2 ERROR: No module named urllib2\n189 - import urlparse ERROR: No module named urlparse\n190 - import user ERROR: No module named user\n191 - import uu ERROR: No module named uu\n192 - import uuid ERROR: No module named uuid\n193 - import warnings OK\n194 - import weakref OK\n195 - import webbrowser ERROR: No module named webbrowser\n196 - import whichdb ERROR: No module named whichdb\n197 - import wsgiref ERROR: No module named wsgiref\n198 - import xdrlib ERROR: No module named xdrlib\n199 - import xml ERROR: No module named xml\n200 - import xmllib ERROR: No module named xmllib\n201 - import xmlrpclib ERROR: No module named xmlrpclib\n202 - import zipfile ERROR: No module named zipfile\n --- END ---' not found in ' --- END --- '
-----------------------------------
Console output:
-----------------------------------
1183 modules (unfiltered)
203 modules (filtered)
0 - import BaseHTTPServer ERROR: No module named BaseHTTPServer
1 - import Bastion ERROR: No module named Bastion
2 - import CGIHTTPServer ERROR: No module named CGIHTTPServer
3 - import ConfigParser ERROR: No module named ConfigParser
4 - import Cookie ERROR: No module named Cookie
5 - import DocXMLRPCServer ERROR: No module named DocXMLRPCServer
6 - import HTMLParser ERROR: No module named HTMLParser
7 - import MimeWriter ERROR: No module named MimeWriter
8 - import Queue ERROR: No module named Queue
9 - import SimpleHTTPServer ERROR: No module named SimpleHTTPServer
10 - import SimpleXMLRPCServer ERROR: No module named SimpleXMLRPCServer
11 - import SocketServer ERROR: No module named SocketServer
12 - import StringIO ERROR: No module named StringIO
13 - import UserDict OK
14 - import UserList ERROR: No module named UserList
15 - import UserString ERROR: No module named UserString
16 - import abc OK
17 - import aifc ERROR: No module named aifc
18 - import antigravity ERROR: No module named antigravity
19 - import anydbm ERROR: No module named anydbm
20 - import argparse ERROR: No module named argparse
21 - import ast ERROR: No module named ast
22 - import asynchat ERROR: No module named asynchat
23 - import asyncore ERROR: No module named asyncore
24 - import atexit ERROR: No module named atexit
25 - import base64 OK
26 - import bdb ERROR: No module named bdb
27 - import binhex ERROR: No module named binhex
28 - import bisect ERROR: No module named bisect
29 - import cPickle ERROR: No module named cPickle
30 - import cProfile ERROR: No module named cProfile
31 - import cStringIO OK
32 - import calendar ERROR: No module named calendar
33 - import cgi ERROR: No module named cgi
34 - import cgitb ERROR: No module named cgitb
35 - import chunk ERROR: No module named chunk
36 - import cmd ERROR: No module named cmd
37 - import code OK
38 - import codecs OK
39 - import codeop OK
40 - import collections ERROR: No module named collections
41 - import colorsys ERROR: No module named colorsys
42 - import commands ERROR: No module named commands
43 - import compileall ERROR: No module named compileall
44 - import compiler ERROR: No module named compiler
45 - import contextlib ERROR: No module named contextlib
46 - import cookielib ERROR: No module named cookielib
47 - import copy OK
48 - import csv ERROR: No module named csv
49 - import datetime ERROR: No module named datetime
50 - import dbhash ERROR: No module named dbhash
51 - import dbm ERROR: No module named dbm
52 - import decimal ERROR: No module named decimal
53 - import difflib ERROR: No module named difflib
54 - import dircache ERROR: No module named dircache
55 - import dis ERROR: No module named dis
56 - import distutils ERROR: No module named distutils
57 - import doctest ERROR: No module named doctest
58 - import dumbdbm ERROR: No module named dumbdbm
59 - import email ERROR: No module named email
60 - import encodings OK
61 - import filecmp ERROR: No module named filecmp
62 - import fileinput ERROR: No module named fileinput
63 - import fnmatch ERROR: No module named fnmatch
64 - import formatter ERROR: No module named formatter
65 - import fpformat ERROR: No module named fpformat
66 - import fractions ERROR: No module named fractions
67 - import ftplib ERROR: No module named ftplib
68 - import functools ERROR: No module named functools
69 - import gdbm ERROR: No module named gdbm
70 - import genericpath OK
71 - import getopt OK
72 - import getpass ERROR: No module named getpass
73 - import gettext ERROR: No module named gettext
74 - import glob ERROR: No module named glob
75 - import greenlet ERROR: No module named greenlet
76 - import grp ERROR: No module named grp
77 - import gzip ERROR: No module named gzip
78 - import hashlib ERROR: No module named hashlib
79 - import heapq ERROR: No module named heapq
80 - import hmac ERROR: No module named hmac
81 - import htmlentitydefs ERROR: No module named htmlentitydefs
82 - import htmllib ERROR: No module named htmllib
83 - import httplib ERROR: No module named httplib
84 - import ihooks ERROR: No module named ihooks
85 - import imaplib ERROR: No module named imaplib
86 - import imghdr ERROR: No module named imghdr
87 - import importlib ERROR: No module named importlib
88 - import imputil ERROR: No module named imputil
89 - import inspect ERROR: No module named inspect
90 - import io ERROR: No module named io
91 - import json ERROR: No module named json
92 - import keyword ERROR: No module named keyword
93 - import lib2to3 ERROR: No module named lib2to3
94 - import linecache OK
95 - import locale ERROR: No module named locale
96 - import logging ERROR: No module named logging
97 - import macurl2path ERROR: No module named macurl2path
98 - import mailbox ERROR: No module named mailbox
99 - import mailcap ERROR: No module named mailcap
100 - import markupbase ERROR: No module named markupbase
101 - import marshal OK
102 - import md5 ERROR: No module named md5
103 - import mhlib ERROR: No module named mhlib
104 - import mimetools ERROR: No module named mimetools
105 - import mimetypes ERROR: No module named mimetypes
106 - import mimify ERROR: No module named mimify
107 - import modulefinder ERROR: No module named modulefinder
108 - import multifile ERROR: No module named multifile
109 - import mutex ERROR: No module named mutex
110 - import netrc ERROR: No module named netrc
111 - import new ERROR: No module named new
112 - import nntplib ERROR: No module named nntplib
113 - import nturl2path ERROR: No module named nturl2path
114 - import numbers ERROR: No module named numbers
115 - import opcode ERROR: No module named opcode
116 - import optparse ERROR: No module named optparse
117 - import os OK
118 - import pdb ERROR: No module named pdb
119 - import pickle ERROR: No module named pickle
120 - import pickletools ERROR: No module named pickletools
121 - import pipes ERROR: No module named pipes
122 - import pkgutil ERROR: No module named pkgutil
123 - import platform ERROR: No module named platform
124 - import plistlib ERROR: No module named plistlib
125 - import popen2 ERROR: No module named popen2
126 - import poplib ERROR: No module named poplib
127 - import posixfile ERROR: No module named posixfile
128 - import posixpath OK
129 - import pprint ERROR: No module named pprint
130 - import profile ERROR: No module named profile
131 - import pstats ERROR: No module named pstats
132 - import pty ERROR: No module named pty
133 - import pwd ERROR: No module named ctypes_support
134 - import pyclbr ERROR: No module named pyclbr
135 - import pydoc ERROR: No module named pydoc
136 - import pyrepl ERROR: No module named pyrepl
137 - import quopri ERROR: No module named quopri
138 - import random ERROR: No module named random
139 - import re OK
140 - import repr OK
141 - import resource ERROR: No module named resource
142 - import rexec ERROR: No module named rexec
143 - import rfc822 ERROR: No module named rfc822
144 - import rlcompleter ERROR: No module named rlcompleter
145 - import robotparser ERROR: No module named robotparser
146 - import runpy ERROR: No module named runpy
147 - import sched ERROR: No module named sched
148 - import sets ERROR: No module named sets
149 - import sgmllib ERROR: No module named sgmllib
150 - import sha ERROR: No module named sha
151 - import shelve ERROR: No module named shelve
152 - import shlex ERROR: No module named shlex
153 - import shutil ERROR: No module named shutil
154 - import site ERROR: No module named site
155 - import smtpd ERROR: No module named smtpd
156 - import smtplib ERROR: No module named smtplib
157 - import sndhdr ERROR: No module named sndhdr
158 - import socket ERROR: No module named socket
159 - import sre ERROR: No module named sre
160 - import stackless ERROR: No module named stackless
161 - import stat OK
162 - import statvfs ERROR: No module named statvfs
163 - import string ERROR: No module named string
164 - import stringold ERROR: No module named stringold
165 - import stringprep ERROR: No module named stringprep
166 - import struct OK
167 - import symbol OK
168 - import sysconfig ERROR: No module named sysconfig
169 - import syslog ERROR: No module named syslog
170 - import tabnanny ERROR: No module named tabnanny
171 - import tarfile ERROR: No module named tarfile
172 - import telnetlib ERROR: No module named telnetlib
173 - import tempfile ERROR: No module named tempfile
174 - import test ERROR: No module named test
175 - import textwrap ERROR: No module named textwrap
176 - import this ERROR: No module named this
177 - import timeit ERROR: No module named timeit
178 - import toaiff ERROR: No module named toaiff
179 - import token OK
180 - import tokenize ERROR: No module named tokenize
181 - import tputil ERROR: No module named tputil
182 - import trace ERROR: No module named trace
183 - import traceback OK
184 - import tty ERROR: No module named tty
185 - import types OK
186 - import unittest ERROR: No module named unittest
187 - import urllib ERROR: No module named urllib
188 - import urllib2 ERROR: No module named urllib2
189 - import urlparse ERROR: No module named urlparse
190 - import user ERROR: No module named user
191 - import uu ERROR: No module named uu
192 - import uuid ERROR: No module named uuid
193 - import warnings OK
194 - import weakref OK
195 - import webbrowser ERROR: No module named webbrowser
196 - import whichdb ERROR: No module named whichdb
197 - import wsgiref ERROR: No module named wsgiref
198 - import xdrlib ERROR: No module named xdrlib
199 - import xml ERROR: No module named xml
200 - import xmllib ERROR: No module named xmllib
201 - import xmlrpclib ERROR: No module named xmlrpclib
202 - import zipfile ERROR: No module named zipfile
--- END ---
-----------------------------------
output:
Where is my mistake?