@@ -187,7 +187,7 @@ def message_to_ordereddict(
187
187
value = getattr (msg , field_name , None )
188
188
value = _convert_value (
189
189
value , field_type = field_type ,
190
- truncate_len = truncate_length , no_arr = no_arr , no_str = no_str )
190
+ truncate_length = truncate_length , no_arr = no_arr , no_str = no_str )
191
191
d [field_name ] = value
192
192
return d
193
193
@@ -196,54 +196,54 @@ def _convert_value(
196
196
value ,
197
197
* ,
198
198
field_type = None ,
199
- truncate_len = None ,
199
+ truncate_length = None ,
200
200
no_arr = False ,
201
201
no_str = False
202
202
):
203
203
204
204
if isinstance (value , bytes ):
205
- if truncate_len is not None and len (value ) > truncate_len :
206
- value = '' .join ([chr (c ) for c in value [:truncate_len ]]) + '...'
205
+ if truncate_length is not None and len (value ) > truncate_length :
206
+ value = '' .join ([chr (c ) for c in value [:truncate_length ]]) + '...'
207
207
else :
208
208
value = '' .join ([chr (c ) for c in value ])
209
209
elif isinstance (value , str ):
210
210
if no_str is True :
211
211
value = '<string length: <{0}>>' .format (len (value ))
212
- elif truncate_len is not None and len (value ) > truncate_len :
213
- value = value [:truncate_len ] + '...'
214
- elif isinstance (value , (array .array , numpy .ndarray )) and not no_arr and truncate_len is None :
212
+ elif truncate_length is not None and len (value ) > truncate_length :
213
+ value = value [:truncate_length ] + '...'
214
+ elif isinstance (value , (array .array , numpy .ndarray )) and not no_arr and truncate_length is None :
215
215
value = value .tolist ()
216
216
elif isinstance (value , (list , tuple , array .array , numpy .ndarray )):
217
217
# Since arrays and ndarrays can't contain mixed types convert to list
218
218
typename = tuple if isinstance (value , tuple ) else list
219
219
if no_arr is True and field_type is not None :
220
220
value = __abbreviate_array_info (value , field_type )
221
- elif truncate_len is not None and len (value ) > truncate_len :
221
+ elif truncate_length is not None and len (value ) > truncate_length :
222
222
# Truncate the sequence
223
- value = value [:truncate_len ]
223
+ value = value [:truncate_length ]
224
224
# Truncate every item in the sequence
225
225
value = typename (
226
- [_convert_value (v , truncate_len = truncate_len ,
226
+ [_convert_value (v , truncate_length = truncate_length ,
227
227
no_arr = no_arr , no_str = no_str ) for v in value ] + ['...' ])
228
228
else :
229
229
# Truncate every item in the list
230
230
value = typename (
231
- [_convert_value (v , truncate_len = truncate_len ,
231
+ [_convert_value (v , truncate_length = truncate_length ,
232
232
no_arr = no_arr , no_str = no_str ) for v in value ])
233
233
elif isinstance (value , dict ) or isinstance (value , OrderedDict ):
234
234
# Convert each key and value in the mapping
235
235
new_value = {} if isinstance (value , dict ) else OrderedDict ()
236
236
for k , v in value .items ():
237
237
# Don't truncate keys because that could result in key collisions and data loss
238
238
new_value [_convert_value (k )] = _convert_value (
239
- v , truncate_len = truncate_len , no_arr = no_arr , no_str = no_str )
239
+ v , truncate_length = truncate_length , no_arr = no_arr , no_str = no_str )
240
240
value = new_value
241
241
elif isinstance (value , numpy .number ):
242
242
value = value .item ()
243
243
elif not isinstance (value , (bool , float , int )):
244
244
# Assuming value is a message since it is neither a collection nor a primitive type
245
245
value = message_to_ordereddict (
246
- value , truncate_length = truncate_len , no_arr = no_arr , no_str = no_str )
246
+ value , truncate_length = truncate_length , no_arr = no_arr , no_str = no_str )
247
247
return value
248
248
249
249
0 commit comments