%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/httplib2/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/httplib2/__pycache__/socks.cpython-312.pyc

�

Zճc�L��F�dZddlZddlZddlZddlZeedd��ed��dZdZdZ	dZ
daejZGd	�d
e
�ZGd�de�ZGd
�de�ZGd�de�ZGd�de�ZGd�de�ZdZdZdZdZ	dd�Zd�ZGd�dej�Zy)aSocksiPy - Python SOCKS module.

Version 1.00

Copyright 2006 Dan-Haim. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. Neither the name of Dan Haim nor the names of his contributors may be used
   to endorse or promote products derived from this software without specific
   prior written permission.

THIS SOFTWARE IS PROVIDED BY DAN HAIM "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL DAN HAIM OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMANGE.

This module provides a standard socket-like interface for Python
for tunneling connections through SOCKS proxies.

Minor modifications made by Christopher Gilbert (http://motomastyle.com/) for
use in PyLoris (http://pyloris.sourceforge.net/).

Minor modifications made by Mario Vilas (http://breakingcode.wordpress.com/)
mainly to merge bug fixes found in Sourceforge.
�N�socketz-socket.socket missing, proxy support unusable����c��eZdZy)�
ProxyErrorN��__name__�
__module__�__qualname__���0/usr/lib/python3/dist-packages/httplib2/socks.pyr	r	7���rr	c��eZdZy)�GeneralProxyErrorNr
rrrrr;rrrc��eZdZy)�Socks5AuthErrorNr
rrrrr?rrrc��eZdZy)�Socks5ErrorNr
rrrrrCrrrc��eZdZy)�Socks4ErrorNr
rrrrrGrrrc��eZdZy)�	HTTPErrorNr
rrrrrKrrr)�successzinvalid dataz
not connectedz
not availablezbad proxy typez	bad input)
�	succeededzgeneral SOCKS server failurez!connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedzTTL expiredzCommand not supportedzAddress type not supportedz
Unknown error)rzauthentication is requiredz0all offered authentication methods were rejectedz$unknown username or invalid password�
unknown error)zrequest grantedzrequest rejected or failedzLrequest rejected because SOCKS server cannot connect to identd on the clientzPrequest rejected because the client program and identd report different user-idsrc��||||||fay)z�setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
    Sets a default proxy which all further socksocket objects will use,
    unless explicitly changed.
    N)�
_defaultproxy)�	proxytype�addr�port�rdns�username�passwords      r�setdefaultproxyr'ws����d�D�(�H�E�Mrc�V�tdk7rt|j_ytd��)a7wrapmodule(module)

    Attempts to replace a module's socket library with a SOCKS socket. Must set
    a default proxy using setdefaultproxy(...) first.
    This will only work on modules that import socket directly into the
    namespace;
    most of the Python Standard Library falls into this category.
    N)rzno proxy specified)r �
socksocketrr)�modules r�
wrapmoduler+�s$�����)��
�
��� 9�:�:rc���eZdZdZej
ejddfd�Zd�Z�fd�Z	d�Z
d�Z							dd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Z�xZS)r)asocksocket([family[, type[, proto]]]) -> socket object
    Open a SOCKS enabled socket. The parameters are the same as
    those of the standard socket init. In order for SOCKS to work,
    you must specify family=AF_INET, type=SOCK_STREAM and proto=0.
    rNc��tj|||||�tdk7rt|_nd|_d|_d|_d|_y)N)NNNNNNT)�
_orgsocket�__init__r �_socksocket__proxy�_socksocket__proxysockname�_socksocket__proxypeername�_socksocket__httptunnel)�self�family�type�proto�_socks     rr/zsocksocket.__init__�sH��	���D�&�$��u�=��D� �(�D�L�?�D�L�#���#��� ��rc��|j|�}t|�|kr>|j|t|�z
�}|std��||z}t|�|kr�>|S)z�__recvall(count) -> data
        Receive EXACTLY the number of bytes requested from the socket.
        Blocks until the required number of bytes have been received.
        )rzconnection closed unexpectedly)�recv�lenr)r4�count�data�ds    r�	__recvallzsocksocket.__recvall�sb��
�y�y�����$�i�%���	�	�%�#�d�)�+�,�A��'�(M�N�N��!�8�D�	�$�i�%��
�rc�f��|js|j|�}tt|�|g|���S)zq override socket.socket.sendall method to rewrite the header
        for non-tunneling proxies if needed
        )r3�_socksocket__rewriteproxy�superr)�sendall)r4�content�args�	__class__s   �rrCzsocksocket.sendall�s5���� � ��)�)�'�2�G��Z��.�w�>��>�>rc
