From: <mi...@us...> - 2012-06-25 13:16:15
|
Revision: 7464 http://docutils.svn.sourceforge.net/docutils/?rev=7464&view=rev Author: milde Date: 2012-06-25 13:16:03 +0000 (Mon, 25 Jun 2012) Log Message: ----------- math, error_reporting, and urischemes moved to the utils package. Modified Paths: -------------- trunk/docutils/HISTORY.txt trunk/docutils/RELEASE-NOTES.txt trunk/docutils/docutils/__init__.py trunk/docutils/docutils/core.py trunk/docutils/docutils/frontend.py trunk/docutils/docutils/io.py trunk/docutils/docutils/parsers/rst/directives/misc.py trunk/docutils/docutils/parsers/rst/directives/tables.py trunk/docutils/docutils/parsers/rst/states.py trunk/docutils/docutils/statemachine.py trunk/docutils/docutils/utils/__init__.py trunk/docutils/docutils/utils/math/latex2mathml.py trunk/docutils/docutils/writers/html4css1/__init__.py trunk/docutils/docutils/writers/latex2e/__init__.py trunk/docutils/setup.py trunk/docutils/test/DocutilsTestSupport.py trunk/docutils/test/test_error_reporting.py trunk/docutils/test/test_io.py trunk/docutils/tools/buildhtml.py Added Paths: ----------- trunk/docutils/docutils/utils/error_reporting.py trunk/docutils/docutils/utils/math/ trunk/docutils/docutils/utils/urischemes.py Removed Paths: ------------- trunk/docutils/docutils/error_reporting.py trunk/docutils/docutils/math/ trunk/docutils/docutils/urischemes.py Modified: trunk/docutils/HISTORY.txt =================================================================== --- trunk/docutils/HISTORY.txt 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/HISTORY.txt 2012-06-25 13:16:03 UTC (rev 7464) @@ -19,6 +19,8 @@ * General - Dropped support for Python 2.3. + - ``docutils/math``, ``docutils/error_reporting.py``, and + ``docutils/urischemes.py`` moved to the utils package. Release 0.9.1 (2012-06-17) Modified: trunk/docutils/RELEASE-NOTES.txt =================================================================== --- trunk/docutils/RELEASE-NOTES.txt 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/RELEASE-NOTES.txt 2012-06-25 13:16:03 UTC (rev 7464) @@ -19,15 +19,6 @@ Future changes ============== -* docutils/math, docutils/error_reporting.py, and - docutils/urischemes.py will move to the utils package - Code importing these modules needs to adapt, e.g.:: - - try: - import docutils.math as math - except ImportError: - import docutils.utils.math as math - * docutils.io.FileInput/FileOutput will no longer do a system-exit on IOError by default. @@ -50,9 +41,20 @@ Docutils 0.9.x is the last version supporting Python 2.3. - Docutils 0.10 is compatible with Python versions from 2.4 to 2.7, - as well as 3.1 and 3.2 (cf. `Python 3 compatibility`_). + Docutils 0.10 is compatible with Python versions from 2.4 to 3.2 + (cf. `Python 3 compatibility`_). +* General: + + - ``docutils/math``, ``docutils/error_reporting.py``, and + ``docutils/urischemes.py`` moved to the utils package. + Code importing these modules needs to adapt, e.g.:: + + try: + import docutils.math as math + except ImportError: + import docutils.utils.math as math + .. _Python 3 compatibility: README.html#python-3-compatibility Modified: trunk/docutils/docutils/__init__.py =================================================================== --- trunk/docutils/docutils/__init__.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/__init__.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -26,9 +26,6 @@ - statemachine.py: A finite state machine specialized for regular-expression-based text filters. -- urischemes.py: Contains a complete mapping of known URI addressing - scheme names to descriptions. - Subpackages: - languages: Language-specific mappings of terms. @@ -44,6 +41,12 @@ - utils: Contains the ``Reporter`` system warning class and miscellaneous utilities used by readers, writers, and transforms. + utils/urischemes.py: Contains a complete mapping of known URI addressing + scheme names to descriptions. + +- utils/math: Contains functions for conversion of mathematical notation + between different formats (LaTeX, MathML, text, ...). + - writers: Format-specific output translators. """ Modified: trunk/docutils/docutils/core.py =================================================================== --- trunk/docutils/docutils/core.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/core.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -20,7 +20,7 @@ from docutils import frontend, io, utils, readers, writers from docutils.frontend import OptionParser from docutils.transforms import Transformer -from docutils.error_reporting import ErrorOutput, ErrorString +from docutils.utils.error_reporting import ErrorOutput, ErrorString import docutils.readers.doctree class Publisher: Deleted: trunk/docutils/docutils/error_reporting.py =================================================================== --- trunk/docutils/docutils/error_reporting.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/error_reporting.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -1,207 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf8 -*- - -# :Id: $Id$ -# :Copyright: © 2011 Günter Milde. -# :License: Released under the terms of the `2-Clause BSD license`_, in short: -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. -# This file is offered as-is, without any warranty. -# -# .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause - -""" -Error reporting should be safe from encoding/decoding errors. -However, implicit conversions of strings and exceptions like - ->>> u'%s world: %s' % ('H\xe4llo', Exception(u'H\xe4llo') - -fail in some Python versions: - -* In Python <= 2.6, ``unicode(<exception instance>)`` uses - `__str__` and fails with non-ASCII chars in`unicode` arguments. - (work around http://bugs.python.org/issue2517): - -* In Python 2, unicode(<exception instance>) fails, with non-ASCII - chars in arguments. (Use case: in some locales, the errstr - argument of IOError contains non-ASCII chars.) - -* In Python 2, str(<exception instance>) fails, with non-ASCII chars - in `unicode` arguments. - -The `SafeString`, `ErrorString` and `ErrorOutput` classes handle -common exceptions. -""" - -import sys, codecs - -# Guess the locale's encoding. -# If no valid guess can be made, locale_encoding is set to `None`: -try: - import locale # module missing in Jython -except ImportError: - locale_encoding = None -else: - locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] - # locale.getpreferredencoding([do_setlocale=True|False]) - # has side-effects | might return a wrong guess. - # (cf. Update 1 in http://stackoverflow.com/questions/4082645/using-python-2-xs-locale-module-to-format-numbers-and-currency) - try: - codecs.lookup(locale_encoding or '') # None -> '' - except LookupError: - locale_encoding = None - - - -class SafeString(object): - """ - A wrapper providing robust conversion to `str` and `unicode`. - """ - - def __init__(self, data, encoding=None, encoding_errors='backslashreplace', - decoding_errors='replace'): - self.data = data - self.encoding = (encoding or getattr(data, 'encoding', None) or - locale_encoding or 'ascii') - self.encoding_errors = encoding_errors - self.decoding_errors = decoding_errors - - - def __str__(self): - try: - return str(self.data) - except UnicodeEncodeError, err: - if isinstance(self.data, Exception): - args = [str(SafeString(arg, self.encoding, - self.encoding_errors)) - for arg in self.data.args] - return ', '.join(args) - if isinstance(self.data, unicode): - return self.data.encode(self.encoding, self.encoding_errors) - raise - - def __unicode__(self): - """ - Return unicode representation of `self.data`. - - Try ``unicode(self.data)``, catch `UnicodeError` and - - * if `self.data` is an Exception instance, work around - http://bugs.python.org/issue2517 with an emulation of - Exception.__unicode__, - - * else decode with `self.encoding` and `self.decoding_errors`. - """ - try: - u = unicode(self.data) - if isinstance(self.data, EnvironmentError): - u = u.replace(": u'", ": '") # normalize filename quoting - return u - except UnicodeError, error: # catch ..Encode.. and ..Decode.. errors - if isinstance(self.data, EnvironmentError): - return u"[Errno %s] %s: '%s'" % (self.data.errno, - SafeString(self.data.strerror, self.encoding, - self.decoding_errors), - SafeString(self.data.filename, self.encoding, - self.decoding_errors)) - if isinstance(self.data, Exception): - args = [unicode(SafeString(arg, self.encoding, - decoding_errors=self.decoding_errors)) - for arg in self.data.args] - return u', '.join(args) - if isinstance(error, UnicodeDecodeError): - return unicode(self.data, self.encoding, self.decoding_errors) - raise - -class ErrorString(SafeString): - """ - Safely report exception type and message. - """ - def __str__(self): - return '%s: %s' % (self.data.__class__.__name__, - super(ErrorString, self).__str__()) - - def __unicode__(self): - return u'%s: %s' % (self.data.__class__.__name__, - super(ErrorString, self).__unicode__()) - - -class ErrorOutput(object): - """ - Wrapper class for file-like error streams with - failsave de- and encoding of `str`, `bytes`, `unicode` and - `Exception` instances. - """ - - def __init__(self, stream=None, encoding=None, - encoding_errors='backslashreplace', - decoding_errors='replace'): - """ - :Parameters: - - `stream`: a file-like object, - a string (path to a file), - `None` (write to `sys.stderr`, default), or - evaluating to `False` (write() requests are ignored). - - `encoding`: `stream` text encoding. Guessed if None. - - `encoding_errors`: how to treat encoding errors. - """ - if stream is None: - stream = sys.stderr - elif not(stream): - stream = False - # if `stream` is a file name, open it - elif isinstance(stream, str): - stream = open(stream, 'w') - elif isinstance(stream, unicode): - stream = open(stream.encode(sys.getfilesystemencoding()), 'w') - - self.stream = stream - """Where warning output is sent.""" - - self.encoding = (encoding or getattr(stream, 'encoding', None) or - locale_encoding or 'ascii') - """The output character encoding.""" - - self.encoding_errors = encoding_errors - """Encoding error handler.""" - - self.decoding_errors = decoding_errors - """Decoding error handler.""" - - def write(self, data): - """ - Write `data` to self.stream. Ignore, if self.stream is False. - - `data` can be a `string`, `unicode`, or `Exception` instance. - """ - if self.stream is False: - return - if isinstance(data, Exception): - data = unicode(SafeString(data, self.encoding, - self.encoding_errors, self.decoding_errors)) - try: - self.stream.write(data) - except UnicodeEncodeError: - self.stream.write(data.encode(self.encoding, self.encoding_errors)) - except TypeError: # in Python 3, stderr expects unicode - if self.stream in (sys.stderr, sys.stdout): - self.stream.buffer.write(data) # write bytes to raw stream - else: - self.stream.write(unicode(data, self.encoding, - self.decoding_errors)) - - def close(self): - """ - Close the error-output stream. - - Ignored if the stream is` sys.stderr` or `sys.stdout` or has no - close() method. - """ - if self.stream in (sys.stdout, sys.stderr): - return - try: - self.stream.close() - except AttributeError: - pass Modified: trunk/docutils/docutils/frontend.py =================================================================== --- trunk/docutils/docutils/frontend.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/frontend.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -38,7 +38,7 @@ import docutils import docutils.utils import docutils.nodes -from docutils.error_reporting import locale_encoding, ErrorOutput, ErrorString +from docutils.utils.error_reporting import locale_encoding, ErrorOutput, ErrorString def store_multiple(option, opt, value, parser, *args, **kwargs): Modified: trunk/docutils/docutils/io.py =================================================================== --- trunk/docutils/docutils/io.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/io.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -15,7 +15,7 @@ import codecs from docutils import TransformSpec from docutils._compat import b -from docutils.error_reporting import locale_encoding, ErrorString, ErrorOutput +from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput class InputError(IOError): pass Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -11,7 +11,7 @@ import re import time from docutils import io, nodes, statemachine, utils -from docutils.error_reporting import SafeString, ErrorString +from docutils.utils.error_reporting import SafeString, ErrorString from docutils.parsers.rst import Directive, convert_directive_function from docutils.parsers.rst import directives, roles, states from docutils.parsers.rst.directives.body import CodeBlock, NumberLines Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -14,7 +14,7 @@ import csv from docutils import io, nodes, statemachine, utils -from docutils.error_reporting import SafeString +from docutils.utils.error_reporting import SafeString from docutils.utils import SystemMessagePropagation from docutils.parsers.rst import Directive from docutils.parsers.rst import directives Modified: trunk/docutils/docutils/parsers/rst/states.py =================================================================== --- trunk/docutils/docutils/parsers/rst/states.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/parsers/rst/states.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -111,7 +111,7 @@ import docutils.utils.roman as roman from types import FunctionType, MethodType -from docutils import nodes, statemachine, utils, urischemes +from docutils import nodes, statemachine, utils from docutils import ApplicationError, DataError from docutils.statemachine import StateMachineWS, StateWS from docutils.nodes import fully_normalize_name as normalize_name @@ -120,7 +120,7 @@ from docutils.parsers.rst import directives, languages, tableparser, roles from docutils.parsers.rst.languages import en as _fallback_language_module from docutils.utils import escape2null, unescape, column_width -from docutils.utils import punctuation_chars +from docutils.utils import punctuation_chars, urischemes class MarkupError(DataError): pass class UnknownInterpretedRoleError(DataError): pass Modified: trunk/docutils/docutils/statemachine.py =================================================================== --- trunk/docutils/docutils/statemachine.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/statemachine.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -111,7 +111,7 @@ import types import unicodedata from docutils import utils -from docutils.error_reporting import ErrorOutput +from docutils.utils.error_reporting import ErrorOutput class StateMachine: Deleted: trunk/docutils/docutils/urischemes.py =================================================================== --- trunk/docutils/docutils/urischemes.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/urischemes.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -1,136 +0,0 @@ -# $Id$ -# Author: David Goodger <go...@py...> -# Copyright: This module has been placed in the public domain. - -""" -`schemes` is a dictionary with lowercase URI addressing schemes as -keys and descriptions as values. It was compiled from the index at -http://www.iana.org/assignments/uri-schemes (revised 2005-11-28) -and an older list at http://www.w3.org/Addressing/schemes.html. -""" - -# Many values are blank and should be filled in with useful descriptions. - -schemes = { - 'about': 'provides information on Navigator', - 'acap': 'Application Configuration Access Protocol; RFC 2244', - 'addbook': "To add vCard entries to Communicator's Address Book", - 'afp': 'Apple Filing Protocol', - 'afs': 'Andrew File System global file names', - 'aim': 'AOL Instant Messenger', - 'callto': 'for NetMeeting links', - 'castanet': 'Castanet Tuner URLs for Netcaster', - 'chttp': 'cached HTTP supported by RealPlayer', - 'cid': 'content identifier; RFC 2392', - 'crid': 'TV-Anytime Content Reference Identifier; RFC 4078', - 'data': ('allows inclusion of small data items as "immediate" data; ' - 'RFC 2397'), - 'dav': 'Distributed Authoring and Versioning Protocol; RFC 2518', - 'dict': 'dictionary service protocol; RFC 2229', - 'dns': 'Domain Name System resources', - 'eid': ('External ID; non-URL data; general escape mechanism to allow ' - 'access to information for applications that are too ' - 'specialized to justify their own schemes'), - 'fax': ('a connection to a terminal that can handle telefaxes ' - '(facsimiles); RFC 2806'), - 'feed' : 'NetNewsWire feed', - 'file': 'Host-specific file names; RFC 1738', - 'finger': '', - 'freenet': '', - 'ftp': 'File Transfer Protocol; RFC 1738', - 'go': 'go; RFC 3368', - 'gopher': 'The Gopher Protocol', - 'gsm-sms': ('Global System for Mobile Communications Short Message ' - 'Service'), - 'h323': ('video (audiovisual) communication on local area networks; ' - 'RFC 3508'), - 'h324': ('video and audio communications over low bitrate connections ' - 'such as POTS modem connections'), - 'hdl': 'CNRI handle system', - 'hnews': 'an HTTP-tunneling variant of the NNTP news protocol', - 'http': 'Hypertext Transfer Protocol; RFC 2616', - 'https': 'HTTP over SSL; RFC 2818', - 'hydra': 'SubEthaEdit URI. See http://www.codingmonkeys.de/subethaedit.', - 'iioploc': 'Internet Inter-ORB Protocol Location?', - 'ilu': 'Inter-Language Unification', - 'im': 'Instant Messaging; RFC 3860', - 'imap': 'Internet Message Access Protocol; RFC 2192', - 'info': 'Information Assets with Identifiers in Public Namespaces', - 'ior': 'CORBA interoperable object reference', - 'ipp': 'Internet Printing Protocol; RFC 3510', - 'irc': 'Internet Relay Chat', - 'iris.beep': 'iris.beep; RFC 3983', - 'iseek' : 'See www.ambrosiasw.com; a little util for OS X.', - 'jar': 'Java archive', - 'javascript': ('JavaScript code; evaluates the expression after the ' - 'colon'), - 'jdbc': 'JDBC connection URI.', - 'ldap': 'Lightweight Directory Access Protocol', - 'lifn': '', - 'livescript': '', - 'lrq': '', - 'mailbox': 'Mail folder access', - 'mailserver': 'Access to data available from mail servers', - 'mailto': 'Electronic mail address; RFC 2368', - 'md5': '', - 'mid': 'message identifier; RFC 2392', - 'mocha': '', - 'modem': ('a connection to a terminal that can handle incoming data ' - 'calls; RFC 2806'), - 'mtqp': 'Message Tracking Query Protocol; RFC 3887', - 'mupdate': 'Mailbox Update (MUPDATE) Protocol; RFC 3656', - 'news': 'USENET news; RFC 1738', - 'nfs': 'Network File System protocol; RFC 2224', - 'nntp': 'USENET news using NNTP access; RFC 1738', - 'opaquelocktoken': 'RFC 2518', - 'phone': '', - 'pop': 'Post Office Protocol; RFC 2384', - 'pop3': 'Post Office Protocol v3', - 'pres': 'Presence; RFC 3859', - 'printer': '', - 'prospero': 'Prospero Directory Service; RFC 4157', - 'rdar' : ('URLs found in Darwin source ' - '(http://www.opensource.apple.com/darwinsource/).'), - 'res': '', - 'rtsp': 'real time streaming protocol; RFC 2326', - 'rvp': '', - 'rwhois': '', - 'rx': 'Remote Execution', - 'sdp': '', - 'service': 'service location; RFC 2609', - 'shttp': 'secure hypertext transfer protocol', - 'sip': 'Session Initiation Protocol; RFC 3261', - 'sips': 'secure session intitiaion protocol; RFC 3261', - 'smb': 'SAMBA filesystems.', - 'snews': 'For NNTP postings via SSL', - 'snmp': 'Simple Network Management Protocol; RFC 4088', - 'soap.beep': 'RFC 3288', - 'soap.beeps': 'RFC 3288', - 'ssh': 'Reference to interactive sessions via ssh.', - 't120': 'real time data conferencing (audiographics)', - 'tag': 'RFC 4151', - 'tcp': '', - 'tel': ('a connection to a terminal that handles normal voice ' - 'telephone calls, a voice mailbox or another voice messaging ' - 'system or a service that can be operated using DTMF tones; ' - 'RFC 2806.'), - 'telephone': 'telephone', - 'telnet': 'Reference to interactive sessions; RFC 4248', - 'tftp': 'Trivial File Transfer Protocol; RFC 3617', - 'tip': 'Transaction Internet Protocol; RFC 2371', - 'tn3270': 'Interactive 3270 emulation sessions', - 'tv': '', - 'urn': 'Uniform Resource Name; RFC 2141', - 'uuid': '', - 'vemmi': 'versatile multimedia interface; RFC 2122', - 'videotex': '', - 'view-source': 'displays HTML code that was generated with JavaScript', - 'wais': 'Wide Area Information Servers; RFC 4156', - 'whodp': '', - 'whois++': 'Distributed directory service.', - 'x-man-page': ('Opens man page in Terminal.app on OS X ' - '(see macosxhints.com)'), - 'xmlrpc.beep': 'RFC 3529', - 'xmlrpc.beeps': 'RFC 3529', - 'z39.50r': 'Z39.50 Retrieval; RFC 2056', - 'z39.50s': 'Z39.50 Session; RFC 2056',} Modified: trunk/docutils/docutils/utils/__init__.py =================================================================== --- trunk/docutils/docutils/utils/__init__.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/utils/__init__.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -17,7 +17,7 @@ from docutils import ApplicationError, DataError from docutils import nodes from docutils.io import FileOutput -from docutils.error_reporting import ErrorOutput, SafeString +from docutils.utils.error_reporting import ErrorOutput, SafeString class SystemMessage(ApplicationError): Copied: trunk/docutils/docutils/utils/error_reporting.py (from rev 7462, trunk/docutils/docutils/error_reporting.py) =================================================================== --- trunk/docutils/docutils/utils/error_reporting.py (rev 0) +++ trunk/docutils/docutils/utils/error_reporting.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -0,0 +1,207 @@ +#!/usr/bin/env python +# -*- coding: utf8 -*- + +# :Id: $Id$ +# :Copyright: © 2011 Günter Milde. +# :License: Released under the terms of the `2-Clause BSD license`_, in short: +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. +# This file is offered as-is, without any warranty. +# +# .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause + +""" +Error reporting should be safe from encoding/decoding errors. +However, implicit conversions of strings and exceptions like + +>>> u'%s world: %s' % ('H\xe4llo', Exception(u'H\xe4llo') + +fail in some Python versions: + +* In Python <= 2.6, ``unicode(<exception instance>)`` uses + `__str__` and fails with non-ASCII chars in`unicode` arguments. + (work around http://bugs.python.org/issue2517): + +* In Python 2, unicode(<exception instance>) fails, with non-ASCII + chars in arguments. (Use case: in some locales, the errstr + argument of IOError contains non-ASCII chars.) + +* In Python 2, str(<exception instance>) fails, with non-ASCII chars + in `unicode` arguments. + +The `SafeString`, `ErrorString` and `ErrorOutput` classes handle +common exceptions. +""" + +import sys, codecs + +# Guess the locale's encoding. +# If no valid guess can be made, locale_encoding is set to `None`: +try: + import locale # module missing in Jython +except ImportError: + locale_encoding = None +else: + locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] + # locale.getpreferredencoding([do_setlocale=True|False]) + # has side-effects | might return a wrong guess. + # (cf. Update 1 in http://stackoverflow.com/questions/4082645/using-python-2-xs-locale-module-to-format-numbers-and-currency) + try: + codecs.lookup(locale_encoding or '') # None -> '' + except LookupError: + locale_encoding = None + + + +class SafeString(object): + """ + A wrapper providing robust conversion to `str` and `unicode`. + """ + + def __init__(self, data, encoding=None, encoding_errors='backslashreplace', + decoding_errors='replace'): + self.data = data + self.encoding = (encoding or getattr(data, 'encoding', None) or + locale_encoding or 'ascii') + self.encoding_errors = encoding_errors + self.decoding_errors = decoding_errors + + + def __str__(self): + try: + return str(self.data) + except UnicodeEncodeError, err: + if isinstance(self.data, Exception): + args = [str(SafeString(arg, self.encoding, + self.encoding_errors)) + for arg in self.data.args] + return ', '.join(args) + if isinstance(self.data, unicode): + return self.data.encode(self.encoding, self.encoding_errors) + raise + + def __unicode__(self): + """ + Return unicode representation of `self.data`. + + Try ``unicode(self.data)``, catch `UnicodeError` and + + * if `self.data` is an Exception instance, work around + http://bugs.python.org/issue2517 with an emulation of + Exception.__unicode__, + + * else decode with `self.encoding` and `self.decoding_errors`. + """ + try: + u = unicode(self.data) + if isinstance(self.data, EnvironmentError): + u = u.replace(": u'", ": '") # normalize filename quoting + return u + except UnicodeError, error: # catch ..Encode.. and ..Decode.. errors + if isinstance(self.data, EnvironmentError): + return u"[Errno %s] %s: '%s'" % (self.data.errno, + SafeString(self.data.strerror, self.encoding, + self.decoding_errors), + SafeString(self.data.filename, self.encoding, + self.decoding_errors)) + if isinstance(self.data, Exception): + args = [unicode(SafeString(arg, self.encoding, + decoding_errors=self.decoding_errors)) + for arg in self.data.args] + return u', '.join(args) + if isinstance(error, UnicodeDecodeError): + return unicode(self.data, self.encoding, self.decoding_errors) + raise + +class ErrorString(SafeString): + """ + Safely report exception type and message. + """ + def __str__(self): + return '%s: %s' % (self.data.__class__.__name__, + super(ErrorString, self).__str__()) + + def __unicode__(self): + return u'%s: %s' % (self.data.__class__.__name__, + super(ErrorString, self).__unicode__()) + + +class ErrorOutput(object): + """ + Wrapper class for file-like error streams with + failsave de- and encoding of `str`, `bytes`, `unicode` and + `Exception` instances. + """ + + def __init__(self, stream=None, encoding=None, + encoding_errors='backslashreplace', + decoding_errors='replace'): + """ + :Parameters: + - `stream`: a file-like object, + a string (path to a file), + `None` (write to `sys.stderr`, default), or + evaluating to `False` (write() requests are ignored). + - `encoding`: `stream` text encoding. Guessed if None. + - `encoding_errors`: how to treat encoding errors. + """ + if stream is None: + stream = sys.stderr + elif not(stream): + stream = False + # if `stream` is a file name, open it + elif isinstance(stream, str): + stream = open(stream, 'w') + elif isinstance(stream, unicode): + stream = open(stream.encode(sys.getfilesystemencoding()), 'w') + + self.stream = stream + """Where warning output is sent.""" + + self.encoding = (encoding or getattr(stream, 'encoding', None) or + locale_encoding or 'ascii') + """The output character encoding.""" + + self.encoding_errors = encoding_errors + """Encoding error handler.""" + + self.decoding_errors = decoding_errors + """Decoding error handler.""" + + def write(self, data): + """ + Write `data` to self.stream. Ignore, if self.stream is False. + + `data` can be a `string`, `unicode`, or `Exception` instance. + """ + if self.stream is False: + return + if isinstance(data, Exception): + data = unicode(SafeString(data, self.encoding, + self.encoding_errors, self.decoding_errors)) + try: + self.stream.write(data) + except UnicodeEncodeError: + self.stream.write(data.encode(self.encoding, self.encoding_errors)) + except TypeError: # in Python 3, stderr expects unicode + if self.stream in (sys.stderr, sys.stdout): + self.stream.buffer.write(data) # write bytes to raw stream + else: + self.stream.write(unicode(data, self.encoding, + self.decoding_errors)) + + def close(self): + """ + Close the error-output stream. + + Ignored if the stream is` sys.stderr` or `sys.stdout` or has no + close() method. + """ + if self.stream in (sys.stdout, sys.stderr): + return + try: + self.stream.close() + except AttributeError: + pass Modified: trunk/docutils/docutils/utils/math/latex2mathml.py =================================================================== --- trunk/docutils/docutils/math/latex2mathml.py 2012-06-19 14:35:37 UTC (rev 7462) +++ trunk/docutils/docutils/utils/math/latex2mathml.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -19,7 +19,7 @@ # Based on the `latex_math` sandbox project by Jens Jørgen Mortensen -import docutils.math.tex2unichar as tex2unichar +import docutils.utils.math.tex2unichar as tex2unichar # TeX spacing combining over = {'acute': u'\u00B4', # u'\u0301', Copied: trunk/docutils/docutils/utils/urischemes.py (from rev 7462, trunk/docutils/docutils/urischemes.py) =================================================================== --- trunk/docutils/docutils/utils/urischemes.py (rev 0) +++ trunk/docutils/docutils/utils/urischemes.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -0,0 +1,136 @@ +# $Id$ +# Author: David Goodger <go...@py...> +# Copyright: This module has been placed in the public domain. + +""" +`schemes` is a dictionary with lowercase URI addressing schemes as +keys and descriptions as values. It was compiled from the index at +http://www.iana.org/assignments/uri-schemes (revised 2005-11-28) +and an older list at http://www.w3.org/Addressing/schemes.html. +""" + +# Many values are blank and should be filled in with useful descriptions. + +schemes = { + 'about': 'provides information on Navigator', + 'acap': 'Application Configuration Access Protocol; RFC 2244', + 'addbook': "To add vCard entries to Communicator's Address Book", + 'afp': 'Apple Filing Protocol', + 'afs': 'Andrew File System global file names', + 'aim': 'AOL Instant Messenger', + 'callto': 'for NetMeeting links', + 'castanet': 'Castanet Tuner URLs for Netcaster', + 'chttp': 'cached HTTP supported by RealPlayer', + 'cid': 'content identifier; RFC 2392', + 'crid': 'TV-Anytime Content Reference Identifier; RFC 4078', + 'data': ('allows inclusion of small data items as "immediate" data; ' + 'RFC 2397'), + 'dav': 'Distributed Authoring and Versioning Protocol; RFC 2518', + 'dict': 'dictionary service protocol; RFC 2229', + 'dns': 'Domain Name System resources', + 'eid': ('External ID; non-URL data; general escape mechanism to allow ' + 'access to information for applications that are too ' + 'specialized to justify their own schemes'), + 'fax': ('a connection to a terminal that can handle telefaxes ' + '(facsimiles); RFC 2806'), + 'feed' : 'NetNewsWire feed', + 'file': 'Host-specific file names; RFC 1738', + 'finger': '', + 'freenet': '', + 'ftp': 'File Transfer Protocol; RFC 1738', + 'go': 'go; RFC 3368', + 'gopher': 'The Gopher Protocol', + 'gsm-sms': ('Global System for Mobile Communications Short Message ' + 'Service'), + 'h323': ('video (audiovisual) communication on local area networks; ' + 'RFC 3508'), + 'h324': ('video and audio communications over low bitrate connections ' + 'such as POTS modem connections'), + 'hdl': 'CNRI handle system', + 'hnews': 'an HTTP-tunneling variant of the NNTP news protocol', + 'http': 'Hypertext Transfer Protocol; RFC 2616', + 'https': 'HTTP over SSL; RFC 2818', + 'hydra': 'SubEthaEdit URI. See http://www.codingmonkeys.de/subethaedit.', + 'iioploc': 'Internet Inter-ORB Protocol Location?', + 'ilu': 'Inter-Language Unification', + 'im': 'Instant Messaging; RFC 3860', + 'imap': 'Internet Message Access Protocol; RFC 2192', + 'info': 'Information Assets with Identifiers in Public Namespaces', + 'ior': 'CORBA interoperable object reference', + 'ipp': 'Internet Printing Protocol; RFC 3510', + 'irc': 'Internet Relay Chat', + 'iris.beep': 'iris.beep; RFC 3983', + 'iseek' : 'See www.ambrosiasw.com; a little util for OS X.', + 'jar': 'Java archive', + 'javascript': ('JavaScript code; evaluates the expression after the ' + 'colon'), + 'jdbc': 'JDBC connection URI.', + 'ldap': 'Lightweight Directory Access Protocol', + 'lifn': '', + 'livescript': '', + 'lrq': '', + 'mailbox': 'Mail folder access', + 'mailserver': 'Access to data available from mail servers', + 'mailto': 'Electronic mail address; RFC 2368', + 'md5': '', + 'mid': 'message identifier; RFC 2392', + 'mocha': '', + 'modem': ('a connection to a terminal that can handle incoming data ' + 'calls; RFC 2806'), + 'mtqp': 'Message Tracking Query Protocol; RFC 3887', + 'mupdate': 'Mailbox Update (MUPDATE) Protocol; RFC 3656', + 'news': 'USENET news; RFC 1738', + 'nfs': 'Network File System protocol; RFC 2224', + 'nntp': 'USENET news using NNTP access; RFC 1738', + 'opaquelocktoken': 'RFC 2518', + 'phone': '', + 'pop': 'Post Office Protocol; RFC 2384', + 'pop3': 'Post Office Protocol v3', + 'pres': 'Presence; RFC 3859', + 'printer': '', + 'prospero': 'Prospero Directory Service; RFC 4157', + 'rdar' : ('URLs found in Darwin source ' + '(http://www.opensource.apple.com/darwinsource/).'), + 'res': '', + 'rtsp': 'real time streaming protocol; RFC 2326', + 'rvp': '', + 'rwhois': '', + 'rx': 'Remote Execution', + 'sdp': '', + 'service': 'service location; RFC 2609', + 'shttp': 'secure hypertext transfer protocol', + 'sip': 'Session Initiation Protocol; RFC 3261', + 'sips': 'secure session intitiaion protocol; RFC 3261', + 'smb': 'SAMBA filesystems.', + 'snews': 'For NNTP postings via SSL', + 'snmp': 'Simple Network Management Protocol; RFC 4088', + 'soap.beep': 'RFC 3288', + 'soap.beeps': 'RFC 3288', + 'ssh': 'Reference to interactive sessions via ssh.', + 't120': 'real time data conferencing (audiographics)', + 'tag': 'RFC 4151', + 'tcp': '', + 'tel': ('a connection to a terminal that handles normal voice ' + 'telephone calls, a voice mailbox or another voice messaging ' + 'system or a service that can be operated using DTMF tones; ' + 'RFC 2806.'), + 'telephone': 'telephone', + 'telnet': 'Reference to interactive sessions; RFC 4248', + 'tftp': 'Trivial File Transfer Protocol; RFC 3617', + 'tip': 'Transaction Internet Protocol; RFC 2371', + 'tn3270': 'Interactive 3270 emulation sessions', + 'tv': '', + 'urn': 'Uniform Resource Name; RFC 2141', + 'uuid': '', + 'vemmi': 'versatile multimedia interface; RFC 2122', + 'videotex': '', + 'view-source': 'displays HTML code that was generated with JavaScript', + 'wais': 'Wide Area Information Servers; RFC 4156', + 'whodp': '', + 'whois++': 'Distributed directory service.', + 'x-man-page': ('Opens man page in Terminal.app on OS X ' + '(see macosxhints.com)'), + 'xmlrpc.beep': 'RFC 3529', + 'xmlrpc.beeps': 'RFC 3529', + 'z39.50r': 'Z39.50 Retrieval; RFC 2056', + 'z39.50s': 'Z39.50 Session; RFC 2056',} Modified: trunk/docutils/docutils/writers/html4css1/__init__.py =================================================================== --- trunk/docutils/docutils/writers/html4css1/__init__.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/writers/html4css1/__init__.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -32,11 +32,11 @@ PIL = None import docutils from docutils import frontend, nodes, utils, writers, languages, io -from docutils.error_reporting import SafeString +from docutils.utils.error_reporting import SafeString from docutils.transforms import writer_aux -from docutils.math import unichar2tex, pick_math_environment -from docutils.math.latex2mathml import parse_latex_math -from docutils.math.math2html import math2html +from docutils.utils.math import unichar2tex, pick_math_environment +from docutils.utils.math.latex2mathml import parse_latex_math +from docutils.utils.math.math2html import math2html class Writer(writers.Writer): Modified: trunk/docutils/docutils/writers/latex2e/__init__.py =================================================================== --- trunk/docutils/docutils/writers/latex2e/__init__.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/docutils/writers/latex2e/__init__.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -24,9 +24,9 @@ except ImportError: import docutils.utils.roman as roman from docutils import frontend, nodes, languages, writers, utils, io -from docutils.error_reporting import SafeString +from docutils.utils.error_reporting import SafeString from docutils.transforms import writer_aux -from docutils.math import pick_math_environment, unichar2tex +from docutils.utils.math import pick_math_environment, unichar2tex class Writer(writers.Writer): Modified: trunk/docutils/setup.py =================================================================== --- trunk/docutils/setup.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/setup.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -132,7 +132,7 @@ # 'docutils.readers.python', # in the sandbox since 0.8 'docutils.transforms', 'docutils.utils', - 'docutils.math', + 'docutils.utils.math', 'docutils.writers', 'docutils.writers.html4css1', # 'docutils.writers.html4strict', # in the sandbox! Modified: trunk/docutils/test/DocutilsTestSupport.py =================================================================== --- trunk/docutils/test/DocutilsTestSupport.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/test/DocutilsTestSupport.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -9,7 +9,7 @@ :Modules: - `statemachine` is 'docutils.statemachine' - `nodes` is 'docutils.nodes' - - `urischemes` is 'docutils.urischemes' + - `urischemes` is 'docutils.utils.urischemes' - `utils` is 'docutils.utils' - `transforms` is 'docutils.transforms' - `states` is 'docutils.parsers.rst.states' @@ -65,7 +65,8 @@ import package_unittest import docutils import docutils.core - from docutils import frontend, nodes, statemachine, urischemes, utils + from docutils import frontend, nodes, statemachine, utils + from docutils.utils import urischemes from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, roles, languages Modified: trunk/docutils/test/test_error_reporting.py =================================================================== --- trunk/docutils/test/test_error_reporting.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/test/test_error_reporting.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -36,7 +36,7 @@ import DocutilsTestSupport # must be imported before docutils from docutils import core, parsers, frontend, utils -from docutils.error_reporting import SafeString, ErrorString, ErrorOutput +from docutils.utils.error_reporting import SafeString, ErrorString, ErrorOutput from docutils._compat import b, bytes oldlocale = None Modified: trunk/docutils/test/test_io.py =================================================================== --- trunk/docutils/test/test_io.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/test/test_io.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -12,7 +12,7 @@ import DocutilsTestSupport # must be imported before docutils from docutils import io from docutils._compat import b, bytes -from docutils.error_reporting import locale_encoding +from docutils.utils.error_reporting import locale_encoding from test_error_reporting import BBuf, UBuf class mock_stdout(UBuf): Modified: trunk/docutils/tools/buildhtml.py =================================================================== --- trunk/docutils/tools/buildhtml.py 2012-06-22 19:49:51 UTC (rev 7463) +++ trunk/docutils/tools/buildhtml.py 2012-06-25 13:16:03 UTC (rev 7464) @@ -29,7 +29,7 @@ import docutils from docutils import ApplicationError from docutils import core, frontend, utils -from docutils.error_reporting import ErrorOutput, ErrorString +from docutils.utils.error_reporting import ErrorOutput, ErrorString from docutils.parsers import rst from docutils.readers import standalone, pep from docutils.writers import html4css1, pep_html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |