"Fossies" - the Fresh Open Source Software Archive

Member "pyzor-1.0.0/pyzor/hacks/py26.py" (10 Dec 2014, 1258 Bytes) of package /linux/privat/pyzor-1.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "py26.py" see the Fossies "Dox" file reference documentation.

    1 """Hacks for Python 2.6"""
    2 
    3 __all__ = ["hack_all", "hack_email", "hack_select"]
    4 
    5 
    6 def hack_all(email=True, select=True):
    7     """Apply all Python 2.6 patches."""
    8     if email:
    9         hack_email()
   10     if select:
   11         hack_select()
   12 
   13 
   14 def hack_email():
   15     """The python2.6 version of email.message_from_string, doesn't work with
   16     unicode strings. And in python3 it will only work with a decoded.
   17 
   18     So switch to using only message_from_bytes.
   19     """
   20     import email
   21     if not hasattr(email, "message_from_bytes"):
   22         email.message_from_bytes = email.message_from_string
   23 
   24 
   25 def hack_select():
   26     """The python2.6 version of SocketServer does not handle interrupt calls
   27     from signals. Patch the select call if necessary.
   28     """
   29     import sys
   30     if sys.version_info[0] == 2 and sys.version_info[1] == 6:
   31         import select
   32         import errno
   33 
   34         real_select = select.select
   35 
   36         def _eintr_retry(*args):
   37             """restart a system call interrupted by EINTR"""
   38             while True:
   39                 try:
   40                     return real_select(*args)
   41                 except (OSError, select.error) as ex:
   42                     if ex.args[0] != errno.EINTR:
   43                         raise
   44         select.select = _eintr_retry