removed all trailing spaces from blank lines

This commit is contained in:
Miroslav Stampar 2010-11-03 10:08:27 +00:00
parent 977df7276d
commit 6adee3792a
29 changed files with 121 additions and 122 deletions

View File

@ -1279,7 +1279,7 @@ class Control:
def get_labels(self): def get_labels(self):
"""Return all labels (Label instances) for this control. """Return all labels (Label instances) for this control.
If the control was surrounded by a <label> tag, that will be the first If the control was surrounded by a <label> tag, that will be the first
label; all other labels, connected by 'for' and 'id', are in the order label; all other labels, connected by 'for' and 'id', are in the order
that appear in the HTML. that appear in the HTML.
@ -1622,12 +1622,12 @@ class Item:
def get_labels(self): def get_labels(self):
"""Return all labels (Label instances) for this item. """Return all labels (Label instances) for this item.
For items that represent radio buttons or checkboxes, if the item was For items that represent radio buttons or checkboxes, if the item was
surrounded by a <label> tag, that will be the first label; all other surrounded by a <label> tag, that will be the first label; all other
labels, connected by 'for' and 'id', are in the order that appear in labels, connected by 'for' and 'id', are in the order that appear in
the HTML. the HTML.
For items that represent select options, if the option had a label For items that represent select options, if the option had a label
attribute, that will be the first label. If the option has contents attribute, that will be the first label. If the option has contents
(text within the option tags) and it is not the same as the label (text within the option tags) and it is not the same as the label
@ -1936,9 +1936,9 @@ class ListControl(Control):
def toggle_single(self, by_label=None): def toggle_single(self, by_label=None):
"""Deprecated: toggle the selection of the single item in this control. """Deprecated: toggle the selection of the single item in this control.
Raises ItemCountError if the control does not contain only one item. Raises ItemCountError if the control does not contain only one item.
by_label argument is ignored, and included only for backwards by_label argument is ignored, and included only for backwards
compatibility. compatibility.
@ -1953,9 +1953,9 @@ class ListControl(Control):
def set_single(self, selected, by_label=None): def set_single(self, selected, by_label=None):
"""Deprecated: set the selection of the single item in this control. """Deprecated: set the selection of the single item in this control.
Raises ItemCountError if the control does not contain only one item. Raises ItemCountError if the control does not contain only one item.
by_label argument is ignored, and included only for backwards by_label argument is ignored, and included only for backwards
compatibility. compatibility.
@ -2067,7 +2067,7 @@ class ListControl(Control):
# RFC 1866 if the _select_default attribute is set, and Netscape and IE # RFC 1866 if the _select_default attribute is set, and Netscape and IE
# otherwise. RFC 1866 and HTML 4 are always violated insofar as you # otherwise. RFC 1866 and HTML 4 are always violated insofar as you
# can deselect all items in a RadioControl. # can deselect all items in a RadioControl.
for o in self.items: for o in self.items:
# set items' controls to self, now that we've merged # set items' controls to self, now that we've merged
o.__dict__["_control"] = self o.__dict__["_control"] = self

View File

@ -56,7 +56,7 @@ def main():
except (OptionError, TypeError), e: except (OptionError, TypeError), e:
parser.error(e) parser.error(e)
if not os.path.isfile(args.inputFile): if not os.path.isfile(args.inputFile):
print 'ERROR: the provided input file \'%s\' is not a regular file' % args.inputFile print 'ERROR: the provided input file \'%s\' is not a regular file' % args.inputFile
sys.exit(1) sys.exit(1)

View File

@ -58,7 +58,7 @@ def convert(inputFile):
script += "w\nq\n" script += "w\nq\n"
return script return script
def main(inputFile, outputFile): def main(inputFile, outputFile):
if not os.path.isfile(inputFile): if not os.path.isfile(inputFile):
print "ERROR: the provided input file '%s' is not a regular file" % inputFile print "ERROR: the provided input file '%s' is not a regular file" % inputFile
@ -73,7 +73,7 @@ def main(inputFile, outputFile):
sys.stdout.close() sys.stdout.close()
else: else:
print script print script
if __name__ == "__main__": if __name__ == "__main__":
usage = "%s -i <input file> [-o <output file>]" % sys.argv[0] usage = "%s -i <input file> [-o <output file>]" % sys.argv[0]
parser = OptionParser(usage=usage, version="0.1") parser = OptionParser(usage=usage, version="0.1")

View File

