<86>Mar 12 01:25:19 userdel[69017]: delete user 'rooter' <86>Mar 12 01:25:19 userdel[69017]: removed group 'rooter' owned by 'rooter' <86>Mar 12 01:25:19 userdel[69017]: removed shadow group 'rooter' owned by 'rooter' <86>Mar 12 01:25:19 groupadd[69042]: group added to /etc/group: name=rooter, GID=657 <86>Mar 12 01:25:19 groupadd[69042]: group added to /etc/gshadow: name=rooter <86>Mar 12 01:25:19 groupadd[69042]: new group: name=rooter, GID=657 <86>Mar 12 01:25:19 useradd[69054]: new user: name=rooter, UID=657, GID=657, home=/root, shell=/bin/bash <86>Mar 12 01:25:19 userdel[69079]: delete user 'builder' <86>Mar 12 01:25:19 userdel[69079]: removed group 'builder' owned by 'builder' <86>Mar 12 01:25:19 userdel[69079]: removed shadow group 'builder' owned by 'builder' <86>Mar 12 01:25:19 groupadd[69100]: group added to /etc/group: name=builder, GID=658 <86>Mar 12 01:25:19 groupadd[69100]: group added to /etc/gshadow: name=builder <86>Mar 12 01:25:19 groupadd[69100]: new group: name=builder, GID=658 <86>Mar 12 01:25:19 useradd[69111]: new user: name=builder, UID=658, GID=658, home=/usr/src, shell=/bin/bash <13>Mar 12 01:25:22 rpmi: libgdbm-1.8.3-alt10 1454943313 installed <13>Mar 12 01:25:22 rpmi: libexpat-2.2.4-alt1 1503305341 installed <13>Mar 12 01:25:22 rpmi: libtasn1-4.13-alt2 1521133848 installed <13>Mar 12 01:25:22 rpmi: libp11-kit-0.23.9-alt5 1525798241 installed <13>Mar 12 01:25:22 rpmi: rpm-macros-alternatives-0.5.0-alt1 sisyphus+221902.300.4.1 1550587121 installed <13>Mar 12 01:25:22 rpmi: alternatives-0.5.0-alt1 sisyphus+221902.300.4.1 1550587121 installed <13>Mar 12 01:25:22 rpmi: ca-certificates-2019.02.01-alt1 sisyphus+220384.200.1.1 1549032756 installed <13>Mar 12 01:25:22 rpmi: ca-trust-0.1.1-alt2 1515595785 installed <13>Mar 12 01:25:22 rpmi: p11-kit-trust-0.23.9-alt5 1525798241 installed <13>Mar 12 01:25:22 rpmi: libcrypto1.1-1.1.0j-alt2 sisyphus+223638.100.2.1 1551791039 installed <13>Mar 12 01:25:22 rpmi: libssl1.1-1.1.0j-alt2 sisyphus+223638.100.2.1 1551791039 installed <13>Mar 12 01:25:22 rpmi: python3-3.6.8-alt1 sisyphus+220164.200.3.1 1548842470 installed <13>Mar 12 01:25:23 rpmi: python3-base-3.6.8-alt1 sisyphus+220164.200.3.1 1548842470 installed <13>Mar 12 01:25:23 rpmi: libpython3-3.6.8-alt1 sisyphus+220164.200.3.1 1548842470 installed <13>Mar 12 01:25:23 rpmi: tests-for-installed-python3-pkgs-0.1.13.1-alt2 1535450458 installed <13>Mar 12 01:25:23 rpmi: rpm-build-python3-0.1.13.1-alt2 1535450458 installed <13>Mar 12 01:25:27 rpmi: libtinfo-devel-6.1.20180407-alt2 sisyphus+222164.200.1.1 1550686221 installed <13>Mar 12 01:25:27 rpmi: libncurses-devel-6.1.20180407-alt2 sisyphus+222164.200.1.1 1550686221 installed <13>Mar 12 01:25:27 rpmi: python-modules-curses-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: libverto-0.3.0-alt1_7 sisyphus+223221.100.1.1 1551348952 installed <13>Mar 12 01:25:27 rpmi: libkeyutils-1.6-alt2 sisyphus.217337.100 1544003165 installed <13>Mar 12 01:25:27 rpmi: libcom_err-1.44.6-alt1 sisyphus+224154.100.1.1 1552091653 installed <86>Mar 12 01:25:27 groupadd[98281]: group added to /etc/group: name=_keytab, GID=499 <86>Mar 12 01:25:27 groupadd[98281]: group added to /etc/gshadow: name=_keytab <86>Mar 12 01:25:27 groupadd[98281]: new group: name=_keytab, GID=499 <13>Mar 12 01:25:27 rpmi: libkrb5-1.16.3-alt1 sisyphus+223678.100.1.1 1551746443 installed <13>Mar 12 01:25:27 rpmi: libtirpc-1.0.3-alt1 1532008015 installed <13>Mar 12 01:25:27 rpmi: libnsl2-1.1.0-alt1_1 1511548748 installed <13>Mar 12 01:25:27 rpmi: python-modules-email-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-unittest-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-nis-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-encodings-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-compiler-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-xml-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-hotshot-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-bsddb-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-ctypes-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-multiprocessing-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-logging-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-modules-distutils-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: libnsl2-devel-1.1.0-alt1_1 1511548748 installed <13>Mar 12 01:25:27 rpmi: python-dev-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python-tools-2to3-2.7.15-alt1 sisyphus.217364.100 1544022396 installed <13>Mar 12 01:25:27 rpmi: python3-dev-3.6.8-alt1 sisyphus+220164.200.3.1 1548842470 installed <13>Mar 12 01:25:27 rpmi: python3-module-sgmllib-1.0.0-alt1.hg20100824.1.1.2 1526978038 installed Building target platforms: x86_64 Building for target x86_64 Wrote: /usr/src/in/nosrpm/python-module-BeautifulSoup-3.2.1-alt2.1.1.1.nosrc.rpm <13>Mar 12 01:25:30 rpmi: python3-module-pkg_resources-1:40.8.0-alt1 sisyphus+221229.100.2.1 1550559950 installed <13>Mar 12 01:25:30 rpmi: python3-module-setuptools-1:40.8.0-alt1 sisyphus+221229.100.2.1 1550559950 installed Installing python-module-BeautifulSoup-3.2.1-alt2.1.1.1.src.rpm Building target platforms: x86_64 Building for target x86_64 Executing(%prep): /bin/sh -e /usr/src/tmp/rpm-tmp.9367 + umask 022 + /bin/mkdir -p /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + rm -rf BeautifulSoup-3.2.1 + echo 'Source #0 (BeautifulSoup-3.2.1.tar.bz2):' Source #0 (BeautifulSoup-3.2.1.tar.bz2): + /bin/bzip2 -dc /usr/src/RPM/SOURCES/BeautifulSoup-3.2.1.tar.bz2 + /bin/tar -xf - + cd BeautifulSoup-3.2.1 + /bin/chmod -c -Rf u+rwX,go-w . + rm -rf ../python3 + cp -a . ../python3 + exit 0 Executing(%build): /bin/sh -e /usr/src/tmp/rpm-tmp.63379 + umask 022 + /bin/mkdir -p /usr/src/RPM/BUILD + cd /usr/src/RPM/BUILD + cd BeautifulSoup-3.2.1 + export LC_ALL=en_US.UTF-8 + LC_ALL=en_US.UTF-8 + CFLAGS='-pipe -frecord-gcc-switches -Wall -g -O2' + python setup.py build running build running build_py creating build creating build/lib copying BeautifulSoup.py -> build/lib copying BeautifulSoupTests.py -> build/lib + pushd ../python3 ~/RPM/BUILD/python3 ~/RPM/BUILD/BeautifulSoup-3.2.1 + for i in *.py + 2to3 -w BeautifulSoup.py RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored BeautifulSoup.py --- BeautifulSoup.py (original) +++ BeautifulSoup.py (refactored) @@ -76,7 +76,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE, DAMMIT. """ -from __future__ import generators + __author__ = "Leonard Richardson (leonardr@segfault.org)" __version__ = "3.2.1" @@ -85,12 +85,12 @@ from sgmllib import SGMLParser, SGMLParseError import codecs -import markupbase +import _markupbase import types import re import sgmllib try: - from htmlentitydefs import name2codepoint + from html.entities import name2codepoint except ImportError: name2codepoint = {} try: @@ -100,7 +100,7 @@ #These hacks make Beautiful Soup able to parse XML with namespaces sgmllib.tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*') -markupbase._declname_match = re.compile(r'[a-zA-Z][-_.:a-zA-Z0-9]*\s*').match +_markupbase._declname_match = re.compile(r'[a-zA-Z][-_.:a-zA-Z0-9]*\s*').match DEFAULT_OUTPUT_ENCODING = "utf-8" @@ -117,7 +117,7 @@ def _invert(h): "Cheap function to invert a hash." i = {} - for k,v in h.items(): + for k,v in list(h.items()): i[v] = k return i @@ -177,7 +177,7 @@ #this element (and any children) hadn't been parsed. Connect #the two. lastChild = self._lastRecursiveChild() - nextElement = lastChild.next + nextElement = lastChild.__next__ if self.previous: self.previous.next = nextElement @@ -202,7 +202,7 @@ return lastChild def insert(self, position, newChild): - if isinstance(newChild, basestring) \ + if isinstance(newChild, str) \ and not isinstance(newChild, NavigableString): newChild = NavigableString(newChild) @@ -256,7 +256,7 @@ newChild.nextSibling.previousSibling = newChild newChildsLastElement.next = nextChild - if newChildsLastElement.next: + if newChildsLastElement.__next__: newChildsLastElement.next.previous = newChildsLastElement self.contents.insert(position, newChild) @@ -357,7 +357,7 @@ return [element for element in generator() if isinstance(element, Tag)] # findAll*('tag-name') - elif isinstance(name, basestring): + elif isinstance(name, str): return [element for element in generator() if isinstance(element, Tag) and element.name == name] @@ -370,7 +370,7 @@ g = generator() while True: try: - i = g.next() + i = next(g) except StopIteration: break if i: @@ -386,7 +386,7 @@ def nextGenerator(self): i = self while i is not None: - i = i.next + i = i.__next__ yield i def nextSiblingGenerator(self): @@ -421,19 +421,19 @@ def toEncoding(self, s, encoding=None): """Encodes an object to a string in some encoding, or to Unicode. .""" - if isinstance(s, unicode): + if isinstance(s, str): if encoding: s = s.encode(encoding) elif isinstance(s, str): if encoding: s = s.encode(encoding) else: - s = unicode(s) + s = str(s) else: if encoding: s = self.toEncoding(str(s), encoding) else: - s = unicode(s) + s = str(s) return s BARE_AMPERSAND_OR_BRACKET = re.compile("([<>]|" @@ -446,7 +446,7 @@ return "&" + self.XML_SPECIAL_CHARS_TO_ENTITIES[x.group(0)[0]] + ";" -class NavigableString(unicode, PageElement): +class NavigableString(str, PageElement): def __new__(cls, value): """Create a new NavigableString. @@ -456,9 +456,9 @@ passed in to the superclass's __new__ or the superclass won't know how to handle non-ASCII characters. """ - if isinstance(value, unicode): - return unicode.__new__(cls, value) - return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) + if isinstance(value, str): + return str.__new__(cls, value) + return str.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) def __getnewargs__(self): return (NavigableString.__str__(self),) @@ -470,7 +470,7 @@ if attr == 'string': return self else: - raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) + raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)) def __unicode__(self): return str(self).decode(DEFAULT_OUTPUT_ENCODING) @@ -514,23 +514,23 @@ escaped.""" x = match.group(1) if self.convertHTMLEntities and x in name2codepoint: - return unichr(name2codepoint[x]) + return chr(name2codepoint[x]) elif x in self.XML_ENTITIES_TO_SPECIAL_CHARS: if self.convertXMLEntities: return self.XML_ENTITIES_TO_SPECIAL_CHARS[x] else: - return u'&%s;' % x + return '&%s;' % x elif len(x) > 0 and x[0] == '#': # Handle numeric entities if len(x) > 1 and x[1] == 'x': - return unichr(int(x[2:], 16)) + return chr(int(x[2:], 16)) else: - return unichr(int(x[1:])) + return chr(int(x[1:])) elif self.escapeUnrecognizedEntities: - return u'&%s;' % x + return '&%s;' % x else: - return u'&%s;' % x + return '&%s;' % x def __init__(self, parser, name, attrs=None, parent=None, previous=None): @@ -544,7 +544,7 @@ if attrs is None: attrs = [] elif isinstance(attrs, dict): - attrs = attrs.items() + attrs = list(attrs.items()) self.attrs = attrs self.contents = [] self.setup(parent, previous) @@ -555,11 +555,11 @@ self.escapeUnrecognizedEntities = parser.escapeUnrecognizedEntities # Convert any HTML, XML, or numeric entities in the attribute values. - convert = lambda(k, val): (k, + convert = lambda k_val: (k_val[0], re.sub("&(#\d+|#x[0-9a-fA-F]+|\w+);", self._convertEntities, - val)) - self.attrs = map(convert, self.attrs) + k_val[1])) + self.attrs = list(map(convert, self.attrs)) def getString(self): if (len(self.contents) == 1 @@ -573,16 +573,16 @@ string = property(getString, setString) - def getText(self, separator=u""): + def getText(self, separator=""): if not len(self.contents): - return u"" - stopNode = self._lastRecursiveChild().next + return "" + stopNode = self._lastRecursiveChild().__next__ strings = [] current = self.contents[0] while current is not stopNode: if isinstance(current, NavigableString): strings.append(current.strip()) - current = current.next + current = current.__next__ return separator.join(strings) text = property(getText) @@ -605,7 +605,7 @@ raise ValueError("Tag.index: element not in tag") def has_key(self, key): - return self._getAttrMap().has_key(key) + return key in self._getAttrMap() def __getitem__(self, key): """tag[key] returns the value of the 'key' attribute for the tag, @@ -623,7 +623,7 @@ def __contains__(self, x): return x in self.contents - def __nonzero__(self): + def __bool__(self): "A tag is non-None even if it has no contents." return True @@ -649,14 +649,14 @@ #We don't break because bad HTML can define the same #attribute multiple times. self._getAttrMap() - if self.attrMap.has_key(key): + if key in self.attrMap: del self.attrMap[key] def __call__(self, *args, **kwargs): """Calling a tag like a function is the same as calling its findAll() method. Eg. tag('a') returns a list of all the A tags found within this tag.""" - return apply(self.findAll, args, kwargs) + return self.findAll(*args, **kwargs) def __getattr__(self, tag): #print "Getattr %s.%s" % (self.__class__, tag) @@ -664,7 +664,7 @@ return self.find(tag[:-3]) elif tag.find('__') != 0: return self.find(tag) - raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__, tag) + raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__, tag)) def __eq__(self, other): """Returns true iff this tag has the same name, the same attributes, @@ -708,7 +708,7 @@ if self.attrs: for key, val in self.attrs: fmt = '%s="%s"' - if isinstance(val, basestring): + if isinstance(val, str): if self.containsSubstitutions and '%SOUP-ENCODING%' in val: val = self.substituteEncoding(val, encoding) @@ -785,7 +785,7 @@ return current = self.contents[0] while current is not None: - next = current.next + next = current.__next__ if isinstance(current, Tag): del current.contents[:] current.parent = None @@ -878,11 +878,11 @@ def recursiveChildGenerator(self): if not len(self.contents): raise StopIteration - stopNode = self._lastRecursiveChild().next + stopNode = self._lastRecursiveChild().__next__ current = self.contents[0] while current is not stopNode: yield current - current = current.next + current = current.__next__ # Next, a couple classes to represent queries and their results. @@ -892,7 +892,7 @@ def __init__(self, name=None, attrs={}, text=None, **kwargs): self.name = name - if isinstance(attrs, basestring): + if isinstance(attrs, str): kwargs['class'] = _match_css_class(attrs) attrs = None if kwargs: @@ -928,7 +928,7 @@ else: match = True markupAttrMap = None - for attr, matchAgainst in self.attrs.items(): + for attr, matchAgainst in list(self.attrs.items()): if not markupAttrMap: if hasattr(markupAttrs, 'get'): markupAttrMap = markupAttrs @@ -966,12 +966,12 @@ found = self.searchTag(markup) # If it's text, make sure the text matches. elif isinstance(markup, NavigableString) or \ - isinstance(markup, basestring): + isinstance(markup, str): if self._matches(markup, self.text): found = markup else: - raise Exception, "I don't know how to match against a %s" \ - % markup.__class__ + raise Exception("I don't know how to match against a %s" \ + % markup.__class__) return found def _matches(self, markup, matchAgainst): @@ -986,8 +986,8 @@ #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name - if markup and not isinstance(markup, basestring): - markup = unicode(markup) + if markup and not isinstance(markup, str): + markup = str(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. @@ -995,10 +995,10 @@ elif hasattr(matchAgainst, '__iter__'): # list-like result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): - result = markup.has_key(matchAgainst) - elif matchAgainst and isinstance(markup, basestring): - if isinstance(markup, unicode): - matchAgainst = unicode(matchAgainst) + result = matchAgainst in markup + elif matchAgainst and isinstance(markup, str): + if isinstance(markup, str): + matchAgainst = str(matchAgainst) else: matchAgainst = str(matchAgainst) @@ -1023,7 +1023,7 @@ for portion in args: if hasattr(portion, 'items'): #It's a map. Merge it. - for k,v in portion.items(): + for k,v in list(portion.items()): built[k] = v elif hasattr(portion, '__iter__'): # is a list #It's a list. Map each item to the default. @@ -1066,7 +1066,7 @@ lambda x: '') ] - ROOT_TAG_NAME = u'[document]' + ROOT_TAG_NAME = '[document]' HTML_ENTITIES = "html" XML_ENTITIES = "xml" @@ -1162,14 +1162,14 @@ def _feed(self, inDocumentEncoding=None, isHTML=False): # Convert the document to Unicode. markup = self.markup - if isinstance(markup, unicode): + if isinstance(markup, str): if not hasattr(self, 'originalEncoding'): self.originalEncoding = None else: dammit = UnicodeDammit\ (markup, [self.fromEncoding, inDocumentEncoding], smartQuotesTo=self.smartQuotesTo, isHTML=isHTML) - markup = dammit.unicode + markup = dammit.str self.originalEncoding = dammit.originalEncoding self.declaredHTMLEncoding = dammit.declaredHTMLEncoding if markup: @@ -1208,8 +1208,8 @@ def isSelfClosingTag(self, name): """Returns true iff the given string is the name of a self-closing tag according to this parser.""" - return self.SELF_CLOSING_TAGS.has_key(name) \ - or self.instanceSelfClosingTags.has_key(name) + return name in self.SELF_CLOSING_TAGS \ + or name in self.instanceSelfClosingTags def reset(self): Tag.__init__(self, self, self.ROOT_TAG_NAME) @@ -1238,7 +1238,7 @@ def endData(self, containerClass=NavigableString): if self.currentData: - currentData = u''.join(self.currentData) + currentData = ''.join(self.currentData) if (currentData.translate(self.STRIP_ASCII_SPACES) == '' and not set([tag.name for tag in self.tagStack]).intersection( self.PRESERVE_WHITESPACE_TAGS)): @@ -1301,7 +1301,7 @@ nestingResetTriggers = self.NESTABLE_TAGS.get(name) isNestable = nestingResetTriggers != None - isResetNesting = self.RESET_NESTING_TAGS.has_key(name) + isResetNesting = name in self.RESET_NESTING_TAGS popTo = None inclusive = True for i in range(len(self.tagStack)-1, 0, -1): @@ -1314,7 +1314,7 @@ if (nestingResetTriggers is not None and p.name in nestingResetTriggers) \ or (nestingResetTriggers is None and isResetNesting - and self.RESET_NESTING_TAGS.has_key(p.name)): + and p.name in self.RESET_NESTING_TAGS): #If we encounter one of the nesting reset triggers #peculiar to this tag, or we encounter another tag @@ -1385,7 +1385,7 @@ object, possibly one with a %SOUP-ENCODING% slot into which an encoding will be plugged later.""" if text[:3] == "xml": - text = u"xml version='1.0' encoding='%SOUP-ENCODING%'" + text = "xml version='1.0' encoding='%SOUP-ENCODING%'" self._toStringSubclass(text, ProcessingInstruction) def handle_comment(self, text): @@ -1395,7 +1395,7 @@ def handle_charref(self, ref): "Handle character references as data." if self.convertEntities: - data = unichr(int(ref)) + data = chr(int(ref)) else: data = '&#%s;' % ref self.handle_data(data) @@ -1407,7 +1407,7 @@ data = None if self.convertHTMLEntities: try: - data = unichr(name2codepoint[ref]) + data = chr(name2codepoint[ref]) except KeyError: pass @@ -1516,7 +1516,7 @@ BeautifulStoneSoup before writing your own subclass.""" def __init__(self, *args, **kwargs): - if not kwargs.has_key('smartQuotesTo'): + if 'smartQuotesTo' not in kwargs: kwargs['smartQuotesTo'] = self.HTML_ENTITIES kwargs['isHTML'] = True BeautifulStoneSoup.__init__(self, *args, **kwargs) @@ -1699,7 +1699,7 @@ parent._getAttrMap() if (isinstance(tag, Tag) and len(tag.contents) == 1 and isinstance(tag.contents[0], NavigableString) and - not parent.attrMap.has_key(tag.name)): + tag.name not in parent.attrMap): parent[tag.name] = tag.contents[0] BeautifulStoneSoup.popTag(self) @@ -1773,9 +1773,9 @@ self._detectEncoding(markup, isHTML) self.smartQuotesTo = smartQuotesTo self.triedEncodings = [] - if markup == '' or isinstance(markup, unicode): + if markup == '' or isinstance(markup, str): self.originalEncoding = None - self.unicode = unicode(markup) + self.str = str(markup) return u = None @@ -1788,7 +1788,7 @@ if u: break # If no luck and we have auto-detection library, try that: - if not u and chardet and not isinstance(self.markup, unicode): + if not u and chardet and not isinstance(self.markup, str): u = self._convertFrom(chardet.detect(self.markup)['encoding']) # As a last resort, try utf-8 and windows-1252: @@ -1797,7 +1797,7 @@ u = self._convertFrom(proposed_encoding) if u: break - self.unicode = u + self.str = u if not u: self.originalEncoding = None def _subMSChar(self, orig): @@ -1824,7 +1824,7 @@ "iso-8859-1", "iso-8859-2"): markup = re.compile("([\x80-\x9f])").sub \ - (lambda(x): self._subMSChar(x.group(1)), + (lambda x: self._subMSChar(x.group(1)), markup) try: @@ -1832,7 +1832,7 @@ u = self._toUnicode(markup, proposed) self.markup = u self.originalEncoding = proposed - except Exception, e: + except Exception as e: # print "That didn't work!" # print e return None @@ -1861,7 +1861,7 @@ elif data[:4] == '\xff\xfe\x00\x00': encoding = 'utf-32le' data = data[4:] - newdata = unicode(data, encoding) + newdata = str(data, encoding) return newdata def _detectEncoding(self, xml_data, isHTML=False): @@ -1874,41 +1874,41 @@ elif xml_data[:4] == '\x00\x3c\x00\x3f': # UTF-16BE sniffed_xml_encoding = 'utf-16be' - xml_data = unicode(xml_data, 'utf-16be').encode('utf-8') + xml_data = str(xml_data, 'utf-16be').encode('utf-8') elif (len(xml_data) >= 4) and (xml_data[:2] == '\xfe\xff') \ and (xml_data[2:4] != '\x00\x00'): # UTF-16BE with BOM sniffed_xml_encoding = 'utf-16be' - xml_data = unicode(xml_data[2:], 'utf-16be').encode('utf-8') + xml_data = str(xml_data[2:], 'utf-16be').encode('utf-8') elif xml_datRefactoringTool: Files that were modified: RefactoringTool: BeautifulSoup.py a[:4] == '\x3c\x00\x3f\x00': # UTF-16LE sniffed_xml_encoding = 'utf-16le' - xml_data = unicode(xml_data, 'utf-16le').encode('utf-8') + xml_data = str(xml_data, 'utf-16le').encode('utf-8') elif (len(xml_data) >= 4) and (xml_data[:2] == '\xff\xfe') and \ (xml_data[2:4] != '\x00\x00'): # UTF-16LE with BOM sniffed_xml_encoding = 'utf-16le' - xml_data = unicode(xml_data[2:], 'utf-16le').encode('utf-8') + xml_data = str(xml_data[2:], 'utf-16le').encode('utf-8') elif xml_data[:4] == '\x00\x00\x00\x3c': # UTF-32BE sniffed_xml_encoding = 'utf-32be' - xml_data = unicode(xml_data, 'utf-32be').encode('utf-8') + xml_data = str(xml_data, 'utf-32be').encode('utf-8') elif xml_data[:4] == '\x3c\x00\x00\x00': # UTF-32LE sniffed_xml_encoding = 'utf-32le' - xml_data = unicode(xml_data, 'utf-32le').encode('utf-8') + xml_data = str(xml_data, 'utf-32le').encode('utf-8') elif xml_data[:4] == '\x00\x00\xfe\xff': # UTF-32BE with BOM sniffed_xml_encoding = 'utf-32be' - xml_data = unicode(xml_data[4:], 'utf-32be').encode('utf-8') + xml_data = str(xml_data[4:], 'utf-32be').encode('utf-8') elif xml_data[:4] == '\xff\xfe\x00\x00': # UTF-32LE with BOM sniffed_xml_encoding = 'utf-32le' - xml_data = unicode(xml_data[4:], 'utf-32le').encode('utf-8') + xml_data = str(xml_data[4:], 'utf-32le').encode('utf-8') elif xml_data[:3] == '\xef\xbb\xbf': # UTF-8 with BOM sniffed_xml_encoding = 'utf-8' - xml_data = unicode(xml_data[3:], 'utf-8').encode('utf-8') + xml_data = str(xml_data[3:], 'utf-8').encode('utf-8') else: sniffed_xml_encoding = 'ascii' pass @@ -1971,7 +1971,7 @@ 250,251,252,253,254,255) import string c.EBCDIC_TO_ASCII_MAP = string.maketrans( \ - ''.join(map(chr, range(256))), ''.join(map(chr, emap))) + ''.join(map(chr, list(range(256)))), ''.join(map(chr, emap))) return s.translate(c.EBCDIC_TO_ASCII_MAP) MS_CHARS = { '\x80' : ('euro', '20AC'), @@ -2014,4 +2014,4 @@ if __name__ == '__main__': import sys soup = BeautifulSoup(sys.stdin) - print soup.prettify() + print(soup.prettify()) + for i in *.py + 2to3 -w BeautifulSoupTests.py RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored BeautifulSoupTests.py --- BeautifulSoupTests.py (original) +++ BeautifulSoupTests.py (refactored) @@ -82,7 +82,7 @@ def testFindAllText(self): soup = BeautifulSoup("\xbb") self.assertEqual(soup.findAll(text=re.compile('.*')), - [u'\xbb']) + ['\xbb']) def testFindAllByRE(self): import re @@ -123,26 +123,26 @@ def testParents(self): soup = BeautifulSoup('