Repository navigation
Expand file tree
/
Copy pathlogmodule.py
More file actions
156 lines (137 loc) · 5.33 KB
/
Copy pathlogmodule.py
File metadata and controls
156 lines (137 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#####################################################################################
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
# copy of the license can be found in the License.html file at the root of this distribution. If
# you cannot locate the Apache License, Version 2.0, please send an email to
# [email protected]. By using this source code in any fashion, you are agreeing to be bound
# by the terms of the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
#####################################################################################
"""Used for getting a list of members defined in a module.
When run stand-alone outputs the differences for all built-in modules
and known types.
Also used by modulediff.py for testing to ensure we don't regress.
"""
from __future__ import print_function
import sys
import datetime
import _weakref
class C(object):
def f(self): pass
class OC: pass
def f(): pass
knownTypes = [object, bytes, bool, int, str, list, tuple, dict, float, complex, long, type(f), type(C().f), type(OC), type(list.append), type([].append), type(None), type(object.__new__),
type(type.__dict__), type(Exception.args), type(complex.imag), type(type.__call__), type(type.__call__.__call__), type(datetime.datetime.max), type(datetime.date.max), type(datetime.time.max),
type(datetime.timedelta.max), type(staticmethod.__new__), unicode, type(_weakref.ProxyType.__add__), C.__weakref__.__class__, file, basestring]
BUILTIN_MODULES = [
"__builtin__",
"_codecs",
"_collections",
"copy_reg",
"_functools",
"_heapq", #CodePlex 21396
"_locale",
"_md5",
"_random",
"_sha",
"_sha256",
"_sha512",
"_sre",
"_struct",
"_subprocess",
"_warnings",
"_weakref",
"_winreg",
"array",
"binascii",
"cPickle",
"cStringIO",
"cmath",
"datetime",
"errno",
"exceptions",
"future_builtins", #CodePlex 19580
"gc",
"imp",
"itertools",
"marshal",
"math",
"mmap",
"msvcrt",
"nt",
"operator",
"select",
"signal", #CodePlex 16414
"sys",
"thread",
"time",
"xxsubtype",
]
MISSING_MODULES = [
"_csv", #CodePlex 21395
"_hotshot", #CodePlex 21397
"_json", #CodePlex 19581
"_lsprof", #CodePlex 21398
"_multibytecodec", #CodePlex 21399
"_ast", #CodePlex 21088
"_bisect", #CodePlex 21392
"_codecs_cn", #CodePlex 15507
"_codecs_hk", #CodePlex 15507
"_codecs_iso2022", #CodePlex 21394
"_codecs_jp", #CodePlex 15507
"_codecs_kr", #CodePlex 15507
"_codecs_tw", #CodePlex 15507
"_symtable", #IronPython incompat
"_types", #Can't import this in CPython 2.6 either...
"audioop", #CodePlex 21400
"imageop", #Deprecated in CPy 2.6. Removed in Cpy 3.0
"parser", #CodePlex 1347 - Won't fix
"strop", #CodePlex 21403
"zipimport", #CodePlex 391
"zlib", #CodePlex 2590
]
def dump_module(module):
print('Module:', module)
try:
mod = __import__(module)
except ImportError:
print(' no module', module)
else:
dump_object(mod)
def dump_object(obj, depth = 1):
for x in dir(obj):
try:
newobj = getattr(obj, x)
except NotImplementedError:
print('%s%-30s %r' % (' ' * depth, x, '**NotImplemented**'))
else:
print('%s%-30s' % (' ' * depth, x, ))
#print '%s%-30s %r %r' % (' ' * depth, x, type(newobj), type(obj))
if (type(newobj) in knownTypes or
newobj in knownTypes or
newobj is type):
continue
dump_object(newobj, depth + 1)
def dump_types():
for knownType in knownTypes:
print('Type:', knownType)
dump_object(knownType)
print('Type:', type)
dump_object(type)
def dump_all():
for module in BUILTIN_MODULES:
dump_module(module)
dump_types()
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == 'types_only':
dump_types()
else:
dump_module(sys.argv[1])
else:
dump_all()