@ -79,7 +79,7 @@ def ratio(numerator, denominator):
class UndefinedEvent(Exception): class UndefinedEvent(Exception):
"""Raised when attempting to get an event which is undefined.""" """Raised when attempting to get an event which is undefined."""
def __init__(self, event): def __init__(self, event):
Exception.__init__(self) Exception.__init__(self)
self.event = event self.event = event
@ -111,7 +111,7 @@ class Event(object):
assert val1 is not None assert val1 is not None
assert val2 is not None assert val2 is not None
return self._aggregator(val1, val2) return self._aggregator(val1, val2)
def format(self, val): def format(self, val):
"""Format an event value.""" """Format an event value."""
assert val is not None assert val is not None
@ -145,13 +145,13 @@ class Object(object):
def __contains__(self, event): def __contains__(self, event):
return event in self.events return event in self.events
def __getitem__(self, event): def __getitem__(self, event):
try: try:
return self.events[event] return self.events[event]
except KeyError: except KeyError:
raise UndefinedEvent(event) raise UndefinedEvent(event)
def __setitem__(self, event, value): def __setitem__(self, event, value):
if value is None: if value is None:
if event in self.events: if event in self.events:
@ -162,7 +162,7 @@ class Object(object):
class Call(Object): class Call(Object):
"""A call between functions. """A call between functions.
There should be at most one call object for every pair of functions. There should be at most one call object for every pair of functions.
""" """
@ -186,7 +186,7 @@ class Function(Object):
self.called = None self.called = None
self.weight = None self.weight = None
self.cycle = None self.cycle = None
def add_call(self, call): def add_call(self, call):
if call.callee_id in self.calls: if call.callee_id in self.calls:
sys.stderr.write('warning: overwriting call from function %s to %s\n' % (str(self.id), str(call.callee_id))) sys.stderr.write('warning: overwriting call from function %s to %s\n' % (str(self.id), str(call.callee_id)))
@ -261,7 +261,7 @@ class Profile(Object):
sys.stderr.write("Cycle:\n") sys.stderr.write("Cycle:\n")
for member in cycle.functions: for member in cycle.functions:
sys.stderr.write("\tFunction %s\n" % member.name) sys.stderr.write("\tFunction %s\n" % member.name)
def _tarjan(self, function, order, stack, orders, lowlinks, visited): def _tarjan(self, function, order, stack, orders, lowlinks, visited):
"""Tarjan's strongly connected components algorithm. """Tarjan's strongly connected components algorithm.
@ -365,7 +365,7 @@ class Profile(Object):
total += self._integrate_call(call, outevent, inevent) total += self._integrate_call(call, outevent, inevent)
function[outevent] = total function[outevent] = total
return function[outevent] return function[outevent]
def _integrate_call(self, call, outevent, inevent): def _integrate_call(self, call, outevent, inevent):
assert outevent not in call assert outevent not in call
assert call.ratio is not None assert call.ratio is not None
@ -387,7 +387,7 @@ class Profile(Object):
subtotal += self._integrate_call(call, outevent, inevent) subtotal += self._integrate_call(call, outevent, inevent)
total += subtotal total += subtotal
cycle[outevent] = total cycle[outevent] = total
# Compute the time propagated to callers of this cycle # Compute the time propagated to callers of this cycle
callees = {} callees = {}
for function in self.functions.itervalues(): for function in self.functions.itervalues():
@ -399,7 +399,7 @@ class Profile(Object):
callees[callee] += call.ratio callees[callee] += call.ratio
except KeyError: except KeyError:
callees[callee] = call.ratio callees[callee] = call.ratio
for member in cycle.functions: for member in cycle.functions:
member[outevent] = outevent.null() member[outevent] = outevent.null()
@ -521,7 +521,7 @@ class Profile(Object):
call = function.calls[callee_id] call = function.calls[callee_id]
if callee_id not in self.functions or call.weight is not None and call.weight < edge_thres: if callee_id not in self.functions or call.weight is not None and call.weight < edge_thres:
del function.calls[callee_id] del function.calls[callee_id]
def dump(self): def dump(self):
for function in self.functions.itervalues(): for function in self.functions.itervalues():
sys.stderr.write('Function %s:\n' % (function.name,)) sys.stderr.write('Function %s:\n' % (function.name,))
@ -548,7 +548,7 @@ class Struct:
if attrs is None: if attrs is None:
attrs = {} attrs = {}
self.__dict__['_attrs'] = attrs self.__dict__['_attrs'] = attrs
def __getattr__(self, name): def __getattr__(self, name):
try: try:
return self._attrs[name] return self._attrs[name]
@ -563,7 +563,7 @@ class Struct:
def __repr__(self): def __repr__(self):
return repr(self._attrs) return repr(self._attrs)
class ParseError(Exception): class ParseError(Exception):
"""Raised when parsing to signal mismatches.""" """Raised when parsing to signal mismatches."""
@ -586,7 +586,7 @@ class Parser:
def parse(self): def parse(self):
raise NotImplementedError raise NotImplementedError
class LineParser(Parser): class LineParser(Parser):
"""Base class for parsers that read line-based formats.""" """Base class for parsers that read line-based formats."""
@ -652,21 +652,21 @@ class XmlTokenizer:
self.index = 0 self.index = 0
self.final = False self.final = False
self.skip_ws = skip_ws self.skip_ws = skip_ws
self.character_pos = 0, 0 self.character_pos = 0, 0
self.character_data = '' self.character_data = ''
self.parser = xml.parsers.expat.ParserCreate() self.parser = xml.parsers.expat.ParserCreate()
self.parser.StartElementHandler = self.handle_element_start self.parser.StartElementHandler = self.handle_element_start
self.parser.EndElementHandler = self.handle_element_end self.parser.EndElementHandler = self.handle_element_end
self.parser.CharacterDataHandler = self.handle_character_data self.parser.CharacterDataHandler = self.handle_character_data
def handle_element_start(self, name, attributes): def handle_element_start(self, name, attributes):
self.finish_character_data() self.finish_character_data()
line, column = self.pos() line, column = self.pos()
token = XmlToken(XML_ELEMENT_START, name, attributes, line, column) token = XmlToken(XML_ELEMENT_START, name, attributes, line, column)
self.tokens.append(token) self.tokens.append(token)
def handle_element_end(self, name): def handle_element_end(self, name):
self.finish_character_data() self.finish_character_data()
line, column = self.pos() line, column = self.pos()
@ -677,7 +677,7 @@ class XmlTokenizer:
if not self.character_data: if not self.character_data:
self.character_pos = self.pos() self.character_pos = self.pos()
self.character_data += data self.character_data += data
def finish_character_data(self): def finish_character_data(self):
if self.character_data: if self.character_data:
if not self.skip_ws or not self.character_data.isspace(): if not self.skip_ws or not self.character_data.isspace():
@ -685,7 +685,7 @@ class XmlTokenizer:
token = XmlToken(XML_CHARACTER_DATA, self.character_data, None, line, column) token = XmlToken(XML_CHARACTER_DATA, self.character_data, None, line, column)
self.tokens.append(token) self.tokens.append(token)
self.character_data = '' self.character_data = ''
def next(self): def next(self):
size = 16*1024 size = 16*1024
while self.index >= len(self.tokens) and not self.final: while self.index >= len(self.tokens) and not self.final:
@ -730,13 +730,13 @@ class XmlParser(Parser):
Parser.__init__(self) Parser.__init__(self)
self.tokenizer = XmlTokenizer(fp) self.tokenizer = XmlTokenizer(fp)
self.consume() self.consume()
def consume(self): def consume(self):
self.token = self.tokenizer.next() self.token = self.tokenizer.next()
def match_element_start(self, name): def match_element_start(self, name):
return self.token.type == XML_ELEMENT_START and self.token.name_or_data == name return self.token.type == XML_ELEMENT_START and self.token.name_or_data == name
def match_element_end(self, name): def match_element_end(self, name):
return self.token.type == XML_ELEMENT_END and self.token.name_or_data == name return self.token.type == XML_ELEMENT_END and self.token.name_or_data == name
@ -750,7 +750,7 @@ class XmlParser(Parser):
attrs = self.token.attrs attrs = self.token.attrs
self.consume() self.consume()
return attrs return attrs
def element_end(self, name): def element_end(self, name):
while self.token.type == XML_CHARACTER_DATA: while self.token.type == XML_CHARACTER_DATA:
self.consume() self.consume()
@ -880,7 +880,7 @@ class GprofParser(Parser):
line = lines.pop(0) line = lines.pop(0)
if line.startswith('['): if line.startswith('['):
break break
# read function parent line # read function parent line
mo = self._cg_parent_re.match(line) mo = self._cg_parent_re.match(line)
if not mo: if not mo:
@ -901,7 +901,7 @@ class GprofParser(Parser):
while lines: while lines:
line = lines.pop(0) line = lines.pop(0)
# read function subroutine line # read function subroutine line
mo = self._cg_child_re.match(line) mo = self._cg_child_re.match(line)
if not mo: if not mo:
@ -911,7 +911,7 @@ class GprofParser(Parser):
else: else:
child = self.translate(mo) child = self.translate(mo)
children.append(child) children.append(child)
function.parents = parents function.parents = parents
function.children = children function.children = children
@ -936,7 +936,7 @@ class GprofParser(Parser):
continue continue
call = self.translate(mo) call = self.translate(mo)
cycle.functions.append(call) cycle.functions.append(call)
self.cycles[cycle.cycle] = cycle self.cycles[cycle.cycle] = cycle
def parse_cg_entry(self, lines): def parse_cg_entry(self, lines):
@ -965,14 +965,14 @@ class GprofParser(Parser):
else: else:
entry_lines.append(line) entry_lines.append(line)
line = self.readline() line = self.readline()
def parse(self): def parse(self):
self.parse_cg() self.parse_cg()
self.fp.close() self.fp.close()
profile = Profile() profile = Profile()
profile[TIME] = 0.0 profile[TIME] = 0.0
cycles = {} cycles = {}
for index in self.cycles.iterkeys(): for index in self.cycles.iterkeys():
cycles[index] = Cycle() cycles[index] = Cycle()
@ -987,11 +987,11 @@ class GprofParser(Parser):
call = Call(entry.index) call = Call(entry.index)
call[CALLS] = entry.called_self call[CALLS] = entry.called_self
function.called += entry.called_self function.called += entry.called_self
# populate the function calls # populate the function calls
for child in entry.children: for child in entry.children:
call = Call(child.index) call = Call(child.index)
assert child.called is not None assert child.called is not None
call[CALLS] = child.called call[CALLS] = child.called
@ -1034,7 +1034,7 @@ class GprofParser(Parser):
class CallgrindParser(LineParser): class CallgrindParser(LineParser):
"""Parser for valgrind's callgrind tool. """Parser for valgrind's callgrind tool.
See also: See also:
- http://valgrind.org/docs/manual/cl-format.html - http://valgrind.org/docs/manual/cl-format.html
""" """
@ -1171,7 +1171,7 @@ class CallgrindParser(LineParser):
else: else:
callee = self.get_callee() callee = self.get_callee()
callee.called += calls callee.called += calls
try: try:
call = function.calls[callee.id] call = function.calls[callee.id]
except KeyError: except KeyError:
@ -1319,7 +1319,7 @@ class CallgrindParser(LineParser):
class OprofileParser(LineParser): class OprofileParser(LineParser):
"""Parser for oprofile callgraph output. """Parser for oprofile callgraph output.
See also: See also:
- http://oprofile.sourceforge.net/doc/opreport.html#opreport-callgraph - http://oprofile.sourceforge.net/doc/opreport.html#opreport-callgraph
""" """
@ -1348,7 +1348,7 @@ class OprofileParser(LineParser):
self.update_subentries_dict(callers_total, callers) self.update_subentries_dict(callers_total, callers)
function_total.samples += function.samples function_total.samples += function.samples
self.update_subentries_dict(callees_total, callees) self.update_subentries_dict(callees_total, callees)
def update_subentries_dict(self, totals, partials): def update_subentries_dict(self, totals, partials):
for partial in partials.itervalues(): for partial in partials.itervalues():
try: try:
@ -1357,7 +1357,7 @@ class OprofileParser(LineParser):
totals[partial.id] = partial totals[partial.id] = partial
else: else:
total.samples += partial.samples total.samples += partial.samples
def parse(self): def parse(self):
# read lookahead # read lookahead
self.readline() self.readline()
@ -1369,7 +1369,7 @@ class OprofileParser(LineParser):
profile = Profile() profile = Profile()
reverse_call_samples = {} reverse_call_samples = {}
# populate the profile # populate the profile
profile[SAMPLES] = 0 profile[SAMPLES] = 0
for _callers, _function, _callees in self.entries.itervalues(): for _callers, _function, _callees in self.entries.itervalues():
@ -1392,7 +1392,7 @@ class OprofileParser(LineParser):
call = Call(_callee.id) call = Call(_callee.id)
call[SAMPLES2] = _callee.samples call[SAMPLES2] = _callee.samples
function.add_call(call) function.add_call(call)
# compute derived data # compute derived data
profile.validate() profile.validate()
profile.find_cycles() profile.find_cycles()
@ -1478,7 +1478,7 @@ class OprofileParser(LineParser):
def match_primary(self): def match_primary(self):
line = self.lookahead() line = self.lookahead()
return not line[:1].isspace() return not line[:1].isspace()
def match_secondary(self): def match_secondary(self):
line = self.lookahead() line = self.lookahead()
return line[:1].isspace() return line[:1].isspace()
@ -1546,7 +1546,7 @@ class SysprofParser(XmlParser):
def build_profile(self, objects, nodes): def build_profile(self, objects, nodes):
profile = Profile() profile = Profile()
profile[SAMPLES] = 0 profile[SAMPLES] = 0
for id, object in objects.iteritems(): for id, object in objects.iteritems():
# Ignore fake objects (process names, modules, "Everything", "kernel", etc.) # Ignore fake objects (process names, modules, "Everything", "kernel", etc.)
@ -1620,7 +1620,7 @@ class SharkParser(LineParser):
else: else:
function_total, callees_total = entry function_total, callees_total = entry
function_total.samples += function.samples function_total.samples += function.samples
def add_callee(self, function, callee): def add_callee(self, function, callee):
func, callees = self.entries[function.id] func, callees = self.entries[function.id]
try: try:
@ -1629,7 +1629,7 @@ class SharkParser(LineParser):
callees[callee.id] = callee callees[callee.id] = callee
else: else:
entry.samples += callee.samples entry.samples += callee.samples
def parse(self): def parse(self):
self.readline() self.readline()
self.readline() self.readline()
@ -1667,9 +1667,9 @@ class SharkParser(LineParser):
# if the callstack has had an entry, it's this functions caller # if the callstack has had an entry, it's this functions caller
if prefix > 0: if prefix > 0:
self.add_callee(self.stack[prefix - 1], entry) self.add_callee(self.stack[prefix - 1], entry)
self.add_entry(entry) self.add_entry(entry)
profile = Profile() profile = Profile()
profile[SAMPLES] = 0 profile[SAMPLES] = 0
for _function, _callees in self.entries.itervalues(): for _function, _callees in self.entries.itervalues():
@ -1685,7 +1685,7 @@ class SharkParser(LineParser):
call = Call(_callee.id) call = Call(_callee.id)
call[SAMPLES] = _callee.samples call[SAMPLES] = _callee.samples
function.add_call(call) function.add_call(call)
# compute derived data # compute derived data
profile.validate() profile.validate()
profile.find_cycles() profile.find_cycles()
@ -1723,7 +1723,7 @@ class XPerfParser(Parser):
self.parse_header(row) self.parse_header(row)
for row in it: for row in it:
self.parse_row(row) self.parse_row(row)
# compute derived data # compute derived data
self.profile.validate() self.profile.validate()
self.profile.find_cycles() self.profile.find_cycles()
@ -1751,7 +1751,7 @@ class XPerfParser(Parser):
else: else:
break break
fields[name] = value fields[name] = value
process = fields['Process Name'] process = fields['Process Name']
symbol = fields['Module'] + '!' + fields['Function'] symbol = fields['Module'] + '!' + fields['Function']
weight = fields['Weight'] weight = fields['Weight']
@ -1817,7 +1817,7 @@ class SleepyParser(Parser):
self.calls = {} self.calls = {}
self.profile = Profile() self.profile = Profile()
_symbol_re = re.compile( _symbol_re = re.compile(
r'^(?P<id>\w+)' + r'^(?P<id>\w+)' +
r'\s+"(?P<module>[^"]*)"' + r'\s+"(?P<module>[^"]*)"' +
@ -1832,7 +1832,7 @@ class SleepyParser(Parser):
mo = self._symbol_re.match(line) mo = self._symbol_re.match(line)
if mo: if mo:
symbol_id, module, procname, sourcefile, sourceline = mo.groups() symbol_id, module, procname, sourcefile, sourceline = mo.groups()
function_id = ':'.join([module, procname]) function_id = ':'.join([module, procname])
try: try:
@ -1858,7 +1858,7 @@ class SleepyParser(Parser):
callee[SAMPLES] += samples callee[SAMPLES] += samples
self.profile[SAMPLES] += samples self.profile[SAMPLES] += samples
for caller in callstack[1:]: for caller in callstack[1:]:
try: try:
call = caller.calls[callee.id] call = caller.calls[callee.id]
@ -2030,7 +2030,7 @@ class AQtimeParser(XmlParser):
profile[TOTAL_TIME] = profile[TIME] profile[TOTAL_TIME] = profile[TIME]
profile.ratio(TOTAL_TIME_RATIO, TOTAL_TIME) profile.ratio(TOTAL_TIME_RATIO, TOTAL_TIME)
return profile return profile
def build_function(self, fields): def build_function(self, fields):
function = Function(self.build_id(fields), self.build_name(fields)) function = Function(self.build_id(fields), self.build_name(fields))
function[TIME] = fields['Time'] function[TIME] = fields['Time']
@ -2187,10 +2187,10 @@ class Theme:
def color(self, weight): def color(self, weight):
weight = min(max(weight, 0.0), 1.0) weight = min(max(weight, 0.0), 1.0)
hmin, smin, lmin = self.mincolor hmin, smin, lmin = self.mincolor
hmax, smax, lmax = self.maxcolor hmax, smax, lmax = self.maxcolor
if self.skew < 0: if self.skew < 0:
raise ValueError("Skew must be greater than 0") raise ValueError("Skew must be greater than 0")
elif self.skew == 1.0: elif self.skew == 1.0:
@ -2488,7 +2488,7 @@ class Main:
self.theme = self.themes[self.options.theme] self.theme = self.themes[self.options.theme]
except KeyError: except KeyError:
parser.error('invalid colormap \'%s\'' % self.options.theme) parser.error('invalid colormap \'%s\'' % self.options.theme)
# set skew on the theme now that it has been picked. # set skew on the theme now that it has been picked.
if self.options.theme_skew: if self.options.theme_skew:
self.theme.skew = self.options.theme_skew self.theme.skew = self.options.theme_skew
@ -2547,7 +2547,7 @@ class Main:
parser.error('invalid format \'%s\'' % self.options.format) parser.error('invalid format \'%s\'' % self.options.format)
self.profile = parser.parse() self.profile = parser.parse()
if self.options.output is None: if self.options.output is None:
self.output = sys.stdout self.output = sys.stdout
else: else:

View File

@ -23,7 +23,7 @@
keepalive_handler = HTTPHandler() keepalive_handler = HTTPHandler()
opener = urllib2.build_opener(keepalive_handler) opener = urllib2.build_opener(keepalive_handler)
urllib2.install_opener(opener) urllib2.install_opener(opener)
fo = urllib2.urlopen('http://www.python.org') fo = urllib2.urlopen('http://www.python.org')
To remove the handler, simply re-run build_opener with no arguments, and To remove the handler, simply re-run build_opener with no arguments, and
@ -84,7 +84,7 @@ HANDLE_ERRORS = 1
class HTTPHandler(urllib2.HTTPHandler): class HTTPHandler(urllib2.HTTPHandler):
def __init__(self): def __init__(self):
self._connections = {} self._connections = {}
def close_connection(self, host): def close_connection(self, host):
"""close connection to <host> """close connection to <host>
host is the host:port spec, as in 'www.cnn.com:8080' as passed in. host is the host:port spec, as in 'www.cnn.com:8080' as passed in.
@ -105,16 +105,16 @@ class HTTPHandler(urllib2.HTTPHandler):
for _, conn in self._connections.items(): for _, conn in self._connections.items():
conn.close() conn.close()
self._connections = {} self._connections = {}
def _remove_connection(self, host, close=0): def _remove_connection(self, host, close=0):
key = self._get_connection_key(host) key = self._get_connection_key(host)
if self._connections.has_key(key): if self._connections.has_key(key):
if close: self._connections[key].close() if close: self._connections[key].close()
del self._connections[key] del self._connections[key]
def _get_connection_key(self, host): def _get_connection_key(self, host):
return (threading.currentThread(), host) return (threading.currentThread(), host)
def _start_connection(self, h, req): def _start_connection(self, h, req):
h.clearheaders() h.clearheaders()
try: try:
@ -160,7 +160,7 @@ class HTTPHandler(urllib2.HTTPHandler):
else: else:
try: r = h.getresponse() try: r = h.getresponse()
except httplib.ResponseNotReady, e: r = None except httplib.ResponseNotReady, e: r = None
if r is None or r.version == 9: if r is None or r.version == 9:
# httplib falls back to assuming HTTP 0.9 if it gets a # httplib falls back to assuming HTTP 0.9 if it gets a
# bad header back. This is most likely to happen if # bad header back. This is most likely to happen if
@ -180,7 +180,7 @@ class HTTPHandler(urllib2.HTTPHandler):
except socket.error, err: except socket.error, err:
if h: h.close() if h: h.close()
raise urllib2.URLError(err) raise urllib2.URLError(err)
# if not a persistent connection, don't try to reuse it # if not a persistent connection, don't try to reuse it
if r.will_close: self._remove_connection(host) if r.will_close: self._remove_connection(host)
@ -225,7 +225,7 @@ class HTTPResponse(httplib.HTTPResponse):
# although read() never adds to the buffer. # although read() never adds to the buffer.
# Both readline and readlines have been stolen with almost no # Both readline and readlines have been stolen with almost no
# modification from socket.py # modification from socket.py
def __init__(self, sock, debuglevel=0, strict=0, method=None): def __init__(self, sock, debuglevel=0, strict=0, method=None):
if method: # the httplib in python 2.3 uses the method arg if method: # the httplib in python 2.3 uses the method arg
@ -244,7 +244,7 @@ class HTTPResponse(httplib.HTTPResponse):
def close_connection(self): def close_connection(self):
self.close() self.close()
self._handler._remove_connection(self._host, close=1) self._handler._remove_connection(self._host, close=1)
def info(self): def info(self):
return self.msg return self.msg
@ -367,7 +367,7 @@ def error_handler(url):
def continuity(url): def continuity(url):
import md5 import md5
format = '%25s: %s' format = '%25s: %s'
# first fetch the file with the normal http handler # first fetch the file with the normal http handler
opener = urllib2.build_opener() opener = urllib2.build_opener()
urllib2.install_opener(opener) urllib2.install_opener(opener)
@ -414,7 +414,7 @@ def comp(N, url):
t2 = fetch(N, url) t2 = fetch(N, url)
print ' TIME: %.3f s' % t2 print ' TIME: %.3f s' % t2
print ' improvement factor: %.2f' % (t1/t2, ) print ' improvement factor: %.2f' % (t1/t2, )
def fetch(N, url, delay=0): def fetch(N, url, delay=0):
lens = [] lens = []
starttime = time.time() starttime = time.time()
@ -446,7 +446,7 @@ def test(url, N=10):
print print
print "performing speed comparison" print "performing speed comparison"
comp(N, url) comp(N, url)
if __name__ == '__main__': if __name__ == '__main__':
import time import time
import sys import sys

View File

@ -42,7 +42,7 @@ def _patch_minidom():
minidom.Text.writexml = _writexml_text minidom.Text.writexml = _writexml_text
minidom.Element.writexml = _writexml_element minidom.Element.writexml = _writexml_element
minidom.Node.toprettyxml = _toprettyxml_node minidom.Node.toprettyxml = _toprettyxml_node
def _collapse(node): def _collapse(node):
for child in node.childNodes: for child in node.childNodes:
if child.nodeType == Node.TEXT_NODE and len(child.data.strip()) == 0: if child.nodeType == Node.TEXT_NODE and len(child.data.strip()) == 0:
@ -52,17 +52,17 @@ def _collapse(node):
def _writexml_text(self, writer, indent="", addindent="", newl=""): def _writexml_text(self, writer, indent="", addindent="", newl=""):
minidom._write_data(writer, "%s"%(self.data.strip())) minidom._write_data(writer, "%s"%(self.data.strip()))
def _writexml_element(self, writer, indent="", addindent="", newl=""): def _writexml_element(self, writer, indent="", addindent="", newl=""):
# indent = current indentation # indent = current indentation
# addindent = indentation to add to higher levels # addindent = indentation to add to higher levels
# newl = newline string # newl = newline string
writer.write(indent+"<" + self.tagName) writer.write(indent+"<" + self.tagName)
attrs = self._get_attributes() attrs = self._get_attributes()
a_names = attrs.keys() a_names = attrs.keys()
a_names.sort() a_names.sort()
for a_name in a_names: for a_name in a_names:
writer.write(" %s=\"" % a_name) writer.write(" %s=\"" % a_name)
minidom._write_data(writer, attrs[a_name].value) minidom._write_data(writer, attrs[a_name].value)
@ -80,7 +80,7 @@ def _writexml_element(self, writer, indent="", addindent="", newl=""):
writer.write("%s</%s>%s" % (indent,self.tagName,newl)) writer.write("%s</%s>%s" % (indent,self.tagName,newl))
else: else:
writer.write("/>%s"%(newl)) writer.write("/>%s"%(newl))
def _toprettyxml_node(self, indent="\t", newl="\n", encoding = None): def _toprettyxml_node(self, indent="\t", newl="\n", encoding = None):
_collapse(self) _collapse(self)
# indent = the indentation string to prepend, per level # indent = the indentation string to prepend, per level

View File

@ -453,7 +453,7 @@ class XDotAttrParser:
self.parser = parser self.parser = parser
self.buf = self.unescape(buf) self.buf = self.unescape(buf)
self.pos = 0 self.pos = 0
self.pen = Pen() self.pen = Pen()
self.shapes = [] self.shapes = []
@ -549,7 +549,7 @@ class XDotAttrParser:
b = b*s b = b*s
a = 1.0 a = 1.0
return r, g, b, a return r, g, b, a
sys.stderr.write("unknown color '%s'\n" % c) sys.stderr.write("unknown color '%s'\n" % c)
return None return None
@ -615,7 +615,7 @@ class XDotAttrParser:
break break
return self.shapes return self.shapes
def transform(self, x, y): def transform(self, x, y):
return self.parser.transform(x, y) return self.parser.transform(x, y)
@ -677,7 +677,7 @@ class ParseError(Exception):
def __str__(self): def __str__(self):
return ':'.join([str(part) for part in (self.filename, self.line, self.col, self.msg) if part != None]) return ':'.join([str(part) for part in (self.filename, self.line, self.col, self.msg) if part != None])
class Scanner: class Scanner:
"""Stateless scanner.""" """Stateless scanner."""
@ -921,7 +921,7 @@ class DotLexer(Lexer):
text = text.replace('\\\r\n', '') text = text.replace('\\\r\n', '')
text = text.replace('\\\r', '') text = text.replace('\\\r', '')
text = text.replace('\\\n', '') text = text.replace('\\\n', '')
text = text.replace('\\r', '\r') text = text.replace('\\r', '\r')
text = text.replace('\\n', '\n') text = text.replace('\\n', '\n')
text = text.replace('\\t', '\t') text = text.replace('\\t', '\t')
@ -1062,7 +1062,7 @@ class XDotParser(DotParser):
def __init__(self, xdotcode): def __init__(self, xdotcode):
lexer = DotLexer(buf = xdotcode) lexer = DotLexer(buf = xdotcode)
DotParser.__init__(self, lexer) DotParser.__init__(self, lexer)
self.nodes = [] self.nodes = []
self.edges = [] self.edges = []
self.shapes = [] self.shapes = []
@ -1091,7 +1091,7 @@ class XDotParser(DotParser):
self.height = ymax - ymin self.height = ymax - ymin
self.top_graph = False self.top_graph = False
for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"): for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"):
if attr in attrs: if attr in attrs:
parser = XDotAttrParser(self, attrs[attr]) parser = XDotAttrParser(self, attrs[attr])
@ -1122,7 +1122,7 @@ class XDotParser(DotParser):
pos = attrs['pos'] pos = attrs['pos']
except KeyError: except KeyError:
return return
points = self.parse_edge_pos(pos) points = self.parse_edge_pos(pos)
shapes = [] shapes = []
for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"): for attr in ("_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_"):

View File

@ -21,7 +21,7 @@ class MagicException(Exception): pass
class Magic: class Magic:
""" """
Magic is a wrapper around the libmagic C library. Magic is a wrapper around the libmagic C library.
""" """
def __init__(self, mime=False, magic_file=None): def __init__(self, mime=False, magic_file=None):
@ -30,12 +30,12 @@ class Magic:
mime - if True, mimetypes are returned instead of textual descriptions mime - if True, mimetypes are returned instead of textual descriptions
magic_file - use a mime database other than the system default magic_file - use a mime database other than the system default
""" """
flags = MAGIC_NONE flags = MAGIC_NONE
if mime: if mime:
flags |= MAGIC_MIME flags |= MAGIC_MIME
self.cookie = magic_open(flags) self.cookie = magic_open(flags)
magic_load(self.cookie, magic_file) magic_load(self.cookie, magic_file)
@ -54,7 +54,7 @@ class Magic:
if not os.path.exists(filename): if not os.path.exists(filename):
raise IOError("File does not exist: " + filename) raise IOError("File does not exist: " + filename)
return magic_file(self.cookie, filename) return magic_file(self.cookie, filename)
def __del__(self): def __del__(self):

View File

@ -47,11 +47,11 @@ class MultipartPostHandler(urllib2.BaseHandler):
def http_request(self, request): def http_request(self, request):
data = request.get_data() data = request.get_data()
if data is not None and type(data) != str: if data is not None and type(data) != str:
v_files = [] v_files = []
v_vars = [] v_vars = []
try: try:
for(key, value) in data.items(): for(key, value) in data.items():
if type(value) == file or hasattr(value, 'file'): if type(value) == file or hasattr(value, 'file'):

View File

@ -311,5 +311,5 @@ def start():
if conf.loggedToOut: if conf.loggedToOut:
logger.info("Fetched data logged to text files under '%s'" % conf.outputPath) logger.info("Fetched data logged to text files under '%s'" % conf.outputPath)
return True return True

View File

@ -313,7 +313,7 @@ class Agent:
fieldsToCastStr = fieldsSelect.groups()[0] fieldsToCastStr = fieldsSelect.groups()[0]
elif fieldsNoSelect: elif fieldsNoSelect:
fieldsToCastStr = fieldsNoSelect fieldsToCastStr = fieldsNoSelect
if re.search("\A\w+\(.*\)", fieldsToCastStr, re.I): #function if re.search("\A\w+\(.*\)", fieldsToCastStr, re.I): #function
fieldsToCastList = [fieldsToCastStr] fieldsToCastList = [fieldsToCastStr]
else: else:
@ -531,7 +531,7 @@ class Agent:
if kb.dbms in ( DBMS.MYSQL, DBMS.POSTGRESQL, DBMS.SQLITE ): if kb.dbms in ( DBMS.MYSQL, DBMS.POSTGRESQL, DBMS.SQLITE ):
limitStr = queries[kb.dbms].limit.query % (num, 1) limitStr = queries[kb.dbms].limit.query % (num, 1)
limitedQuery += " %s" % limitStr limitedQuery += " %s" % limitStr
elif kb.dbms == DBMS.FIREBIRD: elif kb.dbms == DBMS.FIREBIRD:
limitStr = queries[kb.dbms].limit.query % (num+1, num+1) limitStr = queries[kb.dbms].limit.query % (num+1, num+1)
limitedQuery += " %s" % limitStr limitedQuery += " %s" % limitStr

View File

@ -1256,7 +1256,7 @@ def readCachedFileContent(filename, mode='rb'):
xfile.close() xfile.close()
kb.locks.cacheLock.release() kb.locks.cacheLock.release()
return kb.cache.content[filename] return kb.cache.content[filename]
def readXmlFile(xmlFile): def readXmlFile(xmlFile):

View File

@ -39,7 +39,7 @@ def hexdecode(string):
string = string[2:] string = string[2:]
return string.decode("hex") return string.decode("hex")
def hexencode(string): def hexencode(string):
return string.encode("hex") return string.encode("hex")

View File

@ -611,7 +611,7 @@ def __setHTTPProxy():
errMsg = "Proxy authentication credentials " errMsg = "Proxy authentication credentials "
errMsg += "value must be in format username:password" errMsg += "value must be in format username:password"
raise sqlmapSyntaxException, errMsg raise sqlmapSyntaxException, errMsg
# Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
__proxyString = "%s@" % conf.pCred __proxyString = "%s@" % conf.pCred

View File

@ -89,4 +89,3 @@ class Replication:
def __del__(self): def __del__(self):
self.cursor.close() self.cursor.close()
self.connection.close() self.connection.close()

View File

@ -180,13 +180,13 @@ def __setOutputResume():
continue continue
url, _, _, expression, value = line url, _, _, expression, value = line
if not value: if not value:
continue continue
if url[0] == "[": if url[0] == "[":
url = url[1:] url = url[1:]
value = value.rstrip('\r\n') # Strips both chars independently value = value.rstrip('\r\n') # Strips both chars independently
if url not in ( conf.url, conf.hostname ): if url not in ( conf.url, conf.hostname ):
@ -197,9 +197,9 @@ def __setOutputResume():
kb.resumedQueries[url][expression] = value kb.resumedQueries[url][expression] = value
__url_cache.add(url) __url_cache.add(url)
__expression_cache[url] = set(expression) __expression_cache[url] = set(expression)
resumeConfKb(expression, url, value) resumeConfKb(expression, url, value)
if expression not in __expression_cache[url]: if expression not in __expression_cache[url]:
kb.resumedQueries[url][expression] = value kb.resumedQueries[url][expression] = value
__expression_cache[url].add(value) __expression_cache[url].add(value)

View File

@ -116,7 +116,7 @@ def decodePage(page, contentEncoding, contentType):
data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(page)) data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(page))
page = data.read() page = data.read()
#http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode #http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode
if contentType and (contentType.find('charset=') != -1): if contentType and (contentType.find('charset=') != -1):
charset = checkCharEncoding(contentType.split('charset=')[-1]) charset = checkCharEncoding(contentType.split('charset=')[-1])

