#NEWLINE# @ internationalizeDocstring #NEWLINE# def calc( self , irc , msg , args , text ) : #NEWLINE# #INDENT# "<math expression>\n\n        Returns the value of the evaluated <math expression>.  The syntax is\n        Python syntax; the type of arithmetic is floating point.  Floating\n        point arithmetic is used in order to prevent a user from being able to\n        crash to the bot with something like '10**10**10**10'.  One consequence\n        is that large values such as '10**24' might not be exact.\n        " #NEWLINE# try : #NEWLINE# #INDENT# text = str ( text ) #NEWLINE# #UNINDENT# except UnicodeEncodeError : #NEWLINE# #INDENT# irc . error ( _ ( "There's no reason you should have fancy non-ASCII characters in your mathematical expression. Please remove them." ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if self . _calc_match_forbidden_chars . match ( text ) : #NEWLINE# #INDENT# irc . error ( _ ( "There's really no reason why you should have underscores or brackets in your mathematical expression.  Please remove them." ) ) #NEWLINE# return #NEWLINE# #UNINDENT# text = self . _calc_remover ( msg ) #NEWLINE# if ( 'lambda' in text ) : #NEWLINE# #INDENT# irc . error ( _ ( "You can't use lambda in this command." ) ) #NEWLINE# return #NEWLINE# #UNINDENT# text = text . lower ( ) #NEWLINE# def handleMatch( m ) : #NEWLINE# #INDENT# s = m . group ( 1 ) #NEWLINE# if s . startswith ( '0x' ) : #NEWLINE# #INDENT# i = int ( s , 16 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( s . startswith ( '0' ) and ( '.' not in s ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# i = int ( s , 8 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# i = int ( s ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# i = float ( s ) #NEWLINE# #UNINDENT# #UNINDENT# x = complex ( i ) #NEWLINE# if ( x . imag == 0 ) : #NEWLINE# #INDENT# x = x . real #NEWLINE# return ( '%.16f' % x ) #NEWLINE# #UNINDENT# return str ( x ) #NEWLINE# #UNINDENT# text = self . _mathRe . sub ( handleMatch , text ) #NEWLINE# try : #NEWLINE# #INDENT# self . log . info ( 'evaluating %q from %s' , text , msg . prefix ) #NEWLINE# x = complex ( eval ( text , self . _mathSafeEnv , self . _mathSafeEnv ) ) #NEWLINE# irc . reply ( self . _complexToString ( x ) ) #NEWLINE# #UNINDENT# except OverflowError : #NEWLINE# #INDENT# maxFloat = math . ldexp ( 0.9999999999999999 , 1024 ) #NEWLINE# irc . error ( ( _ ( 'The answer exceeded %s or so.' ) % maxFloat ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# irc . error ( _ ( "Something in there wasn't a valid number." ) ) #NEWLINE# #UNINDENT# except NameError as e : #NEWLINE# #INDENT# irc . error ( ( _ ( '%s is not a defined function.' ) % str ( e ) . split ( ) [ 1 ] ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# irc . error ( str ( e ) )