mirror of https://github.com/scrapy/scrapy.git
Python 3 compatible syntax: print, except, raise, octal numbers; removed Python 2.2 boolean compatibility code in xlib/pydispatch/dispatcher.py
This commit is contained in:
parent
2e8cc281b0
commit
d381a35732
|
|
@ -29,9 +29,9 @@ def get_commands():
|
|||
|
||||
def cmd_help(args, opts):
|
||||
"""help - list available commands"""
|
||||
print "Available commands:"
|
||||
print("Available commands:")
|
||||
for _, func in sorted(get_commands().items()):
|
||||
print " ", func.__doc__
|
||||
print(" ", func.__doc__)
|
||||
|
||||
def cmd_stop(args, opts):
|
||||
"""stop <spider> - stop a running spider"""
|
||||
|
|
@ -40,29 +40,29 @@ def cmd_stop(args, opts):
|
|||
def cmd_list_running(args, opts):
|
||||
"""list-running - list running spiders"""
|
||||
for x in json_get(opts, 'crawler/engine/open_spiders'):
|
||||
print x
|
||||
print(x)
|
||||
|
||||
def cmd_list_available(args, opts):
|
||||
"""list-available - list name of available spiders"""
|
||||
for x in jsonrpc_call(opts, 'crawler/spiders', 'list'):
|
||||
print x
|
||||
print(x)
|
||||
|
||||
def cmd_list_resources(args, opts):
|
||||
"""list-resources - list available web service resources"""
|
||||
for x in json_get(opts, '')['resources']:
|
||||
print x
|
||||
print(x)
|
||||
|
||||
def cmd_get_spider_stats(args, opts):
|
||||
"""get-spider-stats <spider> - get stats of a running spider"""
|
||||
stats = jsonrpc_call(opts, 'stats', 'get_stats', args[0])
|
||||
for name, value in stats.items():
|
||||
print "%-40s %s" % (name, value)
|
||||
print("%-40s %s" % (name, value))
|
||||
|
||||
def cmd_get_global_stats(args, opts):
|
||||
"""get-global-stats - get global stats"""
|
||||
stats = jsonrpc_call(opts, 'stats', 'get_stats')
|
||||
for name, value in stats.items():
|
||||
print "%-40s %s" % (name, value)
|
||||
print("%-40s %s" % (name, value))
|
||||
|
||||
def get_wsurl(opts, path):
|
||||
return urljoin("http://%s:%s/"% (opts.host, opts.port), path)
|
||||
|
|
@ -101,12 +101,12 @@ def main():
|
|||
try:
|
||||
cmd(args, opts)
|
||||
except IndexError:
|
||||
print cmd.__doc__
|
||||
except JsonRpcError, e:
|
||||
print str(e)
|
||||
print(cmd.__doc__)
|
||||
except JsonRpcError as e:
|
||||
print(str(e))
|
||||
if e.data:
|
||||
print "Server Traceback below:"
|
||||
print e.data
|
||||
print("Server Traceback below:")
|
||||
print(e.data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ version_info = tuple(__version__.split('.')[:3])
|
|||
import sys, os, warnings
|
||||
|
||||
if sys.version_info < (2, 6):
|
||||
print "Scrapy %s requires Python 2.6 or above" % __version__
|
||||
print("Scrapy %s requires Python 2.6 or above" % __version__)
|
||||
sys.exit(1)
|
||||
|
||||
# ignore noisy twisted deprecation warnings
|
||||
|
|
|
|||
|
|
@ -59,34 +59,34 @@ def _pop_command_name(argv):
|
|||
|
||||
def _print_header(settings, inproject):
|
||||
if inproject:
|
||||
print "Scrapy %s - project: %s\n" % (scrapy.__version__, \
|
||||
settings['BOT_NAME'])
|
||||
print("Scrapy %s - project: %s\n" % (scrapy.__version__, \
|
||||
settings['BOT_NAME']))
|
||||
else:
|
||||
print "Scrapy %s - no active project\n" % scrapy.__version__
|
||||
print("Scrapy %s - no active project\n" % scrapy.__version__)
|
||||
|
||||
def _print_commands(settings, inproject):
|
||||
_print_header(settings, inproject)
|
||||
print "Usage:"
|
||||
print " scrapy <command> [options] [args]\n"
|
||||
print "Available commands:"
|
||||
print("Usage:")
|
||||
print(" scrapy <command> [options] [args]\n")
|
||||
print("Available commands:")
|
||||
cmds = _get_commands_dict(settings, inproject)
|
||||
for cmdname, cmdclass in sorted(cmds.iteritems()):
|
||||
print " %-13s %s" % (cmdname, cmdclass.short_desc())
|
||||
print(" %-13s %s" % (cmdname, cmdclass.short_desc()))
|
||||
if not inproject:
|
||||
print
|
||||
print " [ more ] More commands available when run from project directory"
|
||||
print
|
||||
print 'Use "scrapy <command> -h" to see more info about a command'
|
||||
print()
|
||||
print(" [ more ] More commands available when run from project directory")
|
||||
print()
|
||||
print('Use "scrapy <command> -h" to see more info about a command')
|
||||
|
||||
def _print_unknown_command(settings, cmdname, inproject):
|
||||
_print_header(settings, inproject)
|
||||
print "Unknown command: %s\n" % cmdname
|
||||
print 'Use "scrapy" to see available commands'
|
||||
print("Unknown command: %s\n" % cmdname)
|
||||
print('Use "scrapy" to see available commands')
|
||||
|
||||
def _run_print_help(parser, func, *a, **kw):
|
||||
try:
|
||||
func(*a, **kw)
|
||||
except UsageError, e:
|
||||
except UsageError as e:
|
||||
if str(e):
|
||||
parser.error(str(e))
|
||||
if e.print_help:
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ class Command(ScrapyCommand):
|
|||
# start checks
|
||||
if opts.list:
|
||||
for spider, methods in sorted(contract_reqs.iteritems()):
|
||||
print spider
|
||||
print(spider)
|
||||
for method in sorted(methods):
|
||||
print ' * %s' % method
|
||||
print(' * %s' % method)
|
||||
else:
|
||||
self.crawler_process.start()
|
||||
self.results.printErrors()
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class Command(ScrapyCommand):
|
|||
|
||||
if opts.list_targets:
|
||||
for name, target in _get_targets().items():
|
||||
print "%-20s %s" % (name, target['url'])
|
||||
print("%-20s %s" % (name, target['url']))
|
||||
return
|
||||
|
||||
if opts.list_projects:
|
||||
|
|
@ -81,7 +81,7 @@ class Command(ScrapyCommand):
|
|||
_add_auth_header(req, target)
|
||||
f = urllib2.urlopen(req)
|
||||
projects = json.loads(f.read())['projects']
|
||||
print os.linesep.join(projects)
|
||||
print(os.linesep.join(projects))
|
||||
return
|
||||
|
||||
tmpdir = None
|
||||
|
|
@ -208,12 +208,12 @@ def _http_post(request):
|
|||
try:
|
||||
f = urllib2.urlopen(request)
|
||||
_log("Server response (%s):" % f.code)
|
||||
print f.read()
|
||||
print(f.read())
|
||||
return True
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
_log("Deploy failed (%s):" % e.code)
|
||||
print e.read()
|
||||
except urllib2.URLError, e:
|
||||
print(e.read())
|
||||
except urllib2.URLError as e:
|
||||
_log("Deploy failed: %s" % e)
|
||||
|
||||
def _build_egg():
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ class Command(ScrapyCommand):
|
|||
def _print_headers(self, headers, prefix):
|
||||
for key, values in headers.items():
|
||||
for value in values:
|
||||
print '%s %s: %s' % (prefix, key, value)
|
||||
print('%s %s: %s' % (prefix, key, value))
|
||||
|
||||
def _print_response(self, response, opts):
|
||||
if opts.headers:
|
||||
self._print_headers(response.request.headers, '>')
|
||||
print '>'
|
||||
print('>')
|
||||
self._print_headers(response.headers, '<')
|
||||
else:
|
||||
print response.body
|
||||
print(response.body)
|
||||
|
||||
def run(self, args, opts):
|
||||
if len(args) != 1 or not is_url(args[0]):
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Command(ScrapyCommand):
|
|||
if opts.dump:
|
||||
template_file = self._find_template(opts.dump)
|
||||
if template_file:
|
||||
print open(template_file, 'r').read()
|
||||
print(open(template_file, 'r').read())
|
||||
return
|
||||
if len(args) != 2:
|
||||
raise UsageError()
|
||||
|
|
@ -58,7 +58,7 @@ class Command(ScrapyCommand):
|
|||
module = sanitize_module_name(name)
|
||||
|
||||
if self.settings.get('BOT_NAME') == module:
|
||||
print "Cannot create a spider with the same name as your project"
|
||||
print("Cannot create a spider with the same name as your project")
|
||||
return
|
||||
|
||||
try:
|
||||
|
|
@ -69,8 +69,8 @@ class Command(ScrapyCommand):
|
|||
else:
|
||||
# if spider already exists and not --force then halt
|
||||
if not opts.force:
|
||||
print "Spider %r already exists in module:" % name
|
||||
print " %s" % spider.__module__
|
||||
print("Spider %r already exists in module:" % name)
|
||||
print(" %s" % spider.__module__)
|
||||
return
|
||||
template_file = self._find_template(opts.template)
|
||||
if template_file:
|
||||
|
|
@ -94,22 +94,22 @@ class Command(ScrapyCommand):
|
|||
spider_file = "%s.py" % join(spiders_dir, module)
|
||||
shutil.copyfile(template_file, spider_file)
|
||||
render_templatefile(spider_file, **tvars)
|
||||
print "Created spider %r using template %r in module:" % (name, \
|
||||
template_name)
|
||||
print " %s.%s" % (spiders_module.__name__, module)
|
||||
print("Created spider %r using template %r in module:" % (name, \
|
||||
template_name))
|
||||
print(" %s.%s" % (spiders_module.__name__, module))
|
||||
|
||||
def _find_template(self, template):
|
||||
template_file = join(self.templates_dir, '%s.tmpl' % template)
|
||||
if exists(template_file):
|
||||
return template_file
|
||||
print "Unable to find template: %s\n" % template
|
||||
print 'Use "scrapy genspider --list" to see all available templates.'
|
||||
print("Unable to find template: %s\n" % template)
|
||||
print('Use "scrapy genspider --list" to see all available templates.')
|
||||
|
||||
def _list_templates(self):
|
||||
print "Available templates:"
|
||||
print("Available templates:")
|
||||
for filename in sorted(os.listdir(self.templates_dir)):
|
||||
if filename.endswith('.tmpl'):
|
||||
print " %s" % splitext(filename)[0]
|
||||
print(" %s" % splitext(filename)[0])
|
||||
|
||||
@property
|
||||
def templates_dir(self):
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@ class Command(ScrapyCommand):
|
|||
def run(self, args, opts):
|
||||
crawler = self.crawler_process.create_crawler()
|
||||
for s in crawler.spiders.list():
|
||||
print s
|
||||
print(s)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Command(ScrapyCommand):
|
|||
else:
|
||||
items = self.items.get(lvl, [])
|
||||
|
||||
print "# Scraped Items ", "-"*60
|
||||
print("# Scraped Items ", "-"*60)
|
||||
display.pprint([dict(x) for x in items], colorize=colour)
|
||||
|
||||
def print_requests(self, lvl=None, colour=True):
|
||||
|
|
@ -81,7 +81,7 @@ class Command(ScrapyCommand):
|
|||
else:
|
||||
requests = self.requests.get(lvl, [])
|
||||
|
||||
print "# Requests ", "-"*65
|
||||
print("# Requests ", "-"*65)
|
||||
display.pprint(requests, colorize=colour)
|
||||
|
||||
def print_results(self, opts):
|
||||
|
|
@ -89,13 +89,13 @@ class Command(ScrapyCommand):
|
|||
|
||||
if opts.verbose:
|
||||
for level in xrange(1, self.max_level+1):
|
||||
print '\n>>> DEPTH LEVEL: %s <<<' % level
|
||||
print('\n>>> DEPTH LEVEL: %s <<<' % level)
|
||||
if not opts.noitems:
|
||||
self.print_items(level, colour)
|
||||
if not opts.nolinks:
|
||||
self.print_requests(level, colour)
|
||||
else:
|
||||
print '\n>>> STATUS DEPTH LEVEL %s <<<' % self.max_level
|
||||
print('\n>>> STATUS DEPTH LEVEL %s <<<' % self.max_level)
|
||||
if not opts.noitems:
|
||||
self.print_items(colour=colour)
|
||||
if not opts.nolinks:
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class Command(ScrapyCommand):
|
|||
raise UsageError("File not found: %s\n" % filename)
|
||||
try:
|
||||
module = _import_file(filename)
|
||||
except (ImportError, ValueError), e:
|
||||
except (ImportError, ValueError) as e:
|
||||
raise UsageError("Unable to load %r: %s\n" % (filename, e))
|
||||
spclasses = list(iter_spider_classes(module))
|
||||
if not spclasses:
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ class Command(ScrapyCommand):
|
|||
def run(self, args, opts):
|
||||
settings = self.crawler_process.settings
|
||||
if opts.get:
|
||||
print settings.get(opts.get)
|
||||
print(settings.get(opts.get))
|
||||
elif opts.getbool:
|
||||
print settings.getbool(opts.getbool)
|
||||
print(settings.getbool(opts.getbool))
|
||||
elif opts.getint:
|
||||
print settings.getint(opts.getint)
|
||||
print(settings.getint(opts.getint))
|
||||
elif opts.getfloat:
|
||||
print settings.getfloat(opts.getfloat)
|
||||
print(settings.getfloat(opts.getfloat))
|
||||
elif opts.getlist:
|
||||
print settings.getlist(opts.getlist)
|
||||
print(settings.getlist(opts.getlist))
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ class Command(ScrapyCommand):
|
|||
raise UsageError()
|
||||
project_name = args[0]
|
||||
if not re.search(r'^[_a-zA-Z]\w*$', project_name):
|
||||
print 'Error: Project names must begin with a letter and contain only\n' \
|
||||
'letters, numbers and underscores'
|
||||
print('Error: Project names must begin with a letter and contain only\n' \
|
||||
'letters, numbers and underscores')
|
||||
sys.exit(1)
|
||||
elif exists(project_name):
|
||||
print "Error: directory %r already exists" % project_name
|
||||
print("Error: directory %r already exists" % project_name)
|
||||
sys.exit(1)
|
||||
|
||||
moduletpl = join(TEMPLATES_PATH, 'module')
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ class Command(ScrapyCommand):
|
|||
import lxml.etree
|
||||
lxml_version = ".".join(map(str, lxml.etree.LXML_VERSION))
|
||||
libxml2_version = ".".join(map(str, lxml.etree.LIBXML_VERSION))
|
||||
print "Scrapy : %s" % scrapy.__version__
|
||||
print "lxml : %s" % lxml_version
|
||||
print "libxml2 : %s" % libxml2_version
|
||||
print "Twisted : %s" % twisted.version.short()
|
||||
print "Python : %s" % sys.version.replace("\n", "- ")
|
||||
print "Platform: %s" % platform.platform()
|
||||
print("Scrapy : %s" % scrapy.__version__)
|
||||
print("lxml : %s" % lxml_version)
|
||||
print("libxml2 : %s" % libxml2_version)
|
||||
print("Twisted : %s" % twisted.version.short())
|
||||
print("Python : %s" % sys.version.replace("\n", "- "))
|
||||
print("Platform: %s" % platform.platform())
|
||||
else:
|
||||
print "Scrapy %s" % scrapy.__version__
|
||||
print("Scrapy %s" % scrapy.__version__)
|
||||
|
|
|
|||
|
|
@ -51,12 +51,12 @@ class DjangoItem(Item):
|
|||
|
||||
try:
|
||||
self.instance.clean_fields(exclude=exclude)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._errors = e.update_error_dict(self._errors)
|
||||
|
||||
try:
|
||||
self.instance.clean()
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
self._errors = e.update_error_dict(self._errors)
|
||||
|
||||
# uniqueness is not checked, because it is faster to check it when
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class ItemLoader(object):
|
|||
proc = wrap_loader_context(proc, self.context)
|
||||
try:
|
||||
return proc(self._values[field_name])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
raise ValueError("Error with output processor: field=%r value=%r error='%s: %s'" % \
|
||||
(field_name, self._values[field_name], type(e).__name__, str(e)))
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class DownloadHandlers(object):
|
|||
cls = load_object(clspath)
|
||||
try:
|
||||
dh = cls(crawler.settings)
|
||||
except NotConfigured, ex:
|
||||
except NotConfigured as ex:
|
||||
self._notconfigured[scheme] = str(ex)
|
||||
else:
|
||||
self._handlers[scheme] = dh
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class S3DownloadHandler(object):
|
|||
|
||||
try:
|
||||
self.conn = _S3Connection(aws_access_key_id, aws_secret_access_key)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
raise NotConfigured(str(ex))
|
||||
self._download_http = httpdownloadhandler(settings).download_request
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class ExecutionEngine(object):
|
|||
request = slot.start_requests.next()
|
||||
except StopIteration:
|
||||
slot.start_requests = None
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
log.err(None, 'Obtaining request from start requests', \
|
||||
spider=spider)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class Scheduler(object):
|
|||
try:
|
||||
reqd = request_to_dict(request, self.spider)
|
||||
self.dqs.push(reqd, -request.priority)
|
||||
except ValueError, e: # non serializable request
|
||||
except ValueError as e: # non serializable request
|
||||
if self.logunser:
|
||||
log.msg(format="Unable to serialize request: %(request)s - reason: %(reason)s",
|
||||
level=log.ERROR, spider=self.spider,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class MiddlewareManager(object):
|
|||
else:
|
||||
mw = mwcls()
|
||||
middlewares.append(mw)
|
||||
except NotConfigured, e:
|
||||
except NotConfigured as e:
|
||||
if e.args:
|
||||
clsname = clspath.split('.')[-1]
|
||||
log.msg(format="Disabled %(clsname)s: %(eargs)s",
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Shell(object):
|
|||
else:
|
||||
self.populate_vars()
|
||||
if self.code:
|
||||
print eval(self.code, globals(), self.vars)
|
||||
print(eval(self.code, globals(), self.vars))
|
||||
else:
|
||||
start_python_console(self.vars)
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ class Shell(object):
|
|||
self.p(" view(response) View response in a browser")
|
||||
|
||||
def p(self, line=''):
|
||||
print "[s] %s" % line
|
||||
print("[s] %s" % line)
|
||||
|
||||
def _is_relevant(self, value):
|
||||
return isinstance(value, self.relevant_classes)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def _serializable_queue(queue_class, serialize, deserialize):
|
|||
def _pickle_serialize(obj):
|
||||
try:
|
||||
return pickle.dumps(obj, protocol=2)
|
||||
except pickle.PicklingError, e:
|
||||
except pickle.PicklingError as e:
|
||||
raise ValueError(str(e))
|
||||
|
||||
PickleFifoDiskQueue = _serializable_queue(queue.FifoDiskQueue, \
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ error = KeyError
|
|||
|
||||
_DATABASES = collections.defaultdict(DummyDB)
|
||||
|
||||
def open(file, flag='r', mode=0666):
|
||||
def open(file, flag='r', mode=0o666):
|
||||
"""Open or create a dummy database compatible.
|
||||
|
||||
Arguments `flag` and `mode` are ignored.
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ if __name__ == "__main__":
|
|||
def print_listening():
|
||||
httpHost = httpPort.getHost()
|
||||
httpsHost = httpsPort.getHost()
|
||||
print "Mock server running at http://%s:%d and https://%s:%d" % (
|
||||
httpHost.host, httpHost.port, httpsHost.host, httpsHost.port)
|
||||
print("Mock server running at http://%s:%d and https://%s:%d" % (
|
||||
httpHost.host, httpHost.port, httpsHost.host, httpsHost.port))
|
||||
reactor.callWhenRunning(print_listening)
|
||||
reactor.run()
|
||||
|
|
|
|||
|
|
@ -227,13 +227,13 @@ class ItemLoaderTest(unittest.TestCase):
|
|||
il.add_value('name', [u'$10'])
|
||||
try:
|
||||
float('$10')
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
expected_exc_str = str(e)
|
||||
|
||||
exc = None
|
||||
try:
|
||||
il.load_item()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
exc = e
|
||||
assert isinstance(exc, ValueError)
|
||||
s = str(exc)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class ScrapyUtilsTest(unittest.TestCase):
|
|||
def test_required_openssl_version(self):
|
||||
try:
|
||||
module = __import__('OpenSSL', {}, {}, [''])
|
||||
except ImportError, ex:
|
||||
except ImportError as ex:
|
||||
raise unittest.SkipTest("OpenSSL is not available")
|
||||
|
||||
if hasattr(module, '__version__'):
|
||||
|
|
|
|||
|
|
@ -242,9 +242,9 @@ class RFC2616PolicyTest(DefaultStorageTest):
|
|||
assert isinstance(result, Response)
|
||||
return result
|
||||
except Exception:
|
||||
print 'Request', request
|
||||
print 'Response', response
|
||||
print 'Result', result
|
||||
print('Request', request)
|
||||
print('Response', response)
|
||||
print('Result', result)
|
||||
raise
|
||||
|
||||
def test_request_cacheability(self):
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ def start_test_site(debug=False):
|
|||
|
||||
port = reactor.listenTCP(0, server.Site(r), interface="127.0.0.1")
|
||||
if debug:
|
||||
print "Test server running at http://localhost:%d/ - hit Ctrl-C to finish." \
|
||||
% port.getHost().port
|
||||
print("Test server running at http://localhost:%d/ - hit Ctrl-C to finish." \
|
||||
% port.getHost().port)
|
||||
return port
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from scrapy.settings import Settings
|
|||
skip = False
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
skip = 'Missing Python Imaging Library, install https://pypi.python.org/pypi/Pillow'
|
||||
else:
|
||||
encoders = set(('jpeg_encoder', 'jpeg_decoder'))
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ class SelectorTestCase(unittest.TestCase):
|
|||
xpath = "//test[@foo='bar]"
|
||||
try:
|
||||
x.xpath(xpath)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
assert xpath in str(e), "Exception message does not contain invalid xpath"
|
||||
except Exception:
|
||||
raise AssertionError("A invalid XPath does not raise ValueError")
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class DeferUtilsTest(unittest.TestCase):
|
|||
gotexc = False
|
||||
try:
|
||||
yield process_chain([cb1, cb_fail, cb3], 'res', 'v1', 'v2')
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
gotexc = True
|
||||
self.failUnless(gotexc)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class JsonRpcUtilsTestCase(unittest.TestCase):
|
|||
raised = False
|
||||
try:
|
||||
jsonrpc_client_call('url', 'test', _urllib=ul)
|
||||
except JsonRpcError, e:
|
||||
except JsonRpcError as e:
|
||||
raised = True
|
||||
self.assertEqual(e.code, 123)
|
||||
self.assertEqual(e.message, 'hello')
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class MultiValueDict(dict):
|
|||
try:
|
||||
list_ = dict.__getitem__(self, key)
|
||||
except KeyError:
|
||||
raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self)
|
||||
raise MultiValueDictKeyError("Key %r not found in %r" % (key, self))
|
||||
try:
|
||||
return list_[-1]
|
||||
except IndexError:
|
||||
|
|
@ -124,7 +124,7 @@ class MultiValueDict(dict):
|
|||
def update(self, *args, **kwargs):
|
||||
"update() extends rather than replaces existing key lists. Also accepts keyword args."
|
||||
if len(args) > 1:
|
||||
raise TypeError, "update expected at most 1 arguments, got %d" % len(args)
|
||||
raise TypeError("update expected at most 1 arguments, got %d" % len(args))
|
||||
if args:
|
||||
other_dict = args[0]
|
||||
if isinstance(other_dict, MultiValueDict):
|
||||
|
|
@ -135,7 +135,7 @@ class MultiValueDict(dict):
|
|||
for key, value in other_dict.items():
|
||||
self.setlistdefault(key, []).append(value)
|
||||
except TypeError:
|
||||
raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
|
||||
raise ValueError("MultiValueDict.update() takes either a MultiValueDict or dictionary")
|
||||
for key, value in kwargs.iteritems():
|
||||
self.setlistdefault(key, []).append(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def mustbe_deferred(f, *args, **kw):
|
|||
# FIXME: Hack to avoid introspecting tracebacks. This to speed up
|
||||
# processing of IgnoreRequest errors which are, by far, the most common
|
||||
# exception in Scrapy - see #125
|
||||
except IgnoreRequest, e:
|
||||
except IgnoreRequest as e:
|
||||
return defer_fail(failure.Failure(e))
|
||||
except:
|
||||
return defer_fail(failure.Failure())
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@ def pformat(obj, *args, **kwargs):
|
|||
return _colorize(pformat_(obj), kwargs.pop('colorize', True))
|
||||
|
||||
def pprint(obj, *args, **kwargs):
|
||||
print pformat(obj, *args, **kwargs)
|
||||
print(pformat(obj, *args, **kwargs))
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ def get_engine_status(engine):
|
|||
for test in global_tests:
|
||||
try:
|
||||
status['global'] += [(test, eval(test))]
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
status['global'] += [(test, "%s (exception)" % type(e).__name__)]
|
||||
for spider in engine.slots.keys():
|
||||
x = []
|
||||
for test in spider_tests:
|
||||
try:
|
||||
x += [(test, eval(test))]
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
x += [(test, "%s (exception)" % type(e).__name__)]
|
||||
status['spiders'][spider] = x
|
||||
return status
|
||||
|
|
@ -52,5 +52,5 @@ def format_engine_status(engine=None):
|
|||
return s
|
||||
|
||||
def print_engine_status(engine):
|
||||
print format_engine_status(engine)
|
||||
print(format_engine_status(engine))
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def jsonrpc_server_call(target, jsonrpc_request, json_decoder=None):
|
|||
|
||||
try:
|
||||
req = json_decoder.decode(jsonrpc_request)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
return jsonrpc_error(None, jsonrpc_errors.PARSE_ERROR, 'Parse error', \
|
||||
traceback.format_exc())
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ def jsonrpc_server_call(target, jsonrpc_request, json_decoder=None):
|
|||
kw = dict([(str(k), v) for k, v in kw.items()]) # convert kw keys to str
|
||||
try:
|
||||
return jsonrpc_result(id, method(*a, **kw))
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
return jsonrpc_error(id, jsonrpc_errors.INTERNAL_ERROR, str(e), \
|
||||
traceback.format_exc())
|
||||
|
||||
|
|
|
|||
|
|
@ -31,18 +31,18 @@ def load_object(path):
|
|||
try:
|
||||
dot = path.rindex('.')
|
||||
except ValueError:
|
||||
raise ValueError, "Error loading object '%s': not a full path" % path
|
||||
raise ValueError("Error loading object '%s': not a full path" % path)
|
||||
|
||||
module, name = path[:dot], path[dot+1:]
|
||||
try:
|
||||
mod = __import__(module, {}, {}, [''])
|
||||
except ImportError, e:
|
||||
raise ImportError, "Error loading object '%s': %s" % (path, e)
|
||||
except ImportError as e:
|
||||
raise ImportError("Error loading object '%s': %s" % (path, e))
|
||||
|
||||
try:
|
||||
obj = getattr(mod, name)
|
||||
except AttributeError:
|
||||
raise NameError, "Module '%s' doesn't define any object named '%s'" % (module, name)
|
||||
raise NameError("Module '%s' doesn't define any object named '%s'" % (module, name))
|
||||
|
||||
return obj
|
||||
|
||||
|
|
|
|||
|
|
@ -274,6 +274,6 @@ def retry_on_eintr(function, *args, **kw):
|
|||
while True:
|
||||
try:
|
||||
return function(*args, **kw)
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno != errno.EINTR:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def assert_aws_environ():
|
|||
"""
|
||||
try:
|
||||
import boto
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
raise SkipTest(str(e))
|
||||
|
||||
if 'AWS_ACCESS_KEY_ID' not in os.environ:
|
||||
|
|
|
|||
|
|
@ -27,5 +27,5 @@ def test_site():
|
|||
|
||||
if __name__ == '__main__':
|
||||
port = reactor.listenTCP(0, test_site(), interface="127.0.0.1")
|
||||
print "http://localhost:%d/" % port.getHost().port
|
||||
print("http://localhost:%d/" % port.getHost().port)
|
||||
reactor.run()
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ def format_live_refs(ignore=NoneType):
|
|||
return s
|
||||
|
||||
def print_live_refs(*a, **kw):
|
||||
print format_live_refs(*a, **kw)
|
||||
print(format_live_refs(*a, **kw))
|
||||
|
||||
def get_oldest(class_name):
|
||||
for cls, wdict in live_refs.iteritems():
|
||||
|
|
|
|||
|
|
@ -33,12 +33,6 @@ __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
|||
__cvsid__ = "$Id: dispatcher.py,v 1.1.1.1 2006/07/07 15:59:38 mcfletch Exp $"
|
||||
__version__ = "$Revision: 1.1.1.1 $"[11:-2]
|
||||
|
||||
try:
|
||||
True
|
||||
except NameError:
|
||||
True = 1==1
|
||||
False = 1==0
|
||||
|
||||
class _Parameter:
|
||||
"""Used to represent default parameter values."""
|
||||
def __repr__(self):
|
||||
|
|
@ -379,13 +373,13 @@ def _removeReceiver(receiver):
|
|||
backKey = id(receiver)
|
||||
try:
|
||||
backSet = sendersBack.pop(backKey)
|
||||
except KeyError, err:
|
||||
except KeyError as err:
|
||||
return False
|
||||
else:
|
||||
for senderkey in backSet:
|
||||
try:
|
||||
signals = connections[senderkey].keys()
|
||||
except KeyError,err:
|
||||
except KeyError as err:
|
||||
pass
|
||||
else:
|
||||
for signal in signals:
|
||||
|
|
@ -396,7 +390,7 @@ def _removeReceiver(receiver):
|
|||
else:
|
||||
try:
|
||||
receivers.remove( receiver )
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
pass
|
||||
_cleanupConnections(senderkey, signal)
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ def sendRobust(
|
|||
*arguments,
|
||||
**named
|
||||
)
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
responses.append((receiver, err))
|
||||
else:
|
||||
responses.append((receiver, response))
|
||||
|
|
|
|||
|
|
@ -109,13 +109,13 @@ class BoundMethodWeakref(object):
|
|||
try:
|
||||
if callable( function ):
|
||||
function( self )
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
try:
|
||||
traceback.print_exc()
|
||||
except AttributeError, err:
|
||||
print '''Exception during saferef %s cleanup function %s: %s'''%(
|
||||
except AttributeError as err:
|
||||
print('''Exception during saferef %s cleanup function %s: %s'''%(
|
||||
self, function, e
|
||||
)
|
||||
))
|
||||
self.deletionMethods = [onDelete]
|
||||
self.key = self.calculateKey( target )
|
||||
self.weakSelf = weakref.ref(target.im_self, remove)
|
||||
|
|
|
|||
|
|
@ -392,7 +392,7 @@ class HTTPClientParser(HTTPParser):
|
|||
proto, strnumber = strversion.split('/')
|
||||
major, minor = strnumber.split('.')
|
||||
major, minor = int(major), int(minor)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise BadResponseVersion(str(e), strversion)
|
||||
if major < 0 or minor < 0:
|
||||
raise BadResponseVersion("version may not be negative", strversion)
|
||||
|
|
|
|||
Loading…
Reference in New Issue