rem
stringlengths 1
322k
| add
stringlengths 0
2.05M
| context
stringlengths 4
228k
| meta
stringlengths 156
215
|
---|---|---|---|
def doit (self, data, **args): # note: data is the complete request method, url, httpver = data.split() debug(FILTER, "block filter working on url %s", `url`) if self.allowed(url): return data blocked = self.strict_whitelist or self.blocked(url) if blocked: debug(FILTER, "blocked url %s", url) if isinstance(blocked, basestring): doc = blocked # index 3, not 2! elif is_image(url): doc = self.block_image else: # XXX hmmm, what about CGI images? # make HTTP HEAD request? doc = self.block_url port = config['port'] if method=='CONNECT': return 'CONNECT https://localhost:%d%s HTTP/1.1'%(port, doc) return 'GET http://localhost:%d%s HTTP/1.1'%(port, doc) return data | f32d2a1749d0cb0f35bb52a4e34151db130f20f9 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f32d2a1749d0cb0f35bb52a4e34151db130f20f9/Blocker.py |
||
self.log.debug("Translating %s" % `args`) | self.log.debug("Translating %s with %s", `args`, str(self.translator)) | def cmdOutput (self, command, args): if self.translator is not None and self.translateContent: self.log.debug("Translating %s" % `args`) self.file.write(self.translator.gettext(args) % \ self.context.getVariableMap()) else: self.file.write (args) self.programCounter += 1 | a5dff201b5de3e3d868820f8e7fb21352e41b115 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a5dff201b5de3e3d868820f8e7fb21352e41b115/simpleTAL.py |
self.log.debug("Translating %s" % `result.value()`) | self.log.debug("Translating %s with %s", `result.value()`, str(self.translator)) | def cmdI18nTranslate (self, command, args): """ args: translation string, translation args, endTagSymbol Translate tag content. If the translation string is an empty string, the translate message id is the tag content. Otherwise, the value of the tag content is the message id. """ # an empty string means use tag content as message id if args[0] == "": self.translateContent = 1 else: result = self.context.evaluate (args[0], self.originalAttributes) if not (result is None or result.isNothing() or result.isDefault()): if self.translator is not None: self.log.debug("Translating %s" % `result.value()`) self.tagContent = (0, self.translator.gettext(result.value()) % \ self.context.getVariableMap()) else: self.tagContent = (0, result.value()) self.movePCForward = self.symbolTable[args[1]] self.programCounter += 1 | a5dff201b5de3e3d868820f8e7fb21352e41b115 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a5dff201b5de3e3d868820f8e7fb21352e41b115/simpleTAL.py |
self.log.debug("Translating %s" % `attExpr`) | self.log.debug("Translating %s with %s", `attExpr`, str(self.translator)) | def cmdI18nAttributes (self, command, args): | a5dff201b5de3e3d868820f8e7fb21352e41b115 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a5dff201b5de3e3d868820f8e7fb21352e41b115/simpleTAL.py |
def _write_color_nt (text, color): | def _write_color_nt (fp, text, color): | def _write_color_nt (text, color): """ Assumes WConio has been imported at module level. """ oldcolor = WConio.gettextinfo()[4] oldtextcolor = oldcolor & 0x000F if ";" in color: control, color = color.split(";", 1) WConio.textcolor(WConioColor.get(color, oldtextcolor)) fp.write(text) WConio.textattr(oldcolor) | 292f5558bbe7787693abe785856c8661334aa8a3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/292f5558bbe7787693abe785856c8661334aa8a3/ansicolor.py |
logging.getLogger(log).debug(msg, *args) | def debug (log, msg, *args): #logging.getLogger(log).debug("collected %d"%gc.collect()) #logging.getLogger(log).debug("objects %d"%len(gc.get_objects())) #logging.getLogger(log).debug("garbage %d"%len(gc.garbage)) #logging.getLogger(log).debug("Mem: %s"%usedmemory()) logging.getLogger(log).debug(msg, *args) | 5e8de8438c790e00672673c046e23ae8471afdc8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/5e8de8438c790e00672673c046e23ae8471afdc8/log.py |
|
"""<img>""" % tag) | """<img>""") | def testImgWidthHeight (self): for tag in ("width", "height"): self.filt("""<img %s="9999">""" % tag, """<img %s="9999">""" % tag) self.filt("""<img %s="12345">""" % tag, """<img>""" % tag) | 9d5125261945b583474a09f0393996cca18f2d8f /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/9d5125261945b583474a09f0393996cca18f2d8f/test_rewriter.py |
JSFilter(self.url, **opts) | return JSFilter(self.url, opts) | def new_instance (self, **opts): JSFilter(self.url, **opts) | 74fe2f9efe34e5b50273ff87179196fa6b117cb7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/74fe2f9efe34e5b50273ff87179196fa6b117cb7/JSFilter.py |
super(SetList), self).__setitem__(key, value) | super(SetList, self).__setitem__(key, value) | def __setitem__ (self, key, value): if value not in self: super(SetList), self).__setitem__(key, value) | 911540c3370237a5aad9b9a94470472f2b0592c3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/911540c3370237a5aad9b9a94470472f2b0592c3/containers.py |
def do_install (): """ Install shortcuts and NT service. """ fix_configdata() import wc wc.init_i18n() install_shortcuts() install_certificates() install_service() restart_service() open_browser_config() | def fix_install_path (line): """ Replace placeholders written by bdist_wininst with those specified in win_path_scheme. """ key, eq, val = line.split() # unescape string (do not use eval()) val = val[1:-1].replace("\\\\", "\\") for d in win_path_scheme.keys(): # look for placeholders to replace oldpath, newpath = win_path_scheme[d] oldpath = "%s%s" % (os.sep, oldpath) if oldpath in val: val = val.replace(oldpath, newpath) val = os.path.join(sys.prefix, val) val = os.path.normpath(val) return "%s = %r%s" % (key, val, os.linesep) | 7cbac3bde56dcd51807f4ea80d77e1716d38a2e7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7cbac3bde56dcd51807f4ea80d77e1716d38a2e7/install-webcleaner.py |
|
def state_nt_service (name): """ Return status of NT service. """ try: return win32serviceutil.QueryServiceStatus(name)[1] except pywintypes.error, msg: print _("Service status error: %s") % str(msg) return None def install_service (): """ Install WebCleaner as NT service. """ import wc import wc.win32start oldargs = sys.argv print _("Installing %s service...") % wc.AppName sys.argv = ['webcleaner', 'install'] win32serviceutil.HandleCommandLine(wc.win32start.ProxyService) sys.argv = oldargs def remove_service (): import wc import wc.win32start oldargs = sys.argv print _("Removing %s service...") % wc.AppName sys.argv = ['webcleaner', 'remove'] win32serviceutil.HandleCommandLine(wc.win32start.ProxyService) sys.argv = oldargs def restart_service (): """ Restart WebCleaner NT service. """ stop_service() start_service() def stop_service (): """ Stop WebCleaner NT service (if it is running). """ import wc import wc.win32start print _("Stopping %s proxy...") % wc.AppName oldargs = sys.argv state = state_nt_service(wc.AppName) while state==win32service.SERVICE_START_PENDING: time.sleep(1) state = state_nt_service(wc.AppName) if state==win32service.SERVICE_RUNNING: sys.argv = ['webcleaner', 'stop'] win32serviceutil.HandleCommandLine(wc.win32start.ProxyService) state = state_nt_service(wc.AppName) while state==win32service.SERVICE_STOP_PENDING: time.sleep(1) state = state_nt_service(wc.AppName) sys.argv = oldargs def start_service (): """ Start WebCleaner NT service. """ import wc import wc.win32start print _("Starting %s proxy...") % wc.AppName oldargs = sys.argv sys.argv = ['webcleaner', 'start'] win32serviceutil.HandleCommandLine(wc.win32start.ProxyService) sys.argv = oldargs | def install_adminpassword (): """ Ask for admin password if not already set. """ if has_adminpassword(): return import wc import Tkinter as tk root = init_tk() import tkSimpleDialog class PasswordDialog (tkSimpleDialog.Dialog): """ Admin password dialog. """ def body(self, master): d = {"appname": wc.AppName} msg = _("""The administrator password protects the web configuration frontend of %s. The default username is "admin" (without the quotes). You have to enter a non-empty password. If you press cancel, the administrator password has to be entered manually (don't worry, the web interface will tell you how to do that).""") label = Label(master, text=msg % d, anchor=tk.W, justify=tk.LEFT) label.grid(row=0, columnspan=2, sticky=tk.W) label = Label(master, text=_("Password:")) label.grid(row=1, sticky=tk.W) self.pass_entry = Entry(master) self.pass_entry.grid(row=1, column=1) return self.pass_entry def apply(self): password = self.pass_entry.get() if password: save_adminpassword(password) else: print _("Not saving empty password.") title = _("%s administrator password") % wc.AppName PasswordDialog(root, title=title) def has_adminpassword (): """ Check if admin password is already set. """ return get_wc_config()["adminpass"] def save_adminpassword (password): """ Save new admin password to WebCleaner configuration. Also checks for invalid password format. """ import base64 import wc.strformat password = base64.b64encode(password) if not password or not wc.strformat.is_ascii(password): print _("Not saving binary password.") return config = get_wc_config() config["password"] = password config.write_proxyconf() | def state_nt_service (name): """ Return status of NT service. """ try: return win32serviceutil.QueryServiceStatus(name)[1] except pywintypes.error, msg: print _("Service status error: %s") % str(msg) return None | 7cbac3bde56dcd51807f4ea80d77e1716d38a2e7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7cbac3bde56dcd51807f4ea80d77e1716d38a2e7/install-webcleaner.py |
""" Open the WebCleaner administration web interface. """ | def open_browser_config (): # sleep a while to let the proxy start... import wc import wc.configuration state = state_nt_service(wc.AppName) while state==win32service.SERVICE_START_PENDING: time.sleep(1) state = state_nt_service(wc.AppName) time.sleep(3) # open configuration config = wc.configuration.init() config_url = "http://localhost:%d/" % config['port'] open_browser(config_url) | 7cbac3bde56dcd51807f4ea80d77e1716d38a2e7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7cbac3bde56dcd51807f4ea80d77e1716d38a2e7/install-webcleaner.py |
|
from Tkinter import tkMessageBox answer = tkMessageBox.askyesno(_("Purge local config"), _("""Do you want to remove your local filter rules? They can be re-used in other installations of %s, but are useless otherwise.""")) | init_tk() import tkMessageBox answer = tkMessageBox.askyesno(_("%s config purge") % wc.AppName, _("""There are local filter rules in the configuration directory. Do you want to remove them? They can be re-used in other installations of %s, but are useless otherwise.""") % wc.AppName) | def purge_tempfiles (): """ Ask if user wants to purge local config files. """ files = glob.glob(os.path.join(wc.ConfigDir, "local_*.zap")) if not files: return from Tkinter import tkMessageBox answer = tkMessageBox.askyesno(_("Purge local config"), _("""Do you want to remove your local filter rules? | 7cbac3bde56dcd51807f4ea80d77e1716d38a2e7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7cbac3bde56dcd51807f4ea80d77e1716d38a2e7/install-webcleaner.py |
print _("Could not remove %r: %s") % (fname, str(msg)) | print _("Could not remove file %r: %s") % (fname, str(msg)) def is_empty_dir (name): """ Check if given name is a non-empty directory. """ return os.path.isdir(name) and not os.listdir(name) def remove_empty_directories (dname): """ Remove empty directory structure. """ try: if is_empty_dir(dname): os.rmdir(dname) remove_empty_directories(os.path.dirname(dname)) except OSError, msg: print _("Could not remove directory %r: %s") % (dname, str(msg)) | def remove_file (fname): """ Remove a single file if it exists. Errors are printed to stdout. """ if os.path.exists(fname): try: os.remove(fname) except OSError, msg: print _("Could not remove %r: %s") % (fname, str(msg)) | 7cbac3bde56dcd51807f4ea80d77e1716d38a2e7 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7cbac3bde56dcd51807f4ea80d77e1716d38a2e7/install-webcleaner.py |
se_offset_abs = "^\(([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)" \ "(\.[bslBSL])*\)" se_offset_add = "^\(([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)" \ "(\.[bslBSL])*([-+])([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)\)" | se_offset_abs = re.compile( r"^\(([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)" \ r"(\.[bslBSL])*\)").match se_offset_add = re.compile( r"^\(([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)" \ r"(\.[bslBSL])*([-+])([0\\\][xX][\dA-Fa-f]+|[0\\\][0-7]*|\d+)\)").match | def dump (o, f): """pickle object o to file f""" cPickle.dump(o, f, pickle.HIGHEST_PROTOCOL) | f71dd792b3cd7b971abd17643d3a4ef8a134fcf8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f71dd792b3cd7b971abd17643d3a4ef8a134fcf8/__init__.py |
match_abs = re.compile(self.se_offset_abs).match(text) match_add = re.compile(self.se_offset_add).match(text) | match_abs = self.se_offset_abs(text) match_add = self.se_offset_add(text) | def _offset (self, text): direct = self._direct_offset(text) offset_type = 'l' offset_delta = 0L offset_relatif = 0L | f71dd792b3cd7b971abd17643d3a4ef8a134fcf8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f71dd792b3cd7b971abd17643d3a4ef8a134fcf8/__init__.py |
if line and not line.startswith(' part = self._split(line) while len(part) < 4: part.append('\b') level = self._level(part[0]) offset_string = self._strip_start('&', part[0][level:]) (direct, offset_type, offset_delta, offset_relatif) = \ self._offset(offset_string) (oper, mask, rest) = self._oper_mask(part[1]) full_type = self._strip_start('u', rest) endian = self._endian(full_type) kind = self._kind(full_type, endian) (test, result) = self._test_result(part[2]) data = self._data(kind, result) length = self._length(kind, data) mime = self._mime(part[3:]) self._leveldict[index] = level self._direct[index] = direct self._offset_type[index] = offset_type self._offset_delta[index] = offset_delta self._offset_relatif[index] = offset_relatif self._endiandict[index] = endian self._kinddict[index] = kind self._oper[index] = oper self._mask[index] = mask self._test[index] = test self._datadict[index] = data self._lengthdict[index] = length self._mimedict[index] = mime index += 1 self.entries = index | if not line or line.startswith(' continue part = self._split(line) while len(part) < 4: part.append(r'\b') level = self._level(part[0]) offset_string = self._strip_start('&', part[0][level:]) (direct, offset_type, offset_delta, offset_relatif) = \ self._offset(offset_string) (oper, mask, rest) = self._oper_mask(part[1]) full_type = self._strip_start('u', rest) endian = self._endian(full_type) kind = self._kind(full_type, endian) (test, result) = self._test_result(part[2]) data = self._data(kind, result) length = self._length(kind, data) mime = self._mime(part[3:]) self._leveldict[index] = level self._direct[index] = direct self._offset_type[index] = offset_type self._offset_delta[index] = offset_delta self._offset_relatif[index] = offset_relatif self._endiandict[index] = endian self._kinddict[index] = kind self._oper[index] = oper self._mask[index] = mask self._test[index] = test self._datadict[index] = data self._lengthdict[index] = length self._mimedict[index] = mime index += 1 self.entries = index | def read_magic (self, magic_file): self.magic = [] | f71dd792b3cd7b971abd17643d3a4ef8a134fcf8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f71dd792b3cd7b971abd17643d3a4ef8a134fcf8/__init__.py |
value = 0 | value = data | def _convert (self, kind, endian, data): # Can raise StandardError and IOError value = 0 | f71dd792b3cd7b971abd17643d3a4ef8a134fcf8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f71dd792b3cd7b971abd17643d3a4ef8a134fcf8/__init__.py |
s = u'<Rule %s sid="%s"' % (self.get_name(), | s = u'<%s sid="%s"' % (self.get_name(), | def toxml (self): """Rule data as XML for storing, must be overridden in subclass""" s = u'<Rule %s sid="%s"' % (self.get_name(), wc.XmlUtils.xmlquoteattr(self.sid)) if self.disable: s += u' disable="%d"' % self.disable return s | e792f72e34ca8bd6a676d9c6181d84a193371e94 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/e792f72e34ca8bd6a676d9c6181d84a193371e94/Rule.py |
self.filt("""<frameset><frame src="aaa"><embed name="sp", style><applet hspace="file:\\">""", """<frameset><frame src="aaa"><embed name="sp", style><applet>""") | self.filt("""<frameset><frame src="aaa"><embed name="sp" style><applet hspace="file:\\\\">""", """<frameset><frame src="aaa"><embed name="sp" style><applet>""") | def testAppletHspace (self): self.filt("""<frameset><frame src="aaa"><embed name="sp", style><applet hspace="file:\\">""", """<frameset><frame src="aaa"><embed name="sp", style><applet>""") | c57f671115f51744639ece8a11d7eae0f46e0a45 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c57f671115f51744639ece8a11d7eae0f46e0a45/test_rewriter.py |
self.jsScript(script, ver) return 1 | return self.jsScript(script, ver) | def jsScriptSrc (self, url, language): if not url: return url = urlparse.urljoin(self.url, url) #debug(HURT_ME_PLENTY, "jsScriptSrc", url, language) try: script = urlutils.open_url(url).read() except: print >>sys.stderr, "exception fetching script url", `url` return if not script: return ver = 0.0 if language: mo = re.search(r'(?i)javascript(?P<num>\d\.\d)', language) if mo: ver = float(mo.group('num')) self.jsScript(script, ver) return 1 | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
"""execute given script with javascript version ver""" | """execute given script with javascript version ver return True if the script generates any output, else False""" | def jsScript (self, script, ver): """execute given script with javascript version ver""" #debug(HURT_ME_PLENTY, "jsScript", script, ver) self.jsEnv.attachListener(self) self.jsfilter = HtmlFilter(self.rules, self.url, comments=self.comments, javascript=self.javascript) self.jsEnv.executeScript(script, ver) self.jsEnv.detachListener(self) self.jsfilter.flush() self.data.append(self.jsfilter.flushbuf()) self.buffer += self.jsfilter.buffer self.rulestack += self.jsfilter.rulestack self.jsfilter = None | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
self.jsfilter.flush() self.data.append(self.jsfilter.flushbuf()) self.buffer += self.jsfilter.buffer self.rulestack += self.jsfilter.rulestack | if self.output_counter: self.jsfilter.flush() self.data.append(self.jsfilter.flushbuf()) self.buffer += self.jsfilter.buffer self.rulestack += self.jsfilter.rulestack | def jsScript (self, script, ver): """execute given script with javascript version ver""" #debug(HURT_ME_PLENTY, "jsScript", script, ver) self.jsEnv.attachListener(self) self.jsfilter = HtmlFilter(self.rules, self.url, comments=self.comments, javascript=self.javascript) self.jsEnv.executeScript(script, ver) self.jsEnv.detachListener(self) self.jsfilter.flush() self.data.append(self.jsfilter.flushbuf()) self.buffer += self.jsfilter.buffer self.rulestack += self.jsfilter.rulestack self.jsfilter = None | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
if not filtered and self.javascript and tag=='script': self.jsEndElement(tag) | if not filtered and self.javascript and tag=='script' and \ self.jsEndElement(tag): del self.buffer[-1] del self.buffer[-1] | def endElement (self, tag): """We know the following: if a rule matches, it must be the one on the top of the stack. So we look only at the top rule. | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
"""parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" | """parse generated html for scripts return True if the script generates any output, else False""" if len(self.buffer)<2: | def jsEndElement (self, tag): """parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" return if self.buffer[-1][0]!=DATA: print >>sys.stderr, "missing data for </script>", self.buffer[-1:] return script = self.buffer[-1][1].strip() del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): # there was a <script src="..."> already return del self.buffer[-1] if script.startswith("<!--"): script = script[4:].strip() if not script: return self.jsScript(script, 0.0) | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): | if not (self.buffer[-2][0]==STARTTAG and \ self.buffer[-2][1]=='script'): | def jsEndElement (self, tag): """parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" return if self.buffer[-1][0]!=DATA: print >>sys.stderr, "missing data for </script>", self.buffer[-1:] return script = self.buffer[-1][1].strip() del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): # there was a <script src="..."> already return del self.buffer[-1] if script.startswith("<!--"): script = script[4:].strip() if not script: return self.jsScript(script, 0.0) | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
del self.buffer[-1] | def jsEndElement (self, tag): """parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" return if self.buffer[-1][0]!=DATA: print >>sys.stderr, "missing data for </script>", self.buffer[-1:] return script = self.buffer[-1][1].strip() del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): # there was a <script src="..."> already return del self.buffer[-1] if script.startswith("<!--"): script = script[4:].strip() if not script: return self.jsScript(script, 0.0) | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
|
script = script[4:].strip() | i = script.index('\n') if i==-1: script = script[4:] else: script = script[(i+1):] if script.endswith("-->"): script = script[:-3] | def jsEndElement (self, tag): """parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" return if self.buffer[-1][0]!=DATA: print >>sys.stderr, "missing data for </script>", self.buffer[-1:] return script = self.buffer[-1][1].strip() del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): # there was a <script src="..."> already return del self.buffer[-1] if script.startswith("<!--"): script = script[4:].strip() if not script: return self.jsScript(script, 0.0) | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
self.jsScript(script, 0.0) | return self.jsScript(script, 0.0) | def jsEndElement (self, tag): """parse generated html for scripts""" if not self.buffer: print >>sys.stderr, "empty buffer on </script>" return if self.buffer[-1][0]!=DATA: print >>sys.stderr, "missing data for </script>", self.buffer[-1:] return script = self.buffer[-1][1].strip() del self.buffer[-1] if not (self.buffer and self.buffer[-1][0]==STARTTAG and \ self.buffer[-1][1]=='script'): # there was a <script src="..."> already return del self.buffer[-1] if script.startswith("<!--"): script = script[4:].strip() if not script: return self.jsScript(script, 0.0) | 3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/3065d1c6c10f0c7943a3e34722dcd91e9c5a16f5/Rewriter.py |
if data: p.feed(data) | if data: p.feed(data) | def finish (self, data, **attrs): if not attrs.has_key('filter'): return data p = attrs['filter'] if data: p.feed(data) p.flush() p.buf2data() return p.flushbuf() | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
"""The parser has the rules, a data buffer and a rule stack.""" | """The parser has the rules, a data buffer and a rule stack. States: parse => default parsing state, no background fetching wait => Fetching additionally data in the background. Feeding new data in wait state raises a FilterException. When finished, the buffers look like data [---------|--------][-------][----------] ^-script src tag waitbuf [--------] inbuf [-------------- ... """ | def _buf2data (buf, outbuf): """Append all tags of the buffer to the data""" for item in buf: if item[0]==DATA: outbuf.write(item[1]) elif item[0]==STARTTAG: s = "<"+item[1] for name,val in item[2].items(): s += ' %s'%name if val: s += "=%s"%val outbuf.write(s+">") elif item[0]==ENDTAG: outbuf.write("</%s>"%item[1]) elif item[0]==COMMENT: outbuf.write("<!--%s-->"%item[1]) else: error("unknown buffer element %s" % item[0]) | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
data = "%s%s%s" % (self.waitbuf.getvalue(), self.inbuf.getvalue(), data) | data = "%s%s" % (self.waitbuf.getvalue(), self.inbuf.getvalue(), ) | def feed (self, data): if self.state=='parse': if self.waited: data = "%s%s%s" % (self.waitbuf.getvalue(), self.inbuf.getvalue(), data) self.inbuf.close() self.waitbuf.close() self.inbuf = StringIO() self.waitbuf = StringIO() self.waited = 0 HtmlParser.feed(self, data) else: self.inbuf.write(data) | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
debug(NIGHTMARE, "Filter: matched rule %s on tag %s" % (`rule.title`, `tag`)) | debug(NIGHTMARE, "HtmlFilter: matched rule %s on tag %s" % (`rule.title`, `tag`)) | def startElement (self, tag, attrs): """We get a new start tag. New rules could be appended to the pending rules. No rules can be removed from the list.""" # default data item = [STARTTAG, tag, attrs] if self.state=='wait': return _buf2data([item], self.waitbuf) rulelist = [] filtered = 0 # look for filter rules which apply for rule in self.rules: if rule.match_tag(tag) and rule.match_attrs(attrs): debug(NIGHTMARE, "Filter: matched rule %s on tag %s" % (`rule.title`, `tag`)) if rule.start_sufficient: item = rule.filter_tag(tag, attrs) filtered = "True" # give'em a chance to replace more than one attribute if item[0]==STARTTAG and item[1]==tag: foo,tag,attrs = item continue else: break else: debug(NIGHTMARE, "Filter: put on buffer") rulelist.append(rule) if rulelist: # remember buffer position for end tag matching pos = len(self.buf) self.rulestack.append((pos, rulelist)) # if its not yet filtered, try filter javascript if filtered: self.buf_append_data(item) elif self.javascript: self.jsStartElement(tag, attrs) else: self.buf.append(item) # if rule stack is empty, write out the buffered data if not self.rulestack and \ (not self.javascript or tag!='script'): self.buf2data() | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
debug(NIGHTMARE, "Filter: put on buffer") | debug(NIGHTMARE, "HtmlFilter: put on buffer") | def startElement (self, tag, attrs): """We get a new start tag. New rules could be appended to the pending rules. No rules can be removed from the list.""" # default data item = [STARTTAG, tag, attrs] if self.state=='wait': return _buf2data([item], self.waitbuf) rulelist = [] filtered = 0 # look for filter rules which apply for rule in self.rules: if rule.match_tag(tag) and rule.match_attrs(attrs): debug(NIGHTMARE, "Filter: matched rule %s on tag %s" % (`rule.title`, `tag`)) if rule.start_sufficient: item = rule.filter_tag(tag, attrs) filtered = "True" # give'em a chance to replace more than one attribute if item[0]==STARTTAG and item[1]==tag: foo,tag,attrs = item continue else: break else: debug(NIGHTMARE, "Filter: put on buffer") rulelist.append(rule) if rulelist: # remember buffer position for end tag matching pos = len(self.buf) self.rulestack.append((pos, rulelist)) # if its not yet filtered, try filter javascript if filtered: self.buf_append_data(item) elif self.javascript: self.jsStartElement(tag, attrs) else: self.buf.append(item) # if rule stack is empty, write out the buffered data if not self.rulestack and \ (not self.javascript or tag!='script'): self.buf2data() | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
def startElement (self, tag, attrs): """We get a new start tag. New rules could be appended to the pending rules. No rules can be removed from the list.""" # default data item = [STARTTAG, tag, attrs] if self.state=='wait': return _buf2data([item], self.waitbuf) rulelist = [] filtered = 0 # look for filter rules which apply for rule in self.rules: if rule.match_tag(tag) and rule.match_attrs(attrs): debug(NIGHTMARE, "Filter: matched rule %s on tag %s" % (`rule.title`, `tag`)) if rule.start_sufficient: item = rule.filter_tag(tag, attrs) filtered = "True" # give'em a chance to replace more than one attribute if item[0]==STARTTAG and item[1]==tag: foo,tag,attrs = item continue else: break else: debug(NIGHTMARE, "Filter: put on buffer") rulelist.append(rule) if rulelist: # remember buffer position for end tag matching pos = len(self.buf) self.rulestack.append((pos, rulelist)) # if its not yet filtered, try filter javascript if filtered: self.buf_append_data(item) elif self.javascript: self.jsStartElement(tag, attrs) else: self.buf.append(item) # if rule stack is empty, write out the buffered data if not self.rulestack and \ (not self.javascript or tag!='script'): self.buf2data() | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
||
if not self.rulestack and \ (not self.javascript or tag!='script'): | if not self.rulestack and not self.javascript: | def startElement (self, tag, attrs): """We get a new start tag. New rules could be appended to the pending rules. No rules can be removed from the list.""" # default data item = [STARTTAG, tag, attrs] if self.state=='wait': return _buf2data([item], self.waitbuf) rulelist = [] filtered = 0 # look for filter rules which apply for rule in self.rules: if rule.match_tag(tag) and rule.match_attrs(attrs): debug(NIGHTMARE, "Filter: matched rule %s on tag %s" % (`rule.title`, `tag`)) if rule.start_sufficient: item = rule.filter_tag(tag, attrs) filtered = "True" # give'em a chance to replace more than one attribute if item[0]==STARTTAG and item[1]==tag: foo,tag,attrs = item continue else: break else: debug(NIGHTMARE, "Filter: put on buffer") rulelist.append(rule) if rulelist: # remember buffer position for end tag matching pos = len(self.buf) self.rulestack.append((pos, rulelist)) # if its not yet filtered, try filter javascript if filtered: self.buf_append_data(item) elif self.javascript: self.jsStartElement(tag, attrs) else: self.buf.append(item) # if rule stack is empty, write out the buffered data if not self.rulestack and \ (not self.javascript or tag!='script'): self.buf2data() | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
filtered = 1 | filtered = "True" | def endElement (self, tag): """We know the following: if a rule matches, it must be the one on the top of the stack. So we look only at the top rule. | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
self.buf.append((ENDTAG, tag)) | self.buf.append(item) | def endElement (self, tag): """We know the following: if a rule matches, it must be the one on the top of the stack. So we look only at the top rule. | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
self.jsScriptSrc(url, lang) self.buf.append((STARTTAG, tag, attrs)) | return self.jsScriptSrc(url, lang) self.buf.append([STARTTAG, tag, attrs]) | def jsStartElement (self, tag, attrs): """Check popups for onmouseout and onmouseover. Inline extern javascript sources (only in the same domain)""" changed = 0 for name in ('onmouseover', 'onmouseout'): if attrs.has_key(name) and self.jsPopup(attrs, name): del attrs[name] changed = 1 if tag=='form': name = attrs.get('name', attrs.get('id')) self.jsForm(name, attrs.get('action', ''), attrs.get('target', '')) elif tag=='script': lang = attrs.get('language', '').lower() url = attrs.get('src', '') scrtype = attrs.get('type', '').lower() is_js = scrtype=='text/javascript' or \ lang.startswith('javascript') or \ not (lang or scrtype) if is_js and url: self.jsScriptSrc(url, lang) self.buf.append((STARTTAG, tag, attrs)) | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
ClientServerMatchmaker(clien t, | ClientServerMatchmaker(client, | def jsScriptSrc (self, url, language): assert self.state=='parse' ver = 0.0 if language: mo = re.search(r'(?i)javascript(?P<num>\d\.\d)', language) if mo: ver = float(mo.group('num')) url = urlparse.urljoin(self.url, url) debug(HURT_ME_PLENTY, "JS: jsScriptSrc", url, ver) self.script = '' self.state = 'wait' client = HttpProxyClient(self.jsScriptData, (url, ver)) ClientServerMatchmaker(clien t, "GET %s HTTP/1.1" % url, #request {}, #headers '', #content {'nofilter': None}, 'identity', # compress ) | 963fe71cee0c18f8415eff13338f105ff2d99ae1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/963fe71cee0c18f8415eff13338f105ff2d99ae1/Rewriter.py |
val = "^%s$" % val | val = "^(%s)$" % val | def compileRegex (obj, attr, fullmatch=False, flags=0): """ Regex-compile object attribute into <attr>_ro. """ if hasattr(obj, attr): val = getattr(obj, attr) if val: if fullmatch: val = "^%s$" % val setattr(obj, attr+"_ro", re.compile(val, flags)) | 705c01f39b9ae5c98cd2a5b9eaef5a8821a0fd6a /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/705c01f39b9ae5c98cd2a5b9eaef5a8821a0fd6a/Rule.py |
self.assertEquals(linkcheck.strformat.unquote(""), "") self.assertEquals(linkcheck.strformat.unquote(None), None) self.assertEquals(linkcheck.strformat.unquote("'"), "'") self.assertEquals(linkcheck.strformat.unquote("\""), "\"") self.assertEquals(linkcheck.strformat.unquote("\"\""), "") self.assertEquals(linkcheck.strformat.unquote("''"), "") self.assertEquals(linkcheck.strformat.unquote("'a'"), "a") self.assertEquals(linkcheck.strformat.unquote("'a\"'"), "a\"") self.assertEquals(linkcheck.strformat.unquote("'\"a'"), "\"a") self.assertEquals(linkcheck.strformat.unquote('"a\'"'), 'a\'') self.assertEquals(linkcheck.strformat.unquote('"\'a"'), '\'a') | self.assertEquals(wc.strformat.unquote(""), "") self.assertEquals(wc.strformat.unquote(None), None) self.assertEquals(wc.strformat.unquote("'"), "'") self.assertEquals(wc.strformat.unquote("\""), "\"") self.assertEquals(wc.strformat.unquote("\"\""), "") self.assertEquals(wc.strformat.unquote("''"), "") self.assertEquals(wc.strformat.unquote("'a'"), "a") self.assertEquals(wc.strformat.unquote("'a\"'"), "a\"") self.assertEquals(wc.strformat.unquote("'\"a'"), "\"a") self.assertEquals(wc.strformat.unquote('"a\'"'), 'a\'') self.assertEquals(wc.strformat.unquote('"\'a"'), '\'a') | def test_unquote (self): """test quote stripping""" self.assertEquals(linkcheck.strformat.unquote(""), "") self.assertEquals(linkcheck.strformat.unquote(None), None) self.assertEquals(linkcheck.strformat.unquote("'"), "'") self.assertEquals(linkcheck.strformat.unquote("\""), "\"") self.assertEquals(linkcheck.strformat.unquote("\"\""), "") self.assertEquals(linkcheck.strformat.unquote("''"), "") self.assertEquals(linkcheck.strformat.unquote("'a'"), "a") self.assertEquals(linkcheck.strformat.unquote("'a\"'"), "a\"") self.assertEquals(linkcheck.strformat.unquote("'\"a'"), "\"a") self.assertEquals(linkcheck.strformat.unquote('"a\'"'), 'a\'') self.assertEquals(linkcheck.strformat.unquote('"\'a"'), '\'a') # even mis-matching quotes should be removed... self.assertEquals(linkcheck.strformat.unquote("'a\""), "a") self.assertEquals(linkcheck.strformat.unquote("\"a'"), "a") | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertEquals(linkcheck.strformat.unquote("'a\""), "a") self.assertEquals(linkcheck.strformat.unquote("\"a'"), "a") | self.assertEquals(wc.strformat.unquote("'a\""), "a") self.assertEquals(wc.strformat.unquote("\"a'"), "a") | def test_unquote (self): """test quote stripping""" self.assertEquals(linkcheck.strformat.unquote(""), "") self.assertEquals(linkcheck.strformat.unquote(None), None) self.assertEquals(linkcheck.strformat.unquote("'"), "'") self.assertEquals(linkcheck.strformat.unquote("\""), "\"") self.assertEquals(linkcheck.strformat.unquote("\"\""), "") self.assertEquals(linkcheck.strformat.unquote("''"), "") self.assertEquals(linkcheck.strformat.unquote("'a'"), "a") self.assertEquals(linkcheck.strformat.unquote("'a\"'"), "a\"") self.assertEquals(linkcheck.strformat.unquote("'\"a'"), "\"a") self.assertEquals(linkcheck.strformat.unquote('"a\'"'), 'a\'') self.assertEquals(linkcheck.strformat.unquote('"\'a"'), '\'a') # even mis-matching quotes should be removed... self.assertEquals(linkcheck.strformat.unquote("'a\""), "a") self.assertEquals(linkcheck.strformat.unquote("\"a'"), "a") | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertEquals(linkcheck.strformat.wrap(s, -1), s) self.assertEquals(linkcheck.strformat.wrap(s, 0), s) | self.assertEquals(wc.strformat.wrap(s, -1), s) self.assertEquals(wc.strformat.wrap(s, 0), s) | def test_wrap (self): """test line wrapping""" s = "11%(sep)s22%(sep)s33%(sep)s44%(sep)s55" % {'sep': os.linesep} # testing width <= 0 self.assertEquals(linkcheck.strformat.wrap(s, -1), s) self.assertEquals(linkcheck.strformat.wrap(s, 0), s) s2 = "11 22%(sep)s33 44%(sep)s55" % {'sep': os.linesep} # splitting lines self.assertEquals(linkcheck.strformat.wrap(s2, 2), s) # combining lines self.assertEquals(linkcheck.strformat.wrap(s, 5), s2) | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertEquals(linkcheck.strformat.wrap(s2, 2), s) | self.assertEquals(wc.strformat.wrap(s2, 2), s) | def test_wrap (self): """test line wrapping""" s = "11%(sep)s22%(sep)s33%(sep)s44%(sep)s55" % {'sep': os.linesep} # testing width <= 0 self.assertEquals(linkcheck.strformat.wrap(s, -1), s) self.assertEquals(linkcheck.strformat.wrap(s, 0), s) s2 = "11 22%(sep)s33 44%(sep)s55" % {'sep': os.linesep} # splitting lines self.assertEquals(linkcheck.strformat.wrap(s2, 2), s) # combining lines self.assertEquals(linkcheck.strformat.wrap(s, 5), s2) | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertEquals(linkcheck.strformat.wrap(s, 5), s2) | self.assertEquals(wc.strformat.wrap(s, 5), s2) | def test_wrap (self): """test line wrapping""" s = "11%(sep)s22%(sep)s33%(sep)s44%(sep)s55" % {'sep': os.linesep} # testing width <= 0 self.assertEquals(linkcheck.strformat.wrap(s, -1), s) self.assertEquals(linkcheck.strformat.wrap(s, 0), s) s2 = "11 22%(sep)s33 44%(sep)s55" % {'sep': os.linesep} # splitting lines self.assertEquals(linkcheck.strformat.wrap(s2, 2), s) # combining lines self.assertEquals(linkcheck.strformat.wrap(s, 5), s2) | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertEquals(linkcheck.strformat.remove_markup("<a>"), "") self.assertEquals(linkcheck.strformat.remove_markup("<>"), "") self.assertEquals(linkcheck.strformat.remove_markup("<<>"), "") self.assertEquals(linkcheck.strformat.remove_markup("a < b"), "a < b") | self.assertEquals(wc.strformat.remove_markup("<a>"), "") self.assertEquals(wc.strformat.remove_markup("<>"), "") self.assertEquals(wc.strformat.remove_markup("<<>"), "") self.assertEquals(wc.strformat.remove_markup("a < b"), "a < b") | def test_remove_markup (self): """test markup removing""" self.assertEquals(linkcheck.strformat.remove_markup("<a>"), "") self.assertEquals(linkcheck.strformat.remove_markup("<>"), "") self.assertEquals(linkcheck.strformat.remove_markup("<<>"), "") self.assertEquals(linkcheck.strformat.remove_markup("a < b"), "a < b") | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
self.assertRaises(ValueError, linkcheck.strformat.strsize, -1) self.assertEquals(linkcheck.strformat.strsize(0), "0 Bytes") self.assertEquals(linkcheck.strformat.strsize(1), "1 Byte") self.assertEquals(linkcheck.strformat.strsize(2), "2 Bytes") self.assertEquals(linkcheck.strformat.strsize(1023), "1023 Bytes") self.assertEquals(linkcheck.strformat.strsize(1024), "1.00 kB") | self.assertRaises(ValueError, wc.strformat.strsize, -1) self.assertEquals(wc.strformat.strsize(0), "0 Bytes") self.assertEquals(wc.strformat.strsize(1), "1 Byte") self.assertEquals(wc.strformat.strsize(2), "2 Bytes") self.assertEquals(wc.strformat.strsize(1023), "1023 Bytes") self.assertEquals(wc.strformat.strsize(1024), "1.00 kB") | def test_strsize (self): """test byte size strings""" self.assertRaises(ValueError, linkcheck.strformat.strsize, -1) self.assertEquals(linkcheck.strformat.strsize(0), "0 Bytes") self.assertEquals(linkcheck.strformat.strsize(1), "1 Byte") self.assertEquals(linkcheck.strformat.strsize(2), "2 Bytes") self.assertEquals(linkcheck.strformat.strsize(1023), "1023 Bytes") self.assertEquals(linkcheck.strformat.strsize(1024), "1.00 kB") | 4a23be976d9b50896ccaccc02ae89f5ca6c9f960 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/4a23be976d9b50896ccaccc02ae89f5ca6c9f960/test_strformat.py |
raise RatingParseError(i18n._(",alformed rating line %r")%line) | raise RatingParseError(i18n._("malformed rating line %r")%line) | def rating_parse (data, debug=0): """parse given rating data, throws ParseError on error""" categories = {} for line in data.splitlines(): if debug: debug(RATING, "Read line %r", line) try: category, value = line.split(None, 1) except ValueError, msg: raise RatingParseError(i18n._(",alformed rating line %r")%line) categories[category] = value return categories | 95214b3a2be0a4d0f8bc15494a0109270a3be776 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/95214b3a2be0a4d0f8bc15494a0109270a3be776/Rating.py |
self._debug(ALWAYS, "self.inbuf", `self.inbuf.getvalue()`) | def feed (self, data): """feed some data to the parser""" if self.state=='parse': # look if we must replay something if self.waited: self.waited = 0 waitbuf, self.waitbuf = self.waitbuf, [] self.replay(waitbuf) if self.state!='parse': self._debug(ALWAYS, "self.inbuf", `self.inbuf.getvalue()`) return data = self.inbuf.getvalue() + data self.inbuf.close() self.inbuf = StringIO() if data: # only feed non-empty data #self._debug(NIGHTMARE, "feed", `data`) self.parser.feed(data) else: #self._debug(NIGHTMARE, "feed") pass else: # wait state --> put in input buffer #self._debug(NIGHTMARE, "wait") self.inbuf.write(data) | d4fce7e0af88a8a5a2d9abb289283697c880aa94 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/d4fce7e0af88a8a5a2d9abb289283697c880aa94/HtmlParser.py |
|
self.handleError() | self.handleError(record) | def emit (self, record): """ A little more verbose emit function. """ try: msg = self.format(record) self.stream.write("%s\n" % msg) self.flush() except: print >>sys.stderr, "Could not format record", record self.handleError() | 5cd49b18dc1167723f4244fbf8c71130b9ecfa73 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/5cd49b18dc1167723f4244fbf8c71130b9ecfa73/log.py |
categories[cat][type] = gzip.GzipFile(fname, 'wb') | categories[cat][ftype] = gzip.GzipFile(fname, 'wb') | def open_files (directory): for cat in categories.keys(): if cat=='kids_and_teens': d='whitelists' else: d='blacklists' basedir = "%s/%s/%s" % (directory, d, cat) if not os.path.isdir(basedir): os.makedirs(basedir) for ftype in categories[cat].keys(): if ftype=="expressions": continue fname = "%s/%s.gz" % (basedir, ftype) if os.path.exists(fname): os.remove(fname) print "opening", fname categories[cat][type] = gzip.GzipFile(fname, 'wb') | 82972525a8431813b7a7a283ac425d1bab740300 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/82972525a8431813b7a7a283ac425d1bab740300/bl2wc.py |
scripts = ['webcleaner', 'webcleanerconf', 'wcheaders'] | scripts = ['webcleaner', 'webcleanerconf', 'wcheaders'], | def create_batch_file(self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | a6fe0eab568a121d891c5e05b6628b402c768f60 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a6fe0eab568a121d891c5e05b6628b402c768f60/setup.py |
"charset": ConfigCharset, "title_en": xmlify("%s %s" % (ftype.capitalize(), cat)), "title_de": xmlify("%s %s" % (transtypes[ftype]['de'].capitalize(), | "charset": wc.ConfigCharset, "title_en": wc.XmlUtils.xmlquote("%s %s" % (ftype.capitalize(), cat)), "title_de": wc.XmlUtils.xmlquote("%s %s" % (transtypes[ftype]['de'].capitalize(), | def write_folder (cat, ftype, data, f): print "write", cat, "folder" d = { "charset": ConfigCharset, "title_en": xmlify("%s %s" % (ftype.capitalize(), cat)), "title_de": xmlify("%s %s" % (transtypes[ftype]['de'].capitalize(), transcats[cat]['de'].capitalize())), "desc_en": xmlify("Automatically generated on %s" % date), "desc_de": xmlify("Automatisch generiert am %s" % date), } f.write("""<?xml version="1.0" encoding="%(charset)s"?> | ea210123cf99e19e452cf01342949f702e718584 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/ea210123cf99e19e452cf01342949f702e718584/bl2wc.py |
"desc_en": xmlify("Automatically generated on %s" % date), "desc_de": xmlify("Automatisch generiert am %s" % date), | "desc_en": wc.XmlUtils.xmlquote("Automatically generated on %s" % date), "desc_de": wc.XmlUtils.xmlquote("Automatisch generiert am %s" % date), | def write_folder (cat, ftype, data, f): print "write", cat, "folder" d = { "charset": ConfigCharset, "title_en": xmlify("%s %s" % (ftype.capitalize(), cat)), "title_de": xmlify("%s %s" % (transtypes[ftype]['de'].capitalize(), transcats[cat]['de'].capitalize())), "desc_en": xmlify("Automatically generated on %s" % date), "desc_de": xmlify("Automatisch generiert am %s" % date), } f.write("""<?xml version="1.0" encoding="%(charset)s"?> | ea210123cf99e19e452cf01342949f702e718584 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/ea210123cf99e19e452cf01342949f702e718584/bl2wc.py |
d['path'] = xmlify(expr) | d['path'] = wc.XmlUtils.xmlquote(expr) | def write_expressions (cat, b, ftype, f): d = { 'title_en': "%s expression filter"%cat.capitalize(), 'title_de': "%s Ausdruckfilter"%transcats[cat]['de'].capitalize(), 'desc_en': """Automatically generated, you should not edit this filter. | ea210123cf99e19e452cf01342949f702e718584 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/ea210123cf99e19e452cf01342949f702e718584/bl2wc.py |
f = TarFile.gzopen(source) | f = tarfile.TarFile.gzopen(source) | def blacklist (fname): source = os.path.join("downloads", fname) # extract tar if fname.endswith(".tar.gz"): print "extracting archive..." d = os.path.join("extracted", fname[:-7]) f = TarFile.gzopen(source) for m in f: a, b = os.path.split(m.name) a = os.path.basename(a) if b in myfiles and a in mycats: print m.name f.extract(m, d) f.close() read_blacklists(d) elif fname.endswith(".gz"): print "gunzip..." f = gzip.open(source) fname = "extracted/"+fname[:-3] os.makedirs(os.path.dirname(fname)) w = file(fname, 'wb') w.write(f.read()) w.close() f.close() read_data(fname, "domains", domains) | ea210123cf99e19e452cf01342949f702e718584 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/ea210123cf99e19e452cf01342949f702e718584/bl2wc.py |
webbrowser.open(config_url) | webbrowser.open(url) | def open_browser (url): print _("Opening proxy configuration interface...") # the windows webbrowser.open func raises an exception for http:// # urls, but works nevertheless. Just ignore the error. try: webbrowser.open(config_url) except WindowsError, msg: print _("Could not open webbrowser: %r") % str(msg) | f94fbfa074359d0fba5a7f515afd4d800c3b6eaf /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/f94fbfa074359d0fba5a7f515afd4d800c3b6eaf/install-webcleaner.py |
scripts = ['webcleaner', 'webcleaner-certificates'] | def create_batch_file (self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | bd30da30bdd53933fa759d9ba107108ee6d7e0eb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/bd30da30bdd53933fa759d9ba107108ee6d7e0eb/setup.py |
|
scripts.append('webcleaner-service') | def create_batch_file (self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | bd30da30bdd53933fa759d9ba107108ee6d7e0eb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/bd30da30bdd53933fa759d9ba107108ee6d7e0eb/setup.py |
|
scripts = scripts, | scripts = ['webcleaner', 'webcleaner-certificates'], | def create_batch_file (self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | bd30da30bdd53933fa759d9ba107108ee6d7e0eb /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/bd30da30bdd53933fa759d9ba107108ee6d7e0eb/setup.py |
def filter (self, data, url): | def filter (self, data, url, rules): encoding = "UTF8" self.parser.encoding = encoding data = data.encode(encoding) self.rules = rules | def filter (self, data, url): self.url = url self.parser.feed(data) self.parser.flush() self.parser.reset() self.valid = True self.stack = [] data = self.outbuf.getvalue() self.outbuf.close() self.outbuf = StringIO() return data | a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407/RssHtmlFilter.py |
self.valid = True self.stack = [] | def filter (self, data, url): self.url = url self.parser.feed(data) self.parser.flush() self.parser.reset() self.valid = True self.stack = [] data = self.outbuf.getvalue() self.outbuf.close() self.outbuf = StringIO() return data | a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407/RssHtmlFilter.py |
|
self.outbuf = StringIO() | self.reset() | def filter (self, data, url): self.url = url self.parser.feed(data) self.parser.flush() self.parser.reset() self.valid = True self.stack = [] data = self.outbuf.getvalue() self.outbuf.close() self.outbuf = StringIO() return data | a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407/RssHtmlFilter.py |
tag = wc.filter.HtmlTags.check_spelling(tag, self.url) | tag = wc.filter.html.check_spelling(tag, self.url) | def _start_element (self, tag, attrs, startend): tag = wc.filter.HtmlTags.check_spelling(tag, self.url) self.stack.append(tag) if not self.valid: return if tag in rss_allowed: self.outbuf.write(u"<%s" % tag) if attrs: quote = wc.HtmlParser.htmllib.quote_attrval for attr in attrs: if attr in rss_allowed[tag]: val = attrs[attr] self.outbuf.write(u' %s="%s"' % (attr, quote(val))) if startend: self.outbuf.write(u"/>") else: self.outbuf.write(u">") elif not startend: self.valid = False self.stack = [tag] | a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/a7d64b9a3c3e6a8d17da2470e8d1a16a5f926407/RssHtmlFilter.py |
if err in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): | if err in (errno.EINPROGRESS, errno.EWOULDBLOCK): | def connect (self, addr): wc.log.debug(wc.LOG_PROXY, '%s connecting', self) self.connected = False err = self.socket.connect_ex(addr) if err != 0: strerr = errno.errorcode[err] wc.log.debug(wc.LOG_PROXY, '%s connection error %s', self, strerr) # XXX Should interpret Winsock return values if err in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): wc.proxy.make_timer(0.2, lambda a=addr: self.check_connect(addr)) elif err in (0, errno.EISCONN): self.addr = addr self.connected = True wc.log.debug(wc.LOG_PROXY, '%s connected', self) self.handle_connect() else: raise socket.error, (err, errno.errorcode[err]) return err | 85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b/Dispatcher.py |
See also http://cr.yp.to/docs/connect.html | See also http://cr.yp.to/docs/connect.html and connect(2) manpage. | def check_connect (self, addr): """ Check if the connection is etablished. See also http://cr.yp.to/docs/connect.html """ wc.log.debug(wc.LOG_PROXY, '%s check connect', self) err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if err == 0: self.addr = addr self.connected = True wc.log.debug(wc.LOG_PROXY, '%s connected', self) self.handle_connect() elif err in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): wc.proxy.make_timer(0.2, lambda a=addr: self.check_connect(addr)) else: self.handle_close() | 85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b/Dispatcher.py |
elif err in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): | elif err in (errno.EINPROGRESS, errno.EWOULDBLOCK): | def check_connect (self, addr): """ Check if the connection is etablished. See also http://cr.yp.to/docs/connect.html """ wc.log.debug(wc.LOG_PROXY, '%s check connect', self) err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if err == 0: self.addr = addr self.connected = True wc.log.debug(wc.LOG_PROXY, '%s connected', self) self.handle_connect() elif err in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): wc.proxy.make_timer(0.2, lambda a=addr: self.check_connect(addr)) else: self.handle_close() | 85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/85dbeb116b4d37d1b8b35f2a3b5ddeb3f4fac34b/Dispatcher.py |
return self.enclosed_ro.match(data) | return self.enclosed_ro.search(data) | def match_complete (self, pos, tagbuf): """ We know that the tag (and tag attributes) match. Now match the enclosing block. Return True on a match. """ if not self.enclosed: # no enclosed expression => match return True # put buf items together for matching items = tagbuf[pos:] data = wc.filter.html.tagbuf2data(items, StringIO()).getvalue() return self.enclosed_ro.match(data) | 7dd938cf2887c827895292966733d8e0500470da /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/7dd938cf2887c827895292966733d8e0500470da/HtmlrewriteRule.py |
data += "0000000000%d\r\n" % len(body) | data += "0000000000%s\r\n" % hex(self.body_length)[2:] | def do_GET (self): """send chunk data""" body = random_chars(self.body_length) data = 'HTTP/1.1 200 OK\r\n' data += "Date: %s\r\n" % self.date_time_string() data += "Transfer-Encoding: chunked\r\n" data += "Connection: close\r\n" data += "\r\n" data += "0000000000%d\r\n" % len(body) data += "%s\r\n" % body data += "0\r\n\r\n" self.server.log.write("server will send %d bytes\n" % len(data)) self.print_lines(data) self.wfile.write(data) | 8c928c4cff6d8d86f79d5f024b821246d9b4020b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/8c928c4cff6d8d86f79d5f024b821246d9b4020b/TestChunkedEncoding.py |
wc.proxy.make_timer(1, reload_config) | global pending_reload if not pending_reload: pending_reload = True wc.proxy.make_timer(1, reload_config) | def sighup_reload_config (signum, frame): """store timer for reloading configuration data""" wc.proxy.make_timer(1, reload_config) | 8ecb2c0b01971497ebdc1b9b0f7c0cf611eb483f /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/8ecb2c0b01971497ebdc1b9b0f7c0cf611eb483f/configuration.py |
p.debug(1) | def _main (args): """USAGE: test/run.sh test/parsefile.py test.html""" if len(args) < 1: print _main.__doc__ sys.exit(1) from wc.HtmlParser.htmllib import HtmlPrinter, HtmlPrettyPrinter if args[0] == "-p": klass = HtmlPrettyPrinter filename = args[1] else: klass = HtmlPrinter filename = args[0] if filename == '-': f = sys.stdin else: f = open(filename) from wc.HtmlParser import htmlsax p = htmlsax.parser(klass()) #p.debug(1) size = 1024 #size = 1 data = f.read(size) while data: p.feed(data) data = f.read(size) p.flush() | 0027f5525ab1582347585e15daf358926f5d68d3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/0027f5525ab1582347585e15daf358926f5d68d3/parsefile.py |
|
version = "0.51", | version = "0.52", | def create_batch_file(self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | afddd5dd8a0038b1afbf3aecb72e9530ebec3b27 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/afddd5dd8a0038b1afbf3aecb72e9530ebec3b27/setup.py |
('share/webcleaner/config/blacklists/audio-video', ['config/blacklists/audio-video/urls.gz', 'config/blacklists/audio-video/domains.gz']), ('share/webcleaner/config/blacklists/drugs', ['config/blacklists/drugs/urls.gz', 'config/blacklists/drugs/domains.gz']), ('share/webcleaner/config/blacklists/gambling', ['config/blacklists/gambling/urls.gz', 'config/blacklists/gambling/domains.gz']), ('share/webcleaner/config/blacklists/hacking', ['config/blacklists/hacking/urls.gz', 'config/blacklists/hacking/domains.gz']), ('share/webcleaner/config/blacklists/mail', ['config/blacklists/mail/domains.gz']), ('share/webcleaner/config/blacklists/porn', ['config/blacklists/porn/urls.gz', 'config/blacklists/porn/domains.gz']), ('share/webcleaner/config/blacklists/proxy', ['config/blacklists/proxy/urls.gz', 'config/blacklists/proxy/domains.gz']), | def create_batch_file(self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | afddd5dd8a0038b1afbf3aecb72e9530ebec3b27 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/afddd5dd8a0038b1afbf3aecb72e9530ebec3b27/setup.py |
|
['config/blacklists/violence/urls.gz', 'config/blacklists/violence/domains.gz']), ('share/webcleaner/config/blacklists/warez', ['config/blacklists/warez/urls.gz', 'config/blacklists/warez/domains.gz']), | ['config/blacklists/violence/domains.gz']), | def create_batch_file(self, directory, data, filename): filename = os.path.join(directory, filename) # write the batch file util.execute(write_file, (filename, data), "creating %s" % filename, self.verbose>=1, self.dry_run) | afddd5dd8a0038b1afbf3aecb72e9530ebec3b27 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/afddd5dd8a0038b1afbf3aecb72e9530ebec3b27/setup.py |
i = src.find('.') | i = src.rfind('.') | def scan_start_tag (self, tag, attrs, htmlfilter): if tag=="input" and attrs.has_key('type'): # prevent IE crash bug on empty type attribute if not attrs['type']: warn(FILTER, "%s\n Detected and prevented IE <input type> crash bug", str(htmlfilter)) del attrs['type'] elif tag=="fieldset" and attrs.has_key('style'): # prevent Mozilla crash bug on fieldsets if "position" in attrs['style']: warn(FILTER, "%s\n Detected and prevented Mozilla <fieldset style> crash bug", str(htmlfilter)) del attrs['style'] elif tag=="hr" and attrs.has_key('align'): # prevent CAN-2003-0469, length 50 should be safe if len(attrs['align']) > 50: warn(FILTER, "%s\n Detected and prevented IE <hr align> crash bug", str(htmlfilter)) del attrs['align'] elif tag=="object" and attrs.has_key('type'): # prevent CAN-2003-0344, only one / (slash) allowed t = attrs['type'] c = t.count("/") if c > 1: warn(FILTER, "%s\n Detected and prevented IE <object type> bug", str(htmlfilter)) t = t.replace("/", "", c-1) attrs['type'] = t elif tag=='table' and attrs.has_key('width'): # prevent CAN-2003-0238, table width=-1 crashes ICQ client if attrs['width']=='-1': warn(FILTER, "%s\n Detected and prevented ICQ table width crash bug", str(htmlfilter)) del attrs['width'] elif tag=='object' and attrs.has_key('codebase'): self.in_winhelp = attrs['codebase'].lower().startswith('hhctrl.ocx') elif tag=='param' and attrs.has_key('value') and self.in_winhelp: # prevent CVE-2002-0823 if len(attrs['value']) > 50: warn(FILTER, "%s\n Detected and prevented WinHlp overflow bug", str(htmlfilter)) del attrs['value'] elif tag=='meta' and attrs.has_key('content') and self.macintosh: # prevent CVE-2002-0153 if attrs.get('http-equiv', '').lower()=='refresh': url = attrs['content'].lower() if ";" in url: url = url.split(";", 1)[1] if url.startswith('url='): url = url[4:] if url.startswith('file:/'): warn(FILTER, "%s %s\n Detected and prevented local file redirection", str(htmlfilter), `attrs['content']`) del attrs['content'] elif tag=='embed' and attrs.has_key('src'): src = attrs['src'] if "." in src: # prevent CVE-2002-0022 i = src.find('.') if len(src[i:]) > 10: warn(FILTER, "%s %s\n Detected and prevented IE filename overflow crash", str(htmlfilter), `src`) del attrs['src'] elif tag=='font' and attrs.has_key('size'): if len(attrs['size']) > 10: # prevent CVE-2001-0130 warn(FILTER, "%s %s\n Detected and prevented Lotus Domino font size overflow crash", str(htmlfilter), `attrs['size']`) del attrs['size'] | 739a6c7412b347e19930646a0c5ace06b38dedbc /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/739a6c7412b347e19930646a0c5ace06b38dedbc/HtmlSecurity.py |
if not scanner.infected and data: | buf = attrs['virus_buf'] if data: | def filter (self, data, **attrs): if not attrs.has_key('scanner'): return data scanner = attrs['scanner'] if not scanner.infected and data: scanner.scan(data) if not scanner.infected: return data for msg in scanner.infected: warn(FILTER, "Found virus %r in %r", msg, attrs['url']) return "" | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
if not scanner.infected: return data for msg in scanner.infected: warn(FILTER, "Found virus %r in %r", msg, attrs['url']) | buf.write(data) | def filter (self, data, **attrs): if not attrs.has_key('scanner'): return data scanner = attrs['scanner'] if not scanner.infected and data: scanner.scan(data) if not scanner.infected: return data for msg in scanner.infected: warn(FILTER, "Found virus %r in %r", msg, attrs['url']) return "" | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
if not scanner.infected and data: | buf = attrs['virus_buf'] if data: | def finish (self, data, **attrs): if not attrs.has_key('scanner'): return data scanner = attrs['scanner'] if not scanner.infected and data: scanner.scan(data) scanner.close() for msg in scanner.errors: warn(FILTER, "Virus scanner error %r", msg) if not scanner.infected: return data for msg in scanner.infected: warn(FILTER, "Found virus %r in %r", msg, attrs['url']) return "" | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
d['scanner'] = ClamdScanner() | d['scanner'] = ClamdScanner(get_clamav_conf()) d['virus_buf'] = StringIO() | def getAttrs (self, url, headers): d = super(VirusFilter, self).getAttrs(url, headers) # weed out the rules that don't apply to this url rules = [ rule for rule in self.rules if rule.appliesTo(url) ] if not rules: return d d['scanner'] = ClamdScanner() return d | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
def __init__ (self): """initialize clamd daemon process connection""" | def __init__ (self, clamav_conf): """initialize clamd daemon process sockets""" | def __init__ (self): """initialize clamd daemon process connection""" self.infected = [] self.errors = [] self.sock, host = clamav_conf.new_connection() self.wsock = clamav_conf.new_scansock(self.sock, host) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
self.sock, host = clamav_conf.new_connection() self.wsock = clamav_conf.new_scansock(self.sock, host) | self.clamav_conf = clamav_conf self.sock, host = self.clamav_conf.new_connection() self.wsock = self.clamav_conf.new_scansock(self.sock, host) | def __init__ (self): """initialize clamd daemon process connection""" self.infected = [] self.errors = [] self.sock, host = clamav_conf.new_connection() self.wsock = clamav_conf.new_scansock(self.sock, host) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
"""scan given data for viruses, add results to infected and errors attributes""" | """scan given data for viruses""" | def scan (self, data): """scan given data for viruses, add results to infected and errors attributes""" self.wsock.sendall(data) data = self.sock.recv(RECV_BUFSIZE) while data: if "FOUND\n" in data: self.infected.append(data) if "ERROR\n" in data: self.errors.append(data) data = self.sock.recv(RECV_BUFSIZE) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
def close (self): """close clamd daemon connection""" | def scan (self, data): """scan given data for viruses, add results to infected and errors attributes""" self.wsock.sendall(data) data = self.sock.recv(RECV_BUFSIZE) while data: if "FOUND\n" in data: self.infected.append(data) if "ERROR\n" in data: self.errors.append(data) data = self.sock.recv(RECV_BUFSIZE) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
|
clamav_conf = None | _clamav_conf = None | def close (self): """close clamd daemon connection""" self.sock.close() | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
global clamav_conf | global _clamav_conf | def init_clamav_conf (): global clamav_conf from wc import config clamav_conf = ClamavConfig(config['clamavconf']) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
clamav_conf = ClamavConfig(config['clamavconf']) | _clamav_conf = ClamavConfig(config['clamavconf']) def get_clamav_conf (): return _clamav_conf | def init_clamav_conf (): global clamav_conf from wc import config clamav_conf = ClamavConfig(config['clamavconf']) | c1d07a5dae765cc144bb6ec68299de892bfde3ff /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/c1d07a5dae765cc144bb6ec68299de892bfde3ff/VirusFilter.py |
warndate = split_quoted_string(warning) | warndate, warning = split_quoted_string(warning) | def parse_http_warning (warning): """ Grammar for a warning: Warning = "Warning" ":" 1#warning-value warning-value = warn-code SP warn-agent SP warn-text [SP warn-date] warn-code = 3DIGIT warn-agent = ( host [ ":" port ] ) | pseudonym ; the name or pseudonym of the server adding ; the Warning header, for use in debugging warn-text = quoted-string warn-date = <"> HTTP-date <"> """ try: warncode, warning = warning.split(None, 1) warncode = int(warncode) warnagent, warning = warning.split(None, 1) warntext, warning = split_quoted_string(warning) if warning: warndate = split_quoted_string(warning) warndate = wc.http.date.parse_http_date(warndate) else: warndate = None except ValueError, OverflowError: return None return warncode, warnagent, warntext, warndate | d37315516802ca4f51749ab61aab4c86f0ed5afe /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/d37315516802ca4f51749ab61aab4c86f0ed5afe/__init__.py |
the win_cross_compiling flag""" | the win_compiling flag""" | def cnormpath (path): """norm a path name to platform specific notation, but honoring the win_cross_compiling flag""" path = normpath(path) if win_cross_compiling: # replace slashes with backslashes path = path.replace("/", "\\") return path | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if win_cross_compiling: | if win_compiling: | def cnormpath (path): """norm a path name to platform specific notation, but honoring the win_cross_compiling flag""" path = normpath(path) if win_cross_compiling: # replace slashes with backslashes path = path.replace("/", "\\") return path | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if win_cross_compiling and d in win_path_scheme: | if win_compiling and d in win_path_scheme: | def run (self): super(MyInstall, self).run() # we have to write a configuration file because we need the # <install_data> directory (and other stuff like author, url, ...) data = [] for d in ['purelib', 'platlib', 'lib', 'headers', 'scripts', 'data']: attr = 'install_%s'%d if self.root: # cut off root path prefix cutoff = len(self.root) # don't strip the path separator if self.root.endswith(os.sep): cutoff -= 1 val = getattr(self, attr)[cutoff:] else: val = getattr(self, attr) if win_cross_compiling and d in win_path_scheme: # look for placeholders to replace oldpath, newpath = win_path_scheme[d] oldpath = "/%s" % oldpath if oldpath in val: val = val.replace(oldpath, newpath) if attr=="install_data": base = os.path.join(val, 'share', 'webcleaner') data.append('config_dir = %r' % \ cnormpath(os.path.join(base, 'config'))) data.append('template_dir = %r' % \ cnormpath(os.path.join(base, 'templates'))) val = cnormpath(val) data.append("%s = %r" % (attr, val)) self.distribution.create_conf_file(data, directory=self.install_lib) | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
oldpath = "/%s" % oldpath | oldpath = "%s%s" % (os.sep, oldpath) | def run (self): super(MyInstall, self).run() # we have to write a configuration file because we need the # <install_data> directory (and other stuff like author, url, ...) data = [] for d in ['purelib', 'platlib', 'lib', 'headers', 'scripts', 'data']: attr = 'install_%s'%d if self.root: # cut off root path prefix cutoff = len(self.root) # don't strip the path separator if self.root.endswith(os.sep): cutoff -= 1 val = getattr(self, attr)[cutoff:] else: val = getattr(self, attr) if win_cross_compiling and d in win_path_scheme: # look for placeholders to replace oldpath, newpath = win_path_scheme[d] oldpath = "/%s" % oldpath if oldpath in val: val = val.replace(oldpath, newpath) if attr=="install_data": base = os.path.join(val, 'share', 'webcleaner') data.append('config_dir = %r' % \ cnormpath(os.path.join(base, 'config'))) data.append('template_dir = %r' % \ cnormpath(os.path.join(base, 'templates'))) val = cnormpath(val) data.append("%s = %r" % (attr, val)) self.distribution.create_conf_file(data, directory=self.install_lib) | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if (sys.platform != "win32" and not win_cross_compiling and | if (sys.platform != "win32" and not win_compiling and | def run (self): if (sys.platform != "win32" and not win_cross_compiling and (self.distribution.has_ext_modules() or self.distribution.has_c_libraries())): raise DistutilsPlatformError \ ("distribution contains extensions and/or C libraries; " "must be compiled on a Windows 32 platform") | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if win_cross_compiling: | if win_compiling: | def get_exe_bytes (self): if win_cross_compiling: # wininst.exe is in the same directory as bdist_wininst # XXX for python2.4, use wininst-X.Y.exe directory = os.path.dirname(distutils.command.__file__) filename = os.path.join(directory, "wininst.exe") return open(filename, "rb").read() return super(MyBdistWininst, self).get_exe_bytes() | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if win_cross_compiling: | if win_compiling: | def get_exe_bytes (self): if win_cross_compiling: # wininst.exe is in the same directory as bdist_wininst # XXX for python2.4, use wininst-X.Y.exe directory = os.path.dirname(distutils.command.__file__) filename = os.path.join(directory, "wininst.exe") return open(filename, "rb").read() return super(MyBdistWininst, self).get_exe_bytes() | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if os.name=='nt': extensions.append(Extension('wc.js.jslib', sources=['wc/js/jslib.c'], define_macros = [('WIN32', None), ('XP_WIN', None), ('EXPORT_JS_API', None)], include_dirs = include_dirs + ['libjs'], extra_compile_args = extra_compile_args, extra_objects = ['libjs/.libs/libjs.a'], library_dirs = library_dirs, libraries = libraries, )) | if win_compiling: define_macros = [('WIN32', None), ('XP_WIN', None), ('EXPORT_JS_API', None), ] | def get_exe_bytes (self): if win_cross_compiling: # wininst.exe is in the same directory as bdist_wininst # XXX for python2.4, use wininst-X.Y.exe directory = os.path.dirname(distutils.command.__file__) filename = os.path.join(directory, "wininst.exe") return open(filename, "rb").read() return super(MyBdistWininst, self).get_exe_bytes() | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if win_cross_compiling: define_macros = [('WIN32', None), ('XP_WIN', None), ('EXPORT_JS_API', None), ] else: define_macros = [] extensions.append(Extension('wc.js.jslib', sources=['wc/js/jslib.c'], include_dirs = include_dirs + ['libjs'], define_macros = define_macros, extra_compile_args = extra_compile_args, extra_objects = ['libjs/.libs/libjs.a'], library_dirs = library_dirs, libraries = libraries, )) | define_macros = [] extensions.append(Extension('wc.js.jslib', sources=['wc/js/jslib.c'], include_dirs = include_dirs + ['libjs'], define_macros = define_macros, extra_compile_args = extra_compile_args, extra_objects = ['libjs/.libs/libjs.a'], library_dirs = library_dirs, libraries = libraries, )) | def get_exe_bytes (self): if win_cross_compiling: # wininst.exe is in the same directory as bdist_wininst # XXX for python2.4, use wininst-X.Y.exe directory = os.path.dirname(distutils.command.__file__) filename = os.path.join(directory, "wininst.exe") return open(filename, "rb").read() return super(MyBdistWininst, self).get_exe_bytes() | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
if os.name=='nt' or win_cross_compiling: | if win_compiling: | def get_exe_bytes (self): if win_cross_compiling: # wininst.exe is in the same directory as bdist_wininst # XXX for python2.4, use wininst-X.Y.exe directory = os.path.dirname(distutils.command.__file__) filename = os.path.join(directory, "wininst.exe") return open(filename, "rb").read() return super(MyBdistWininst, self).get_exe_bytes() | 44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/44ccc6339c9b7b06a9beaa414a5ef9dd982bdb33/setup.py |
s += '\n '.join(asyncore.socket_map.values()) | s += '\n '.join(map(str, asyncore.socket_map.values())) | def text_status (): data = { 'uptime': format_seconds(time.time() - config['starttime']), 'valid': config['requests']['valid'], 'error': config['requests']['error'], 'blocked': config['requests']['blocked'], } s = STATUS_TEMPLATE % data s += '\n '.join(asyncore.socket_map.values()) s += ']\n\ndnscache: %s'%dns_lookups.dnscache return s | 751a0b59d658a7b7ad11b3f98d5c3fd31d4d64c5 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/751a0b59d658a7b7ad11b3f98d5c3fd31d4d64c5/__init__.py |
self._debug("self.outbuf %r", self.outbuf.getvalue()) self._debug("self.tagbuf %r", self.tagbuf) self._debug("self.waitbuf %r", self.waitbuf) self._debug("self.inbuf %r", self.inbuf.getvalue()) | debug(FILTER, "self.outbuf %r", self.outbuf.getvalue()) debug(FILTER, "self.tagbuf %r", self.tagbuf) debug(FILTER, "self.waitbuf %r", self.waitbuf) debug(FILTER, "self.inbuf %r", self.inbuf.getvalue()) | def _debugbuf (self): """print debugging information about data buffer status""" self._debug("self.outbuf %r", self.outbuf.getvalue()) self._debug("self.tagbuf %r", self.tagbuf) self._debug("self.waitbuf %r", self.waitbuf) self._debug("self.inbuf %r", self.inbuf.getvalue()) | 2fa8ed0461f00a71a3050e53a4866d6d407b1e52 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/3948/2fa8ed0461f00a71a3050e53a4866d6d407b1e52/HtmlParser.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.