<s> r"""<STR_LIT>""" <EOL> from . . pgen2 import token <EOL> from . . import fixer_base <EOL> _mapping = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:str>" } <EOL> class FixUnicode ( fixer_base . BaseFix ) : <EOL> BM_compatible = True <EOL> PATTERN = "<STR_LIT>" <EOL> def start_tree ( self , tree , filename ) : <EOL> super ( FixUnicode , self ) . start_tree ( tree , filename ) <EOL> self . unicode_literals = '<STR_LIT>' in tree . future_features <EOL> def transform ( self , node , results ) : <EOL> if node . type == token . NAME : <EOL> new = node . clone ( ) <EOL> new . value = _mapping [ node . value ] <EOL> return new <EOL> elif node . type == token . STRING : <EOL> val = node . value <EOL> if not self . unicode_literals and val [ <NUM_LIT:0> ] in '<STR_LIT>' and '<STR_LIT:\\>' in val : <EOL> val = r'<STR_LIT:\\>' . join ( [ <EOL> v . replace ( '<STR_LIT>' , r'<STR_LIT>' ) . replace ( '<STR_LIT>' , r'<STR_LIT>' ) <EOL> for v in val . split ( r'<STR_LIT:\\>' ) <EOL> ] ) <EOL> if val [ <NUM_LIT:0> ] in '<STR_LIT>' : <EOL> val = val [ <NUM_LIT:1> : ] <EOL> if val == node . value : <EOL> return node <EOL> new = node . clone ( ) <EOL> new . value = val <EOL> return new </s>
