aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/vcs.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-11-17 09:51:18 -0500
committerW. Trevor King <wking@drexel.edu>2009-11-17 09:51:18 -0500
commit5563818b85a7c9f68ede85cae902aceea42e5679 (patch)
tree674a4de9a5f63c5e67ed07b15a76f4b1fcedf398 /libbe/vcs.py
parent0b51c1b9a7495821dcdf444eb636b4764b96c0b1 (diff)
parentf108f5a0fb0984c0daccd8be72ea0ffa309b3fff (diff)
downloadbugseverywhere-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/vcs.py')
-rw-r--r--libbe/vcs.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/libbe/vcs.py b/libbe/vcs.py
index 7484660..ba23858 100644
--- a/libbe/vcs.py
+++ b/libbe/vcs.py
@@ -384,7 +384,7 @@ class VCS(object):
revision==None specifies the current revision.
Return the path to the arbitrary directory at the base of the new repo.
"""
- # Dirname in Baseir to protect against simlink attacks.
+ # Dirname in Basedir to protect against simlink attacks.
if self._duplicateBasedir == None:
self._duplicateBasedir = tempfile.mkdtemp(prefix='BEvcs')
self._duplicateDirname = \
@@ -456,10 +456,13 @@ class VCS(object):
if list_string in string:
return True
return False
- def _u_invoke(self, args, stdin=None, expect=(0,), cwd=None):
+ def _u_invoke(self, args, stdin=None, expect=(0,), cwd=None,
+ unicode_output=True):
"""
expect should be a tuple of allowed exit codes. cwd should be
- the directory from which the command will be executed.
+ the directory from which the command will be executed. When
+ unicode_output == True, convert stdout and stdin strings to
+ unicode before returing them.
"""
if cwd == None:
cwd = self.rootdir
@@ -474,20 +477,20 @@ class VCS(object):
shell=True, cwd=cwd)
except OSError, e :
raise CommandError(args, status=e.args[0], stdout="", stderr=e)
- output,error = q.communicate(input=stdin)
+ stdout,stderr = q.communicate(input=stdin)
status = q.wait()
+ if unicode_output == True:
+ stdout = unicode(stdout, self.encoding)
+ stderr = unicode(stderr, self.encoding)
if self.verboseInvoke == True:
- print >> sys.stderr, "%d\n%s%s" % (status, output, error)
+ print >> sys.stderr, "%d\n%s%s" % (status, stdout, stderr)
if status not in expect:
- raise CommandError(args, status, output, error)
- return status, output, error
+ raise CommandError(args, status, stdout, stderr)
+ return status, stdout, stderr
def _u_invoke_client(self, *args, **kwargs):
- directory = kwargs.get('directory',None)
- expect = kwargs.get('expect', (0,))
- stdin = kwargs.get('stdin', None)
cl_args = [self.client]
cl_args.extend(args)
- return self._u_invoke(cl_args, stdin=stdin,expect=expect,cwd=directory)
+ return self._u_invoke(cl_args, **kwargs)
def _u_search_parent_directories(self, path, filename):
"""
Find the file (or directory) named filename in path or in any
@@ -678,6 +681,7 @@ class VCSTestCase(unittest.TestCase):
def tearDown(self):
self.vcs.cleanup()
+ self.dir.cleanup()
super(VCSTestCase, self).tearDown()
def full_path(self, rel_path):