@@ -82,8 +82,10 @@ def _extract(self, parsed, nest=None):
82
82
83
83
if self .name == "STRUCTURED_JSON" :
84
84
try :
85
- (string_value , _ ), = value .find_children (self .STRING_KEY )
86
- except :
85
+ (string_value , _ ), = value .find_children (
86
+ self .STRING_KEY
87
+ )
88
+ except Exception :
87
89
# Ignore other types of values like lists
88
90
pass
89
91
else :
@@ -284,7 +286,8 @@ def _insert_item(self, value, value_position, is_real_stringset):
284
286
value_position + len (value ) + 1
285
287
)
286
288
else :
287
- # value is an empty string, add the key but don't update stringset_index
289
+ # value is an empty string, add the key but don't update
290
+ # stringset_index
288
291
at_least_one = True
289
292
self ._insert_regular_string (
290
293
value , value_position , '' , False
@@ -306,7 +309,7 @@ def _insert_item(self, value, value_position, is_real_stringset):
306
309
return at_least_one
307
310
308
311
def _insert_from_dict (self , parsed , is_real_stringset ):
309
- at_least_one = False
312
+ at_least_one = not bool ( list ( parsed ))
310
313
311
314
for key , key_position , value , value_position in parsed :
312
315
@@ -323,7 +326,7 @@ def _insert_from_dict(self, parsed, is_real_stringset):
323
326
return at_least_one
324
327
325
328
def _insert_from_list (self , parsed , is_real_stringset ):
326
- at_least_one = False
329
+ at_least_one = not bool ( list ( parsed ))
327
330
328
331
for value , value_position in parsed :
329
332
self .transcriber .copy_until (value_position - 1 )
@@ -512,7 +515,9 @@ def _compile_value(self, value, template_value, value_position):
512
515
else :
513
516
self .transcriber .add (u"null" )
514
517
self .transcriber .skip (len (u"{}" .format (template_value )))
515
- self .transcriber .copy_until (value_position + len (u"{}" .format (template_value )) + 1 )
518
+ self .transcriber .copy_until (value_position +
519
+ len (u"{}" .format (template_value )) +
520
+ 1 )
516
521
517
522
def _compile_recursively (self , current_part ):
518
523
if isinstance (current_part , DumbJson ):
@@ -522,7 +527,8 @@ def _compile_recursively(self, current_part):
522
527
if current_part .type == dict :
523
528
(value , _ ) = current_part .find_children (self .STRING_KEY )[0 ]
524
529
if not value :
525
- for key , key_position , value , value_position in current_part :
530
+ for (key , key_position , value ,
531
+ value_position ) in current_part :
526
532
self .transcriber .copy_until (key_position - 1 )
527
533
self .transcriber .copy_until (value_position )
528
534
self ._compile_recursively (value )
@@ -534,46 +540,85 @@ def _compile_recursively(self, current_part):
534
540
535
541
line_separator = None
536
542
key_value_separator = None
537
- for key , key_position , value , value_position in current_part :
543
+ for (key , key_position , value ,
544
+ value_position ) in current_part :
538
545
prev_position_end = self .transcriber .ptr
539
- line_separator = current_part .source [prev_position_end + 1 :key_position - 1 ]
540
- key_value_separator = current_part .source [key_position + len (key ):value_position - 1 ]
546
+ line_separator = current_part .source [
547
+ prev_position_end + 1 :key_position - 1
548
+ ]
549
+ key_value_separator = current_part .source [
550
+ key_position + len (key ):value_position - 1
551
+ ]
541
552
self .transcriber .copy_until (key_position - 1 )
542
553
self .transcriber .copy_until (value_position )
543
554
if key == self .CONTEXT_KEY and translation :
544
555
context = translation .context
545
- self ._compile_value (self .escape (context ), value , value_position )
556
+ self ._compile_value (self .escape (context ),
557
+ value ,
558
+ value_position )
546
559
context_added = True
547
560
elif key == self .DEVELOPER_COMMENT_KEY and translation :
548
561
developer_comment = translation .developer_comment
549
- self ._compile_value (self .escape (developer_comment ), value , value_position )
562
+ self ._compile_value (self .escape (developer_comment ),
563
+ value ,
564
+ value_position )
550
565
developer_comments_added = True
551
566
elif key == self .CHARACTER_LIMIT_KEY and translation :
552
567
character_limit = translation .character_limit
553
- self ._compile_value (character_limit , value , value_position )
568
+ self ._compile_value (character_limit ,
569
+ value ,
570
+ value_position )
554
571
character_limit_added = True
555
572
elif key == self .STRING_KEY and translation :
556
573
if translation .pluralized :
557
- string_replacement = ICUCompiler ().serialize_strings (translation .string , delimiter = ' ' )
558
- string_replacement = value .replace (translation .template_replacement , string_replacement )
574
+ string_replacement = ICUCompiler ().\
575
+ serialize_strings (translation .string ,
576
+ delimiter = ' ' )
577
+ string_replacement = value .replace (
578
+ translation .template_replacement ,
579
+ string_replacement ,
580
+ )
559
581
else :
560
582
string_replacement = translation .string
561
- self ._compile_value (string_replacement , value , value_position )
583
+ self ._compile_value (string_replacement ,
584
+ value ,
585
+ value_position )
562
586
elif not isinstance (value , DumbJson ):
563
- self .transcriber .copy_until (value_position + len (u"{}" .format (value )) + 1 )
587
+ self .transcriber .copy_until (
588
+ value_position + len (u"{}" .format (value )) + 1
589
+ )
564
590
565
591
extra_elements = []
566
- if not context_added and translation and translation .context :
592
+ if (not context_added and
593
+ translation and
594
+ translation .context ):
567
595
extra_elements .append (u"\" {}{}\" {}\" " .format (
568
- "context" , key_value_separator , self .escape (translation .context )))
569
- if not character_limit_added and translation and translation .character_limit :
596
+ "context" ,
597
+ key_value_separator ,
598
+ self .escape (translation .context ),
599
+ ))
600
+ if (not character_limit_added and
601
+ translation and
602
+ translation .character_limit ):
570
603
extra_elements .append (u"\" {}{}{}" .format (
571
- "character_limit" , key_value_separator , translation .character_limit ))
572
- if not developer_comments_added and translation and translation .developer_comment :
604
+ "character_limit" ,
605
+ key_value_separator ,
606
+ translation .character_limit ,
607
+ ))
608
+ if (not developer_comments_added and
609
+ translation and
610
+ translation .developer_comment ):
573
611
extra_elements .append (u"\" {}{}\" {}\" " .format (
574
- "developer_comment" , key_value_separator , self .escape (translation .developer_comment )))
612
+ "developer_comment" ,
613
+ key_value_separator ,
614
+ self .escape (translation .developer_comment ),
615
+ ))
575
616
if extra_elements :
576
- self .transcriber .add ("," + line_separator + ("," + line_separator ).join (extra_elements ))
617
+ self .transcriber .add (
618
+ "," +
619
+ line_separator +
620
+ ("," + line_separator ).join (extra_elements )
621
+ )
577
622
578
623
def _create_openstring (self , key , payload_dict ):
579
624
"""Return a new OpenString based on the given key and payload_dict
@@ -644,7 +689,9 @@ def _create_regular_string(self, key, payload_dict):
644
689
:param value: the translation string
645
690
:return: an OpenString or None
646
691
"""
647
- (string_value , string_position ), = payload_dict .find_children (self .STRING_KEY )
692
+ (string_value , string_position ), = payload_dict .find_children (
693
+ self .STRING_KEY
694
+ )
648
695
payload_dict = json .loads (
649
696
payload_dict .source [payload_dict .start :payload_dict .end + 1 ])
650
697
comment_value = payload_dict .get (self .DEVELOPER_COMMENT_KEY )
0 commit comments