ePdZddlZddlZdZeedZdZdZdZdZ d d Z y) z Support functions for dealing with differences in platforms, including Python versions and implementations. This file should have no imports from the rest of zope.interface because it is used during early bootstrapping. Nctt|tr t|d}t|tr|Std)Nasciiz)name must be a string or ASCII-only bytes) isinstancebytesstr TypeError)names 8/usr/lib/python3/dist-packages/zope/interface/_compat.py_normalize_namer s3$4!$ ? @@pypy_version_infocNtjjd}|dk(}|S)z Return a true value if the C optimizations are required. This uses the ``PURE_PYTHON`` variable as documented in `_use_c_impl`. PURE_PYTHON0osenvironget)pure_env require_cs r _c_optimizations_requiredr#s% zz~~m,HCI r cPtrdntf} ddlm}|S#|$rYywxYw)z Return the C optimization module, if available, otherwise a false value. If the optimizations are required but not available, this raises the ImportError. This does not say whether they should be used or not. r)_zope_interface_coptimizationsF)r ImportErrorzope.interfacer)catchc_opts r _c_optimizations_availabler.s1,-BK>EJ s %%cVtjjd}|duxr|dk7S)z6 The opposite of `_c_optimizations_required`. rNrr)rs r _c_optimizations_ignoredr!@s*zz~~m,H 4  3HO3r cTttd}try|ryt S)z Return a true value if we should attempt to use the C optimizations. This takes into account whether we're on PyPy and the value of the ``PURE_PYTHON`` environment variable, as defined in `_use_c_impl`. r TF)hasattrsysrr!)is_pypys r _should_attempt_c_optimizationsr&Hs,c./G "') ))r cxs j|xstjdj}fd}|}|dz<|dz<|S)a Decorator. Given an object implemented in Python, with a name like ``Foo``, import the corresponding C implementation from ``zope.interface._zope_interface_coptimizations`` with the name ``Foo`` and use it instead. If the ``PURE_PYTHON`` environment variable is set to any value other than ``"0"``, or we're on PyPy, ignore the C implementation and return the Python version. If the C implementation cannot be imported, return the Python version. If ``PURE_PYTHON`` is set to 0, *require* the C implementation (let the ImportError propagate); note that PyPy can import the C implementation in this case (and all tests pass). In all cases, the Python version is kept available. in the module globals with the name ``FooPy`` and the name ``FooFallback`` (both conventions have been used; the C implementation of some functions looks for the ``Fallback`` version, as do some of the Sphinx documents). Example:: @_use_c_impl class Foo(object): ... cTtsSt}|sS|}t|S)N)r&rgetattr)r__traceback_info__r py_impls r find_implz_use_c_impl..find_implvs1.0N*,N"ud##r PyFallback)__name__r$ _getframe f_globals)r,r globsr-c_impls`` r _use_c_implr5Xs`6  #7##D  /S]]1%//E $[F!E$+&E$  Mr )NN) __doc__rr$r r#PYPYrrr!r&r5rr r r8s@ As'($4 * /r