��d\}}|jd�}|D]e}|j�jd�r|}�%|j�jd�s |j�jd�s�d|}�g|r�|r�|j|�|j|�|jd�d}|jd�}|jdd	k7r2|jd
d	k7r |jd|j
��|jdd|z�|jd|d�d
|�|d�d|d���dj|�S)z� rewrite HTTP request headers to support non-tunneling proxies
        (i.e. those which do not support the CONNECT method).
        This only works for HTTP (not HTTPS) since HTTPS requires tunneling.
        )NN�
zhost:�get�post� rrN�rzHost: %sz http://r)�split�lower�
startswith�remover0�insert�_socksocket__getauthheader�join)r4�header�host�endpt�hdrs�hdrs      r�__rewriteproxyzsocksocket.__rewriteproxy�s*��
!���e��|�|�F�#���	�C��y�y�{�%�%�g�.�������'�'��.�#�)�)�+�2H�2H��2P���		�
�E��K�K����K�K����:�:�c�?�1�%�D��K�K��$�E��|�|�A��$�&�4�<�<��?�d�+B����A�t�3�3�5�6��K�K��:��,�-��K�K��%��(�D�%��(�E�RS�H�U�V��{�{�4� � rc��|jddz|jdz}dtj|�j�zS)Nr�:rLzProxy-Authorization: Basic )r0�base64�	b64encode�decode)r4�auths  r�__getauthheaderzsocksocket.__getauthheader�s@���|�|�A���%����Q��7��,�v�/?�/?��/E�/L�/L�/N�N�Nrc�h�|||||r|j�nd|r|j�nd|f|_y)a
setproxy(proxytype, addr[, port[, rdns[, username[, password]]]])

        Sets the proxy to be used.
        proxytype -    The type of the proxy to be used. Three types
                are supported: PROXY_TYPE_SOCKS4 (including socks4a),
                PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
        addr -        The address of the server (IP or DNS).
        port -        The port of the server. Defaults to 1080 for SOCKS
                servers and 8080 for HTTP proxy servers.
        rdns -        Should DNS queries be preformed on the remote side
                (rather than the local side). The default is True.
                Note: This has no effect with SOCKS4 servers.
        username -    Username to authenticate with to the server.
                The default is no authentication.
        password -    Password to authenticate with to the server.
                Only relevant when username is also provided.
        headers -     Additional or modified headers for the proxy connect
        request.
        N)�encoder0)r4r!r"r#r$r%r&�headerss        r�setproxyzsocksocket.setproxy�s8��<
����!)�H�O�O��t�!)�H�O�O��t��
��rc	�~�|jddk7r;|jddk7r)|jtjddddd��n'|jtjdddd��|j	d�}|ddtd�j
�k7r$|j�tdtdf��|ddtd�j
�k(r�n�|ddtd�j
�k(�rMt�}|jd�|jt|jd��|j|jd�|jt|jd��|j|jd�|j|�|j	d�}|ddtd�j
�k7r$|j�tdtdf��|ddtd�j
�k7r{|j�td	td	f��|j�|dtd
�j
�k(rtdtdf��tdtdf��tjdddd�}	t!j"|�}|td�j
�z|z}|tjd|�z}|j|�|j	d�}|ddtd�j
�k7r$|j�tdtdf��|ddtd�j
�k7ra|j�t)|dd�dkr,t+t)|dd�t,t)|dd�f��t+d
t,d
f��|d	dtd�j
�k(r|j	d�}	nu|d	dtd	�j
�k(r2||j/d�z}|j	t)|dd��}	n$|j�tdtdf��tj0d|j	d��d}
|	|
f|_|dk7rt!j4|�|f|_y||f|_y#t j$$r�|jd	rSd}|td	�j
�ztt|��j
�z|j
�z}nGt!j"t!j&|��}|td�j
�z|z}Y���wxYw)zk__negotiatesocks5(self,destaddr,destport)
        Negotiates a connection through a SOCKS5 server.
        rNrL�BBBBrr�BBBrr��>H��	)r0rC�struct�pack�_socksocket__recvall�chrrb�closer�_generalerrors�	bytearray�appendr;�extendr�_socks5autherrorsr�	inet_aton�error�
gethostbyname�ordr�
_socks5errorsr:�unpackr1�	inet_ntoar2)r4�destaddr�destport�
chosenauth�packet�authstat�req�ipaddr�resp�	boundaddr�	boundports           r�__negotiatesocks5zsocksocket.__negotiatesocks5�s���

