@@ -529,7 +529,6 @@ def gen_string_lipsumtobytes4(context: dict, value: str):
529
529
ints : List [Target ] = join_target (
530
530
sep = (LITERAL , "," ), targets = [(INTEGER , ord (c )) for c in value ]
531
531
)
532
- # TODO: rewrite it with GENERATED_EXPR
533
532
bytes_targets = targets_from_pattern (
534
533
"lipsum[GLOBALS][BUILTINS][BYTES]( ( INTS ) MAYBE_COMMA)[DECODE]( )" ,
535
534
{
@@ -579,6 +578,40 @@ def gen_string_lipsumtobytes5(context: dict, value: str):
579
578
] + [(REQUIRE_PYTHON3 ,)]
580
579
581
580
581
+ @expression_gen
582
+ def gen_string_undefinedtobytes (context : dict , value : str ):
583
+
584
+ bytes_targets = targets_from_pattern (
585
+ "UNDEFINED|attr( ADD )|attr( GLOBALS )|attr( GETITEM )( BUILTINS )"
586
+ "|attr( GETITEM )( BYTES )( ( INTS ) MAYBE_COMMA)|attr(DECODE)( )" ,
587
+ {
588
+ "UNDEFINED" : (ONEOF , [
589
+ [(LITERAL , "a" )],
590
+ [(LITERAL , "t" )],
591
+ [(LITERAL , "r" )],
592
+ [(LITERAL , "x" )],
593
+ ]),
594
+ "ADD" : (GENERATED_EXPR , (STRING , "__add__" )),
595
+ "GLOBALS" : (GENERATED_EXPR , (STRING , "__globals__" )),
596
+ "GETITEM" : (GENERATED_EXPR , (STRING , "__getitem__" )),
597
+ "BUILTINS" : (GENERATED_EXPR , (STRING , "__builtins__" )),
598
+ "BYTES" : (GENERATED_EXPR , (STRING , "bytes" )),
599
+ " " : (WHITESPACE ,),
600
+ "INTS" : join_target (
601
+ sep = (LITERAL , "," ), targets = [(INTEGER , ord (c )) for c in value ]
602
+ ),
603
+ "MAYBE_COMMA" : (ONEOF , [[(LITERAL , "," )], [(LITERAL , "" )]]),
604
+ "DECODE" : (GENERATED_EXPR , (STRING , "decode" )),
605
+ },
606
+ )
607
+ return [
608
+ (
609
+ EXPRESSION ,
610
+ precedence ["function_call" ],
611
+ bytes_targets ,
612
+ )
613
+ ] + [(REQUIRE_PYTHON3 ,)]
614
+
582
615
@expression_gen
583
616
def gen_string_formatpercent1 (context : dict , value : str ):
584
617
# (('%c'*n)%(97,98,99))
0 commit comments