rem
stringlengths
1
322k
add
stringlengths
0
2.05M
context
stringlengths
4
228k
meta
stringlengths
156
215
return self.decode(self.stream.read())[0]
return self.decode(self.stream.read(), self.errors)[0]
def read(self, size=-1):
c6c283840316dec54244b311657511e95e742eb0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/c6c283840316dec54244b311657511e95e742eb0/codecs.py
object, decodedbytes = decode(data)
object, decodedbytes = decode(data, self.errors)
def read(self, size=-1):
c6c283840316dec54244b311657511e95e742eb0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/c6c283840316dec54244b311657511e95e742eb0/codecs.py
return self.decode(line)[0]
return self.decode(line,self.errors)[0]
def readline(self, size=None):
c6c283840316dec54244b311657511e95e742eb0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/c6c283840316dec54244b311657511e95e742eb0/codecs.py
return self.decode(data)[0].splitlines(1)
return self.decode(data,self.errors)[0].splitlines(1)
def readlines(self, sizehint=0):
c6c283840316dec54244b311657511e95e742eb0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/c6c283840316dec54244b311657511e95e742eb0/codecs.py
def __init__(self, *args): apply(URLopener.__init__, (self,) + args)
def __init__(self, *args, **kwargs): apply(URLopener.__init__, (self,) + args, kwargs)
def __init__(self, *args): apply(URLopener.__init__, (self,) + args) self.auth_cache = {} self.tries = 0 self.maxtries = 10
60e04cd317201f43b612e99444eac297fae0ea40 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/60e04cd317201f43b612e99444eac297fae0ea40/urllib.py
elif 'r' in how: l_type = FCNTL.F_WRLCK
elif 'r' in how: l_type = FCNTL.F_RDLCK
def lock(self, how, *args):
ba3e46b9ce8c02c0215cc45bffa36b8500351f5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/ba3e46b9ce8c02c0215cc45bffa36b8500351f5b/posixfile.py
if sys.platform[:4] != 'java': value = u"%(x)s, %()s" % {'x':u"abc", u''.encode('utf-8'):"def"} else: value = u"%(x)s, %()s" % {'x':u"abc", u'':"def"}
value = u"%(x)s, %()s" % {'x':u"abc", u'':"def"}
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)
72f8213ba4b960bdf540a1cc494ac699170c9dec /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/72f8213ba4b960bdf540a1cc494ac699170c9dec/test_unicode.py
def seval(item): """ Strips parens from item prior to calling eval in an attempt to make it safer """ return eval(item.replace('(', '').replace(')', ''))
def seval(item): """ Strips parens from item prior to calling eval in an attempt to make it safer """ return eval(item.replace('(', '').replace(')', ''))
39a55920018ef19cc01b53063a2f090fe05d4982 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/39a55920018ef19cc01b53063a2f090fe05d4982/csv.py
try:
for thisType in [int, long, float, complex]:
def seval(item): """ Strips parens from item prior to calling eval in an attempt to make it safer """ return eval(item.replace('(', '').replace(')', ''))
39a55920018ef19cc01b53063a2f090fe05d4982 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/39a55920018ef19cc01b53063a2f090fe05d4982/csv.py
thisType = type(seval(row[col])) except OverflowError: thisType = type(seval(row[col] + 'L')) thisType = type(0) except:
thisType(row[col]) break except ValueError, OverflowError: pass else:
def seval(item): """ Strips parens from item prior to calling eval in an attempt to make it safer """ return eval(item.replace('(', '').replace(')', ''))
39a55920018ef19cc01b53063a2f090fe05d4982 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/39a55920018ef19cc01b53063a2f090fe05d4982/csv.py
eval("%s(%s)" % (colType.__name__, header[col])) except:
colType(header[col]) except ValueError, TypeError:
def seval(item): """ Strips parens from item prior to calling eval in an attempt to make it safer """ return eval(item.replace('(', '').replace(')', ''))
39a55920018ef19cc01b53063a2f090fe05d4982 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/39a55920018ef19cc01b53063a2f090fe05d4982/csv.py
pass
def __str__(self): return repr(self)
def _stringify(string): return string
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
(repr(self.faultCode), repr(self.faultString))
(self.faultCode, repr(self.faultString))
def __repr__(self): return ( "<Fault %s: %s>" % (repr(self.faultCode), repr(self.faultString)) )
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
xmllib.XMLParser.__init__(self)
try: xmllib.XMLParser.__init__(self, accept_utf8=1) except TypeError: xmllib.XMLParser.__init__(self)
def __init__(self, target): import xmllib # lazy subclassing (!) if xmllib.XMLParser not in SlowParser.__bases__: SlowParser.__bases__ = (xmllib.XMLParser,) self.handle_xml = target.xml self.unknown_starttag = target.start self.handle_data = target.data self.unknown_endtag = target.end xmllib.XMLParser.__init__(self)
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
messages (start, data, end). Call close to get the resulting
messages (start, data, end). Call close() to get the resulting
def dump_instance(self, value): # check for special wrappers if value.__class__ in WRAPPERS: value.encode(self) else: # store instance attributes as a struct (really?) self.dump_struct(value.__dict__)
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
Note that this reader is fairly tolerant, and gladly accepts bogus XML-RPC data without complaining (but not bogus XML).
Note that this reader is fairly tolerant, and gladly accepts bogus XML-RPC data without complaining (but not bogus XML).
def dump_instance(self, value): # check for special wrappers if value.__class__ in WRAPPERS: value.encode(self) else: # store instance attributes as a struct (really?) self.dump_struct(value.__dict__)
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
Create an instance of the fastest available parser, and attach it to an unmarshalling object. Return both objects.
Create an instance of the fastest available parser, and attach it to an unmarshalling object. Return both objects.
def getparser(): """getparser() -> parser, unmarshaller Create an instance of the fastest available parser, and attach it to an unmarshalling object. Return both objects. """ if FastParser and FastUnmarshaller: target = FastUnmarshaller(True, False, binary, datetime) parser = FastParser(target) else: target = Unmarshaller() if FastParser: parser = FastParser(target) elif SgmlopParser: parser = SgmlopParser(target) elif ExpatParser: parser = ExpatParser(target) else: parser = SlowParser(target) return parser, target
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
In addition to the data object, the following options can be given as keyword arguments:
In addition to the data object, the following options can be given as keyword arguments:
def dumps(params, methodname=None, methodresponse=None, encoding=None): """data [,options] -> marshalled data Convert an argument tuple or a Fault instance to an XML-RPC request (or response, if the methodresponse option is used). In addition to the data object, the following options can be given as keyword arguments: methodname: the method name for a methodCall packet methodresponse: true to create a methodResponse packet. If this option is used with a tuple, the tuple must be a singleton (i.e. it can contain only one element). encoding: the packet encoding (default is UTF-8) All 8-bit strings in the data structure are assumed to use the packet encoding. Unicode strings are automatically converted, as necessary. """ assert isinstance(params, TupleType) or isinstance(params, Fault),\ "argument must be tuple or Fault instance" if isinstance(params, Fault): methodresponse = 1 elif methodresponse and isinstance(params, TupleType): assert len(params) == 1, "response tuple must be a singleton" if not encoding: encoding = "utf-8" m = Marshaller(encoding) data = m.dumps(params) if encoding != "utf-8": xmlheader = "<?xml version='1.0' encoding=%s?>\n" % repr(encoding) else: xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default # standard XML-RPC wrappings if methodname: # a method call if not isinstance(methodname, StringType): methodname = methodname.encode(encoding) data = ( xmlheader, "<methodCall>\n" "<methodName>", methodname, "</methodName>\n", data, "</methodCall>\n" ) elif methodresponse: # a method response, or a fault structure data = ( xmlheader, "<methodResponse>\n", data, "</methodResponse>\n" ) else: return data # return as is return string.join(data, "")
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
as necessary.
where necessary.
def dumps(params, methodname=None, methodresponse=None, encoding=None): """data [,options] -> marshalled data Convert an argument tuple or a Fault instance to an XML-RPC request (or response, if the methodresponse option is used). In addition to the data object, the following options can be given as keyword arguments: methodname: the method name for a methodCall packet methodresponse: true to create a methodResponse packet. If this option is used with a tuple, the tuple must be a singleton (i.e. it can contain only one element). encoding: the packet encoding (default is UTF-8) All 8-bit strings in the data structure are assumed to use the packet encoding. Unicode strings are automatically converted, as necessary. """ assert isinstance(params, TupleType) or isinstance(params, Fault),\ "argument must be tuple or Fault instance" if isinstance(params, Fault): methodresponse = 1 elif methodresponse and isinstance(params, TupleType): assert len(params) == 1, "response tuple must be a singleton" if not encoding: encoding = "utf-8" m = Marshaller(encoding) data = m.dumps(params) if encoding != "utf-8": xmlheader = "<?xml version='1.0' encoding=%s?>\n" % repr(encoding) else: xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default # standard XML-RPC wrappings if methodname: # a method call if not isinstance(methodname, StringType): methodname = methodname.encode(encoding) data = ( xmlheader, "<methodCall>\n" "<methodName>", methodname, "</methodName>\n", data, "</methodCall>\n" ) elif methodresponse: # a method response, or a fault structure data = ( xmlheader, "<methodResponse>\n", data, "</methodResponse>\n" ) else: return data # return as is return string.join(data, "")
b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b0e8e9b72fb6eb42ecd4d9ea9e88563d1ca4528a/xmlrpclib.py
if 'Host' in (headers or [k for k in headers.iterkeys() if k.lower() == "host"]):
if 'host' in [k.lower() for k in headers]:
def _send_request(self, method, url, body, headers): # If headers already contains a host header, then define the # optional skip_host argument to putrequest(). The check is # harder because field names are case insensitive. if 'Host' in (headers or [k for k in headers.iterkeys() if k.lower() == "host"]): self.putrequest(method, url, skip_host=1) else: self.putrequest(method, url)
0c5b4ad8f2c83b8c7731731ae0ed48b95da9515e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0c5b4ad8f2c83b8c7731731ae0ed48b95da9515e/httplib.py
Keywords are width, height, startx and starty
Keywords are width, height, startx and starty:
def setup(**geometry): """ Sets the size and position of the main window. Keywords are width, height, startx and starty width: either a size in pixels or a fraction of the screen. Default is 50% of screen. height: either the height in pixels or a fraction of the screen. Default is 75% of screen. Setting either width or height to None before drawing will force use of default geometry as in older versions of turtle.py startx: starting position in pixels from the left edge of the screen. Default is to center window. Setting startx to None is the default and centers window horizontally on screen. starty: starting position in pixels from the top edge of the screen. Default is to center window. Setting starty to None is the default and centers window vertically on screen. Examples: >>> setup (width=200, height=200, startx=0, starty=0) sets window to 200x200 pixels, in upper left of screen >>> setup(width=.75, height=0.5, startx=None, starty=None) sets window to 75% of screen by 50% of screen and centers >>> setup(width=None) forces use of default geometry as in older versions of turtle.py """ global _width, _height, _startx, _starty width = geometry.get('width',_width) if width >= 0 or width == None: _width = width else: raise ValueError, "width can not be less than 0" height = geometry.get('height',_height) if height >= 0 or height == None: _height = height else: raise ValueError, "height can not be less than 0" startx = geometry.get('startx', _startx) if startx >= 0 or startx == None: _startx = _startx else: raise ValueError, "startx can not be less than 0" starty = geometry.get('starty', _starty) if starty >= 0 or starty == None: _starty = starty else: raise ValueError, "startx can not be less than 0" if _root and _width and _height: if 0 < _width <= 1: _width = _root.winfo_screenwidth() * +width if 0 < _height <= 1: _height = _root.winfo_screenheight() * _height # center window on screen if _startx is None: _startx = (_root.winfo_screenwidth() - _width) / 2 if _starty is None: _starty = (_root.winfo_screenheight() - _height) / 2 _root.geometry("%dx%d+%d+%d" % (_width, _height, _startx, _starty))
e2222a083b434b582d7b7f8d1e7155b55b769323 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/e2222a083b434b582d7b7f8d1e7155b55b769323/turtle.py
""" set the window title.
"""Set the window title.
def title(title): """ set the window title. By default this is set to 'Turtle Graphics' Example: >>> title("My Window") """ global _title _title = title
e2222a083b434b582d7b7f8d1e7155b55b769323 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/e2222a083b434b582d7b7f8d1e7155b55b769323/turtle.py
home = os.environ['HOME']
home = os.environ.get('HOME')
def addpackage(sitedir, name): global _dirs_in_sys_path if _dirs_in_sys_path is None: _init_pathinfo() reset = 1 else: reset = 0 fullname = os.path.join(sitedir, name) try: f = open(fullname) except IOError: return while 1: dir = f.readline() if not dir: break if dir[0] == '#': continue if dir.startswith("import"): exec dir continue if dir[-1] == '\n': dir = dir[:-1] dir, dircase = makepath(sitedir, dir) if not dircase in _dirs_in_sys_path and os.path.exists(dir): sys.path.append(dir) _dirs_in_sys_path[dircase] = 1 if reset: _dirs_in_sys_path = None
470b0c0e1f7247539210cb5c13f8cb0f28894714 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/470b0c0e1f7247539210cb5c13f8cb0f28894714/site.py
tests = [Signed_TestCase, Unsigned_TestCase]
tests = [Signed_TestCase, Unsigned_TestCase, Tuple_TestCase]
def test_main(): tests = [Signed_TestCase, Unsigned_TestCase] try: from _testcapi import getargs_L, getargs_K except ImportError: pass # PY_LONG_LONG not available else: tests.append(LongLong_TestCase) test_support.run_unittest(*tests)
5f135787ec4040bfbeb16f2944086028635151db /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/5f135787ec4040bfbeb16f2944086028635151db/test_getargs2.py
import traceback
def formatException(self, ei): """ Format and return the specified exception information as a string.
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
import traceback
def handleError(self, record): """ Handle errors which occur during an emit() call.
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
def __init__(self, filename, mode="a"):
def __init__(self, filename, mode='a', encoding=None):
def __init__(self, filename, mode="a"): """ Open the specified file and use it as the stream for logging. """ StreamHandler.__init__(self, open(filename, mode)) #keep the absolute path, otherwise derived classes which use this #may come a cropper when the current directory changes self.baseFilename = os.path.abspath(filename) self.mode = mode
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
StreamHandler.__init__(self, open(filename, mode))
if codecs is None: encoding = None if encoding is None: stream = open(filename, mode) else: stream = codecs.open(filename, mode, encoding) StreamHandler.__init__(self, stream)
def __init__(self, filename, mode="a"): """ Open the specified file and use it as the stream for logging. """ StreamHandler.__init__(self, open(filename, mode)) #keep the absolute path, otherwise derived classes which use this #may come a cropper when the current directory changes self.baseFilename = os.path.abspath(filename) self.mode = mode
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
(if filemode is unspecified, it defaults to "a").
(if filemode is unspecified, it defaults to 'a').
def basicConfig(**kwargs): """ Do basic configuration for the logging system. This function does nothing if the root logger already has handlers configured. It is a convenience method intended for use by simple scripts to do one-shot configuration of the logging package. The default behaviour is to create a StreamHandler which writes to sys.stderr, set a formatter using the BASIC_FORMAT format string, and add the handler to the root logger. A number of optional keyword arguments may be specified, which can alter the default behaviour. filename Specifies that a FileHandler be created, using the specified filename, rather than a StreamHandler. filemode Specifies the mode to open the file, if filename is specified (if filemode is unspecified, it defaults to "a"). format Use the specified format string for the handler. datefmt Use the specified date/time format. level Set the root logger level to the specified level. stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with 'filename' - if both are present, 'stream' is ignored. Note that you could specify a stream created using open(filename, mode) rather than passing the filename and mode in. However, it should be remembered that StreamHandler does not close its stream (since it may be using sys.stdout or sys.stderr), whereas FileHandler closes its stream when the handler is closed. """ if len(root.handlers) == 0: filename = kwargs.get("filename") if filename: mode = kwargs.get("filemode", "a") hdlr = FileHandler(filename, mode) else: stream = kwargs.get("stream") hdlr = StreamHandler(stream) fs = kwargs.get("format", BASIC_FORMAT) dfs = kwargs.get("datefmt", None) fmt = Formatter(fs, dfs) hdlr.setFormatter(fmt) root.addHandler(hdlr) level = kwargs.get("level") if level: root.setLevel(level)
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
mode = kwargs.get("filemode", "a")
mode = kwargs.get("filemode", 'a')
def basicConfig(**kwargs): """ Do basic configuration for the logging system. This function does nothing if the root logger already has handlers configured. It is a convenience method intended for use by simple scripts to do one-shot configuration of the logging package. The default behaviour is to create a StreamHandler which writes to sys.stderr, set a formatter using the BASIC_FORMAT format string, and add the handler to the root logger. A number of optional keyword arguments may be specified, which can alter the default behaviour. filename Specifies that a FileHandler be created, using the specified filename, rather than a StreamHandler. filemode Specifies the mode to open the file, if filename is specified (if filemode is unspecified, it defaults to "a"). format Use the specified format string for the handler. datefmt Use the specified date/time format. level Set the root logger level to the specified level. stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with 'filename' - if both are present, 'stream' is ignored. Note that you could specify a stream created using open(filename, mode) rather than passing the filename and mode in. However, it should be remembered that StreamHandler does not close its stream (since it may be using sys.stdout or sys.stderr), whereas FileHandler closes its stream when the handler is closed. """ if len(root.handlers) == 0: filename = kwargs.get("filename") if filename: mode = kwargs.get("filemode", "a") hdlr = FileHandler(filename, mode) else: stream = kwargs.get("stream") hdlr = StreamHandler(stream) fs = kwargs.get("format", BASIC_FORMAT) dfs = kwargs.get("datefmt", None) fmt = Formatter(fs, dfs) hdlr.setFormatter(fmt) root.addHandler(hdlr) level = kwargs.get("level") if level: root.setLevel(level)
b89e7c9bc97d3f9332ecc94c88a055c0fe947625 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/b89e7c9bc97d3f9332ecc94c88a055c0fe947625/__init__.py
if not str:
if not s:
def decode(in_file, out_file=None, mode=None): """Decode uuencoded file""" # # Open the input file, if needed. # if in_file == '-': in_file = sys.stdin elif type(in_file) == type(''): in_file = open(in_file) # # Read until a begin is encountered or we've exhausted the file # while 1: hdr = in_file.readline() if not hdr: raise Error, 'No valid begin line found in input file' if hdr[:5] != 'begin': continue hdrfields = hdr.split(" ", 2) if len(hdrfields) == 3 and hdrfields[0] == 'begin': try: int(hdrfields[1], 8) break except ValueError: pass if out_file is None: out_file = hdrfields[2].rstrip() if mode is None: mode = int(hdrfields[1], 8) # # Open the output file # if out_file == '-': out_file = sys.stdout elif type(out_file) == type(''): fp = open(out_file, 'wb') try: os.path.chmod(out_file, mode) except AttributeError: pass out_file = fp # # Main decoding loop # s = in_file.readline() while s and s != 'end\n': try: data = binascii.a2b_uu(s) except binascii.Error, v: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3 data = binascii.a2b_uu(s[:nbytes]) sys.stderr.write("Warning: %s\n" % str(v)) out_file.write(data) s = in_file.readline() if not str: raise Error, 'Truncated input file'
79c8671c7aee3dfaeb3aa9ce14abe08cc30ecc54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/79c8671c7aee3dfaeb3aa9ce14abe08cc30ecc54/uu.py
self.assertEqual(stderr, "pineapple")
self.assert_(stderr.startswith("pineapple"))
def test_communicate_stderr(self): p = subprocess.Popen([sys.executable, "-c", 'import sys; sys.stderr.write("pineapple")'], stderr=subprocess.PIPE) (stdout, stderr) = p.communicate() self.assertEqual(stdout, None) self.assertEqual(stderr, "pineapple")
653a5adcca68d445b21dd2a640627f0f0185204a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/653a5adcca68d445b21dd2a640627f0f0185204a/test_subprocess.py
self._lookup()
assert self._toc is not None self._file.seek(0, 2) cur_len = self._file.tell() if cur_len != self._file_length: raise ExternalClashError('Size of mailbox file changed ' '(expected %i, found %i)' % (self._file_length, cur_len))
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 _sync_close(new_file) # self._file is about to get replaced, so no need to sync. 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)
eca4c31267526dffe471bc78712dd884c4f04c34 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/eca4c31267526dffe471bc78712dd884c4f04c34/mailbox.py
self._file.seek(0, 2) self._file_length = self._file.tell()
def _generate_toc(self): """Generate key-to-(start, stop) table of contents.""" starts, stops = [], [] self._file.seek(0) next_pos = 0 label_lists = [] while True: line_pos = next_pos line = self._file.readline() next_pos = self._file.tell() if line == '\037\014' + os.linesep: if len(stops) < len(starts): stops.append(line_pos - len(os.linesep)) starts.append(next_pos) labels = [label.strip() for label in self._file.readline()[1:].split(',') if label.strip() != ''] label_lists.append(labels) elif line == '\037' or line == '\037' + os.linesep: if len(stops) < len(starts): stops.append(line_pos - len(os.linesep)) elif line == '': stops.append(line_pos - len(os.linesep)) break self._toc = dict(enumerate(zip(starts, stops))) self._labels = dict(enumerate(label_lists)) self._next_key = len(self._toc)
eca4c31267526dffe471bc78712dd884c4f04c34 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/eca4c31267526dffe471bc78712dd884c4f04c34/mailbox.py
print 'Deleted breakpoint %s ' % (i,)
print 'Deleted breakpoint', i
def do_clear(self, arg): """Three possibilities, tried in this order: clear -> clear all breaks, ask for confirmation clear file:lineno -> clear all breaks at file:lineno clear bpno bpno ... -> clear breakpoints by number""" if not arg: try: reply = raw_input('Clear all breaks? ') except EOFError: reply = 'no' reply = reply.strip().lower() if reply in ('y', 'yes'): self.clear_all_breaks() return if ':' in arg: # Make sure it works for "clear C:\foo\bar.py:12" i = arg.rfind(':') filename = arg[:i] arg = arg[i+1:] try: lineno = int(arg) except: err = "Invalid line number (%s)" % arg else: err = self.clear_break(filename, lineno) if err: print '***', err return numberlist = arg.split() for i in numberlist: err = self.clear_bpbynumber(i) if err: print '***', err else: print 'Deleted breakpoint %s ' % (i,)
6d2b346140ed0f3bc4c67fc33bf69a60c496e6a4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/6d2b346140ed0f3bc4c67fc33bf69a60c496e6a4/pdb.py
res = [] for c in s: if c in safe: res.append(c) else: res.append('%%%02x' % ord(c))
res = list(s) for i in range(len(res)): c = res[i] if c not in safe: res[i] = '%%%02x' % ord(c)
def quote(s, safe = '/'): safe = always_safe + safe res = [] for c in s: if c in safe: res.append(c) else: res.append('%%%02x' % ord(c)) return string.joinfields(res, '')
810a3396d130eda7d3e2be08966b40949757598e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/810a3396d130eda7d3e2be08966b40949757598e/urllib.py
s = string.join(string.split(s, ' '), '+') return quote(s, safe + '+')
l = string.split(s, ' ') for i in range(len(l)): l[i] = quote(l[i], safe) return string.join(l, '+')
def quote_plus(s, safe = '/'): if ' ' in s: # replace ' ' with '+' s = string.join(string.split(s, ' '), '+') return quote(s, safe + '+') else: return quote(s, safe)
810a3396d130eda7d3e2be08966b40949757598e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/810a3396d130eda7d3e2be08966b40949757598e/urllib.py
* any RCS or CVS directories
* any RCS, CVS and .svn directories
def prune_file_list (self): """Prune off branches that might slip into the file list as created by 'read_template()', but really don't belong there: * the build tree (typically "build") * the release tree itself (only an issue if we ran "sdist" previously with --keep-temp, or it aborted) * any RCS or CVS directories """ build = self.get_finalized_command('build') base_dir = self.distribution.get_fullname()
2f50e90818f17dd20760c9eb0854b603634f157d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2f50e90818f17dd20760c9eb0854b603634f157d/sdist.py
self.filelist.exclude_pattern(r'/(RCS|CVS)/.*', is_regex=1)
self.filelist.exclude_pattern(r'/(RCS|CVS|\.svn)/.*', is_regex=1)
def prune_file_list (self): """Prune off branches that might slip into the file list as created by 'read_template()', but really don't belong there: * the build tree (typically "build") * the release tree itself (only an issue if we ran "sdist" previously with --keep-temp, or it aborted) * any RCS or CVS directories """ build = self.get_finalized_command('build') base_dir = self.distribution.get_fullname()
2f50e90818f17dd20760c9eb0854b603634f157d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2f50e90818f17dd20760c9eb0854b603634f157d/sdist.py
fp.write("%s = %s\n" % (key, value))
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
def write(self, fp): """Write an .ini-format representation of the configuration state.""" if self.__defaults: fp.write("[DEFAULT]\n") for (key, value) in self.__defaults.items(): fp.write("%s = %s\n" % (key, value)) fp.write("\n") for section in self.sections(): fp.write("[" + section + "]\n") sectdict = self.__sections[section] for (key, value) in sectdict.items(): if key == "__name__": continue fp.write("%s = %s\n" % (key, value)) fp.write("\n")
00824ed733a5bd9cd94227fdfbf33b98f1ae900a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/00824ed733a5bd9cd94227fdfbf33b98f1ae900a/ConfigParser.py
fp.write("%s = %s\n" % (key, value))
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
def write(self, fp): """Write an .ini-format representation of the configuration state.""" if self.__defaults: fp.write("[DEFAULT]\n") for (key, value) in self.__defaults.items(): fp.write("%s = %s\n" % (key, value)) fp.write("\n") for section in self.sections(): fp.write("[" + section + "]\n") sectdict = self.__sections[section] for (key, value) in sectdict.items(): if key == "__name__": continue fp.write("%s = %s\n" % (key, value)) fp.write("\n")
00824ed733a5bd9cd94227fdfbf33b98f1ae900a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/00824ed733a5bd9cd94227fdfbf33b98f1ae900a/ConfigParser.py
print '--Call--' self.interaction(frame, None)
if self.stop_here(frame): print '--Call--' self.interaction(frame, None)
def user_call(self, frame, argument_list): """This method is called when there is the remote possibility that we ever need to stop in this function.""" print '--Call--' self.interaction(frame, None)
01eb85cc0324a42160b676ee31a1a707bda579ee /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/01eb85cc0324a42160b676ee31a1a707bda579ee/pdb.py
if not modname:
if not modname or '.' in modname:
def search_function(encoding): # Cache lookup entry = _cache.get(encoding, _unknown) if entry is not _unknown: return entry # Import the module: # # First try to find an alias for the normalized encoding # name and lookup the module using the aliased name, then try to # lookup the module using the standard import scheme, i.e. first # try in the encodings package, then at top-level. # norm_encoding = normalize_encoding(encoding) aliased_encoding = _aliases.get(norm_encoding) or \ _aliases.get(norm_encoding.replace('.', '_')) if aliased_encoding is not None: modnames = [aliased_encoding, norm_encoding] else: modnames = [norm_encoding] for modname in modnames: if not modname: continue try: mod = __import__('encodings.' + modname, globals(), locals(), _import_tail) except ImportError: pass else: break else: mod = None try: getregentry = mod.getregentry except AttributeError: # Not a codec module mod = None if mod is None: # Cache misses _cache[encoding] = None return None # Now ask the module for the registry entry entry = getregentry() if not isinstance(entry, codecs.CodecInfo): if not 4 <= len(entry) <= 7: raise CodecRegistryError,\ 'module "%s" (%s) failed to register' % \ (mod.__name__, mod.__file__) if not callable(entry[0]) or \ not callable(entry[1]) or \ (entry[2] is not None and not callable(entry[2])) or \ (entry[3] is not None and not callable(entry[3])) or \ (len(entry) > 4 and entry[4] is not None and not callable(entry[4])) or \ (len(entry) > 5 and entry[5] is not None and not callable(entry[5])): raise CodecRegistryError,\ 'incompatible codecs in module "%s" (%s)' % \ (mod.__name__, mod.__file__) if len(entry)<7 or entry[6] is None: entry += (None,)*(6-len(entry)) + (mod.__name__.split(".", 1)[1],) entry = codecs.CodecInfo(*entry) # Cache the codec registry entry _cache[encoding] = entry # Register its aliases (without overwriting previously registered # aliases) try: codecaliases = mod.getaliases() except AttributeError: pass else: for alias in codecaliases: if not _aliases.has_key(alias): _aliases[alias] = modname # Return the registry entry return entry
a92979a1db11ca42e78390fead218afbefb61587 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/a92979a1db11ca42e78390fead218afbefb61587/__init__.py
f = open('/dev/null', 'wb')
if sys.platform[:3]=="win": f = open('nul', 'wb') else: f = open('/dev/null', 'wb')
def main(): VERBOSE = 0 opts, args = getopt.getopt(sys.argv[1:], 'vq') for k, v in opts: if k == '-v': VERBOSE = 1 visitor.ASTVisitor.VERBOSE = visitor.ASTVisitor.VERBOSE + 1 if k == '-q': f = open('/dev/null', 'wb') sys.stdout = f if not args: print "no files to compile" else: for filename in args: if VERBOSE: print filename compile(filename)
0a4f1ff64eeb50cdf0b81bd4cff5b2e1d159daa5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a4f1ff64eeb50cdf0b81bd4cff5b2e1d159daa5/compile.py
print dom
confirm(isinstance(dom,Document))
def testParseFromFile(): from StringIO import StringIO dom=parse( StringIO( open( tstfile ).read() ) ) print dom
89c528b02d5fad6a211f3f9e6915677e1baa7806 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/89c528b02d5fad6a211f3f9e6915677e1baa7806/test_minidom.py
print Node.allnodes.items()[0:10]
if verbose: print Node.allnodes.items()[0:10] else: print len(Node.allnodes)
def testClonePIDeep(): pass
89c528b02d5fad6a211f3f9e6915677e1baa7806 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/89c528b02d5fad6a211f3f9e6915677e1baa7806/test_minidom.py
def message_from_string(s, _class=_Message): return _Parser(_class).parsestr(s)
def message_from_string(s, _class=_Message, strict=1): return _Parser(_class, strict=strict).parsestr(s)
def message_from_string(s, _class=_Message): return _Parser(_class).parsestr(s)
2d2fc229a05ae4bb65a8d0c1f7a588b73539d361 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2d2fc229a05ae4bb65a8d0c1f7a588b73539d361/__init__.py
testtar = path("testtar" + os.extsep + "tar") tempdir = path("testtar" + os.extsep + "dir") tempname = path("testtar" + os.extsep + "tmp")
testtar = path("testtar.tar") tempdir = os.path.join(tempfile.gettempdir(), "testtar" + os.extsep + "dir") tempname = test_support.TESTFN
def path(path): return test_support.findfile(path)
455ea53d0e7a21af210eef71644700b3979badce /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/455ea53d0e7a21af210eef71644700b3979badce/test_tarfile.py
if os.path.exists(tempdir): shutil.rmtree(tempdir) if os.path.exists(tempname): os.remove(tempname)
if os.path.exists(dirname()): shutil.rmtree(dirname()) if os.path.exists(tmpname()): os.remove(tmpname())
def test_main(): if gzip: # create testtar.tar.gz gzip.open(tarname("gz"), "wb").write(file(tarname(), "rb").read()) if bz2: # create testtar.tar.bz2 bz2.BZ2File(tarname("bz2"), "wb").write(file(tarname(), "rb").read()) tests = [ ReadTest, ReadStreamTest, WriteTest, WriteStreamTest ] if gzip: tests.extend([ ReadTestGzip, ReadStreamTestGzip, WriteTestGzip, WriteStreamTestGzip ]) if bz2: tests.extend([ ReadTestBzip2, ReadStreamTestBzip2, WriteTestBzip2, WriteStreamTestBzip2 ]) try: test_support.run_unittest(*tests) finally: if gzip: os.remove(tarname("gz")) if bz2: os.remove(tarname("bz2")) if os.path.exists(tempdir): shutil.rmtree(tempdir) if os.path.exists(tempname): os.remove(tempname)
455ea53d0e7a21af210eef71644700b3979badce /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/455ea53d0e7a21af210eef71644700b3979badce/test_tarfile.py
if verbose: if output: print "%s %% %s =? %s ..." %\ (repr(formatstr), repr(args), repr(output)), else: print "%s %% %s works? ..." % (repr(formatstr), repr(args)), try: result = formatstr % args except OverflowError: if verbose: print 'overflow (this is fine)' else: if output and result != output: if verbose: print 'no' print "%s %% %s == %s != %s" %\ (repr(formatstr), repr(args), repr(result), repr(output)) else: if verbose: print 'yes'
if verbose: if output: print "%s %% %s =? %s ..." %\ (repr(formatstr), repr(args), repr(output)), else: print "%s %% %s works? ..." % (repr(formatstr), repr(args)), try: result = formatstr % args except OverflowError: if not overflowok: raise if verbose: print 'overflow (this is fine)' else: if output and result != output: if verbose: print 'no' print "%s %% %s == %s != %s" %\ (repr(formatstr), repr(args), repr(result), repr(output)) else: if verbose: print 'yes'
def testformat(formatstr, args, output=None): if verbose: if output: print "%s %% %s =? %s ..." %\ (repr(formatstr), repr(args), repr(output)), else: print "%s %% %s works? ..." % (repr(formatstr), repr(args)), try: result = formatstr % args except OverflowError: if verbose: print 'overflow (this is fine)' else: if output and result != output: if verbose: print 'no' print "%s %% %s == %s != %s" %\ (repr(formatstr), repr(args), repr(result), repr(output)) else: if verbose: print 'yes'
38fd5b641366eedc74e4be3a0e4d2210f3bcdb5a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/38fd5b641366eedc74e4be3a0e4d2210f3bcdb5a/test_format.py
testformat(formatstr, *args) testformat(unicode(formatstr), *args)
testformat(formatstr, *args) testformat(unicode(formatstr), *args)
def testboth(formatstr, *args): testformat(formatstr, *args) testformat(unicode(formatstr), *args)
38fd5b641366eedc74e4be3a0e4d2210f3bcdb5a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/38fd5b641366eedc74e4be3a0e4d2210f3bcdb5a/test_format.py
else: boundary = ""
if not valid_boundary(boundary): raise ValueError, ('Invalid boundary in multipart form: %s' % `ib`)
def parse_multipart(fp, pdict): """Parse multipart input. Arguments: fp : input file pdict: dictionary containing other parameters of conten-type header Returns a dictionary just like parse_qs(): keys are the field names, each value is a list of values for that field. This is easy to use but not much good if you are expecting megabytes to be uploaded -- in that case, use the FieldStorage class instead which is much more flexible. Note that content-type is the raw, unparsed contents of the content-type header. XXX This does not parse nested multipart parts -- use FieldStorage for that. XXX This should really be subsumed by FieldStorage altogether -- no point in having two implementations of the same parsing algorithm. """ if pdict.has_key('boundary'): boundary = pdict['boundary'] else: boundary = "" nextpart = "--" + boundary lastpart = "--" + boundary + "--" partdict = {} terminator = "" while terminator != lastpart: bytes = -1 data = None if terminator: # At start of next part. Read headers first. headers = mimetools.Message(fp) clength = headers.getheader('content-length') if clength: try: bytes = int(clength) except ValueError: pass if bytes > 0: if maxlen and bytes > maxlen: raise ValueError, 'Maximum content length exceeded' data = fp.read(bytes) else: data = "" # Read lines until end of part. lines = [] while 1: line = fp.readline() if not line: terminator = lastpart # End outer loop break if line[:2] == "--": terminator = line.strip() if terminator in (nextpart, lastpart): break lines.append(line) # Done with part. if data is None: continue if bytes < 0: if lines: # Strip final line terminator line = lines[-1] if line[-2:] == "\r\n": line = line[:-2] elif line[-1:] == "\n": line = line[:-1] lines[-1] = line data = "".join(lines) line = headers['content-disposition'] if not line: continue key, params = parse_header(line) if key != 'form-data': continue if params.has_key('name'): name = params['name'] else: continue if partdict.has_key(name): partdict[name].append(data) else: partdict[name] = [data] return partdict
2e441f7836134c475e35eea4a005f19699703a9b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2e441f7836134c475e35eea4a005f19699703a9b/cgi.py
part = klass(self.fp, {}, self.innerboundary,
part = klass(self.fp, {}, ib,
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" self.list = [] klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, self.innerboundary, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, self.innerboundary, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
2e441f7836134c475e35eea4a005f19699703a9b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2e441f7836134c475e35eea4a005f19699703a9b/cgi.py
part = klass(self.fp, headers, self.innerboundary,
part = klass(self.fp, headers, ib,
def read_multi(self, environ, keep_blank_values, strict_parsing): """Internal: read a part that is itself multipart.""" self.list = [] klass = self.FieldStorageClass or self.__class__ part = klass(self.fp, {}, self.innerboundary, environ, keep_blank_values, strict_parsing) # Throw first part away while not part.done: headers = rfc822.Message(self.fp) part = klass(self.fp, headers, self.innerboundary, environ, keep_blank_values, strict_parsing) self.list.append(part) self.skip_lines()
2e441f7836134c475e35eea4a005f19699703a9b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2e441f7836134c475e35eea4a005f19699703a9b/cgi.py
if os.name == 'mac': import macfs fss, ok = macfs.GetDirectory('Directory to zap pyc files in') if not ok: sys.exit(0) dir = fss.as_pathname() zappyc(dir) else: if not sys.argv[1:]:
if not sys.argv[1:]: if os.name == 'mac': import macfs fss, ok = macfs.GetDirectory('Directory to zap pyc files in') if not ok: sys.exit(0) dir = fss.as_pathname() zappyc(dir) else:
def main(): if os.name == 'mac': import macfs fss, ok = macfs.GetDirectory('Directory to zap pyc files in') if not ok: sys.exit(0) dir = fss.as_pathname() zappyc(dir) else: if not sys.argv[1:]: print 'Usage: zappyc dir ...' sys.exit(1) for dir in sys.argv[1:]: zappyc(dir)
f1148f0bb3b227baac1708221cbf818427365c09 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/f1148f0bb3b227baac1708221cbf818427365c09/zappycfiles.py
for dir in sys.argv[1:]: zappyc(dir)
for dir in sys.argv[1:]: zappyc(dir)
def main(): if os.name == 'mac': import macfs fss, ok = macfs.GetDirectory('Directory to zap pyc files in') if not ok: sys.exit(0) dir = fss.as_pathname() zappyc(dir) else: if not sys.argv[1:]: print 'Usage: zappyc dir ...' sys.exit(1) for dir in sys.argv[1:]: zappyc(dir)
f1148f0bb3b227baac1708221cbf818427365c09 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/f1148f0bb3b227baac1708221cbf818427365c09/zappycfiles.py
if n > self.maxlist: s = s + ', ...'
if n > self.maxdict: s = s + ', ...'
def repr_dictionary(self, x, level): n = len(x) if n == 0: return '{}' if level <= 0: return '{...}' s = '' keys = x.keys() keys.sort() for i in range(min(n, self.maxdict)): if s: s = s + ', ' key = keys[i] s = s + self.repr1(key, level-1) s = s + ': ' + self.repr1(x[key], level-1) if n > self.maxlist: s = s + ', ...' return '{' + s + '}'
ff3a278d3be871942e8fe14c01a70d03cdac752d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/ff3a278d3be871942e8fe14c01a70d03cdac752d/repr.py
sys.stderr = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stderr) sys.stderr = sys.__stderr__
save_stderr = sys.stderr try: sys.stderr = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stderr) finally: sys.stderr = save_stderr
def assertParseFail(self, cmdline_args, expected_output): """Assert the parser fails with the expected message.""" sys.stderr = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stderr) sys.stderr = sys.__stderr__
579f7355fe2c90b3f7001135c0ec0766dad6d244 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/579f7355fe2c90b3f7001135c0ec0766dad6d244/test_optparse.py
sys.stdout = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stdout) sys.stdout = sys.__stdout__
save_stdout = sys.stdout try: sys.stdout = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stdout) finally: sys.stdout = save_stdout
def assertStdoutEquals(self, cmdline_args, expected_output): """Assert the parser prints the expected output on stdout.""" sys.stdout = StringIO() self.assertRaises(self.parser.parse_args, (cmdline_args,), None, SystemExit, expected_output, self.redirected_stdout) sys.stdout = sys.__stdout__
579f7355fe2c90b3f7001135c0ec0766dad6d244 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/579f7355fe2c90b3f7001135c0ec0766dad6d244/test_optparse.py
sys.argv[0] = "/foo/bar/baz.py" parser = OptionParser("usage: %prog ...", version="%prog 1.2") expected_usage = "usage: baz.py ...\n" self.assertUsage(parser, expected_usage) self.assertVersion(parser, "baz.py 1.2") self.assertHelp(parser, expected_usage + "\n" + "options:\n" " --version show program's version number and exit\n" " -h, --help show this help message and exit\n")
save_argv = sys.argv[:] try: sys.argv[0] = "/foo/bar/baz.py" parser = OptionParser("usage: %prog ...", version="%prog 1.2") expected_usage = "usage: baz.py ...\n" self.assertUsage(parser, expected_usage) self.assertVersion(parser, "baz.py 1.2") self.assertHelp(parser, expected_usage + "\n" + "options:\n" " --version show program's version number and exit\n" " -h, --help show this help message and exit\n") finally: sys.argv[:] = save_argv
def test_default_progname(self): # Make sure that program name taken from sys.argv[0] by default. sys.argv[0] = "/foo/bar/baz.py" parser = OptionParser("usage: %prog ...", version="%prog 1.2") expected_usage = "usage: baz.py ...\n" self.assertUsage(parser, expected_usage) self.assertVersion(parser, "baz.py 1.2") self.assertHelp(parser, expected_usage + "\n" + "options:\n" " --version show program's version number and exit\n" " -h, --help show this help message and exit\n")
579f7355fe2c90b3f7001135c0ec0766dad6d244 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/579f7355fe2c90b3f7001135c0ec0766dad6d244/test_optparse.py
onoff = 0 else: onoff = 255 if self.barx: self.barx.HiliteControl(onoff) if self.bary: self.bary.HiliteControl(onoff)
if self.barx and self.barx_enabled: self.barx.HiliteControl(0) if self.bary and self.bary_enabled: self.bary.HiliteControl(0) else: if self.barx: self.barx.HiliteControl(255) if self.bary: self.bary.HiliteControl(255)
def do_activate(self, onoff, event): if onoff: onoff = 0 else: onoff = 255 if self.barx: self.barx.HiliteControl(onoff) if self.bary: self.bary.HiliteControl(onoff)
7bfc875270587bd6819702ab51d0a6a41aaec0cb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7bfc875270587bd6819702ab51d0a6a41aaec0cb/FrameWork.py
self.barx.SetControlValue(vx)
if vx == None: self.barx.HiliteControl(255) self.barx_enabled = 0 else: if not self.barx_enabled: self.barx_enabled = 1 if self.activated: self.barx.HiliteControl(0) self.barx.SetControlValue(vx)
def updatescrollbars(self): SetPort(self.wid) vx, vy = self.getscrollbarvalues() if self.barx: self.barx.SetControlValue(vx) if self.bary: self.bary.SetControlValue(vy)
7bfc875270587bd6819702ab51d0a6a41aaec0cb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7bfc875270587bd6819702ab51d0a6a41aaec0cb/FrameWork.py
self.bary.SetControlValue(vy)
if vy == None: self.bary.HiliteControl(255) self.bary_enabled = 0 else: if not self.bary_enabled: self.bary_enabled = 1 if self.activated: self.bary.HiliteControl(0) self.bary.SetControlValue(vy) def scalebarvalue(self, absmin, absmax, curmin, curmax): if curmin <= absmin and curmax >= absmax: return None if curmin <= absmin: return 0 if curmax >= absmax: return 32767 perc = float(curmin-absmin)/float(absmax-absmin) return int(perc*32767)
def updatescrollbars(self): SetPort(self.wid) vx, vy = self.getscrollbarvalues() if self.barx: self.barx.SetControlValue(vx) if self.bary: self.bary.SetControlValue(vy)
7bfc875270587bd6819702ab51d0a6a41aaec0cb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7bfc875270587bd6819702ab51d0a6a41aaec0cb/FrameWork.py
incomment = ''
instr = '' brackets = 0
def checkline(self, filename, lineno): """Return line number of first line at or after input argument such that if the input points to a 'def', the returned line number is the first non-blank/non-comment line to follow. If the input points to a blank or comment line, return 0. At end of file, also return 0."""
e85c93f52109711f415e860ba41609ae22984d92 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/e85c93f52109711f415e860ba41609ae22984d92/pdb.py
if incomment: if len(line) < 3: continue if (line[-3:] == incomment): incomment = '' continue
def checkline(self, filename, lineno): """Return line number of first line at or after input argument such that if the input points to a 'def', the returned line number is the first non-blank/non-comment line to follow. If the input points to a blank or comment line, return 0. At end of file, also return 0."""
e85c93f52109711f415e860ba41609ae22984d92 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/e85c93f52109711f415e860ba41609ae22984d92/pdb.py
if len(line) >= 3: if (line[:3] == '"""' or line[:3] == "'''"): if line[-3:] == line[:3]: continue incomment = line[:3] continue if line[0] != '
if brackets <= 0 and line[0] not in (' break
def checkline(self, filename, lineno): """Return line number of first line at or after input argument such that if the input points to a 'def', the returned line number is the first non-blank/non-comment line to follow. If the input points to a blank or comment line, return 0. At end of file, also return 0."""
e85c93f52109711f415e860ba41609ae22984d92 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/e85c93f52109711f415e860ba41609ae22984d92/pdb.py
dict = readmodule_ex(module, path)
dict = _readmodule(module, path)
def readmodule(module, path=[]): '''Backwards compatible interface. Call readmodule_ex() and then only keep Class objects from the resulting dictionary.''' dict = readmodule_ex(module, path) res = {} for key, value in dict.items(): if isinstance(value, Class): res[key] = value return res
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
def readmodule_ex(module, path=[], inpackage=None):
def readmodule_ex(module, path=[]):
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
return _readmodule(module, path) def _readmodule(module, path, inpackage=None): '''Do the hard work for readmodule[_ex].'''
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
parent = readmodule_ex(package, path, inpackage)
parent = _readmodule(package, path, inpackage)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
return readmodule_ex(submodule, parent['__path__'], package)
return _readmodule(submodule, parent['__path__'], package)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
classstack = []
stack = []
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
if token == 'def':
if tokentype == DEDENT:
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno)
if stack: cur_class = stack[-1][0] if isinstance(cur_class, Class): cur_class._addmethod(meth_name, lineno)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1]
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
dict[class_name] = cur_class classstack.append((cur_class, thisindent))
if not stack: dict[class_name] = cur_class stack.append((cur_class, thisindent))
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
readmodule_ex(mod, path)
_readmodule(mod, path)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
readmodule_ex(mod, path, inpackage)
_readmodule(mod, path, inpackage)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
readmodule_ex(mod)
_readmodule(mod, [])
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
d = readmodule_ex(mod, path, inpackage)
d = _readmodule(mod, path, inpackage)
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
if n[0] != '_' and not n in dict:
if n[0] != '_':
def readmodule_ex(module, path=[], inpackage=None): '''Read a module file and return a dictionary of classes. Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module. If INPACKAGE is true, it must be the dotted name of the package in which we are searching for a submodule, and then PATH must be the package search path; otherwise, we are searching for a top-level module, and PATH is combined with sys.path. ''' # Compute the full module name (prepending inpackage if set) if inpackage: fullmodule = "%s.%s" % (inpackage, module) else: fullmodule = module # Check in the cache if fullmodule in _modules: return _modules[fullmodule] # Initialize the dict for this module's contents dict = {} # Check if it is a built-in module; we don't do much for these if module in sys.builtin_module_names and not inpackage: _modules[module] = dict return dict # Check for a dotted module name i = module.rfind('.') if i >= 0: package = module[:i] submodule = module[i+1:] parent = readmodule_ex(package, path, inpackage) if inpackage: package = "%s.%s" % (inpackage, package) return readmodule_ex(submodule, parent['__path__'], package) # Search the path for the module f = None if inpackage: f, file, (suff, mode, type) = imp.find_module(module, path) else: f, file, (suff, mode, type) = imp.find_module(module, path + sys.path) if type == imp.PKG_DIRECTORY: dict['__path__'] = [file] path = [file] + path f, file, (suff, mode, type) = imp.find_module('__init__', [file]) _modules[fullmodule] = dict if type != imp.PY_SOURCE: # not Python source, can't do anything with this module f.close() return dict classstack = [] # stack of (class, indent) pairs g = tokenize.generate_tokens(f.readline) try: for tokentype, token, start, end, line in g: if token == 'def': lineno, thisindent = start tokentype, meth_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] if classstack: # it's a class method cur_class = classstack[-1][0] cur_class._addmethod(meth_name, lineno) else: # it's a function dict[meth_name] = Function(module, meth_name, file, lineno) elif token == 'class': lineno, thisindent = start tokentype, class_name, start, end, line = g.next() if tokentype != NAME: continue # Syntax error # close all classes indented at least as much while classstack and \ classstack[-1][1] >= thisindent: del classstack[-1] # parse what follows the class name tokentype, token, start, end, line = g.next() inherit = None if token == '(': names = [] # List of superclasses # there's a list of superclasses level = 1 super = [] # Tokens making up current superclass while True: tokentype, token, start, end, line = g.next() if token in (')', ',') and level == 1: n = "".join(super) if n in dict: # we know this super class n = dict[n] else: c = n.split('.') if len(c) > 1: # super class is of the form # module.class: look in module for # class m = c[-2] c = c[-1] if m in _modules: d = _modules[m] if c in d: n = d[c] names.append(n) if token == '(': level += 1 elif token == ')': level -= 1 if level == 0: break elif token == ',' and level == 1: pass else: super.append(token) inherit = names cur_class = Class(module, class_name, inherit, file, lineno) dict[class_name] = cur_class classstack.append((cur_class, thisindent)) elif token == 'import' and start[1] == 0: modules = _getnamelist(g) for mod, mod2 in modules: try: # Recursively read the imported module if not inpackage: readmodule_ex(mod, path) else: try: readmodule_ex(mod, path, inpackage) except ImportError: readmodule_ex(mod) except: # If we can't find or parse the imported module, # too bad -- don't die here. pass elif token == 'from' and start[1] == 0: mod, token = _getname(g) if not mod or token != "import": continue names = _getnamelist(g) try: # Recursively read the imported module d = readmodule_ex(mod, path, inpackage) except: # If we can't find or parse the imported module, # too bad -- don't die here. continue # add any classes that were defined in the imported module # to our name space if they were mentioned in the list for n, n2 in names: if n in d: dict[n2 or n] = d[n] elif n == '*': # only add a name if not already there (to mimic # what Python does internally) also don't add # names that start with _ for n in d: if n[0] != '_' and not n in dict: dict[n] = d[n] except StopIteration: pass f.close() return dict
0a6f954766cd091b117a1c5b16bdb0d2a837c2a8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/0a6f954766cd091b117a1c5b16bdb0d2a837c2a8/pyclbr.py
input_charset = input_charset.lower()
input_charset = unicode(input_charset, 'ascii').lower()
def __init__(self, input_charset=DEFAULT_CHARSET): # RFC 2046, $4.1.2 says charsets are not case sensitive input_charset = input_charset.lower() # Set the input charset after filtering through the aliases self.input_charset = ALIASES.get(input_charset, input_charset) # We can try to guess which encoding and conversion to use by the # charset_map dictionary. Try that first, but let the user override # it. henc, benc, conv = CHARSETS.get(self.input_charset, (SHORTEST, BASE64, None)) if not conv: conv = self.input_charset # Set the attributes, allowing the arguments to override the default. self.header_encoding = henc self.body_encoding = benc self.output_charset = ALIASES.get(conv, conv) # Now set the codecs. If one isn't defined for input_charset, # guess and try a Unicode codec with the same name as input_codec. self.input_codec = CODEC_MAP.get(self.input_charset, self.input_charset) self.output_codec = CODEC_MAP.get(self.output_charset, self.output_charset)
ea7c7af10b72ec4f3c5ad2bb6beb1d3667ff978e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/ea7c7af10b72ec4f3c5ad2bb6beb1d3667ff978e/Charset.py
return _float(s)
return _float(s)
def atof(s): """atof(s) -> float Return the floating point number represented by the string s. """ if type(s) == _StringType: return _float(s) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
def atof(s): """atof(s) -> float Return the floating point number represented by the string s. """ if type(s) == _StringType: return _float(s) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
s = args[0]
s = args[0]
def atoi(*args): """atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to int(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_int, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise TypeError('function requires at least 1 argument: %d given' % len(args))
raise TypeError('function requires at least 1 argument: %d given' % len(args))
def atoi(*args): """atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to int(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_int, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
return _apply(_int, args)
return _apply(_int, args)
def atoi(*args): """atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to int(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_int, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
def atoi(*args): """atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to int(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_int, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
s = args[0]
s = args[0]
def atol(*args): """atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to long(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_long, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise TypeError('function requires at least 1 argument: %d given' % len(args))
raise TypeError('function requires at least 1 argument: %d given' % len(args))
def atol(*args): """atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to long(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_long, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
return _apply(_long, args)
return _apply(_long, args)
def atol(*args): """atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to long(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_long, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
def atol(*args): """atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to long(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_long, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
half = half+1
half = half+1
def center(s, width): """center(s, width) -> string Return a center version of s, in a field of the specified width. padded with spaces as needed. The string is never truncated. """ n = width - len(s) if n <= 0: return s half = n/2 if n%2 and width%2: # This ensures that center(center(s, i), j) = center(s, j) half = half+1 return ' '*half + s + ' '*(n-half)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
sign, s = s[0], s[1:]
sign, s = s[0], s[1:]
def zfill(x, width): """zfill(x, width) -> string Pad a numeric string x with zeros on the left, to fill a field of the specified width. The string x is never truncated. """ if type(x) == type(''): s = x else: s = `x` n = len(s) if n >= width: return s sign = '' if s[0] in ('-', '+'): sign, s = s[0], s[1:] return sign + '0'*(width-n) + s
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
if c == '\t': c = ' '*(tabsize - len(line) % tabsize) line = line + c if c == '\n': res = res + line line = ''
if c == '\t': c = ' '*(tabsize - len(line) % tabsize) line = line + c if c == '\n': res = res + line line = ''
def expandtabs(s, tabsize=8): """expandtabs(s [,tabsize]) -> string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8). """ res = line = '' for c in s: if c == '\t': c = ' '*(tabsize - len(line) % tabsize) line = line + c if c == '\n': res = res + line line = '' return res + line
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
raise ValueError, "maketrans arguments must have same length"
raise ValueError, "maketrans arguments must have same length"
def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = map(None, _idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return joinfields(L, "")
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
_idmapL = map(None, _idmap)
_idmapL = map(None, _idmap)
def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = map(None, _idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return joinfields(L, "")
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
L[fromstr[i]] = tostr[i]
L[fromstr[i]] = tostr[i]
def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = map(None, _idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return joinfields(L, "")
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py
pass
pass
def replace(s, old, new, maxsplit=0): """replace (str, old, new[, maxsplit]) -> string Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxsplit is given, only the first maxsplit occurrences are replaced. """ return s.replace(old, new, maxsplit)
857c4c36b962c6e74559e045c7fb43177dd5bcea /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/857c4c36b962c6e74559e045c7fb43177dd5bcea/string.py