rem
stringlengths
1
322k
add
stringlengths
0
2.05M
context
stringlengths
4
228k
meta
stringlengths
156
215
exts.append( Extension('syslog', ['syslogmodule.c']) )
if platform not in ['mac']: exts.append( Extension('syslog', ['syslogmodule.c']) )
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
081563166713aac056a0230633f21a332e43c91d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/081563166713aac056a0230633f21a332e43c91d/setup.py
if self.compiler.find_library_file(lib_dirs, 'crypt'): libs = ['crypt'] else: libs = [] exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
if platform not in ['mac']: if self.compiler.find_library_file(lib_dirs, 'crypt'): libs = ['crypt'] else: libs = [] exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
081563166713aac056a0230633f21a332e43c91d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/081563166713aac056a0230633f21a332e43c91d/setup.py
if platform not in ['cygwin']:
if platform not in ['cygwin', 'mac']:
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
081563166713aac056a0230633f21a332e43c91d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/081563166713aac056a0230633f21a332e43c91d/setup.py
def gather(self): "Collect and return the contents of the window." result = "" for y in range(self.maxy+1): self.win.move(y, 0) stop = self._end_of_line(y) #sys.stderr.write("y=%d, _end_of_line(y)=%d\n" % (y, stop)) if stop == 0 and self.stripspaces: continue for x in range(self.maxx+1): if self.stripspaces and x == stop: break result = result + chr(ascii.ascii(self.win.inch(y, x))) if self.maxy > 0: result = result + "\n" return result
4e0822c78f0c552b758ad2c47c9cea1ae11d004e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/4e0822c78f0c552b758ad2c47c9cea1ae11d004e/textpad.py
filename = EasyDialogs.AskFileForOpen(message='Select file with aeut/aete resource:')
filename = EasyDialogs.AskFileForOpen( message='Select scriptable application', dialogOptionFlags=0x1056)
def main(): if len(sys.argv) > 1: for filename in sys.argv[1:]: processfile(filename) else: filename = EasyDialogs.AskFileForOpen(message='Select file with aeut/aete resource:') if not filename: sys.exit(0) processfile(filename)
969a896ab1c25fc9716f058d85ea6a0c44ea463a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/969a896ab1c25fc9716f058d85ea6a0c44ea463a/gensuitemodule.py
processfile(filename) def processfile(fullname):
try: processfile(filename) except MacOS.Error, arg: print "Error getting terminology:", arg print "Retry, manually parsing resources" processfile_fromresource(filename) def processfile_fromresource(fullname):
def main(): if len(sys.argv) > 1: for filename in sys.argv[1:]: processfile(filename) else: filename = EasyDialogs.AskFileForOpen(message='Select file with aeut/aete resource:') if not filename: sys.exit(0) processfile(filename)
969a896ab1c25fc9716f058d85ea6a0c44ea463a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/969a896ab1c25fc9716f058d85ea6a0c44ea463a/gensuitemodule.py
defaultLocation=DEFAULT_PACKAGEFOLDER)
defaultLocation=DEFAULT_USER_PACKAGEFOLDER)
def compileaete(aete, resinfo, fname): """Generate code for a full aete resource. fname passed for doc purposes""" [version, language, script, suites] = aete major, minor = divmod(version, 256) creatorsignature, dummy = MacOS.GetCreatorAndType(fname) packagename = identify(os.path.splitext(os.path.basename(fname))[0]) if language: packagename = packagename+'_lang%d'%language if script: packagename = packagename+'_script%d'%script if len(packagename) > 27: packagename = packagename[:27] pathname = EasyDialogs.AskFolder(message='Create and select package folder for %s'%packagename, defaultLocation=DEFAULT_PACKAGEFOLDER) if not pathname: return packagename = os.path.split(os.path.normpath(pathname))[1] basepkgname = EasyDialogs.AskFolder(message='Package folder for base suite (usually StdSuites)', defaultLocation=DEFAULT_PACKAGEFOLDER) if basepkgname: dirname, basepkgname = os.path.split(os.path.normpath(basepkgname)) if not dirname in sys.path: sys.path.insert(0, dirname) basepackage = __import__(basepkgname) else: basepackage = None suitelist = [] allprecompinfo = [] allsuites = [] for suite in suites: code, suite, pathname, modname, precompinfo = precompilesuite(suite, basepackage) if not code: continue allprecompinfo = allprecompinfo + precompinfo suiteinfo = suite, pathname, modname suitelist.append((code, modname)) allsuites.append(suiteinfo) for suiteinfo in allsuites: compilesuite(suiteinfo, major, minor, language, script, fname, basepackage, allprecompinfo) initfilename = EasyDialogs.AskFileForSave(message='Package module', savedFileName='__init__.py') if not initfilename: return fp = open(initfilename, 'w') MacOS.SetCreatorAndType(initfilename, 'Pyth', 'TEXT') fp.write('"""\n') fp.write("Package generated from %s\n"%fname) if resinfo: fp.write("Resource %s resid %d %s\n"%(ascii(resinfo[1]), resinfo[0], ascii(resinfo[2]))) fp.write('"""\n') fp.write('import aetools\n') fp.write('Error = aetools.Error\n') for code, modname in suitelist: fp.write("import %s\n" % modname) fp.write("\n\n_code_to_module = {\n") for code, modname in suitelist: fp.write("\t'%s' : %s,\n"%(ascii(code), modname)) fp.write("}\n\n") fp.write("\n\n_code_to_fullname = {\n") for code, modname in suitelist: fp.write("\t'%s' : ('%s.%s', '%s'),\n"%(ascii(code), packagename, modname, modname)) fp.write("}\n\n") for code, modname in suitelist: fp.write("from %s import *\n"%modname) # Generate property dicts and element dicts for all types declared in this module fp.write("def getbaseclasses(v):\n") fp.write("\tif hasattr(v, '_superclassnames') and not hasattr(v, '_propdict'):\n") fp.write("\t\tv._propdict = {}\n") fp.write("\t\tv._elemdict = {}\n") fp.write("\t\tfor superclass in v._superclassnames:\n")
969a896ab1c25fc9716f058d85ea6a0c44ea463a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/969a896ab1c25fc9716f058d85ea6a0c44ea463a/gensuitemodule.py
defaultLocation=DEFAULT_PACKAGEFOLDER)
defaultLocation=DEFAULT_STANDARD_PACKAGEFOLDER)
def compileaete(aete, resinfo, fname): """Generate code for a full aete resource. fname passed for doc purposes""" [version, language, script, suites] = aete major, minor = divmod(version, 256) creatorsignature, dummy = MacOS.GetCreatorAndType(fname) packagename = identify(os.path.splitext(os.path.basename(fname))[0]) if language: packagename = packagename+'_lang%d'%language if script: packagename = packagename+'_script%d'%script if len(packagename) > 27: packagename = packagename[:27] pathname = EasyDialogs.AskFolder(message='Create and select package folder for %s'%packagename, defaultLocation=DEFAULT_PACKAGEFOLDER) if not pathname: return packagename = os.path.split(os.path.normpath(pathname))[1] basepkgname = EasyDialogs.AskFolder(message='Package folder for base suite (usually StdSuites)', defaultLocation=DEFAULT_PACKAGEFOLDER) if basepkgname: dirname, basepkgname = os.path.split(os.path.normpath(basepkgname)) if not dirname in sys.path: sys.path.insert(0, dirname) basepackage = __import__(basepkgname) else: basepackage = None suitelist = [] allprecompinfo = [] allsuites = [] for suite in suites: code, suite, pathname, modname, precompinfo = precompilesuite(suite, basepackage) if not code: continue allprecompinfo = allprecompinfo + precompinfo suiteinfo = suite, pathname, modname suitelist.append((code, modname)) allsuites.append(suiteinfo) for suiteinfo in allsuites: compilesuite(suiteinfo, major, minor, language, script, fname, basepackage, allprecompinfo) initfilename = EasyDialogs.AskFileForSave(message='Package module', savedFileName='__init__.py') if not initfilename: return fp = open(initfilename, 'w') MacOS.SetCreatorAndType(initfilename, 'Pyth', 'TEXT') fp.write('"""\n') fp.write("Package generated from %s\n"%fname) if resinfo: fp.write("Resource %s resid %d %s\n"%(ascii(resinfo[1]), resinfo[0], ascii(resinfo[2]))) fp.write('"""\n') fp.write('import aetools\n') fp.write('Error = aetools.Error\n') for code, modname in suitelist: fp.write("import %s\n" % modname) fp.write("\n\n_code_to_module = {\n") for code, modname in suitelist: fp.write("\t'%s' : %s,\n"%(ascii(code), modname)) fp.write("}\n\n") fp.write("\n\n_code_to_fullname = {\n") for code, modname in suitelist: fp.write("\t'%s' : ('%s.%s', '%s'),\n"%(ascii(code), packagename, modname, modname)) fp.write("}\n\n") for code, modname in suitelist: fp.write("from %s import *\n"%modname) # Generate property dicts and element dicts for all types declared in this module fp.write("def getbaseclasses(v):\n") fp.write("\tif hasattr(v, '_superclassnames') and not hasattr(v, '_propdict'):\n") fp.write("\t\tv._propdict = {}\n") fp.write("\t\tv._elemdict = {}\n") fp.write("\t\tfor superclass in v._superclassnames:\n")
969a896ab1c25fc9716f058d85ea6a0c44ea463a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/969a896ab1c25fc9716f058d85ea6a0c44ea463a/gensuitemodule.py
print identify('for')
def identify(str): """Turn any string into an identifier: - replace space by _ - replace other illegal chars by _xx_ (hex code) - prepend _ if the result is a python keyword """ if not str: return "empty_ae_name_" rv = '' ok = string.ascii_letters + '_' ok2 = ok + string.digits for c in str: if c in ok: rv = rv + c elif c == ' ': rv = rv + '_' else: rv = rv + '_%02.2x_'%ord(c) ok = ok2 if keyword.iskeyword(rv): rv = rv + '_' return rv
969a896ab1c25fc9716f058d85ea6a0c44ea463a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/969a896ab1c25fc9716f058d85ea6a0c44ea463a/gensuitemodule.py
class TestMultipartMixed(unittest.TestCase):
class TestMultipartMixed(TestEmailBase):
def test_charset(self): eq = self.assertEqual msg = MIMEText('hello there', _charset='us-ascii') eq(msg.get_charset().input_charset, 'us-ascii') eq(msg['content-type'], 'text/plain; charset="us-ascii"')
6c092335fbbbed9a020cb4f6c46ffc1affc8b887 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/6c092335fbbbed9a020cb4f6c46ffc1affc8b887/test_email.py
By default, smtplib.SMTP_PORT is used.
By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised if the specified `host' doesn't respond correctly.
def __init__(self, host = '', port = 0): """Initialize a new instance.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
if host: self.connect(host, port)
if host: (code, msg) = self.connect(host, port) if code != 220: raise SMTPConnectError(code, msg)
def __init__(self, host = '', port = 0): """Initialize a new instance.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return msg
return (code,msg)
def connect(self, host='localhost', port = 0): """Connect to a host on a given port.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
if self.file is None: self.file = self.sock.makefile('rb')
if self.file is None: self.file = self.sock.makefile('rb')
def getreply(self): """Get a reply from the server. Returns a tuple consisting of:
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
if line == '': self.close() raise SMTPServerDisconnected("Connection unexpectedly closed")
if line == '': self.close() raise SMTPServerDisconnected("Connection unexpectedly closed")
def getreply(self): """Get a reply from the server. Returns a tuple consisting of:
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
try: errcode = string.atoi(code) except ValueError: errcode = -1 break
try: errcode = string.atoi(code) except ValueError: errcode = -1 break
def getreply(self): """Get a reply from the server. Returns a tuple consisting of:
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
(code,msg)=self.getreply() return code
return self.getreply()
def docmd(self, cmd, args=""): """Send a command, and return its response code.""" self.putcmd(cmd,args) (code,msg)=self.getreply() return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return code
return (code,msg)
def helo(self, name=''): """SMTP 'helo' command. Hostname to send for this command defaults to the FQDN of the local host. """ name=string.strip(name) if len(name)==0: name=socket.gethostbyaddr(socket.gethostname())[0] self.putcmd("helo",name) (code,msg)=self.getreply() self.helo_resp=msg return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return code
return (code,msg)
def ehlo(self, name=''): """ SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host. """ name=string.strip(name) if len(name)==0: name=socket.gethostbyaddr(socket.gethostname())[0] self.putcmd("ehlo",name) (code,msg)=self.getreply() # According to RFC1869 some (badly written) # MTA's will disconnect on an ehlo. Toss an exception if # that happens -ddm if code == -1 and len(msg) == 0: raise SMTPServerDisconnected("Server not connected") self.ehlo_resp=msg if code<>250: return code self.does_esmtp=1 #parse the ehlo responce -ddm resp=string.split(self.ehlo_resp,'\n') del resp[0] for each in resp: m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)',each) if m: feature=string.lower(m.group("feature")) params=string.strip(m.string[m.end("feature"):]) self.esmtp_features[feature]=params return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return code
return (code,msg)
def ehlo(self, name=''): """ SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host. """ name=string.strip(name) if len(name)==0: name=socket.gethostbyaddr(socket.gethostname())[0] self.putcmd("ehlo",name) (code,msg)=self.getreply() # According to RFC1869 some (badly written) # MTA's will disconnect on an ehlo. Toss an exception if # that happens -ddm if code == -1 and len(msg) == 0: raise SMTPServerDisconnected("Server not connected") self.ehlo_resp=msg if code<>250: return code self.does_esmtp=1 #parse the ehlo responce -ddm resp=string.split(self.ehlo_resp,'\n') del resp[0] for each in resp: m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)',each) if m: feature=string.lower(m.group("feature")) params=string.strip(m.string[m.end("feature"):]) self.esmtp_features[feature]=params return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
(code,msg)=self.getreply() return msg
return self.getreply()
def help(self, args=''): """SMTP 'help' command. Returns help text from server.""" self.putcmd("help", args) (code,msg)=self.getreply() return msg
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
code=self.docmd("rset") return code
return self.docmd("rset")
def rset(self): """SMTP 'rset' command -- resets session.""" code=self.docmd("rset") return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
code=self.docmd("noop") return code
return self.docmd("noop")
def noop(self): """SMTP 'noop' command -- doesn't do anything :>""" code=self.docmd("noop") return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return -1
raise SMTPDataError(code,repl)
def data(self,msg): """SMTP 'DATA' command -- sends message data to server. Automatically quotes lines beginning with a period per rfc821. """ self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print "data:", (code,repl) if code <> 354: return -1 else: self.send(quotedata(msg)) self.send("%s.%s" % (CRLF, CRLF)) (code,msg)=self.getreply() if self.debuglevel >0 : print "data:", (code,msg) return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
return code
return (code,msg)
def data(self,msg): """SMTP 'DATA' command -- sends message data to server. Automatically quotes lines beginning with a period per rfc821. """ self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print "data:", (code,repl) if code <> 354: return -1 else: self.send(quotedata(msg)) self.send("%s.%s" % (CRLF, CRLF)) (code,msg)=self.getreply() if self.debuglevel >0 : print "data:", (code,msg) return code
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
one recipient. Otherwise it will throw an exception (either SMTPSenderRefused, SMTPRecipientsRefused, or SMTPDataError) That is, if this method does not throw an exception, then someone should get your mail. If this method does not throw an exception, it returns a dictionary, with one entry for each recipient that was refused.
one recipient. It returns a dictionary, with one entry for each recipient that was refused. Each entry contains a tuple of the SMTP error code and the accompanying error message sent by the server. This method may raise the following exceptions: SMTPHeloError The server didn't reply properly to the helo greeting. SMTPRecipientsRefused The server rejected for ALL recipients (no mail was sent). SMTPSenderRefused The server didn't accept the from_addr. SMTPDataError The server replied with an unexpected error code (other than a refusal of a recipient). Note: the connection will be open even after an exception is raised.
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): """This command performs an entire mail transaction.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
if not self.helo_resp and not self.ehlo_resp: if self.ehlo() >= 400: self.helo()
if self.helo_resp is None and self.ehlo_resp is None: if not (200 <= self.ehlo()[0] <= 299): (code,resp) = self.helo() if not (200 <= code <= 299): raise SMTPHeloError(code, resp)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): """This command performs an entire mail transaction.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
raise SMTPSenderRefused('%s: %s' % (from_addr, resp))
raise SMTPSenderRefused(code, resp, from_addr)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): """This command performs an entire mail transaction.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
raise SMTPRecipientsRefused(string.join( map(lambda x:"%s: %s" % (x[0], x[1][1]), senderrs.items()), '; ')) code=self.data(msg) if code <>250 :
raise SMTPRecipientsRefused(senderrs) (code,resp)=self.data(msg) if code <> 250:
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): """This command performs an entire mail transaction.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
raise SMTPDataError('data transmission error: %s' % code)
raise SMTPDataError(code, resp)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): """This command performs an entire mail transaction.
df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/df0320a7ccf9b73e33c7b9b5d44674b3de8ddb2a/smtplib.py
"Test MCRYPT type miscelaneous methods."
"Test BZ2File type miscellaneous methods."
def decompress(self, data): return bz2.decompress(data)
679d56f7ae21c91dfa0cc77bfdf35fca50fc9212 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/679d56f7ae21c91dfa0cc77bfdf35fca50fc9212/test_bz2.py
raise norm_error, 'Cannot use :: immedeately after volume name'
raise norm_error, 'Cannot use :: immediately after volume name'
def normpath(s): """Normalize a pathname. Will return the same result for equivalent paths.""" if ":" not in s: return ":"+s comps = s.split(":") i = 1 while i < len(comps)-1: if comps[i] == "" and comps[i-1] != "": if i > 1: del comps[i-1:i+1] i = i - 1 else: # best way to handle this is to raise an exception raise norm_error, 'Cannot use :: immedeately after volume name' else: i = i + 1 s = ":".join(comps) # remove trailing ":" except for ":" and "Volume:" if s[-1] == ":" and len(comps) > 2 and s != ":"*len(s): s = s[:-1] return s
664767ee8f12e739028b0e1b362cf9eeec46240b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/664767ee8f12e739028b0e1b362cf9eeec46240b/macpath.py
self.passiveserver = 0
def connect(self, host = '', port = 0): '''Connect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port)''' if host: self.host = host if port: self.port = port self.passiveserver = 0 msg = "getaddrinfo returns an empty list" for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) self.sock.connect(sa) except socket.error, msg: if self.sock: self.sock.close() self.sock = None continue break if not self.sock: raise socket.error, msg self.af = af self.file = self.sock.makefile('rb') self.welcome = self.getresp() return self.welcome
ee4dce57cc74f89f165f3d08517e89a520bcbf7c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/ee4dce57cc74f89f165f3d08517e89a520bcbf7c/ftplib.py
try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass for fd in w: try: obj = map[fd] try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
pass
continue try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass for fd in w: try: obj = map[fd] try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass for fd in w: try: obj = map[fd] try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
pass
continue try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass for fd in w: try: obj = map[fd] try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
try: if (flags & poll.POLLIN): obj.handle_read_event() if (flags & poll.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll2 (timeout=0.0, map=None): import poll if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) if map: l = [] for fd, obj in map.items(): flags = 0 if obj.readable(): flags = poll.POLLIN if obj.writable(): flags = flags | poll.POLLOUT if flags: l.append ((fd, flags)) r = poll.poll (l, timeout) for fd, flags in r: try: obj = map[fd] try: if (flags & poll.POLLIN): obj.handle_read_event() if (flags & poll.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
pass
continue try: if (flags & poll.POLLIN): obj.handle_read_event() if (flags & poll.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll2 (timeout=0.0, map=None): import poll if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) if map: l = [] for fd, obj in map.items(): flags = 0 if obj.readable(): flags = poll.POLLIN if obj.writable(): flags = flags | poll.POLLOUT if flags: l.append ((fd, flags)) r = poll.poll (l, timeout) for fd, flags in r: try: obj = map[fd] try: if (flags & poll.POLLIN): obj.handle_read_event() if (flags & poll.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll3 (timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags = select.POLLIN if obj.writable(): flags = flags | select.POLLOUT if flags: pollster.register(fd, flags) r = pollster.poll (timeout) for fd, flags in r: try: obj = map[fd] try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
pass
continue try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll3 (timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags = select.POLLIN if obj.writable(): flags = flags | select.POLLOUT if flags: pollster.register(fd, flags) r = pollster.poll (timeout) for fd, flags in r: try: obj = map[fd] try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error() except KeyError: pass
3867795940c08dad1d75bc262a5735b059b045e3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3867795940c08dad1d75bc262a5735b059b045e3/asyncore.py
def __init__ (self, dist): """Create and initialize a new Command object. Most importantly, invokes the 'initialize_options()' method, which is the real initializer and depends on the actual command being instantiated. """ # late import because of mutual dependence between these classes from distutils.dist import Distribution
5c7a1450e46585d2c01099d250034db4712d94bc /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/5c7a1450e46585d2c01099d250034db4712d94bc/cmd.py
if opener == "else" or "elif":
if opener in ("else", "elif"):
def interesting_lines(self, firstline): """Generator which yields context lines, starting at firstline.""" # The indentation level we are currently in: lastindent = INFINITY # For a line to be interesting, it must begin with a block opening # keyword, and have less indentation than lastindent. for line_index in xrange(firstline, -1, -1): indent, text, opener = self.get_line_info(line_index) if indent < lastindent: lastindent = indent if opener == "else" or "elif": # We also show the if statement lastindent += 1 if opener and line_index < firstline: yield line_index, text
c7499b724059035b06cfded0f82dfb87a4b813ac /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/c7499b724059035b06cfded0f82dfb87a4b813ac/CodeContext.py
return scheme, url[len(scheme) + 1:]
return scheme.lower(), url[len(scheme) + 1:]
def splittype(url): """splittype('type:opaquestring') --> 'type', 'opaquestring'.""" global _typeprog if _typeprog is None: import re _typeprog = re.compile('^([^/:]+):') match = _typeprog.match(url) if match: scheme = match.group(1) return scheme, url[len(scheme) + 1:] return None, url
ac8d1df05cac4badf0339e2136712573d69a1126 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/ac8d1df05cac4badf0339e2136712573d69a1126/urllib.py
epoch = time.gmtime(0)[0]
gm_epoch = time.gmtime(0)[0:3] loc_epoch = time.localtime(0)[0:3]
def test_formatdate(self): now = 1005327232.109884 epoch = time.gmtime(0)[0] # When does the epoch start? if epoch == 1970: # traditional Unix epoch matchdate = 'Fri, 09 Nov 2001 17:33:52 -0000' elif epoch == 1904: # Mac epoch matchdate = 'Sat, 09 Nov 1935 16:33:52 -0000' else: matchdate = "I don't understand your epoch" gdate = Utils.formatdate(now) self.assertEqual(gdate, matchdate)
64a261a1e66de175b4f9c229e944d290a185c96b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/64a261a1e66de175b4f9c229e944d290a185c96b/test_email.py
if epoch == 1970:
if gm_epoch == (1970, 1, 1):
def test_formatdate(self): now = 1005327232.109884 epoch = time.gmtime(0)[0] # When does the epoch start? if epoch == 1970: # traditional Unix epoch matchdate = 'Fri, 09 Nov 2001 17:33:52 -0000' elif epoch == 1904: # Mac epoch matchdate = 'Sat, 09 Nov 1935 16:33:52 -0000' else: matchdate = "I don't understand your epoch" gdate = Utils.formatdate(now) self.assertEqual(gdate, matchdate)
64a261a1e66de175b4f9c229e944d290a185c96b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/64a261a1e66de175b4f9c229e944d290a185c96b/test_email.py
elif epoch == 1904:
elif loc_epoch == (1904, 1, 1):
def test_formatdate(self): now = 1005327232.109884 epoch = time.gmtime(0)[0] # When does the epoch start? if epoch == 1970: # traditional Unix epoch matchdate = 'Fri, 09 Nov 2001 17:33:52 -0000' elif epoch == 1904: # Mac epoch matchdate = 'Sat, 09 Nov 1935 16:33:52 -0000' else: matchdate = "I don't understand your epoch" gdate = Utils.formatdate(now) self.assertEqual(gdate, matchdate)
64a261a1e66de175b4f9c229e944d290a185c96b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/64a261a1e66de175b4f9c229e944d290a185c96b/test_email.py
__slots__ = ('_exp','_int','_sign') def __init__(self, value="0", context=None):
__slots__ = ('_exp','_int','_sign', '_is_special') def __new__(cls, value="0", context=None):
def setcontext(context, _local=local): """Set this thread's context to context.""" if context in (DefaultContext, BasicContext, ExtendedContext): context = context.copy() context.clear_flags() _local.__decimal_context__ = context
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext()
self = object.__new__(cls) self._is_special = False if isinstance(value, _WorkRep): if value.sign == 1: self._sign = 0 else: self._sign = 1 self._int = tuple(map(int, str(value.int))) self._exp = int(value.exp) return self if isinstance(value, Decimal): self._exp = value._exp self._sign = value._sign self._int = value._int self._is_special = value._is_special return self
def __init__(self, value="0", context=None): """Create a decimal point instance.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
value = str(value) if isinstance(value, basestring): if _isinfinity(value): self._exp = 'F' self._int = (0,) sign = _isinfinity(value) if sign == 1: self._sign = 0 else: self._sign = 1 return if _isnan(value): sig, sign, diag = _isnan(value) if len(diag) > context.prec: self._sign, self._int, self._exp = \ context._raise_error(ConversionSyntax) return if sig == 1: self._exp = 'n' else: self._exp = 'N' self._sign = sign self._int = tuple(map(int, diag)) return try: self._sign, self._int, self._exp = _string2exact(value) except ValueError: self._sign, self._int, self._exp = context._raise_error(ConversionSyntax) return
if value >= 0: self._sign = 0 else: self._sign = 1 self._exp = 0 self._int = tuple(map(int, str(abs(value)))) return self
def __init__(self, value="0", context=None): """Create a decimal point instance.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
return if isinstance(value, _WorkRep): if value.sign == 1: self._sign = 0 else: self._sign = 1 self._int = tuple(value.int) self._exp = int(value.exp) return if isinstance(value, Decimal): self._exp = value._exp self._sign = value._sign self._int = value._int return
return self
def __init__(self, value="0", context=None): """Create a decimal point instance.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
raise TypeError("Cannot convert %r" % value) def _convert_other(self, other): """Convert other to Decimal. Verifies that it's ok to use in an implicit construction. """ if isinstance(other, Decimal): return other if isinstance(other, (int, long)): other = Decimal(other) return other raise TypeError, "You can interact Decimal only with int, long or Decimal data types."
if context is None: context = getcontext() if isinstance(value, basestring): if _isinfinity(value): self._exp = 'F' self._int = (0,) self._is_special = True if _isinfinity(value) == 1: self._sign = 0 else: self._sign = 1 return self if _isnan(value): sig, sign, diag = _isnan(value) self._is_special = True if len(diag) > context.prec: self._sign, self._int, self._exp = \ context._raise_error(ConversionSyntax) return self if sig == 1: self._exp = 'n' else: self._exp = 'N' self._sign = sign self._int = tuple(map(int, diag)) return self try: self._sign, self._int, self._exp = _string2exact(value) except ValueError: self._is_special = True self._sign, self._int, self._exp = context._raise_error(ConversionSyntax) return self raise TypeError("Cannot convert %r to Decimal" % value)
def __init__(self, value="0", context=None): """Create a decimal point instance.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._exp == 'n': return 1 elif self._exp == 'N': return 2
if self._is_special: exp = self._exp if exp == 'n': return 1 elif exp == 'N': return 2
def _isnan(self): """Returns whether the number is not actually one.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() if self._isnan() == 2: return context._raise_error(InvalidOperation, 'sNaN', 1, self) if other is not None and other._isnan() == 2: return context._raise_error(InvalidOperation, 'sNaN', 1, other) if self._isnan(): return self if other is not None and other._isnan():
self_is_nan = self._isnan() if other is None: other_is_nan = False else: other_is_nan = other._isnan() if self_is_nan or other_is_nan: if context is None: context = getcontext() if self_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', 1, self) if other_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', 1, other) if self_is_nan: return self
def _check_nans(self, other = None, context=None): """Returns whether the number is not actually one.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if isinstance(self._exp, str):
if self._is_special:
def __nonzero__(self): """Is the number non-zero?
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
return self._int != (0,)*len(self._int)
return sum(self._int) != 0
def __nonzero__(self): """Is the number non-zero?
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return 1
other = _convert_other(other) if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: return 1 return cmp(self._isinfinity(), other._isinfinity())
def __cmp__(self, other, context=None): if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._isinfinity() and other._isinfinity(): return 0 if self._isinfinity(): return (-1)**self._sign if other._isinfinity(): return -((-1)**other._sign) if self.adjusted() == other.adjusted() and \
self_adjusted = self.adjusted() other_adjusted = other.adjusted() if self_adjusted == other_adjusted and \
def __cmp__(self, other, context=None): if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
elif self.adjusted() > other.adjusted() and self._int[0] != 0:
elif self_adjusted > other_adjusted and self._int[0] != 0:
def __cmp__(self, other, context=None): if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
elif self.adjusted < other.adjusted() and other._int[0] != 0:
elif self_adjusted < other_adjusted and other._int[0] != 0:
def __cmp__(self, other, context=None): if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() other = self._convert_other(other)
other = _convert_other(other)
def compare(self, other, context=None): """Compares one to another.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
ans = self._check_nans(other, context) if ans: return ans
if (self._is_special or other and other._is_special): ans = self._check_nans(other, context) if ans: return ans
def compare(self, other, context=None): """Compares one to another.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext()
def to_eng_string(self, context=None): """Convert to engineering-type string.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
def __neg__(self, context=None): """Returns a copy with the sign switched.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
def __pos__(self, context=None): """Returns a copy, unless it is a sNaN.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
def __abs__(self, round=1, context=None): """Returns the absolute value of self.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if self._sign != other._sign and other._isinfinity(): return context._raise_error(InvalidOperation, '-INF + INF') return Decimal(self) if other._isinfinity(): return Decimal(other)
if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if self._sign != other._sign and other._isinfinity(): return context._raise_error(InvalidOperation, '-INF + INF') return Decimal(self) if other._isinfinity(): return Decimal(other)
def __add__(self, other, context=None): """Returns self + other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
op1.int.reverse() op2.int.reverse()
def __add__(self, other, context=None): """Returns self + other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
result.int = resultint = map(operator.add, op1.int, op2.int) carry = 0 for i in xrange(len(op1.int)): tmp = resultint[i] + carry carry = 0 if tmp > 9: carry = 1 tmp -= 10 resultint[i] = tmp if carry: resultint.append(1)
result.int = op1.int + op2.int
def __add__(self, other, context=None): """Returns self + other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
result.int = resultint = map(operator.sub, op1.int, op2.int) loan = 0 for i in xrange(len(op1.int)): tmp = resultint[i] - loan loan = 0 if tmp < 0: loan = 1 tmp += 10 resultint[i] = tmp assert not loan while resultint[-1] == 0: resultint.pop() resultint.reverse()
result.int = op1.int - op2.int
def __add__(self, other, context=None): """Returns self + other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() other = self._convert_other(other) ans = self._check_nans(other, context=context) if ans: return ans
other = _convert_other(other) if self._is_special or other._is_special: ans = self._check_nans(other, context=context) if ans: return ans
def __sub__(self, other, context=None): """Return self + (-other)""" if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() other = self._convert_other(other)
other = _convert_other(other)
def __rsub__(self, other, context=None): """Return other + (-self)""" if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans return Decimal(self)
def _increment(self, round=1, context=None): """Special case of add, adding 1eExponent
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans
def __mul__(self, other, context=None): """Return self * other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') return Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') return Infsign[resultsign]
if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') return Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') return Infsign[resultsign]
def __mul__(self, other, context=None): """Return self * other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
op1 = list(self._int) op2 = list(other._int) op1.reverse() op2.reverse() if len(op2) > len(op1): op1, op2 = op2, op1 _divmod = divmod accumulator = [0]*(len(self._int) + len(other._int)) for i in xrange(len(op2)): if op2[i] == 0: continue mult = op2[i] carry = 0 for j in xrange(len(op1)): carry, accumulator[i+j] = _divmod( mult * op1[j] + carry + accumulator[i+j], 10) if carry: accumulator[i + j + 1] += carry while not accumulator[-1]: accumulator.pop() accumulator.reverse() ans = Decimal( (resultsign, accumulator, resultexp))
op1 = _WorkRep(self) op2 = _WorkRep(other) ans = Decimal( (resultsign, map(int, str(op1.int * op2.int)), resultexp))
def __mul__(self, other, context=None): """Return self * other.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: if divmod: return (ans, ans) else:
sign = self._sign ^ other._sign if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: if divmod: return (ans, ans)
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
sign = self._sign ^ other._sign if not self and not other: if divmod: return context._raise_error(DivisionUndefined, '0 / 0', 1) return context._raise_error(DivisionUndefined, '0 / 0') if self._isinfinity() and other._isinfinity(): if not divmod:
if self._isinfinity() and other._isinfinity(): if divmod: return (context._raise_error(InvalidOperation, '(+-)INF // (+-)INF'), context._raise_error(InvalidOperation, '(+-)INF % (+-)INF'))
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
else: return (context._raise_error(InvalidOperation, '(+-)INF // (+-)INF'), context._raise_error(InvalidOperation, '(+-)INF % (+-)INF')) if not divmod: if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') return Decimal((sign, (0,), context.Etiny())) if self._isinfinity(): return Infsign[sign] if not self: exp = self._exp - other._exp if exp < context.Etiny(): exp = context.Etiny() context._raise_error(Clamped, '0e-x / y') if exp > context.Emax: exp = context.Emax context._raise_error(Clamped, '0e+x / y') return Decimal( (sign, (0,), exp) ) if not other: return context._raise_error(DivisionByZero, 'x / 0', sign) if divmod: if other._isinfinity(): return (Decimal((sign, (0,), 0)), Decimal(self))
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if not self:
return Infsign[sign] if other._isinfinity(): if divmod: return (Decimal((sign, (0,), 0)), Decimal(self)) context._raise_error(Clamped, 'Division by infinity') return Decimal((sign, (0,), context.Etiny())) if not self and not other: if divmod: return context._raise_error(DivisionUndefined, '0 / 0', 1) return context._raise_error(DivisionUndefined, '0 / 0') if not self: if divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if not other:
exp = self._exp - other._exp if exp < context.Etiny(): exp = context.Etiny() context._raise_error(Clamped, '0e-x / y') if exp > context.Emax: exp = context.Emax context._raise_error(Clamped, '0e+x / y') return Decimal( (sign, (0,), exp) ) if not other: if divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
return context._raise_error(DivisionByZero, 'x / 0', sign)
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
res = _WorkRep( (sign, [0], (op1.exp - op2.exp)) )
res = _WorkRep( (sign, 0, (op1.exp - op2.exp)) )
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
while( (len(op2.int) < len(op1.int) and op1.int[0]) or (len(op2.int) == len(op1.int) and op2.int <= op1.int)): res._increment() op1.subtract(op2.int)
while op2.int <= op1.int: res.int += 1 op1.int -= op2.int
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if len(res.int) > context.prec and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if op1.int == [0]*len(op1.int) and adjust >= 0 and not divmod:
if op1.int == 0 and adjust >= 0 and not divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if (len(res.int) > context.prec) and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if op1.int != [0]*len(op1.int): res.int.append(1)
if op1.int != 0: res.int *= 10 res.int += 1
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
res.int.append(0) op1.int.append(0)
op1.int *= 10
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if res.exp == 0 and divmod and (len(op2.int) > len(op1.int) or (len(op2.int) == len(op1.int) and op2.int > op1.int)):
if res.exp == 0 and divmod and op2.int > op1.int:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if len(res.int) > context.prec and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rdiv__(self, other, context=None): """Swaps self/other and returns __div__.""" other = self._convert_other(other) return other.__div__(self, context=context)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rdivmod__(self, other, context=None): """Swaps self/other and returns __divmod__.""" other = self._convert_other(other) return other.__divmod__(self, context=context)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self and not other: return context._raise_error(InvalidOperation, 'x % 0') return self._divide(other, 3, context)[1] def __rmod__(self, other, context=None): """Swaps self/other and returns __mod__.""" other = self._convert_other(other) return other.__mod__(self, context=context) def remainder_near(self, other, context=None): """ Remainder nearest to 0- abs(remainder-near) <= other/2 """ if context is None: context = getcontext() other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self and not other: return context._raise_error(InvalidOperation, 'x % 0')
def __mod__(self, other, context=None): """ self % other """ if context is None: context = getcontext() other = self._convert_other(other)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rfloordiv__(self, other, context=None): """Swaps self/other and returns __floordiv__.""" other = self._convert_other(other) return other.__floordiv__(self, context=context)
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long"
if self._is_special: if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long"
def __int__(self): """Converts self to a int, truncating if necessary.""" if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long" if not self: return 0 sign = '-'*self._sign if self._exp >= 0: s = sign + ''.join(map(str, self._int)) + '0'*self._exp return int(s) s = sign + ''.join(map(str, self._int))[:self._exp] return int(s) tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
def __int__(self): """Converts self to a int, truncating if necessary.""" if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long" if not self: return 0 sign = '-'*self._sign if self._exp >= 0: s = sign + ''.join(map(str, self._int)) + '0'*self._exp return int(s) s = sign + ''.join(map(str, self._int))[:self._exp] return int(s) tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._isinfinity() or self._isnan():
if self._is_special:
def _fix(self, prec=None, rounding=None, folddown=None, context=None): """Round if it is necessary to keep self within prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
ans = ans._fixexponents(prec, rounding, folddown=folddown, context=context)
ans = ans._fixexponents(prec, rounding, folddown=folddown, context=context)
def _fix(self, prec=None, rounding=None, folddown=None, context=None): """Round if it is necessary to keep self within prec precision.
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py
if self._isinfinity():
if self._is_special:
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
1a63da64df2af26e1f050749c19281f1de9084fa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1a63da64df2af26e1f050749c19281f1de9084fa/decimal.py