�L�L��O�t�#�$�,�,�q�/�T�*A�
�L�L����V�T�4��t�D�E�
�L�L����U�D�$��=�>��^�^�A�&�
��a��?�c�$�i�.�.�0�0��J�J�L�#�Q��q�(9�$:�;�;��a��?�c�$�i�.�.�0�0��
��!�_��D�	� 0� 0� 2�
2��[�F��M�M�$���M�M�#�d�l�l�1�o�.�/��M�M�$�,�,�q�/�*��M�M�#�d�l�l�1�o�.�/��M�M�$�,�,�q�/�*��L�L�� ��~�~�a�(�H���!�}��D�	� 0� 0� 2�2��
�
��'��N�1�,=�(>�?�?���!�}��D�	� 0� 0� 2�2��
�
��%�q�*;�A�*>�&?�@�@�
�J�J�L��!�}��D�	� 0� 0� 2�2�%�q�*;�A�*>�&?�@�@�'��N�1�,=�(>�?�?��k�k�%��t�T�2��	8��%�%�h�/�F���D�	�(�(�*�*�V�3�C� �F�K�K��h�/�/�����S���~�~�a� ����!�9��D�	�(�(�*�*��J�J�L�#�Q��q�(9�$:�;�;�
�!�A�Y�#�d�)�*�*�,�
,��J�J�L��4��!�9�~��"�!�3�t�A�a�y�>�=��T�!�A�Y��3P�"Q�R�R�!�1�m�A�&6�"7�8�8�
�!�A�Y�#�d�)�*�*�,�
,����q�)�I�
�!�A�Y�#�d�)�*�*�,�
,��$�)�)�A�,�&�D����s�4��!�9�~�6�I��J�J�L�#�Q��q�(9�$:�;�;��M�M�$����q�(9�:�1�=�	� )�9�5����T�>�$*�$4�$4�V�$<�h�#G�D� �$,�h�#7�D� ��W�|�|�	8��|�|�A������$�i�&�&�(�)��#�h�-�(�/�/�1�2��o�o�'�(�� �)�)�&�*>�*>�x�*H�I���C��I�,�,�.�.��7���	8�s�4S<�<B<V<�;V<c��|jS)zigetsockname() -> address info
        Returns the bound IP address and port number at the proxy.
        )r1�r4s r�getproxysocknamezsocksocket.getproxysocknamebs���#�#�#rc�,�tj|�S)z`getproxypeername() -> address info
        Returns the IP and port number of the proxy.
        )r.�getpeernamer�s r�getproxypeernamezsocksocket.getproxypeernamehs���%�%�d�+�+rc��|jS)z�getpeername() -> address info
        Returns the IP address and port number of the destination
        machine (note: getproxypeername returns the proxy)
        )r2r�s rr�zsocksocket.getpeernamens��
�#�#�#rc	��d}	tj|�}t	j
ddd|�|z}|jdd	k7r||jdz}|td�j�z}|r||ztd�j�z}|j|�|jd
�}|ddtd�j�k7r$|j�tdtdf��|ddtd�j�k7rs|j�t|dd�d
vr?|j�tt|dd�t t|dd�dz
f��tdt df��tj"|dd	�t	j$d|dd�df|_|d	k7rtj"|�|f|_y	||f|_y	#tj$rW|jdrt	j
ddddd�}d}n(tjtj|��}Y��AwxYw)zk__negotiatesocks4(self,destaddr,destport)
        Negotiates a connection through a SOCKS4 server.
        FrrfrrTz>BBHrNrjr�Z)�[�\�]�^ri)rrvrwr0rlrmrxrorbrCrnrprrqryr�
_socks4errorsr|r{r1r2)r4r}r~�rmtrslvr�r�r�s       r�__negotiatesocks4zsocksocket.__negotiatesocks4us*��
��	J��%�%�h�/�F��k�k�&�$��h�7�&�@���<�<��?�d�"�����Q��'�C��C��I�$�$�&�&�����.�3�t�9�#3�#3�#5�5�C����S���~�~�a� ����!�9��D�	�(�(�*�*��J�J�L�#�Q��q�(9�$:�;�;���!�9��D�	�(�(�*�*��J�J�L��4��!�9�~��-��
�
��!�3�t�A�a�y�>�=��T�!�A�Y��RT�AT�3U�"V�W�W�!�2�}�Q�'7�"8�9�9�
���T�!�"�X�&��M�M�$��Q�q�	�*�1�-� 
����d�?�$*�$4�$4�V�$<�h�#G�D� �$,�h�#7�D� ��S�|�|�	J��|�|�A�����V�T�4��t�D�����)�)�&�*>�*>�x�*H�I���
	J�s�G1�1A&I�Ic��|jdstj|�}n|}d|dt|�dg}d}d}|jddk7rT|jdj	�D]4\}}||d|d	gz
}|j�d
k(}|j�dk(}�6|s|d|d	gz
}|s9|jd
dk7r'|jddk7r||j
�d	gz
}|jd	�|jdj|�j��|jd�}	|	jdj��dk(r7|	|jd�z}	|	jdj��dk(r�7|	j�djdj�d�}
|
ddj�dj�fvr$|j�t!dt"df��	t%|
d�}|dk7r |j�t)||
df��d|_||f|_y#t&$r%|j�t!dt"df��wxYw)zh__negotiatehttp(self,destaddr,destport)
        Negotiates a connection through an HTTP server.
        rzCONNECT �:z HTTP/1.1
F�Nz: rHrUzproxy-authorizationzHost: rrL�rz

���rrKrzHTTP/1.0zHTTP/1.1��)z0.0.0.0r)r0rrx�str�	iteritemsrNrRrsrCrSrbr:�find�
splitlinesrMrprrq�int�
ValueErrorrr1r2)r4r}r~r"rc�wrote_host_header�wrote_auth_header�key�valr��
statusline�
statuscodes            r�__negotiatehttpzsocksocket.__negotiatehttp�sd��
�|�|�A���'�'��1�D��D��t�S�#�h�-��I��!��!���<�<��?�d�"� �L�L��O�5�5�7�
I���S��C��s�F�3�3��$'�I�I�K�6�$9�!�$'�I�I�K�3H�$H�!�
I�!���(�F�3�3�G� ��|�|�A��$�&�4�<�<��?�d�+B��D�0�0�2�F�;�;�����v�����R�W�W�W�%�,�,�.�/��y�y��|���i�i�
�)�)�+�,��2��$�)�)�A�,�&�D��i�i�
�)�)�+�,��2��_�_�&�q�)�/�/��
�
��a�@�
��a�=��!2�!2�!4�j�6G�6G�6I� J�J��J�J�L�#�Q��q�(9�$:�;�;�	<��Z��]�+�J�����J�J�L��Z��A��7�8�8�-��� $�h�/�����	<��J�J�L�#�Q��q�(9�$:�;�;�	<�s�I�.I=c�:�t|�ttfvs<t|�dks.t	|dt
tf�rt|d�tk7rtdtdf��|jdtk(rb|jddk7r|jd}nd}tj||jd|f�|j|d|d�y|jdtk(rb|jddk7r|jd}nd}tj||jd|f�|j!|d|d�y|jdt"k(rb|jddk7r|jd}nd}tj||jd|f�|j%|d|d�y|jdt&k(rr|jddk7r|jd}nd}tj||jd|f�|ddk(r|j%|d|d�yd	|_y|jddk(rtj||d|df�ytd
td
f��)z�connect(self, despair)
        Connects to the specified destination through a proxy.
        destpar - A tuple of the IP/DNS address and the port number.
        (identical to socket's connect).
        To select the proxy server use setproxy().
        rrrrLNi8i�i�Fr)r6�list�tupler;�
isinstancer��bytesr�rrqr0�PROXY_TYPE_SOCKS5r.�connect�_socksocket__negotiatesocks5�PROXY_TYPE_SOCKS4�_socksocket__negotiatesocks4�PROXY_TYPE_HTTP�_socksocket__negotiatehttp�PROXY_TYPE_HTTP_NO_TUNNELr3)r4�destpair�portnums   rr�zsocksocket.connect�sM���h��D�%�=�0��H�
��!��x��{�S�%�L�9��X�a�[�!�S�(�#�Q��q�(9�$:�;�;��<�<��?�/�/��|�|�A��$�&��,�,�q�/�������t�d�l�l�1�o�w�%?�@��"�"�8�A�;����<�
�\�\�!�_� 1�
1��|�|�A��$�&��,�,�q�/�������t�d�l�l�1�o�w�%?�@��"�"�8�A�;����<�
�\�\�!�_��
/��|�|�A��$�&��,�,�q�/�������t�d�l�l�1�o�w�%?�@�� � ��!��h�q�k�:�
�\�\�!�_� 9�
9��|�|�A��$�&��,�,�q�/�������t�d�l�l�1�o�w�%?�@���{�c�!��$�$�X�a�[�(�1�+�>�$)��!�
�\�\�!�_��
$����t�h�q�k�8�A�;�%?�@�#�Q��q�(9�$:�;�;r)NNNTNNN)rrr
�__doc__r�AF_INET�SOCK_STREAMr/rnrCrArRrdr�r�r�r�r�r�r��
__classcell__)rFs@rr)r)�s{�����^�^�&�*<�*<�A�T�
!��?�!�.O��
�
�
����%
�Ne8�N$�,�$�18�f+0�Z1<rr))NNNTNN)r�r\rrl�sys�getattr�ImportErrorr�r�r�r�r r.�	Exceptionr	rrrrrrqrzrur�r'r+r)rrr�<module>r�s���#�J�
�
�
�
�6�8�T�"�*�
�E�
F�F����������
�
�]�]�
�	��	�	�
�	�	�j�	�	�*�	�	�*�	�	�
�	����
����
�NR�F�;�u<����u<r

Zerion Mini Shell 1.0