B “äî\ª ã @südZddlZddlZy ddlZWnek r8dZYn�Xye ¡dpRe ¡dZWnDek rŒZ zde j krxdZndZWddZ [ XYndZYnXye  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úB/tmp/pip-build-uw_ogi45/docutils/docutils/utils/error_reporting.pyÚ__init__Is  zSafeString.__init__cs€y tˆjƒStk rztˆjtƒrF‡fdd„ˆjjDƒ}d |¡StˆjtƒrttjdkrbˆjSˆj  ˆj ˆj ¡S‚YnXdS)Ncs g|]}tt|ˆjˆjƒƒ‘qSr)Ústrrrr )Ú.0Úarg)rrrú Wsz&SafeString.__str__..z, )ér) rr ÚUnicodeEncodeErrorÚ isinstanceÚ ExceptionÚargsÚjoinÚsysÚ version_infoÚencoderr )rrr)rrÚ__str__Rs        zSafeString.__str__c sÖy&tˆjƒ}tˆjtƒr$| dd¡}|Stk rÐ}zŒtˆjtƒrvdˆjjtˆjjˆj ˆj ƒtˆjj ˆj ˆj ƒfStˆjt ƒr¢‡fdd„ˆjj Dƒ}d |¡St|tƒr¾tˆjˆj ˆj ƒS‚Wdd}~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 )rr)rrrr|sz*SafeString.__unicode__..z, N)rr rÚEnvironmentErrorrÚ UnicodeErrorÚerrnorÚstrerrorrr ÚfilenamerrrÚUnicodeDecodeError)rÚuÚerrorrr)rrÚ __unicode__cs&             zSafeString.__unicode__)Nrr)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr(rrrrrDs  rcs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú ErrorStringz3 Safely report exception type and message. csd|jjjtt|ƒ ¡fS)Nz%s: %s)r Ú __class__r)Úsuperr-r)r)r.rrrˆs zErrorString.__str__csd|jjjtt|ƒ ¡fS)Nz%s: %s)r r.r)r/r-r()r)r.rrr(Œs zErrorString.__unicode__)r)r*r+r,rr(Ú __classcell__rr)r.rr-„s r-c@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 )rr6rr r rrrr˜s     zErrorOutput.__init__c Csä|jdkrdSt|tƒr0tt||j|j|jƒƒ}y|j |¡Wnžt k rl|j |  |j|j¡¡Yntt k rÞt|tƒr |j |  |j|j¡¡dS|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)r6rrrrrr r ÚwriterrÚ TypeErrorrr3ÚstdoutÚbuffer)rr rrrr7»s$     zErrorOutput.writecCs>|jtjtjfkrdSy|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)r6rr9r3ÚcloseÚAttributeError)rrrrr;Õs zErrorOutput.close)NNrr)r)r*r+r,rr7r;rrrrr1‘s  !r1)r,rÚcodecsÚlocaleÚ ImportErrorr Ú getlocaleÚgetdefaultlocaleÚ ValueErrorr'rÚlookupÚ LookupErrorÚobjectrr-r1rrrrÚ$s(     @