l
&δϋ]c               @   sJ  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  d$ k  re j Z n e Z y e j Z Wn e k
 r=e j Z Yn 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 Gd   d e6  Z7 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  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(&   uP   The compat module provides various Python 2 / Python 3
compatibility functions

i    Ni   i   u   (\d+).+u   Linuxu   Darwinu   Windowsu   AbstractBase(   u   quoteu   unquoteu	   urlencodeu   parse_qsu   urlparse(   u   StringIOc               C   s
   t  j   S(   u:   
            Python 3 supports monotonic time
            (   u   timeu	   monotonic(    (    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   time_now;   s    c               C   s
   t  j    S(   uE   
            Python <3.3 does not support monotonic time
            (   u   time(    (    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   time_nowB   s    c             C   s   t  |  j    S(   u   
        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).
        (   u   listu   keys(   u   dct(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   dictkeysH   s    
c             C   s   t  |  j    S(   u(  
        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).
        (   u   listu   values(   u   dct(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu
   dictvaluesT   s    	c             C   s
   |  j    S(   u<  
        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).
        (   u   items(   u   dct(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   dict_iteritems_   s    	c             C   s
   |  j    S(   uw   
        :param dict dct:
        :returns: an iterator of the values of a dictionary
        :rtype: iterator
        (   u   values(   u   dct(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   dict_itervaluesj   s    c              G   s
   t  |   S(   u  
        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.
        (   u   bytes(   u   args(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   byter   s    c             B   s   |  Ee  Z d  Z d   Z d S(   uy   
        A marker class that signifies that the integer value should be
        serialized as `l` instead of `I`
        c             C   s   t  |   d S(   Nu   L(   u   str(   u   self(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   __repr__   s    N(   u   __name__u
   __module__u   __doc__u   __repr__(   u
   __locals__(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   long|   s   
u   longc             C   s
   t  |   S(   us   
        Return the canonical str value for the string.
        In both Python 3 and Python 2 this is str.
        (   u   str(   u   value(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   canonical_str   s    c             C   s   t  |  t  S(   u&   
        Is value an integer?
        (   u
   isinstanceu   int(   u   value(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu
   is_integer   s    (   u   quoteu   unquoteu	   urlencode(   u   parse_qsu   urlparsec               C   s
   t  j    S(   u:   
        Python 2 does not support monotonic time
        (   u   time(    (    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   time_now’   s    c             C   s:   y t  |   SWn% t k
 r5 t  |  j d   SYn Xd S(   uΖ   
        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.
        u   utf-8N(   u   stru   UnicodeEncodeErroru   encode(   u   value(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   canonical_str¨   s    c             C   s   t  |  t t f  S(   u&   
        Is value an integer?
        (   u
   isinstanceu   intu   long(   u   value(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu
   is_integer΄   s    c             C   s    t  |  t  s |  j d  S|  S(   u    
    Returns value as bytes
    u   UTF-8(   u
   isinstanceu   bytesu   encode(   u   value(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   as_bytes»   s    c             C   sC   |  j    r t |   St j |   } | r? t | j   d  Sd S(   u%   
    Returns value as in integer
    i    (   u   isdigitu   intu   RE_NUMu   matchu   groups(   u   valueu   match(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   to_digitΔ   s    
c             C   s9   |  j  d  d } t t t | j  d  d d    S(   u   
    Gets linux version
    u   -i    u   .Ni   (   u   splitu   tupleu   mapu   to_digit(   u   release_stru   ver_str(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   get_linux_versionΞ   s    u   posixi   u	   127.0.0.1u   ::1c       
      C   sh  |  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 d  \ } } t  j  |  | |  } y) | j | | f  | j   \ } }	 Wn t k
 r4| j     Yn XWd | j   X| j d  | j d  | | f S(	   uΔ   
    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.
    u?   Only AF_INET and AF_INET6 socket address families are supportedu0   Only SOCK_STREAM socket socket_type is supportedi    u   Only protocol zero is supportedi   Ni   F(   u   socketu   AF_INETu
   _LOCALHOSTu   AF_INET6u   _LOCALHOST_V6u
   ValueErroru   SOCK_STREAMu   bindu   listenu   minu	   SOMAXCONNu   getsocknameu   connectu   acceptu	   Exceptionu   closeu   setblockingu   False(
   u   familyu   socket_typeu   protou   hostu   lsocku   addru   portu   csocku   ssocku   _(    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   _nonblocking_socketpairβ   s2    		
(   i   i   (   i   i   (P   u   __doc__u   abcu   osu   platformu   reu   socketu   sysu   _sysu   timeu   version_infou   majoru   PY2u   PY3u   minoru   PY3_3u   compileu   RE_NUMu   systemu   ON_LINUXu   ON_OSXu
   ON_WINDOWSu   ABCMetau   objectu   AbstractBaseu   erroru   SOCKET_ERRORu   OSErroru   SOL_TCPu   AttributeErroru   IPPROTO_TCPu   urllib.parseu   quoteu	   url_quoteu   unquoteu   url_unquoteu	   urlencodeu   parse_qsu   url_parse_qsu   urlparseu   iou   StringIOu   stru
   basestringu   bytesu   str_or_bytesu   rangeu   xrangeu   unicode_typeu   time_nowu   dictkeysu
   dictvaluesu   dict_iteritemsu   dict_itervaluesu   byteu   intu   longu   canonical_stru
   is_integeru   urllibu   unicodeu   dictu   keysu   valuesu	   iteritemsu
   itervaluesu   chru   as_bytesu   to_digitu   get_linux_versionu   nameu   HAVE_SIGNALu   EINTR_IS_EXPOSEDu   Noneu   LINUX_VERSIONu   releaseu
   _LOCALHOSTu   _LOCALHOST_V6u   AF_INETu   SOCK_STREAMu   _nonblocking_socketpair(    (    (    u0   /srv/kernel/kteam-tools/dashboard/pika/compat.pyu   <module>   s   (							
												
	