pytidylib-0.2.1/0000755000175000017500000000000011301050430012514 5ustar janosjanospytidylib-0.2.1/LICENSE0000644000175000017500000000203311163707615013543 0ustar janosjanosCopyright 2009 Jason Stitt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pytidylib-0.2.1/._LICENSE0000644000175000017500000000027211163707615013763 0ustar janosjanosMac OS X  2ˆºTxMtATTR\DÓº˜"˜"com.macromates.caret{ column = 0; line = 19; }pytidylib-0.2.1/tests/0000755000175000017500000000000011301050430013656 5ustar janosjanospytidylib-0.2.1/tests/._threadsafety.py0000644000175000017500000000027211166672363017161 0ustar janosjanosMac OS X  2ˆºTxMtATTR]‡º˜"˜"com.macromates.caret{ column = 0; line = 20; }pytidylib-0.2.1/tests/SinkMemTest.py0000644000175000017500000000320411166672360016457 0ustar janosjanos# Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import unittest from tidylib import tidy_document, tidy_fragment, sink class TestSinkMemory(unittest.TestCase): """ Make sure error sinks are cleared properly """ def test_tidy_document(self): h = "

hello" for i in xrange(100): doc, err = tidy_document(h) self.assertEqual(sink.sinks, {}) def test_tidy_fragment(self): h = "

