<s> import re <EOL> from . . errors import log <EOL> warn = log . warning <EOL> class BasePdfName ( str ) : <EOL> '''<STR_LIT>''' <EOL> indirect = False <EOL> whitespace = '<STR_LIT>' <EOL> delimiters = '<STR_LIT>' <EOL> forbidden = list ( whitespace ) + list ( '<STR_LIT:\\>' + x for x in delimiters ) <EOL> remap = dict ( ( x , '<STR_LIT>' % ord ( x ) ) for x in ( whitespace + delimiters ) ) <EOL> split_to_encode = re . compile ( '<STR_LIT>' % '<STR_LIT:|>' . join ( forbidden ) ) . split <EOL> split_to_decode = re . compile ( r'<STR_LIT>' ) . split <EOL> def __new__ ( cls , name , pre_encoded = True , remap = remap , <EOL> join = '<STR_LIT>' . join , new = str . __new__ , chr = chr , int = int , <EOL> split_to_encode = split_to_encode , <EOL> split_to_decode = split_to_decode , <EOL> ) : <EOL> '''<STR_LIT>''' <EOL> if name [ <NUM_LIT:1> : ] . isalnum ( ) : <EOL> return new ( cls , name ) <EOL> encoded = name <EOL> if pre_encoded : <EOL> if '<STR_LIT:#>' in name : <EOL> substrs = split_to_decode ( name ) <EOL> substrs [ <NUM_LIT:1> : : <NUM_LIT:2> ] = ( chr ( int ( x , <NUM_LIT:16> ) ) for x in substrs [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) <EOL> name = join ( substrs ) <EOL> else : <EOL> encoded = split_to_encode ( encoded ) <EOL> encoded [ <NUM_LIT:3> : : <NUM_LIT:2> ] = ( remap [ x ] for x in encoded [ <NUM_LIT:3> : : <NUM_LIT:2> ] ) <EOL> encoded = join ( encoded ) <EOL> self = new ( cls , name ) <EOL> if encoded != name : <EOL> self . encoded = encoded <EOL> return self <EOL> class PdfName ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __getattr__ ( self , name , BasePdfName = BasePdfName ) : <EOL> return BasePdfName ( '<STR_LIT:/>' + name , False ) <EOL> def __call__ ( self , name , BasePdfName = BasePdfName ) : <EOL> return BasePdfName ( '<STR_LIT:/>' + name , False ) <EOL> PdfName = PdfName ( ) </s>
