@@ -34,16 +34,14 @@ def maybe_string(ptr):
34
34
if not ptr :
35
35
return None
36
36
37
- try :
38
- return ffi .string (ptr ).decode ('utf8' )
39
- except UnicodeDecodeError :
40
- return ffi .string (ptr )
37
+ return ffi .string (ptr ).decode ("utf8" , errors = "surrogateescape" )
38
+
41
39
42
- def to_bytes (s , encoding = ' utf-8' , errors = ' strict' ):
40
+ def to_bytes (s , encoding = " utf-8" , errors = " strict" ):
43
41
if s == ffi .NULL or s is None :
44
42
return ffi .NULL
45
43
46
- if hasattr (s , ' __fspath__' ):
44
+ if hasattr (s , " __fspath__" ):
47
45
s = os .fspath (s )
48
46
49
47
if isinstance (s , bytes ):
@@ -53,7 +51,7 @@ def to_bytes(s, encoding='utf-8', errors='strict'):
53
51
54
52
55
53
def to_str (s ):
56
- if hasattr (s , ' __fspath__' ):
54
+ if hasattr (s , " __fspath__" ):
57
55
s = os .fspath (s )
58
56
59
57
if type (s ) is str :
@@ -71,13 +69,13 @@ def ptr_to_bytes(ptr_cdata):
71
69
to a byte buffer containing the address that the pointer refers to.
72
70
"""
73
71
74
- pp = ffi .new (' void **' , ptr_cdata )
72
+ pp = ffi .new (" void **" , ptr_cdata )
75
73
return bytes (ffi .buffer (pp )[:])
76
74
77
75
78
76
@contextlib .contextmanager
79
77
def new_git_strarray ():
80
- strarray = ffi .new (' git_strarray *' )
78
+ strarray = ffi .new (" git_strarray *" )
81
79
yield strarray
82
80
C .git_strarray_dispose (strarray )
83
81
@@ -90,7 +88,7 @@ def strarray_to_strings(arr):
90
88
calling this function.
91
89
"""
92
90
try :
93
- return [ffi .string (arr .strings [i ]).decode (' utf-8' ) for i in range (arr .count )]
91
+ return [ffi .string (arr .strings [i ]).decode (" utf-8" ) for i in range (arr .count )]
94
92
finally :
95
93
C .git_strarray_dispose (arr )
96
94
@@ -122,19 +120,19 @@ def __init__(self, l):
122
120
return
123
121
124
122
if not isinstance (l , (list , tuple )):
125
- raise TypeError (' Value must be a list' )
123
+ raise TypeError (" Value must be a list" )
126
124
127
125
strings = [None ] * len (l )
128
126
for i in range (len (l )):
129
127
li = l [i ]
130
- if not isinstance (li , str ) and not hasattr (li , ' __fspath__' ):
131
- raise TypeError (' Value must be a string or PathLike object' )
128
+ if not isinstance (li , str ) and not hasattr (li , " __fspath__" ):
129
+ raise TypeError (" Value must be a string or PathLike object" )
132
130
133
- strings [i ] = ffi .new (' char []' , to_bytes (li ))
131
+ strings [i ] = ffi .new (" char []" , to_bytes (li ))
134
132
135
- self .__arr = ffi .new (' char *[]' , strings )
133
+ self .__arr = ffi .new (" char *[]" , strings )
136
134
self .__strings = strings
137
- self .__array = ffi .new (' git_strarray *' , [self .__arr , len (strings )])
135
+ self .__array = ffi .new (" git_strarray *" , [self .__arr , len (strings )])
138
136
139
137
def __enter__ (self ):
140
138
return self
0 commit comments