Skip to content

Commit 7519415

Browse files
committed
Merge pull request #175 from craigez/feature/handle_utf8
Handling unicode arguments
2 parents 22a2103 + 8fa25b1 commit 7519415

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

‎git/cmd.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,16 @@ def transform_kwargs(self, **kwargs):
426426
@classmethod
427427
def__unpack_args(cls, arg_list):
428428
ifnotisinstance(arg_list, (list,tuple)):
429+
ifisinstance(arg_list, unicode):
430+
return [arg_list.encode('utf-8')]
429431
return [ str(arg_list) ]
430432

431433
outlist=list()
432434
forarginarg_list:
433435
ifisinstance(arg_list, (list, tuple)):
434436
outlist.extend(cls.__unpack_args( arg ))
437+
elifisinstance(arg_list, unicode):
438+
outlist.append(arg_list.encode('utf-8'))
435439
# END recursion
436440
else:
437441
outlist.append(str(arg))

‎git/test/test_cmd.py‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
importos, sys
88
fromgit.test.libimport (
9-
TestBase,
10-
patch,
9+
TestBase,
10+
patch,
1111
raises,
1212
assert_equal,
1313
assert_true,
@@ -17,7 +17,7 @@
1717
fromgitimportGit, GitCommandError
1818

1919
classTestGit(TestBase):
20-
20+
2121
@classmethod
2222
defsetUp(cls):
2323
super(TestGit, cls).setUp()
@@ -30,6 +30,14 @@ def test_call_process_calls_execute(self, git):
3030
assert_true(git.called)
3131
assert_equal(git.call_args, ((['git', 'version'],),{}))
3232

33+
deftest_call_unpack_args_unicode(self):
34+
args=Git._Git__unpack_args(u'Unicode'+unichr(40960))
35+
assert_equal(args, ['Unicode\xea\x80\x80'])
36+
37+
deftest_call_unpack_args(self):
38+
args=Git._Git__unpack_args(['git', 'log', '--', u'Unicode'+unichr(40960)])
39+
assert_equal(args, ['git', 'log', '--', 'Unicode\xea\x80\x80'])
40+
3341
@raises(GitCommandError)
3442
deftest_it_raises_errors(self):
3543
self.git.this_does_not_exist()
@@ -59,7 +67,7 @@ def test_it_ignores_false_kwargs(self, git):
5967
# this_should_not_be_ignored=False implies it *should* be ignored
6068
output=self.git.version(pass_this_kwarg=False)
6169
assert_true("pass_this_kwarg"notingit.call_args[1])
62-
70+
6371
deftest_persistent_cat_file_command(self):
6472
# read header only
6573
importsubprocessassp
@@ -68,37 +76,37 @@ def test_persistent_cat_file_command(self):
6876
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
6977
g.stdin.flush()
7078
obj_info=g.stdout.readline()
71-
79+
7280
# read header + data
7381
g=self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
7482
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
7583
g.stdin.flush()
7684
obj_info_two=g.stdout.readline()
7785
assertobj_info==obj_info_two
78-
86+
7987
# read data - have to read it in one large chunk
8088
size=int(obj_info.split()[2])
8189
data=g.stdout.read(size)
8290
terminating_newline=g.stdout.read(1)
83-
91+
8492
# now we should be able to read a new object
8593
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
8694
g.stdin.flush()
8795
assertg.stdout.readline() ==obj_info
88-
89-
96+
97+
9098
# same can be achived using the respective command functions
9199
hexsha, typename, size=self.git.get_object_header(hexsha)
92100
hexsha, typename_two, size_two, data=self.git.get_object_data(hexsha)
93101
asserttypename==typename_twoandsize==size_two
94-
102+
95103
deftest_version(self):
96104
v=self.git.version_info
97105
assertisinstance(v, tuple)
98106
forninv:
99107
assertisinstance(n, int)
100108
#END verify number types
101-
109+
102110
deftest_cmd_override(self):
103111
prev_cmd=self.git.GIT_PYTHON_GIT_EXECUTABLE
104112
try:
@@ -108,7 +116,7 @@ def test_cmd_override(self):
108116
finally:
109117
type(self.git).GIT_PYTHON_GIT_EXECUTABLE=prev_cmd
110118
#END undo adjustment
111-
119+
112120
deftest_output_strip(self):
113121
importsubprocessassp
114122
hexsha="b2339455342180c7cc1e9bba3e9f181f7baa5167"

0 commit comments

Comments
(0)