hello" for i in xrange(100): doc, err = tidy_fragment(h) self.assertEqual(sink.sinks, {}) if __name__ == '__main__': unittest.main() pytidylib-0.2.1/tests/threadsafety.py0000644000175000017500000000414011166672363016742 0ustar janosjanos# Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import threading from Queue import Queue from tidylib import tidy_document error_queue = Queue() DOC = ''' hello, world ''' SAMPLE = "hello, world" NUM_THREADS = 100 NUM_TRIES = 100 class TidyingThread(threading.Thread): def run(self): for x in xrange(NUM_TRIES): output, errors = tidy_document(SAMPLE, keep_doc=True) if output != DOC: error_queue.put(output) def run_test(): threads = [] for i in xrange(NUM_THREADS): t = TidyingThread() threads.append(t) t.start() for t in threads: t.join() if __name__ == '__main__': run_test() if not error_queue.empty(): print "About %s errors out of %s" % (error_queue.qsize(), NUM_THREADS * NUM_TRIES) print error_queue.get() pytidylib-0.2.1/tests/FragsTest.py0000644000175000017500000000461211300317050016140 0ustar janosjanos# -*- coding: utf-8 -*- # Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import unittest from tidylib import tidy_fragment class TestFrags1(unittest.TestCase): """ Test some sample fragment documents """ def test_frag_with_unclosed_tag(self): h = "

hello" expected = '''

hello

''' doc, err = tidy_fragment(h) self.assertEqual(doc, expected) def test_frag_with_incomplete_img_tag(self): h = "" expected = '''''' doc, err = tidy_fragment(h) self.assertEqual(doc, expected) def test_frag_with_entity(self): h = "é" expected = "é" doc, err = tidy_fragment(h) self.assertEqual(doc, expected) expected = "é" doc, err = tidy_fragment(h, {'numeric-entities':1}) self.assertEqual(doc, expected) def test_frag_with_unicode(self): h = u"unicode string ß" expected = h doc, err = tidy_fragment(h) self.assertEqual(doc, expected) def test_frag_with_unicode_subclass(self): class MyUnicode(unicode): pass h = MyUnicode(u"unicode string ß") expected = h doc, err = tidy_fragment(h) self.assertEqual(doc, expected) if __name__ == '__main__': unittest.main() pytidylib-0.2.1/tests/._FragsTest.py0000644000175000017500000000027311300317050016354 0ustar janosjanosMac OS X  2‰»TxMtATTRÖ`T»˜#˜#com.macromates.caret{ column = 16; line = 59; }pytidylib-0.2.1/tests/._DocsTest.py0000644000175000017500000000027011300316237016205 0ustar janosjanosMac OS X  2†¸TxMtATTR]G¸˜ ˜ com.macromates.caretxœ«æR‚äüœÒÜ<[k0?'3/«‹™pytidylib-0.2.1/tests/DocsTest.py0000644000175000017500000000531511300316237015775 0ustar janosjanos# -*- coding: utf-8 -*- # Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import unittest from tidylib import tidy_document DOC = ''' %s ''' class TestDocs1(unittest.TestCase): """ Test some sample documents """ def test_doc_with_unclosed_tag(self): h = "

hello" expected = DOC % '''

hello

''' doc, err = tidy_document(h) self.assertEqual(doc, expected) def test_doc_with_incomplete_img_tag(self): h = "" expected = DOC % '''''' doc, err = tidy_document(h) self.assertEqual(doc, expected) def test_doc_with_entity(self): h = "é" expected = DOC % "é" doc, err = tidy_document(h) self.assertEqual(doc, expected) expected = DOC % "é" doc, err = tidy_document(h, {'numeric-entities':1}) self.assertEqual(doc, expected) def test_doc_with_unicode(self): h = u"unicode string ß" expected = unicode(DOC, 'utf-8') % h doc, err = tidy_document(h) self.assertEqual(doc, expected) def test_doc_with_unicode_subclass(self): class MyUnicode(unicode): pass h = MyUnicode(u"unicode string ß") expected = unicode(DOC, 'utf-8') % h doc, err = tidy_document(h) self.assertEqual(doc, expected) if __name__ == '__main__': unittest.main()pytidylib-0.2.1/tests/._SinkMemTest.py0000644000175000017500000000027211166672360016676 0ustar janosjanosMac OS X  2ˆºTxMtATTR]Eº˜"˜"com.macromates.caret{ column = 0; line = 20; }pytidylib-0.2.1/README0000644000175000017500000000046711274706651013431 0ustar janosjanosFor documentation, see docs/html/index.html in this distribution, or http://countergram.com/open-source/pytidylib/ Small example of use: from tidylib import tidy_document document, errors = tidy_document('''

fõo ''', options={'numeric-entities':1}) print document print errors pytidylib-0.2.1/tidylib/0000755000175000017500000000000011301050430014154 5ustar janosjanospytidylib-0.2.1/tidylib/._sink.py0000644000175000017500000000027311274656346015744 0ustar janosjanosMac OS X  2‰»TxMtATTR\.l»˜#˜#com.macromates.caret{ column = 26; line = 13; }pytidylib-0.2.1/tidylib/sink.py0000644000175000017500000000702311274656346015527 0ustar janosjanos# Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import ctypes import sys import threading import platform try: from cStringIO import StringIO except ImportError: from StringIO import StringIO __all__ = ['Sink', 'create_sink', 'destroy_sink'] #----------------------------------------------------------------------------# # Globals sinks = {} # of int: Sink last_sink_id = 0 sink_id_lock = threading.Lock() #----------------------------------------------------------------------------# # ctypes type definitions # Fix for Windows b/c tidy uses stdcall on Windows if "Windows" == platform.system(): functype = ctypes.WINFUNCTYPE else: functype = ctypes.CFUNCTYPE PutByteType = functype(None, ctypes.c_int, ctypes.c_char) class TidyOutputSink(ctypes.Structure): """ Mirrors the _TidyOutputSink structure in tidy.h """ _fields_ = [ ('sinkData', ctypes.c_void_p), ('putByte', PutByteType) ] #----------------------------------------------------------------------------# # Python interface class Sink(object): """ Represent a buffer to which Tidy writes errors with a callback function """ def __init__(self, sink_id): self.data = StringIO() self.sink_id = sink_id self.struct = TidyOutputSink() self.struct.sinkData = ctypes.cast( ctypes.pointer(ctypes.c_int(sink_id)), ctypes.c_void_p) # Windows fix write_func = self.data.write # Avoid 2 attr accesses per byte def put_byte(sink_id, byte): # We don't need sink_id because we have a separate put_byte # function for each sink write_func(byte) self.struct.putByte = PutByteType(put_byte) self._as_parameter_ = ctypes.byref(self.struct) def __str__(self): return self.data.getvalue() def create_sink(): """ Return a new Sink with a numeric ID incremented in a threadsafe way """ global last_sink_id, sink_id_lock, sinks sink_id_lock.acquire() try: this_sink_id = last_sink_id last_sink_id = (last_sink_id + 1) % sys.maxint # If you have more than maxint sinks open at a time, you're screwed finally: sink_id_lock.release() sink = Sink(this_sink_id) sinks[this_sink_id] = sink return sink def destroy_sink(sink): """ Free a Sink object by eliminating the reference from the global map """ global sinks del sinks[sink.sink_id] del sink #----------------------------------------------------------------------------# pytidylib-0.2.1/tidylib/.___init__.py0000644000175000017500000000027311300315340016507 0ustar janosjanosMac OS X  2‰»TxMtATTR\.i»˜#˜#com.macromates.caret{ column = 42; line = 32; }pytidylib-0.2.1/tidylib/__init__.py0000644000175000017500000001642511300315340016300 0ustar janosjanos# Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import ctypes import threading import re import platform from sink import create_sink, destroy_sink __all__ = ['tidy_document', 'tidy_fragment', 'release_tidy_doc'] #----------------------------------------------------------------------------# # Constants LIB_NAMES = ['libtidy', 'libtidy.so', 'libtidy-0.99.so.0', 'cygtidy-0-99-0', 'tidylib', 'libtidy.dylib', 'tidy'] ENOMEM = -12 RE_BODY = re.compile(r"[\r\n]*(.+?)", re.S) BASE_OPTIONS = { "output-xhtml": 1, # XHTML instead of HTML4 "indent": 1, # Pretty; not too much of a performance hit "tidy-mark": 0, # No tidy meta tag in output "wrap": 0, # No wrapping "alt-text": "", # Help ensure validation "doctype": 'strict', # Little sense in transitional for tool-generated markup... "force-output": 1, # May not get what you expect but you will get something } # Note: These are meant as sensible defaults. If you don't like these being # applied by default, just set tidylib.BASE_OPTIONS = {} after importing. # You can of course override any of these options when you call the # tidy_document() or tidy_fragment() function #----------------------------------------------------------------------------# # Globals tidy = None thread_local_doc = threading.local() # Fix for Windows b/c tidy uses stdcall on Windows if "Windows" == platform.system(): load_library = ctypes.windll.LoadLibrary else: load_library = ctypes.cdll.LoadLibrary for name in LIB_NAMES: try: tidy = load_library(name) break except OSError: pass if tidy is None: raise OSError("Could not load libtidy using any of these names: %s" % (",".join(LIB_NAMES))) tidy.tidyCreate.restype = ctypes.POINTER(ctypes.c_void_p) # Fix for 64-bit systems #----------------------------------------------------------------------------# # Functions def tidy_document(text, options=None, keep_doc=False): """ Run a string with markup through HTML Tidy; return the corrected one. text (str): The markup, which may be anything from an empty string to a complete (X)HTML document. Unicode values are supported; they will be encoded as UTF-8, and HTML Tidy's output will be decoded back to a unicode object. options (dict): Options passed directly to HTML Tidy; see the HTML Tidy docs (http://tidy.sourceforge.net/docs/quickref.html) or run tidy -help-config from the command line. keep_doc (boolean): If True, store 1 document object per thread and re-use it, for a slight performance boost especially when tidying very large numbers of very short documents. returns (str, str): The tidied markup [0] and warning/error messages[1]. Warnings and errors are returned just as tidylib returns them. """ global tidy, option_names # Unicode approach is to encode as string, then decode libtidy output use_unicode = False if isinstance(text, unicode): use_unicode = True text = text.encode('utf-8') # Manage thread-local storage of persistent document object if keep_doc: if not hasattr(thread_local_doc, 'doc'): thread_local_doc.doc = tidy.tidyCreate() doc = thread_local_doc.doc else: doc = tidy.tidyCreate() # This is where error messages are sent by libtidy sink = create_sink() tidy.tidySetErrorSink(doc, sink) try: # Set options on the document # If keep_doc=True, options will persist between calls, but they can # be overridden, and the BASE_OPTIONS will be set each time tidy_options = dict(BASE_OPTIONS) if options: tidy_options.update(options) if use_unicode: tidy_options['input-encoding'] = 'utf8' tidy_options['output-encoding'] = 'utf8' for key in tidy_options: value = tidy_options[key] key = key.replace('_', '-') if value is None: value = '' tidy.tidyOptParseValue(doc, key, str(value)) error = str(sink) if error: raise ValueError("(tidylib) " + error) # The point of the whole thing tidy.tidyParseString(doc, text) tidy.tidyCleanAndRepair(doc) # Guess at buffer size; tidy returns ENOMEM if the buffer is too # small and puts the required size into out_length out_length = ctypes.c_int(8192) out = ctypes.c_buffer(out_length.value) if ENOMEM == tidy.tidySaveString(doc, out, ctypes.byref(out_length)): out = ctypes.c_buffer(out_length.value) tidy.tidySaveString(doc, out, ctypes.byref(out_length)) document = out.value if use_unicode: document = document.decode('utf-8') errors = str(sink) finally: destroy_sink(sink) if not keep_doc: tidy.tidyRelease(doc) return (document, errors) def tidy_fragment(text, options=None, keep_doc=False): """ Tidy a string with markup and return only the contents. HTML Tidy normally returns a full (X)HTML document; this function returns only the contents of the element and is meant to be used for snippets. Calling tidy_fragment on elements that don't go in the , like , will produce incorrect behavior. Arguments and return value are the same as tidy_document. Note that HTML Tidy will always complain about the lack of a doctype and <title> element in fragments, and these errors are not stripped out for you. """ document, errors = tidy_document(text, options, keep_doc) match = RE_BODY.search(document) if match: document = match.group(1).strip() return (document, errors) else: raise ValueError("tidy_fragment failed to process text") def release_tidy_doc(): """ Release the stored document object in the current thread. Only useful if you have called tidy_document or tidy_fragament with keep_doc=True. """ if hasattr(thread_local_doc, 'doc'): tidy.tidyRelease(thread_local_doc.doc) del thread_local_doc.doc #----------------------------------------------------------------------------# �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/PKG-INFO����������������������������������������������������������������������������0000644�0001750�0001750�00000004357�11301050430�013622� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Metadata-Version: 1.0 Name: pytidylib Version: 0.2.1 Summary: Python wrapper for HTML Tidy (tidylib) Home-page: http://countergram.com/open-source/pytidylib/ Author: Jason Stitt Author-email: js@jasonstitt.com License: UNKNOWN Download-URL: http://cloud.github.com/downloads/countergram/pytidylib/pytidylib-0.2.1.tar.gz Description: 0.2.0: Works on Windows! See documentation for available DLL download locations. Documentation rewritten and expanded. `PyTidyLib`_ is a Python package that wraps the `HTML Tidy`_ library. This allows you, from Python code, to "fix" invalid (X)HTML markup. Some of the library's many capabilities include: * Clean up unclosed tags and unescaped characters such as ampersands * Output HTML 4 or XHTML, strict or transitional, and add missing doctypes * Convert named entities to numeric entities, which can then be used in XML documents without an HTML doctype. * Clean up HTML from programs such as Word (to an extent) * Indent the output, including proper (i.e. no) indenting for ``pre`` elements, which some (X)HTML indenting code overlooks. Small example of use ==================== The following code cleans up an invalid HTML document and sets an option:: from tidylib import tidy_document document, errors = tidy_document('''<p>fõo <img src="bar.jpg">''', options={'numeric-entities':1}) print document print errors Docs ==== Documentation is shipped with the source distribution and is available at the `PyTidyLib`_ web page. .. _`HTML Tidy`: http://tidy.sourceforge.net/ .. _`PyTidyLib`: http://countergram.com/open-source/pytidylib/ Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Other Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Topic :: Utilities Classifier: Topic :: Text Processing :: Markup :: HTML Classifier: Topic :: Text Processing :: Markup :: XML ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/�������������������������������������������������������������������������������0000755�0001750�0001750�00000000000�11556361745�013476� 5����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/rst/���������������������������������������������������������������������������0000755�0001750�0001750�00000000000�11301050430�014254� 5����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/rst/index.rst������������������������������������������������������������������0000644�0001750�0001750�00000014222�11274665033�016142� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������PyTidyLib: A Python Interface to HTML Tidy ------------------------------------------ `PyTidyLib`_ is a Python package that wraps the `HTML Tidy`_ library. This allows you, from Python code, to "fix" invalid (X)HTML markup. Some of the library's many capabilities include: * Clean up unclosed tags and unescaped characters such as ampersands * Output HTML 4 or XHTML, strict or transitional, and add missing doctypes * Convert named entities to numeric entities, which can then be used in XML documents without an HTML doctype. * Clean up HTML from programs such as Word (to an extent) * Indent the output, including proper (i.e. no) indenting for ``pre`` elements, which some (X)HTML indenting code overlooks. PyTidyLib is intended as as replacement for uTidyLib, which fills a similar purpose. The author previously used uTidyLib but found several areas for improvement, including OS X support, 64-bit platform support, unicode support, fixing a memory leak, and better speed. Naming conventions ================== `HTML Tidy`_ is a longstanding open-source library written in C that implements the actual functionality of cleaning up (X)HTML markup. It provides a shared library (``so``, ``dll``, or ``dylib``) that can variously be called ``tidy``, ``libtidy``, or ``tidylib``, as well as a command-line executable named ``tidy``. For clarity, this document will consistently refer to it by the project name, HTML Tidy. `PyTidyLib`_ is the name of the Python package discussed here. As this is the package name, ``easy_install pytidylib`` or ``pip install pytidylib`` is correct (they are case-insenstive). The *module* name is ``tidylib``, so ``import tidylib`` is correct in Python code. This document will consistently use the package name, PyTidyLib, outside of code examples. Installing HTML Tidy ==================== You must have both `HTML Tidy`_ and `PyTidyLib`_ installed in order to use the functionality described here. There is no affiliation between the two projects. The following briefly outlines what you must do to install HTML Tidy. See the `HTML Tidy`_ web site for more information. **Linux/BSD or similar:** First, try to use your distribution's package management system (``apt-get``, ``yum``, etc.) to install HTML Tidy. It might go under the name ``libtidy``, ``tidylib``, ``tidy``, or something similar. Otherwise see *Building from Source*, below. **OS X:** You may already have HTML Tidy installed. In the Terminal, run ``locate libtidy`` and see if you get any results, which should end in ``dylib``. Otherwise see *Building from Source*, below. **Windows:** (Use PyTidyLib version 0.2 or later!) Prebuilt HTML Tidy DLLs are available from at least two locations. The `int64.org Tidy Binaries`_ page provides binaries that were built in 2005, for both 32-bit and 64-bit Windows, against a patched version of the source. The `HTML Tidy`_ web site links to a DLL built in 2006, for 32-bit Windows only, using the vanilla source (scroll near the bottom to "Other Builds" -- use the one that reads "exe/lib/dll", *not* the "exe"-only version.) Once you have a DLL (which may be named ``tidy.dll``, ``libtidy.dll``, or ``tidylib.dll``), you must place it in a directory on your system path. If you are running Python from the command-line, placing the DLL in the present working directory will work, but this is unreliable otherwise (e.g. for server software). See the articles `How to set the path in Windows 2000/Windows XP <http://www.computerhope.com/issues/ch000549.htm>`_ (ComputerHope.com) and `Modify a Users Path in Windows Vista <http://www.question-defense.com/2009/06/22/modify-a-users-path-in-windows-vista-vista-path-environment-variable/>`_ (Question Defense) for more information on your system path. **Building from Source:** The HTML Tidy developers have chosen to make the source code downloadable *only* through CVS, and not from the web site. Use the following CVS checkout at the command line:: cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co -P tidy Then see the instructions packaged with the source code or on the `HTML Tidy`_ web site. Installing PyTidyLib ==================== PyTidyLib is available on the Python Package Index and may be installed in the usual ways if you have `pip`_ or `setuptools`_ installed:: pip install pytidylib # or: easy_install pytidylib You can also download the latest source distribution from the `PyTidyLib`_ web site. Small example of use ==================== The following code cleans up an invalid HTML document and sets an option:: from tidylib import tidy_document document, errors = tidy_document('''<p>fõo <img src="bar.jpg">''', options={'numeric-entities':1}) print document print errors Configuration options ===================== The Python interface allows you to pass options directly to HTML Tidy. For a complete list of options, see the `HTML Tidy Configuration Options Quick Reference`_ or, from the command line, run ``tidy -help-config``. .. _`HTML Tidy Configuration Options Quick Reference`: http://tidy.sourceforge.net/docs/quickref.html This module sets certain default options, as follows:: BASE_OPTIONS = { "output-xhtml": 1, # XHTML instead of HTML4 "indent": 1, # Pretty; not too much of a performance hit "tidy-mark": 0, # No tidy meta tag in output "wrap": 0, # No wrapping "alt-text": "", # Help ensure validation "doctype": 'strict', # Little sense in transitional for tool-generated markup... "force-output": 1, # May not get what you expect but you will get something } If you do not like these options to be set for you, do the following after importing ``tidylib``:: tidylib.BASE_OPTIONS = {} Function reference ================== .. autofunction:: tidylib.tidy_document .. autofunction:: tidylib.tidy_fragment .. autofunction:: tidylib.release_tidy_doc .. _`HTML Tidy`: http://tidy.sourceforge.net/ .. _`PyTidyLib`: http://countergram.com/open-source/pytidylib/ .. _`int64.org Tidy Binaries`: http://int64.org/projects/tidy-binaries .. _`setuptools`: http://pypi.python.org/pypi/setuptools .. _`pip`: http://pypi.python.org/pypi/pip ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/rst/conf.py��������������������������������������������������������������������0000644�0001750�0001750�00000000630�11274665256�015605� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# Configuration file for Sphinx documentation tool extensions = ['sphinx.ext.autodoc'] master_doc = "index" project = "pytidylib" copyright = "2009 Jason Stitt" version = "0.1" language = "en" html_title = "pytidylib module" latex_use_modindex = False latex_documents = [ ( master_doc, 'pytidylib.tex', 'PyTidyLib documentation', 'Jason Stitt', 'howto', False, ) ] ��������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/rst/._index.rst����������������������������������������������������������������0000644�0001750�0001750�00000000272�11274665033�016357� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Mac OS X ���� ���2���ˆ������º��������TxMt��������������������������ATTR�\PS���º���˜���"������������������˜���"��com.macromates.caret�{ column = 0; line = 95; }��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/docs/rst/._conf.py������������������������������������������������������������������0000644�0001750�0001750�00000000273�11274665256�016025� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Mac OS X ���� ���2���‰������»��������TxMt��������������������������ATTR�\P=���»���˜���#������������������˜���#��com.macromates.caret�{ column = 28; line = 19; }�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/._README����������������������������������������������������������������������������0000644�0001750�0001750�00000000272�11274706651�013640� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Mac OS X ���� ���2���ˆ������º��������TxMt��������������������������ATTR�\DÒ���º���˜���"������������������˜���"��com.macromates.caret�{ column = 21; line = 3; }��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/setup.py����������������������������������������������������������������������������0000644�0001750�0001750�00000006340�11301050372�014236� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# Copyright 2009 Jason Stitt # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from distutils.core import setup longdesc = """\ 0.2.0: Works on Windows! See documentation for available DLL download locations. Documentation rewritten and expanded. `PyTidyLib`_ is a Python package that wraps the `HTML Tidy`_ library. This allows you, from Python code, to "fix" invalid (X)HTML markup. Some of the library's many capabilities include: * Clean up unclosed tags and unescaped characters such as ampersands * Output HTML 4 or XHTML, strict or transitional, and add missing doctypes * Convert named entities to numeric entities, which can then be used in XML documents without an HTML doctype. * Clean up HTML from programs such as Word (to an extent) * Indent the output, including proper (i.e. no) indenting for ``pre`` elements, which some (X)HTML indenting code overlooks. Small example of use ==================== The following code cleans up an invalid HTML document and sets an option:: from tidylib import tidy_document document, errors = tidy_document('''<p>fõo <img src="bar.jpg">''', options={'numeric-entities':1}) print document print errors Docs ==== Documentation is shipped with the source distribution and is available at the `PyTidyLib`_ web page. .. _`HTML Tidy`: http://tidy.sourceforge.net/ .. _`PyTidyLib`: http://countergram.com/open-source/pytidylib/ """ VERSION = "0.2.1" setup( name="pytidylib", version=VERSION, description="Python wrapper for HTML Tidy (tidylib)", long_description=longdesc, author="Jason Stitt", author_email="js@jasonstitt.com", url="http://countergram.com/open-source/pytidylib/", download_url="http://cloud.github.com/downloads/countergram/pytidylib/pytidylib-%s.tar.gz" % VERSION, packages=['tidylib'], classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Other Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Natural Language :: English', 'Topic :: Utilities', 'Topic :: Text Processing :: Markup :: HTML', 'Topic :: Text Processing :: Markup :: XML', ], ) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/MANIFEST.in�������������������������������������������������������������������������0000644�0001750�0001750�00000000405�11164003527�014265� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������include README include LICENSE include MANIFEST.in include tidylib/*.py include tests/*.py include *.py include docs/pytidylib.pdf include docs/html/*.html include docs/html/*.js include docs/html/_static/*.* include docs/html/_sources/*.* include docs/rst/*.* �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/._setup.py��������������������������������������������������������������������������0000644�0001750�0001750�00000000273�11301050372�014452� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Mac OS X ���� ���2���‰������»��������TxMt��������������������������ATTR�\DÍ���»���˜���#������������������˜���#��com.macromates.caret�{ column = 16; line = 59; }�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������pytidylib-0.2.1/._MANIFEST.in�����������������������������������������������������������������������0000644�0001750�0001750�00000000272�11164003527�014504� 0����������������������������������������������������������������������������������������������������ustar �janos���������������������������janos����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Mac OS X ���� ���2���ˆ������º��������TxMt��������������������������ATTR�\Dâ���º���˜���"������������������˜���"��com.macromates.caret�{ column = 0; line = 12; }����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������