---
scripts/urlgrabber | 40 ++++++++++++++++++++--------------------
urlgrabber/grabber.py | 38 ++++++++++++++++++++------------------
urlgrabber/progress.py | 2 --
3 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/scripts/urlgrabber b/scripts/urlgrabber
index a23a11c..c8d915a 100644
--- a/scripts/urlgrabber
+++ b/scripts/urlgrabber
@@ -139,6 +139,7 @@ import re
import urlgrabber.grabber
from urlgrabber.grabber import URLGrabber, URLGrabberOptions, URLGrabError
+from __future__ import print_function
class client_options:
def __init__(self):
@@ -161,7 +162,6 @@ class client_options:
for k in ugo.__dict__.keys():
if (k not in ug_options) and (k not in options_exclude):
ug_options.append(k)
- #print k
ug_defaults = {}
for k in list(ug_options):
try:
@@ -179,7 +179,7 @@ class client_options:
optlist, args = getopt.getopt(sys.argv[1:], short_options,
long_options + ug_long)
except getopt.GetoptError as e:
- print >>sys.stderr, "Error:", e
+ print("Error:", e, file=sys.stderr)
self.help([], ret=1)
self.verbose = 0
@@ -209,7 +209,7 @@ class client_options:
self.repeat = int(v)
if self.repeat < 1: raise ValueError()
except ValueError:
- print 'ERROR: repeat value must be an int >= 1'
+ print('ERROR: repeat value must be an int >= 1')
sys.exit(1)
if o == '-D':
self.verbose = 3
@@ -219,19 +219,19 @@ class client_options:
try:
val = eval(v)
except Exception as e:
- print "error processing option value: %s" % v
- print e
+ print("error processing option value: %s" % v)
+ print(e)
sys.exit(1)
else:
self.ugops[o[2:]] = val
if len(self.args) > 1 and self.outputfile is not None:
- print "ERROR: cannot use -o when grabbing multiple files"
+ print("ERROR: cannot use -o when grabbing multiple files")
sys.exit(1)
def help(self, args, ret=0):
if not args:
- print MAINHELP
+ print(MAINHELP)
else:
for a in args:
m = getattr(self, 'help_'+a, None)
@@ -240,20 +240,20 @@ class client_options:
elif a in self.ug_options:
self.help_ug_option(a)
else:
- print 'ERROR: no help on command "%s"' % a
+ print('ERROR: no help on command "%s"' % a)
sys.exit(ret)
def help_doc(self):
- print __doc__
+ print(__doc__)
def help_options(self):
width = max(map(len, self.ug_options))
format = ' %-' + str(width) + 's = %s'
hformat = ' %-' + str(width) + 's %s'
- print hformat % ('OPTION', 'DEFAULT')
- print '-'*(width + 20)
+ print(hformat % ('OPTION', 'DEFAULT'))
+ print('-'*(width + 20))
for k in self.ug_options:
- print format % (k, self.ug_defaults[k])
+ print(format % (k, self.ug_defaults[k]))
def help_all(self):
for k in self.ug_options:
@@ -264,21 +264,21 @@ class client_options:
m = re.search(r'^( '+option+'.*?)\s*^ {,2}\S',
urlgrabber.grabber.__doc__, re.M|re.S)
if m:
- print m.group(1)
+ print(m.group(1))
else:
- print ' %s: no help found for this option' % option
- print ''
+ print(' %s: no help found for this option' % option)
+ print('')
class ugclient:
def __init__(self):
op = client_options()
self.op = op
if op.verbose >= 2 and op.ugops:
- print "Module Options:"
+ print("Module Options:")
width = max(map(len, op.ugops.keys()))
format = " %-" + str(width) + "s = %s"
for k, v in op.ugops.items():
- print format % (k, repr(v))
+ print(format % (k, repr(v)))
if op.debug:
self.set_debug_logger(op.debug)
@@ -294,13 +294,13 @@ class ugclient:
def run(self):
for url in self.op.args:
- if self.op.verbose: print 'grabbing: %s' % url
+ if self.op.verbose: print('grabbing: %s' % url)
try:
for i in range(0, self.op.repeat):
f = self.g.urlgrab(url, self.op.outputfile)
- if self.op.localfile: print f
+ if self.op.localfile: print(f)
except URLGrabError as e:
- print e
+ print(e)
def set_debug_logger(self, dbspec):
try:
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 9e1c6ee..465acd2 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -463,6 +463,7 @@ BANDWIDTH THROTTLING
"""
+from __future__ import print_function
import os
import sys
@@ -2346,11 +2347,12 @@ class _TH:
#####################################################################
# TESTING
+
def _main_test():
try: url, filename = sys.argv[1:3]
except ValueError:
- print 'usage:', sys.argv[0], \
- '<url> <filename> [copy_local=0|1] [close_connection=0|1]'
+ print('usage:', sys.argv[0], \
+ '<url> <filename> [copy_local=0|1] [close_connection=0|1]')
sys.exit()
kwargs = {}
@@ -2360,23 +2362,23 @@ def _main_test():
set_throttle(1.0)
set_bandwidth(32 * 1024)
- print "throttle: %s, throttle bandwidth: %s B/s" %
(default_grabber.throttle,
-
default_grabber.bandwidth)
+ print("throttle: %s, throttle bandwidth: %s B/s" %
(default_grabber.throttle,
+
default_grabber.bandwidth))
try: from progress import text_progress_meter
except ImportError: pass
else: kwargs['progress_obj'] = text_progress_meter()
try: name = apply(urlgrab, (url, filename), kwargs)
- except URLGrabError as e: print e
- else: print 'LOCAL FILE:', name
+ except URLGrabError as e: print(e)
+ else: print('LOCAL FILE:', name)
def _retry_test():
try: url, filename = sys.argv[1:3]
except ValueError:
- print 'usage:', sys.argv[0], \
- '<url> <filename> [copy_local=0|1] [close_connection=0|1]'
+ print('usage:', sys.argv[0], \
+ '<url> <filename> [copy_local=0|1] [close_connection=0|1]')
sys.exit()
kwargs = {}
@@ -2389,28 +2391,28 @@ def _retry_test():
else: kwargs['progress_obj'] = text_progress_meter()
def cfunc(filename, hello, there='foo'):
- print hello, there
+ print(hello, there)
import random
rnum = random.random()
if rnum < .5:
- print 'forcing retry'
+ print('forcing retry')
raise URLGrabError(-1, 'forcing retry')
if rnum < .75:
- print 'forcing failure'
+ print('forcing failure')
raise URLGrabError(-2, 'forcing immediate failure')
- print 'success'
+ print('success')
return
kwargs['checkfunc'] = (cfunc, ('hello',), {'there':'there'})
try: name = apply(retrygrab, (url, filename), kwargs)
- except URLGrabError as e: print e
- else: print 'LOCAL FILE:', name
+ except URLGrabError as e: print(e)
+ else: print('LOCAL FILE:', name)
def _file_object_test(filename=None):
import cStringIO
if filename is None:
filename = __file__
- print 'using file "%s" for comparisons' % filename
+ print('using file "%s" for comparisons' % filename)
fo = open(filename)
s_input = fo.read()
fo.close()
@@ -2422,11 +2424,11 @@ def _file_object_test(filename=None):
fo_input = cStringIO.StringIO(s_input)
fo_output = cStringIO.StringIO()
wrapper = PyCurlFileObject(fo_input, None, 0)
- print 'testing %-30s ' % testfunc.__name__,
+ print('testing %-30s ' % testfunc.__name__, end='')
testfunc(wrapper, fo_output)
s_output = fo_output.getvalue()
- if s_output == s_input: print 'passed'
- else: print 'FAILED'
+ if s_output == s_input: print('passed')
+ else: print('FAILED')
def _test_file_object_smallread(wrapper, fo_output):
while 1:
diff --git a/urlgrabber/progress.py b/urlgrabber/progress.py
index 4c126c5..0d4d7bb 100644
--- a/urlgrabber/progress.py
+++ b/urlgrabber/progress.py
@@ -623,7 +623,6 @@ class RateEstimator:
self.ave_rate = None
return
- #print 'times', now, self.last_update_time
time_diff = now - self.last_update_time
read_diff = amount_read - self.last_amount_read
# First update, on reget is the file size
@@ -632,7 +631,6 @@ class RateEstimator:
self.ave_rate = self._temporal_rolling_ave(\
time_diff, read_diff, self.ave_rate, self.timescale)
self.last_amount_read = amount_read
- #print 'results', time_diff, read_diff, self.ave_rate
#####################################################################
# result methods
--
1.7.4.4
_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel