Commit 982d0d7e authored by Vincent Pelletier's avatar Vincent Pelletier

README.rst: Document parsing encoded file.

parent 1e0ac65c
......@@ -192,18 +192,26 @@ Generate with unicode chars fitting in single UTF-8-encoded bytes::
Generate again, with chars needing more bytes when encoded, and demonstrating
checksum generation::
>>> input_data = (
>>> wide_input_data = (
... {
... 'comment': u'\u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051\u3053\u3055\u3057\u3059\u305b\u305d',
... },
... [],
... )
>>> sample_file = StringIO()
>>> checksumed_wrapper = xfw.SHA1ChecksumedFile(sample_file)
>>> FILE_STRUCTURE.generateStream(encoded_writer(checksumed_wrapper), input_data)
>>> sample_file.getvalue()
>>> wide_sample_file = StringIO()
>>> checksumed_wrapper = xfw.SHA1ChecksumedFile(wide_sample_file)
>>> FILE_STRUCTURE.generateStream(encoded_writer(checksumed_wrapper), wide_input_data)
>>> wide_sample_file.getvalue()
'HEAD1000\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a\xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93\xe3\x81\x95\xe3\x81\x97\xe3\x81\x99\xe3\x81\x9b\xe3\x81\x9d'
>>> len(sample_file.getvalue())
>>> len(wide_sample_file.getvalue())
53
>>> hashlib.sha1(sample_file.getvalue()).hexdigest() == checksumed_wrapper.getHexDigest()
>>> hashlib.sha1(wide_sample_file.getvalue()).hexdigest() == checksumed_wrapper.getHexDigest()
True
Still, both parse to their respective original data::
>>> encoded_reader = codecs.getreader('UTF-8')
>>> FILE_STRUCTURE.parseStream(encoded_reader(StringIO(sample_file.getvalue())))[0]['comment']
u'Just ASCII'
>>> FILE_STRUCTURE.parseStream(encoded_reader(StringIO(wide_sample_file.getvalue())))[0]['comment']
u'\u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051\u3053\u3055\u3057\u3059\u305b\u305d'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment