ó
&äû]c           @   s@  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z e j	 j
 d k Z e Z e oˆ e j	 j d k Z e j d ƒ Z e j ƒ  d k Z e j ƒ  d k Z e j ƒ  d k Z e j d	 e f i  ƒ Z e j	 d  d% k  re j Z n e Z y e j Z Wn e k
 r6e j Z n Xe r	d d
 l m Z  m! Z" m# Z# m$ Z% m& Z& d d l' m( Z( e) f Z* e) e+ f Z, e- Z. e) Z/ e r¨d „  Z0 n	 d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d „  Z5 d e6 f d „  ƒ  YZ7 d „  Z8 d „  Z9 n¥ d d l: m Z  m! Z" m# Z# d d l& m$ Z% m& Z& d d l( m( Z( e* Z* e* Z, e. Z. e; Z/ e< j= Z1 e< j> Z2 e< j? Z3 e< j@ Z4 eA Z5 e7 Z7 d „  Z0 d „  Z8 d „  Z9 d „  ZB d „  ZC d „  ZD e jE d k ZF e j	 d  d& k ZG d ZI e j ƒ  d k reD e jJ ƒ  ƒ ZI n  d! ZK d" ZL e jM e jN d# d$ „ ZO d S('   sP   The compat module provides various Python 2 / Python 3
compatibility functions

