Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xfw
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
xfw
Commits
982d0d7e
Commit
982d0d7e
authored
Nov 26, 2013
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
README.rst: Document parsing encoded file.
parent
1e0ac65c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
README.rst
README.rst
+15
-7
No files found.
README.rst
View file @
982d0d7e
...
@@ -192,18 +192,26 @@ Generate with unicode chars fitting in single UTF-8-encoded bytes::
...
@@ -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
Generate again, with chars needing more bytes when encoded, and demonstrating
checksum generation::
checksum generation::
>>> input_data = (
>>>
wide_
input_data = (
... {
... {
... 'comment': u'\u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051\u3053\u3055\u3057\u3059\u305b\u305d',
... 'comment': u'\u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051\u3053\u3055\u3057\u3059\u305b\u305d',
... },
... },
... [],
... [],
... )
... )
>>> sample_file = StringIO()
>>>
wide_
sample_file = StringIO()
>>> checksumed_wrapper = xfw.SHA1ChecksumedFile(sample_file)
>>> checksumed_wrapper = xfw.SHA1ChecksumedFile(
wide_
sample_file)
>>> FILE_STRUCTURE.generateStream(encoded_writer(checksumed_wrapper), input_data)
>>> FILE_STRUCTURE.generateStream(encoded_writer(checksumed_wrapper),
wide_
input_data)
>>> sample_file.getvalue()
>>>
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'
'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
53
>>> hashlib.sha1(sample_file.getvalue()).hexdigest() == checksumed_wrapper.getHexDigest()
>>> hashlib.sha1(
wide_
sample_file.getvalue()).hexdigest() == checksumed_wrapper.getHexDigest()
True
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'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment