diff options
author | W. Trevor King <wking@drexel.edu> | 2009-11-17 09:51:18 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-11-17 09:51:18 -0500 |
commit | 5563818b85a7c9f68ede85cae902aceea42e5679 (patch) | |
tree | 674a4de9a5f63c5e67ed07b15a76f4b1fcedf398 /libbe/mapfile.py | |
parent | 0b51c1b9a7495821dcdf444eb636b4764b96c0b1 (diff) | |
parent | f108f5a0fb0984c0daccd8be72ea0ffa309b3fff (diff) | |
download | bugseverywhere-5563818b85a7c9f68ede85cae902aceea42e5679.tar.gz |
Fixed bug with unicode handling reported by Nicolas Alvarez.
Date: Mon, 16 Nov 2009 20:34:50 -0300
From: Nicolas Alvarez <nicolas.alvarez@gmail.com>
Subject: [Be-devel] Mercurial + BE + Unicode doesn't work
My username in ~/.hgrc contains a Unicode character. When I run "be new" on
a Mercurial repository, I get an unhandled Python exception:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13:
ordinal not in range(128)
The following shell script should reproduce the error:
#!/bin/sh
repo=/tmp/`mktemp -d bug-repro.XXXX`
hg init $repo
cd $repo
/usr/bin/printf "[ui]\nusername = Nicol\u00e1s\n" > $repo/.hg/hgrc
be set-root $repo
be new "Testing"
rm -rf /tmp/$repo
[WTK:
Note that the
be set-root
usage is out of date, it is now
be init
]
Diffstat (limited to 'libbe/mapfile.py')
-rw-r--r-- | libbe/mapfile.py | 13 |
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() |