@@ -34,16 +34,14 @@ def maybe_string(ptr):
3434 if not ptr :
3535 return None
3636
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+
4139
42- def to_bytes (s , encoding = ' utf-8' , errors = ' strict' ):
40+ def to_bytes (s , encoding = " utf-8" , errors = " strict" ):
4341 if s == ffi .NULL or s is None :
4442 return ffi .NULL
4543
46- if hasattr (s , ' __fspath__' ):
44+ if hasattr (s , " __fspath__" ):
4745 s = os .fspath (s )
4846
4947 if isinstance (s , bytes ):
@@ -53,7 +51,7 @@ def to_bytes(s, encoding='utf-8', errors='strict'):
5351
5452
5553def to_str (s ):
56- if hasattr (s , ' __fspath__' ):
54+ if hasattr (s , " __fspath__" ):
5755 s = os .fspath (s )
5856
5957 if type (s ) is str :
@@ -71,13 +69,13 @@ def ptr_to_bytes(ptr_cdata):
7169 to a byte buffer containing the address that the pointer refers to.
7270 """
7371
74- pp = ffi .new (' void **' , ptr_cdata )
72+ pp = ffi .new (" void **" , ptr_cdata )
7573 return bytes (ffi .buffer (pp )[:])
7674
7775
7876@contextlib .contextmanager
7977def new_git_strarray ():
80- strarray = ffi .new (' git_strarray *' )
78+ strarray = ffi .new (" git_strarray *" )
8179 yield strarray
8280 C .git_strarray_dispose (strarray )
8381
@@ -90,7 +88,7 @@ def strarray_to_strings(arr):
9088 calling this function.
9189 """
9290 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 )]
9492 finally :
9593 C .git_strarray_dispose (arr )
9694
@@ -122,19 +120,19 @@ def __init__(self, l):
122120 return
123121
124122 if not isinstance (l , (list , tuple )):
125- raise TypeError (' Value must be a list' )
123+ raise TypeError (" Value must be a list" )
126124
127125 strings = [None ] * len (l )
128126 for i in range (len (l )):
129127 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" )
132130
133- strings [i ] = ffi .new (' char []' , to_bytes (li ))
131+ strings [i ] = ffi .new (" char []" , to_bytes (li ))
134132
135- self .__arr = ffi .new (' char *[]' , strings )
133+ self .__arr = ffi .new (" char *[]" , strings )
136134 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 )])
138136
139137 def __enter__ (self ):
140138 return self
0 commit comments