rem
stringlengths 1
322k
| add
stringlengths 0
2.05M
| context
stringlengths 4
228k
| meta
stringlengths 156
215
|
---|---|---|---|
if ok: | if fss: | def interact(options, title): """Let the user interact with the dialog""" try: # Try to go to the "correct" dir for GetDirectory os.chdir(options['dir'].as_pathname()) except os.error: pass d = GetNewDialog(DIALOG_ID, -1) htext = d.GetDialogItemAsControl(TITLE_ITEM) SetDialogItemText(htext, title) path_ctl = d.GetDialogItemAsControl(TEXT_ITEM) data = string.joinfields(options['path'], '\r') path_ctl.SetControlData(Controls.kControlEditTextPart, Controls.kControlEditTextTextTag, data) d.SelectDialogItemText(TEXT_ITEM, 0, 32767) d.SelectDialogItemText(TEXT_ITEM, 0, 0) | 4ba5f3d9042c7fe625c3ab94de13fc814606a4e5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/4ba5f3d9042c7fe625c3ab94de13fc814606a4e5/EditPythonPrefs.py |
print >>sys.stderr, name, "exists:", os.path.exists(name) | def expect(got_this, expect_this): if test_support.verbose: print '%s =?= %s ...' % (`got_this`, `expect_this`), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %s, but expected %s' %\ (str(got_this), str(expect_this)) else: if test_support.verbose: print 'yes' | 77a47db3968c843b6eed8bcf4b8f39d9c3d0a99d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/77a47db3968c843b6eed8bcf4b8f39d9c3d0a99d/test_largefile.py |
|
try: path = win32api.GetFullPathName(path) except win32api.error: pass | if path: try: path = win32api.GetFullPathName(path) except win32api.error: pass else: path = os.getcwd() | def _abspath(path): if not isabs(path): path = join(os.getcwd(), path) return normpath(path) | 5f5c2ee76076660a5b2cc97ff7cbef7240361ef6 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/5f5c2ee76076660a5b2cc97ff7cbef7240361ef6/ntpath.py |
if string.find(string.lower(name), 'xml') >= 0: | if string.lower(name) == 'xml': | def parse_proc(self, i): rawdata = self.rawdata end = procclose.search(rawdata, i) if end is None: return -1 j = end.start(0) if illegal.search(rawdata, i+2, j): self.syntax_error('illegal character in processing instruction') res = tagfind.match(rawdata, i+2) if res is None: raise RuntimeError, 'unexpected call to parse_proc' k = res.end(0) name = res.group(0) if name == 'xml:namespace': self.syntax_error('old-fashioned namespace declaration') self.__use_namespaces = -1 # namespace declaration # this must come after the <?xml?> declaration (if any) # and before the <!DOCTYPE> (if any). if self.__seen_doctype or self.__seen_starttag: self.syntax_error('xml:namespace declaration too late in document') attrdict, namespace, k = self.parse_attributes(name, k, j) if namespace: self.syntax_error('namespace declaration inside namespace declaration') for attrname in attrdict.keys(): if not self.__xml_namespace_attributes.has_key(attrname): self.syntax_error("unknown attribute `%s' in xml:namespace tag" % attrname) if not attrdict.has_key('ns') or not attrdict.has_key('prefix'): self.syntax_error('xml:namespace without required attributes') prefix = attrdict.get('prefix') if ncname.match(prefix) is None: self.syntax_error('xml:namespace illegal prefix value') return end.end(0) if self.__namespaces.has_key(prefix): self.syntax_error('xml:namespace prefix not unique') self.__namespaces[prefix] = attrdict['ns'] else: if string.find(string.lower(name), 'xml') >= 0: self.syntax_error('illegal processing instruction target name') self.handle_proc(name, rawdata[k:j]) return end.end(0) | 876033a7e833e1df74fca7c9cc91b9a0541c127c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/876033a7e833e1df74fca7c9cc91b9a0541c127c/xmllib.py |
assert re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx') == 'xxxx' | assert re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx') == 'xxxx' | def bump_num(matchobj): | f8143768ade1ae498008a46491e2c6b5cca8d457 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/f8143768ade1ae498008a46491e2c6b5cca8d457/test_re.py |
m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)',each) | m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*) ?',each) | def ehlo(self, name=''): """ SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host. """ self.esmtp_features = {} self.putcmd("ehlo", name or self.local_hostname) (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: self.close() raise SMTPServerDisconnected("Server not connected") self.ehlo_resp=msg if code != 250: return (code,msg) self.does_esmtp=1 #parse the ehlo response -ddm resp=self.ehlo_resp.split('\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=m.group("feature").lower() params=m.string[m.end("feature"):].strip() self.esmtp_features[feature]=params return (code,msg) | f64fb3766ea1bf2a3dd8a0f98b7a689336201509 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/f64fb3766ea1bf2a3dd8a0f98b7a689336201509/smtplib.py |
if ext in self.swig_ext(): | if ext == ".i": | def swig_sources (self, sources): | 017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8/build_ext.py |
swig_files.append(source) | swig_sources.append(source) | def swig_sources (self, sources): | 017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8/build_ext.py |
if not swig_files: | if not swig_sources: | def swig_sources (self, sources): | 017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/017df766f2a9bcf9a57d1bb1efeeadc60dbc6cb8/build_ext.py |
d = dict(items={}) | d = dict({}) | def dict_constructor(): if verbose: print "Testing dict constructor ..." d = dict() vereq(d, {}) d = dict({}) vereq(d, {}) d = dict(items={}) vereq(d, {}) d = dict({1: 2, 'a': 'b'}) vereq(d, {1: 2, 'a': 'b'}) vereq(d, dict(d.items())) vereq(d, dict(items=d.iteritems())) for badarg in 0, 0L, 0j, "0", [0], (0,): try: dict(badarg) except TypeError: pass except ValueError: if badarg == "0": # It's a sequence, and its elements are also sequences (gotta # love strings <wink>), but they aren't of length 2, so this # one seemed better as a ValueError than a TypeError. pass else: raise TestFailed("no TypeError from dict(%r)" % badarg) else: raise TestFailed("no TypeError from dict(%r)" % badarg) try: dict(senseless={}) except TypeError: pass else: raise TestFailed("no TypeError from dict(senseless={})") try: dict({}, {}) except TypeError: pass else: raise TestFailed("no TypeError from dict({}, {})") class Mapping: # Lacks a .keys() method; will be added later. dict = {1:2, 3:4, 'a':1j} try: dict(Mapping()) except TypeError: pass else: raise TestFailed("no TypeError from dict(incomplete mapping)") Mapping.keys = lambda self: self.dict.keys() Mapping.__getitem__ = lambda self, i: self.dict[i] d = dict(items=Mapping()) vereq(d, Mapping.dict) # Init from sequence of iterable objects, each producing a 2-sequence. class AddressBookEntry: def __init__(self, first, last): self.first = first self.last = last def __iter__(self): return iter([self.first, self.last]) d = dict([AddressBookEntry('Tim', 'Warsaw'), AddressBookEntry('Barry', 'Peters'), AddressBookEntry('Tim', 'Peters'), AddressBookEntry('Barry', 'Warsaw')]) vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'}) d = dict(zip(range(4), range(1, 5))) vereq(d, dict([(i, i+1) for i in range(4)])) # Bad sequence lengths. for bad in [('tooshort',)], [('too', 'long', 'by 1')]: try: dict(bad) except ValueError: pass else: raise TestFailed("no ValueError from dict(%r)" % bad) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
vereq(d, dict(items=d.iteritems())) | vereq(d, dict(d.iteritems())) d = dict({'one':1, 'two':2}) vereq(d, dict(one=1, two=2)) vereq(d, dict(**d)) vereq(d, dict({"one": 1}, two=2)) vereq(d, dict([("two", 2)], one=1)) vereq(d, dict([("one", 100), ("two", 200)], **d)) verify(d is not dict(**d)) | def dict_constructor(): if verbose: print "Testing dict constructor ..." d = dict() vereq(d, {}) d = dict({}) vereq(d, {}) d = dict(items={}) vereq(d, {}) d = dict({1: 2, 'a': 'b'}) vereq(d, {1: 2, 'a': 'b'}) vereq(d, dict(d.items())) vereq(d, dict(items=d.iteritems())) for badarg in 0, 0L, 0j, "0", [0], (0,): try: dict(badarg) except TypeError: pass except ValueError: if badarg == "0": # It's a sequence, and its elements are also sequences (gotta # love strings <wink>), but they aren't of length 2, so this # one seemed better as a ValueError than a TypeError. pass else: raise TestFailed("no TypeError from dict(%r)" % badarg) else: raise TestFailed("no TypeError from dict(%r)" % badarg) try: dict(senseless={}) except TypeError: pass else: raise TestFailed("no TypeError from dict(senseless={})") try: dict({}, {}) except TypeError: pass else: raise TestFailed("no TypeError from dict({}, {})") class Mapping: # Lacks a .keys() method; will be added later. dict = {1:2, 3:4, 'a':1j} try: dict(Mapping()) except TypeError: pass else: raise TestFailed("no TypeError from dict(incomplete mapping)") Mapping.keys = lambda self: self.dict.keys() Mapping.__getitem__ = lambda self, i: self.dict[i] d = dict(items=Mapping()) vereq(d, Mapping.dict) # Init from sequence of iterable objects, each producing a 2-sequence. class AddressBookEntry: def __init__(self, first, last): self.first = first self.last = last def __iter__(self): return iter([self.first, self.last]) d = dict([AddressBookEntry('Tim', 'Warsaw'), AddressBookEntry('Barry', 'Peters'), AddressBookEntry('Tim', 'Peters'), AddressBookEntry('Barry', 'Warsaw')]) vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'}) d = dict(zip(range(4), range(1, 5))) vereq(d, dict([(i, i+1) for i in range(4)])) # Bad sequence lengths. for bad in [('tooshort',)], [('too', 'long', 'by 1')]: try: dict(bad) except ValueError: pass else: raise TestFailed("no ValueError from dict(%r)" % bad) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
try: dict(senseless={}) except TypeError: pass else: raise TestFailed("no TypeError from dict(senseless={})") | def dict_constructor(): if verbose: print "Testing dict constructor ..." d = dict() vereq(d, {}) d = dict({}) vereq(d, {}) d = dict(items={}) vereq(d, {}) d = dict({1: 2, 'a': 'b'}) vereq(d, {1: 2, 'a': 'b'}) vereq(d, dict(d.items())) vereq(d, dict(items=d.iteritems())) for badarg in 0, 0L, 0j, "0", [0], (0,): try: dict(badarg) except TypeError: pass except ValueError: if badarg == "0": # It's a sequence, and its elements are also sequences (gotta # love strings <wink>), but they aren't of length 2, so this # one seemed better as a ValueError than a TypeError. pass else: raise TestFailed("no TypeError from dict(%r)" % badarg) else: raise TestFailed("no TypeError from dict(%r)" % badarg) try: dict(senseless={}) except TypeError: pass else: raise TestFailed("no TypeError from dict(senseless={})") try: dict({}, {}) except TypeError: pass else: raise TestFailed("no TypeError from dict({}, {})") class Mapping: # Lacks a .keys() method; will be added later. dict = {1:2, 3:4, 'a':1j} try: dict(Mapping()) except TypeError: pass else: raise TestFailed("no TypeError from dict(incomplete mapping)") Mapping.keys = lambda self: self.dict.keys() Mapping.__getitem__ = lambda self, i: self.dict[i] d = dict(items=Mapping()) vereq(d, Mapping.dict) # Init from sequence of iterable objects, each producing a 2-sequence. class AddressBookEntry: def __init__(self, first, last): self.first = first self.last = last def __iter__(self): return iter([self.first, self.last]) d = dict([AddressBookEntry('Tim', 'Warsaw'), AddressBookEntry('Barry', 'Peters'), AddressBookEntry('Tim', 'Peters'), AddressBookEntry('Barry', 'Warsaw')]) vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'}) d = dict(zip(range(4), range(1, 5))) vereq(d, dict([(i, i+1) for i in range(4)])) # Bad sequence lengths. for bad in [('tooshort',)], [('too', 'long', 'by 1')]: try: dict(bad) except ValueError: pass else: raise TestFailed("no ValueError from dict(%r)" % bad) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
|
d = dict(items=Mapping()) | d = dict(Mapping()) | def dict_constructor(): if verbose: print "Testing dict constructor ..." d = dict() vereq(d, {}) d = dict({}) vereq(d, {}) d = dict(items={}) vereq(d, {}) d = dict({1: 2, 'a': 'b'}) vereq(d, {1: 2, 'a': 'b'}) vereq(d, dict(d.items())) vereq(d, dict(items=d.iteritems())) for badarg in 0, 0L, 0j, "0", [0], (0,): try: dict(badarg) except TypeError: pass except ValueError: if badarg == "0": # It's a sequence, and its elements are also sequences (gotta # love strings <wink>), but they aren't of length 2, so this # one seemed better as a ValueError than a TypeError. pass else: raise TestFailed("no TypeError from dict(%r)" % badarg) else: raise TestFailed("no TypeError from dict(%r)" % badarg) try: dict(senseless={}) except TypeError: pass else: raise TestFailed("no TypeError from dict(senseless={})") try: dict({}, {}) except TypeError: pass else: raise TestFailed("no TypeError from dict({}, {})") class Mapping: # Lacks a .keys() method; will be added later. dict = {1:2, 3:4, 'a':1j} try: dict(Mapping()) except TypeError: pass else: raise TestFailed("no TypeError from dict(incomplete mapping)") Mapping.keys = lambda self: self.dict.keys() Mapping.__getitem__ = lambda self, i: self.dict[i] d = dict(items=Mapping()) vereq(d, Mapping.dict) # Init from sequence of iterable objects, each producing a 2-sequence. class AddressBookEntry: def __init__(self, first, last): self.first = first self.last = last def __iter__(self): return iter([self.first, self.last]) d = dict([AddressBookEntry('Tim', 'Warsaw'), AddressBookEntry('Barry', 'Peters'), AddressBookEntry('Tim', 'Peters'), AddressBookEntry('Barry', 'Warsaw')]) vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'}) d = dict(zip(range(4), range(1, 5))) vereq(d, dict([(i, i+1) for i in range(4)])) # Bad sequence lengths. for bad in [('tooshort',)], [('too', 'long', 'by 1')]: try: dict(bad) except ValueError: pass else: raise TestFailed("no ValueError from dict(%r)" % bad) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
vereq(dict(items={1: 2}), {1: 2}) | def keywords(): if verbose: print "Testing keyword args to basic type constructors ..." vereq(int(x=1), 1) vereq(float(x=2), 2.0) vereq(long(x=3), 3L) vereq(complex(imag=42, real=666), complex(666, 42)) vereq(str(object=500), '500') vereq(unicode(string='abc', errors='strict'), u'abc') vereq(tuple(sequence=range(3)), (0, 1, 2)) vereq(list(sequence=(0, 1, 2)), range(3)) vereq(dict(items={1: 2}), {1: 2}) for constructor in (int, float, long, complex, str, unicode, tuple, list, dict, file): try: constructor(bogus_keyword_arg=1) except TypeError: pass else: raise TestFailed("expected TypeError from bogus keyword " "argument to %r" % constructor) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
|
tuple, list, dict, file): | tuple, list, file): | def keywords(): if verbose: print "Testing keyword args to basic type constructors ..." vereq(int(x=1), 1) vereq(float(x=2), 2.0) vereq(long(x=3), 3L) vereq(complex(imag=42, real=666), complex(666, 42)) vereq(str(object=500), '500') vereq(unicode(string='abc', errors='strict'), u'abc') vereq(tuple(sequence=range(3)), (0, 1, 2)) vereq(list(sequence=(0, 1, 2)), range(3)) vereq(dict(items={1: 2}), {1: 2}) for constructor in (int, float, long, complex, str, unicode, tuple, list, dict, file): try: constructor(bogus_keyword_arg=1) except TypeError: pass else: raise TestFailed("expected TypeError from bogus keyword " "argument to %r" % constructor) | d65fb152f1cb970df809fba08a4132871bd4aace /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d65fb152f1cb970df809fba08a4132871bd4aace/test_descr.py |
if type(url) == Types.StringType: | if type(url) == types.StringType: | def checkonly(package, url, version, verbose=0): if verbose >= VERBOSE_EACHFILE: print '%s:'%package if type(url) == Types.StringType: ok, newversion, fp = _check1version(package, url, version, verbose) else: for u in url: ok, newversion, fp = _check1version(package, u, version, verbose) if ok >= 0 and verbose < VERBOSE_CHECKALL: break return ok, newversion, fp | 9ab54adfc5cb606b879d563127c9eafdeff9f31f /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9ab54adfc5cb606b879d563127c9eafdeff9f31f/pyversioncheck.py |
def _test(): | def test_main(): | def _test(): threads = [] print "Creating" for i in range(NUM_THREADS): t = TempFileGreedy() threads.append(t) t.start() print "Starting" startEvent.set() print "Reaping" ok = errors = 0 for t in threads: t.join() ok += t.ok_count errors += t.error_count if t.error_count: print '%s errors:\n%s' % (t.getName(), t.errors.getvalue()) msg = "Done: errors %d ok %d" % (errors, ok) print msg if errors: raise TestFailed(msg) | 3788417f1e46b7852ac48fee5c5fb9216c27eced /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3788417f1e46b7852ac48fee5c5fb9216c27eced/test_threadedtempfile.py |
_test() | test_main() | def _test(): threads = [] print "Creating" for i in range(NUM_THREADS): t = TempFileGreedy() threads.append(t) t.start() print "Starting" startEvent.set() print "Reaping" ok = errors = 0 for t in threads: t.join() ok += t.ok_count errors += t.error_count if t.error_count: print '%s errors:\n%s' % (t.getName(), t.errors.getvalue()) msg = "Done: errors %d ok %d" % (errors, ok) print msg if errors: raise TestFailed(msg) | 3788417f1e46b7852ac48fee5c5fb9216c27eced /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3788417f1e46b7852ac48fee5c5fb9216c27eced/test_threadedtempfile.py |
def handle(self): """Handle a single HTTP request. You normally don't need to override this method; see the class __doc__ string for information on how to handle specific HTTP commands such as GET and POST. """ self.raw_requestline = self.rfile.readline() | def parse_request(self): """Parse a request (internal). The request should be stored in self.raw_request; the results are in self.command, self.path, self.request_version and self.headers. Return value is 1 for success, 0 for failure; on failure, an error is sent back. """ | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
return | return 0 | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
return | return 0 | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
return | return 0 | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
mname = 'do_' + command | return 1 def handle(self): """Handle a single HTTP request. You normally don't need to override this method; see the class __doc__ string for information on how to handle specific HTTP commands such as GET and POST. """ self.raw_requestline = self.rfile.readline() if not self.parse_request(): return mname = 'do_' + self.command | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
self.send_error(501, "Unsupported method (%s)" % `command`) | self.send_error(501, "Unsupported method (%s)" % `self.command`) | def handle(self): """Handle a single HTTP request. | 3dc5ebef964a116acb492860df90e1165b19cd39 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/3dc5ebef964a116acb492860df90e1165b19cd39/BaseHTTPServer.py |
upp_dispose_handler = NewWENewObjectProc(my_dispose_handler); upp_draw_handler = NewWENewObjectProc(my_draw_handler); upp_click_handler = NewWENewObjectProc(my_click_handler); | upp_dispose_handler = NewWEDisposeObjectProc(my_dispose_handler); upp_draw_handler = NewWEDrawObjectProc(my_draw_handler); upp_click_handler = NewWEClickObjectProc(my_click_handler); | def outputCheckNewArg(self): Output("""if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }""") | 1c6c4b0f06a94c5c2a0bfcbf1f61f563c590c3fd /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1c6c4b0f06a94c5c2a0bfcbf1f61f563c590c3fd/wastesupport.py |
if ( selector == weNewHandler ) handler = upp_new_handler; else if ( selector == weDisposeHandler ) handler = upp_dispose_handler; else if ( selector == weDrawHandler ) handler = upp_draw_handler; else if ( selector == weClickHandler ) handler = upp_click_handler; | if ( selector == weNewHandler ) handler = (UniversalProcPtr)upp_new_handler; else if ( selector == weDisposeHandler ) handler = (UniversalProcPtr)upp_dispose_handler; else if ( selector == weDrawHandler ) handler = (UniversalProcPtr)upp_draw_handler; else if ( selector == weClickHandler ) handler = (UniversalProcPtr)upp_click_handler; | def outputCheckNewArg(self): Output("""if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }""") | 1c6c4b0f06a94c5c2a0bfcbf1f61f563c590c3fd /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/1c6c4b0f06a94c5c2a0bfcbf1f61f563c590c3fd/wastesupport.py |
def makefile(self, mode): | def makefile(self, mode, bufsize=None): """Return a readable file-like object with data from socket. This method offers only partial support for the makefile interface of a real socket. It only supports modes 'r' and 'rb' and the bufsize argument is ignored. The returned object contains *all* of the file data """ | def makefile(self, mode): # hopefully, never have to write if mode != 'r' and mode != 'rb': raise UnimplementedFileMode() | a809ab51a1f0830bd85a8c4bda919585b9e6ec27 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/a809ab51a1f0830bd85a8c4bda919585b9e6ec27/httplib.py |
opt_name = string.translate(opt_name, longopt_xlate) val = getattr(self, opt_name) | if self.negative_opt.has_key(opt_name): opt_name = string.translate(self.negative_opt[opt_name], longopt_xlate) val = not getattr(self, opt_name) else: opt_name = string.translate(opt_name, longopt_xlate) val = getattr(self, opt_name) | def dump_dirs (self, msg): if DEBUG: from distutils.fancy_getopt import longopt_xlate print msg + ":" for opt in self.user_options: opt_name = opt[0] if opt_name[-1] == "=": opt_name = opt_name[0:-1] opt_name = string.translate(opt_name, longopt_xlate) val = getattr(self, opt_name) print " %s: %s" % (opt_name, val) | 2da9ba2b28b00baa0cece6ddf7f00f4553c4ea41 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/2da9ba2b28b00baa0cece6ddf7f00f4553c4ea41/install.py |
attempdirs = ['/usr/tmp', '/tmp', pwd] | attempdirs = ['/var/tmp', '/usr/tmp', '/tmp', pwd] | def gettempdir(): """Function to calculate the directory to use.""" global tempdir if tempdir is not None: return tempdir try: pwd = os.getcwd() except (AttributeError, os.error): pwd = os.curdir attempdirs = ['/usr/tmp', '/tmp', pwd] if os.name == 'nt': attempdirs.insert(0, 'C:\\TEMP') attempdirs.insert(0, '\\TEMP') elif os.name == 'mac': import macfs, MACFS try: refnum, dirid = macfs.FindFolder(MACFS.kOnSystemDisk, MACFS.kTemporaryFolderType, 1) dirname = macfs.FSSpec((refnum, dirid, '')).as_pathname() attempdirs.insert(0, dirname) except macfs.error: pass for envname in 'TMPDIR', 'TEMP', 'TMP': if os.environ.has_key(envname): attempdirs.insert(0, os.environ[envname]) testfile = gettempprefix() + 'test' for dir in attempdirs: try: filename = os.path.join(dir, testfile) if os.name == 'posix': try: fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700) except OSError: pass else: fp = os.fdopen(fd, 'w') fp.write('blat') fp.close() os.unlink(filename) del fp, fd tempdir = dir break else: fp = open(filename, 'w') fp.write('blat') fp.close() os.unlink(filename) tempdir = dir break except IOError: pass if tempdir is None: msg = "Can't find a usable temporary directory amongst " + `attempdirs` raise IOError, msg return tempdir | 7c2f04ab85b94d92a6eb385bac9dd81794496b22 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/7c2f04ab85b94d92a6eb385bac9dd81794496b22/tempfile.py |
(script, type) = self.tk.splitlist( self.tk.call('after', 'info', id)) | data = self.tk.call('after', 'info', id) script = self.tk.splitlist(data)[0] | def after_cancel(self, id): """Cancel scheduling of function identified with ID. | 65c7667201d31e2ac6edd8d694034869832dcfb2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/65c7667201d31e2ac6edd8d694034869832dcfb2/Tkinter.py |
@bigmemtest(minsize=_2G, memuse=8) | @bigmemtest(minsize=_2G, memuse=9) | def test_repr_large(self, size): return self.basic_test_repr(size) | c30db97d491406a6344c69607b9e51ca88a71765 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/c30db97d491406a6344c69607b9e51ca88a71765/test_bigmem.py |
@bigmemtest(minsize=_2G + 10, memuse=8) | @bigmemtest(minsize=_2G + 10, memuse=9) | def test_index(self, size): l = [1L, 2L, 3L, 4L, 5L] * (size // 5) self.assertEquals(l.index(1), 0) self.assertEquals(l.index(5, size - 5), size - 1) self.assertEquals(l.index(5, size - 5, size), size - 1) self.assertRaises(ValueError, l.index, 1, size - 4, size) self.assertRaises(ValueError, l.index, 6L) | c30db97d491406a6344c69607b9e51ca88a71765 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/c30db97d491406a6344c69607b9e51ca88a71765/test_bigmem.py |
except (ImportError, AttributeError): def _set_cloexec(fd): pass | def _set_cloexec(fd): flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0) if flags >= 0: # flags read successfully, modify flags |= _fcntl.FD_CLOEXEC _fcntl.fcntl(fd, _fcntl.F_SETFD, flags) | a8047a377355243008b7bb2fd756862c2ccb251b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/a8047a377355243008b7bb2fd756862c2ccb251b/tempfile.py |
|
value = apply(f, args) except: value = sys.exc_type exc = sys.exc_info()[:2] else: exc = None if value == output and type(value) is type(output): | value = f(*args) self.assertEqual(output, value) self.assert_(type(output) is type(value)) | def test(method, input, output, *args): if verbose: print '%s.%s%s =? %s... ' % (repr(input), method, args, repr(output)), try: f = getattr(input, method) value = apply(f, args) except: value = sys.exc_type exc = sys.exc_info()[:2] else: exc = None if value == output and type(value) is type(output): # if the original is returned make sure that # this doesn't happen with subclasses if value is input: class usub(unicode): def __repr__(self): return 'usub(%r)' % unicode.__repr__(self) input = usub(input) try: f = getattr(input, method) value = apply(f, args) except: value = sys.exc_type exc = sys.exc_info()[:2] if value is input: if verbose: print 'no' print '*',f, `input`, `output`, `value` return if value != output or type(value) is not type(output): if verbose: print 'no' print '*',f, `input`, `output`, `value` if exc: print ' value == %s: %s' % (exc) else: if verbose: print 'yes' | 2297ca3284c57a984832427dbc81d0141ceff94c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/2297ca3284c57a984832427dbc81d0141ceff94c/test_unicode.py |
try: f = getattr(input, method) value = apply(f, args) except: value = sys.exc_type exc = sys.exc_info()[:2] if value is input: if verbose: print 'no' print '*',f, `input`, `output`, `value` return if value != output or type(value) is not type(output): if verbose: print 'no' print '*',f, `input`, `output`, `value` if exc: print ' value == %s: %s' % (exc) else: if verbose: print 'yes' test('capitalize', u' hello ', u' hello ') test('capitalize', u'Hello ', u'Hello ') test('capitalize', u'hello ', u'Hello ') test('capitalize', u'aaaa', u'Aaaa') test('capitalize', u'AaAa', u'Aaaa') test('count', u'aaa', 3, u'a') test('count', u'aaa', 0, u'b') test('count', 'aaa', 3, u'a') test('count', 'aaa', 0, u'b') test('count', u'aaa', 3, 'a') test('count', u'aaa', 0, 'b') test('title', u' hello ', u' Hello ') test('title', u'Hello ', u'Hello ') test('title', u'hello ', u'Hello ') test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String') test('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String') test('title', u"getInt", u'Getint') test('find', u'abcdefghiabc', 0, u'abc') test('find', u'abcdefghiabc', 9, u'abc', 1) test('find', u'abcdefghiabc', -1, u'def', 4) test('rfind', u'abcdefghiabc', 9, u'abc') test('rfind', 'abcdefghiabc', 9, u'abc') test('rfind', 'abcdefghiabc', 12, u'') test('rfind', u'abcdefghiabc', 12, '') test('rfind', u'abcdefghiabc', 12, u'') test('lower', u'HeLLo', u'hello') test('lower', u'hello', u'hello') test('upper', u'HeLLo', u'HELLO') test('upper', u'HELLO', u'HELLO') if 0: transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !" test('maketrans', u'abc', transtable, u'xyz') test('maketrans', u'abc', ValueError, u'xyzq') test('split', u'this is the split function', [u'this', u'is', u'the', u'split', u'function']) test('split', u'a|b|c|d', [u'a', u'b', u'c', u'd'], u'|') test('split', u'a|b|c|d', [u'a', u'b', u'c|d'], u'|', 2) test('split', u'a b c d', [u'a', u'b c d'], None, 1) test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2) test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 3) test('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 4) test('split', u'a b c d', [u'a b c d'], None, 0) test('split', u'a b c d', [u'a', u'b', u'c d'], None, 2) test('split', u'a b c d ', [u'a', u'b', u'c', u'd']) test('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//') test('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], '//') test('split', 'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//') test('split', u'endcase test', [u'endcase ', u''], u'test') test('split', u'endcase test', [u'endcase ', u''], 'test') test('split', 'endcase test', [u'endcase ', u''], u'test') class Sequence: def __init__(self, seq): self.seq = seq def __len__(self): return len(self.seq) def __getitem__(self, i): return self.seq[i] test('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd']) test('join', u' ', u'a b c d', ['a', 'b', u'c', u'd']) test('join', u'', u'abcd', (u'a', u'b', u'c', u'd')) test('join', u' ', u'w x y z', Sequence('wxyz')) test('join', u' ', TypeError, 7) test('join', u' ', TypeError, Sequence([7, u'hello', 123L])) test('join', ' ', u'a b c d', [u'a', u'b', u'c', u'd']) test('join', ' ', u'a b c d', ['a', 'b', u'c', u'd']) test('join', '', u'abcd', (u'a', u'b', u'c', u'd')) test('join', ' ', u'w x y z', Sequence(u'wxyz')) test('join', ' ', TypeError, 7) result = u'' for i in range(10): if i > 0: result = result + u':' result = result + u'x'*10 test('join', u':', result, [u'x' * 10] * 10) test('join', u':', result, (u'x' * 10,) * 10) test('strip', u' hello ', u'hello') test('lstrip', u' hello ', u'hello ') test('rstrip', u' hello ', u' hello') test('strip', u'hello', u'hello') test('strip', u' hello ', u'hello', None) test('lstrip', u' hello ', u'hello ', None) test('rstrip', u' hello ', u' hello', None) test('strip', u'hello', u'hello', None) test('strip', u'xyzzyhelloxyzzy', u'hello', u'xyz') test('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', u'xyz') test('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', u'xyz') test('strip', u'hello', u'hello', u'xyz') test('strip', u'xyzzyhelloxyzzy', u'hello', 'xyz') test('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', 'xyz') test('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', 'xyz') test('strip', u'hello', u'hello', 'xyz') test('swapcase', u'HeLLo cOmpUteRs', u'hEllO CoMPuTErS') if 0: test('translate', u'xyzabcdef', u'xyzxyz', transtable, u'def') table = string.maketrans('a', u'A') test('translate', u'abc', u'Abc', table) test('translate', u'xyz', u'xyz', table) test('replace', u'one!two!three!', u'one@two!three!', u'!', u'@', 1) test('replace', u'one!two!three!', u'onetwothree', '!', '') test('replace', u'one!two!three!', u'one@two@three!', u'!', u'@', 2) test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 3) test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 4) test('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0) test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@') test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@') test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2) test('replace', u'abc', u'-a-b-c-', u'', u'-') test('replace', u'abc', u'-a-b-c', u'', u'-', 3) test('replace', u'abc', u'abc', u'', u'-', 0) test('replace', u'abc', u'abc', u'ab', u'--', 0) test('replace', u'abc', u'abc', u'xy', u'--') test('replace', u'', u'', u'', u'') test('startswith', u'hello', True, u'he') test('startswith', u'hello', True, u'hello') test('startswith', u'hello', False, u'hello world') test('startswith', u'hello', True, u'') test('startswith', u'hello', False, u'ello') test('startswith', u'hello', True, u'ello', 1) test('startswith', u'hello', True, u'o', 4) test('startswith', u'hello', False, u'o', 5) test('startswith', u'hello', True, u'', 5) test('startswith', u'hello', False, u'lo', 6) test('startswith', u'helloworld', True, u'lowo', 3) test('startswith', u'helloworld', True, u'lowo', 3, 7) test('startswith', u'helloworld', False, u'lowo', 3, 6) test('endswith', u'hello', True, u'lo') test('endswith', u'hello', False, u'he') test('endswith', u'hello', True, u'') test('endswith', u'hello', False, u'hello world') test('endswith', u'helloworld', False, u'worl') test('endswith', u'helloworld', True, u'worl', 3, 9) test('endswith', u'helloworld', True, u'world', 3, 12) test('endswith', u'helloworld', True, u'lowo', 1, 7) test('endswith', u'helloworld', True, u'lowo', 2, 7) test('endswith', u'helloworld', True, u'lowo', 3, 7) test('endswith', u'helloworld', False, u'lowo', 4, 7) test('endswith', u'helloworld', False, u'lowo', 3, 8) test('endswith', u'ab', False, u'ab', 0, 1) test('endswith', u'ab', False, u'ab', 0, 0) test('endswith', 'helloworld', True, u'd') test('endswith', 'helloworld', False, u'l') test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi') test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8) test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4) test('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4) test('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4) if 0: test('capwords', u'abc def ghi', u'Abc Def Ghi') test('capwords', u'abc\tdef\nghi', u'Abc Def Ghi') test('capwords', u'abc\t def \nghi', u'Abc Def Ghi') test('zfill', u'123', u'123', 2) test('zfill', u'123', u'123', 3) test('zfill', u'123', u'0123', 4) test('zfill', u'+123', u'+123', 3) test('zfill', u'+123', u'+123', 4) test('zfill', u'+123', u'+0123', 5) test('zfill', u'-123', u'-123', 3) test('zfill', u'-123', u'-123', 4) test('zfill', u'-123', u'-0123', 5) test('zfill', u'', u'000', 3) test('zfill', u'34', u'34', 1) test('zfill', u'34', u'00034', 5) print 'Testing Unicode comparisons...', verify(u'abc' == 'abc') verify('abc' == u'abc') verify(u'abc' == u'abc') verify(u'abcd' > 'abc') verify('abcd' > u'abc') verify(u'abcd' > u'abc') verify(u'abc' < 'abcd') verify('abc' < u'abcd') verify(u'abc' < u'abcd') print 'done.' if 0: print 'Testing UTF-16 code point order comparisons...', verify(u'\u0061' < u'\u20ac') verify(u'\u0061' < u'\ud800\udc02') def test_lecmp(s, s2): verify(s < s2 , "comparison failed on %s < %s" % (s, s2)) def test_fixup(s): s2 = u'\ud800\udc01' test_lecmp(s, s2) s2 = u'\ud900\udc01' test_lecmp(s, s2) s2 = u'\uda00\udc01' test_lecmp(s, s2) s2 = u'\udb00\udc01' test_lecmp(s, s2) s2 = u'\ud800\udd01' test_lecmp(s, s2) s2 = u'\ud900\udd01' test_lecmp(s, s2) s2 = u'\uda00\udd01' test_lecmp(s, s2) s2 = u'\udb00\udd01' test_lecmp(s, s2) s2 = u'\ud800\ude01' test_lecmp(s, s2) s2 = u'\ud900\ude01' test_lecmp(s, s2) s2 = u'\uda00\ude01' test_lecmp(s, s2) s2 = u'\udb00\ude01' test_lecmp(s, s2) s2 = u'\ud800\udfff' test_lecmp(s, s2) s2 = u'\ud900\udfff' test_lecmp(s, s2) s2 = u'\uda00\udfff' test_lecmp(s, s2) s2 = u'\udb00\udfff' test_lecmp(s, s2) test_fixup(u'\ue000') test_fixup(u'\uff61') verify(u'\ud800\udc02' < u'\ud84d\udc56') print 'done.' test('ljust', u'abc', u'abc ', 10) test('rjust', u'abc', u' abc', 10) test('center', u'abc', u' abc ', 10) test('ljust', u'abc', u'abc ', 6) test('rjust', u'abc', u' abc', 6) test('center', u'abc', u' abc ', 6) test('ljust', u'abc', u'abc', 2) test('rjust', u'abc', u'abc', 2) test('center', u'abc', u'abc', 2) test('islower', u'a', True) test('islower', u'A', False) test('islower', u'\n', False) test('islower', u'\u1FFc', False) test('islower', u'abc', True) test('islower', u'aBc', False) test('islower', u'abc\n', True) test('isupper', u'a', False) test('isupper', u'A', True) test('isupper', u'\n', False) if sys.platform[:4] != 'java': test('isupper', u'\u1FFc', False) test('isupper', u'ABC', True) test('isupper', u'AbC', False) test('isupper', u'ABC\n', True) test('istitle', u'a', False) test('istitle', u'A', True) test('istitle', u'\n', False) test('istitle', u'\u1FFc', True) test('istitle', u'A Titlecased Line', True) test('istitle', u'A\nTitlecased Line', True) test('istitle', u'A Titlecased, Line', True) test('istitle', u'Greek \u1FFcitlecases ...', True) test('istitle', u'Not a capitalized String', False) test('istitle', u'Not\ta Titlecase String', False) test('istitle', u'Not--a Titlecase String', False) test('isalpha', u'a', True) test('isalpha', u'A', True) test('isalpha', u'\n', False) test('isalpha', u'\u1FFc', True) test('isalpha', u'abc', True) test('isalpha', u'aBc123', False) test('isalpha', u'abc\n', False) test('isalnum', u'a', True) test('isalnum', u'A', True) test('isalnum', u'\n', False) test('isalnum', u'123abc456', True) test('isalnum', u'a1b3c', True) test('isalnum', u'aBc000 ', False) test('isalnum', u'abc\n', False) test('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi']) test('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi']) test('splitlines', u"abc\ndef\r\nghi", [u'abc', u'def', u'ghi']) test('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi']) test('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u'']) test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u'']) test('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], True) test('translate', u"abababc", u'bbbc', {ord('a'):None}) test('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')}) test('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'}) test('translate', u"abababc", u'<i><i><i>c', {ord('a'):None, ord('b'):u'<i>'}) test('translate', u"abababc", u'c', {ord('a'):None, ord('b'):u''}) print 'Testing Unicode contains method...', vereq(('a' in u'abdb'), True) vereq(('a' in u'bdab'), True) vereq(('a' in u'bdaba'), True) vereq(('a' in u'bdba'), True) vereq(('a' in u'bdba'), True) vereq((u'a' in u'bdba'), True) vereq((u'a' in u'bdb'), False) vereq((u'a' in 'bdb'), False) vereq((u'a' in 'bdba'), True) vereq((u'a' in ('a',1,None)), True) vereq((u'a' in (1,None,'a')), True) vereq((u'a' in (1,None,u'a')), True) vereq(('a' in ('a',1,None)), True) vereq(('a' in (1,None,'a')), True) vereq(('a' in (1,None,u'a')), True) vereq(('a' in ('x',1,u'y')), False) vereq(('a' in ('x',1,None)), False) vereq(u'abcd' in u'abcxxxx', False) vereq((u'ab' in u'abcd'), True) vereq(('ab' in u'abc'), True) vereq((u'ab' in 'abc'), True) vereq((u'ab' in (1,None,u'ab')), True) vereq((u'' in u'abc'), True) vereq(('' in u'abc'), True) try: u'\xe2' in 'g\xe2teau' except UnicodeError: pass else: print '*** contains operator does not propagate UnicodeErrors' print 'done.' print 'Testing Unicode formatting strings...', verify(u"%s, %s" % (u"abc", "abc") == u'abc, abc') verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3) == u'abc, abc, 1, 2.000000, 3.00') verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3) == u'abc, abc, 1, -2.000000, 3.00') verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5) == u'abc, abc, -1, -2.000000, 3.50') verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57) == u'abc, abc, -1, -2.000000, 3.57') verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57) == u'abc, abc, -1, -2.000000, 1003.57') verify(u"%c" % (u"a",) == u'a') verify(u"%c" % ("a",) == u'a') verify(u"%c" % (34,) == u'"') verify(u"%c" % (36,) == u'$') verify(u"%d".__mod__(10) == u'10') if sys.platform[:4] != 'java': value = u"%r, %r" % (u"abc", "abc") if value != u"u'abc', 'abc'": print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")' verify(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def') try: value = u"%(x)s, %()s" % {'x':u"abc", u'':"def"} except KeyError: print '*** formatting failed for "%s"' % "u'abc, def'" else: verify(value == u'abc, def') for ordinal in (-100, 0x200000): try: u"%c" % ordinal except ValueError: pass else: print '*** formatting u"%%c" %% %i should give a ValueError' % ordinal for prec in range(100): formatstring = u'%%.%if' % prec value = 0.01 for x in range(60): value = value * 3.141592655 / 3.0 * 10.0 try: result = formatstring % value except OverflowError: if x >= 50 or \ prec < 67: print '*** unexpected OverflowError for x=%i and prec=%i' % (x, prec) | f = getattr(input, method) value = f(*args) self.assertEqual(output, value) self.assert_(input is not value) def test_capitalize(self): self.checkmethod('capitalize', u' hello ', u' hello ') self.checkmethod('capitalize', u'Hello ', u'Hello ') self.checkmethod('capitalize', u'hello ', u'Hello ') self.checkmethod('capitalize', u'aaaa', u'Aaaa') self.checkmethod('capitalize', u'AaAa', u'Aaaa') self.assertRaises(TypeError, u'hello'.capitalize, 42) def test_count(self): self.checkmethod('count', u'aaa', 3, u'a') self.checkmethod('count', u'aaa', 0, u'b') self.checkmethod('count', 'aaa', 3, u'a') self.checkmethod('count', 'aaa', 0, u'b') self.checkmethod('count', u'aaa', 3, 'a') self.checkmethod('count', u'aaa', 0, 'b') self.assertRaises(TypeError, u'hello'.count) def test_title(self): self.checkmethod('title', u' hello ', u' Hello ') self.checkmethod('title', u'Hello ', u'Hello ') self.checkmethod('title', u'hello ', u'Hello ') self.checkmethod('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String') self.checkmethod('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String') self.checkmethod('title', u"getInt", u'Getint') self.assertRaises(TypeError, u'hello'.count, 42) def test_find(self): self.checkmethod('find', u'abcdefghiabc', 0, u'abc') self.checkmethod('find', u'abcdefghiabc', 9, u'abc', 1) self.checkmethod('find', u'abcdefghiabc', -1, u'def', 4) self.assertRaises(TypeError, u'hello'.find) self.assertRaises(TypeError, u'hello'.find, 42) def test_rfind(self): self.checkmethod('rfind', u'abcdefghiabc', 9, u'abc') self.checkmethod('rfind', 'abcdefghiabc', 9, u'abc') self.checkmethod('rfind', 'abcdefghiabc', 12, u'') self.checkmethod('rfind', u'abcdefghiabc', 12, '') self.checkmethod('rfind', u'abcdefghiabc', 12, u'') self.assertRaises(TypeError, u'hello'.rfind) self.assertRaises(TypeError, u'hello'.rfind, 42) def test_index(self): self.checkmethod('index', u'abcdefghiabc', 0, u'') self.checkmethod('index', u'abcdefghiabc', 3, u'def') self.checkmethod('index', u'abcdefghiabc', 0, u'abc') self.checkmethod('index', u'abcdefghiabc', 9, u'abc', 1) self.assertRaises(ValueError, u'abcdefghiabc'.index, u'hib') self.assertRaises(ValueError, u'abcdefghiab'.index, u'abc', 1) self.assertRaises(ValueError, u'abcdefghi'.index, u'ghi', 8) self.assertRaises(ValueError, u'abcdefghi'.index, u'ghi', -1) self.assertRaises(TypeError, u'hello'.index) self.assertRaises(TypeError, u'hello'.index, 42) def test_rindex(self): self.checkmethod('rindex', u'abcdefghiabc', 12, u'') self.checkmethod('rindex', u'abcdefghiabc', 3, u'def') self.checkmethod('rindex', u'abcdefghiabc', 9, u'abc') self.checkmethod('rindex', u'abcdefghiabc', 0, u'abc', 0, -1) self.assertRaises(ValueError, u'abcdefghiabc'.rindex, u'hib') self.assertRaises(ValueError, u'defghiabc'.rindex, u'def', 1) self.assertRaises(ValueError, u'defghiabc'.rindex, u'abc', 0, -1) self.assertRaises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, 8) self.assertRaises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, -1) self.assertRaises(TypeError, u'hello'.rindex) self.assertRaises(TypeError, u'hello'.rindex, 42) def test_lower(self): self.checkmethod('lower', u'HeLLo', u'hello') self.checkmethod('lower', u'hello', u'hello') self.assertRaises(TypeError, u"hello".lower, 42) def test_upper(self): self.checkmethod('upper', u'HeLLo', u'HELLO') self.checkmethod('upper', u'HELLO', u'HELLO') self.assertRaises(TypeError, u'hello'.upper, 42) def test_translate(self): if 0: transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !" self.checkmethod('maketrans', u'abc', transtable, u'xyz') self.checkmethod('maketrans', u'abc', ValueError, u'xyzq') self.checkmethod('translate', u'xyzabcdef', u'xyzxyz', transtable, u'def') table = string.maketrans('a', u'A') self.checkmethod('translate', u'abc', u'Abc', table) self.checkmethod('translate', u'xyz', u'xyz', table) self.checkmethod('translate', u"abababc", u'bbbc', {ord('a'):None}) self.checkmethod('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')}) self.checkmethod('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'}) self.checkmethod('translate', u"abababc", u'<i><i><i>c', {ord('a'):None, ord('b'):u'<i>'}) self.checkmethod('translate', u"abababc", u'c', {ord('a'):None, ord('b'):u''}) self.assertRaises(TypeError, u'hello'.translate) def test_split(self): self.checkmethod( 'split', u'this is the split function', [u'this', u'is', u'the', u'split', u'function'] ) self.checkmethod('split', u'a|b|c|d', [u'a', u'b', u'c', u'd'], u'|') self.checkmethod('split', u'a|b|c|d', [u'a', u'b', u'c|d'], u'|', 2) self.checkmethod('split', u'a b c d', [u'a', u'b c d'], None, 1) self.checkmethod('split', u'a b c d', [u'a', u'b', u'c d'], None, 2) self.checkmethod('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 3) self.checkmethod('split', u'a b c d', [u'a', u'b', u'c', u'd'], None, 4) self.checkmethod('split', u'a b c d', [u'a b c d'], None, 0) self.checkmethod('split', u'a b c d', [u'a', u'b', u'c d'], None, 2) self.checkmethod('split', u'a b c d ', [u'a', u'b', u'c', u'd']) self.checkmethod('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//') self.checkmethod('split', u'a//b//c//d', [u'a', u'b', u'c', u'd'], '//') self.checkmethod('split', 'a//b//c//d', [u'a', u'b', u'c', u'd'], u'//') self.checkmethod('split', u'endcase test', [u'endcase ', u''], u'test') self.checkmethod('split', u'endcase test', [u'endcase ', u''], 'test') self.checkmethod('split', 'endcase test', [u'endcase ', u''], u'test') self.assertRaises(TypeError, u"hello".split, 42, 42, 42) def test_join(self): class Sequence: def __init__(self, seq): self.seq = seq def __len__(self): return len(self.seq) def __getitem__(self, i): return self.seq[i] self.checkmethod('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd']) self.checkmethod('join', u' ', u'a b c d', ['a', 'b', u'c', u'd']) self.checkmethod('join', u'', u'abcd', (u'a', u'b', u'c', u'd')) self.checkmethod('join', u' ', u'w x y z', Sequence('wxyz')) self.assertRaises(TypeError, u' '.join, 7) self.assertRaises(TypeError, u' '.join, Sequence([7, u'hello', 123L])) self.checkmethod('join', ' ', u'a b c d', [u'a', u'b', u'c', u'd']) self.checkmethod('join', ' ', u'a b c d', ['a', 'b', u'c', u'd']) self.checkmethod('join', '', u'abcd', (u'a', u'b', u'c', u'd')) self.checkmethod('join', ' ', u'w x y z', Sequence(u'wxyz')) self.assertRaises(TypeError, ' '.join, TypeError) result = u'' for i in range(10): if i > 0: result = result + u':' result = result + u'x'*10 self.checkmethod('join', u':', result, [u'x' * 10] * 10) self.checkmethod('join', u':', result, (u'x' * 10,) * 10) self.assertRaises(TypeError, u"hello".join) def test_strip(self): self.checkmethod('strip', u' hello ', u'hello') self.checkmethod('lstrip', u' hello ', u'hello ') self.checkmethod('rstrip', u' hello ', u' hello') self.checkmethod('strip', u'hello', u'hello') self.checkmethod('strip', u' hello ', u'hello', None) self.checkmethod('lstrip', u' hello ', u'hello ', None) self.checkmethod('rstrip', u' hello ', u' hello', None) self.checkmethod('strip', u'hello', u'hello', None) self.checkmethod('strip', u'xyzzyhelloxyzzy', u'hello', u'xyz') self.checkmethod('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', u'xyz') self.checkmethod('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', u'xyz') self.checkmethod('strip', u'hello', u'hello', u'xyz') self.checkmethod('strip', u'xyzzyhelloxyzzy', u'hello', 'xyz') self.checkmethod('lstrip', u'xyzzyhelloxyzzy', u'helloxyzzy', 'xyz') self.checkmethod('rstrip', u'xyzzyhelloxyzzy', u'xyzzyhello', 'xyz') self.checkmethod('strip', u'hello', u'hello', 'xyz') self.assertRaises(TypeError, u"hello".strip, 42, 42) self.assertRaises(UnicodeError, u"hello".strip, "\xff") def test_swapcase(self): self.checkmethod('swapcase', u'HeLLo cOmpUteRs', u'hEllO CoMPuTErS') self.assertRaises(TypeError, u"hello".swapcase, 42) def test_replace(self): self.checkmethod('replace', u'one!two!three!', u'one@two!three!', u'!', u'@', 1) self.checkmethod('replace', u'one!two!three!', u'onetwothree', '!', '') self.checkmethod('replace', u'one!two!three!', u'one@two@three!', u'!', u'@', 2) self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 3) self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@', 4) self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0) self.checkmethod('replace', u'one!two!three!', u'one@two@three@', u'!', u'@') self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'x', u'@') self.checkmethod('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2) self.checkmethod('replace', u'abc', u'-a-b-c-', u'', u'-') self.checkmethod('replace', u'abc', u'-a-b-c', u'', u'-', 3) self.checkmethod('replace', u'abc', u'abc', u'', u'-', 0) self.checkmethod('replace', u'abc', u'abc', u'ab', u'--', 0) self.checkmethod('replace', u'abc', u'abc', u'xy', u'--') self.checkmethod('replace', u'', u'', u'', u'') self.checkmethod('replace', 'one!two!three!', u'one@two!three!', u'!', u'@', 1) self.assertRaises(TypeError, 'replace'.replace, 42) self.assertRaises(TypeError, 'replace'.replace, u"r", 42) self.assertRaises(TypeError, u"hello".replace) self.assertRaises(TypeError, u"hello".replace, 42, u"h") self.assertRaises(TypeError, u"hello".replace, u"h", 42) def test_startswith(self): self.checkmethod('startswith', u'hello', True, u'he') self.checkmethod('startswith', u'hello', True, u'hello') self.checkmethod('startswith', u'hello', False, u'hello world') self.checkmethod('startswith', u'hello', True, u'') self.checkmethod('startswith', u'hello', False, u'ello') self.checkmethod('startswith', u'hello', True, u'ello', 1) self.checkmethod('startswith', u'hello', True, u'o', 4) self.checkmethod('startswith', u'hello', False, u'o', 5) self.checkmethod('startswith', u'hello', True, u'', 5) self.checkmethod('startswith', u'hello', False, u'lo', 6) self.checkmethod('startswith', u'helloworld', True, u'lowo', 3) self.checkmethod('startswith', u'helloworld', True, u'lowo', 3, 7) self.checkmethod('startswith', u'helloworld', False, u'lowo', 3, 6) self.assertRaises(TypeError, u"hello".startswith) self.assertRaises(TypeError, u"hello".startswith, 42) def test_endswith(self): self.checkmethod('endswith', u'hello', True, u'lo') self.checkmethod('endswith', u'hello', False, u'he') self.checkmethod('endswith', u'hello', True, u'') self.checkmethod('endswith', u'hello', False, u'hello world') self.checkmethod('endswith', u'helloworld', False, u'worl') self.checkmethod('endswith', u'helloworld', True, u'worl', 3, 9) self.checkmethod('endswith', u'helloworld', True, u'world', 3, 12) self.checkmethod('endswith', u'helloworld', True, u'lowo', 1, 7) self.checkmethod('endswith', u'helloworld', True, u'lowo', 2, 7) self.checkmethod('endswith', u'helloworld', True, u'lowo', 3, 7) self.checkmethod('endswith', u'helloworld', False, u'lowo', 4, 7) self.checkmethod('endswith', u'helloworld', False, u'lowo', 3, 8) self.checkmethod('endswith', u'ab', False, u'ab', 0, 1) self.checkmethod('endswith', u'ab', False, u'ab', 0, 0) self.checkmethod('endswith', 'helloworld', True, u'd') self.checkmethod('endswith', 'helloworld', False, u'l') self.assertRaises(TypeError, u"hello".endswith) self.assertRaises(TypeError, u"hello".endswith, 42) def test_expandtabs(self): self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi') self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 8) self.checkmethod('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab def\ng hi', 4) self.checkmethod('expandtabs', u'abc\r\nab\tdef\ng\thi', u'abc\r\nab def\ng hi', 4) self.checkmethod('expandtabs', u'abc\r\nab\r\ndef\ng\r\nhi', u'abc\r\nab\r\ndef\ng\r\nhi', 4) self.assertRaises(TypeError, u"hello".expandtabs, 42, 42) def test_capwords(self): if 0: self.checkmethod('capwords', u'abc def ghi', u'Abc Def Ghi') self.checkmethod('capwords', u'abc\tdef\nghi', u'Abc Def Ghi') self.checkmethod('capwords', u'abc\t def \nghi', u'Abc Def Ghi') def test_zfill(self): self.checkmethod('zfill', u'123', u'123', 2) self.checkmethod('zfill', u'123', u'123', 3) self.checkmethod('zfill', u'123', u'0123', 4) self.checkmethod('zfill', u'+123', u'+123', 3) self.checkmethod('zfill', u'+123', u'+123', 4) self.checkmethod('zfill', u'+123', u'+0123', 5) self.checkmethod('zfill', u'-123', u'-123', 3) self.checkmethod('zfill', u'-123', u'-123', 4) self.checkmethod('zfill', u'-123', u'-0123', 5) self.checkmethod('zfill', u'', u'000', 3) self.checkmethod('zfill', u'34', u'34', 1) self.checkmethod('zfill', u'34', u'00034', 5) self.assertRaises(TypeError, u"123".zfill) def test_comparison(self): self.assertEqual(u'abc', 'abc') self.assertEqual('abc', u'abc') self.assertEqual(u'abc', u'abc') self.assert_(u'abcd' > 'abc') self.assert_('abcd' > u'abc') self.assert_(u'abcd' > u'abc') self.assert_(u'abc' < 'abcd') self.assert_('abc' < u'abcd') self.assert_(u'abc' < u'abcd') if 0: self.assert_(u'\u0061' < u'\u20ac') self.assert_(u'\u0061' < u'\ud800\udc02') def test_lecmp(s, s2): self.assert_(s < s2) def test_fixup(s): s2 = u'\ud800\udc01' test_lecmp(s, s2) s2 = u'\ud900\udc01' test_lecmp(s, s2) s2 = u'\uda00\udc01' test_lecmp(s, s2) s2 = u'\udb00\udc01' test_lecmp(s, s2) s2 = u'\ud800\udd01' test_lecmp(s, s2) s2 = u'\ud900\udd01' test_lecmp(s, s2) s2 = u'\uda00\udd01' test_lecmp(s, s2) s2 = u'\udb00\udd01' test_lecmp(s, s2) s2 = u'\ud800\ude01' test_lecmp(s, s2) s2 = u'\ud900\ude01' test_lecmp(s, s2) s2 = u'\uda00\ude01' test_lecmp(s, s2) s2 = u'\udb00\ude01' test_lecmp(s, s2) s2 = u'\ud800\udfff' test_lecmp(s, s2) s2 = u'\ud900\udfff' test_lecmp(s, s2) s2 = u'\uda00\udfff' test_lecmp(s, s2) s2 = u'\udb00\udfff' test_lecmp(s, s2) test_fixup(u'\ue000') test_fixup(u'\uff61') self.assert_(u'\ud800\udc02' < u'\ud84d\udc56') def test_ljust(self): self.checkmethod('ljust', u'abc', u'abc ', 10) self.checkmethod('ljust', u'abc', u'abc ', 6) self.checkmethod('ljust', u'abc', u'abc', 2) self.assertRaises(TypeError, u"abc".ljust) def test_rjust(self): self.checkmethod('rjust', u'abc', u' abc', 10) self.checkmethod('rjust', u'abc', u' abc', 6) self.checkmethod('rjust', u'abc', u'abc', 2) self.assertRaises(TypeError, u"abc".rjust) def test_center(self): self.checkmethod('center', u'abc', u' abc ', 10) self.checkmethod('center', u'abc', u' abc ', 6) self.checkmethod('center', u'abc', u'abc', 2) self.assertRaises(TypeError, u"abc".center) def test_islower(self): self.checkmethod('islower', u'', False) self.checkmethod('islower', u'a', True) self.checkmethod('islower', u'A', False) self.checkmethod('islower', u'\n', False) self.checkmethod('islower', u'\u1FFc', False) self.checkmethod('islower', u'abc', True) self.checkmethod('islower', u'aBc', False) self.checkmethod('islower', u'abc\n', True) self.assertRaises(TypeError, u"abc".islower, 42) def test_isupper(self): self.checkmethod('isupper', u'', False) self.checkmethod('isupper', u'a', False) self.checkmethod('isupper', u'A', True) self.checkmethod('isupper', u'\n', False) if sys.platform[:4] != 'java': self.checkmethod('isupper', u'\u1FFc', False) self.checkmethod('isupper', u'ABC', True) self.checkmethod('isupper', u'AbC', False) self.checkmethod('isupper', u'ABC\n', True) self.assertRaises(TypeError, u"abc".isupper, 42) def test_istitle(self): self.checkmethod('istitle', u'', False) self.checkmethod('istitle', u'a', False) self.checkmethod('istitle', u'A', True) self.checkmethod('istitle', u'\n', False) self.checkmethod('istitle', u'\u1FFc', True) self.checkmethod('istitle', u'A Titlecased Line', True) self.checkmethod('istitle', u'A\nTitlecased Line', True) self.checkmethod('istitle', u'A Titlecased, Line', True) self.checkmethod('istitle', u'Greek \u1FFcitlecases ...', True) self.checkmethod('istitle', u'Not a capitalized String', False) self.checkmethod('istitle', u'Not\ta Titlecase String', False) self.checkmethod('istitle', u'Not--a Titlecase String', False) self.checkmethod('istitle', u'NOT', False) self.assertRaises(TypeError, u"abc".istitle, 42) def test_isspace(self): self.checkmethod('isspace', u'', False) self.checkmethod('isspace', u'a', False) self.checkmethod('isspace', u' ', True) self.checkmethod('isspace', u'\t', True) self.checkmethod('isspace', u'\r', True) self.checkmethod('isspace', u'\n', True) self.checkmethod('isspace', u' \t\r\n', True) self.checkmethod('isspace', u' \t\r\na', False) self.assertRaises(TypeError, u"abc".isspace, 42) def test_isalpha(self): self.checkmethod('isalpha', u'', False) self.checkmethod('isalpha', u'a', True) self.checkmethod('isalpha', u'A', True) self.checkmethod('isalpha', u'\n', False) self.checkmethod('isalpha', u'\u1FFc', True) self.checkmethod('isalpha', u'abc', True) self.checkmethod('isalpha', u'aBc123', False) self.checkmethod('isalpha', u'abc\n', False) self.assertRaises(TypeError, u"abc".isalpha, 42) def test_isalnum(self): self.checkmethod('isalnum', u'', False) self.checkmethod('isalnum', u'a', True) self.checkmethod('isalnum', u'A', True) self.checkmethod('isalnum', u'\n', False) self.checkmethod('isalnum', u'123abc456', True) self.checkmethod('isalnum', u'a1b3c', True) self.checkmethod('isalnum', u'aBc000 ', False) self.checkmethod('isalnum', u'abc\n', False) self.assertRaises(TypeError, u"abc".isalnum, 42) def test_isdecimal(self): self.checkmethod('isdecimal', u'', False) self.checkmethod('isdecimal', u'a', False) self.checkmethod('isdecimal', u'0', True) self.checkmethod('isdecimal', u'\u2460', False) self.checkmethod('isdecimal', u'\xbc', False) self.checkmethod('isdecimal', u'\u0660', True) self.checkmethod('isdecimal', u'0123456789', True) self.checkmethod('isdecimal', u'0123456789a', False) self.assertRaises(TypeError, u"abc".isdecimal, 42) def test_isdigit(self): self.checkmethod('isdigit', u'', False) self.checkmethod('isdigit', u'a', False) self.checkmethod('isdigit', u'0', True) self.checkmethod('isdigit', u'\u2460', True) self.checkmethod('isdigit', u'\xbc', False) self.checkmethod('isdigit', u'\u0660', True) self.checkmethod('isdigit', u'0123456789', True) self.checkmethod('isdigit', u'0123456789a', False) self.assertRaises(TypeError, u"abc".isdigit, 42) def test_isnumeric(self): self.checkmethod('isnumeric', u'', False) self.checkmethod('isnumeric', u'a', False) self.checkmethod('isnumeric', u'0', True) self.checkmethod('isnumeric', u'\u2460', True) self.checkmethod('isnumeric', u'\xbc', True) self.checkmethod('isnumeric', u'\u0660', True) self.checkmethod('isnumeric', u'0123456789', True) self.checkmethod('isnumeric', u'0123456789a', False) self.assertRaises(TypeError, u"abc".isnumeric, 42) def test_splitlines(self): self.checkmethod('splitlines', u"abc\ndef\n\rghi", [u'abc', u'def', u'', u'ghi']) self.checkmethod('splitlines', u"abc\ndef\n\r\nghi", [u'abc', u'def', u'', u'ghi']) self.checkmethod('splitlines', u"abc\ndef\r\nghi", [u'abc', u'def', u'ghi']) self.checkmethod('splitlines', u"abc\ndef\r\nghi\n", [u'abc', u'def', u'ghi']) self.checkmethod('splitlines', u"abc\ndef\r\nghi\n\r", [u'abc', u'def', u'ghi', u'']) self.checkmethod('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'', u'abc', u'def', u'ghi', u'']) self.checkmethod('splitlines', u"\nabc\ndef\r\nghi\n\r", [u'\n', u'abc\n', u'def\r\n', u'ghi\n', u'\r'], True) self.assertRaises(TypeError, u"abc".splitlines, 42, 42) def test_contains(self): self.assert_('a' in u'abdb') self.assert_('a' in u'bdab') self.assert_('a' in u'bdaba') self.assert_('a' in u'bdba') self.assert_('a' in u'bdba') self.assert_(u'a' in u'bdba') self.assert_(u'a' not in u'bdb') self.assert_(u'a' not in 'bdb') self.assert_(u'a' in 'bdba') self.assert_(u'a' in ('a',1,None)) self.assert_(u'a' in (1,None,'a')) self.assert_(u'a' in (1,None,u'a')) self.assert_('a' in ('a',1,None)) self.assert_('a' in (1,None,'a')) self.assert_('a' in (1,None,u'a')) self.assert_('a' not in ('x',1,u'y')) self.assert_('a' not in ('x',1,None)) self.assert_(u'abcd' not in u'abcxxxx') self.assert_(u'ab' in u'abcd') self.assert_('ab' in u'abc') self.assert_(u'ab' in 'abc') self.assert_(u'ab' in (1,None,u'ab')) self.assert_(u'' in u'abc') self.assert_('' in u'abc') self.assertRaises(UnicodeError, 'g\xe2teau'.__contains__, u'\xe2') self.assert_(u'' in '') self.assert_('' in u'') self.assert_(u'' in u'') self.assert_(u'' in 'abc') self.assert_('' in u'abc') self.assert_(u'' in u'abc') self.assert_(u'\0' not in 'abc') self.assert_('\0' not in u'abc') self.assert_(u'\0' not in u'abc') self.assert_(u'\0' in '\0abc') self.assert_('\0' in u'\0abc') self.assert_(u'\0' in u'\0abc') self.assert_(u'\0' in 'abc\0') self.assert_('\0' in u'abc\0') self.assert_(u'\0' in u'abc\0') self.assert_(u'a' in '\0abc') self.assert_('a' in u'\0abc') self.assert_(u'a' in u'\0abc') self.assert_(u'asdf' in 'asdf') self.assert_('asdf' in u'asdf') self.assert_(u'asdf' in u'asdf') self.assert_(u'asdf' not in 'asd') self.assert_('asdf' not in u'asd') self.assert_(u'asdf' not in u'asd') self.assert_(u'asdf' not in '') self.assert_('asdf' not in u'') self.assert_(u'asdf' not in u'') self.assertRaises(TypeError, u"abc".__contains__) def test_formatting(self): self.assertEqual(u"%s, %s" % (u"abc", "abc"), u'abc, abc') self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3), u'abc, abc, 1, 2.000000, 3.00') self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3), u'abc, abc, 1, -2.000000, 3.00') self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5), u'abc, abc, -1, -2.000000, 3.50') self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57), u'abc, abc, -1, -2.000000, 3.57') self.assertEqual(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57), u'abc, abc, -1, -2.000000, 1003.57') self.assertEqual(u"%c" % (u"a",), u'a') self.assertEqual(u"%c" % ("a",), u'a') self.assertEqual(u"%c" % (34,), u'"') self.assertEqual(u"%c" % (36,), u'$') self.assertEqual(u"%d".__mod__(10), u'10') if not sys.platform.startswith('java'): self.assertEqual(u"%r, %r" % (u"abc", "abc"), u"u'abc', 'abc'") self.assertEqual(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"}, u'abc, def') self.assertEqual(u"%(x)s, %()s" % {'x':u"abc", u'':"def"}, u'abc, def') for ordinal in (-100, 0x200000): self.assertRaises(ValueError, u"%c".__mod__, ordinal) for prec in xrange(100): format = u'%%.%if' % prec value = 0.01 for x in xrange(60): value = value * 3.141592655 / 3.0 * 10.0 if x < 50 and prec >= 67: self.assertRaises(OverflowError, format.__mod__, value) else: format % value self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...') self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') self.assertEqual('...%(foo)s...' % {u'foo':"abc"}, '...abc...') self.assertEqual('...%(foo)s...' % {u'foo':u"abc"}, u'...abc...') self.assertEqual('...%(foo)s...' % {u'foo':u"abc",'def':123}, u'...abc...') self.assertEqual('...%(foo)s...' % {u'foo':u"abc",u'def':123}, u'...abc...') self.assertEqual('...%s...%s...%s...%s...' % (1,2,3,u"abc"), u'...1...2...3...abc...') self.assertEqual('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc"), u'...%...%s...1...2...3...abc...') self.assertEqual('...%s...' % u"abc", u'...abc...') self.assertEqual('%*s' % (5,u'abc',), u' abc') self.assertEqual('%*s' % (-5,u'abc',), u'abc ') self.assertEqual('%*.*s' % (5,2,u'abc',), u' ab') self.assertEqual('%*.*s' % (5,3,u'abc',), u' abc') self.assertEqual('%i %*.*s' % (10, 5,3,u'abc',), u'10 abc') self.assertEqual('%i%s %*.*s' % (10, 3, 5,3,u'abc',), u'103 abc') self.assertEqual(u'%3ld' % 42, u' 42') self.assertEqual(u'%07.2f' % 42, u'0042.00') self.assertRaises(TypeError, u"abc".__mod__) self.assertRaises(TypeError, u"%(foo)s".__mod__, 42) self.assertRaises(TypeError, u"%s%s".__mod__, (42,)) self.assertRaises(TypeError, u"%c".__mod__, (None,)) self.assertRaises(ValueError, u"%c".__mod__, (sys.maxunicode+1,)) self.assertRaises(ValueError, u"%(foo".__mod__, {}) self.assertRaises(TypeError, u"%(foo)s %(bar)s".__mod__, (u"foo", 42)) self.assertEqual(u"%((foo))s" % {u"(foo)": u"bar"}, u"bar") self.assertEqual(u"%sx" % (103*u"a"), 103*u"a"+u"x") self.assertRaises(TypeError, u"%*s".__mod__, (u"foo", u"bar")) self.assertRaises(TypeError, u"%10.*f".__mod__, (u"foo", 42.)) self.assertRaises(ValueError, u"%10".__mod__, (42,)) def test_constructor(self): self.assertEqual( unicode(u'unicode remains unicode'), u'unicode remains unicode' ) class UnicodeSubclass(unicode): pass self.assertEqual( unicode(UnicodeSubclass('unicode subclass becomes unicode')), u'unicode subclass becomes unicode' ) self.assertEqual( unicode('strings are converted to unicode'), u'strings are converted to unicode' ) class UnicodeCompat: def __init__(self, x): self.x = x def __unicode__(self): return self.x self.assertEqual( unicode(UnicodeCompat('__unicode__ compatible objects are recognized')), u'__unicode__ compatible objects are recognized') class StringCompat: def __init__(self, x): self.x = x def __str__(self): return self.x self.assertEqual( unicode(StringCompat('__str__ compatible objects are recognized')), u'__str__ compatible objects are recognized' ) o = StringCompat('unicode(obj) is compatible to str()') self.assertEqual(unicode(o), u'unicode(obj) is compatible to str()') self.assertEqual(str(o), 'unicode(obj) is compatible to str()') for obj in (123, 123.45, 123L): self.assertEqual(unicode(obj), unicode(str(obj))) if not sys.platform.startswith('java'): self.assertRaises( TypeError, unicode, u'decoding unicode is not supported', 'utf-8', 'strict' ) self.assertEqual( unicode('strings are decoded to unicode', 'utf-8', 'strict'), u'strings are decoded to unicode' ) if not sys.platform.startswith('java'): self.assertEqual( unicode( buffer('character buffers are decoded to unicode'), 'utf-8', 'strict' ), u'character buffers are decoded to unicode' ) self.assertRaises(TypeError, unicode, 42, 42, 42) def test_codecs_utf7(self): utfTests = [ (u'A\u2262\u0391.', 'A+ImIDkQ.'), (u'Hi Mom -\u263a-!', 'Hi Mom -+Jjo--!'), (u'\u65E5\u672C\u8A9E', '+ZeVnLIqe-'), (u'Item 3 is \u00a31.', 'Item 3 is +AKM-1.'), (u'+', '+-'), (u'+-', '+--'), (u'+?', '+-?'), (u'\?', '+AFw?'), (u'+?', '+-?'), (ur'\\?', '+AFwAXA?'), (ur'\\\?', '+AFwAXABc?'), (ur'++--', '+-+---') ] for (x, y) in utfTests: self.assertEqual(x.encode('utf-7'), y) self.assertRaises(UnicodeError, unicode, '+3ADYAA-', 'utf-7') self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd') def test_codecs_utf8(self): self.assertEqual(u''.encode('utf-8'), '') self.assertEqual(u'\u20ac'.encode('utf-8'), '\xe2\x82\xac') self.assertEqual(u'\ud800\udc02'.encode('utf-8'), '\xf0\x90\x80\x82') self.assertEqual(u'\ud84d\udc56'.encode('utf-8'), '\xf0\xa3\x91\x96') self.assertEqual(u'\ud800'.encode('utf-8'), '\xed\xa0\x80') self.assertEqual(u'\udc00'.encode('utf-8'), '\xed\xb0\x80') self.assertEqual( (u'\ud800\udc02'*1000).encode('utf-8'), '\xf0\x90\x80\x82'*1000 ) self.assertEqual( u'\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f' u'\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00' u'\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c' u'\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067' u'\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das' u' Nunstuck git und'.encode('utf-8'), '\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81' '\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3' '\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe' '\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83' '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8' '\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81' '\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81' '\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3' '\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf' '\xe3\x80\x8cWenn ist das Nunstuck git und' ) self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456' ) self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002' ) self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac' ) def test_codecs_errors(self): self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii') self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii','strict') self.assertEqual(u'Andr\202 x'.encode('ascii','ignore'), "Andr x") self.assertEqual(u'Andr\202 x'.encode('ascii','replace'), "Andr? x") self.assertRaises(UnicodeError, unicode, 'Andr\202 x', 'ascii') self.assertRaises(UnicodeError, unicode, 'Andr\202 x', 'ascii','strict') self.assertEqual(unicode('Andr\202 x','ascii','ignore'), u"Andr x") self.assertEqual(unicode('Andr\202 x','ascii','replace'), u'Andr\uFFFD x') self.assertEqual("\\N{foo}xx".decode("unicode-escape", "ignore"), u"xx") self.assertRaises(UnicodeError, "\\".decode, "unicode-escape") def search_function(encoding): def decode1(input, errors="strict"): return 42 def encode1(input, errors="strict"): return 42 def encode2(input, errors="strict"): return (42, 42) def decode2(input, errors="strict"): return (42, 42) if encoding=="test.unicode1": return (encode1, decode1, None, None) elif encoding=="test.unicode2": return (encode2, decode2, None, None) | def __repr__(self): return 'usub(%r)' % unicode.__repr__(self) | 2297ca3284c57a984832427dbc81d0141ceff94c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/2297ca3284c57a984832427dbc81d0141ceff94c/test_unicode.py |
return None codecs.register(search_function) self.assertRaises(TypeError, "hello".decode, "test.unicode1") self.assertRaises(TypeError, unicode, "hello", "test.unicode2") self.assertRaises(TypeError, u"hello".encode, "test.unicode1") self.assertRaises(TypeError, u"hello".encode, "test.unicode2") import imp self.assertRaises( ImportError, imp.find_module, "non-existing module", [u"non-existing dir"] ) self.assertRaises(TypeError, u"hello".encode, 42, 42, 42) self.assertRaises(UnicodeError, int, u"\u0200") def test_codecs(self): self.assertEqual(u'hello'.encode('ascii'), 'hello') self.assertEqual(u'hello'.encode('utf-7'), 'hello') self.assertEqual(u'hello'.encode('utf-8'), 'hello') self.assertEqual(u'hello'.encode('utf8'), 'hello') self.assertEqual(u'hello'.encode('utf-16-le'), 'h\000e\000l\000l\000o\000') self.assertEqual(u'hello'.encode('utf-16-be'), '\000h\000e\000l\000l\000o') self.assertEqual(u'hello'.encode('latin-1'), 'hello') u = u''.join(map(unichr, xrange(1024))) for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'): self.assertEqual(unicode(u.encode(encoding),encoding), u) u = u''.join(map(unichr, xrange(256))) for encoding in ('latin-1',): self.assertEqual(unicode(u.encode(encoding),encoding), u) u = u''.join(map(unichr, xrange(128))) for encoding in ('ascii',): self.assertEqual(unicode(u.encode(encoding),encoding), u) u = u'\U00010001\U00020002\U00030003\U00040004\U00050005' for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', 'unicode_escape', 'unicode_internal'): self.assertEqual(unicode(u.encode(encoding),encoding), u) u = u''.join(map(unichr, range(0,0xd800)+range(0xe000,0x10000))) for encoding in ('utf-8',): self.assertEqual(unicode(u.encode(encoding),encoding), u) def test_codecs_charmap(self): s = ''.join(map(chr, xrange(128))) for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1', 'mac_cyrillic', 'mac_latin2', 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874', 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', 'cp1006', 'iso8859_8', ): self.assertEqual(unicode(s, encoding).encode(encoding), s) s = ''.join(map(chr, xrange(128, 256))) for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_4', 'iso8859_5', 'iso8859_9', 'koi8_r', 'latin_1', 'mac_cyrillic', 'mac_latin2', ): self.assertEqual(unicode(s, encoding).encode(encoding), s) def test_concatenation(self): self.assertEqual((u"abc" u"def"), u"abcdef") self.assertEqual(("abc" u"def"), u"abcdef") self.assertEqual((u"abc" "def"), u"abcdef") self.assertEqual((u"abc" u"def" "ghi"), u"abcdefghi") self.assertEqual(("abc" "def" u"ghi"), u"abcdefghi") def test_printing(self): class BitBucket: def write(self, text): | def test_fixup(s): s2 = u'\ud800\udc01' test_lecmp(s, s2) s2 = u'\ud900\udc01' test_lecmp(s, s2) s2 = u'\uda00\udc01' test_lecmp(s, s2) s2 = u'\udb00\udc01' test_lecmp(s, s2) s2 = u'\ud800\udd01' test_lecmp(s, s2) s2 = u'\ud900\udd01' test_lecmp(s, s2) s2 = u'\uda00\udd01' test_lecmp(s, s2) s2 = u'\udb00\udd01' test_lecmp(s, s2) s2 = u'\ud800\ude01' test_lecmp(s, s2) s2 = u'\ud900\ude01' test_lecmp(s, s2) s2 = u'\uda00\ude01' test_lecmp(s, s2) s2 = u'\udb00\ude01' test_lecmp(s, s2) s2 = u'\ud800\udfff' test_lecmp(s, s2) s2 = u'\ud900\udfff' test_lecmp(s, s2) s2 = u'\uda00\udfff' test_lecmp(s, s2) s2 = u'\udb00\udfff' test_lecmp(s, s2) | 2297ca3284c57a984832427dbc81d0141ceff94c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/2297ca3284c57a984832427dbc81d0141ceff94c/test_unicode.py |
|
else: pass verify('...%(foo)s...' % {'foo':u"abc"} == u'...abc...') verify('...%(foo)s...' % {'foo':"abc"} == '...abc...') verify('...%(foo)s...' % {u'foo':"abc"} == '...abc...') verify('...%(foo)s...' % {u'foo':u"abc"} == u'...abc...') verify('...%(foo)s...' % {u'foo':u"abc",'def':123} == u'...abc...') verify('...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...') verify('...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...') verify('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...%...%s...1...2...3...abc...') verify('...%s...' % u"abc" == u'...abc...') verify('%*s' % (5,u'abc',) == u' abc') verify('%*s' % (-5,u'abc',) == u'abc ') verify('%*.*s' % (5,2,u'abc',) == u' ab') verify('%*.*s' % (5,3,u'abc',) == u' abc') verify('%i %*.*s' % (10, 5,3,u'abc',) == u'10 abc') verify('%i%s %*.*s' % (10, 3, 5,3,u'abc',) == u'103 abc') print 'done.' print 'Testing builtin unicode()...', verify(unicode(u'unicode remains unicode') == u'unicode remains unicode') class UnicodeSubclass(unicode): pass verify(unicode(UnicodeSubclass('unicode subclass becomes unicode')) == u'unicode subclass becomes unicode') verify(unicode('strings are converted to unicode') == u'strings are converted to unicode') class UnicodeCompat: def __init__(self, x): self.x = x def __unicode__(self): return self.x verify(unicode(UnicodeCompat('__unicode__ compatible objects are recognized')) == u'__unicode__ compatible objects are recognized') class StringCompat: def __init__(self, x): self.x = x def __str__(self): return self.x verify(unicode(StringCompat('__str__ compatible objects are recognized')) == u'__str__ compatible objects are recognized') o = StringCompat('unicode(obj) is compatible to str()') verify(unicode(o) == u'unicode(obj) is compatible to str()') verify(str(o) == 'unicode(obj) is compatible to str()') for obj in (123, 123.45, 123L): verify(unicode(obj) == unicode(str(obj))) if not sys.platform.startswith('java'): try: unicode(u'decoding unicode is not supported', 'utf-8', 'strict') except TypeError: pass else: raise TestFailed, "decoding unicode should NOT be supported" verify(unicode('strings are decoded to unicode', 'utf-8', 'strict') == u'strings are decoded to unicode') if not sys.platform.startswith('java'): verify(unicode(buffer('character buffers are decoded to unicode'), 'utf-8', 'strict') == u'character buffers are decoded to unicode') print 'done.' print 'Testing builtin codecs...', utfTests = [(u'A\u2262\u0391.', 'A+ImIDkQ.'), (u'Hi Mom -\u263a-!', 'Hi Mom -+Jjo--!'), (u'\u65E5\u672C\u8A9E', '+ZeVnLIqe-'), (u'Item 3 is \u00a31.', 'Item 3 is +AKM-1.'), (u'+', '+-'), (u'+-', '+--'), (u'+?', '+-?'), (u'\?', '+AFw?'), (u'+?', '+-?'), (ur'\\?', '+AFwAXA?'), (ur'\\\?', '+AFwAXABc?'), (ur'++--', '+-+---')] for x,y in utfTests: verify( x.encode('utf-7') == y ) try: unicode('+3ADYAA-', 'utf-7') except UnicodeError: pass else: raise TestFailed, "unicode('+3ADYAA-', 'utf-7') failed to raise an exception" verify(unicode('+3ADYAA-', 'utf-7', 'replace') == u'\ufffd') verify(u''.encode('utf-8') == '') verify(u'\u20ac'.encode('utf-8') == '\xe2\x82\xac') verify(u'\ud800\udc02'.encode('utf-8') == '\xf0\x90\x80\x82') verify(u'\ud84d\udc56'.encode('utf-8') == '\xf0\xa3\x91\x96') verify(u'\ud800'.encode('utf-8') == '\xed\xa0\x80') verify(u'\udc00'.encode('utf-8') == '\xed\xb0\x80') verify((u'\ud800\udc02'*1000).encode('utf-8') == '\xf0\x90\x80\x82'*1000) verify(u'\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f' u'\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00' u'\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c' u'\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067' u'\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das' u' Nunstuck git und'.encode('utf-8') == '\xe6\xad\xa3\xe7\xa2\xba\xe3\x81\xab\xe8\xa8\x80\xe3\x81' '\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3\xe3\x81\xaf\xe3' '\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x81\xbe' '\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83' '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8' '\xaa\x9e\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81' '\xe3\x81\x82\xe3\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81' '\x9f\xe3\x82\x89\xe3\x82\x81\xe3\x81\xa7\xe3\x81\x99\xe3' '\x80\x82\xe5\xae\x9f\xe9\x9a\x9b\xe3\x81\xab\xe3\x81\xaf' '\xe3\x80\x8cWenn ist das Nunstuck git und') verify(unicode('\xf0\xa3\x91\x96', 'utf-8') == u'\U00023456' ) verify(unicode('\xf0\x90\x80\x82', 'utf-8') == u'\U00010002' ) verify(unicode('\xe2\x82\xac', 'utf-8') == u'\u20ac' ) verify(unicode('hello','ascii') == u'hello') verify(unicode('hello','utf-8') == u'hello') verify(unicode('hello','utf8') == u'hello') verify(unicode('hello','latin-1') == u'hello') try: u'Andr\202 x'.encode('ascii') u'Andr\202 x'.encode('ascii','strict') except ValueError: pass else: raise TestFailed, "u'Andr\202'.encode('ascii') failed to raise an exception" verify(u'Andr\202 x'.encode('ascii','ignore') == "Andr x") verify(u'Andr\202 x'.encode('ascii','replace') == "Andr? x") try: unicode('Andr\202 x','ascii') unicode('Andr\202 x','ascii','strict') except ValueError: pass else: raise TestFailed, "unicode('Andr\202') failed to raise an exception" verify(unicode('Andr\202 x','ascii','ignore') == u"Andr x") verify(unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x') verify("\\N{foo}xx".decode("unicode-escape", "ignore") == u"xx") try: "\\".decode("unicode-escape") except ValueError: pass else: raise TestFailed, '"\\".decode("unicode-escape") should fail' try: int(u"\u0200") except UnicodeError: pass else: raise TestFailed, "int(u'\\u0200') failed to raise an exception" verify(u'hello'.encode('ascii') == 'hello') verify(u'hello'.encode('utf-7') == 'hello') verify(u'hello'.encode('utf-8') == 'hello') verify(u'hello'.encode('utf8') == 'hello') verify(u'hello'.encode('utf-16-le') == 'h\000e\000l\000l\000o\000') verify(u'hello'.encode('utf-16-be') == '\000h\000e\000l\000l\000o') verify(u'hello'.encode('latin-1') == 'hello') u = u''.join(map(unichr, range(1024))) for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'): verify(unicode(u.encode(encoding),encoding) == u) u = u''.join(map(unichr, range(256))) for encoding in ( 'latin-1', ): try: verify(unicode(u.encode(encoding),encoding) == u) except TestFailed: print '*** codec "%s" failed round-trip' % encoding except ValueError,why: print '*** codec for "%s" failed: %s' % (encoding, why) u = u''.join(map(unichr, range(128))) for encoding in ( 'ascii', ): try: verify(unicode(u.encode(encoding),encoding) == u) except TestFailed: print '*** codec "%s" failed round-trip' % encoding except ValueError,why: print '*** codec for "%s" failed: %s' % (encoding, why) u = u'\U00010001\U00020002\U00030003\U00040004\U00050005' for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', 'unicode_escape', 'unicode_internal'): verify(unicode(u.encode(encoding),encoding) == u) u = u''.join(map(unichr, range(0,0xd800)+range(0xe000,0x10000))) for encoding in ('utf-8',): verify(unicode(u.encode(encoding),encoding) == u) print 'done.' print 'Testing standard mapping codecs...', print '0-127...', s = ''.join(map(chr, range(128))) for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1', 'mac_cyrillic', 'mac_latin2', 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874', 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', 'cp1006', 'iso8859_8', ): try: verify(unicode(s,encoding).encode(encoding) == s) except TestFailed: print '*** codec "%s" failed round-trip' % encoding except ValueError,why: print '*** codec for "%s" failed: %s' % (encoding, why) print '128-255...', s = ''.join(map(chr, range(128,256))) for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_4', 'iso8859_5', 'iso8859_9', 'koi8_r', 'latin_1', 'mac_cyrillic', 'mac_latin2', ): try: verify(unicode(s,encoding).encode(encoding) == s) except TestFailed: print '*** codec "%s" failed round-trip' % encoding except ValueError,why: print '*** codec for "%s" failed: %s' % (encoding, why) print 'done.' print 'Testing Unicode string concatenation...', verify((u"abc" u"def") == u"abcdef") verify(("abc" u"def") == u"abcdef") verify((u"abc" "def") == u"abcdef") verify((u"abc" u"def" "ghi") == u"abcdefghi") verify(("abc" "def" u"ghi") == u"abcdefghi") print 'done.' print 'Testing Unicode printing...', print u'abc' print u'abc', u'def' print u'abc', 'def' print 'abc', u'def' print u'abc\n' print u'abc\n', print u'abc\n', print u'def\n' print u'def\n' print 'done.' def test_exception(lhs, rhs, msg): try: lhs in rhs except TypeError: pass else: raise TestFailed, msg def run_contains_tests(): vereq(u'' in '', True) vereq('' in u'', True) vereq(u'' in u'', True) vereq(u'' in 'abc', True) vereq('' in u'abc', True) vereq(u'' in u'abc', True) vereq(u'\0' in 'abc', False) vereq('\0' in u'abc', False) vereq(u'\0' in u'abc', False) vereq(u'\0' in '\0abc', True) vereq('\0' in u'\0abc', True) vereq(u'\0' in u'\0abc', True) vereq(u'\0' in 'abc\0', True) vereq('\0' in u'abc\0', True) vereq(u'\0' in u'abc\0', True) vereq(u'a' in '\0abc', True) vereq('a' in u'\0abc', True) vereq(u'a' in u'\0abc', True) vereq(u'asdf' in 'asdf', True) vereq('asdf' in u'asdf', True) vereq(u'asdf' in u'asdf', True) vereq(u'asdf' in 'asd', False) vereq('asdf' in u'asd', False) vereq(u'asdf' in u'asd', False) vereq(u'asdf' in '', False) vereq('asdf' in u'', False) vereq(u'asdf' in u'', False) run_contains_tests() | out = BitBucket() print >>out, u'abc' print >>out, u'abc', u'def' print >>out, u'abc', 'def' print >>out, 'abc', u'def' print >>out, u'abc\n' print >>out, u'abc\n', print >>out, u'abc\n', print >>out, u'def\n' print >>out, u'def\n' def test_mul(self): self.checkmethod('__mul__', u'abc', u'', -1) self.checkmethod('__mul__', u'abc', u'', 0) self.checkmethod('__mul__', u'abc', u'abc', 1) self.checkmethod('__mul__', u'abc', u'abcabcabc', 3) self.assertRaises(OverflowError, (10000*u'abc').__mul__, sys.maxint) def test_subscript(self): self.checkmethod('__getitem__', u'abc', u'a', 0) self.checkmethod('__getitem__', u'abc', u'c', -1) self.checkmethod('__getitem__', u'abc', u'a', 0L) self.checkmethod('__getitem__', u'abc', u'abc', slice(0, 3)) self.checkmethod('__getitem__', u'abc', u'abc', slice(0, 1000)) self.checkmethod('__getitem__', u'abc', u'a', slice(0, 1)) self.checkmethod('__getitem__', u'abc', u'', slice(0, 0)) self.assertRaises(TypeError, u"abc".__getitem__, "def") def test_slice(self): self.checkmethod('__getslice__', u'abc', u'abc', 0, 1000) self.checkmethod('__getslice__', u'abc', u'abc', 0, 3) self.checkmethod('__getslice__', u'abc', u'ab', 0, 2) self.checkmethod('__getslice__', u'abc', u'bc', 1, 3) self.checkmethod('__getslice__', u'abc', u'b', 1, 2) self.checkmethod('__getslice__', u'abc', u'', 2, 2) self.checkmethod('__getslice__', u'abc', u'', 1000, 1000) self.checkmethod('__getslice__', u'abc', u'', 2000, 1000) self.checkmethod('__getslice__', u'abc', u'', 2, 1) def test_main(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(UnicodeTest)) test.test_support.run_suite(suite) if __name__ == "__main__": test_main() | def test_fixup(s): s2 = u'\ud800\udc01' test_lecmp(s, s2) s2 = u'\ud900\udc01' test_lecmp(s, s2) s2 = u'\uda00\udc01' test_lecmp(s, s2) s2 = u'\udb00\udc01' test_lecmp(s, s2) s2 = u'\ud800\udd01' test_lecmp(s, s2) s2 = u'\ud900\udd01' test_lecmp(s, s2) s2 = u'\uda00\udd01' test_lecmp(s, s2) s2 = u'\udb00\udd01' test_lecmp(s, s2) s2 = u'\ud800\ude01' test_lecmp(s, s2) s2 = u'\ud900\ude01' test_lecmp(s, s2) s2 = u'\uda00\ude01' test_lecmp(s, s2) s2 = u'\udb00\ude01' test_lecmp(s, s2) s2 = u'\ud800\udfff' test_lecmp(s, s2) s2 = u'\ud900\udfff' test_lecmp(s, s2) s2 = u'\uda00\udfff' test_lecmp(s, s2) s2 = u'\udb00\udfff' test_lecmp(s, s2) | 2297ca3284c57a984832427dbc81d0141ceff94c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/2297ca3284c57a984832427dbc81d0141ceff94c/test_unicode.py |
verify(inc(1) == 2) | verify(inc(1) == 11) | def adder(y): return global_nest_x + y | f9891cc01c9cb82b881327139ef71c1dc3722448 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/f9891cc01c9cb82b881327139ef71c1dc3722448/test_scope.py |
if type(value) != type([]): | if type(value) not in (type([]), type( () )): | def post_to_server(self, data, auth=None): ''' Post a query to the server, and return a string response. ''' | ca253f47eee6c9b98d38daa53c09fc0a4722d6e9 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/ca253f47eee6c9b98d38daa53c09fc0a4722d6e9/register.py |
if value.sign == 1: self._sign = 0 else: self._sign = 1 | self._sign = value.sign | def __new__(cls, value="0", context=None): """Create a decimal point instance. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
||
diff = cmp(abs(op1), abs(op2)) | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
|
if diff == 0: | if op1.int == op2.int: | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
if diff < 0: | if op1.int < op2.int: | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
if op1.sign == -1: result.sign = -1 | if op1.sign == 1: result.sign = 1 | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
result.sign = 1 | result.sign = 0 | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
elif op1.sign == -1: result.sign = -1 op1.sign, op2.sign = (1, 1) | elif op1.sign == 1: result.sign = 1 op1.sign, op2.sign = (0, 0) | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
result.sign = 1 | result.sign = 0 | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
if op2.sign == 1: | if op2.sign == 0: | def __add__(self, other, context=None): """Returns self + other. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
if sign: sign = -1 else: sign = 1 adjust = 0 | def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
|
otherside = otherside._rescale(exp, context=context, watchexp=0) | otherside = otherside._rescale(exp, context=context, watchexp=0) | def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
def to_integral(self, a): """Rounds to an integer. | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
||
if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 | elif isinstance(value, Decimal): self.sign = value._sign | def __init__(self, value=None): if value is None: self.sign = None self.int = 0 self.exp = None if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 cum = 0 for digit in value._int: cum = cum * 10 + digit self.int = cum self.exp = value._exp if isinstance(value, tuple): self.sign = value[0] self.int = value[1] self.exp = value[2] | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
for digit in value._int: | for digit in value._int: | def __init__(self, value=None): if value is None: self.sign = None self.int = 0 self.exp = None if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 cum = 0 for digit in value._int: cum = cum * 10 + digit self.int = cum self.exp = value._exp if isinstance(value, tuple): self.sign = value[0] self.int = value[1] self.exp = value[2] | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
if isinstance(value, tuple): | else: | def __init__(self, value=None): if value is None: self.sign = None self.int = 0 self.exp = None if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 cum = 0 for digit in value._int: cum = cum * 10 + digit self.int = cum self.exp = value._exp if isinstance(value, tuple): self.sign = value[0] self.int = value[1] self.exp = value[2] | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
def __neg__(self): if self.sign == 1: return _WorkRep( (-1, self.int, self.exp) ) else: return _WorkRep( (1, self.int, self.exp) ) def __abs__(self): if self.sign == -1: return -self else: return self def __cmp__(self, other): if self.exp != other.exp: raise ValueError("Operands not normalized: %r, %r" % (self, other)) if self.sign != other.sign: if self.sign == -1: return -1 else: return 1 if self.sign == -1: direction = -1 else: direction = 1 int1 = self.int int2 = other.int if int1 > int2: return direction * 1 if int1 < int2: return direction * -1 return 0 | def __repr__(self): return "(%r, %r, %r)" % (self.sign, self.int, self.exp) | b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/b7ed2df9f8b3eaa226b68d6c2ebfcb1ddb522d57/decimal.py |
|
self._parser.ProcessingInstructionHandler = \ self._cont_handler.processingInstruction self._parser.CharacterDataHandler = self._cont_handler.characters | self._reset_cont_handler() | def reset(self): if self._namespaces: self._parser = expat.ParserCreate(None, " ") self._parser.StartElementHandler = self.start_element_ns self._parser.EndElementHandler = self.end_element_ns else: self._parser = expat.ParserCreate() self._parser.StartElementHandler = self.start_element self._parser.EndElementHandler = self.end_element | 4626ec0f40696dd05f0fc774b0b47caa575067aa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/4626ec0f40696dd05f0fc774b0b47caa575067aa/expatreader.py |
self._parser.CommentHandler = self._lex_handler_prop.comment self._parser.StartCdataSectionHandler = self._lex_handler_prop.startCDATA self._parser.EndCdataSectionHandler = self._lex_handler_prop.endCDATA | self._reset_lex_handler_prop() | def reset(self): if self._namespaces: self._parser = expat.ParserCreate(None, " ") self._parser.StartElementHandler = self.start_element_ns self._parser.EndElementHandler = self.end_element_ns else: self._parser = expat.ParserCreate() self._parser.StartElementHandler = self.start_element self._parser.EndElementHandler = self.end_element | 4626ec0f40696dd05f0fc774b0b47caa575067aa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/4626ec0f40696dd05f0fc774b0b47caa575067aa/expatreader.py |
if string.lower(filename[-3:]) == '.py' and os.path.exists(filename): | for suffix, mode, kind in imp.get_suffixes(): if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix: return None if os.path.exists(filename): | def getsourcefile(object): """Return the Python source file an object was defined in, if it exists.""" filename = getfile(object) if string.lower(filename[-4:]) in ['.pyc', '.pyo']: filename = filename[:-4] + '.py' if string.lower(filename[-3:]) == '.py' and os.path.exists(filename): return filename | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
"""Return an absolute path to the source file or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.""" return os.path.normcase(os.path.abspath(getsourcefile(object) or getfile(object))) | """Return an absolute path to the source or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.""" return os.path.normcase( os.path.abspath(getsourcefile(object) or getfile(object))) | def getabsfile(object): """Return an absolute path to the source file or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.""" return os.path.normcase(os.path.abspath(getsourcefile(object) or getfile(object))) | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
"""Try to guess which module an object was defined in.""" | """Return the module an object was defined in, or None if not found.""" | def getmodule(object): """Try to guess which module an object was defined in.""" if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for module in sys.modules.values(): if hasattr(module, '__file__'): modulesbyfile[getabsfile(module)] = module.__name__ if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] main = sys.modules['__main__'] try: mainobject = getattr(main, object.__name__) if mainobject is object: return main except AttributeError: pass builtin = sys.modules['__builtin__'] try: builtinobject = getattr(builtin, object.__name__) if builtinobject is object: return builtin except AttributeError: pass | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
try: | if hasattr(main, object.__name__): | def getmodule(object): """Try to guess which module an object was defined in.""" if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for module in sys.modules.values(): if hasattr(module, '__file__'): modulesbyfile[getabsfile(module)] = module.__name__ if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] main = sys.modules['__main__'] try: mainobject = getattr(main, object.__name__) if mainobject is object: return main except AttributeError: pass builtin = sys.modules['__builtin__'] try: builtinobject = getattr(builtin, object.__name__) if builtinobject is object: return builtin except AttributeError: pass | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
if mainobject is object: return main except AttributeError: pass | if mainobject is object: return main | def getmodule(object): """Try to guess which module an object was defined in.""" if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for module in sys.modules.values(): if hasattr(module, '__file__'): modulesbyfile[getabsfile(module)] = module.__name__ if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] main = sys.modules['__main__'] try: mainobject = getattr(main, object.__name__) if mainobject is object: return main except AttributeError: pass builtin = sys.modules['__builtin__'] try: builtinobject = getattr(builtin, object.__name__) if builtinobject is object: return builtin except AttributeError: pass | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
try: | if hasattr(builtin, object.__name__): | def getmodule(object): """Try to guess which module an object was defined in.""" if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for module in sys.modules.values(): if hasattr(module, '__file__'): modulesbyfile[getabsfile(module)] = module.__name__ if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] main = sys.modules['__main__'] try: mainobject = getattr(main, object.__name__) if mainobject is object: return main except AttributeError: pass builtin = sys.modules['__builtin__'] try: builtinobject = getattr(builtin, object.__name__) if builtinobject is object: return builtin except AttributeError: pass | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
if builtinobject is object: return builtin except AttributeError: pass | if builtinobject is object: return builtin | def getmodule(object): """Try to guess which module an object was defined in.""" if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for module in sys.modules.values(): if hasattr(module, '__file__'): modulesbyfile[getabsfile(module)] = module.__name__ if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] main = sys.modules['__main__'] try: mainobject = getattr(main, object.__name__) if mainobject is object: return main except AttributeError: pass builtin = sys.modules['__builtin__'] try: builtinobject = getattr(builtin, object.__name__) if builtinobject is object: return builtin except AttributeError: pass | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
lines = file.readlines() file.close() | def findsource(object): """Return the entire source file and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An IOError is raised if the source code cannot be retrieved.""" try: file = open(getsourcefile(object)) lines = file.readlines() file.close() except (TypeError, IOError): raise IOError, 'could not get source code' if ismodule(object): return lines, 0 if isclass(object): name = object.__name__ matches = (['class', name], ['class', name + ':']) for i in range(len(lines)): if string.split(lines[i])[:2] in matches: return lines, i else: raise IOError, 'could not find class definition' if ismethod(object): object = object.im_func if isfunction(object): object = object.func_code if istraceback(object): object = object.tb_frame if isframe(object): object = object.f_code if iscode(object): try: lnum = object.co_firstlineno - 1 except AttributeError: raise IOError, 'could not find function definition' else: while lnum > 0: if string.split(lines[lnum])[:1] == ['def']: break lnum = lnum - 1 return lines, lnum | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
|
try: lnum = object.co_firstlineno - 1 except AttributeError: | if not hasattr(object, 'co_firstlineno'): | def findsource(object): """Return the entire source file and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An IOError is raised if the source code cannot be retrieved.""" try: file = open(getsourcefile(object)) lines = file.readlines() file.close() except (TypeError, IOError): raise IOError, 'could not get source code' if ismodule(object): return lines, 0 if isclass(object): name = object.__name__ matches = (['class', name], ['class', name + ':']) for i in range(len(lines)): if string.split(lines[i])[:2] in matches: return lines, i else: raise IOError, 'could not find class definition' if ismethod(object): object = object.im_func if isfunction(object): object = object.func_code if istraceback(object): object = object.tb_frame if isframe(object): object = object.f_code if iscode(object): try: lnum = object.co_firstlineno - 1 except AttributeError: raise IOError, 'could not find function definition' else: while lnum > 0: if string.split(lines[lnum])[:1] == ['def']: break lnum = lnum - 1 return lines, lnum | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
else: while lnum > 0: if string.split(lines[lnum])[:1] == ['def']: break lnum = lnum - 1 return lines, lnum | lnum = object.co_firstlineno - 1 while lnum > 0: if string.split(lines[lnum])[:1] == ['def']: break lnum = lnum - 1 return lines, lnum | def findsource(object): """Return the entire source file and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An IOError is raised if the source code cannot be retrieved.""" try: file = open(getsourcefile(object)) lines = file.readlines() file.close() except (TypeError, IOError): raise IOError, 'could not get source code' if ismodule(object): return lines, 0 if isclass(object): name = object.__name__ matches = (['class', name], ['class', name + ':']) for i in range(len(lines)): if string.split(lines[i])[:2] in matches: return lines, i else: raise IOError, 'could not find class definition' if ismethod(object): object = object.im_func if isfunction(object): object = object.func_code if istraceback(object): object = object.tb_frame if isframe(object): object = object.f_code if iscode(object): try: lnum = object.co_firstlineno - 1 except AttributeError: raise IOError, 'could not find function definition' else: while lnum > 0: if string.split(lines[lnum])[:1] == ['def']: break lnum = lnum - 1 return lines, lnum | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
except: return None | except IOError: return None | def getcomments(object): """Get lines of comments immediately preceding an object's source code.""" try: lines, lnum = findsource(object) except: return None if ismodule(object): # Look for a comment block at the top of the file. start = 0 if lines[0][:2] == '#!': start = 1 while start < len(lines) and string.strip(lines[start]) in ['', '#']: start = start + 1 if lines[start][:1] == '#': comments = [] end = start while end < len(lines) and lines[end][:1] == '#': comments.append(string.expandtabs(lines[end])) end = end + 1 return string.join(comments, '') # Look for a preceding block of comments at the same indentation. elif lnum > 0: indent = indentsize(lines[lnum]) end = lnum - 1 if end >= 0 and string.lstrip(lines[end])[:1] == '#' and \ indentsize(lines[end]) == indent: comments = [string.lstrip(string.expandtabs(lines[end]))] if end > 0: end = end - 1 comment = string.lstrip(string.expandtabs(lines[end])) while comment[:1] == '#' and indentsize(lines[end]) == indent: comments[:0] = [comment] end = end - 1 if end < 0: break comment = string.lstrip(string.expandtabs(lines[end])) while comments and string.strip(comments[0]) == '#': comments[:1] = [] while comments and string.strip(comments[-1]) == '#': comments[-1:] = [] return string.join(comments, '') | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
except IOError: lines = index = None | def getframeinfo(frame, context=1): """Get information about a frame or traceback object. A tuple of five things is returned: the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line.""" if istraceback(frame): frame = frame.tb_frame if not isframe(frame): raise TypeError, 'arg is not a frame or traceback object' filename = getsourcefile(frame) lineno = getlineno(frame) if context > 0: start = lineno - 1 - context/2 try: lines, lnum = findsource(frame) start = max(start, 1) start = min(start, len(lines) - context) lines = lines[start:start+context] index = lineno - 1 - start except IOError: lines = index = None else: lines = index = None return (filename, lineno, frame.f_code.co_name, lines, index) | d6c86dae430f16a4790418f8c96eb8ef11aab251 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/d6c86dae430f16a4790418f8c96eb8ef11aab251/inspect.py |
|
bytes = "" while 1: line = self.rfile.readline() bytes = bytes + line if line == '\r\n' or line == '\n' or line == '': break | def parse_request(self): """Parse a request (internal). | 74e32f228fdbfa857e026c1254123fe9614f86cc /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/74e32f228fdbfa857e026c1254123fe9614f86cc/BaseHTTPServer.py |
|
hfile = cStringIO.StringIO(bytes) self.headers = self.MessageClass(hfile) | self.headers = self.MessageClass(self.rfile, 0) | def parse_request(self): """Parse a request (internal). | 74e32f228fdbfa857e026c1254123fe9614f86cc /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/74e32f228fdbfa857e026c1254123fe9614f86cc/BaseHTTPServer.py |
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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
||
sqlite_inc_paths = [ '/usr/include', | sqlite_inc_paths = [ '/usr/include', | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
MIN_SQLITE_VERSION_NUMBER = 3000008 MIN_SQLITE_VERSION = "3.0.8" | MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) MIN_SQLITE_VERSION = ".".join([str(x) for x in MIN_SQLITE_VERSION_NUMBER]) | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
f = open(f).read() m = re.search(r" | incf = open(f).read() m = re.search( r'\s*.* | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
sqlite_version = int(m.group(1)) if sqlite_version >= MIN_SQLITE_VERSION_NUMBER: | sqlite_version = m.group(1) sqlite_version_tuple = tuple([int(x) for x in sqlite_version.split(".")]) if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER: | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
elif sqlite_version == 3000000: if sqlite_setup_debug: print "found buggy SQLITE_VERSION_NUMBER, checking" m = re.search(r' f) if m: sqlite_version = m.group(1) if sqlite_version >= MIN_SQLITE_VERSION: print "%s/sqlite3.h: version %s"%(d, sqlite_version) sqlite_incdir = d break | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
|
if sqlite_setup_debug: | if sqlite_setup_debug: | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
elif sqlite_setup_debug: print "sqlite: %s had no SQLITE_VERSION"%(f,) | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
|
sqlite_defines.append(('PYSQLITE_VERSION', | sqlite_defines.append(('PYSQLITE_VERSION', | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
sqlite_defines.append(('PYSQLITE_VERSION', | sqlite_defines.append(('PYSQLITE_VERSION', | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
sqlite_defines.append(('PY_MAJOR_VERSION', | sqlite_defines.append(('PY_MAJOR_VERSION', | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
sqlite_defines.append(('PY_MINOR_VERSION', | sqlite_defines.append(('PY_MINOR_VERSION', | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
include_dirs=["Modules/_sqlite", | include_dirs=["Modules/_sqlite", | 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') | e25005bba7396fd747cf8a1e8599dbd4d921ef70 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/e25005bba7396fd747cf8a1e8599dbd4d921ef70/setup.py |
tmp_file.close() | _sync_close(tmp_file) | def add(self, message): """Add message and return assigned key.""" tmp_file = self._create_tmp() try: self._dump_message(message, tmp_file) finally: tmp_file.close() if isinstance(message, MaildirMessage): subdir = message.get_subdir() suffix = self.colon + message.get_info() if suffix == self.colon: suffix = '' else: subdir = 'new' suffix = '' uniq = os.path.basename(tmp_file.name).split(self.colon)[0] dest = os.path.join(self._path, subdir, uniq + suffix) os.rename(tmp_file.name, dest) if isinstance(message, MaildirMessage): os.utime(dest, (os.path.getatime(dest), message.get_date())) return uniq | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
new_file.close() | _sync_close(new_file) | def flush(self): """Write any pending changes to disk.""" if not self._pending: return self._lookup() new_file = _create_temporary(self._path) try: new_toc = {} self._pre_mailbox_hook(new_file) for key in sorted(self._toc.keys()): start, stop = self._toc[key] self._file.seek(start) self._pre_message_hook(new_file) new_start = new_file.tell() while True: buffer = self._file.read(min(4096, stop - self._file.tell())) if buffer == '': break new_file.write(buffer) new_toc[key] = (new_start, new_file.tell()) self._post_message_hook(new_file) except: new_file.close() os.remove(new_file.name) raise new_file.close() self._file.close() try: os.rename(new_file.name, self._path) except OSError, e: if e.errno == errno.EEXIST or \ (os.name == 'os2' and e.errno == errno.EACCES): os.remove(self._path) os.rename(new_file.name, self._path) else: raise self._file = open(self._path, 'rb+') self._toc = new_toc self._pending = False if self._locked: _lock_file(self._file, dotlock=False) | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
self._file.close() | self._file.close() | def close(self): """Flush and close the mailbox.""" self.flush() if self._locked: self.unlock() self._file.close() | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
f.close() | _sync_close(f) | def add(self, message): """Add message and return assigned key.""" keys = self.keys() if len(keys) == 0: new_key = 1 else: new_key = max(keys) + 1 new_path = os.path.join(self._path, str(new_key)) f = _create_carefully(new_path) try: if self._locked: _lock_file(f) try: self._dump_message(message, f) if isinstance(message, MHMessage): self._dump_sequences(message, new_key) finally: if self._locked: _unlock_file(f) finally: f.close() return new_key | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
f.close() | _sync_close(f) | def __setitem__(self, key, message): """Replace the keyed message; raise KeyError if it doesn't exist.""" path = os.path.join(self._path, str(key)) try: f = open(path, 'rb+') except IOError, e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: raise try: if self._locked: _lock_file(f) try: os.close(os.open(path, os.O_WRONLY | os.O_TRUNC)) self._dump_message(message, f) if isinstance(message, MHMessage): self._dump_sequences(message, key) finally: if self._locked: _unlock_file(f) finally: f.close() | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
self._file.close() | _sync_close(self._file) | def unlock(self): """Unlock the mailbox if it is locked.""" if self._locked: _unlock_file(self._file) self._file.close() del self._file self._locked = False | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
f.close() | _sync_close(f) | def set_sequences(self, sequences): """Set sequences using the given name-to-key-list dictionary.""" f = open(os.path.join(self._path, '.mh_sequences'), 'r+') try: os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC)) for name, keys in sequences.iteritems(): if len(keys) == 0: continue f.write('%s:' % name) prev = None completing = False for key in sorted(set(keys)): if key - 1 == prev: if not completing: completing = True f.write('-') elif completing: completing = False f.write('%s %s' % (prev, key)) else: f.write(' %s' % key) prev = key if completing: f.write(str(prev) + '\n') else: f.write('\n') finally: f.close() | 9642fb1c136c4c0b78f4a639661c003e4acc6ae3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9642fb1c136c4c0b78f4a639661c003e4acc6ae3/mailbox.py |
def walktree(name, change): if os.path.isfile(name): for ext, cr, tp in list: if name[-len(ext):] == ext: fs = macfs.FSSpec(name) curcrtp = fs.GetCreatorType() if curcrtp <> (cr, tp): if change: fs.SetCreatorType(cr, tp) print 'Fixed ', name else: print 'Wrong', curcrtp, name elif os.path.isdir(name): print '->', name files = os.listdir(name) for f in files: walktree(os.path.join(name, f), change) | def mkalias(src, dst): """Create a finder alias""" srcfss = macfs.FSSpec(src) dstfss = macfs.FSSpec(dst) alias = srcfss.NewAlias() srcfinfo = srcfss.GetFInfo() Res.FSpCreateResFile(dstfss, srcfinfo.Creator, srcfinfo.Type, -1) h = Res.FSpOpenResFile(dstfss, 3) resource = Res.Resource(alias.data) resource.AddResource('alis', 0, '') Res.CloseResFile(h) dstfinfo = dstfss.GetFInfo() dstfinfo.Flags = dstfinfo.Flags|0x8000 dstfss.SetFInfo(dstfinfo) def main(): dir, ok = macfs.GetDirectory() if not ok: sys.exit(0) os.chdir(dir.as_pathname()) if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: sys.exit(0) LibFiles = [] allfiles = os.listdir(':') for f in allfiles: if f[-4:] == '.slb': finfo = macfs.FSSpec(f).GetFInfo() if finfo.Flags & 0x8000: os.unlink(f) else: LibFiles.append(f) print LibFiles if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0: sys.exit(0) for dst, src in goals: if src in LibFiles: mkalias(src, dst) else: EasyDialogs.Message(dst+' not created: '+src+' not found') | def walktree(name, change): if os.path.isfile(name): for ext, cr, tp in list: if name[-len(ext):] == ext: fs = macfs.FSSpec(name) curcrtp = fs.GetCreatorType() if curcrtp <> (cr, tp): if change: fs.SetCreatorType(cr, tp) print 'Fixed ', name else: print 'Wrong', curcrtp, name elif os.path.isdir(name): print '->', name files = os.listdir(name) for f in files: walktree(os.path.join(name, f), change) | 14842d631807964ee4e0c5633be5723b57b8f135 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/14842d631807964ee4e0c5633be5723b57b8f135/ConfigurePython.py |
def run(change): fss, ok = macfs.GetDirectory() if not ok: sys.exit(0) walktree(fss.as_pathname(), change) | EasyDialogs.Message('All done!') | def run(change): fss, ok = macfs.GetDirectory() if not ok: sys.exit(0) walktree(fss.as_pathname(), change) | 14842d631807964ee4e0c5633be5723b57b8f135 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/14842d631807964ee4e0c5633be5723b57b8f135/ConfigurePython.py |
run(1) | main() | def run(change): fss, ok = macfs.GetDirectory() if not ok: sys.exit(0) walktree(fss.as_pathname(), change) | 14842d631807964ee4e0c5633be5723b57b8f135 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/14842d631807964ee4e0c5633be5723b57b8f135/ConfigurePython.py |
InteractiveInterpreter.__init__(self) | locals = sys.modules['__main__'].__dict__ InteractiveInterpreter.__init__(self, locals=locals) | def __init__(self, tkconsole): self.tkconsole = tkconsole InteractiveInterpreter.__init__(self) | 9e37a41814a378d7017bd5b336151f30a46ac96a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9e37a41814a378d7017bd5b336151f30a46ac96a/PyShell.py |
filename = self.stuffsource(source) self.more = 0 return InteractiveInterpreter.runsource(self, source, filename) def stuffsource(self, source): | def runsource(self, source): # Extend base class to stuff the source in the line cache filename = "<pyshell#%d>" % self.gid self.gid = self.gid + 1 lines = string.split(source, "\n") linecache.cache[filename] = len(source)+1, 0, lines, filename self.more = 0 return InteractiveInterpreter.runsource(self, source, filename) | 9e37a41814a378d7017bd5b336151f30a46ac96a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9e37a41814a378d7017bd5b336151f30a46ac96a/PyShell.py |
|
self.more = 0 return InteractiveInterpreter.runsource(self, source, filename) | return filename | def runsource(self, source): # Extend base class to stuff the source in the line cache filename = "<pyshell#%d>" % self.gid self.gid = self.gid + 1 lines = string.split(source, "\n") linecache.cache[filename] = len(source)+1, 0, lines, filename self.more = 0 return InteractiveInterpreter.runsource(self, source, filename) | 9e37a41814a378d7017bd5b336151f30a46ac96a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9e37a41814a378d7017bd5b336151f30a46ac96a/PyShell.py |
if char in string.letters + string.digits + "_": | if char and char in string.letters + string.digits + "_": | def showsyntaxerror(self, filename=None): # Extend base class to color the offending position # (instead of printing it and pointing at it with a caret) text = self.tkconsole.text stuff = self.unpackerror() if not stuff: self.tkconsole.resetoutput() InteractiveInterpreter.showsyntaxerror(self, filename) return msg, lineno, offset, line = stuff if lineno == 1: pos = "iomark + %d chars" % (offset-1) else: pos = "iomark linestart + %d lines + %d chars" % (lineno-1, offset-1) text.tag_add("ERROR", pos) text.see(pos) char = text.get(pos) if char in string.letters + string.digits + "_": text.tag_add("ERROR", pos + " wordstart", pos) self.tkconsole.resetoutput() self.write("SyntaxError: %s\n" % str(msg)) | 9e37a41814a378d7017bd5b336151f30a46ac96a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9e37a41814a378d7017bd5b336151f30a46ac96a/PyShell.py |
ok = type == SyntaxError | ok = type is SyntaxError | def unpackerror(self): type, value, tb = sys.exc_info() ok = type == SyntaxError if ok: try: msg, (dummy_filename, lineno, offset, line) = value except: ok = 0 if ok: return msg, lineno, offset, line else: return None | 9e37a41814a378d7017bd5b336151f30a46ac96a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12029/9e37a41814a378d7017bd5b336151f30a46ac96a/PyShell.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.