<86>Apr 21 00:53:52 userdel[30042]: delete user 'rooter' <86>Apr 21 00:53:52 groupadd[30120]: group added to /etc/group: name=rooter, GID=681 <86>Apr 21 00:53:52 groupadd[30120]: group added to /etc/gshadow: name=rooter <86>Apr 21 00:53:52 groupadd[30120]: new group: name=rooter, GID=681 <86>Apr 21 00:53:52 useradd[30171]: new user: name=rooter, UID=681, GID=681, home=/root, shell=/bin/bash <86>Apr 21 00:53:52 userdel[30245]: delete user 'builder' <86>Apr 21 00:53:52 userdel[30245]: removed group 'builder' owned by 'builder' <86>Apr 21 00:53:52 userdel[30245]: removed shadow group 'builder' owned by 'builder' <86>Apr 21 00:53:52 groupadd[30315]: group added to /etc/group: name=builder, GID=682 <86>Apr 21 00:53:52 groupadd[30315]: group added to /etc/gshadow: name=builder <86>Apr 21 00:53:52 groupadd[30315]: new group: name=builder, GID=682 <86>Apr 21 00:53:52 useradd[30372]: new user: name=builder, UID=682, GID=682, home=/usr/src, shell=/bin/bash <13>Apr 21 00:53:54 rpmi: libexpat-2.2.4-alt0.M80P.1 1503871120 installed <13>Apr 21 00:53:54 rpmi: libgdbm-1.8.3-alt10 1454943313 installed <13>Apr 21 00:53:54 rpmi: libtinfo-devel-5.9-alt8 1456756459 installed <13>Apr 21 00:53:54 rpmi: libncurses-devel-5.9-alt8 1456756459 installed <13>Apr 21 00:53:54 rpmi: python-modules-curses-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:54 rpmi: libverto-0.2.6-alt1_6 1455633234 installed <13>Apr 21 00:53:54 rpmi: libkeyutils-1.5.10-alt0.M80P.2 p8+216694.100.6.1 1547827915 installed <13>Apr 21 00:53:54 rpmi: libcom_err-1.42.13-alt2 1449075846 installed <13>Apr 21 00:53:54 rpmi: ca-certificates-2016.02.25-alt1 1462368370 installed <13>Apr 21 00:53:54 rpmi: libcrypto10-1.0.2n-alt0.M80P.1 1512766129 installed <13>Apr 21 00:53:54 rpmi: libssl10-1.0.2n-alt0.M80P.1 1512766129 installed <86>Apr 21 00:53:54 groupadd[46841]: group added to /etc/group: name=_keytab, GID=499 <86>Apr 21 00:53:54 groupadd[46841]: group added to /etc/gshadow: name=_keytab <86>Apr 21 00:53:54 groupadd[46841]: new group: name=_keytab, GID=499 <13>Apr 21 00:53:55 rpmi: libkrb5-1.14.6-alt1.M80P.1 1525355673 installed <13>Apr 21 00:53:55 rpmi: python3-base-3.5.4-alt2.M80P.1 1527753911 installed <13>Apr 21 00:53:55 rpmi: python3-3.5.4-alt2.M80P.1 1527753911 installed <13>Apr 21 00:53:55 rpmi: python-modules-compiler-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:55 rpmi: rpm-build-python3-0.1.10.10-alt1.M80P.1 1530521451 installed <13>Apr 21 00:53:55 rpmi: libpython3-3.5.4-alt2.M80P.1 1527753911 installed <13>Apr 21 00:53:56 rpmi: python3-dev-3.5.4-alt2.M80P.1 1527753911 installed <13>Apr 21 00:53:56 rpmi: python3-module-sgmllib-1.0.0-alt1.hg20100824.1.1.1 1458155334 installed <13>Apr 21 00:53:56 rpmi: python-modules-email-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-unittest-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-encodings-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-xml-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-hotshot-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-bsddb-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-ctypes-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-multiprocessing-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-modules-logging-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-dev-2.7.11-alt6.M80P.1 1527682470 installed <13>Apr 21 00:53:56 rpmi: python-tools-2to3-2.7.11-alt6.M80P.1 1527682470 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.49252 + 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/tar -xf - + /bin/bzip2 -dc /usr/src/RPM/SOURCES/BeautifulSoup-3.2.1.tar.bz2 + 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.49252 + 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 -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,13 @@ from sgmllib import SGMLParser, SGMLParseError import codecs -import markupbase +import _markupbase import types import re import sgmllib +import collections try: - from htmlentitydefs import name2codepoint + from html.entities import name2codepoint except ImportError: name2codepoint = {} try: @@ -100,7 +101,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 +118,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 +178,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 +203,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 +257,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 +358,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 +371,7 @@ g = generator() while True: try: - i = g.next() + i = next(g) except StopIteration: break if i: @@ -386,7 +387,7 @@ def nextGenerator(self): i = self while i is not None: - i = i.next + i = i.__next__ yield i def nextSiblingGenerator(self): @@ -421,19 +422,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 +447,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 +457,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 +471,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 +515,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 +545,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 +556,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 +574,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 +606,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 +624,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 +650,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 +665,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 +709,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 +786,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 +879,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 +893,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: @@ -916,7 +917,7 @@ if isinstance(markupName, Tag): markup = markupName markupAttrs = markup - callFunctionWithTagData = callable(self.name) \ + callFunctionWithTagData = isinstance(self.name, collections.Callable) \ and not isinstance(markupName, Tag) if (not self.name) \ @@ -928,7 +929,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 +967,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): @@ -979,15 +980,15 @@ result = False if matchAgainst is True: result = markup is not None - elif callable(matchAgainst): + elif isinstance(matchAgainst, collections.Callable): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #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 +996,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 +1024,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 +1067,7 @@ lambda x: '') ] - ROOT_TAG_NAME = u'[document]' + ROOT_TAG_NAME = '[document]' HTML_ENTITIES = "html" XML_ENTITIES = "xml" @@ -1162,14 +1163,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 +1209,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 +1239,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 +1302,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 +1315,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 +1386,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 +1396,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 +1408,7 @@ data = None if self.convertHTMLEntities: try: - data = unichr(name2codepoint[ref]) + data = chr(name2codepoint[ref]) except KeyError: pass @@ -1516,7 +1517,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 +1700,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 +1774,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 +1789,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 +1798,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 +1825,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 +1833,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 +1862,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_RefactoringTool: Files that were modified: RefactoringTool: BeautifulSoup.py data, isHTML=False): @@ -1874,41 +1875,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_data[: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 +1972,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 +2015,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('