bugged
stringlengths
4
228k
fixed
stringlengths
0
96.3M
__index_level_0__
int64
0
481k
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
14,000
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
14,001
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize, nonames=nonames ) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
14,002
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
def main(): checkext = CHECKEXT verbose = VERBOSE maxpage = MAXPAGE roundsize = ROUNDSIZE dumpfile = DUMPFILE restart = 0 norun = 0 try: # Begin SLB 2/24/99: Added -t option here. opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vx') # End SLB 2/24/99 except getopt.error, msg: sys.stdout = sys.stderr print msg print __doc__%globals() sys.exit(2) # Begin SLB 2/24/99: Added extra_roots variable to # collect extra roots. extra_roots = [] # End SLB 2/24/99 for o, a in opts: if o == '-R': restart = 1 if o == '-d': dumpfile = a if o == '-m': maxpage = string.atoi(a) if o == '-n': norun = 1 if o == '-q': verbose = 0 if o == '-r': roundsize = string.atoi(a) # Begin SLB 2/24/99: Added processing for # -t option. if o == '-t': extra_roots.append(a) # End SLB 2/24/99 if o == '-v': verbose = verbose + 1 if o == '-x': checkext = not checkext if verbose > 0: print AGENTNAME, "version", __version__ if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) else: c = Checker() c.setflags(checkext=checkext, verbose=verbose, maxpage=maxpage, roundsize=roundsize) if not restart and not args: args.append(DEFROOT) for arg in args: c.addroot(arg) # Begin SLB 2/24/99. The -t flag is only needed if external # links are not to be checked. So -t values are ignored unless # -x was specified. if not checkext: for root in extra_roots: # Make sure it's terminated by a slash, # so that addroot doesn't discard the last # directory component. if root[-1] != "/": root = root + "/" c.addroot(root) # End SLB 2/24/99 try: if not norun: try: c.run() except KeyboardInterrupt: if verbose > 0: print "[run interrupted]" try: c.report() except KeyboardInterrupt: if verbose > 0: print "[report interrupted]" finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: print "Use ``%s -R'' to restart." % sys.argv[0] else: print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], dumpfile)
14,003
def reset(self): self.roots = [] self.todo = {} self.done = {} self.bad = {}
def reset(self): self.roots = [] self.todo = {} self.done = {} self.bad = {}
14,004
def reset(self): self.roots = [] self.todo = {} self.done = {} self.bad = {}
def reset(self): self.roots = [] self.todo = {} self.done = {} self.bad = {}
14,005
def note(self, level, format, *args): if self.verbose > level: if args: format = format%args self.message(format)
def note(self, level, format, *args): if self.verbose > level: if args: format = format%args self.message(format)
14,006
def addroot(self, root): if root not in self.roots: troot = root scheme, netloc, path, params, query, fragment = \ urlparse.urlparse(root) i = string.rfind(path, "/") + 1 if 0 < i < len(path): path = path[:i] troot = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) self.roots.append(troot) self.addrobot(root) # Begin SLB 2/24/99: Modified this call to respect # the fact that the "done" and "todo" dictionaries # are now (URL, fragment) pairs self.newlink((root, ""), ("<root>", root)) # End SLB 2/24/99
def addroot(self, root, add_to_do = 1): if root not in self.roots: troot = root scheme, netloc, path, params, query, fragment = \ urlparse.urlparse(root) i = string.rfind(path, "/") + 1 if 0 < i < len(path): path = path[:i] troot = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) self.roots.append(troot) self.addrobot(root) # Begin SLB 2/24/99: Modified this call to respect # the fact that the "done" and "todo" dictionaries # are now (URL, fragment) pairs self.newlink((root, ""), ("<root>", root)) # End SLB 2/24/99
14,007
def addroot(self, root): if root not in self.roots: troot = root scheme, netloc, path, params, query, fragment = \ urlparse.urlparse(root) i = string.rfind(path, "/") + 1 if 0 < i < len(path): path = path[:i] troot = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) self.roots.append(troot) self.addrobot(root) # Begin SLB 2/24/99: Modified this call to respect # the fact that the "done" and "todo" dictionaries # are now (URL, fragment) pairs self.newlink((root, ""), ("<root>", root)) # End SLB 2/24/99
def addroot(self, root): if root not in self.roots: troot = root scheme, netloc, path, params, query, fragment = \ urlparse.urlparse(root) i = string.rfind(path, "/") + 1 if 0 < i < len(path): path = path[:i] troot = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) self.roots.append(troot) self.addrobot(root) # Begin SLB 2/24/99: Modified this call to respect # the fact that the "done" and "todo" dictionaries # are now (URL, fragment) pairs self.newlink((root, ""), ("<root>", root)) # End SLB 2/24/99
14,008
def report_errors(self): if not self.bad: self.message("\nNo errors") return self.message("\nError Report:") sources = self.errors.keys() sources.sort() for source in sources: triples = self.errors[source] self.message("") if len(triples) > 1: self.message("%d Errors in %s", len(triples), source) else: self.message("Error in %s", source) # Begin SLB 2/24/99: Modified this loop to # call self.format_url() instead of referring # to the URL directly, since the URLs in these # triples is now a (URL, fragment) pair. The value # of the "source" variable comes from the list of # origins, and is a URL, not a pair. for url, rawlink, msg in triples: if rawlink != self.format_url(url): s = " (%s)" % rawlink else: s = "" self.message(" HREF %s%s\n msg %s", self.format_url(url), s, msg) # End SLB 2/24/99.
def report_errors(self): if not self.bad: self.message("\nNo errors") return self.message("\nError Report:") sources = self.errors.keys() sources.sort() for source in sources: triples = self.errors[source] self.message("") if len(triples) > 1: self.message("%d Errors in %s", len(triples), source) else: self.message("Error in %s", source) # Begin SLB 2/24/99: Modified this loop to # call self.format_url() instead of referring # to the URL directly, since the URLs in these # triples is now a (URL, fragment) pair. The value # of the "source" variable comes from the list of # origins, and is a URL, not a pair. for url, rawlink, msg in triples: if rawlink != self.format_url(url): s = " (%s)" % rawlink else: s = "" self.message(" HREF %s%s\n msg %s", self.format_url(url), s, msg) # End SLB 2/24/99.
14,009
def report_errors(self): if not self.bad: self.message("\nNo errors") return self.message("\nError Report:") sources = self.errors.keys() sources.sort() for source in sources: triples = self.errors[source] self.message("") if len(triples) > 1: self.message("%d Errors in %s", len(triples), source) else: self.message("Error in %s", source) # Begin SLB 2/24/99: Modified this loop to # call self.format_url() instead of referring # to the URL directly, since the URLs in these # triples is now a (URL, fragment) pair. The value # of the "source" variable comes from the list of # origins, and is a URL, not a pair. for url, rawlink, msg in triples: if rawlink != self.format_url(url): s = " (%s)" % rawlink else: s = "" self.message(" HREF %s%s\n msg %s", self.format_url(url), s, msg) # End SLB 2/24/99.
def report_errors(self): if not self.bad: self.message("\nNo errors") return self.message("\nError Report:") sources = self.errors.keys() sources.sort() for source in sources: triples = self.errors[source] self.message("") if len(triples) > 1: self.message("%d Errors in %s", len(triples), source) else: self.message("Error in %s", source) # Begin SLB 2/24/99: Modified this loop to # call self.format_url() instead of referring # to the URL directly, since the URLs in these # triples is now a (URL, fragment) pair. The value # of the "source" variable comes from the list of # origins, and is a URL, not a pair. for url, rawlink, msg in triples: if rawlink != self.format_url(url): s = " (%s)" % rawlink else: s = "" self.message(" HREF %s%s\n msg %s", self.format_url(url), s, msg) # End SLB 2/24/99.
14,010
def dopage(self, url_pair):
def dopage(self, url_pair):
14,011
def dopage(self, url_pair):
def dopage(self, url_pair):
14,012
def dopage(self, url_pair):
def dopage(self, url_pair):
14,013
def dopage(self, url_pair):
def dopage(self, url_pair):
14,014
def dopage(self, url_pair):
def dopage(self, url_pair):
14,015
def dopage(self, url_pair):
def dopage(self, url_pair):
14,016
def newdonelink(self, url, origin): self.done[url].append(origin)
def newdonelink(self, url, origin): self.done[url].append(origin)
14,017
def newdonelink(self, url, origin): self.done[url].append(origin)
def if self.bad.has_key(url): source, rawlink = origin triple = url, rawlink, self.bad[url] self.seterror(source, triple) newdonelink(self, if self.bad.has_key(url): source, rawlink = origin triple = url, rawlink, self.bad[url] self.seterror(source, triple) url, if self.bad.has_key(url): source, rawlink = origin triple = url, rawlink, self.bad[url] self.seterror(source, triple) origin): if self.bad.has_key(url): source, rawlink = origin triple = url, rawlink, self.bad[url] self.seterror(source, triple) self.done[url].append(origin)
14,018
def newtodolink(self, url, origin):
def newtodolink(self, url, origin):
14,019
def newtodolink(self, url, origin):
def newtodolink(self, url, origin):
14,020
def newtodolink(self, url, origin):
def newtodolink(self, url, origin):
14,021
def format_url(self, url):
def format_url(self, url):
14,022
def inroots(self, url): for root in self.roots: if url[:len(root)] == root: return self.isallowed(root, url) return 0
def inroots(self, url): for root in self.roots: if url[:len(root)] == root: return self.isallowed(root, url) return 0
14,023
def getpage(self, url_pair):
def getpage(self, url_pair):
14,024
def getpage(self, url_pair):
def getpage(self, url_pair):
14,025
def getpage(self, url_pair):
def getpage(self, url_pair):
14,026
def readhtml(self, url_pair):
def readhtml(self, url_pair):
14,027
def openhtml(self, url_pair):
def openhtml(self, url_pair):
14,028
def openpage(self, url_pair):
def openpage(self, url_pair):
14,029
def setbad(self, url, msg): if self.bad.has_key(url) and self.bad[url] == msg: self.note(0, "(Seen this error before)") return self.bad[url] = msg self.changed = 1 self.markerror(url)
def setbad(self, url, msg): if self.bad.has_key(url) and self.bad[url] == msg: self.note(0, "(Seen this error before)") return self.bad[url] = msg self.changed = 1 self.markerror(url)
14,030
def seterror(self, url, triple): try: # Begin SLB 2/24/99: Because of the way the # URLs are now processed, I need to check to make # sure the URL hasn't been entered in the error list. # The first element of the triple here is a (URL, fragment) # pair, but the URL key is not, since it's from the # list of origins. if triple not in self.errors[url]:
def seterror(self, url, triple): try: # Begin SLB 2/24/99: Because of the way the # URLs are now processed, I need to check to make # sure the URL hasn't been entered in the error list. # The first element of the triple here is a (URL, fragment) # pair, but the URL key is not, since it's from the # list of origins. if triple not in self.errors[url]:
14,031
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
14,032
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
14,033
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
14,034
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None): self.text = text self.url = url self.verbose = verbose self.maxpage = maxpage self.checker = checker
14,035
def getnames(self):
def getnames(self):
14,036
def getlinkinfos(self):
def getlinkinfos(self):
14,037
def getlinkinfos(self):
def getlinkinfos(self):
14,038
def getlinkinfos(self):
def getlinkinfos(self):
14,039
def open_file(self, url): path = urllib.url2pathname(urllib.unquote(url)) if path[-1] != os.sep: url = url + '/' if os.path.isdir(path): indexpath = os.path.join(path, "index.html") if os.path.exists(indexpath): return self.open_file(url + "index.html") try: names = os.listdir(path) except os.error, msg: raise IOError, msg, sys.exc_traceback names.sort() s = MyStringIO("file:"+url, {'content-type': 'text/html'}) s.write('<BASE HREF="file:%s">\n' % urllib.quote(os.path.join(path, ""))) for name in names: q = urllib.quote(name) s.write('<A HREF="%s">%s</A>\n' % (q, q)) s.seek(0) return s return urllib.FancyURLopener.open_file(self, path)
def open_file(self, url): path = urllib.url2pathname(urllib.unquote(url)) if os.path.isdir(path): indexpath = os.path.join(path, "index.html") if os.path.exists(indexpath): return self.open_file(url + "index.html") try: names = os.listdir(path) except os.error, msg: raise IOError, msg, sys.exc_traceback names.sort() s = MyStringIO("file:"+url, {'content-type': 'text/html'}) s.write('<BASE HREF="file:%s">\n' % urllib.quote(os.path.join(path, ""))) for name in names: q = urllib.quote(name) s.write('<A HREF="%s">%s</A>\n' % (q, q)) s.seek(0) return s return urllib.FancyURLopener.open_file(self, path)
14,040
def open_file(self, url): path = urllib.url2pathname(urllib.unquote(url)) if path[-1] != os.sep: url = url + '/' if os.path.isdir(path): indexpath = os.path.join(path, "index.html") if os.path.exists(indexpath): return self.open_file(url + "index.html") try: names = os.listdir(path) except os.error, msg: raise IOError, msg, sys.exc_traceback names.sort() s = MyStringIO("file:"+url, {'content-type': 'text/html'}) s.write('<BASE HREF="file:%s">\n' % urllib.quote(os.path.join(path, ""))) for name in names: q = urllib.quote(name) s.write('<A HREF="%s">%s</A>\n' % (q, q)) s.seek(0) return s return urllib.FancyURLopener.open_file(self, path)
def open_file(self, url): path = urllib.url2pathname(urllib.unquote(url)) if path[-1] != os.sep: url = url + '/' if os.path.isdir(path): indexpath = os.path.join(path, "index.html") if os.path.exists(indexpath): return self.open_file(url + "index.html") try: names = os.listdir(path) except os.error, msg: raise IOError, msg, sys.exc_traceback names.sort() s = MyStringIO("file:"+url, {'content-type': 'text/html'}) s.write('<BASE HREF="file:%s">\n' % urllib.quote(os.path.join(path, ""))) for name in names: q = urllib.quote(name) s.write('<A HREF="%s">%s</A>\n' % (q, q)) s.seek(0) return s return urllib.FancyURLopener.open_file(self, path)
14,041
def __init__(self, url, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {}
def __init__(self, url, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {}
14,042
def start_a(self, attributes): self.link_attr(attributes, 'href')
def start_a(self, attributes): self.link_attr(attributes, 'href')
14,043
def __init__(self, files=[], dir=os.curdir, allfiles=None, warn=None, debug_print=None): # use standard warning and debug functions, if no other given if warn is None: warn = self.__warn if debug_print is None: debug_print = self.__debug_print self.warn = warn self.debug_print = debug_print self.files = files self.dir = dir self.allfiles = allfiles # if None, it will be filled, when used for first time
def__init__(self,files=[],dir=os.curdir,allfiles=None,warn=None,debug_print=None):#usestandardwarninganddebugfunctions,ifnoothergivenifwarnisNone:warn=self.__warnifdebug_printisNone:debug_print=self.__debug_printself.warn=warnself.debug_print=debug_printself.files=filesself.dir=dirself.allfiles=allfiles#ifNone,itwillbefilled,whenusedforfirsttime
14,044
def __warn (self, msg): sys.stderr.write ("warning: template: %s\n" % msg)
def __warn (self, msg): sys.stderr.write ("warning: %s\n" % msg)
14,045
def process_line(self, line):
def process_line(self, line):
14,046
def process_line(self, line):
def process_line(self, line):
14,047
def process_line(self, line):
def process_line(self, line):
14,048
def process_line(self, line):
def process_line(self, line):
14,049
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
14,050
def _handle_text(self, msg): payload = msg.get_payload() if not isinstance(payload, StringType): raise TypeError, 'string payload expected' if self._mangle_from_: payload = fcre.sub('>From ', payload) self._fp.write(payload)
def _handle_text(self, msg): payload = msg.get_payload() if not isinstance(payload, StringType): raise TypeError, 'string payload expected: %s' % type(payload) if self._mangle_from_: payload = fcre.sub('>From ', payload) self._fp.write(payload)
14,051
def _handle_multipart(self, msg, isdigest=0): # The trick here is to write out each part separately, merge them all # together, and then make sure that the boundary we've chosen isn't # present in the payload. msgtexts = [] for part in msg.get_payload(): s = StringIO() g = self.__class__(s) g(part, unixfrom=0) msgtexts.append(s.getvalue()) # Now make sure the boundary we've selected doesn't appear in any of # the message texts. alltext = NL.join(msgtexts) # BAW: What about boundaries that are wrapped in double-quotes? boundary = msg.get_boundary(failobj=_make_boundary(alltext)) # If we had to calculate a new boundary because the body text # contained that string, set the new boundary. We don't do it # unconditionally because, while set_boundary() preserves order, it # doesn't preserve newlines/continuations in headers. This is no big # deal in practice, but turns out to be inconvenient for the unittest # suite. if msg.get_boundary() <> boundary: msg.set_boundary(boundary) # Write out any preamble if msg.preamble is not None: self._fp.write(msg.preamble) # First boundary is a bit different; it doesn't have a leading extra # newline. print >> self._fp, '--' + boundary if isdigest: print >> self._fp # Join and write the individual parts joiner = '\n--' + boundary + '\n' if isdigest: # multipart/digest types effectively add an extra newline between # the boundary and the body part. joiner += '\n' self._fp.write(joiner.join(msgtexts)) print >> self._fp, '\n--' + boundary + '--', # Write out any epilogue if msg.epilogue is not None: self._fp.write(msg.epilogue)
def _handle_multipart(self, msg, isdigest=0): # The trick here is to write out each part separately, merge them all # together, and then make sure that the boundary we've chosen isn't # present in the payload. msgtexts = [] for part in msg.get_payload(): s = StringIO() g = self.__class__(s, self._mangle_from_, self.__maxheaderlen) g(part, unixfrom=0) msgtexts.append(s.getvalue()) # Now make sure the boundary we've selected doesn't appear in any of # the message texts. alltext = NL.join(msgtexts) # BAW: What about boundaries that are wrapped in double-quotes? boundary = msg.get_boundary(failobj=_make_boundary(alltext)) # If we had to calculate a new boundary because the body text # contained that string, set the new boundary. We don't do it # unconditionally because, while set_boundary() preserves order, it # doesn't preserve newlines/continuations in headers. This is no big # deal in practice, but turns out to be inconvenient for the unittest # suite. if msg.get_boundary() <> boundary: msg.set_boundary(boundary) # Write out any preamble if msg.preamble is not None: self._fp.write(msg.preamble) # First boundary is a bit different; it doesn't have a leading extra # newline. print >> self._fp, '--' + boundary if isdigest: print >> self._fp # Join and write the individual parts joiner = '\n--' + boundary + '\n' if isdigest: # multipart/digest types effectively add an extra newline between # the boundary and the body part. joiner += '\n' self._fp.write(joiner.join(msgtexts)) print >> self._fp, '\n--' + boundary + '--', # Write out any epilogue if msg.epilogue is not None: self._fp.write(msg.epilogue)
14,052
def _handle_message_rfc822(self, msg): s = StringIO() g = self.__class__(s) # A message/rfc822 should contain a scalar payload which is another # Message object. Extract that object, stringify it, and write that # out. g(msg.get_payload(), unixfrom=0) self._fp.write(s.getvalue())
def _handle_message_delivery_status(self, msg): blocks = [] for part in msg.get_payload(): s = StringIO() g = self.__class__(s, self._mangle_from_, self.__maxheaderlen) g(part, unixfrom=0) text = s.getvalue() lines = text.split('\n') if lines and lines[-1] == '': blocks.append(NL.join(lines[:-1])) else: blocks.append(text) self._fp.write(NL.join(blocks)) def _handle_message(self, msg): s = StringIO() g = self.__class__(s) # A message/rfc822 should contain a scalar payload which is another # Message object. Extract that object, stringify it, and write that # out. g(msg.get_payload(), unixfrom=0) self._fp.write(s.getvalue())
14,053
def _handle_message_rfc822(self, msg): s = StringIO() g = self.__class__(s) # A message/rfc822 should contain a scalar payload which is another # Message object. Extract that object, stringify it, and write that # out. g(msg.get_payload(), unixfrom=0) self._fp.write(s.getvalue())
def _handle_message_rfc822(self, msg): s = StringIO() g = self.__class__(s, self._mangle_from_, self.__maxheaderlen) # A message/rfc822 should contain a scalar payload which is another # Message object. Extract that object, stringify it, and write that # out. g(msg.get_payload(), unixfrom=0) self._fp.write(s.getvalue())
14,054
def _dispatch(self, msg): for part in msg.walk(): if part.get_main_type('text') == 'text': print >> self, part.get_payload(decode=1) else: print >> self, self._fmt % { 'type' : part.get_type('[no MIME type]'), 'maintype' : part.get_main_type('[no main MIME type]'), 'subtype' : part.get_subtype('[no sub-MIME type]'), 'filename' : part.get_filename('[no filename]'), 'description': part.get('Content-Description', '[no description]'), 'encoding' : part.get('Content-Transfer-Encoding', '[no encoding]'), }
def _dispatch(self, msg): for part in msg.walk(): maintype = part.get_main_type('text') if maintype == 'text': print >> self, part.get_payload(decode=1) else: print >> self, self._fmt % { 'type' : part.get_type('[no MIME type]'), 'maintype' : part.get_main_type('[no main MIME type]'), 'subtype' : part.get_subtype('[no sub-MIME type]'), 'filename' : part.get_filename('[no filename]'), 'description': part.get('Content-Description', '[no description]'), 'encoding' : part.get('Content-Transfer-Encoding', '[no encoding]'), }
14,055
def addrobot(self, root): root = urlparse.urljoin(root, "/") if self.robots.has_key(root): return url = urlparse.urljoin(root, "/robots.txt") self.robots[root] = rp = robotparser.RobotFileParser() self.note(2, "Parsing %s", url) rp.debug = self.verbose > 3 rp.set_url(url) try: rp.read() except IOError, msg: self.note(1, "I/O error parsing %s: %s", url, msg)
def addrobot(self, root): root = urlparse.urljoin(root, "/") if self.robots.has_key(root): return url = urlparse.urljoin(root, "/robots.txt") self.robots[root] = rp = robotparser.RobotFileParser() self.note(2, "Parsing %s", url) rp.debug = self.verbose > 3 rp.set_url(url) try: rp.read() except (OSError, IOError), msg: self.note(1, "I/O error parsing %s: %s", url, msg)
14,056
def openpage(self, url_pair): url, fragment = url_pair try: return self.urlopener.open(url) except IOError, msg: msg = self.sanitize(msg) self.note(0, "Error %s", msg) if self.verbose > 0: self.show(" HREF ", url, " from", self.todo[url_pair]) self.setbad(url_pair, msg) return None
def openpage(self, url_pair): url, fragment = url_pair try: return self.urlopener.open(url) except (OSError, IOError), msg: msg = self.sanitize(msg) self.note(0, "Error %s", msg) if self.verbose > 0: self.show(" HREF ", url, " from", self.todo[url_pair]) self.setbad(url_pair, msg) return None
14,057
def make_zipfile (self, base_dir):
def make_zipfile (self, base_dir):
14,058
def __init__(self): server_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-Agent', server_version)] # manage the individual handlers self.handlers = [] self.handle_open = {} self.handle_error = {}
def __init__(self): server_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-agent', server_version)] # manage the individual handlers self.handlers = [] self.handle_open = {} self.handle_error = {}
14,059
def proxy_open(self, req, proxy, type): orig_type = req.get_type() type, r_type = splittype(proxy) host, XXX = splithost(r_type) if '@' in host: user_pass, host = host.split('@', 1) if ':' in user_pass: user, password = user_pass.split(':', 1) user_pass = base64.encodestring('%s:%s' % (unquote(user), unquote(password))) req.add_header('Proxy-Authorization', 'Basic ' + user_pass) host = unquote(host) req.set_proxy(host, type) if orig_type == type: # let other handlers take care of it # XXX this only makes sense if the proxy is before the # other handlers return None else: # need to start over, because the other handlers don't # grok the proxy's URL type return self.parent.open(req)
def proxy_open(self, req, proxy, type): orig_type = req.get_type() type, r_type = splittype(proxy) host, XXX = splithost(r_type) if '@' in host: user_pass, host = host.split('@', 1) if ':' in user_pass: user, password = user_pass.split(':', 1) user_pass = base64.encodestring('%s:%s' % (unquote(user), unquote(password))) req.add_header('Proxy-authorization', 'Basic ' + user_pass) host = unquote(host) req.set_proxy(host, type) if orig_type == type: # let other handlers take care of it # XXX this only makes sense if the proxy is before the # other handlers return None else: # need to start over, because the other handlers don't # grok the proxy's URL type return self.parent.open(req)
14,060
def http_error_401(self, req, fp, code, msg, headers): host = urlparse.urlparse(req.get_full_url())[1] return self.http_error_auth_reqed('www-authenticate', host, req, headers)
def http_error_401(self, req, fp, code, msg, headers): host = urlparse.urlparse(req.get_full_url())[1] return self.http_error_auth_reqed('www-authenticate', host, req, headers)
14,061
def do_open(self, http_class, req): host = req.get_host() if not host: raise URLError('no host given')
def do_open(self, http_class, req): host = req.get_host() if not host: raise URLError('no host given')
14,062
def do_open(self, http_class, req): host = req.get_host() if not host: raise URLError('no host given')
def do_open(self, http_class, req): host = req.get_host() if not host: raise URLError('no host given')
14,063
def open_local_file(self, req): host = req.get_host() file = req.get_selector() localfile = url2pathname(file) stats = os.stat(localfile) size = stats.st_size modified = rfc822.formatdate(stats.st_mtime) mtype = mimetypes.guess_type(file)[0] headers = mimetools.Message(StringIO( 'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified))) if host: host, port = splitport(host) if not host or \ (not port and socket.gethostbyname(host) in self.get_names()): return addinfourl(open(localfile, 'rb'), headers, 'file:'+file) raise URLError('file not on local host')
def open_local_file(self, req): host = req.get_host() file = req.get_selector() localfile = url2pathname(file) stats = os.stat(localfile) size = stats.st_size modified = rfc822.formatdate(stats.st_mtime) mtype = mimetypes.guess_type(file)[0] headers = mimetools.Message(StringIO( 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified))) if host: host, port = splitport(host) if not host or \ (not port and socket.gethostbyname(host) in self.get_names()): return addinfourl(open(localfile, 'rb'), headers, 'file:'+file) raise URLError('file not on local host')
14,064
def ftp_open(self, req): host = req.get_host() if not host: raise IOError, ('ftp error', 'no host given') # XXX handle custom username & password try: host = socket.gethostbyname(host) except socket.error, msg: raise URLError(msg) host, port = splitport(host) if port is None: port = ftplib.FTP_PORT path, attrs = splitattr(req.get_selector()) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] user = passwd = '' # XXX try: fw = self.connect_ftp(user, passwd, host, port, dirs) type = file and 'I' or 'D' for attr in attrs: attr, value = splitattr(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() fp, retrlen = fw.retrfile(file, type) headers = "" mtype = mimetypes.guess_type(req.get_full_url())[0] if mtype: headers += "Content-Type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-Length: %d\n" % retrlen sf = StringIO(headers) headers = mimetools.Message(sf) return addinfourl(fp, headers, req.get_full_url()) except ftplib.all_errors, msg: raise IOError, ('ftp error', msg), sys.exc_info()[2]
def ftp_open(self, req): host = req.get_host() if not host: raise IOError, ('ftp error', 'no host given') # XXX handle custom username & password try: host = socket.gethostbyname(host) except socket.error, msg: raise URLError(msg) host, port = splitport(host) if port is None: port = ftplib.FTP_PORT path, attrs = splitattr(req.get_selector()) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] user = passwd = '' # XXX try: fw = self.connect_ftp(user, passwd, host, port, dirs) type = file and 'I' or 'D' for attr in attrs: attr, value = splitattr(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() fp, retrlen = fw.retrfile(file, type) headers = "" mtype = mimetypes.guess_type(req.get_full_url())[0] if mtype: headers += "Content-type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-Length: %d\n" % retrlen sf = StringIO(headers) headers = mimetools.Message(sf) return addinfourl(fp, headers, req.get_full_url()) except ftplib.all_errors, msg: raise IOError, ('ftp error', msg), sys.exc_info()[2]
14,065
def ftp_open(self, req): host = req.get_host() if not host: raise IOError, ('ftp error', 'no host given') # XXX handle custom username & password try: host = socket.gethostbyname(host) except socket.error, msg: raise URLError(msg) host, port = splitport(host) if port is None: port = ftplib.FTP_PORT path, attrs = splitattr(req.get_selector()) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] user = passwd = '' # XXX try: fw = self.connect_ftp(user, passwd, host, port, dirs) type = file and 'I' or 'D' for attr in attrs: attr, value = splitattr(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() fp, retrlen = fw.retrfile(file, type) headers = "" mtype = mimetypes.guess_type(req.get_full_url())[0] if mtype: headers += "Content-Type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-Length: %d\n" % retrlen sf = StringIO(headers) headers = mimetools.Message(sf) return addinfourl(fp, headers, req.get_full_url()) except ftplib.all_errors, msg: raise IOError, ('ftp error', msg), sys.exc_info()[2]
def ftp_open(self, req): host = req.get_host() if not host: raise IOError, ('ftp error', 'no host given') # XXX handle custom username & password try: host = socket.gethostbyname(host) except socket.error, msg: raise URLError(msg) host, port = splitport(host) if port is None: port = ftplib.FTP_PORT path, attrs = splitattr(req.get_selector()) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] user = passwd = '' # XXX try: fw = self.connect_ftp(user, passwd, host, port, dirs) type = file and 'I' or 'D' for attr in attrs: attr, value = splitattr(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() fp, retrlen = fw.retrfile(file, type) headers = "" mtype = mimetypes.guess_type(req.get_full_url())[0] if mtype: headers += "Content-Type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-length: %d\n" % retrlen sf = StringIO(headers) headers = mimetools.Message(sf) return addinfourl(fp, headers, req.get_full_url()) except ftplib.all_errors, msg: raise IOError, ('ftp error', msg), sys.exc_info()[2]
14,066
def deepcopy(x, memo = None): """Deep copy operation on arbitrary Python objects. See the module's __doc__ string for more info. """ if memo is None: memo = {} d = id(x) if memo.has_key(d): return memo[d] try: copierfunction = _deepcopy_dispatch[type(x)] except KeyError: try: copier = x.__deepcopy__ except AttributeError: try: reductor = x.__reduce__ except AttributeError: raise error, \ "un-deep-copyable object of type %s" % type(x) else: y = _reconstruct(x, reductor(), 1) else: y = copier(memo) else: y = copierfunction(x, memo) memo[d] = y return y
def deepcopy(x, memo = None): """Deep copy operation on arbitrary Python objects. See the module's __doc__ string for more info. """ if memo is None: memo = {} d = id(x) if memo.has_key(d): return memo[d] try: copierfunction = _deepcopy_dispatch[type(x)] except KeyError: try: copier = x.__deepcopy__ except AttributeError: try: reductor = x.__reduce__ except AttributeError: raise error, \ "un-deep-copyable object of type %s" % type(x) else: y = _reconstruct(x, reductor(), 1, memo) else: y = copier(memo) else: y = copierfunction(x, memo) memo[d] = y return y
14,067
def _reconstruct(x, info, deep): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args) y = callable(*args) if state: if deep: state = deepcopy(state) y.__dict__.update(state) return y
def _reconstruct(x, info, deep, memo=None): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args) y = callable(*args) if state: if deep: state = deepcopy(state) y.__dict__.update(state) return y
14,068
def _reconstruct(x, info, deep): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args) y = callable(*args) if state: if deep: state = deepcopy(state) y.__dict__.update(state) return y
def _reconstruct(x, info, deep): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args, memo) y = callable(*args) if state: if deep: state = deepcopy(state) y.__dict__.update(state) return y
14,069
def _reconstruct(x, info, deep): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args) y = callable(*args) if state: if deep: state = deepcopy(state) y.__dict__.update(state) return y
def _reconstruct(x, info, deep): if isinstance(info, str): return x assert isinstance(info, tuple) n = len(info) assert n in (2, 3) callable, args = info[:2] if n > 2: state = info[2] else: state = {} if deep: args = deepcopy(args) y = callable(*args) if state: if deep: state = deepcopy(state, memo) y.__dict__.update(state) return y
14,070
def _stringify(string): return string
def"""Base class for client errors.""" _stringify(string):"""Base class for client errors.""" return"""Base class for client errors.""" string
14,071
def _stringify(string): return string
def"""Indicates an HTTP protocol error.""" _stringify(string):"""Indicates an HTTP protocol error.""" return"""Indicates an HTTP protocol error.""" string
14,072
def __repr__(self): return ( "<ProtocolError for %s: %s %s>" % (self.url, self.errcode, self.errmsg) )
def"""Indicates a broken response package""" __repr__(self):"""Indicates a broken response package""" return"""Indicates a broken response package""" ("""Indicates a broken response package""" "<ProtocolError"""Indicates a broken response package""" for"""Indicates a broken response package""" %s:"""Indicates a broken response package""" %s"""Indicates a broken response package""" %s>""""Indicates a broken response package""" %"""Indicates a broken response package""" (self.url,"""Indicates a broken response package""" self.errcode,"""Indicates a broken response package""" self.errmsg)"""Indicates a broken response package""" )
14,073
def __repr__(self): return ( "<ProtocolError for %s: %s %s>" % (self.url, self.errcode, self.errmsg) )
def"""indicates a XML-RPC fault package""" __repr__(self):"""indicates a XML-RPC fault package""" return"""indicates a XML-RPC fault package""" ("""indicates a XML-RPC fault package""" "<ProtocolError"""indicates a XML-RPC fault package""" for"""indicates a XML-RPC fault package""" %s:"""indicates a XML-RPC fault package""" %s"""indicates a XML-RPC fault package""" %s>""""indicates a XML-RPC fault package""" %"""indicates a XML-RPC fault package""" (self.url,"""indicates a XML-RPC fault package""" self.errcode,"""indicates a XML-RPC fault package""" self.errmsg)"""indicates a XML-RPC fault package""" )
14,074
def __repr__(self): return ( "<Fault %s: %s>" % (self.faultCode, repr(self.faultString)) )
def __repr__(self): return ( "<Fault %s: %s>" % (self.faultCode, repr(self.faultString)) )
14,075
def boolean(value, truefalse=(False, True)): # convert any Python value to XML-RPC boolean return truefalse[operator.truth(value)]
def"""Convert any Python value to XML-RPC boolean.""" boolean(value,"""Convert any Python value to XML-RPC boolean.""" truefalse=(False,"""Convert any Python value to XML-RPC boolean.""" True)):"""Convert any Python value to XML-RPC boolean.""" #"""Convert any Python value to XML-RPC boolean.""" convert"""Convert any Python value to XML-RPC boolean.""" any"""Convert any Python value to XML-RPC boolean.""" Python"""Convert any Python value to XML-RPC boolean.""" value"""Convert any Python value to XML-RPC boolean.""" to"""Convert any Python value to XML-RPC boolean.""" XML-RPC"""Convert any Python value to XML-RPC boolean.""" boolean"""Convert any Python value to XML-RPC boolean.""" return"""Convert any Python value to XML-RPC boolean.""" truefalse[operator.truth(value)]"""Convert any Python value to XML-RPC boolean."""
14,076
def datetime(data): value = DateTime() value.decode(data) return value
def datetime(data): value = DateTime() value.decode(data) return value
14,077
def close(self): self._parser.Parse("", 1) # end of data del self._target, self._parser # get rid of circular references
def close(self): self._parser.Parse("", 1) # end of data del self._target, self._parser # get rid of circular references
14,078
def __init__(self, target): self.handle_xml = target.xml self.unknown_starttag = target.start self.handle_data = target.data self.unknown_endtag = target.end xmllib.XMLParser.__init__(self)
def __init__(self, target): self.handle_xml = target.xml self.unknown_starttag = target.start self.handle_data = target.data self.unknown_endtag = target.end xmllib.XMLParser.__init__(self)
14,079
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__)
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__)
14,080
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
14,081
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
14,082
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
defif max < min: raise error, "bad repeat interval" _parse(source,if max < min: raise error, "bad repeat interval" state):if max < min: raise error, "bad repeat interval" #if max < min: raise error, "bad repeat interval" parseif max < min: raise error, "bad repeat interval" aif max < min: raise error, "bad repeat interval" simpleif max < min: raise error, "bad repeat interval" patternif max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" subpatternif max < min: raise error, "bad repeat interval" =if max < min: raise error, "bad repeat interval" SubPattern(state)if max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" whileif max < min: raise error, "bad repeat interval" 1:if max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" source.nextif max < min: raise error, "bad repeat interval" inif max < min: raise error, "bad repeat interval" ("|",if max < min: raise error, "bad repeat interval" ")"):if max < min: raise error, "bad repeat interval" breakif max < min: raise error, "bad repeat interval" #if max < min: raise error, "bad repeat interval" endif max < min: raise error, "bad repeat interval" ofif max < min: raise error, "bad repeat interval" subpatternif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" =if max < min: raise error, "bad repeat interval" source.get()if max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" isif max < min: raise error, "bad repeat interval" None:if max < min: raise error, "bad repeat interval" breakif max < min: raise error, "bad repeat interval" #if max < min: raise error, "bad repeat interval" endif max < min: raise error, "bad repeat interval" ofif max < min: raise error, "bad repeat interval" patternif max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" state.flagsif max < min: raise error, "bad repeat interval" &if max < min: raise error, "bad repeat interval" SRE_FLAG_VERBOSE:if max < min: raise error, "bad repeat interval" #if max < min: raise error, "bad repeat interval" skipif max < min: raise error, "bad repeat interval" whitespaceif max < min: raise error, "bad repeat interval" andif max < min: raise error, "bad repeat interval" commentsif max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" inif max < min: raise error, "bad repeat interval" WHITESPACE:if max < min: raise error, "bad repeat interval" continueif max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" ==if max < min: raise error, "bad repeat interval" "#":if max < min: raise error, "bad repeat interval" whileif max < min: raise error, "bad repeat interval" 1:if max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" =if max < min: raise error, "bad repeat interval" source.get()if max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" inif max < min: raise error, "bad repeat interval" (None,if max < min: raise error, "bad repeat interval" "\n"):if max < min: raise error, "bad repeat interval" breakif max < min: raise error, "bad repeat interval" continueif max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" ifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" andif max < min: raise error, "bad repeat interval" this[0]if max < min: raise error, "bad repeat interval" notif max < min: raise error, "bad repeat interval" inif max < min: raise error, "bad repeat interval" SPECIAL_CHARS:if max < min: raise error, "bad repeat interval" subpattern.append((LITERAL,if max < min: raise error, "bad repeat interval" ord(this)))if max < min: raise error, "bad repeat interval" if max < min: raise error, "bad repeat interval" elifif max < min: raise error, "bad repeat interval" thisif max < min: raise error, "bad repeat interval" ==if max < min: raise error, "bad repeat interval" "[":if max < min: raise error, "bad repeat interval" #if max < min: raise error, "bad repeat interval" characterif max < min: raise error, "bad repeat interval" setif max < min: raise error, "bad repeat interval" setif max < min: raise error, "bad repeat interval" =if max < min: raise error, "bad repeat interval" []
14,083
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
14,084
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
14,085
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
def _parse(source, state): # parse a simple pattern subpattern = SubPattern(state) while 1: if source.next in ("|", ")"): break # end of subpattern this = source.get() if this is None: break # end of pattern if state.flags & SRE_FLAG_VERBOSE: # skip whitespace and comments if this in WHITESPACE: continue if this == "#": while 1: this = source.get() if this in (None, "\n"): break continue if this and this[0] not in SPECIAL_CHARS: subpattern.append((LITERAL, ord(this))) elif this == "[": # character set set = []
14,086
def parse_template(source, pattern): # parse 're' replacement string into list of literals and # group references s = Tokenizer(source) p = [] a = p.append while 1: this = s.get() if this is None: break # end of replacement string if this and this[0] == "\\": # group if this == "\\g": name = "" if s.match("<"): while 1: char = s.get() if char is None: raise error, "unterminated group name" if char == ">": break name = name + char if not name: raise error, "bad group name" try: index = int(name) except ValueError: if not isname(name): raise error, "illegal character in group name" try: index = pattern.groupindex[name] except KeyError: raise IndexError, "unknown group name" a((MARK, index)) elif len(this) > 1 and this[1] in DIGITS: code = None while 1: group = _group(this, pattern.groups+1) if group: if (s.next not in DIGITS or not _group(this + s.next, pattern.groups+1)): code = MARK, int(group) break elif s.next in OCTDIGITS: this = this + s.get() else: break if not code: this = this[1:] code = LITERAL, int(this[-6:], 8) & 0xff a(code) else: try: a(ESCAPES[this]) except KeyError: for c in this: a((LITERAL, ord(c))) else: a((LITERAL, ord(this))) return p
def parse_template(source, pattern): # parse 're' replacement string into list of literals and # group references s = Tokenizer(source) p = [] a = p.append while 1: this = s.get() if this is None: break # end of replacement string if this and this[0] == "\\": # group if this == "\\g": name = "" if s.match("<"): while 1: char = s.get() if char is None: raise error, "unterminated group name" if char == ">": break name = name + char if not name: raise error, "bad group name" try: index = int(name) except ValueError: if not isname(name): raise error, "bad character in group name" try: index = pattern.groupindex[name] except KeyError: raise IndexError, "unknown group name" a((MARK, index)) elif len(this) > 1 and this[1] in DIGITS: code = None while 1: group = _group(this, pattern.groups+1) if group: if (s.next not in DIGITS or not _group(this + s.next, pattern.groups+1)): code = MARK, int(group) break elif s.next in OCTDIGITS: this = this + s.get() else: break if not code: this = this[1:] code = LITERAL, int(this[-6:], 8) & 0xff a(code) else: try: a(ESCAPES[this]) except KeyError: for c in this: a((LITERAL, ord(c))) else: a((LITERAL, ord(this))) return p
14,087
def __init__(self, master=None): """Construct a variable with an optional MASTER as master widget. The variable is named PY_VAR_number in Tcl. """ global _varnum if not master: master = _default_root self._master = master self._tk = master.tk self._name = 'PY_VAR' + repr(_varnum) _varnum = _varnum + 1 self.set(self._default)
def __init__(self, master=None, value=None, name=None): """Construct a variable MASTER can be given as master widget. VALUE is an optional value (defaults to "") NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained. """ global _varnum if not master: master = _default_root self._master = master self._tk = master.tk self._name = 'PY_VAR' + repr(_varnum) _varnum = _varnum + 1 self.set(self._default)
14,088
def __init__(self, master=None): """Construct a variable with an optional MASTER as master widget. The variable is named PY_VAR_number in Tcl. """ global _varnum if not master: master = _default_root self._master = master self._tk = master.tk self._name = 'PY_VAR' + repr(_varnum) _varnum = _varnum + 1 self.set(self._default)
def __init__(self, master=None): """Construct a variable with an optional MASTER as master widget. The variable is named PY_VAR_number in Tcl. """ global _varnum if not master: master = _default_root self._master = master self._tk = master.tk self._name = 'PY_VAR' + repr(_varnum) _varnum = _varnum + 1 self.set(self._default)
14,089
def __init__(self, master=None): """Construct a string variable.
def __init__(self, master=None, value=None, name=None): """Construct a string variable.
14,090
def __init__(self, master=None): """Construct a string variable.
def __init__(self, master=None): """Construct a string variable.
14,091
def __init__(self, master=None): """Construct an integer variable.
def __init__(self, master=None, value=None, name=None): """Construct an integer variable.
14,092
def __init__(self, master=None): """Construct an integer variable.
def __init__(self, master=None): """Construct an integer variable.
14,093
def __init__(self, master=None): """Construct a float variable.
def __init__(self, master=None, value=None, name=None): """Construct a float variable.
14,094
def __init__(self, master=None): """Construct a float variable.
def __init__(self, master=None): """Construct a float variable.
14,095
def get(self): """Return the value of the variable as a float.""" return getdouble(self._tk.globalgetvar(self._name))
def get(self): """Return the value of the variable as a float.""" return getdouble(self._tk.globalgetvar(self._name))
14,096
def __init__(self, master=None): """Construct a boolean variable.
def __init__(self, master=None): """Construct a boolean variable.
14,097
def close(self): if hasattr(self.db, 'close'): self.db.close() self.db = None
def close(self): if hasattr(self.db, 'close'): self.db.close() self.db = None
14,098
def __init__(self, dict, templatelist=TEMPLATELIST, templatename=None): if templatename == None: if hasattr(MacOS, 'runtimemodel'): templatename = 'template-%s'%MacOS.runtimemodel else: templatename = 'template' if os.sep in templatename: templatedir = templatename else: try: packagedir = os.path.split(__file__)[0] except NameError: packagedir = os.curdir templatedir = os.path.join(packagedir, templatename) if not os.path.exists(templatedir): raise Error, "Cannot find templatedir %s"%templatedir self.dict = dict if not dict.has_key('prefixname'): dict['prefixname'] = 'mwerks_plugin_config.h' self.templatelist = templatelist self.templatedir = templatedir
def __init__(self, dict, templatelist=TEMPLATELIST, templatename=None): if templatename == None: if hasattr(MacOS, 'runtimemodel'): templatename = 'template-%s'%MacOS.runtimemodel else: templatename = 'template' if os.sep in templatename: templatedir = templatename else: try: packagedir = os.path.split(__file__)[0] except NameError: packagedir = os.curdir templatedir = os.path.join(packagedir, templatename) if not os.path.exists(templatedir): raise Error, "Cannot find templatedir %s"%templatedir self.dict = dict if not dict.has_key('prefixname'): if hasattr(MacOS, 'runtimemodel') and MacOS.runtimemodel == "carbon": dict['prefixname'] = 'mwerks_carbonplugin_config.h' else: dict['prefixname'] = 'mwerks_plugin_config.h' self.templatelist = templatelist self.templatedir = templatedir
14,099