GRAYBYTE WORDPRESS FILE MANAGER6212

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /lib/python2.7/site-packages/pip/_vendor/requests/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /lib/python2.7/site-packages/pip/_vendor/requests//auth.py
# -*- coding: utf-8 -*-

"""
requests.auth
~~~~~~~~~~~~~

This module contains the authentication handlers for Requests.
"""

import os
import re
import time
import hashlib
import threading
import warnings

from base64 import b64encode

from .compat import urlparse, str, basestring
from .cookies import extract_cookies_to_jar
from ._internal_utils import to_native_string
from .utils import parse_dict_header

CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
CONTENT_TYPE_MULTI_PART = 'multipart/form-data'


def _basic_auth_str(username, password):
    """Returns a Basic Auth string."""

    # "I want us to put a big-ol' comment on top of it that
    # says that this behaviour is dumb but we need to preserve
    # it because people are relying on it."
    #    - Lukasa
    #
    # These are here solely to maintain backwards compatibility
    # for things like ints. This will be removed in 3.0.0.
    if not isinstance(username, basestring):
        warnings.warn(
            "Non-string usernames will no longer be supported in Requests "
            "3.0.0. Please convert the object you've passed in ({0!r}) to "
            "a string or bytes object in the near future to avoid "
            "problems.".format(username),
            category=DeprecationWarning,
        )
        username = str(username)

    if not isinstance(password, basestring):
        warnings.warn(
            "Non-string passwords will no longer be supported in Requests "
            "3.0.0. Please convert the object you've passed in ({0!r}) to "
            "a string or bytes object in the near future to avoid "
            "problems.".format(password),
            category=DeprecationWarning,
        )
        password = str(password)
    # -- End Removal --

    if isinstance(username, str):
        username = username.encode('latin1')

    if isinstance(password, str):
        password = password.encode('latin1')

    authstr = 'Basic ' + to_native_string(
        b64encode(b':'.join((username, password))).strip()
    )

    return authstr


class AuthBase(object):
    """Base class that all auth implementations derive from"""

    def __call__(self, r):
        raise NotImplementedError('Auth hooks must be callable.')


class HTTPBasicAuth(AuthBase):
    """Attaches HTTP Basic Authentication to the given Request object."""

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def __eq__(self, other):
        return all([
            self.username == getattr(other, 'username', None),
            self.password == getattr(other, 'password', None)
        ])

    def __ne__(self, other):
        return not self == other

    def __call__(self, r):
        r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
        return r


class HTTPProxyAuth(HTTPBasicAuth):
    """Attaches HTTP Proxy Authentication to a given Request object."""

    def __call__(self, r):
        r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)
        return r


