86>Aug 24 02:22:16 userdel[1335424]: delete user 'rooter' <86>Aug 24 02:22:16 groupadd[1335444]: group added to /etc/group: name=rooter, GID=573 <86>Aug 24 02:22:16 groupadd[1335444]: group added to /etc/gshadow: name=rooter <86>Aug 24 02:22:16 groupadd[1335444]: new group: name=rooter, GID=573 <86>Aug 24 02:22:16 useradd[1335455]: new user: name=rooter, UID=573, GID=573, home=/root, shell=/bin/bash <86>Aug 24 02:22:16 userdel[1335472]: delete user 'builder' <86>Aug 24 02:22:16 userdel[1335472]: removed group 'builder' owned by 'builder' <86>Aug 24 02:22:16 userdel[1335472]: removed shadow group 'builder' owned by 'builder' <86>Aug 24 02:22:16 groupadd[1335490]: group added to /etc/group: name=builder, GID=574 <86>Aug 24 02:22:16 groupadd[1335490]: group added to /etc/gshadow: name=builder <86>Aug 24 02:22:16 groupadd[1335490]: new group: name=builder, GID=574 <86>Aug 24 02:22:16 useradd[1335499]: new user: name=builder, UID=574, GID=574, home=/usr/src, shell=/bin/bash /usr/src/in/srpm/python-module-ClientForm-0.2.10-alt4.1.2.src.rpm: license not found in '/usr/share/license' directory: BSD-like <13>Aug 24 02:22:19 rpmi: libgdbm-1.8.3-alt10 1454943334 installed <13>Aug 24 02:22:19 rpmi: libexpat-2.2.9-alt1 sisyphus+252464.200.2.1 1590958865 installed <13>Aug 24 02:22:19 rpmi: libp11-kit-0.23.15-alt2 sisyphus+252784.100.2.2 1591274901 installed <13>Aug 24 02:22:19 rpmi: libtasn1-4.16.0-alt1 sisyphus+245480.100.1.1 1580825062 installed <13>Aug 24 02:22:19 rpmi: alternatives-0.5.1-alt1 sisyphus+226946.100.1.1 1554830426 installed <13>Aug 24 02:22:19 rpmi: ca-certificates-2020.06.29-alt1 sisyphus+254237.300.1.1 1593450881 installed <13>Aug 24 02:22:19 rpmi: ca-trust-0.1.2-alt1 sisyphus+233348.100.1.1 1561653823 installed <13>Aug 24 02:22:19 rpmi: p11-kit-trust-0.23.15-alt2 sisyphus+252784.100.2.2 1591274901 installed <13>Aug 24 02:22:19 rpmi: libcrypto1.1-1.1.1g-alt1 sisyphus+249982.60.8.1 1587743711 installed <13>Aug 24 02:22:19 rpmi: libssl1.1-1.1.1g-alt1 sisyphus+249982.60.8.1 1587743711 installed <13>Aug 24 02:22:19 rpmi: python3-3.8.5-alt1 sisyphus+244405.100.3.1 1595544514 installed <13>Aug 24 02:22:20 rpmi: python3-base-3.8.5-alt1 sisyphus+244405.100.3.1 1595544514 installed <13>Aug 24 02:22:20 rpmi: libpython3-3.8.5-alt1 sisyphus+244405.100.3.1 1595544514 installed <13>Aug 24 02:22:20 rpmi: tests-for-installed-python3-pkgs-0.1.13.1-alt2 1535450458 installed <13>Aug 24 02:22:20 rpmi: rpm-build-python3-0.1.13.1-alt2 1535450458 installed <13>Aug 24 02:22:23 rpmi: python3-module-pkg_resources-1:46.1.3-alt1 sisyphus+250566.200.3.1 1587973342 installed <13>Aug 24 02:22:23 rpmi: python-modules-curses-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: libtinfo-devel-6.1.20180407-alt2 sisyphus+222164.200.1.1 1550686226 installed <13>Aug 24 02:22:23 rpmi: libncurses-devel-6.1.20180407-alt2 sisyphus+222164.200.1.1 1550686226 installed <13>Aug 24 02:22:23 rpmi: python3-dev-3.8.5-alt1 sisyphus+244405.100.3.1 1595544514 installed <13>Aug 24 02:22:23 rpmi: libverto-0.3.0-alt1_7 sisyphus+225932.100.1.1 1553994919 installed <13>Aug 24 02:22:23 rpmi: liblmdb-0.9.23-alt1 sisyphus+225277.100.2.1 1553001679 installed <13>Aug 24 02:22:23 rpmi: libkeyutils-1.6.1-alt1 sisyphus+256015.100.1.1 1596820124 installed <13>Aug 24 02:22:23 rpmi: libcom_err-1.44.6-alt1 sisyphus+224154.100.1.1 1552091678 installed <86>Aug 24 02:22:23 groupadd[1358798]: group added to /etc/group: name=_keytab, GID=499 <86>Aug 24 02:22:23 groupadd[1358798]: group added to /etc/gshadow: name=_keytab <86>Aug 24 02:22:23 groupadd[1358798]: new group: name=_keytab, GID=499 <13>Aug 24 02:22:23 rpmi: libkrb5-1.18.2-alt2 sisyphus+254565.100.4.1 1594375666 installed <13>Aug 24 02:22:23 rpmi: libtirpc-1.2.6-alt1 sisyphus+250076.100.1.1 1587038270 installed <13>Aug 24 02:22:23 rpmi: libnsl2-1.1.0-alt1_1 1511548749 installed <13>Aug 24 02:22:23 rpmi: python-modules-compiler-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-email-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-unittest-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-encodings-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-nis-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-ctypes-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-multiprocessing-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:23 rpmi: python-modules-logging-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-tools-2to3-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-modules-xml-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-modules-hotshot-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-modules-bsddb-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-modules-distutils-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-module-pkg_resources-1:42.0.0-alt2 sisyphus+250566.100.6.1 1588187716 installed <13>Aug 24 02:22:24 rpmi: python-modules-json-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: libnsl2-devel-1.1.0-alt1_1 1511548749 installed <13>Aug 24 02:22:24 rpmi: python-dev-2.7.18-alt1 sisyphus+255741.100.1.1 1596450480 installed <13>Aug 24 02:22:24 rpmi: python-module-setuptools-1:42.0.0-alt2 sisyphus+250566.100.6.1 1588187716 installed <13>Aug 24 02:22:24 rpmi: python3-module-setuptools-1:46.1.3-alt1 sisyphus+250566.200.3.1 1587973342 installed Building target platforms: i586 Building for target i586 Wrote: /usr/src/in/nosrpm/python-module-ClientForm-0.2.10-alt4.1.2.nosrc.rpm Installing python-module-ClientForm-0.2.10-alt4.1.2.src.rpm Building target platforms: i586 Building for target i586 Executing(%prep): /bin/sh -e /usr/src/tmp/rpm-tmp.14602 + umask 022 + /bin/mkdir -p /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + rm -rf ClientForm-0.2.10 + echo 'Source #0 (ClientForm-0.2.10.tar.gz):' Source #0 (ClientForm-0.2.10.tar.gz): + /bin/tar -xf - + /bin/gzip -dc /usr/src/RPM/SOURCES/ClientForm-0.2.10.tar.gz + cd ClientForm-0.2.10 + /bin/chmod -c -Rf u+rwX,go-w . + cp -fR . ../python3 + exit 0 Executing(%build): /bin/sh -e /usr/src/tmp/rpm-tmp.14602 + umask 022 + /bin/mkdir -p /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + cd ClientForm-0.2.10 + CFLAGS='-pipe -frecord-gcc-switches -Wall -g -O2 -march=i586 -mtune=generic' + export CFLAGS + CXXFLAGS='-pipe -frecord-gcc-switches -Wall -g -O2 -march=i586 -mtune=generic' + export CXXFLAGS + FFLAGS='-pipe -frecord-gcc-switches -Wall -g -O2 -march=i586 -mtune=generic' + export FFLAGS + /usr/bin/python2.7 setup.py build running build running build_py creating build creating build/lib copying ClientForm.py -> build/lib + pushd ../python3 ~/RPM/BUILD/python3 ~/RPM/BUILD/ClientForm-0.2.10 + find ../python3 -type f -name '*.py' -exec 2to3 -w -n '{}' + RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored ../python3/ez_setup.py RefactoringTool: Refactored ../python3/examples/simple.py --- ../python3/ez_setup.py (original) +++ ../python3/ez_setup.py (refactored) @@ -42,10 +42,10 @@ from md5 import md5 digest = md5(data).hexdigest() if digest != md5_data[egg_name]: - print >>sys.stderr, ( + print(( "md5 validation of %s failed! (Possible download problem?)" % egg_name - ) + ), file=sys.stderr) sys.exit(2) return data @@ -68,10 +68,10 @@ try: import setuptools if setuptools.__version__ == '0.0.1': - print >>sys.stderr, ( + print(( "You have an obsolete version of setuptools installed. Please\n" "remove it from your system entirely before rerunning this script." - ) + ), file=sys.stderr) sys.exit(2) except ImportError: egg = download_setuptools(version, download_base, to_dir, download_delay) @@ -82,13 +82,13 @@ try: pkg_resources.require("setuptools>="+version) - except pkg_resources.VersionConflict, e: + except pkg_resources.VersionConflict as e: # XXX could we install in a subprocess here? - print >>sys.stderr, ( + print(( "The required version of setuptools (>=%s) is not available, and\n" "can't be installed while this script is running. Please install\n" " a more recent version first.\n\n(Currently using %r)" - ) % (version, e.args[0]) + ) % (version, e.args[0]), file=sys.stderr) sys.exit(2) def download_setuptools( @@ -102,7 +102,7 @@ with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the number of seconds to pause before an actual download attempt. """ - import urllib2, shutil + import urllib.request, urllib.error, urllib.parse, shutil egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) url = download_base + egg_name saveto = os.path.join(to_dir, egg_name) @@ -128,7 +128,7 @@ version, download_base, delay, url ); from time import sleep; sleep(delay) log.warn("Downloading %s", url) - src = urllib2.urlopen(url) + src = urllib.request.urlopen(url) # Read/write all in one block, so we don't create a corrupt file # if the download is interrupted. data = _validate_md5(egg_name, src.read()) @@ -174,8 +174,8 @@ from setuptools.command.easy_install import main main(argv) else: - print "Setuptools version",version,"or greater has been installed." - print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + print("Setuptools version",version,"or greater has been installed.") + print('(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)') @@ -191,7 +191,7 @@ md5_data[base] = md5(f.read()).hexdigest() f.close() - data = [" %r: %r,\n" % it for it in md5_data.items()] + data = [" %r: %r,\n" % it for it in list(md5_data.items())] data.sort() repl = "".join(data) @@ -201,7 +201,7 @@ match = re.search("\nmd5_data = {\n([^}]+)}", src) if not match: - print >>sys.stderr, "Internal error!" + print("Internal error!", file=sys.stderr) sys.exit(2) src = src[:match.start(1)] + repl + src[match.end(1):] --- ../python3/examples/simple.py (original) +++ ../python3/examples/simple.py (refactored) @@ -1,14 +1,14 @@ #!/usr/bin/env python -from urllib2 import urlopen +from urllib.request import urlopen from ClientForm import ParseResponse response = urlopen("http://wwwsearch.sourceforge.net/ClientForm/example.html") forms = ParseResponse(response, backwards_compat=False) form = forms[0] -print form +print(form) form["comments"] = "Thanks, Gisle" # form.click() returns a urllib2.Request object # (see HTMLForm.click.__doc__ if you don't have urllib2) -print urlopen(form.click()).read() +print(urlRefactoringTool: Refactored ../python3/examples/example.py RefactoringTool: Refactored ../python3/ClientForm.py open(form.click()).read()) --- ../python3/examples/example.py (original) +++ ../python3/examples/example.py (refactored) @@ -1,10 +1,10 @@ #!/usr/bin/env python import ClientForm -import urllib2 -request = urllib2.Request( +import urllib.request, urllib.error, urllib.parse +request = urllib.request.Request( "http://wwwsearch.sourceforge.net/ClientForm/example.html") -response = urllib2.urlopen(request) +response = urllib.request.urlopen(request) forms = ClientForm.ParseResponse(response, backwards_compat=False) response.close() ## f = open("example.html") @@ -12,7 +12,7 @@ ## backwards_compat=False) ## f.close() form = forms[0] -print form # very useful! +print(form) # very useful! # A 'control' is a graphical HTML form widget: a text entry box, a # dropdown 'select' list, a checkbox, etc. @@ -39,9 +39,9 @@ # All Controls may be disabled (equivalent of greyed-out in browser)... control = form.find_control("comments") -print control.disabled +print(control.disabled) # ...or readonly -print control.readonly +print(control.readonly) # readonly and disabled attributes can be assigned to control.disabled = False # convenience method, used here to make all controls writable (unless @@ -75,11 +75,11 @@ # You can get the Control instances from inside the form... control = form.find_control("cheeses", type="select") -print control.name, control.value, control.type +print(control.name, control.value, control.type) control.value = ["mascarpone", "curd"] # ...and the Item instances from inside the Control item = control.get("curd") -print item.name, item.selected, item.id, item.attrs +print(item.name, item.selected, item.id, item.attrs) item.selected = False # Controls may be referred to by label: @@ -115,7 +115,7 @@ # Control.items is a list of all Item instances in the control for item in form.find_control("cheeses").items: - print item.name + print(item.name) # To remove items from a list control, remove it from .items: cheeses = form.find_control("cheeses") @@ -140,12 +140,12 @@ # Which items are present, selected, and successful? # is the "parmesan" item of the "cheeses" control successful (selected # and not disabled)? -print "parmesan" in form["cheeses"] +print("parmesan" in form["cheeses"]) # is the "parmesan" item of the "cheeses" control selected? -print "parmesan" in [ - item.name for item in form.find_control("cheeses").items if item.selected] +print("parmesan" in [ + item.name for item in form.find_control("cheeses").items if item.selected]) # does cheeses control have a "caerphilly" item? -print "caerphilly" in [item.name for item in form.find_control("cheeses").items] +print("caerphilly" in [item.name for item in form.find_control("cheeses").items]) # Sometimes one wants to set or clear individual items in a list, rather # than setting the whole .value: @@ -167,18 +167,18 @@ # Items may be disabled (selecting or de-selecting a disabled item is # not allowed): control = form.find_control("cheeses") -print control.get("emmenthal").disabled +print(control.get("emmenthal").disabled) control.get("emmenthal").disabled = True # enable all items in control control.set_all_items_disabled(False) request2 = form.click() # urllib2.Request object try: - response2 = urllib2.urlopen(request2) -except urllib2.HTTPError, response2: + response2 = urllib.request.urlopen(request2) +except urllib.error.HTTPError as response2: pass -print response2.geturl() -print response2.info() # headers -print response2.read() # body +print(response2.geturl()) +print(response2.info()) # headers +print(response2.read()) # body response2.close() --- ../python3/ClientForm.py (original) +++ ../python3/ClientForm.py (refactored) @@ -102,9 +102,9 @@ handler.setLevel(logging.DEBUG) _logger.addHandler(handler) -import sys, urllib, urllib2, types, copy, urlparse, \ - htmlentitydefs, re, random -from cStringIO import StringIO +import sys, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, types, copy, urllib.parse, \ + html.entities, re, random +from io import StringIO import sgmllib # monkeypatch to fix http://www.python.org/sf/803422 :-( @@ -113,7 +113,7 @@ # HTMLParser.HTMLParser is recent, so live without it if it's not available # (also, sgmllib.SGMLParser is much more tolerant of bad HTML) try: - import HTMLParser + import html.parser except ImportError: HAVE_MODULE_HTMLPARSER = oFalse else: @@ -160,7 +160,7 @@ if hasattr(query,"items"): # mapping objects - query = query.items() + query = list(query.items()) else: # it's a bother at times that strings and string-like objects are # sequences... @@ -168,7 +168,7 @@ # non-sequence items should not work with len() x = len(query) # non-empty strings will fail this - if len(query) and type(query[0]) != types.TupleType: + if len(query) and type(query[0]) != tuple: raise TypeError() # zero-length sequences of all types will get here and succeed, # but that's a minor nit - since the original implementation @@ -183,20 +183,20 @@ if not doseq: # preserve old behavior for k, v in query: - k = urllib.quote_plus(str(k)) - v = urllib.quote_plus(str(v)) + k = urllib.parse.quote_plus(str(k)) + v = urllib.parse.quote_plus(str(v)) l.append(k + '=' + v) else: for k, v in query: - k = urllib.quote_plus(str(k)) - if type(v) == types.StringType: - v = urllib.quote_plus(v) + k = urllib.parse.quote_plus(str(k)) + if type(v) == bytes: + v = urllib.parse.quote_plus(v) l.append(k + '=' + v) - elif type(v) == types.UnicodeType: + elif type(v) == str: # is there a reasonable way to convert to ASCII? # encode generates a string, but "replace" or "ignore" # lose information and "strict" can raise UnicodeError - v = urllib.quote_plus(v.encode("ASCII","replace")) + v = urllib.parse.quote_plus(v.encode("ASCII","replace")) l.append(k + '=' + v) else: try: @@ -204,12 +204,12 @@ x = len(v) except TypeError: # not a sequence - v = urllib.quote_plus(str(v)) + v = urllib.parse.quote_plus(str(v)) l.append(k + '=' + v) else: # loop over the sequence for elt in v: - l.append(k + '=' + urllib.quote_plus(str(elt))) + l.append(k + '=' + urllib.parse.quote_plus(str(elt))) return '&'.join(l) def unescape(data, entities, encoding=DEFAULT_ENCODING): @@ -239,7 +239,7 @@ name, base = data, 10 if name.startswith("x"): name, base= name[1:], 16 - uc = unichr(int(name, base)) + uc = chr(int(name, base)) if encoding is None: return uc else: @@ -250,21 +250,21 @@ return repl def get_entitydefs(): - import htmlentitydefs + import html.entities from codecs import latin_1_decode entitydefs = {} try: - htmlentitydefs.name2codepoint + html.entities.name2codepoint except AttributeError: entitydefs = {} - for name, char in htmlentitydefs.entitydefs.items(): + for name, char in list(html.entities.entitydefs.items()): uc = latin_1_decode(char)[0] if uc.startswith("") and uc.endswith(";"): uc = unescape_charref(uc[2:-1], None) entitydefs["&%s;" % name] = uc else: - for name, codepoint in htmlentitydefs.name2codepoint.items(): - entitydefs["&%s;" % name] = unichr(codepoint) + for name, codepoint in list(html.entities.name2codepoint.items()): + entitydefs["&%s;" % name] = chr(codepoint) return entitydefs @@ -286,7 +286,7 @@ def choose_boundary(): """Return a string usable as a multipart boundary.""" # follow IE and firefox - nonce = "".join([str(random.randint(0, sys.maxint-1)) for i in 0,1,2]) + nonce = "".join([str(random.randint(0, sys.maxsize-1)) for i in (0,1,2)]) return "-"*27 + nonce # This cut-n-pasted MimeWriter from standard library is here so can add @@ -448,7 +448,7 @@ if HAVE_MODULE_HTMLPARSER: SGMLLIB_PARSEERROR = sgmllib.SGMLParseError class ParseError(sgmllib.SGMLParseError, - HTMLParser.HTMLParseError, + html.parser.HTMLParseError, ): pass else: @@ -586,8 +586,8 @@ self._option = {} self._option.update(d) - if (self._optgroup and self._optgroup.has_key("disabled") and - not self._option.has_key("disabled")): + if (self._optgroup and "disabled" in self._optgroup and + "disabled" not in self._option): self._option["disabled"] = None def _end_option(self): @@ -597,9 +597,9 @@ contents = self._option.get("contents", "").strip() self._option["contents"] = contents - if not self._option.has_key("value"): + if "value" not in self._option: self._option["value"] = contents - if not self._option.has_key("label"): + if "label" not in self._option: self._option["label"] = contents # stuff dict of SELECT HTML attrs into a special private key # (gets deleted again later) @@ -687,7 +687,7 @@ else: return - if data and not map.has_key(key): + if data and key not in map: # according to # http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.1 line break # immediately after start tags or immediately before end tags must @@ -759,7 +759,7 @@ def unescape_attrs(self, attrs): #debug("%s", attrs) escaped_attrs = {} - for key, val in attrs.items(): + for key, val in list(attrs.items()): try: val.items except AttributeError: @@ -778,17 +778,17 @@ def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): raise ValueError("HTMLParser could not be imported") else: - class XHTMLCompatibleFormParser(_AbstractFormParser, HTMLParser.HTMLParser): + class XHTMLCompatibleFormParser(_AbstractFormParser, html.parser.HTMLParser): """Good for XHTML, bad for tolerance of incorrect HTML.""" # thanks to Michael Howitz for this! def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): - HTMLParser.HTMLParser.__init__(self) + html.parser.HTMLParser.__init__(self) _AbstractFormParser.__init__(self, entitydefs, encoding) def feed(self, data): try: - HTMLParser.HTMLParser.feed(self, data) - except HTMLParser.HTMLParseError, exc: + html.parser.HTMLParser.feed(self, data) + except html.parser.HTMLParseError as exc: raise ParseError(exc) def start_option(self, attrs): @@ -829,7 +829,7 @@ return attrs # ditto def close(self): - HTMLParser.HTMLParser.close(self) + html.parser.HTMLParser.close(self) self.end_body() @@ -866,7 +866,7 @@ def feed(self, data): try: sgmllib.SGMLParser.feed(self, data) - except SGMLLIB_PARSEERROR, exc: + except SGMLLIB_PARSEERROR as exc: raise ParseError(exc) def close(self): @@ -892,7 +892,7 @@ def feed(self, data): try: self.bs_base_class.feed(self, data) - except SGMLLIB_PARSEERROR, exc: + except SGMLLIB_PARSEERROR as exc: raise ParseError(exc) def close(self): self.bs_base_class.close(self) @@ -934,14 +934,14 @@ def ParseResponseEx(response, select_default=oFalse, form_parser_class=FormParser, - request_class=urllib2.Request, + request_class=urllib.request.Request, entitydefs=None, encoding=DEFAULT_ENCODING, # private - _urljoin=urlparse.urljoin, - _urlparse=urlparse.urlparse, - _urlunparse=urlparse.urlunparse, + _urljoin=urllib.parse.urljoin, + _urlparse=urllib.parse.urlparse, + _urlunparse=urllib.parse.urlunparse, ): """Identical to ParseResponse, except that: @@ -968,14 +968,14 @@ def ParseFileEx(file, base_uri, select_default=oFalse, form_parser_class=FormParser, - request_class=urllib2.Request, + request_class=urllib.request.Request, entitydefs=None, encoding=DEFAULT_ENCODING, # private - _urljoin=urlparse.urljoin, - _urlparse=urlparse.urlparse, - _urlunparse=urlparse.urlunparse, + _urljoin=urllib.parse.urljoin, + _urlparse=urllib.parse.urlparse, + _urlunparse=urllib.parse.urlunparse, ): """Identical to ParseFile, except that: @@ -1081,13 +1081,13 @@ select_default=oFalse, ignore_errors=oFalse, form_parser_class=FormParser, - request_class=urllib2.Request, + request_class=urllib.request.Request, entitydefs=None, backwards_compat=oTrue, encoding=DEFAULT_ENCODING, - _urljoin=urlparse.urljoin, - _urlparse=urlparse.urlparse, - _urlunparse=urlparse.urlunparse, + _urljoin=urllib.parse.urljoin, + _urlparse=urllib.parse.urlparse, + _urlunparse=urllib.parse.urlunparse, ): if backwards_compat: deprecation("operating in backwards-compatibility mode", 1) @@ -1096,7 +1096,7 @@ data = file.read(CHUNK) try: fp.feed(data) - except ParseError, e: + except ParseError as e: e.base_uri = base_uri raise if len(data) != CHUNK: break @@ -1310,16 +1310,16 @@ self.__dict__["type"] = type.lower() self.__dict__["name"] = name self._value = attrs.get("value") - self.disabled = attrs.has_key("disabled") - self.readonly = attrs.has_key("readonly") + self.disabled = "disabled" in attrs + self.readonly = "readonly" in attrs self.id = attrs.get("id") self.attrs = attrs.copy() self._clicked = oFalse - self._urlparse = urlparse.urlparse - self._urlunparse = urlparse.urlunparse + self._urlparse = urllib.parse.urlparse + self._urlunparse = urllib.parse.urlunparse def __getattr__(self, name): if name == "value": @@ -1531,7 +1531,7 @@ def _totally_ordered_pairs(self): return [] - def _click(self, form, coord, return_type, request_class=urllib2.Request): + def _click(self, form, coord, return_type, request_class=urllib.request.Request): # Relative URL for ISINDEX submission: instead of "foo=bar+baz", # want "bar+baz". # This doesn't seem to be specified in HTML 4.01 spec. (ISINDEX is @@ -1539,7 +1539,7 @@ # Submission of ISINDEX is explained in the HTML 3.2 spec, though. parts = self._urlparse(form.action) rest, (query, frag) = parts[:-2], parts[-2:] - parts = rest + (urllib.quote_plus(self.value), None) + parts = rest + (urllib.parse.quote_plus(self.value), None) url = self._urlunparse(parts) req_data = url, None, [] @@ -1611,7 +1611,7 @@ "_labels": label and [label] or [], "attrs": attrs, "_control": control, - "disabled": attrs.has_key("disabled"), + "disabled": "disabled" in attrs, "_selected": oFalse, "id": attrs.get("id"), "_index": index, @@ -1665,7 +1665,7 @@ def __repr__(self): # XXX appending the attrs without distinguishing them from name and id # is silly - attrs = [("name", self.name), ("id", self.id)]+self.attrs.items() + attrs = [("name", self.name), ("id", self.id)]+list(self.attrs.items()) return "<%s %s>" % ( self.__class__.__name__, " ".join(["%s=%r" % (k, v) for k, v in attrs]) @@ -1673,7 +1673,7 @@ def disambiguate(items, nr, **kwds): msgs = [] - for key, value in kwds.items(): + for key, value in list(kwds.items()): msgs.append("%s=%r" % (key, value)) msg = " ".join(msgs) if not items: @@ -2143,11 +2143,11 @@ item.selected and (not item.disabled or compat)] names = {} for nn in value: - if nn in names.keys(): + if nn in list(names.keys()): names[nn] += 1 else: names[nn] = 1 - for name, count in names.items(): + for name, count in list(names.items()): on, off = self._get_items(name, count) for i in range(count): if on: @@ -2279,7 +2279,7 @@ called_as_base_class=oTrue, index=index) self.__dict__["multiple"] = oFalse o = Item(self, attrs, index) - o.__dict__["_selected"] = attrs.has_key("checked") + o.__dict__["_selected"] = "checked" in attrs def fixup(self): ListControl.fixup(self) @@ -2312,7 +2312,7 @@ called_as_base_class=oTrue, index=index) self.__dict__["multiple"] = oTrue o = Item(self, attrs, index) - o.__dict__["_selected"] = attrs.has_key("checked") + o.__dict__["_selected"] = "checked" in attrs def get_labels(self): return [] @@ -2380,7 +2380,7 @@ self.attrs = attrs["__select"].copy() self.__dict__["_label"] = _get_label(self.attrs) self.__dict__["id"] = self.attrs.get("id") - self.__dict__["multiple"] = self.attrs.has_key("multiple") + self.__dict__["multiple"] = "multiple" in self.attrs # the majority of the contents, label, and value dance already happened contents = attrs.get("contents") attrs = attrs.copy() @@ -2388,12 +2388,12 @@ ListControl.__init__(self, type, name, self.attrs, select_default, called_as_base_class=oTrue, index=index) - self.disabled = self.attrs.has_key("disabled") - self.readonly = self.attrs.has_key("readonly") - if attrs.has_key("value"): + self.disabled = "disabled" in self.attrs + self.readonly = "readonly" in self.attrs + if "value" in attrs: # otherwise it is a marker 'select started' token o = Item(self, attrs, index) - o.__dict__["_selected"] = attrs.has_key("selected") + o.__dict__["_selected"] = "selected" in attrs # add 'label' label and contents label, if different. If both are # provided, the 'label' label is used for display in HTML # 4.0-compliant browsers (and any lower spec? not sure) while the @@ -2458,7 +2458,7 @@ def is_of_kind(self, kind): return kind == "clickable" - def _click(self, form, coord, return_type, request_class=urllib2.Request): + def _click(self, form, coord, return_type, request_class=urllib.request.Request): self._clicked = coord r = form._switch_click(return_type, request_class) self._clicked = oFalse @@ -2754,7 +2754,7 @@ def __init__(self, action, method="GET", enctype="application/x-www-form-urlencoded", name=None, attrs=None, - request_class=uRefactoringTool: Refactored ../python3/test/test_clientform.py rllib2.Request, + request_class=urllib.request.Request, forms=None, labels=None, id_to_labels=None, backwards_compat=True): """ @@ -2786,8 +2786,8 @@ self.backwards_compat = backwards_compat # note __setattr__ - self._urlunparse = urlparse.urlunparse - self._urlparse = urlparse.urlparse + self._urlunparse = urllib.parse.urlunparse + self._urlparse = urllib.parse.urlparse def __getattr__(self, name): if name == "backwards_compat": @@ -2893,7 +2893,7 @@ control = self.find_control(name) try: control.value = value - except AttributeError, e: + except AttributeError as e: raise ValueError(str(e)) def get_value(self, @@ -3085,7 +3085,7 @@ # Form submission methods, applying only to clickable controls. def click(self, name=None, type=None, id=None, nr=0, coord=(1,1), - request_class=urllib2.Request, + request_class=urllib.request.Request, label=None): """Return request that would result from clicking on a control. @@ -3114,7 +3114,7 @@ def click_request_data(self, name=None, type=None, id=None, nr=0, coord=(1,1), - request_class=urllib2.Request, + request_class=urllib.request.Request, label=None): """As for click method, but return a tuple (url, data, headers). @@ -3305,7 +3305,7 @@ assert oFalse def _click(self, name, type, id, label, nr, coord, return_type, - request_class=urllib2.Request): + request_class=urllib.request.Request): try: control = self._find_control( name, type, "clickable", id, label, None, nr) @@ -3377,7 +3377,7 @@ else: raise ValueError("Unknown method '%s'" % method) - def _switch_click(self, return_type, request_class=urllib2.Request): + def _switch_click(self, return_type, request_class=urllib.request.Request): # This is called by HTMLForm and clickable Controls to hide switching # on return_type. if return_type == "pairs": --- ../python3/test/test_clientform.py (original) +++ ../python3/test/test_clientform.py (refactored) @@ -8,7 +8,7 @@ import unittest, string from unittest import TestCase -from cStringIO import StringIO +from io import StringIO import ClientForm from ClientForm import ControlNotFoundError, ItemNotFoundError, \ @@ -107,13 +107,13 @@ def test_unescape_charref(self): from ClientForm import unescape_charref, get_entitydefs - mdash_utf8 = u"\u2014".encode("utf-8") + mdash_utf8 = "\u2014".encode("utf-8") for ref, codepoint, utf8, latin1 in [ - ("38", 38, u"&".encode("utf-8"), "&"), + ("38", 38, "&".encode("utf-8"), "&"), ("x2014", 0x2014, mdash_utf8, "—"), ("8212", 8212, mdash_utf8, "—"), ]: - self.assertEqual(unescape_charref(ref, None), unichr(codepoint)) + self.assertEqual(unescape_charref(ref, None), chr(codepoint)) self.assertEqual(unescape_charref(ref, 'latin-1'), latin1) self.assertEqual(unescape_charref(ref, 'utf-8'), utf8) @@ -121,19 +121,19 @@ from ClientForm import get_entitydefs ed = get_entitydefs() for name, char in [ - ("&", u"&"), - ("<", u"<"), - (">", u">"), - ("—", u"\u2014"), - ("♠", u"\u2660"), + ("&", "&"), + ("<", "<"), + (">", ">"), + ("—", "\u2014"), + ("♠", "\u2660"), ]: self.assertEqual(ed[name], char) def test_unescape1(self): - import htmlentitydefs + import html.entities from ClientForm import unescape, get_entitydefs data = "& < — — —" - mdash_utf8 = u"\u2014".encode("utf-8") + mdash_utf8 = "\u2014".encode("utf-8") ue = unescape(data, get_entitydefs(), "utf-8") self.assertEqual("& < %s %s %s" % ((mdash_utf8,)*3), ue) @@ -160,7 +160,7 @@ self.assertEqual(unescape("&", {}), "&") for encoding, expected in [ - ("utf-8", u"&\u06aa\u2014\u2014".encode("utf-8")), + ("utf-8", "&\u06aa\u2014\u2014".encode("utf-8")), ("latin-1", "&ڪ——")]: self.assertEqual( expected, @@ -175,7 +175,7 @@ forms = ClientForm.ParseFile(file, "http://localhost/", backwards_compat=False, encoding="utf-8") form = forms[0] - test_string = "&"+(u"\u2014".encode('utf8')*3) + test_string = "&"+("\u2014".encode('utf8')*3) self.assertEqual(form.action, "http://localhost/"+test_string) control = form.find_control(type="textarea", nr=0) self.assertEqual(control.value, "val"+test_string) @@ -193,7 +193,7 @@ forms = ClientForm.ParseFileEx( f, "http://localhost/", encoding="utf-8") form = forms[1] - test_string = "&"+(u"\u2014".encode('utf8')*3) + test_string = "&"+("\u2014".encode('utf8')*3) control = form.find_control(nr=0) for ii in range(len(control.items)): item = control.items[ii] @@ -221,7 +221,7 @@ def testEmptyParse(self): forms = ClientForm.ParseFile(StringIO(""), "http://localhost", backwards_compat=False) - self.assert_(len(forms) == 0) + self.assertTrue(len(forms) == 0) def _forms(self): file = StringIO("""