View File

@ -69,7 +69,7 @@ class Abstraction(Web, UDF, xp_cmdshell):
message = "do you want to retrieve the command standard " message = "do you want to retrieve the command standard "
message += "output? [Y/n/a] " message += "output? [Y/n/a] "
getOutput = readInput(message, default="Y") getOutput = readInput(message, default="Y")
if getOutput in ("a", "A"): if getOutput in ("a", "A"):
self.alwaysRetrieveCmdOutput = True self.alwaysRetrieveCmdOutput = True

View File

@ -80,7 +80,7 @@ class Registry:
logger.debug("reading registry key '%s' value '%s'" % (regKey, regValue)) logger.debug("reading registry key '%s' value '%s'" % (regKey, regValue))
data = self.evalCmd(self.__batPathRemote) data = self.evalCmd(self.__batPathRemote)
if data and not parse: if data and not parse:
pattern = ' ' pattern = ' '
index = data.find(pattern) index = data.find(pattern)

View File

@ -60,7 +60,7 @@ class UPX:
logger.debug("executing local command: %s" % self.__upxCmd) logger.debug("executing local command: %s" % self.__upxCmd)
process = execute(self.__upxCmd, shell=True, stdout=PIPE, stderr=STDOUT) process = execute(self.__upxCmd, shell=True, stdout=PIPE, stderr=STDOUT)
dataToStdout("\r[%s] [INFO] compression in progress " % time.strftime("%X")) dataToStdout("\r[%s] [INFO] compression in progress " % time.strftime("%X"))
pollProcess(process) pollProcess(process)
upxStdout, upxStderr = process.communicate() upxStdout, upxStderr = process.communicate()

View File

@ -236,7 +236,7 @@ class Web:
self.webBackdoorUrl = "%s/%s" % (self.webBaseUrl, backdoorName) self.webBackdoorUrl = "%s/%s" % (self.webBaseUrl, backdoorName)
self.webDirectory = directory self.webDirectory = directory
infoMsg = "the backdoor has probably been successfully " infoMsg = "the backdoor has probably been successfully "
infoMsg += "uploaded on '%s', go with your browser " % self.webDirectory infoMsg += "uploaded on '%s', go with your browser " % self.webDirectory
infoMsg += "to '%s' and enjoy it!" % self.webBackdoorUrl infoMsg += "to '%s' and enjoy it!" % self.webBackdoorUrl

View File

@ -22,7 +22,7 @@ class _Getch:
self.impl = _GetchUnix() self.impl = _GetchUnix()
def __call__(self): return self.impl() def __call__(self): return self.impl()
class _GetchUnix: class _GetchUnix:
def __init__(self): def __init__(self):

View File

@ -21,7 +21,7 @@ class Enumeration(GenericEnumeration):
logger.warn(warnMsg) logger.warn(warnMsg)
return [] return []
def getPasswordHashes(self): def getPasswordHashes(self):
warnMsg = "on Firebird it is not possible to enumerate the user password hashes" warnMsg = "on Firebird it is not possible to enumerate the user password hashes"
logger.warn(warnMsg) logger.warn(warnMsg)

