@@ -33,7 +33,8 @@ def _bytes_from_decode_data(s):
33
33
if isinstance (s , str ):
34
34
try :
35
35
return s .encode ('ascii' )
36
- except UnicodeEncodeError :
36
+ # except UnicodeEncodeError:
37
+ except :
37
38
raise ValueError ('string argument should contain only ASCII characters' )
38
39
elif isinstance (s , bytes_types ):
39
40
return s
@@ -109,8 +110,8 @@ def standard_b64decode(s):
109
110
return b64decode (s )
110
111
111
112
112
- _urlsafe_encode_translation = bytes .maketrans (b'+/' , b'-_' )
113
- _urlsafe_decode_translation = bytes .maketrans (b'-_' , b'+/' )
113
+ # _urlsafe_encode_translation = bytes.maketrans(b'+/', b'-_')
114
+ # _urlsafe_decode_translation = bytes.maketrans(b'-_', b'+/')
114
115
115
116
def urlsafe_b64encode (s ):
116
117
"""Encode a byte string using a url-safe Base64 alphabet.
@@ -119,7 +120,8 @@ def urlsafe_b64encode(s):
119
120
returned. The alphabet uses '-' instead of '+' and '_' instead of
120
121
'/'.
121
122
"""
122
- return b64encode (s ).translate (_urlsafe_encode_translation )
123
+ # return b64encode(s).translate(_urlsafe_encode_translation)
124
+ raise NotImplementedError ()
123
125
124
126
def urlsafe_b64decode (s ):
125
127
"""Decode a byte string encoded with the standard Base64 alphabet.
@@ -131,9 +133,10 @@ def urlsafe_b64decode(s):
131
133
132
134
The alphabet uses '-' instead of '+' and '_' instead of '/'.
133
135
"""
134
- s = _bytes_from_decode_data (s )
135
- s = s .translate (_urlsafe_decode_translation )
136
- return b64decode (s )
136
+ # s = _bytes_from_decode_data(s)
137
+ # s = s.translate(_urlsafe_decode_translation)
138
+ # return b64decode(s)
139
+ raise NotImplementedError ()
137
140
138
141
139
142
@@ -187,13 +190,13 @@ def b32encode(s):
187
190
])
188
191
# Adjust for any leftover partial quanta
189
192
if leftover == 1 :
190
- encoded [ - 6 :] = b'======'
193
+ encoded = encoded [: - 6 ] + b'======'
191
194
elif leftover == 2 :
192
- encoded [ - 4 :] = b'===='
195
+ encoded = encoded [: - 4 ] + b'===='
193
196
elif leftover == 3 :
194
- encoded [ - 3 :] = b'==='
197
+ encoded = encoded [: - 3 ] + b'==='
195
198
elif leftover == 4 :
196
- encoded [ - 1 :] = b'='
199
+ encoded = encoded [: - 1 ] + b'='
197
200
return bytes (encoded )
198
201
199
202
@@ -232,12 +235,13 @@ def b32decode(s, casefold=False, map01=None):
232
235
# Strip off pad characters from the right. We need to count the pad
233
236
# characters because this will tell us how many null bytes to remove from
234
237
# the end of the decoded string.
235
- padchars = 0
236
- mo = re .search (b'(?P<pad>[=]*)$' , s )
237
- if mo :
238
- padchars = len (mo .group ('pad' ))
239
- if padchars > 0 :
240
- s = s [:- padchars ]
238
+ padchars = s .find (b'=' )
239
+ if padchars > 0 :
240
+ padchars = len (s ) - padchars
241
+ s = s [:- padchars ]
242
+ else :
243
+ padchars = 0
244
+
241
245
# Now decode the full quanta
242
246
parts = []
243
247
acc = 0
0 commit comments