U å€C^ª ã @südZddlZddlZz ddlZWnek r8dZYn�Xze ¡dpRe ¡dZWnDek rŒZ zde j krxdZndZW5dZ [ XYndZYnXze  ep¨d¡Wne k rÆdZYnXGdd„de ƒZGd d „d eƒZGd d „d e ƒZdS) ué Error reporting should be safe from encoding/decoding errors. However, implicit conversions of strings and exceptions like >>> u'%s world: %s' % ('Hällo', Exception(u'Hällo') fail in some Python versions: * In Python <= 2.6, ``unicode()`` uses `__str__` and fails with non-ASCII chars in`unicode` arguments. (work around http://bugs.python.org/issue2517): * In Python 2, unicode() 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() fails, with non-ASCII chars in `unicode` arguments. The `SafeString`, `ErrorString` and `ErrorOutput` classes handle common exceptions. éNézunknown locale: UTF-8zUTF-8Úc@s*eZdZdZd dd„Zdd„Zd d „ZdS) Ú SafeStringzG A wrapper providing robust conversion to `str` and `unicode`. NÚbackslashreplaceÚreplacecCs0||_|pt|ddƒptpd|_||_||_dS)NÚencodingÚascii)ÚdataÚgetattrÚlocale_encodingrÚencoding_errorsÚdecoding_errors)Úselfr rr r ©rúD/tmp/pip-install-6_kvzl1k/docutils/docutils/utils/error_reporting.pyÚ__init__IsÿÿzSafeString.__init__csŽz tˆjƒWStk rˆtˆjtƒrL‡fdd„ˆjjDƒ}d |¡YStˆjtƒr‚tjdkrlˆjYSˆj  ˆj ˆj ¡YS‚YnXdS)Ncs g|]}tt|ˆjˆjƒƒ‘qSr)Ústrrrr ©Ú.0Úarg©rrrÚ Wsþ ÿz&SafeString.__str__..ú, )ér) rr ÚUnicodeEncodeErrorÚ isinstanceÚ ExceptionÚargsÚjoinÚsysÚ version_infoÚencoderr )rrrrrÚ__str__Rs   þ    ÿzSafeString.__str__c sðz(tˆjƒ}tˆjtƒr$| dd¡}|WStk rê}z¤tˆjtƒr€dˆjjtˆjjˆj ˆj ƒtˆjj ˆj ˆj ƒfWY¢`Stˆjt ƒr´‡fdd„ˆjj Dƒ}d |¡WY¢,St|tƒrØtˆjˆj ˆj ƒWY¢S‚W5d}~XYnXdS)af 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`. z: u'z: 'z[Errno %s] %s: '%s'cs"g|]}tt|ˆjˆjd�ƒ‘qS))r )rrrr rrrrr|sþ ÿz*SafeString.__unicode__..rN)rr rÚEnvironmentErrorrÚ UnicodeErrorÚerrnorÚstrerrorrr ÚfilenamerrrÚUnicodeDecodeError)rÚuÚerrorrrrrÚ __unicode__cs.      ÿ ÿý  þ zSafeString.__unicode__)Nrr)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr"r+rrrrrDs ÿ rcs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú ErrorStringz3 Safely report exception type and message. csd|jjjtt|ƒ ¡fS©Nz%s: %s)r Ú __class__r,Úsuperr0r"r©r2rrr"ˆs  ÿzErrorString.__str__csd|jjjtt|ƒ ¡fSr1)r r2r,r3r0r+rr4rrr+Œs  ÿzErrorString.__unicode__)r,r-r.r/r"r+Ú __classcell__rrr4rr0„s r0c@s*eZdZdZd dd„Zdd„Zd d „ZdS) Ú ErrorOutputz’ Wrapper class for file-like error streams with failsave de- and encoding of `str`, `bytes`, `unicode` and `Exception` instances. NrrcCs~|dkrtj}n>|sd}n4t|tƒr0t|dƒ}nt|tƒrNt| t ¡¡dƒ}||_|pjt|ddƒpjt pjd|_ ||_ ||_ dS)a‘ :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. NFÚwrr) rÚstderrrrÚopenr!ÚgetfilesystemencodingÚstreamr r rr r )rr;rr r rrrr˜s"    ÿÿzErrorOutput.__init__c Csæ|jdkrdSt|tƒr0tt||j|j|jƒƒ}z|j |¡Wn t k rl|j |  |j|j¡¡Ynvt k ràt|tƒr¢|j |  |j|j¡¡YdS|jt j t jfkrÄ|jj |¡n|j t||j|jƒ¡YnXdS)z– Write `data` to self.stream. Ignore, if self.stream is False. `data` can be a `string`, `unicode`, or `Exception` instance. FN)r;rrrrrr r Úwriterr!Ú TypeErrorrr8ÚstdoutÚbuffer)rr rrrr<»s,   ÿ ÿÿzErrorOutput.writecCs>|jtjtjfkrdSz|j ¡Wntk r8YnXdS)z‘ Close the error-output stream. Ignored if the stream is` sys.stderr` or `sys.stdout` or has no close() method. N)r;rr>r8ÚcloseÚAttributeErrorrrrrr@Õs zErrorOutput.close)NNrr)r,r-r.r/rr<r@rrrrr6‘sþ #r6)r/rÚcodecsÚlocaleÚ ImportErrorr Ú getlocaleÚgetdefaultlocaleÚ ValueErrorr*rÚlookupÚ LookupErrorÚobjectrr0r6rrrrÚs(     @