Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efa8e05

Browse files
committed
Merge branch 'release/0.5.2'
2 parents 222130c + feabad9 commit efa8e05

File tree

8 files changed

+515
-126
lines changed

8 files changed

+515
-126
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A more complete documentation could be found in the doc directory (build with sp
77

88

99
Stable: [![Build Status - Stable](https://travis-ci.org/bluec0re/python-wcfbin.svg?branch=master)](https://travis-ci.org/bluec0re/python-wcfbin)
10-
Dev: [![Build Status - Dev](https://travis-ci.org/bluec0re/python-wcfbin.svg?branch=development)](https://travis-ci.org/bluec0re/python-wcfbin)
10+
Dev: [![Build Status - Dev](https://travis-ci.org/bluec0re/python-wcfbin.svg?branch=develop)](https://travis-ci.org/bluec0re/python-wcfbin)
1111

1212

1313
Contributors

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name = "wcf-binary parser",
6-
version = "0.5.0",
6+
version = "0.5.2",
77
author = "Timo Schmid",
88
author_email = "[email protected]",
99
description = ("A library for transforming wcf-binary data from and to xml"),

wcf/datatypes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ def __str__(self):
9494

9595
@classmethod
9696
def parse(cls, fp):
97+
"""
98+
>>> from io import BytesIO
99+
>>> fp = BytesIO(b'\\x7f')
100+
>>> mb = MultiByteInt31.parse(fp)
101+
>>> mb.value
102+
127
103+
>>> fp = BytesIO(b'\\xff\\x7f')
104+
>>> mb = MultiByteInt31.parse(fp)
105+
>>> mb.value
106+
16383
107+
>>> fp = BytesIO(b'\\xb9\\x0a')
108+
>>> mb = MultiByteInt31.parse(fp)
109+
>>> mb.value
110+
1337
111+
"""
97112
v = 0
98113
# tmp = ''
99114
for pos in range(4):
@@ -208,7 +223,7 @@ def parse(cls, fp):
208223
low = struct.unpack(b'<Q', fp.read(8))[0]
209224

210225
return cls(sign, high, low, scale)
211-
226+
212227

213228
if __name__ == '__main__':
214229
import doctest

wcf/records/attributes.py

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import struct
4040
import logging
41+
import sys
4142

4243
log = logging.getLogger(__name__)
4344
logging.basicConfig(level=logging.INFO)
@@ -71,6 +72,15 @@ def __str__(self):
7172

7273
@classmethod
7374
def parse(cls, fp):
75+
"""
76+
>>> from io import BytesIO
77+
>>> fp = BytesIO(b'\\x04test\\x86')
78+
>>> sar = ShortAttributeRecord.parse(fp)
79+
>>> str(sar.name)
80+
'test'
81+
>>> sar.value
82+
<TrueTextRecord(type=0x86)>
83+
"""
7484
name = Utf8String.parse(fp).value
7585
type = struct.unpack(b'<B', fp.read(1))[0]
7686
value = Record.records[type].parse(fp)
@@ -100,13 +110,24 @@ def to_bytes(self):
100110

101111
def __str__(self):
102112
return '%s:%s="%s"' % (self.prefix, self.name, str(self.value))
103-
113+
104114
@classmethod
105115
def parse(cls, fp):
116+
"""
117+
>>> from io import BytesIO
118+
>>> fp = BytesIO(b'\\x01x\\x04test\\x86')
119+
>>> ar = AttributeRecord.parse(fp)
120+
>>> str(ar.prefix)
121+
'x'
122+
>>> str(ar.name)
123+
'test'
124+
>>> ar.value
125+
<TrueTextRecord(type=0x86)>
126+
"""
106127
prefix = Utf8String.parse(fp).value
107-
name = Utf8String.parse(fp).value
108-
type = struct.unpack(b'<B', fp.read(1))[0]
109-
value= Record.records[type].parse(fp)
128+
name = Utf8String.parse(fp).value
129+
type = struct.unpack(b'<B', fp.read(1))[0]
130+
value = Record.records[type].parse(fp)
110131

111132
return cls(prefix, name, value)
112133

@@ -131,12 +152,23 @@ def to_bytes(self):
131152

132153
def __str__(self):
133154
return '%s="%s"' % (dictionary[self.index], str(self.value))
134-
155+
135156
@classmethod
136157
def parse(cls, fp):
158+
"""
159+
>>> from io import BytesIO
160+
>>> fp = BytesIO(b'\\x0c\\x86')
161+
>>> sdar = ShortDictionaryAttributeRecord.parse(fp)
162+
>>> sdar.index
163+
12
164+
>>> sdar.value
165+
<TrueTextRecord(type=0x86)>
166+
>>> str(sdar)
167+
'To="true"'
168+
"""
137169
index = MultiByteInt31.parse(fp).value
138-
type = struct.unpack(b'<B', fp.read(1))[0]
139-
value= Record.records[type].parse(fp)
170+
type = struct.unpack(b'<B', fp.read(1))[0]
171+
value = Record.records[type].parse(fp)
140172

141173
return cls(index, value)
142174

@@ -162,15 +194,26 @@ def to_bytes(self):
162194
return bytes(bt)
163195

164196
def __str__(self):
165-
return '%s:%s="%s"' % (self.prefix, dictionary[self.index],
197+
return '%s:%s="%s"' % (self.prefix, dictionary[self.index],
166198
str(self.value))
167-
199+
168200
@classmethod
169201
def parse(cls, fp):
202+
"""
203+
>>> from io import BytesIO
204+
>>> fp = BytesIO(b'\\x01x\\x02\\x86')
205+
>>> dar = DictionaryAttributeRecord.parse(fp)
206+
>>> str(dar.prefix)
207+
'x'
208+
>>> dar.index
209+
2
210+
>>> str(dar.value)
211+
'true'
212+
"""
170213
prefix = Utf8String.parse(fp).value
171214
index = MultiByteInt31.parse(fp).value
172-
type = struct.unpack(b'<B', fp.read(1))[0]
173-
value= Record.records[type].parse(fp)
215+
type = struct.unpack(b'<B', fp.read(1))[0]
216+
value = Record.records[type].parse(fp)
174217

175218
return cls(prefix, index, value)
176219

@@ -196,6 +239,15 @@ def to_bytes(self):
196239

197240
@classmethod
198241
def parse(cls, fp):
242+
"""
243+
>>> from io import BytesIO
244+
>>> fp = BytesIO(b'\\x06')
245+
>>> sdxar = ShortDictionaryXmlnsAttributeRecord.parse(fp)
246+
>>> sdxar.index
247+
6
248+
>>> str(sdxar)
249+
'xmlns="http://www.w3.org/2005/08/addressing"'
250+
"""
199251
index = MultiByteInt31.parse(fp).value
200252
return cls(index)
201253

@@ -223,6 +275,17 @@ def to_bytes(self):
223275

224276
@classmethod
225277
def parse(cls, fp):
278+
"""
279+
>>> from io import BytesIO
280+
>>> fp = BytesIO(b'\\x01a\\x06')
281+
>>> dxar = DictionaryXmlnsAttributeRecord.parse(fp)
282+
>>> str(dxar.prefix)
283+
'a'
284+
>>> dxar.index
285+
6
286+
>>> str(dxar)
287+
'xmlns:a="http://www.w3.org/2005/08/addressing"'
288+
"""
226289
prefix = Utf8String.parse(fp).value
227290
index = MultiByteInt31.parse(fp).value
228291
return cls(prefix, index)
@@ -236,15 +299,26 @@ def __init__(self, value, *args, **kwargs):
236299
self.value = value
237300

238301
def to_bytes(self):
302+
"""
303+
>>> ShortXmlnsAttributeRecord('test').to_bytes()
304+
b'\\x08\\x04test'
305+
"""
239306
bt = struct.pack(b'<B', self.type)
240307
bt += Utf8String(self.value).to_bytes()
241308
return bytes(bt)
242309

243310
def __str__(self):
244311
return 'xmlns="%s"' % (self.value,)
245-
312+
246313
@classmethod
247314
def parse(cls, fp):
315+
"""
316+
>>> from io import BytesIO
317+
>>> fp = BytesIO(b'\\x04test')
318+
>>> sxar = ShortXmlnsAttributeRecord.parse(fp)
319+
>>> str(sxar)
320+
'xmlns="test"'
321+
"""
248322
value = Utf8String.parse(fp).value
249323
return cls(value)
250324

@@ -258,16 +332,26 @@ def __init__(self, name, value, *args, **kwargs):
258332
self.value = value
259333

260334
def to_bytes(self):
335+
"""
336+
>>> XmlnsAttributeRecord('name', 'value').to_bytes()
337+
b'\\t\\x04name\\x05value'
338+
"""
261339
bt = struct.pack(b'<B', self.type)
262340
bt += Utf8String(self.name).to_bytes()
263341
bt += Utf8String(self.value).to_bytes()
264342
return bytes(bt)
265343

266344
def __str__(self):
267345
return 'xmlns:%s="%s"' % (self.name, self.value)
268-
346+
269347
@classmethod
270348
def parse(cls, fp):
349+
r"""
350+
>>> from io import BytesIO
351+
>>> fp = BytesIO(b'\x04name\x05value')
352+
>>> str(XmlnsAttributeRecord.parse(fp))
353+
'xmlns:name="value"'
354+
"""
271355
name = Utf8String.parse(fp).value
272356
value = Utf8String.parse(fp).value
273357
return cls(name, value)
@@ -278,12 +362,23 @@ def __init__(self, name, value):
278362
super(PrefixAttributeRecord, self).__init__(self.char, name, value)
279363

280364
def to_bytes(self):
365+
r"""
366+
>>> PrefixAttributeARecord('name', TrueTextRecord()).to_bytes()
367+
b'&\x04name\x86'
368+
"""
281369
string = Utf8String(self.name)
282370
return bytes(struct.pack(b'<B', self.type) + string.to_bytes() +
283371
self.value.to_bytes())
284372

285373
@classmethod
286374
def parse(cls, fp):
375+
r"""
376+
>>> from io import BytesIO
377+
>>> fp = BytesIO(b'\x04name\x86')
378+
>>> paar = PrefixAttributeARecord.parse(fp)
379+
>>> str(paar)
380+
'a:name="true"'
381+
"""
287382
name = Utf8String.parse(fp).value
288383
type = struct.unpack(b'<B', fp.read(1))[0]
289384
value= Record.records[type].parse(fp)
@@ -296,12 +391,23 @@ def __init__(self, index, value):
296391
index, value)
297392

298393
def to_bytes(self):
394+
r"""
395+
>>> PrefixDictionaryAttributeBRecord(2, TrueTextRecord()).to_bytes()
396+
b'\r\x02\x86'
397+
"""
299398
idx = MultiByteInt31(self.index)
300399
return bytes(struct.pack(b'<B', self.type) + idx.to_bytes() +
301400
self.value.to_bytes())
302401

303402
@classmethod
304403
def parse(cls, fp):
404+
r"""
405+
>>> from io import BytesIO
406+
>>> fp = BytesIO(b'\02\x86')
407+
>>> pdabr = PrefixDictionaryAttributeBRecord.parse(fp)
408+
>>> str(pdabr)
409+
'b:Envelope="true"'
410+
"""
305411
index = MultiByteInt31.parse(fp).value
306412
type = struct.unpack(b'<B', fp.read(1))[0]
307413
value = Record.records[type].parse(fp)
@@ -320,8 +426,8 @@ def parse(cls, fp):
320426
))
321427

322428

429+
__module__ = sys.modules[__name__]
323430
__records__ = []
324-
325431
for c in range(0x0C, 0x25 + 1):
326432
char = chr(c - 0x0C + ord('a'))
327433
clsname = 'PrefixDictionaryAttribute' + char.upper() + 'Record'
@@ -335,6 +441,7 @@ def parse(cls, fp):
335441
char=char,
336442
)
337443
)
444+
setattr(__module__, clsname, cls)
338445
__records__.append(cls)
339446

340447
for c in range(0x26, 0x3F + 1):
@@ -350,6 +457,7 @@ def parse(cls, fp):
350457
char=char,
351458
)
352459
)
460+
setattr(__module__, clsname, cls)
353461
__records__.append(cls)
354462

355463
Record.add_records(__records__)

0 commit comments

Comments
 (0)