iÿÿÿÿNi   i   s   (\d+).+t   Linuxt   Darwint   Windowst   AbstractBase(   t   quotet   unquotet	   urlencodet   parse_qst   urlparse(   t   StringIOc           C   s
   t  j ƒ  S(   s:   
            Python 3 supports monotonic time
            (   t   timet	   monotonic(    (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   time_now;   s    c           C   s
   t  j  ƒ  S(   sE   
            Python <3.3 does not support monotonic time
            (   R
   (    (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyR   B   s    c         C   s   t  |  j ƒ  ƒ S(   s   
        Returns a list of keys of dictionary

        dict.keys returns a view that works like .keys in Python 2
        *except* any modifications in the dictionary will be visible
        (and will cause errors if the view is being iterated over while
        it is modified).
        (   t   listt   keys(   t   dct(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   dictkeysH   s    
c         C   s   t  |  j ƒ  ƒ S(   s(  
        Returns a list of values of a dictionary

        dict.values returns a view that works like .values in Python 2
        *except* any modifications in the dictionary will be visible
        (and will cause errors if the view is being iterated over while
        it is modified).
        (   R   t   values(   R   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt
   dictvaluesT   s    	c         C   s
   |  j  ƒ  S(   s<  
        Returns an iterator of items (key/value pairs) of a dictionary

        dict.items returns a view that works like .items in Python 2
        *except* any modifications in the dictionary will be visible
        (and will cause errors if the view is being iterated over while
        it is modified).
        (   t   items(   R   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   dict_iteritems_   s    	c         C   s
   |  j  ƒ  S(   sw   
        :param dict dct:
        :returns: an iterator of the values of a dictionary
        :rtype: iterator
        (   R   (   R   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   dict_itervaluesj   s    c          G   s
   t  |  ƒ S(   s  
        This is the same as Python 2 `chr(n)` for bytes in Python 3

        Returns a single byte `bytes` for the given int argument (we
        optimize it a bit here by passing the positional argument tuple
        directly to the bytes constructor.
        (   t   bytes(   t   args(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   byter   s    t   longc           B   s   e  Z d  Z d „  Z RS(   sy   
        A marker class that signifies that the integer value should be
        serialized as `l` instead of `I`
        c         C   s   t  |  ƒ d S(   Nt   L(   t   str(   t   self(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   __repr__‚   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyR   |   s   c         C   s
   t  |  ƒ S(   ss   
        Return the canonical str value for the string.
        In both Python 3 and Python 2 this is str.
        (   R   (   t   value(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   canonical_str…   s    c         C   s   t  |  t ƒ S(   s&   
        Is value an integer?
        (   t
   isinstancet   int(   R!   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt
   is_integer   s    (   R   R   R   (   R   R   c           C   s
   t  j  ƒ  S(   s:   
        Python 2 does not support monotonic time
        (   R
   (    (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyR   ¢   s    c         C   s6   y t  |  ƒ SWn! t k
 r1 t  |  j d ƒ ƒ SXd S(   sÆ   
        Returns the canonical string value of the given string.
        In Python 2 this is the value unchanged if it is an str, otherwise
        it is the unicode value encoded as UTF-8.
        s   utf-8N(   R   t   UnicodeEncodeErrort   encode(   R!   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyR"   ¨   s    c         C   s   t  |  t t f ƒ S(   s&   
        Is value an integer?
        (   R#   R$   R   (   R!   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyR%   ´   s    c         C   s    t  |  t ƒ s |  j d ƒ S|  S(   s    
    Returns value as bytes
    s   UTF-8(   R#   R   R'   (   R!   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   as_bytes»   s    c         C   sC   |  j  ƒ  r t |  ƒ St j |  ƒ } | r? t | j ƒ  d ƒ Sd S(   s%   
    Returns value as in integer
    i    (   t   isdigitR$   t   RE_NUMt   matcht   groups(   R!   R+   (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   to_digitÄ   s    
c         C   s3   |  j  d ƒ d } t t t | j  d ƒ d  ƒ ƒ S(   s   
    Gets linux version
    t   -i    t   .i   (   t   splitt   tuplet   mapR-   (   t   release_strt   ver_str(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   get_linux_versionÎ   s    t   posixi   s	   127.0.0.1s   ::1i    c   
      C   sa  |  t  j k r t } n$ |  t  j k r0 t } n t d ƒ ‚ | t  j k rZ t d ƒ ‚ n  | d k ru t d ƒ ‚ n  t  j  |  | | ƒ } z¥ | j | d f ƒ | j t	 t  j
 d ƒ ƒ | j ƒ  d  \ } } t  j  |  | | ƒ } y) | j | | f ƒ | j ƒ  \ } }	 Wn t k
 r-| j ƒ  ‚  n XWd | j ƒ  X| j t ƒ | j t ƒ | | f S(   sÄ   
    Returns a pair of sockets in the manner of socketpair with the additional
    feature that they will be non-blocking. Prior to Python 3.5, socketpair
    did not exist on Windows at all.
    s?   Only AF_INET and AF_INET6 socket address families are supporteds0   Only SOCK_STREAM socket socket_type is supportedi    s   Only protocol zero is supportedi€   i   N(   t   sockett   AF_INETt
   _LOCALHOSTt   AF_INET6t   _LOCALHOST_V6t
   ValueErrort   SOCK_STREAMt   bindt   listent   mint	   SOMAXCONNt   getsocknamet   connectt   acceptt	   Exceptiont   closet   setblockingt   False(
   t   familyt   socket_typet   protot   hostt   lsockt   addrt   portt   csockt   ssockt   _(    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   _nonblocking_socketpairâ   s2    		
(   i   i   (   i   i   (P   R    t   abct   ost   platformt   reR7   t   syst   _sysR
   t   version_infot   majort   PY2t   PY3t   minort   PY3_3t   compileR*   t   systemt   ON_LINUXt   ON_OSXt
   ON_WINDOWSt   ABCMetat   objectR   t   errort   SOCKET_ERRORt   OSErrort   SOL_TCPt   AttributeErrort   IPPROTO_TCPt   urllib.parseR   t	   url_quoteR   t   url_unquoteR   R   t   url_parse_qsR   t   ioR	   R   t
   basestringR   t   str_or_bytest   ranget   xranget   unicode_typeR   R   R   R   R   R   R$   R   R"   R%   t   urllibt   unicodet   dictR   R   t	   iteritemst
   itervaluest   chrR(   R-   R5   t   namet   HAVE_SIGNALt   EINTR_IS_EXPOSEDt   Nonet   LINUX_VERSIONt   releaseR9   R;   R8   R=   RS   (    (    (    s+   /srv/kernel/kteam-tools/libs/pika/compat.pyt   <module>   sŠ   (							
												
	