sgmllib3k-1.0.0/0000755000000000000240000000000011434736060013467 5ustar rootstaff00000000000000sgmllib3k-1.0.0/PKG-INFO0000644000000000000240000000163611434736060014572 0ustar rootstaff00000000000000Metadata-Version: 1.0 Name: sgmllib3k Version: 1.0.0 Summary: Py3k port of sgmllib. Home-page: http://hg.hardcoded.net/sgmllib Author: Hardcoded Software Author-email: hsoft@hardcoded.net License: BSD License Description: ================================================== sgmllib3k -- Py3k port of the old stdlib module ================================================== sgmllib was dropped in Python 3. For those depending on it, that's somewhat infortunate. This is a quick and dirty port of this old module. I just ran 2to3 on it and published it. I don't indend to maintain it, so it might be a good idea to eventually think about finding another module to use. Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python :: 3 sgmllib3k-1.0.0/README0000644000076500000240000000067611434722102014532 0ustar hsoftstaff00000000000000================================================== sgmllib3k -- Py3k port of the old stdlib module ================================================== sgmllib was dropped in Python 3. For those depending on it, that's somewhat infortunate. This is a quick and dirty port of this old module. I just ran 2to3 on it and published it. I don't indend to maintain it, so it might be a good idea to eventually think about finding another module to use. sgmllib3k-1.0.0/setup.cfg0000644000000000000240000000007311434736060015310 0ustar rootstaff00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 sgmllib3k-1.0.0/setup.py0000644000076500000240000000114311434722435015363 0ustar hsoftstaff00000000000000from setuptools import setup CLASSIFIERS = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 3', ] setup( name='sgmllib3k', version='1.0.0', author='Hardcoded Software', author_email='hsoft@hardcoded.net', py_modules=['sgmllib'], scripts=[], url='http://hg.hardcoded.net/sgmllib', license='BSD License', description='Py3k port of sgmllib.', long_description=open('README').read(), classifiers=CLASSIFIERS, test_suite='test_sgmllib', )sgmllib3k-1.0.0/sgmllib.py0000644000076500000240000004257411434722336015671 0ustar hsoftstaff00000000000000"""A parser for SGML, using the derived class as a static DTD.""" # XXX This only supports those SGML features used by HTML. # XXX There should be a way to distinguish between PCDATA (parsed # character data -- the normal case), RCDATA (replaceable character # data -- only char and entity references and end tags are special) # and CDATA (character data -- only end tags are special). RCDATA is # not supported at all. import _markupbase import re __all__ = ["SGMLParser", "SGMLParseError"] # Regular expressions used for parsing interesting = re.compile('[&<]') incomplete = re.compile('&([a-zA-Z][a-zA-Z0-9]*|#[0-9]*)?|' '<([a-zA-Z][^<>]*|' '/([a-zA-Z][^<>]*)?|' '![^<>]*)?') entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]') charref = re.compile('&#([0-9]+)[^0-9]') starttagopen = re.compile('<[>a-zA-Z]') shorttagopen = re.compile('<[a-zA-Z][-.a-zA-Z0-9]*/') shorttag = re.compile('<([a-zA-Z][-.a-zA-Z0-9]*)/([^/]*)/') piclose = re.compile('>') endbracket = re.compile('[<>]') tagfind = re.compile('[a-zA-Z][-_.a-zA-Z0-9]*') attrfind = re.compile( r'\s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*' r'(\'[^\']*\'|"[^"]*"|[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?') class SGMLParseError(RuntimeError): """Exception raised for all parse errors.""" pass # SGML parser base class -- find tags and call handler functions. # Usage: p = SGMLParser(); p.feed(data); ...; p.close(). # The dtd is defined by deriving a class which defines methods # with special names to handle tags: start_foo and end_foo to handle # and , respectively, or do_foo to handle by itself. # (Tags are converted to lower case for this purpose.) The data # between tags is passed to the parser by calling self.handle_data() # with some data as argument (the data may be split up in arbitrary # chunks). Entity references are passed by calling # self.handle_entityref() with the entity reference as argument. class SGMLParser(_markupbase.ParserBase): # Definition of entities -- derived classes may override entity_or_charref = re.compile('&(?:' '([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+)' ')(;?)') def __init__(self, verbose=0): """Initialize and reset this instance.""" self.verbose = verbose self.reset() def reset(self): """Reset this instance. Loses all unprocessed data.""" self.__starttag_text = None self.rawdata = '' self.stack = [] self.lasttag = '???' self.nomoretags = 0 self.literal = 0 _markupbase.ParserBase.reset(self) def setnomoretags(self): """Enter literal mode (CDATA) till EOF. Intended for derived classes only. """ self.nomoretags = self.literal = 1 def setliteral(self, *args): """Enter literal mode (CDATA). Intended for derived classes only. """ self.literal = 1 def feed(self, data): """Feed some data to the parser. Call this as often as you want, with as little or as much text as you want (may include '\n'). (This just saves the text, all the processing is done by goahead().) """ self.rawdata = self.rawdata + data self.goahead(0) def close(self): """Handle the remaining data.""" self.goahead(1) def error(self, message): raise SGMLParseError(message) # Internal -- handle data as far as reasonable. May leave state # and data to be processed by a subsequent call. If 'end' is # true, force handling all data as if followed by EOF marker. def goahead(self, end): rawdata = self.rawdata i = 0 n = len(rawdata) while i < n: if self.nomoretags: self.handle_data(rawdata[i:n]) i = n break match = interesting.search(rawdata, i) if match: j = match.start() else: j = n if i < j: self.handle_data(rawdata[i:j]) i = j if i == n: break if rawdata[i] == '<': if starttagopen.match(rawdata, i): if self.literal: self.handle_data(rawdata[i]) i = i+1 continue k = self.parse_starttag(i) if k < 0: break i = k continue if rawdata.startswith(" (i + 1): self.handle_data("<") i = i+1 else: # incomplete break continue if rawdata.startswith("