-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpydocparser.py
More file actions
71 lines (60 loc) · 2.63 KB
/
Copy pathpydocparser.py
File metadata and controls
71 lines (60 loc) · 2.63 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
#!/usr/bin/env python2.6
import re
import os
import sys
import subprocess
modules = ['random']
state = None
PackageScanState, ClassScanState = 'pkg', 'cls'
ClassScanState_Outline, ClassScanState_MethodResolution, ClassScanState_MethodDefinition, ClassScanState_DataDescriptors, ClassScanState_Attributes, ClassScanState_InheritedMethods = 'c_otl', 'c_res', 'c_mdf', 'c_dat', 'c_att', 'c_inh'
ClassScanState_InheritedAttributes, ClassScanState_MethodDocumentation = 'c_iat', 'c_mdc'
ClassMatchRegex = re.compile(r' (class .*?\(.*?\).*?)')
InClassMatchRegex = re.compile(r' \| ')
ResolvedMethodMatchRegex = re.compile(r' \| ([A-Za-z_]*?\(.*?\))')
UnresolvedMethodMatchRegex = re.compile(r' \| (.*? = \<built\-in function.*?\>)')
CouldBeMethodDocLineRegex = re.compile(r' \| (.*)')
class method():
documentation = ''
name = ''
parameters = []
def __repr__(self):
return '<'+self.name+'>'
for module in modules:
doctext = subprocess.Popen(['/usr/bin/pydoc', module], stdout = subprocess.PIPE).stdout.read()
doctext_lines = doctext.split('\n')
methods = []
currentMethod = None
state = None
classState = None
for line in doctext_lines:
print state, classState, line[:70]
if state == None:
if re.match(ClassMatchRegex, line):
state = ClassScanState
classState = ClassScanState_Outline
if re.match(ResolvedMethodMatchRegex, line): pass
elif state == ClassScanState:
if not re.match(InClassMatchRegex, line):
state = None
classState = None
continue
if line == ' | Method resolution order:':
classState = ClassScanState_MethodResolution
continue
if line == ' | Methods defined here:':
classState = ClassScanState_MethodDefinition
continue
if classState == ClassScanState_MethodDocumentation:
if re.match(CouldBeMethodDocLineRegex, line):
currentMethod.documentation += line
else:
classState = ClassScanState_MethodDefinition
if classState == ClassScanState_MethodDefinition:
if re.match(ResolvedMethodMatchRegex, line):
if currentMethod is not None:
methods.append(currentMethod)
currentMethod = method()
currentMethod.name = line
classState = ClassScanState_MethodDocumentation
for m in methods:
print m