View File

@ -138,7 +138,7 @@ class Fingerprint(GenericFingerprint):
if not conf.extensiveFp: if not conf.extensiveFp:
return True return True
kb.dbmsVersion = [self.__sysTablesCheck()] kb.dbmsVersion = [self.__sysTablesCheck()]
return True return True

View File

@ -16,7 +16,7 @@ from plugins.generic.enumeration import Enumeration as GenericEnumeration
class Enumeration(GenericEnumeration): class Enumeration(GenericEnumeration):
def __init__(self): def __init__(self):
GenericEnumeration.__init__(self, DBMS.MAXDB) GenericEnumeration.__init__(self, DBMS.MAXDB)
kb.data.processChar = lambda x: x.replace('_', ' ') if x else x kb.data.processChar = lambda x: x.replace('_', ' ') if x else x
def getDbs(self): def getDbs(self):

View File

@ -251,7 +251,7 @@ class Fingerprint(GenericFingerprint):
logger.warn(warnMsg) logger.warn(warnMsg)
return False return False
def checkDbmsOs(self, detailed=False): def checkDbmsOs(self, detailed=False):
if kb.os: if kb.os:
return return

View File

@ -101,7 +101,7 @@ class Fingerprint(GenericFingerprint):
if not conf.extensiveFp: if not conf.extensiveFp:
return True return True
for version in range(12, 16): for version in range(12, 16):
randInt = randomInt() randInt = randomInt()
query = " AND @@VERSION_NUMBER/1000=%d" % version query = " AND @@VERSION_NUMBER/1000=%d" % version

View File

@ -34,7 +34,7 @@ class Connector:
infoMsg = "connection to %s server %s" % (conf.dbms, self.hostname) infoMsg = "connection to %s server %s" % (conf.dbms, self.hostname)
infoMsg += ":%d established" % self.port infoMsg += ":%d established" % self.port
logger.info(infoMsg) logger.info(infoMsg)
def closed(self): def closed(self):
infoMsg = "connection to %s server %s" % (conf.dbms, self.hostname) infoMsg = "connection to %s server %s" % (conf.dbms, self.hostname)
infoMsg += ":%d closed" % self.port infoMsg += ":%d closed" % self.port

View File

@ -900,7 +900,7 @@ class Enumeration:
logger.warn(warnMsg) logger.warn(warnMsg)
conf.db = self.getCurrentDb() conf.db = self.getCurrentDb()
firebirdTypes = { firebirdTypes = {
"261":"BLOB", "261":"BLOB",
"14":"CHAR", "14":"CHAR",