aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-11-17 08:36:22 -0500
committerW. Trevor King <wking@drexel.edu>2009-11-17 08:36:22 -0500
commiteaa6d158608b0b47c337fc1433902532bc646128 (patch)
treed133104f2decacd514f88c3888b120191ccd6b5b
parent32fbab0fb8f5defc3698d288024a10b8d32a0f25 (diff)
downloadbugseverywhere-eaa6d158608b0b47c337fc1433902532bc646128.tar.gz
Set binary=True for mapfile file handling
The YAML library produces Python string encodings of unicode objects. There's no reason to try and convert them back into Python unicode objects just to save them with binary=False, because the files are only read in to be passed into the YAML parser, which can handle the unicode characters correctly.
-rw-r--r--libbe/mapfile.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/libbe/mapfile.py b/libbe/mapfile.py
index 4d69601..d0e16fe 100644
--- a/libbe/mapfile.py
+++ b/libbe/mapfile.py
@@ -75,7 +75,7 @@ def generate(map):
assert(len(key) > 0)
except AssertionError:
raise IllegalKey(unicode(key).encode('unicode_escape'))
- if "\n" in map[key]:
+ if '\n' in map[key]:
raise IllegalValue(unicode(map[key]).encode('unicode_escape'))
lines = []
@@ -83,7 +83,7 @@ def generate(map):
lines.append(yaml.safe_dump({key: map[key]},
default_flow_style=False,
allow_unicode=True))
- lines.append("")
+ lines.append('')
return '\n'.join(lines)
def parse(contents):
@@ -101,16 +101,21 @@ def parse(contents):
'd'
>>> dict["e"]
'f'
+ >>> contents = generate({"q":u"Fran\u00e7ais"})
+ >>> dict = parse(contents)
+ >>> dict["q"]
+ u'Fran\\xe7ais'
"""
return yaml.load(contents) or {}
def map_save(vcs, path, map, allow_no_vcs=False):
"""Save the map as a mapfile to the specified path"""
contents = generate(map)
- vcs.set_file_contents(path, contents, allow_no_vcs)
+ vcs.set_file_contents(path, contents, allow_no_vcs, binary=True)
def map_load(vcs, path, allow_no_vcs=False):
- contents = vcs.get_file_contents(path, allow_no_vcs=allow_no_vcs)
+ contents = vcs.get_file_contents(path, allow_no_vcs=allow_no_vcs,
+ binary=True)
return parse(contents)
suite = doctest.DocTestSuite()