class HTTPDigestAuth(AuthBase):
    """Attaches HTTP Digest Authentication to the given Request object."""

    def __init__(self, username, password):
        self.username = username
        self.password = password
        # Keep state in per-thread local storage
        self._thread_local = threading.local()

    def init_per_thread_state(self):
        # Ensure state is initialized just once per-thread
        if not hasattr(self._thread_local, 'init'):
            self._thread_local.init = True
            self._thread_local.last_nonce = ''
            self._thread_local.nonce_count = 0
            self._thread_local.chal = {}
            self._thread_local.pos = None
            self._thread_local.num_401_calls = None

    def build_digest_header(self, method, url):
        """
        :rtype: str
        """

        realm = self._thread_local.chal['realm']
        nonce = self._thread_local.chal['nonce']
        qop = self._thread_local.chal.get('qop')
        algorithm = self._thread_local.chal.get('algorithm')
        opaque = self._thread_local.chal.get('opaque')
        hash_utf8 = None

        if algorithm is None:
            _algorithm = 'MD5'
        else:
            _algorithm = algorithm.upper()
        # lambdas assume digest modules are imported at the top level
        if _algorithm == 'MD5' or _algorithm == 'MD5-SESS':
            def md5_utf8(x):
                if isinstance(x, str):
                    x = x.encode('utf-8')
                return hashlib.md5(x).hexdigest()
            hash_utf8 = md5_utf8
        elif _algorithm == 'SHA':
            def sha_utf8(x):
                if isinstance(x, str):
                    x = x.encode('utf-8')
                return hashlib.sha1(x).hexdigest()
            hash_utf8 = sha_utf8

        KD = lambda s, d: hash_utf8("%s:%s" % (s, d))

        if hash_utf8 is None:
            return None

        # XXX not implemented yet
        entdig = None
        p_parsed = urlparse(url)
        #: path is request-uri defined in RFC 2616 which should not be empty
        path = p_parsed.path or "/"
        if p_parsed.query:
            path += '?' + p_parsed.query

        A1 = '%s:%s:%s' % (self.username, realm, self.password)
        A2 = '%s:%s' % (method, path)

        HA1 = hash_utf8(A1)
        HA2 = hash_utf8(A2)

        if nonce == self._thread_local.last_nonce:
            self._thread_local.nonce_count += 1
        else:
            self._thread_local.nonce_count = 1
        ncvalue = '%08x' % self._thread_local.nonce_count
        s = str(self._thread_local.nonce_count).encode('utf-8')
        s += nonce.encode('utf-8')
        s += time.ctime().encode('utf-8')
        s += os.urandom(8)

        cnonce = (hashlib.sha1(s).hexdigest()[:16])
        if _algorithm == 'MD5-SESS':
            HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce))

        if not qop:
            respdig = KD(HA1, "%s:%s" % (nonce, HA2))
        elif qop == 'auth' or 'auth' in qop.split(','):
            noncebit = "%s:%s:%s:%s:%s" % (
                nonce, ncvalue, cnonce, 'auth', HA2
            )
            respdig = KD(HA1, noncebit)
        else:
            # XXX handle auth-int.
            return None

        self._thread_local.last_nonce = nonce

        # XXX should the partial digests be encoded too?
        base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
               'response="%s"' % (self.username, realm, nonce, path, respdig)
        if opaque:
            base += ', opaque="%s"' % opaque
        if algorithm:
            base += ', algorithm="%s"' % algorithm
        if entdig:
            base += ', digest="%s"' % entdig
        if qop:
            base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce)

        return 'Digest %s' % (base)

    def handle_redirect(self, r, **kwargs):
        """Reset num_401_calls counter on redirects."""
        if r.is_redirect:
            self._thread_local.num_401_calls = 1

    def handle_401(self, r, **kwargs):
        """
        Takes the given response and tries digest-auth, if needed.

        :rtype: requests.Response
        """

        # If response is not 4xx, do not auth
        # See https://github.com/requests/requests/issues/3772
        if not 400 <= r.status_code < 500:
            self._thread_local.num_401_calls = 1
            return r

        if self._thread_local.pos is not None:
            # Rewind the file position indicator of the body to where
            # it was to resend the request.
            r.request.body.seek(self._thread_local.pos)
        s_auth = r.headers.get('www-authenticate', '')

        if 'digest' in s_auth.lower() and self._thread_local.num_401_calls < 2:

            self._thread_local.num_401_calls += 1
            pat = re.compile(r'digest ', flags=re.IGNORECASE)
            self._thread_local.chal = parse_dict_header(pat.sub('', s_auth, count=1))

            # Consume content and release the original connection
            # to allow our new request to reuse the same one.
            r.content
            r.close()
            prep = r.request.copy()
            extract_cookies_to_jar(prep._cookies, r.request, r.raw)
            prep.prepare_cookies(prep._cookies)

            prep.headers['Authorization'] = self.build_digest_header(
                prep.method, prep.url)
            _r = r.connection.send(prep, **kwargs)
            _r.history.append(r)
            _r.request = prep

            return _r

        self._thread_local.num_401_calls = 1
        return r

    def __call__(self, r):
        # Initialize per-thread state, if needed
        self.init_per_thread_state()
        # If we have a saved nonce, skip the 401
        if self._thread_local.last_nonce:
            r.headers['Authorization'] = self.build_digest_header(r.method, r.url)
        try:
            self._thread_local.pos = r.body.tell()
        except AttributeError:
            # In the case of HTTPDigestAuth being reused and the body of
            # the previous request was a file-like object, pos has the
            # file position of the previous body. Ensure it's set to
            # None.
            self._thread_local.pos = None
        r.register_hook('response', self.handle_401)
        r.register_hook('response', self.handle_redirect)
        self._thread_local.num_401_calls = 1

        return r

    def __eq__(self, other):
        return all([
            self.username == getattr(other, 'username', None),
            self.password == getattr(other, 'password', None)
        ])

    def __ne__(self, other):
        return not self == other

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
March 03 2024 20:23:47
root / root
0755
__init__.py
3.491 KB
April 21 2022 18:08:21
root / root
0644
__init__.pyc
3.766 KB
April 21 2022 18:08:34
root / root
0644
__init__.pyo
3.601 KB
April 21 2022 18:08:35
root / root
0644
__version__.py
0.426 KB
April 21 2022 18:08:21
root / root
0644
__version__.pyc
0.573 KB
April 21 2022 18:08:34
root / root
0644
__version__.pyo
0.573 KB
April 21 2022 18:08:34
root / root
0644
_internal_utils.py
1.07 KB
April 21 2022 18:08:21
root / root
0644
_internal_utils.pyc
1.499 KB
April 21 2022 18:08:34
root / root
0644
_internal_utils.pyo
1.448 KB
April 21 2022 18:08:35
root / root
0644
adapters.py
20.523 KB
April 21 2022 18:08:21
root / root
0644
adapters.pyc
18.534 KB
April 21 2022 18:08:34
root / root
0644
adapters.pyo
18.534 KB
April 21 2022 18:08:34
root / root
0644
api.py
6.091 KB
April 21 2022 18:08:21
root / root
0644
api.pyc
6.895 KB
April 21 2022 18:08:34
root / root
0644
api.pyo
6.895 KB
April 21 2022 18:08:34
root / root
0644
auth.py
9.5 KB
April 21 2022 18:08:21
root / root
0644
auth.pyc
9.691 KB
April 21 2022 18:08:34
root / root
0644
auth.pyo
9.691 KB
April 21 2022 18:08:34
root / root
0644
certs.py
0.454 KB
April 21 2022 18:08:21
root / root
0644
certs.pyc
0.604 KB
April 21 2022 18:08:34
root / root
0644
certs.pyo
0.604 KB
April 21 2022 18:08:34
root / root
0644
compat.py
1.588 KB
April 21 2022 18:08:21
root / root
0644
compat.pyc
1.802 KB
April 21 2022 18:08:34
root / root
0644
compat.pyo
1.802 KB
April 21 2022 18:08:34
root / root
0644
cookies.py
17.781 KB
April 21 2022 18:08:21
root / root
0644
cookies.pyc
21.879 KB
April 21 2022 18:08:34
root / root
0644
cookies.pyo
21.879 KB
April 21 2022 18:08:34
root / root
0644
exceptions.py
3.042 KB
April 21 2022 18:08:21
root / root
0644
exceptions.pyc
6.756 KB
April 21 2022 18:08:34
root / root
0644
exceptions.pyo
6.756 KB
April 21 2022 18:08:34
root / root
0644
help.py
3.581 KB
April 21 2022 18:08:21
root / root
0644
help.pyc
3.315 KB
April 21 2022 18:08:34
root / root
0644
help.pyo
3.315 KB
April 21 2022 18:08:34
root / root
0644
hooks.py
0.749 KB
April 21 2022 18:08:21
root / root
0644
hooks.pyc
1.206 KB
April 21 2022 18:08:34
root / root
0644
hooks.pyo
1.206 KB
April 21 2022 18:08:34
root / root
0644
models.py
33.253 KB
April 21 2022 18:08:21
root / root
0644
models.pyc
28.523 KB
April 21 2022 18:08:34
root / root
0644
models.pyo
28.523 KB
April 21 2022 18:08:34
root / root
0644
packages.py
0.679 KB
April 21 2022 18:08:21
root / root
0644
packages.pyc
0.564 KB
April 21 2022 18:08:34
root / root
0644
packages.pyo
0.564 KB
April 21 2022 18:08:34
root / root
0644
sessions.py
28.017 KB
April 21 2022 18:08:21
root / root
0644
sessions.pyc
21.848 KB
April 21 2022 18:08:34
root / root
0644
sessions.pyo
21.848 KB
April 21 2022 18:08:34
root / root
0644
status_codes.py
3.245 KB
April 21 2022 18:08:21
root / root
0644
status_codes.pyc
4.524 KB
April 21 2022 18:08:34
root / root
0644
status_codes.pyo
4.524 KB
April 21 2022 18:08:34
root / root
0644
structures.py
2.941 KB
April 21 2022 18:08:21
root / root
0644
structures.pyc
5.292 KB
April 21 2022 18:08:34
root / root
0644
structures.pyo
5.292 KB
April 21 2022 18:08:34
root / root
0644
utils.py
27.046 KB
April 21 2022 18:08:21
root / root
0644
utils.pyc
25.037 KB
April 21 2022 18:08:34
root / root
0644
utils.pyo
25.037 KB
April 21 2022 18:08:34
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF