#NEWLINE# def number( self , num ) : #NEWLINE# #INDENT# 'Parse a string containing a label or number into an address.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# if num . startswith ( '$' ) : #NEWLINE# #INDENT# return self . _constrain ( int ( num [ 1 : ] , 16 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if num . startswith ( '+' ) : #NEWLINE# #INDENT# return self . _constrain ( int ( num [ 1 : ] , 10 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if num . startswith ( '%' ) : #NEWLINE# #INDENT# return self . _constrain ( int ( num [ 1 : ] , 2 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num in self . labels ) : #NEWLINE# #INDENT# return self . labels [ num ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# matches = re . match ( '^([^\\s+-]+)\\s*([+\\-])\\s*([$+%]?\\d+)$' , num ) #NEWLINE# if matches : #NEWLINE# #INDENT# ( label , sign , offset ) = matches . groups ( ) #NEWLINE# if ( label not in self . labels ) : #NEWLINE# #INDENT# raise KeyError ( ( 'Label not found: %s' % label ) ) #NEWLINE# #UNINDENT# base = self . labels [ label ] #NEWLINE# offset = self . number ( offset ) #NEWLINE# if ( sign == '+' ) : #NEWLINE# #INDENT# address = ( base + offset ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# address = ( base - offset ) #NEWLINE# #UNINDENT# return self . _constrain ( address ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . _constrain ( int ( num , self . radix ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise KeyError ( ( 'Label not found: %s' % num ) )