rsclib 0.65__py3-none-any.whl → 0.66__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rsclib/Version.py +1 -1
- rsclib/__init__.py +4 -1
- rsclib/execute.py +145 -143
- rsclib/hexdump.py +13 -3
- rsclib/iter_recipes.py +16 -0
- rsclib/stateparser.py +52 -52
- rsclib-0.66.dist-info/METADATA +700 -0
- {rsclib-0.65.dist-info → rsclib-0.66.dist-info}/RECORD +11 -11
- {rsclib-0.65.dist-info → rsclib-0.66.dist-info}/WHEEL +1 -1
- rsclib-0.65.dist-info/METADATA +0 -692
- {rsclib-0.65.dist-info → rsclib-0.66.dist-info}/entry_points.txt +0 -0
- {rsclib-0.65.dist-info → rsclib-0.66.dist-info}/top_level.txt +0 -0
rsclib/hexdump.py
CHANGED
@@ -73,19 +73,29 @@ def unhexdump (iterable, file = None):
|
|
73
73
|
continue
|
74
74
|
if end:
|
75
75
|
raise ValueError ("Unknown hexdump format")
|
76
|
-
x = line.split (' ',
|
76
|
+
x = line.split (' ', 1)
|
77
77
|
if len (x) == 1:
|
78
78
|
h = x [0]
|
79
79
|
else:
|
80
80
|
h = x [1]
|
81
|
-
assert len (x [0]) <=
|
81
|
+
assert len (x [0]) <= 10
|
82
82
|
# Probably last line with only an address
|
83
83
|
if ' ' not in h and len (x) == 1 and len (h) > 2:
|
84
84
|
end = True
|
85
85
|
continue
|
86
|
-
|
86
|
+
# Determine format: split the thing and throw away last element
|
87
|
+
# if that is longer than 2.
|
88
|
+
h = h.strip ().split ()
|
87
89
|
if len (h [0]) > 2:
|
88
90
|
h = h [1:]
|
91
|
+
if len (h) > 16:
|
92
|
+
h = h [:16]
|
93
|
+
if len (h [-1]) != 2:
|
94
|
+
h = h [:-1]
|
95
|
+
assert len (h [0]) == 2
|
96
|
+
assert len (h [-1]) == 2
|
97
|
+
assert len (h) <= 16
|
98
|
+
|
89
99
|
if sys.version_info [0] < 3:
|
90
100
|
method = lambda x: b''.join (chr (c) for c in x)
|
91
101
|
else:
|
rsclib/iter_recipes.py
CHANGED
@@ -182,3 +182,19 @@ except ImportError :
|
|
182
182
|
for j in range (i+1, r) :
|
183
183
|
indices [j] = indices [j-1] + 1
|
184
184
|
yield tuple (pool [i] for i in indices)
|
185
|
+
|
186
|
+
try :
|
187
|
+
from itertools import batched
|
188
|
+
except ImportError :
|
189
|
+
def batched (x, n):
|
190
|
+
b = []
|
191
|
+
x = iter (x)
|
192
|
+
while True:
|
193
|
+
for k in range (n):
|
194
|
+
try:
|
195
|
+
b.append (next (x))
|
196
|
+
except StopIteration:
|
197
|
+
yield b
|
198
|
+
return
|
199
|
+
yield b
|
200
|
+
b = []
|
rsclib/stateparser.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/python3
|
2
|
-
# Copyright (C) 2007-
|
2
|
+
# Copyright (C) 2007-24 Dr. Ralf Schlatterbeck Open Source Consulting.
|
3
3
|
# Reichergasse 131, A-3411 Weidling.
|
4
4
|
# Web: http://www.runtux.com Email: office@runtux.com
|
5
5
|
# All rights reserved
|
@@ -25,21 +25,21 @@ import re
|
|
25
25
|
import sys
|
26
26
|
from rsclib.autosuper import autosuper
|
27
27
|
from rsclib.base_pickler import Base_Pickler
|
28
|
-
from rsclib.pycompat import string_types
|
28
|
+
from rsclib.pycompat import string_types, text_type
|
29
29
|
|
30
30
|
pattern_type = type (re.compile (''))
|
31
31
|
|
32
|
-
class Parse_Error (ValueError)
|
32
|
+
class Parse_Error (ValueError): pass
|
33
33
|
|
34
|
-
class Debug (autosuper)
|
35
|
-
def debug (self, level, * msg)
|
36
|
-
if self.
|
37
|
-
print (' '.join (
|
34
|
+
class Debug (autosuper):
|
35
|
+
def debug (self, level, * msg):
|
36
|
+
if self.debug_level >= level:
|
37
|
+
print (' '.join (text_type (x) for x in msg), file = sys.stderr)
|
38
38
|
sys.stderr.flush ()
|
39
39
|
# end def debug
|
40
40
|
# end class Debug
|
41
41
|
|
42
|
-
class Transition (Debug)
|
42
|
+
class Transition (Debug):
|
43
43
|
""" Represents one line in a state-change diagram. If matched,
|
44
44
|
applies the defined action (if any) and returns new state.
|
45
45
|
|
@@ -50,23 +50,23 @@ class Transition (Debug) :
|
|
50
50
|
Action methods get the matched line, and in case of a regex the
|
51
51
|
matched groups as parameter.
|
52
52
|
"""
|
53
|
-
def __init__ (self, pattern, state, new_state, action, **kw)
|
54
|
-
self.pattern
|
55
|
-
self.state
|
56
|
-
self.new_state
|
57
|
-
self.
|
58
|
-
self.act_name
|
59
|
-
if action
|
53
|
+
def __init__ (self, pattern, state, new_state, action, **kw):
|
54
|
+
self.pattern = pattern
|
55
|
+
self.state = state
|
56
|
+
self.new_state = new_state
|
57
|
+
self.debug_level = kw.get ('debug_level', 0)
|
58
|
+
self.act_name = action
|
59
|
+
if action:
|
60
60
|
action = getattr (self.state.parser, action)
|
61
|
-
self.action
|
61
|
+
self.action = action
|
62
62
|
self.__super.__init__ (**kw)
|
63
63
|
# end def __init__
|
64
64
|
|
65
|
-
def _transition (self, match = None)
|
65
|
+
def _transition (self, match = None):
|
66
66
|
new = None
|
67
67
|
pstate = self.state.parser.state
|
68
68
|
line = self.state.parser.line
|
69
|
-
if self.action
|
69
|
+
if self.action:
|
70
70
|
new = self.action (self.state, self.new_state, match)
|
71
71
|
new = new or self.new_state
|
72
72
|
self.debug \
|
@@ -77,15 +77,15 @@ class Transition (Debug) :
|
|
77
77
|
return new
|
78
78
|
# end def _transition
|
79
79
|
|
80
|
-
def match (self)
|
80
|
+
def match (self):
|
81
81
|
line = self.state.parser.line
|
82
|
-
if self.pattern is None or line == self.pattern
|
82
|
+
if self.pattern is None or line == self.pattern:
|
83
83
|
self.debug \
|
84
84
|
(2, "match: %s (act = %s)" % (self.pattern, self.act_name))
|
85
85
|
return self._transition ()
|
86
|
-
if isinstance (self.pattern, pattern_type)
|
86
|
+
if isinstance (self.pattern, pattern_type):
|
87
87
|
m = self.pattern.search (line)
|
88
|
-
if m
|
88
|
+
if m:
|
89
89
|
self.debug (2, "match: <regex> (act = %s)" % self.act_name)
|
90
90
|
return self._transition (m)
|
91
91
|
self.debug \
|
@@ -98,34 +98,34 @@ class Transition (Debug) :
|
|
98
98
|
|
99
99
|
# end class Transition
|
100
100
|
|
101
|
-
class State (Debug)
|
101
|
+
class State (Debug):
|
102
102
|
""" Represents a single state of the parser """
|
103
103
|
|
104
|
-
def __init__ (self, parser, name, **kw)
|
104
|
+
def __init__ (self, parser, name, **kw):
|
105
105
|
self.name = name
|
106
106
|
self.parser = parser
|
107
107
|
self.transitions = []
|
108
|
-
self.
|
108
|
+
self.debug_level = kw.get ('debug_level', 0)
|
109
109
|
self.__super.__init__ (**kw)
|
110
110
|
# end def __init__
|
111
111
|
|
112
|
-
def append (self, transition)
|
112
|
+
def append (self, transition):
|
113
113
|
self.transitions.append (transition)
|
114
114
|
# end def append
|
115
115
|
|
116
|
-
def match (self)
|
117
|
-
for t in self.transitions
|
116
|
+
def match (self):
|
117
|
+
for t in self.transitions:
|
118
118
|
state = t.match ()
|
119
|
-
if state
|
119
|
+
if state:
|
120
120
|
return state
|
121
|
-
else
|
121
|
+
else:
|
122
122
|
raise Parse_Error \
|
123
123
|
("%s: %s" % (self.parser.lineno, self.parser.line))
|
124
124
|
# end def match
|
125
125
|
|
126
126
|
# end class State
|
127
127
|
|
128
|
-
class Parser (Debug, Base_Pickler)
|
128
|
+
class Parser (Debug, Base_Pickler):
|
129
129
|
""" Simple state-machine parser.
|
130
130
|
To use, define a subclass with the necessary actions. An action
|
131
131
|
method gets the line matched and an optional match object.
|
@@ -134,55 +134,55 @@ class Parser (Debug, Base_Pickler) :
|
|
134
134
|
pickle_exceptions = dict.fromkeys (('stack', 'state', 'states'))
|
135
135
|
encoding = 'latin1'
|
136
136
|
|
137
|
-
def __init__ (self, matrix = None, **kw)
|
138
|
-
self.
|
139
|
-
self.state
|
140
|
-
self.states
|
137
|
+
def __init__ (self, matrix = None, **kw):
|
138
|
+
self.debug_level = kw.get ('debug_level', 0)
|
139
|
+
self.state = None
|
140
|
+
self.states = {}
|
141
141
|
matrix = matrix or self.matrix
|
142
142
|
self.__super.__init__ (**kw)
|
143
|
-
for line in matrix
|
143
|
+
for line in matrix:
|
144
144
|
self.add_transition (* line)
|
145
145
|
self.stack = []
|
146
146
|
# end def __init__
|
147
147
|
|
148
|
-
def add_transition (self, statename, pattern, newname, action)
|
149
|
-
if statename not in self.states
|
148
|
+
def add_transition (self, statename, pattern, newname, action):
|
149
|
+
if statename not in self.states:
|
150
150
|
self.states [statename] = \
|
151
|
-
State (self, statename,
|
151
|
+
State (self, statename, debug_level = self.debug_level)
|
152
152
|
state = self.states [statename]
|
153
153
|
new = None
|
154
|
-
if newname
|
155
|
-
if newname not in self.states
|
154
|
+
if newname:
|
155
|
+
if newname not in self.states:
|
156
156
|
self.states [newname] = \
|
157
|
-
State (self, newname,
|
157
|
+
State (self, newname, debug_level = self.debug_level)
|
158
158
|
new = self.states [newname]
|
159
|
-
if not self.state
|
159
|
+
if not self.state:
|
160
160
|
self.state = state
|
161
161
|
t = Transition \
|
162
|
-
(pattern, state, new, action,
|
162
|
+
(pattern, state, new, action, debug_level = self.debug_level)
|
163
163
|
state.append (t)
|
164
164
|
# end def add_transition
|
165
165
|
|
166
|
-
def parse (self, file)
|
167
|
-
for n, line in enumerate (file)
|
168
|
-
if self.encoding
|
166
|
+
def parse (self, file):
|
167
|
+
for n, line in enumerate (file):
|
168
|
+
if self.encoding:
|
169
169
|
line = line.decode (self.encoding)
|
170
170
|
self.line = line.rstrip ()
|
171
171
|
self.lineno = n + 1
|
172
|
-
try
|
172
|
+
try:
|
173
173
|
self.state = self.state.match ()
|
174
|
-
except Exception as cause
|
174
|
+
except Exception as cause:
|
175
175
|
#raise Parse_Error (self.lineno, cause)
|
176
176
|
raise
|
177
177
|
# end def parse
|
178
178
|
|
179
|
-
def push (self, state, new_state = None, match = None)
|
179
|
+
def push (self, state, new_state = None, match = None):
|
180
180
|
self.stack.append (state)
|
181
181
|
stack = [s.name for s in self.stack]
|
182
182
|
self.debug (3, "push: %s, stack: %s" % (new_state.name, stack))
|
183
183
|
# end def push
|
184
184
|
|
185
|
-
def pop (self, state = None, new_state = None, match = None)
|
185
|
+
def pop (self, state = None, new_state = None, match = None):
|
186
186
|
self.debug \
|
187
187
|
( 3
|
188
188
|
, "before pop: %s" % self.state.name
|
@@ -201,7 +201,7 @@ class Parser (Debug, Base_Pickler) :
|
|
201
201
|
return state
|
202
202
|
# end def pop
|
203
203
|
|
204
|
-
def endpop (self, state = None, new_state = None, match = None)
|
204
|
+
def endpop (self, state = None, new_state = None, match = None):
|
205
205
|
""" Pop stack *after* handling the current line
|
206
206
|
"""
|
207
207
|
return self.stack.pop ()
|