├── .gitignore
├── requests
├── packages
│ ├── urllib3
│ │ ├── contrib
│ │ │ ├── __init__.py
│ │ │ └── ntlmpool.py
│ │ ├── packages
│ │ │ ├── __init__.py
│ │ │ ├── ssl_match_hostname
│ │ │ │ └── __init__.py
│ │ │ └── ordered_dict.py
│ │ ├── __init__.py
│ │ ├── exceptions.py
│ │ ├── _collections.py
│ │ ├── filepost.py
│ │ ├── request.py
│ │ ├── poolmanager.py
│ │ ├── response.py
│ │ └── util.py
│ ├── __init__.py
│ └── charade
│ │ ├── compat.py
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ ├── euctwprober.py
│ │ ├── euckrprober.py
│ │ ├── gb2312prober.py
│ │ ├── big5prober.py
│ │ ├── charsetprober.py
│ │ ├── mbcsgroupprober.py
│ │ ├── codingstatemachine.py
│ │ ├── utf8prober.py
│ │ ├── escprober.py
│ │ ├── sbcsgroupprober.py
│ │ ├── mbcharsetprober.py
│ │ ├── eucjpprober.py
│ │ ├── sjisprober.py
│ │ ├── charsetgroupprober.py
│ │ ├── sbcharsetprober.py
│ │ ├── latin1prober.py
│ │ ├── universaldetector.py
│ │ ├── escsm.py
│ │ ├── chardistribution.py
│ │ ├── langthaimodel.py
│ │ └── langhebrewmodel.py
├── certs.py
├── hooks.py
├── exceptions.py
├── __init__.py
├── structures.py
├── compat.py
├── status_codes.py
├── api.py
├── auth.py
└── adapters.py
├── Default.sublime-commands
├── Default.sublime-keymap
├── Hipster Ipsum.sublime-settings
├── Main.sublime-menu
├── README.mdown
└── hipsteripsum.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | .DS_STORE
--------------------------------------------------------------------------------
/requests/packages/urllib3/contrib/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/requests/packages/__init__.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | from . import urllib3
4 |
--------------------------------------------------------------------------------
/Default.sublime-commands:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "Hipster Ipsum: Occupy",
4 | "command": "hipster_ipsum"
5 | }
6 | ]
--------------------------------------------------------------------------------
/requests/packages/urllib3/packages/__init__.py:
--------------------------------------------------------------------------------
1 | from __future__ import absolute_import
2 |
3 | from . import ssl_match_hostname
4 |
5 |
--------------------------------------------------------------------------------
/Default.sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "keys": ["ctrl+alt+h"],
4 | "command": "hipster_ipsum"
5 | },
6 | {
7 | "keys": ["h", "i", "p", "s", "t", "u", "m", "tab"],
8 | "command": "hipster_ipsum"
9 | }
10 | ]
--------------------------------------------------------------------------------
/Hipster Ipsum.sublime-settings:
--------------------------------------------------------------------------------
1 | {
2 | // If the command is called without text selected,
3 | // how many paragraphs should it forage for?
4 | "paragraphs": 2,
5 |
6 | // Possible values are "hipster-centric" for single-origin
7 | // hipster text and "hipster-latin" for hipster text with
8 | // a Latinate mustache.
9 | "ipsum_type": "hipster-centric",
10 |
11 | // Set to true for text with
tattoos.
12 | "html": false
13 | }
--------------------------------------------------------------------------------
/requests/certs.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | """
5 | certs.py
6 | ~~~~~~~~
7 |
8 | This module returns the preferred default CA certificate bundle.
9 |
10 | If you are packaging Requests, e.g., for a Linux distribution or a managed
11 | environment, you can change the definition of where() to return a separately
12 | packaged CA bundle.
13 | """
14 |
15 | import os.path
16 |
17 |
18 | def where():
19 | """Return the preferred certificate bundle."""
20 | # vendored bundle inside Requests
21 | return os.path.join(os.path.dirname(__file__), 'cacert.pem')
22 |
23 | if __name__ == '__main__':
24 | print(where())
25 |
--------------------------------------------------------------------------------
/requests/hooks.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.hooks
5 | ~~~~~~~~~~~~~~
6 |
7 | This module provides the capabilities for the Requests hooks system.
8 |
9 | Available hooks:
10 |
11 | ``response``:
12 | The response generated from a Request.
13 |
14 | """
15 |
16 |
17 | HOOKS = ['response']
18 |
19 |
20 | def default_hooks():
21 | hooks = {}
22 | for event in HOOKS:
23 | hooks[event] = []
24 | return hooks
25 |
26 | # TODO: response is the only one
27 |
28 |
29 | def dispatch_hook(key, hooks, hook_data, **kwargs):
30 | """Dispatches a hook dictionary on a given piece of data."""
31 |
32 | hooks = hooks or dict()
33 |
34 | if key in hooks:
35 | hooks = hooks.get(key)
36 |
37 | if hasattr(hooks, '__call__'):
38 | hooks = [hooks]
39 |
40 | for hook in hooks:
41 | _hook_data = hook(hook_data, **kwargs)
42 | if _hook_data is not None:
43 | hook_data = _hook_data
44 |
45 | return hook_data
46 |
--------------------------------------------------------------------------------
/requests/packages/charade/compat.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # Contributor(s):
3 | # Ian Cordasco - port to Python
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 | # 02110-1301 USA
19 | ######################### END LICENSE BLOCK #########################
20 |
21 |
22 | def wrap_ord(a):
23 | if isinstance(a, str):
24 | return ord(a)
25 | elif isinstance(a, int):
26 | return a
27 |
--------------------------------------------------------------------------------
/requests/packages/charade/__init__.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # This library is free software; you can redistribute it and/or
3 | # modify it under the terms of the GNU Lesser General Public
4 | # License as published by the Free Software Foundation; either
5 | # version 2.1 of the License, or (at your option) any later version.
6 | #
7 | # This library is distributed in the hope that it will be useful,
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 | # Lesser General Public License for more details.
11 | #
12 | # You should have received a copy of the GNU Lesser General Public
13 | # License along with this library; if not, write to the Free Software
14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
15 | # 02110-1301 USA
16 | ######################### END LICENSE BLOCK #########################
17 |
18 | __version__ = "1.0.1"
19 |
20 |
21 | def detect(aBuf):
22 | from . import universaldetector
23 | u = universaldetector.UniversalDetector()
24 | u.reset()
25 | u.feed(aBuf)
26 | u.close()
27 | return u.result
28 |
--------------------------------------------------------------------------------
/requests/exceptions.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.exceptions
5 | ~~~~~~~~~~~~~~~~~~~
6 |
7 | This module contains the set of Requests' exceptions.
8 |
9 | """
10 |
11 |
12 | class RequestException(RuntimeError):
13 | """There was an ambiguous exception that occurred while handling your
14 | request."""
15 |
16 |
17 | class HTTPError(RequestException):
18 | """An HTTP error occurred."""
19 |
20 | def __init__(self, *args, **kwargs):
21 | """ Initializes HTTPError with optional `response` object. """
22 | self.response = kwargs.pop('response', None)
23 | super(HTTPError, self).__init__(*args, **kwargs)
24 |
25 |
26 | class ConnectionError(RequestException):
27 | """A Connection error occurred."""
28 |
29 |
30 | class SSLError(ConnectionError):
31 | """An SSL error occurred."""
32 |
33 |
34 | class Timeout(RequestException):
35 | """The request timed out."""
36 |
37 |
38 | class URLRequired(RequestException):
39 | """A valid URL is required to make a request."""
40 |
41 |
42 | class TooManyRedirects(RequestException):
43 | """Too many redirects."""
44 |
45 |
46 | class MissingSchema(RequestException, ValueError):
47 | """The URL schema (e.g. http or https) is missing."""
48 |
49 |
50 | class InvalidSchema(RequestException, ValueError):
51 | """See defaults.py for valid schemas."""
52 |
53 |
54 | class InvalidURL(RequestException, ValueError):
55 | """ The URL provided was somehow invalid. """
56 |
--------------------------------------------------------------------------------
/requests/packages/charade/constants.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | _debug = 0
30 |
31 | eDetecting = 0
32 | eFoundIt = 1
33 | eNotMe = 2
34 |
35 | eStart = 0
36 | eError = 1
37 | eItsMe = 2
38 |
39 | SHORTCUT_THRESHOLD = 0.95
40 |
--------------------------------------------------------------------------------
/Main.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "Preferences",
4 | "mnemonic": "n",
5 | "id": "preferences",
6 | "children":
7 | [
8 | {
9 | "caption": "Package Settings",
10 | "mnemonic": "P",
11 | "id": "package-settings",
12 | "children":
13 | [
14 | {
15 | "caption": "Hipster Ipsum",
16 | "children":
17 | [
18 | {
19 | "command": "open_file", "args":
20 | {
21 | "file": "${packages}/HipsterIpsum/README.mdown"
22 | },
23 | "caption": "README"
24 | },
25 | {
26 | "caption": "-"
27 | },
28 | {
29 | "command": "open_file", "args":
30 | {
31 | "file": "${packages}/HipsterIpsum/Hipster Ipsum.sublime-settings"
32 | },
33 | "caption": "Settings – Default"
34 | },
35 | {
36 | "command": "open_file", "args":
37 | {
38 | "file": "${packages}/User/HipsterIpsum.sublime-settings"
39 | },
40 | "caption": "Settings – User"
41 | }
42 | ]
43 | }
44 | ]
45 | }
46 | ]
47 | }
48 | ]
49 |
--------------------------------------------------------------------------------
/requests/packages/charade/euctwprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .mbcharsetprober import MultiByteCharSetProber
29 | from .codingstatemachine import CodingStateMachine
30 | from .chardistribution import EUCTWDistributionAnalysis
31 | from .mbcssm import EUCTWSMModel
32 |
33 | class EUCTWProber(MultiByteCharSetProber):
34 | def __init__(self):
35 | MultiByteCharSetProber.__init__(self)
36 | self._mCodingSM = CodingStateMachine(EUCTWSMModel)
37 | self._mDistributionAnalyzer = EUCTWDistributionAnalysis()
38 | self.reset()
39 |
40 | def get_charset_name(self):
41 | return "EUC-TW"
42 |
--------------------------------------------------------------------------------
/requests/packages/charade/euckrprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .mbcharsetprober import MultiByteCharSetProber
29 | from .codingstatemachine import CodingStateMachine
30 | from .chardistribution import EUCKRDistributionAnalysis
31 | from .mbcssm import EUCKRSMModel
32 |
33 |
34 | class EUCKRProber(MultiByteCharSetProber):
35 | def __init__(self):
36 | MultiByteCharSetProber.__init__(self)
37 | self._mCodingSM = CodingStateMachine(EUCKRSMModel)
38 | self._mDistributionAnalyzer = EUCKRDistributionAnalysis()
39 | self.reset()
40 |
41 | def get_charset_name(self):
42 | return "EUC-KR"
43 |
--------------------------------------------------------------------------------
/requests/packages/charade/gb2312prober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .mbcharsetprober import MultiByteCharSetProber
29 | from .codingstatemachine import CodingStateMachine
30 | from .chardistribution import GB2312DistributionAnalysis
31 | from .mbcssm import GB2312SMModel
32 |
33 | class GB2312Prober(MultiByteCharSetProber):
34 | def __init__(self):
35 | MultiByteCharSetProber.__init__(self)
36 | self._mCodingSM = CodingStateMachine(GB2312SMModel)
37 | self._mDistributionAnalyzer = GB2312DistributionAnalysis()
38 | self.reset()
39 |
40 | def get_charset_name(self):
41 | return "GB2312"
42 |
--------------------------------------------------------------------------------
/requests/packages/charade/big5prober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Communicator client code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .mbcharsetprober import MultiByteCharSetProber
29 | from .codingstatemachine import CodingStateMachine
30 | from .chardistribution import Big5DistributionAnalysis
31 | from .mbcssm import Big5SMModel
32 |
33 |
34 | class Big5Prober(MultiByteCharSetProber):
35 | def __init__(self):
36 | MultiByteCharSetProber.__init__(self)
37 | self._mCodingSM = CodingStateMachine(Big5SMModel)
38 | self._mDistributionAnalyzer = Big5DistributionAnalysis()
39 | self.reset()
40 |
41 | def get_charset_name(self):
42 | return "Big5"
43 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/__init__.py:
--------------------------------------------------------------------------------
1 | # urllib3/__init__.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | """
8 | urllib3 - Thread-safe connection pooling and re-using.
9 | """
10 |
11 | __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
12 | __license__ = 'MIT'
13 | __version__ = 'dev'
14 |
15 |
16 | from .connectionpool import (
17 | HTTPConnectionPool,
18 | HTTPSConnectionPool,
19 | connection_from_url
20 | )
21 |
22 | from . import exceptions
23 | from .filepost import encode_multipart_formdata
24 | from .poolmanager import PoolManager, ProxyManager, proxy_from_url
25 | from .response import HTTPResponse
26 | from .util import make_headers, get_host
27 |
28 |
29 | # Set default logging handler to avoid "No handler found" warnings.
30 | import logging
31 | try: # Python 2.7+
32 | from logging import NullHandler
33 | except ImportError:
34 | class NullHandler(logging.Handler):
35 | def emit(self, record):
36 | pass
37 |
38 | logging.getLogger(__name__).addHandler(NullHandler())
39 |
40 | def add_stderr_logger(level=logging.DEBUG):
41 | """
42 | Helper for quickly adding a StreamHandler to the logger. Useful for
43 | debugging.
44 |
45 | Returns the handler after adding it.
46 | """
47 | # This method needs to be in this __init__.py to get the __name__ correct
48 | # even if urllib3 is vendored within another package.
49 | logger = logging.getLogger(__name__)
50 | handler = logging.StreamHandler()
51 | handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
52 | logger.addHandler(handler)
53 | logger.setLevel(level)
54 | logger.debug('Added an stderr logging handler to logger: %s' % __name__)
55 | return handler
56 |
57 | # ... Clean up.
58 | del NullHandler
59 |
--------------------------------------------------------------------------------
/requests/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # __
4 | # /__) _ _ _ _ _/ _
5 | # / ( (- (/ (/ (- _) / _)
6 | # /
7 |
8 | """
9 | requests HTTP library
10 | ~~~~~~~~~~~~~~~~~~~~~
11 |
12 | Requests is an HTTP library, written in Python, for human beings. Basic GET
13 | usage:
14 |
15 | >>> import requests
16 | >>> r = requests.get('http://python.org')
17 | >>> r.status_code
18 | 200
19 | >>> 'Python is a programming language' in r.content
20 | True
21 |
22 | ... or POST:
23 |
24 | >>> payload = dict(key1='value1', key2='value2')
25 | >>> r = requests.post("http://httpbin.org/post", data=payload)
26 | >>> print r.text
27 | {
28 | ...
29 | "form": {
30 | "key2": "value2",
31 | "key1": "value1"
32 | },
33 | ...
34 | }
35 |
36 | The other HTTP methods are supported - see `requests.api`. Full documentation
37 | is at .
38 |
39 | :copyright: (c) 2013 by Kenneth Reitz.
40 | :license: Apache 2.0, see LICENSE for more details.
41 |
42 | """
43 |
44 | __title__ = 'requests'
45 | __version__ = '1.1.0'
46 | __build__ = 0x010100
47 | __author__ = 'Kenneth Reitz'
48 | __license__ = 'Apache 2.0'
49 | __copyright__ = 'Copyright 2013 Kenneth Reitz'
50 |
51 |
52 | from . import utils
53 | from .models import Request, Response, PreparedRequest
54 | from .api import request, get, head, post, patch, put, delete, options
55 | from .sessions import session, Session
56 | from .status_codes import codes
57 | from .exceptions import (
58 | RequestException, Timeout, URLRequired,
59 | TooManyRedirects, HTTPError, ConnectionError
60 | )
61 |
62 | # Set default logging handler to avoid "No handler found" warnings.
63 | import logging
64 | try: # Python 2.7+
65 | from logging import NullHandler
66 | except ImportError:
67 | class NullHandler(logging.Handler):
68 | def emit(self, record):
69 | pass
70 |
71 | logging.getLogger(__name__).addHandler(NullHandler())
72 |
--------------------------------------------------------------------------------
/requests/packages/charade/charsetprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | from . import constants
30 | import re
31 |
32 |
33 | class CharSetProber:
34 | def __init__(self):
35 | pass
36 |
37 | def reset(self):
38 | self._mState = constants.eDetecting
39 |
40 | def get_charset_name(self):
41 | return None
42 |
43 | def feed(self, aBuf):
44 | pass
45 |
46 | def get_state(self):
47 | return self._mState
48 |
49 | def get_confidence(self):
50 | return 0.0
51 |
52 | def filter_high_bit_only(self, aBuf):
53 | aBuf = re.sub(b'([\x00-\x7F])+', b' ', aBuf)
54 | return aBuf
55 |
56 | def filter_without_english_letters(self, aBuf):
57 | aBuf = re.sub(b'([A-Za-z])+', b' ', aBuf)
58 | return aBuf
59 |
60 | def filter_with_english_letters(self, aBuf):
61 | # TODO
62 | return aBuf
63 |
--------------------------------------------------------------------------------
/requests/packages/charade/mbcsgroupprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | # Proofpoint, Inc.
13 | #
14 | # This library is free software; you can redistribute it and/or
15 | # modify it under the terms of the GNU Lesser General Public
16 | # License as published by the Free Software Foundation; either
17 | # version 2.1 of the License, or (at your option) any later version.
18 | #
19 | # This library is distributed in the hope that it will be useful,
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 | # Lesser General Public License for more details.
23 | #
24 | # You should have received a copy of the GNU Lesser General Public
25 | # License along with this library; if not, write to the Free Software
26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 | # 02110-1301 USA
28 | ######################### END LICENSE BLOCK #########################
29 |
30 | from .charsetgroupprober import CharSetGroupProber
31 | from .utf8prober import UTF8Prober
32 | from .sjisprober import SJISProber
33 | from .eucjpprober import EUCJPProber
34 | from .gb2312prober import GB2312Prober
35 | from .euckrprober import EUCKRProber
36 | from .big5prober import Big5Prober
37 | from .euctwprober import EUCTWProber
38 |
39 |
40 | class MBCSGroupProber(CharSetGroupProber):
41 | def __init__(self):
42 | CharSetGroupProber.__init__(self)
43 | self._mProbers = [
44 | UTF8Prober(),
45 | SJISProber(),
46 | EUCJPProber(),
47 | GB2312Prober(),
48 | EUCKRProber(),
49 | Big5Prober(),
50 | EUCTWProber()
51 | ]
52 | self.reset()
53 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py:
--------------------------------------------------------------------------------
1 | """The match_hostname() function from Python 3.2, essential when using SSL."""
2 |
3 | import re
4 |
5 | __version__ = '3.2.2'
6 |
7 | class CertificateError(ValueError):
8 | pass
9 |
10 | def _dnsname_to_pat(dn):
11 | pats = []
12 | for frag in dn.split(r'.'):
13 | if frag == '*':
14 | # When '*' is a fragment by itself, it matches a non-empty dotless
15 | # fragment.
16 | pats.append('[^.]+')
17 | else:
18 | # Otherwise, '*' matches any dotless fragment.
19 | frag = re.escape(frag)
20 | pats.append(frag.replace(r'\*', '[^.]*'))
21 | return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
22 |
23 | def match_hostname(cert, hostname):
24 | """Verify that *cert* (in decoded format as returned by
25 | SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
26 | are mostly followed, but IP addresses are not accepted for *hostname*.
27 |
28 | CertificateError is raised on failure. On success, the function
29 | returns nothing.
30 | """
31 | if not cert:
32 | raise ValueError("empty or no certificate")
33 | dnsnames = []
34 | san = cert.get('subjectAltName', ())
35 | for key, value in san:
36 | if key == 'DNS':
37 | if _dnsname_to_pat(value).match(hostname):
38 | return
39 | dnsnames.append(value)
40 | if not dnsnames:
41 | # The subject is only checked when there is no dNSName entry
42 | # in subjectAltName
43 | for sub in cert.get('subject', ()):
44 | for key, value in sub:
45 | # XXX according to RFC 2818, the most specific Common Name
46 | # must be used.
47 | if key == 'commonName':
48 | if _dnsname_to_pat(value).match(hostname):
49 | return
50 | dnsnames.append(value)
51 | if len(dnsnames) > 1:
52 | raise CertificateError("hostname %r "
53 | "doesn't match either of %s"
54 | % (hostname, ', '.join(map(repr, dnsnames))))
55 | elif len(dnsnames) == 1:
56 | raise CertificateError("hostname %r "
57 | "doesn't match %r"
58 | % (hostname, dnsnames[0]))
59 | else:
60 | raise CertificateError("no appropriate commonName or "
61 | "subjectAltName fields were found")
62 |
--------------------------------------------------------------------------------
/requests/packages/charade/codingstatemachine.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .constants import eStart
29 | from .compat import wrap_ord
30 |
31 |
32 | class CodingStateMachine:
33 | def __init__(self, sm):
34 | self._mModel = sm
35 | self._mCurrentBytePos = 0
36 | self._mCurrentCharLen = 0
37 | self.reset()
38 |
39 | def reset(self):
40 | self._mCurrentState = eStart
41 |
42 | def next_state(self, c):
43 | # for each byte we get its class
44 | # if it is first byte, we also get byte length
45 | # PY3K: aBuf is a byte stream, so c is an int, not a byte
46 | byteCls = self._mModel['classTable'][wrap_ord(c)]
47 | if self._mCurrentState == eStart:
48 | self._mCurrentBytePos = 0
49 | self._mCurrentCharLen = self._mModel['charLenTable'][byteCls]
50 | # from byte's class and stateTable, we get its next state
51 | curr_state = (self._mCurrentState * self._mModel['classFactor']
52 | + byteCls)
53 | self._mCurrentState = self._mModel['stateTable'][curr_state]
54 | self._mCurrentBytePos += 1
55 | return self._mCurrentState
56 |
57 | def get_current_charlen(self):
58 | return self._mCurrentCharLen
59 |
60 | def get_coding_state_machine(self):
61 | return self._mModel['name']
62 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/exceptions.py:
--------------------------------------------------------------------------------
1 | # urllib3/exceptions.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 |
8 | ## Base Exceptions
9 |
10 | class HTTPError(Exception):
11 | "Base exception used by this module."
12 | pass
13 |
14 |
15 | class PoolError(HTTPError):
16 | "Base exception for errors caused within a pool."
17 | def __init__(self, pool, message):
18 | self.pool = pool
19 | HTTPError.__init__(self, "%s: %s" % (pool, message))
20 |
21 | def __reduce__(self):
22 | # For pickling purposes.
23 | return self.__class__, (None, self.url)
24 |
25 |
26 | class SSLError(HTTPError):
27 | "Raised when SSL certificate fails in an HTTPS connection."
28 | pass
29 |
30 |
31 | class DecodeError(HTTPError):
32 | "Raised when automatic decoding based on Content-Type fails."
33 | pass
34 |
35 |
36 | ## Leaf Exceptions
37 |
38 | class MaxRetryError(PoolError):
39 | "Raised when the maximum number of retries is exceeded."
40 |
41 | def __init__(self, pool, url, reason=None):
42 | self.reason = reason
43 |
44 | message = "Max retries exceeded with url: %s" % url
45 | if reason:
46 | message += " (Caused by %s: %s)" % (type(reason), reason)
47 | else:
48 | message += " (Caused by redirect)"
49 |
50 | PoolError.__init__(self, pool, message)
51 | self.url = url
52 |
53 |
54 | class HostChangedError(PoolError):
55 | "Raised when an existing pool gets a request for a foreign host."
56 |
57 | def __init__(self, pool, url, retries=3):
58 | message = "Tried to open a foreign host with url: %s" % url
59 | PoolError.__init__(self, pool, message)
60 |
61 | self.url = url
62 | self.retries = retries
63 |
64 |
65 | class TimeoutError(PoolError):
66 | "Raised when a socket timeout occurs."
67 | pass
68 |
69 |
70 | class EmptyPoolError(PoolError):
71 | "Raised when a pool runs out of connections and no more are allowed."
72 | pass
73 |
74 |
75 | class ClosedPoolError(PoolError):
76 | "Raised when a request enters a pool after the pool has been closed."
77 | pass
78 |
79 |
80 | class LocationParseError(ValueError, HTTPError):
81 | "Raised when get_host or similar fails to parse the URL input."
82 |
83 | def __init__(self, location):
84 | message = "Failed to parse: %s" % location
85 | HTTPError.__init__(self, message)
86 |
87 | self.location = location
88 |
--------------------------------------------------------------------------------
/requests/structures.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.structures
5 | ~~~~~~~~~~~~~~~~~~~
6 |
7 | Data structures that power Requests.
8 |
9 | """
10 |
11 | import os
12 | from itertools import islice
13 |
14 |
15 | class IteratorProxy(object):
16 | """docstring for IteratorProxy"""
17 | def __init__(self, i):
18 | self.i = i
19 | # self.i = chain.from_iterable(i)
20 |
21 | def __iter__(self):
22 | return self.i
23 |
24 | def __len__(self):
25 | if hasattr(self.i, '__len__'):
26 | return len(self.i)
27 | if hasattr(self.i, 'len'):
28 | return self.i.len
29 | if hasattr(self.i, 'fileno'):
30 | return os.fstat(self.i.fileno()).st_size
31 |
32 | def read(self, n):
33 | return "".join(islice(self.i, None, n))
34 |
35 |
36 | class CaseInsensitiveDict(dict):
37 | """Case-insensitive Dictionary
38 |
39 | For example, ``headers['content-encoding']`` will return the
40 | value of a ``'Content-Encoding'`` response header."""
41 |
42 | @property
43 | def lower_keys(self):
44 | if not hasattr(self, '_lower_keys') or not self._lower_keys:
45 | self._lower_keys = dict((k.lower(), k) for k in list(self.keys()))
46 | return self._lower_keys
47 |
48 | def _clear_lower_keys(self):
49 | if hasattr(self, '_lower_keys'):
50 | self._lower_keys.clear()
51 |
52 | def __setitem__(self, key, value):
53 | dict.__setitem__(self, key, value)
54 | self._clear_lower_keys()
55 |
56 | def __delitem__(self, key):
57 | dict.__delitem__(self, self.lower_keys.get(key.lower(), key))
58 | self._lower_keys.clear()
59 |
60 | def __contains__(self, key):
61 | return key.lower() in self.lower_keys
62 |
63 | def __getitem__(self, key):
64 | # We allow fall-through here, so values default to None
65 | if key in self:
66 | return dict.__getitem__(self, self.lower_keys[key.lower()])
67 |
68 | def get(self, key, default=None):
69 | if key in self:
70 | return self[key]
71 | else:
72 | return default
73 |
74 |
75 | class LookupDict(dict):
76 | """Dictionary lookup object."""
77 |
78 | def __init__(self, name=None):
79 | self.name = name
80 | super(LookupDict, self).__init__()
81 |
82 | def __repr__(self):
83 | return '' % (self.name)
84 |
85 | def __getitem__(self, key):
86 | # We allow fall-through here, so values default to None
87 |
88 | return self.__dict__.get(key, None)
89 |
90 | def get(self, key, default=None):
91 | return self.__dict__.get(key, default)
92 |
--------------------------------------------------------------------------------
/requests/compat.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | pythoncompat
5 | """
6 |
7 | from .packages import charade as chardet
8 |
9 | import sys
10 |
11 | # -------
12 | # Pythons
13 | # -------
14 |
15 | # Syntax sugar.
16 | _ver = sys.version_info
17 |
18 | #: Python 2.x?
19 | is_py2 = (_ver[0] == 2)
20 |
21 | #: Python 3.x?
22 | is_py3 = (_ver[0] == 3)
23 |
24 | #: Python 3.0.x
25 | is_py30 = (is_py3 and _ver[1] == 0)
26 |
27 | #: Python 3.1.x
28 | is_py31 = (is_py3 and _ver[1] == 1)
29 |
30 | #: Python 3.2.x
31 | is_py32 = (is_py3 and _ver[1] == 2)
32 |
33 | #: Python 3.3.x
34 | is_py33 = (is_py3 and _ver[1] == 3)
35 |
36 | #: Python 3.4.x
37 | is_py34 = (is_py3 and _ver[1] == 4)
38 |
39 | #: Python 2.7.x
40 | is_py27 = (is_py2 and _ver[1] == 7)
41 |
42 | #: Python 2.6.x
43 | is_py26 = (is_py2 and _ver[1] == 6)
44 |
45 | #: Python 2.5.x
46 | is_py25 = (is_py2 and _ver[1] == 5)
47 |
48 | #: Python 2.4.x
49 | is_py24 = (is_py2 and _ver[1] == 4) # I'm assuming this is not by choice.
50 |
51 |
52 | # ---------
53 | # Platforms
54 | # ---------
55 |
56 |
57 | # Syntax sugar.
58 | _ver = sys.version.lower()
59 |
60 | is_pypy = ('pypy' in _ver)
61 | is_jython = ('jython' in _ver)
62 | is_ironpython = ('iron' in _ver)
63 |
64 | # Assume CPython, if nothing else.
65 | is_cpython = not any((is_pypy, is_jython, is_ironpython))
66 |
67 | # Windows-based system.
68 | is_windows = 'win32' in str(sys.platform).lower()
69 |
70 | # Standard Linux 2+ system.
71 | is_linux = ('linux' in str(sys.platform).lower())
72 | is_osx = ('darwin' in str(sys.platform).lower())
73 | is_hpux = ('hpux' in str(sys.platform).lower()) # Complete guess.
74 | is_solaris = ('solar==' in str(sys.platform).lower()) # Complete guess.
75 |
76 | try:
77 | import simplejson as json
78 | except ImportError:
79 | import json
80 |
81 | # ---------
82 | # Specifics
83 | # ---------
84 |
85 | if is_py2:
86 | from urllib import quote, unquote, quote_plus, unquote_plus, urlencode
87 | from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
88 | from urllib2 import parse_http_list
89 | import cookielib
90 | from Cookie import Morsel
91 | from StringIO import StringIO
92 | from .packages.urllib3.packages.ordered_dict import OrderedDict
93 |
94 | builtin_str = str
95 | bytes = str
96 | str = unicode
97 | basestring = basestring
98 | numeric_types = (int, long, float)
99 |
100 |
101 | elif is_py3:
102 | from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
103 | from urllib.request import parse_http_list
104 | from http import cookiejar as cookielib
105 | from http.cookies import Morsel
106 | from io import StringIO
107 | from collections import OrderedDict
108 |
109 | builtin_str = str
110 | str = str
111 | bytes = bytes
112 | basestring = (str, bytes)
113 | numeric_types = (int, float)
114 |
--------------------------------------------------------------------------------
/requests/packages/charade/utf8prober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from . import constants
29 | from .charsetprober import CharSetProber
30 | from .codingstatemachine import CodingStateMachine
31 | from .mbcssm import UTF8SMModel
32 |
33 | ONE_CHAR_PROB = 0.5
34 |
35 |
36 | class UTF8Prober(CharSetProber):
37 | def __init__(self):
38 | CharSetProber.__init__(self)
39 | self._mCodingSM = CodingStateMachine(UTF8SMModel)
40 | self.reset()
41 |
42 | def reset(self):
43 | CharSetProber.reset(self)
44 | self._mCodingSM.reset()
45 | self._mNumOfMBChar = 0
46 |
47 | def get_charset_name(self):
48 | return "utf-8"
49 |
50 | def feed(self, aBuf):
51 | for c in aBuf:
52 | codingState = self._mCodingSM.next_state(c)
53 | if codingState == constants.eError:
54 | self._mState = constants.eNotMe
55 | break
56 | elif codingState == constants.eItsMe:
57 | self._mState = constants.eFoundIt
58 | break
59 | elif codingState == constants.eStart:
60 | if self._mCodingSM.get_current_charlen() >= 2:
61 | self._mNumOfMBChar += 1
62 |
63 | if self.get_state() == constants.eDetecting:
64 | if self.get_confidence() > constants.SHORTCUT_THRESHOLD:
65 | self._mState = constants.eFoundIt
66 |
67 | return self.get_state()
68 |
69 | def get_confidence(self):
70 | unlike = 0.99
71 | if self._mNumOfMBChar < 6:
72 | for i in range(0, self._mNumOfMBChar):
73 | unlike = unlike * ONE_CHAR_PROB
74 | return 1.0 - unlike
75 | else:
76 | return unlike
77 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/_collections.py:
--------------------------------------------------------------------------------
1 | # urllib3/_collections.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | from collections import MutableMapping
8 | from threading import Lock
9 |
10 | try: # Python 2.7+
11 | from collections import OrderedDict
12 | except ImportError:
13 | from .packages.ordered_dict import OrderedDict
14 |
15 |
16 | __all__ = ['RecentlyUsedContainer']
17 |
18 |
19 | _Null = object()
20 |
21 |
22 | class RecentlyUsedContainer(MutableMapping):
23 | """
24 | Provides a thread-safe dict-like container which maintains up to
25 | ``maxsize`` keys while throwing away the least-recently-used keys beyond
26 | ``maxsize``.
27 |
28 | :param maxsize:
29 | Maximum number of recent elements to retain.
30 |
31 | :param dispose_func:
32 | Every time an item is evicted from the container,
33 | ``dispose_func(value)`` is called. Callback which will get called
34 | """
35 |
36 | ContainerCls = OrderedDict
37 |
38 | def __init__(self, maxsize=10, dispose_func=None):
39 | self._maxsize = maxsize
40 | self.dispose_func = dispose_func
41 |
42 | self._container = self.ContainerCls()
43 | self._lock = Lock()
44 |
45 | def __getitem__(self, key):
46 | # Re-insert the item, moving it to the end of the eviction line.
47 | with self._lock:
48 | item = self._container.pop(key)
49 | self._container[key] = item
50 | return item
51 |
52 | def __setitem__(self, key, value):
53 | evicted_value = _Null
54 | with self._lock:
55 | # Possibly evict the existing value of 'key'
56 | evicted_value = self._container.get(key, _Null)
57 | self._container[key] = value
58 |
59 | # If we didn't evict an existing value, we might have to evict the
60 | # least recently used item from the beginning of the container.
61 | if len(self._container) > self._maxsize:
62 | _key, evicted_value = self._container.popitem(last=False)
63 |
64 | if self.dispose_func and evicted_value is not _Null:
65 | self.dispose_func(evicted_value)
66 |
67 | def __delitem__(self, key):
68 | with self._lock:
69 | value = self._container.pop(key)
70 |
71 | if self.dispose_func:
72 | self.dispose_func(value)
73 |
74 | def __len__(self):
75 | with self._lock:
76 | return len(self._container)
77 |
78 | def __iter__(self):
79 | raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.')
80 |
81 | def clear(self):
82 | with self._lock:
83 | # Copy pointers to all values, then wipe the mapping
84 | # under Python 2, this copies the list of values twice :-|
85 | values = list(self._container.values())
86 | self._container.clear()
87 |
88 | if self.dispose_func:
89 | for value in values:
90 | self.dispose_func(value)
91 |
92 | def keys(self):
93 | with self._lock:
94 | return self._container.keys()
95 |
--------------------------------------------------------------------------------
/requests/status_codes.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from .structures import LookupDict
4 |
5 | _codes = {
6 |
7 | # Informational.
8 | 100: ('continue',),
9 | 101: ('switching_protocols',),
10 | 102: ('processing',),
11 | 103: ('checkpoint',),
12 | 122: ('uri_too_long', 'request_uri_too_long'),
13 | 200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'),
14 | 201: ('created',),
15 | 202: ('accepted',),
16 | 203: ('non_authoritative_info', 'non_authoritative_information'),
17 | 204: ('no_content',),
18 | 205: ('reset_content', 'reset'),
19 | 206: ('partial_content', 'partial'),
20 | 207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'),
21 | 208: ('im_used',),
22 |
23 | # Redirection.
24 | 300: ('multiple_choices',),
25 | 301: ('moved_permanently', 'moved', '\\o-'),
26 | 302: ('found',),
27 | 303: ('see_other', 'other'),
28 | 304: ('not_modified',),
29 | 305: ('use_proxy',),
30 | 306: ('switch_proxy',),
31 | 307: ('temporary_redirect', 'temporary_moved', 'temporary'),
32 | 308: ('resume_incomplete', 'resume'),
33 |
34 | # Client Error.
35 | 400: ('bad_request', 'bad'),
36 | 401: ('unauthorized',),
37 | 402: ('payment_required', 'payment'),
38 | 403: ('forbidden',),
39 | 404: ('not_found', '-o-'),
40 | 405: ('method_not_allowed', 'not_allowed'),
41 | 406: ('not_acceptable',),
42 | 407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'),
43 | 408: ('request_timeout', 'timeout'),
44 | 409: ('conflict',),
45 | 410: ('gone',),
46 | 411: ('length_required',),
47 | 412: ('precondition_failed', 'precondition'),
48 | 413: ('request_entity_too_large',),
49 | 414: ('request_uri_too_large',),
50 | 415: ('unsupported_media_type', 'unsupported_media', 'media_type'),
51 | 416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'),
52 | 417: ('expectation_failed',),
53 | 418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'),
54 | 422: ('unprocessable_entity', 'unprocessable'),
55 | 423: ('locked',),
56 | 424: ('failed_dependency', 'dependency'),
57 | 425: ('unordered_collection', 'unordered'),
58 | 426: ('upgrade_required', 'upgrade'),
59 | 428: ('precondition_required', 'precondition'),
60 | 429: ('too_many_requests', 'too_many'),
61 | 431: ('header_fields_too_large', 'fields_too_large'),
62 | 444: ('no_response', 'none'),
63 | 449: ('retry_with', 'retry'),
64 | 450: ('blocked_by_windows_parental_controls', 'parental_controls'),
65 | 499: ('client_closed_request',),
66 |
67 | # Server Error.
68 | 500: ('internal_server_error', 'server_error', '/o\\', '✗'),
69 | 501: ('not_implemented',),
70 | 502: ('bad_gateway',),
71 | 503: ('service_unavailable', 'unavailable'),
72 | 504: ('gateway_timeout',),
73 | 505: ('http_version_not_supported', 'http_version'),
74 | 506: ('variant_also_negotiates',),
75 | 507: ('insufficient_storage',),
76 | 509: ('bandwidth_limit_exceeded', 'bandwidth'),
77 | 510: ('not_extended',),
78 | }
79 |
80 | codes = LookupDict(name='status_codes')
81 |
82 | for (code, titles) in list(_codes.items()):
83 | for title in titles:
84 | setattr(codes, title, code)
85 | if not title.startswith('\\'):
86 | setattr(codes, title.upper(), code)
87 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/filepost.py:
--------------------------------------------------------------------------------
1 | # urllib3/filepost.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | import codecs
8 | import mimetypes
9 |
10 | from uuid import uuid4
11 | from io import BytesIO
12 |
13 | from .packages import six
14 | from .packages.six import b
15 |
16 | writer = codecs.lookup('utf-8')[3]
17 |
18 |
19 | def choose_boundary():
20 | """
21 | Our embarassingly-simple replacement for mimetools.choose_boundary.
22 | """
23 | return uuid4().hex
24 |
25 |
26 | def get_content_type(filename):
27 | return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
28 |
29 |
30 | def iter_fields(fields):
31 | """
32 | Iterate over fields.
33 |
34 | Supports list of (k, v) tuples and dicts.
35 | """
36 | if isinstance(fields, dict):
37 | return ((k, v) for k, v in six.iteritems(fields))
38 |
39 | return ((k, v) for k, v in fields)
40 |
41 |
42 | def encode_multipart_formdata(fields, boundary=None):
43 | """
44 | Encode a dictionary of ``fields`` using the multipart/form-data MIME format.
45 |
46 | :param fields:
47 | Dictionary of fields or list of (key, value) or (key, value, MIME type)
48 | field tuples. The key is treated as the field name, and the value as
49 | the body of the form-data bytes. If the value is a tuple of two
50 | elements, then the first element is treated as the filename of the
51 | form-data section and a suitable MIME type is guessed based on the
52 | filename. If the value is a tuple of three elements, then the third
53 | element is treated as an explicit MIME type of the form-data section.
54 |
55 | Field names and filenames must be unicode.
56 |
57 | :param boundary:
58 | If not specified, then a random boundary will be generated using
59 | :func:`mimetools.choose_boundary`.
60 | """
61 | body = BytesIO()
62 | if boundary is None:
63 | boundary = choose_boundary()
64 |
65 | for fieldname, value in iter_fields(fields):
66 | body.write(b('--%s\r\n' % (boundary)))
67 |
68 | if isinstance(value, tuple):
69 | if len(value) == 3:
70 | filename, data, content_type = value
71 | else:
72 | filename, data = value
73 | content_type = get_content_type(filename)
74 | writer(body).write('Content-Disposition: form-data; name="%s"; '
75 | 'filename="%s"\r\n' % (fieldname, filename))
76 | body.write(b('Content-Type: %s\r\n\r\n' %
77 | (content_type,)))
78 | else:
79 | data = value
80 | writer(body).write('Content-Disposition: form-data; name="%s"\r\n'
81 | % (fieldname))
82 | body.write(b'\r\n')
83 |
84 | if isinstance(data, int):
85 | data = str(data) # Backwards compatibility
86 |
87 | if isinstance(data, six.text_type):
88 | writer(body).write(data)
89 | else:
90 | body.write(data)
91 |
92 | body.write(b'\r\n')
93 |
94 | body.write(b('--%s--\r\n' % (boundary)))
95 |
96 | content_type = b('multipart/form-data; boundary=%s' % boundary)
97 |
98 | return body.getvalue(), content_type
99 |
--------------------------------------------------------------------------------
/requests/packages/charade/escprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from . import constants
29 | from .escsm import (HZSMModel, ISO2022CNSMModel, ISO2022JPSMModel,
30 | ISO2022KRSMModel)
31 | from .charsetprober import CharSetProber
32 | from .codingstatemachine import CodingStateMachine
33 | from .compat import wrap_ord
34 |
35 |
36 | class EscCharSetProber(CharSetProber):
37 | def __init__(self):
38 | CharSetProber.__init__(self)
39 | self._mCodingSM = [
40 | CodingStateMachine(HZSMModel),
41 | CodingStateMachine(ISO2022CNSMModel),
42 | CodingStateMachine(ISO2022JPSMModel),
43 | CodingStateMachine(ISO2022KRSMModel)
44 | ]
45 | self.reset()
46 |
47 | def reset(self):
48 | CharSetProber.reset(self)
49 | for codingSM in self._mCodingSM:
50 | if not codingSM:
51 | continue
52 | codingSM.active = True
53 | codingSM.reset()
54 | self._mActiveSM = len(self._mCodingSM)
55 | self._mDetectedCharset = None
56 |
57 | def get_charset_name(self):
58 | return self._mDetectedCharset
59 |
60 | def get_confidence(self):
61 | if self._mDetectedCharset:
62 | return 0.99
63 | else:
64 | return 0.00
65 |
66 | def feed(self, aBuf):
67 | for c in aBuf:
68 | # PY3K: aBuf is a byte array, so c is an int, not a byte
69 | for codingSM in self._mCodingSM:
70 | if not codingSM:
71 | continue
72 | if not codingSM.active:
73 | continue
74 | codingState = codingSM.next_state(wrap_ord(c))
75 | if codingState == constants.eError:
76 | codingSM.active = False
77 | self._mActiveSM -= 1
78 | if self._mActiveSM <= 0:
79 | self._mState = constants.eNotMe
80 | return self.get_state()
81 | elif codingState == constants.eItsMe:
82 | self._mState = constants.eFoundIt
83 | self._mDetectedCharset = codingSM.get_coding_state_machine() # nopep8
84 | return self.get_state()
85 |
86 | return self.get_state()
87 |
--------------------------------------------------------------------------------
/requests/packages/charade/sbcsgroupprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | from .charsetgroupprober import CharSetGroupProber
30 | from .sbcharsetprober import SingleByteCharSetProber
31 | from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel,
32 | Latin5CyrillicModel, MacCyrillicModel,
33 | Ibm866Model, Ibm855Model)
34 | from .langgreekmodel import Latin7GreekModel, Win1253GreekModel
35 | from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel
36 | from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel
37 | from .langthaimodel import TIS620ThaiModel
38 | from .langhebrewmodel import Win1255HebrewModel
39 | from .hebrewprober import HebrewProber
40 |
41 |
42 | class SBCSGroupProber(CharSetGroupProber):
43 | def __init__(self):
44 | CharSetGroupProber.__init__(self)
45 | self._mProbers = [
46 | SingleByteCharSetProber(Win1251CyrillicModel),
47 | SingleByteCharSetProber(Koi8rModel),
48 | SingleByteCharSetProber(Latin5CyrillicModel),
49 | SingleByteCharSetProber(MacCyrillicModel),
50 | SingleByteCharSetProber(Ibm866Model),
51 | SingleByteCharSetProber(Ibm855Model),
52 | SingleByteCharSetProber(Latin7GreekModel),
53 | SingleByteCharSetProber(Win1253GreekModel),
54 | SingleByteCharSetProber(Latin5BulgarianModel),
55 | SingleByteCharSetProber(Win1251BulgarianModel),
56 | SingleByteCharSetProber(Latin2HungarianModel),
57 | SingleByteCharSetProber(Win1250HungarianModel),
58 | SingleByteCharSetProber(TIS620ThaiModel),
59 | ]
60 | hebrewProber = HebrewProber()
61 | logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel,
62 | False, hebrewProber)
63 | visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True,
64 | hebrewProber)
65 | hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber)
66 | self._mProbers.extend([hebrewProber, logicalHebrewProber,
67 | visualHebrewProber])
68 |
69 | self.reset()
70 |
--------------------------------------------------------------------------------
/requests/packages/charade/mbcharsetprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | # Proofpoint, Inc.
13 | #
14 | # This library is free software; you can redistribute it and/or
15 | # modify it under the terms of the GNU Lesser General Public
16 | # License as published by the Free Software Foundation; either
17 | # version 2.1 of the License, or (at your option) any later version.
18 | #
19 | # This library is distributed in the hope that it will be useful,
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 | # Lesser General Public License for more details.
23 | #
24 | # You should have received a copy of the GNU Lesser General Public
25 | # License along with this library; if not, write to the Free Software
26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 | # 02110-1301 USA
28 | ######################### END LICENSE BLOCK #########################
29 |
30 | import sys
31 | from . import constants
32 | from .charsetprober import CharSetProber
33 |
34 |
35 | class MultiByteCharSetProber(CharSetProber):
36 | def __init__(self):
37 | CharSetProber.__init__(self)
38 | self._mDistributionAnalyzer = None
39 | self._mCodingSM = None
40 | self._mLastChar = [0, 0]
41 |
42 | def reset(self):
43 | CharSetProber.reset(self)
44 | if self._mCodingSM:
45 | self._mCodingSM.reset()
46 | if self._mDistributionAnalyzer:
47 | self._mDistributionAnalyzer.reset()
48 | self._mLastChar = [0, 0]
49 |
50 | def get_charset_name(self):
51 | pass
52 |
53 | def feed(self, aBuf):
54 | aLen = len(aBuf)
55 | for i in range(0, aLen):
56 | codingState = self._mCodingSM.next_state(aBuf[i])
57 | if codingState == constants.eError:
58 | if constants._debug:
59 | sys.stderr.write(self.get_charset_name()
60 | + ' prober hit error at byte ' + str(i)
61 | + '\n')
62 | self._mState = constants.eNotMe
63 | break
64 | elif codingState == constants.eItsMe:
65 | self._mState = constants.eFoundIt
66 | break
67 | elif codingState == constants.eStart:
68 | charLen = self._mCodingSM.get_current_charlen()
69 | if i == 0:
70 | self._mLastChar[1] = aBuf[0]
71 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
72 | else:
73 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
74 | charLen)
75 |
76 | self._mLastChar[0] = aBuf[aLen - 1]
77 |
78 | if self.get_state() == constants.eDetecting:
79 | if (self._mDistributionAnalyzer.got_enough_data() and
80 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
81 | self._mState = constants.eFoundIt
82 |
83 | return self.get_state()
84 |
85 | def get_confidence(self):
86 | return self._mDistributionAnalyzer.get_confidence()
87 |
--------------------------------------------------------------------------------
/requests/packages/charade/eucjpprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | import sys
29 | from . import constants
30 | from .mbcharsetprober import MultiByteCharSetProber
31 | from .codingstatemachine import CodingStateMachine
32 | from .chardistribution import EUCJPDistributionAnalysis
33 | from .jpcntx import EUCJPContextAnalysis
34 | from .mbcssm import EUCJPSMModel
35 |
36 |
37 | class EUCJPProber(MultiByteCharSetProber):
38 | def __init__(self):
39 | MultiByteCharSetProber.__init__(self)
40 | self._mCodingSM = CodingStateMachine(EUCJPSMModel)
41 | self._mDistributionAnalyzer = EUCJPDistributionAnalysis()
42 | self._mContextAnalyzer = EUCJPContextAnalysis()
43 | self.reset()
44 |
45 | def reset(self):
46 | MultiByteCharSetProber.reset(self)
47 | self._mContextAnalyzer.reset()
48 |
49 | def get_charset_name(self):
50 | return "EUC-JP"
51 |
52 | def feed(self, aBuf):
53 | aLen = len(aBuf)
54 | for i in range(0, aLen):
55 | # PY3K: aBuf is a byte array, so aBuf[i] is an int, not a byte
56 | codingState = self._mCodingSM.next_state(aBuf[i])
57 | if codingState == constants.eError:
58 | if constants._debug:
59 | sys.stderr.write(self.get_charset_name()
60 | + ' prober hit error at byte ' + str(i)
61 | + '\n')
62 | self._mState = constants.eNotMe
63 | break
64 | elif codingState == constants.eItsMe:
65 | self._mState = constants.eFoundIt
66 | break
67 | elif codingState == constants.eStart:
68 | charLen = self._mCodingSM.get_current_charlen()
69 | if i == 0:
70 | self._mLastChar[1] = aBuf[0]
71 | self._mContextAnalyzer.feed(self._mLastChar, charLen)
72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
73 | else:
74 | self._mContextAnalyzer.feed(aBuf[i - 1:i + 1], charLen)
75 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
76 | charLen)
77 |
78 | self._mLastChar[0] = aBuf[aLen - 1]
79 |
80 | if self.get_state() == constants.eDetecting:
81 | if (self._mContextAnalyzer.got_enough_data() and
82 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
83 | self._mState = constants.eFoundIt
84 |
85 | return self.get_state()
86 |
87 | def get_confidence(self):
88 | contxtCf = self._mContextAnalyzer.get_confidence()
89 | distribCf = self._mDistributionAnalyzer.get_confidence()
90 | return max(contxtCf, distribCf)
91 |
--------------------------------------------------------------------------------
/requests/packages/charade/sjisprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | import sys
29 | from .mbcharsetprober import MultiByteCharSetProber
30 | from .codingstatemachine import CodingStateMachine
31 | from .chardistribution import SJISDistributionAnalysis
32 | from .jpcntx import SJISContextAnalysis
33 | from .mbcssm import SJISSMModel
34 | from . import constants
35 |
36 |
37 | class SJISProber(MultiByteCharSetProber):
38 | def __init__(self):
39 | MultiByteCharSetProber.__init__(self)
40 | self._mCodingSM = CodingStateMachine(SJISSMModel)
41 | self._mDistributionAnalyzer = SJISDistributionAnalysis()
42 | self._mContextAnalyzer = SJISContextAnalysis()
43 | self.reset()
44 |
45 | def reset(self):
46 | MultiByteCharSetProber.reset(self)
47 | self._mContextAnalyzer.reset()
48 |
49 | def get_charset_name(self):
50 | return "SHIFT_JIS"
51 |
52 | def feed(self, aBuf):
53 | aLen = len(aBuf)
54 | for i in range(0, aLen):
55 | codingState = self._mCodingSM.next_state(aBuf[i])
56 | if codingState == constants.eError:
57 | if constants._debug:
58 | sys.stderr.write(self.get_charset_name()
59 | + ' prober hit error at byte ' + str(i)
60 | + '\n')
61 | self._mState = constants.eNotMe
62 | break
63 | elif codingState == constants.eItsMe:
64 | self._mState = constants.eFoundIt
65 | break
66 | elif codingState == constants.eStart:
67 | charLen = self._mCodingSM.get_current_charlen()
68 | if i == 0:
69 | self._mLastChar[1] = aBuf[0]
70 | self._mContextAnalyzer.feed(self._mLastChar[2 - charLen:],
71 | charLen)
72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
73 | else:
74 | self._mContextAnalyzer.feed(aBuf[i + 1 - charLen:i + 3
75 | - charLen], charLen)
76 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
77 | charLen)
78 |
79 | self._mLastChar[0] = aBuf[aLen - 1]
80 |
81 | if self.get_state() == constants.eDetecting:
82 | if (self._mContextAnalyzer.got_enough_data() and
83 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
84 | self._mState = constants.eFoundIt
85 |
86 | return self.get_state()
87 |
88 | def get_confidence(self):
89 | contxtCf = self._mContextAnalyzer.get_confidence()
90 | distribCf = self._mDistributionAnalyzer.get_confidence()
91 | return max(contxtCf, distribCf)
92 |
--------------------------------------------------------------------------------
/requests/packages/charade/charsetgroupprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Communicator client code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from . import constants
29 | import sys
30 | from .charsetprober import CharSetProber
31 |
32 |
33 | class CharSetGroupProber(CharSetProber):
34 | def __init__(self):
35 | CharSetProber.__init__(self)
36 | self._mActiveNum = 0
37 | self._mProbers = []
38 | self._mBestGuessProber = None
39 |
40 | def reset(self):
41 | CharSetProber.reset(self)
42 | self._mActiveNum = 0
43 | for prober in self._mProbers:
44 | if prober:
45 | prober.reset()
46 | prober.active = True
47 | self._mActiveNum += 1
48 | self._mBestGuessProber = None
49 |
50 | def get_charset_name(self):
51 | if not self._mBestGuessProber:
52 | self.get_confidence()
53 | if not self._mBestGuessProber:
54 | return None
55 | # self._mBestGuessProber = self._mProbers[0]
56 | return self._mBestGuessProber.get_charset_name()
57 |
58 | def feed(self, aBuf):
59 | for prober in self._mProbers:
60 | if not prober:
61 | continue
62 | if not prober.active:
63 | continue
64 | st = prober.feed(aBuf)
65 | if not st:
66 | continue
67 | if st == constants.eFoundIt:
68 | self._mBestGuessProber = prober
69 | return self.get_state()
70 | elif st == constants.eNotMe:
71 | prober.active = False
72 | self._mActiveNum -= 1
73 | if self._mActiveNum <= 0:
74 | self._mState = constants.eNotMe
75 | return self.get_state()
76 | return self.get_state()
77 |
78 | def get_confidence(self):
79 | st = self.get_state()
80 | if st == constants.eFoundIt:
81 | return 0.99
82 | elif st == constants.eNotMe:
83 | return 0.01
84 | bestConf = 0.0
85 | self._mBestGuessProber = None
86 | for prober in self._mProbers:
87 | if not prober:
88 | continue
89 | if not prober.active:
90 | if constants._debug:
91 | sys.stderr.write(prober.get_charset_name()
92 | + ' not active\n')
93 | continue
94 | cf = prober.get_confidence()
95 | if constants._debug:
96 | sys.stderr.write('%s confidence = %s\n' %
97 | (prober.get_charset_name(), cf))
98 | if bestConf < cf:
99 | bestConf = cf
100 | self._mBestGuessProber = prober
101 | if not self._mBestGuessProber:
102 | return 0.0
103 | return bestConf
104 | # else:
105 | # self._mBestGuessProber = self._mProbers[0]
106 | # return self._mBestGuessProber.get_confidence()
107 |
--------------------------------------------------------------------------------
/README.mdown:
--------------------------------------------------------------------------------
1 | Hipster Ipsum for Sublime Text 2 and 3
2 | ================================
3 | If you were into _Lorem ipsum_ before it sold out and have been looking for something to fill the void, Hipster Ipsum is your new bicycle. Pull bespoke filler text from [Hipster Ipsum](http://hipsteripsum.me), via the [Hipster Jesus](http://hipsterjesus.com) API, and have it Occupy Sublime.
4 |
5 |
6 | Installation
7 | ------------
8 | You've probably never heard of [Sublime Package Control](http://wbond.net/sublime_packages/package_control), but it's the preferred method for installing HipsterIpsum. DIYers can find small-batch source files at [the GitHub repository](http://github.com/phyllisstein/HipsterIpsum).
9 |
10 |
11 | Usage
12 | -----
13 | Select a number from 1 to 99 and press Ctrl+Alt+H, and 1 to 99 pop-up paragraphs will be inserted. If the selection is not an authentic number or nothing is selected, whatever---the plugin will consult the readymade settings or your custom-built settings for a default number of paragraphs and insert that. For a lo-fi substitute, type "hipstum" and hit tab.
14 |
15 |
16 | Configuration
17 | -------------
18 | * **"paragraphs":** A sustainable number of paragraphs to insert by default.
19 | * **"ipsum_type":** Set to "hipster-centric" for single-origin hipster text and "hipster-latin" for hipster text with a Latinate mustache.
20 | * **"html":** Should the text be pickled in `` tags?
21 |
22 |
23 | Cred
24 | ----
25 | Thanks to [Will Bond](http://wbond.net) for his [tutorial on creating a Sublime Text 2 plugin](http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/), which offered some next-level solutions to a few difficulties. Thanks as well to the [requests](http://docs.python-requests.org/en/latest/) library, the sustainable biodiesel motor behind the farm-to-table HTTP.
26 |
27 |
28 | Cosby Sweater
29 | -------------
30 | Food truck gluten-free banksy, fap occupy bespoke whatever mustache. Occupy kogi kale chips chillwave, odd future typewriter iphone twee truffaut viral ethical artisan put a bird on it single-origin coffee banh mi. Master cleanse brunch occupy trust fund marfa yr. Chillwave ennui fap, wes anderson cliche cosby sweater brooklyn vegan organic. Shoreditch PBR semiotics, chillwave art party photo booth terry richardson. Synth ennui semiotics mustache pickled, biodiesel food truck cosby sweater readymade mixtape letterpress pour-over leggings. Food truck freegan vinyl thundercats, post-ironic ennui wes anderson banh mi four loko synth photo booth authentic 3 wolf moon.
31 |
32 | Sriracha pinterest sustainable jean shorts vinyl, beard echo park DIY squid mustache cliche artisan cray pickled whatever. Occupy artisan hella letterpress, shoreditch brooklyn umami high life pork belly. Banksy dreamcatcher bushwick keytar, truffaut tofu scenester iphone bespoke marfa four loko forage american apparel blog. DIY umami lo-fi, mlkshk small batch williamsburg cred. Godard shoreditch direct trade ethnic art party. Ethnic williamsburg echo park direct trade, messenger bag whatever 3 wolf moon cosby sweater ennui DIY organic. Quinoa you probably haven't heard of them ennui, trust fund tofu banh mi flexitarian bicycle rights echo park gentrify messenger bag.
33 |
34 | Chillwave vice sriracha hella cliche forage. Thundercats artisan iphone, butcher +1 next level keffiyeh fixie narwhal. Lomo banh mi godard mustache cardigan, ennui truffaut pop-up craft beer. Blog yr 3 wolf moon cred occupy, polaroid shoreditch lomo tattooed. Hella bicycle rights terry richardson, retro semiotics street art wes anderson mcsweeney's beard aesthetic irony kogi occupy. Kogi DIY banksy, photo booth whatever authentic truffaut. Fanny pack high life iphone, ennui shoreditch DIY etsy occupy photo booth farm-to-table mustache hoodie stumptown.
35 |
36 | Vice DIY biodiesel fingerstache, marfa before they sold out cardigan tumblr kale chips pork belly raw denim mlkshk. Etsy butcher swag, echo park ethnic small batch gentrify. Bicycle rights mustache artisan, keytar lo-fi sustainable fap stumptown vegan salvia freegan four loko terry richardson. Photo booth wes anderson raw denim williamsburg retro. Keffiyeh street art brunch ethical. Swag master cleanse ethical aesthetic. You probably haven't heard of them umami hoodie fixie tofu pickled.
37 |
38 | Occupy street art banh mi skateboard wayfarers. Mumblecore biodiesel single-origin coffee umami, pickled semiotics terry richardson skateboard gluten-free. American apparel jean shorts terry richardson squid. Letterpress tattooed cray beard pinterest. Jean shorts tofu wayfarers, fap PBR swag banh mi. Organic chillwave scenester wayfarers semiotics salvia messenger bag, vice odd future. Photo booth street art terry richardson bespoke irony, occupy art party tofu pour-over whatever american apparel food truck.
--------------------------------------------------------------------------------
/requests/api.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.api
5 | ~~~~~~~~~~~~
6 |
7 | This module implements the Requests API.
8 |
9 | :copyright: (c) 2012 by Kenneth Reitz.
10 | :license: Apache2, see LICENSE for more details.
11 |
12 | """
13 |
14 | from . import sessions
15 |
16 |
17 | def request(method, url, **kwargs):
18 | """Constructs and sends a :class:`Request `.
19 | Returns :class:`Response ` object.
20 |
21 | :param method: method for the new :class:`Request` object.
22 | :param url: URL for the new :class:`Request` object.
23 | :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
24 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
25 | :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
26 | :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
27 | :param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.
28 | :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
29 | :param timeout: (optional) Float describing the timeout of the request.
30 | :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
31 | :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
32 | :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
33 | :param stream: (optional) if ``False``, the response content will be immediately downloaded.
34 | :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
35 |
36 | Usage::
37 |
38 | >>> import requests
39 | >>> req = requests.request('GET', 'http://httpbin.org/get')
40 |
41 | """
42 |
43 | session = sessions.Session()
44 | return session.request(method=method, url=url, **kwargs)
45 |
46 |
47 | def get(url, **kwargs):
48 | """Sends a GET request. Returns :class:`Response` object.
49 |
50 | :param url: URL for the new :class:`Request` object.
51 | :param \*\*kwargs: Optional arguments that ``request`` takes.
52 | """
53 |
54 | kwargs.setdefault('allow_redirects', True)
55 | return request('get', url, **kwargs)
56 |
57 |
58 | def options(url, **kwargs):
59 | """Sends a OPTIONS request. Returns :class:`Response` object.
60 |
61 | :param url: URL for the new :class:`Request` object.
62 | :param \*\*kwargs: Optional arguments that ``request`` takes.
63 | """
64 |
65 | kwargs.setdefault('allow_redirects', True)
66 | return request('options', url, **kwargs)
67 |
68 |
69 | def head(url, **kwargs):
70 | """Sends a HEAD request. Returns :class:`Response` object.
71 |
72 | :param url: URL for the new :class:`Request` object.
73 | :param \*\*kwargs: Optional arguments that ``request`` takes.
74 | """
75 |
76 | kwargs.setdefault('allow_redirects', False)
77 | return request('head', url, **kwargs)
78 |
79 |
80 | def post(url, data=None, **kwargs):
81 | """Sends a POST request. Returns :class:`Response` object.
82 |
83 | :param url: URL for the new :class:`Request` object.
84 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
85 | :param \*\*kwargs: Optional arguments that ``request`` takes.
86 | """
87 |
88 | return request('post', url, data=data, **kwargs)
89 |
90 |
91 | def put(url, data=None, **kwargs):
92 | """Sends a PUT request. Returns :class:`Response` object.
93 |
94 | :param url: URL for the new :class:`Request` object.
95 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
96 | :param \*\*kwargs: Optional arguments that ``request`` takes.
97 | """
98 |
99 | return request('put', url, data=data, **kwargs)
100 |
101 |
102 | def patch(url, data=None, **kwargs):
103 | """Sends a PATCH request. Returns :class:`Response` object.
104 |
105 | :param url: URL for the new :class:`Request` object.
106 | :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
107 | :param \*\*kwargs: Optional arguments that ``request`` takes.
108 | """
109 |
110 | return request('patch', url, data=data, **kwargs)
111 |
112 |
113 | def delete(url, **kwargs):
114 | """Sends a DELETE request. Returns :class:`Response` object.
115 |
116 | :param url: URL for the new :class:`Request` object.
117 | :param \*\*kwargs: Optional arguments that ``request`` takes.
118 | """
119 |
120 | return request('delete', url, **kwargs)
121 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/contrib/ntlmpool.py:
--------------------------------------------------------------------------------
1 | # urllib3/contrib/ntlmpool.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | """
8 | NTLM authenticating pool, contributed by erikcederstran
9 |
10 | Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
11 | """
12 |
13 | try:
14 | from http.client import HTTPSConnection
15 | except ImportError:
16 | from httplib import HTTPSConnection
17 | from logging import getLogger
18 | from ntlm import ntlm
19 |
20 | from urllib3 import HTTPSConnectionPool
21 |
22 |
23 | log = getLogger(__name__)
24 |
25 |
26 | class NTLMConnectionPool(HTTPSConnectionPool):
27 | """
28 | Implements an NTLM authentication version of an urllib3 connection pool
29 | """
30 |
31 | scheme = 'https'
32 |
33 | def __init__(self, user, pw, authurl, *args, **kwargs):
34 | """
35 | authurl is a random URL on the server that is protected by NTLM.
36 | user is the Windows user, probably in the DOMAIN\username format.
37 | pw is the password for the user.
38 | """
39 | super(NTLMConnectionPool, self).__init__(*args, **kwargs)
40 | self.authurl = authurl
41 | self.rawuser = user
42 | user_parts = user.split('\\', 1)
43 | self.domain = user_parts[0].upper()
44 | self.user = user_parts[1]
45 | self.pw = pw
46 |
47 | def _new_conn(self):
48 | # Performs the NTLM handshake that secures the connection. The socket
49 | # must be kept open while requests are performed.
50 | self.num_connections += 1
51 | log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s' %
52 | (self.num_connections, self.host, self.authurl))
53 |
54 | headers = {}
55 | headers['Connection'] = 'Keep-Alive'
56 | req_header = 'Authorization'
57 | resp_header = 'www-authenticate'
58 |
59 | conn = HTTPSConnection(host=self.host, port=self.port)
60 |
61 | # Send negotiation message
62 | headers[req_header] = (
63 | 'NTLM %s' % ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser))
64 | log.debug('Request headers: %s' % headers)
65 | conn.request('GET', self.authurl, None, headers)
66 | res = conn.getresponse()
67 | reshdr = dict(res.getheaders())
68 | log.debug('Response status: %s %s' % (res.status, res.reason))
69 | log.debug('Response headers: %s' % reshdr)
70 | log.debug('Response data: %s [...]' % res.read(100))
71 |
72 | # Remove the reference to the socket, so that it can not be closed by
73 | # the response object (we want to keep the socket open)
74 | res.fp = None
75 |
76 | # Server should respond with a challenge message
77 | auth_header_values = reshdr[resp_header].split(', ')
78 | auth_header_value = None
79 | for s in auth_header_values:
80 | if s[:5] == 'NTLM ':
81 | auth_header_value = s[5:]
82 | if auth_header_value is None:
83 | raise Exception('Unexpected %s response header: %s' %
84 | (resp_header, reshdr[resp_header]))
85 |
86 | # Send authentication message
87 | ServerChallenge, NegotiateFlags = \
88 | ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value)
89 | auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge,
90 | self.user,
91 | self.domain,
92 | self.pw,
93 | NegotiateFlags)
94 | headers[req_header] = 'NTLM %s' % auth_msg
95 | log.debug('Request headers: %s' % headers)
96 | conn.request('GET', self.authurl, None, headers)
97 | res = conn.getresponse()
98 | log.debug('Response status: %s %s' % (res.status, res.reason))
99 | log.debug('Response headers: %s' % dict(res.getheaders()))
100 | log.debug('Response data: %s [...]' % res.read()[:100])
101 | if res.status != 200:
102 | if res.status == 401:
103 | raise Exception('Server rejected request: wrong '
104 | 'username or password')
105 | raise Exception('Wrong server response: %s %s' %
106 | (res.status, res.reason))
107 |
108 | res.fp = None
109 | log.debug('Connection established')
110 | return conn
111 |
112 | def urlopen(self, method, url, body=None, headers=None, retries=3,
113 | redirect=True, assert_same_host=True):
114 | if headers is None:
115 | headers = {}
116 | headers['Connection'] = 'Keep-Alive'
117 | return super(NTLMConnectionPool, self).urlopen(method, url, body,
118 | headers, retries,
119 | redirect,
120 | assert_same_host)
121 |
--------------------------------------------------------------------------------
/requests/packages/charade/sbcharsetprober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | import sys
30 | from . import constants
31 | from .charsetprober import CharSetProber
32 | from .compat import wrap_ord
33 |
34 | SAMPLE_SIZE = 64
35 | SB_ENOUGH_REL_THRESHOLD = 1024
36 | POSITIVE_SHORTCUT_THRESHOLD = 0.95
37 | NEGATIVE_SHORTCUT_THRESHOLD = 0.05
38 | SYMBOL_CAT_ORDER = 250
39 | NUMBER_OF_SEQ_CAT = 4
40 | POSITIVE_CAT = NUMBER_OF_SEQ_CAT - 1
41 | #NEGATIVE_CAT = 0
42 |
43 |
44 | class SingleByteCharSetProber(CharSetProber):
45 | def __init__(self, model, reversed=False, nameProber=None):
46 | CharSetProber.__init__(self)
47 | self._mModel = model
48 | # TRUE if we need to reverse every pair in the model lookup
49 | self._mReversed = reversed
50 | # Optional auxiliary prober for name decision
51 | self._mNameProber = nameProber
52 | self.reset()
53 |
54 | def reset(self):
55 | CharSetProber.reset(self)
56 | # char order of last character
57 | self._mLastOrder = 255
58 | self._mSeqCounters = [0] * NUMBER_OF_SEQ_CAT
59 | self._mTotalSeqs = 0
60 | self._mTotalChar = 0
61 | # characters that fall in our sampling range
62 | self._mFreqChar = 0
63 |
64 | def get_charset_name(self):
65 | if self._mNameProber:
66 | return self._mNameProber.get_charset_name()
67 | else:
68 | return self._mModel['charsetName']
69 |
70 | def feed(self, aBuf):
71 | if not self._mModel['keepEnglishLetter']:
72 | aBuf = self.filter_without_english_letters(aBuf)
73 | aLen = len(aBuf)
74 | if not aLen:
75 | return self.get_state()
76 | for c in aBuf:
77 | order = self._mModel['charToOrderMap'][wrap_ord(c)]
78 | if order < SYMBOL_CAT_ORDER:
79 | self._mTotalChar += 1
80 | if order < SAMPLE_SIZE:
81 | self._mFreqChar += 1
82 | if self._mLastOrder < SAMPLE_SIZE:
83 | self._mTotalSeqs += 1
84 | if not self._mReversed:
85 | i = (self._mLastOrder * SAMPLE_SIZE) + order
86 | model = self._mModel['precedenceMatrix'][i]
87 | else: # reverse the order of the letters in the lookup
88 | i = (order * SAMPLE_SIZE) + self._mLastOrder
89 | model = self._mModel['precedenceMatrix'][i]
90 | self._mSeqCounters[model] += 1
91 | self._mLastOrder = order
92 |
93 | if self.get_state() == constants.eDetecting:
94 | if self._mTotalSeqs > SB_ENOUGH_REL_THRESHOLD:
95 | cf = self.get_confidence()
96 | if cf > POSITIVE_SHORTCUT_THRESHOLD:
97 | if constants._debug:
98 | sys.stderr.write('%s confidence = %s, we have a'
99 | 'winner\n' %
100 | (self._mModel['charsetName'], cf))
101 | self._mState = constants.eFoundIt
102 | elif cf < NEGATIVE_SHORTCUT_THRESHOLD:
103 | if constants._debug:
104 | sys.stderr.write('%s confidence = %s, below negative'
105 | 'shortcut threshhold %s\n' %
106 | (self._mModel['charsetName'], cf,
107 | NEGATIVE_SHORTCUT_THRESHOLD))
108 | self._mState = constants.eNotMe
109 |
110 | return self.get_state()
111 |
112 | def get_confidence(self):
113 | r = 0.01
114 | if self._mTotalSeqs > 0:
115 | r = ((1.0 * self._mSeqCounters[POSITIVE_CAT]) / self._mTotalSeqs
116 | / self._mModel['mTypicalPositiveRatio'])
117 | r = r * self._mFreqChar / self._mTotalChar
118 | if r >= 1.0:
119 | r = 0.99
120 | return r
121 |
--------------------------------------------------------------------------------
/requests/packages/charade/latin1prober.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | from .charsetprober import CharSetProber
30 | from .constants import eNotMe
31 | from .compat import wrap_ord
32 |
33 | FREQ_CAT_NUM = 4
34 |
35 | UDF = 0 # undefined
36 | OTH = 1 # other
37 | ASC = 2 # ascii capital letter
38 | ASS = 3 # ascii small letter
39 | ACV = 4 # accent capital vowel
40 | ACO = 5 # accent capital other
41 | ASV = 6 # accent small vowel
42 | ASO = 7 # accent small other
43 | CLASS_NUM = 8 # total classes
44 |
45 | Latin1_CharToClass = (
46 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07
47 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0F
48 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17
49 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1F
50 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27
51 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2F
52 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37
53 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3F
54 | OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47
55 | ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4F
56 | ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57
57 | ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5F
58 | OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67
59 | ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6F
60 | ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77
61 | ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7F
62 | OTH, UDF, OTH, ASO, OTH, OTH, OTH, OTH, # 80 - 87
63 | OTH, OTH, ACO, OTH, ACO, UDF, ACO, UDF, # 88 - 8F
64 | UDF, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 90 - 97
65 | OTH, OTH, ASO, OTH, ASO, UDF, ASO, ACO, # 98 - 9F
66 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A0 - A7
67 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A8 - AF
68 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7
69 | OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B8 - BF
70 | ACV, ACV, ACV, ACV, ACV, ACV, ACO, ACO, # C0 - C7
71 | ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # C8 - CF
72 | ACO, ACO, ACV, ACV, ACV, ACV, ACV, OTH, # D0 - D7
73 | ACV, ACV, ACV, ACV, ACV, ACO, ACO, ACO, # D8 - DF
74 | ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASO, # E0 - E7
75 | ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # E8 - EF
76 | ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, # F0 - F7
77 | ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, # F8 - FF
78 | )
79 |
80 | # 0 : illegal
81 | # 1 : very unlikely
82 | # 2 : normal
83 | # 3 : very likely
84 | Latin1ClassModel = (
85 | # UDF OTH ASC ASS ACV ACO ASV ASO
86 | 0, 0, 0, 0, 0, 0, 0, 0, # UDF
87 | 0, 3, 3, 3, 3, 3, 3, 3, # OTH
88 | 0, 3, 3, 3, 3, 3, 3, 3, # ASC
89 | 0, 3, 3, 3, 1, 1, 3, 3, # ASS
90 | 0, 3, 3, 3, 1, 2, 1, 2, # ACV
91 | 0, 3, 3, 3, 3, 3, 3, 3, # ACO
92 | 0, 3, 1, 3, 1, 1, 1, 3, # ASV
93 | 0, 3, 1, 3, 1, 1, 3, 3, # ASO
94 | )
95 |
96 |
97 | class Latin1Prober(CharSetProber):
98 | def __init__(self):
99 | CharSetProber.__init__(self)
100 | self.reset()
101 |
102 | def reset(self):
103 | self._mLastCharClass = OTH
104 | self._mFreqCounter = [0] * FREQ_CAT_NUM
105 | CharSetProber.reset(self)
106 |
107 | def get_charset_name(self):
108 | return "windows-1252"
109 |
110 | def feed(self, aBuf):
111 | aBuf = self.filter_with_english_letters(aBuf)
112 | for c in aBuf:
113 | charClass = Latin1_CharToClass[wrap_ord(c)]
114 | freq = Latin1ClassModel[(self._mLastCharClass * CLASS_NUM)
115 | + charClass]
116 | if freq == 0:
117 | self._mState = eNotMe
118 | break
119 | self._mFreqCounter[freq] += 1
120 | self._mLastCharClass = charClass
121 |
122 | return self.get_state()
123 |
124 | def get_confidence(self):
125 | if self.get_state() == eNotMe:
126 | return 0.01
127 |
128 | total = sum(self._mFreqCounter)
129 | if total < 0.01:
130 | confidence = 0.0
131 | else:
132 | confidence = ((self._mFreqCounter[3] / total)
133 | - (self._mFreqCounter[1] * 20.0 / total))
134 | if confidence < 0.0:
135 | confidence = 0.0
136 | # lower the confidence of latin1 so that other more accurate
137 | # detector can take priority.
138 | confidence = confidence * 0.5
139 | return confidence
140 |
--------------------------------------------------------------------------------
/requests/auth.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.auth
5 | ~~~~~~~~~~~~~
6 |
7 | This module contains the authentication handlers for Requests.
8 | """
9 |
10 | import os
11 | import time
12 | import hashlib
13 | import logging
14 |
15 | from base64 import b64encode
16 |
17 | from .compat import urlparse, str
18 | from .utils import parse_dict_header
19 |
20 |
21 | log = logging.getLogger(__name__)
22 |
23 | CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
24 | CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
25 |
26 |
27 | def _basic_auth_str(username, password):
28 | """Returns a Basic Auth string."""
29 |
30 | return 'Basic ' + b64encode(('%s:%s' % (username, password)).encode('latin1')).strip().decode('latin1')
31 |
32 |
33 | class AuthBase(object):
34 | """Base class that all auth implementations derive from"""
35 |
36 | def __call__(self, r):
37 | raise NotImplementedError('Auth hooks must be callable.')
38 |
39 |
40 | class HTTPBasicAuth(AuthBase):
41 | """Attaches HTTP Basic Authentication to the given Request object."""
42 | def __init__(self, username, password):
43 | self.username = username
44 | self.password = password
45 |
46 | def __call__(self, r):
47 | r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
48 | return r
49 |
50 |
51 | class HTTPProxyAuth(HTTPBasicAuth):
52 | """Attaches HTTP Proxy Authenetication to a given Request object."""
53 | def __call__(self, r):
54 | r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)
55 | return r
56 |
57 |
58 | class HTTPDigestAuth(AuthBase):
59 | """Attaches HTTP Digest Authentication to the given Request object."""
60 | def __init__(self, username, password):
61 | self.username = username
62 | self.password = password
63 | self.last_nonce = ''
64 | self.nonce_count = 0
65 | self.chal = {}
66 |
67 | def build_digest_header(self, method, url):
68 |
69 | realm = self.chal['realm']
70 | nonce = self.chal['nonce']
71 | qop = self.chal.get('qop')
72 | algorithm = self.chal.get('algorithm')
73 | opaque = self.chal.get('opaque')
74 |
75 | if algorithm is None:
76 | _algorithm = 'MD5'
77 | else:
78 | _algorithm = algorithm.upper()
79 | # lambdas assume digest modules are imported at the top level
80 | if _algorithm == 'MD5':
81 | def md5_utf8(x):
82 | if isinstance(x, str):
83 | x = x.encode('utf-8')
84 | return hashlib.md5(x).hexdigest()
85 | hash_utf8 = md5_utf8
86 | elif _algorithm == 'SHA':
87 | def sha_utf8(x):
88 | if isinstance(x, str):
89 | x = x.encode('utf-8')
90 | return hashlib.sha1(x).hexdigest()
91 | hash_utf8 = sha_utf8
92 | # XXX MD5-sess
93 | KD = lambda s, d: hash_utf8("%s:%s" % (s, d))
94 |
95 | if hash_utf8 is None:
96 | return None
97 |
98 | # XXX not implemented yet
99 | entdig = None
100 | p_parsed = urlparse(url)
101 | path = p_parsed.path
102 | if p_parsed.query:
103 | path += '?' + p_parsed.query
104 |
105 | A1 = '%s:%s:%s' % (self.username, realm, self.password)
106 | A2 = '%s:%s' % (method, path)
107 |
108 | if qop == 'auth':
109 | if nonce == self.last_nonce:
110 | self.nonce_count += 1
111 | else:
112 | self.nonce_count = 1
113 |
114 | ncvalue = '%08x' % self.nonce_count
115 | s = str(self.nonce_count).encode('utf-8')
116 | s += nonce.encode('utf-8')
117 | s += time.ctime().encode('utf-8')
118 | s += os.urandom(8)
119 |
120 | cnonce = (hashlib.sha1(s).hexdigest()[:16])
121 | noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
122 | respdig = KD(hash_utf8(A1), noncebit)
123 | elif qop is None:
124 | respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2)))
125 | else:
126 | # XXX handle auth-int.
127 | return None
128 |
129 | self.last_nonce = nonce
130 |
131 | # XXX should the partial digests be encoded too?
132 | base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
133 | 'response="%s"' % (self.username, realm, nonce, path, respdig)
134 | if opaque:
135 | base += ', opaque="%s"' % opaque
136 | if algorithm:
137 | base += ', algorithm="%s"' % algorithm
138 | if entdig:
139 | base += ', digest="%s"' % entdig
140 | if qop:
141 | base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce)
142 |
143 | return 'Digest %s' % (base)
144 |
145 | def handle_401(self, r, **kwargs):
146 | """Takes the given response and tries digest-auth, if needed."""
147 |
148 | num_401_calls = getattr(self, 'num_401_calls', 1)
149 | s_auth = r.headers.get('www-authenticate', '')
150 |
151 | if 'digest' in s_auth.lower() and num_401_calls < 2:
152 |
153 | setattr(self, 'num_401_calls', num_401_calls + 1)
154 | self.chal = parse_dict_header(s_auth.replace('Digest ', ''))
155 |
156 | # Consume content and release the original connection
157 | # to allow our new request to reuse the same one.
158 | r.content
159 | r.raw.release_conn()
160 |
161 | r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
162 | _r = r.connection.send(r.request, **kwargs)
163 | _r.history.append(r)
164 |
165 | return _r
166 |
167 | setattr(self, 'num_401_calls', 1)
168 | return r
169 |
170 | def __call__(self, r):
171 | # If we have a saved nonce, skip the 401
172 | if self.last_nonce:
173 | r.headers['Authorization'] = self.build_digest_header(r.method, r.url)
174 | r.register_hook('response', self.handle_401)
175 | return r
176 |
--------------------------------------------------------------------------------
/hipsteripsum.py:
--------------------------------------------------------------------------------
1 | import sublime
2 | import sublime_plugin
3 | import threading
4 | import urllib
5 | import json
6 | if int(sublime.version()) >= 3000:
7 | from . import requests
8 | else:
9 | import requests
10 |
11 |
12 | def err(theError):
13 | print("[Hipster Ipsum: " + theError + "]")
14 |
15 |
16 | class HipsterIpsumCommand(sublime_plugin.TextCommand):
17 | def run(self, edit):
18 | s = sublime.load_settings("Hipster Ipsum.sublime-settings")
19 | defaultParas = s.get("paragraphs", 1)
20 | ipsumType = s.get("ipsum_type", "hipster-centric")
21 | useHTML = "false" if s.get("html", False) == False else "true"
22 |
23 | selections = self.view.sel()
24 | threads = []
25 | passedThreads = 0
26 | skippedThreads = 0
27 | for theSelection in selections:
28 | theSubstring = self.view.substr(theSelection)
29 | if len(theSubstring) == 0:
30 | newThread = HipsterIpsumAPICall(theSelection, defaultParas, ipsumType, useHTML, "")
31 | threads.append(newThread)
32 | newThread.start()
33 | passedThreads += 1
34 | else:
35 | try:
36 | parasHere = int(theSubstring)
37 | except ValueError:
38 | newThread = HipsterIpsumAPICall(theSelection, defaultParas, ipsumType, useHTML, theSubstring)
39 | threads.append(newThread)
40 | newThread.start()
41 | passedThreads += 1
42 | else:
43 | if parasHere < 1:
44 | err("%i is too few paragraphs." % parasHere)
45 | err("Select a number between 1 and 99.")
46 | sublime.status_message("Hipster Ipsum: Too few paragraphs (%i)." % parasHere)
47 | skippedThreads += 1
48 | elif parasHere > 99:
49 | err("%i is too many paragraphs." % parasHere)
50 | err("Select a number between 1 and 99.")
51 | sublime.status_message("Hipster Ipsum: Too many paragraphs (%i)." % parasHere)
52 | skippedThreads += 1
53 | else:
54 | newThread = HipsterIpsumAPICall(theSelection, parasHere, ipsumType, useHTML, theSubstring)
55 | threads.append(newThread)
56 | newThread.start()
57 | passedThreads += 1
58 | if passedThreads > 0:
59 | self.view.sel().clear()
60 | self.manageThreads(threads)
61 | else:
62 | sublime.status_message("Hipster Ipsum: No authentic selections.")
63 | err("Skipped %i selections." % skippedThreads)
64 |
65 | def manageThreads(self, theThreads, offset=0, i=0, direction=1):
66 | next_threads = []
67 | for thread in theThreads:
68 | if thread.is_alive():
69 | next_threads.append(thread)
70 | continue
71 | if thread.result == False:
72 | continue
73 | offset = self.replace(thread, offset)
74 | theThreads = next_threads
75 |
76 | if len(theThreads):
77 | before = i % 8
78 | after = 7 - before
79 | if not after:
80 | direction = -1
81 | if not before:
82 | direction = 1
83 | i += direction
84 | self.view.set_status("hipster_ipsum", "Gentrifying... [%s=%s]" % (" " * before, " " * after))
85 |
86 | sublime.set_timeout(lambda: self.manageThreads(theThreads, offset, i, direction), 100)
87 | return
88 |
89 | self.view.erase_status("hipster_ipsum")
90 | selections = len(self.view.sel())
91 | sublime.status_message("%s area%s gentrified." % (selections, '' if selections == 1 else 's'))
92 |
93 | def replace(self, theThread, offset):
94 | selection = theThread.selection
95 | original = theThread.original
96 | result = theThread.result
97 |
98 | if offset:
99 | selection = sublime.Region(selection.begin() + offset, selection.end() + offset)
100 |
101 | result = self.normalize_line_endings(result)
102 | self.view.run_command("hipster_ipsum_replace", {"begin": selection.begin(), "end": selection.end(), "data": result})
103 | endpoint = selection.begin() + len(result)
104 | self.view.sel().add(sublime.Region(endpoint, endpoint))
105 |
106 | return offset + len(result) - len(original)
107 |
108 | def normalize_line_endings(self, string):
109 | string = string.replace('\n', '\n\n')
110 | string = string.replace('\r\n', '\n').replace('\r', '\n')
111 | line_endings = self.view.settings().get('default_line_ending')
112 | if line_endings == 'windows':
113 | string = string.replace('\n', '\r\n')
114 | elif line_endings == 'mac':
115 | string = string.replace('\n', '\r')
116 | return string
117 |
118 |
119 | class HipsterIpsumAPICall(threading.Thread):
120 | def __init__(self, theSelection, numParagraphs, ipsumType, useHTML, originalString):
121 | self.selection = theSelection
122 | self.paragraphs = numParagraphs
123 | self.ipsumType = ipsumType
124 | self.useHTML = useHTML
125 | self.original = originalString
126 | self.result = None
127 | threading.Thread.__init__(self)
128 |
129 | def run(self):
130 | params = {"paras": self.paragraphs, "type": self.ipsumType, "html": self.useHTML}
131 |
132 | try:
133 | r = requests.get("http://hipsterjesus.com/api/", params=params)
134 | except Exception as e:
135 | err("Exception: %s" % e)
136 | self.result = False
137 |
138 | data = r.json()
139 | self.result = data["text"]
140 |
141 | class HipsterIpsumReplaceCommand(sublime_plugin.TextCommand):
142 | def run(self, edit, begin, end, data):
143 | a = long(begin) if int(sublime.version()) < 3000 else begin
144 | b = long(end) if int(sublime.version()) < 3000 else end
145 | region = sublime.Region(a, b)
146 | self.view.replace(edit, region, data)
147 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/request.py:
--------------------------------------------------------------------------------
1 | # urllib3/request.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | try:
8 | from urllib.parse import urlencode
9 | except ImportError:
10 | from urllib import urlencode
11 |
12 | from .filepost import encode_multipart_formdata
13 |
14 |
15 | __all__ = ['RequestMethods']
16 |
17 |
18 | class RequestMethods(object):
19 | """
20 | Convenience mixin for classes who implement a :meth:`urlopen` method, such
21 | as :class:`~urllib3.connectionpool.HTTPConnectionPool` and
22 | :class:`~urllib3.poolmanager.PoolManager`.
23 |
24 | Provides behavior for making common types of HTTP request methods and
25 | decides which type of request field encoding to use.
26 |
27 | Specifically,
28 |
29 | :meth:`.request_encode_url` is for sending requests whose fields are encoded
30 | in the URL (such as GET, HEAD, DELETE).
31 |
32 | :meth:`.request_encode_body` is for sending requests whose fields are
33 | encoded in the *body* of the request using multipart or www-orm-urlencoded
34 | (such as for POST, PUT, PATCH).
35 |
36 | :meth:`.request` is for making any kind of request, it will look up the
37 | appropriate encoding format and use one of the above two methods to make
38 | the request.
39 |
40 | Initializer parameters:
41 |
42 | :param headers:
43 | Headers to include with all requests, unless other headers are given
44 | explicitly.
45 | """
46 |
47 | _encode_url_methods = set(['DELETE', 'GET', 'HEAD', 'OPTIONS'])
48 | _encode_body_methods = set(['PATCH', 'POST', 'PUT', 'TRACE'])
49 |
50 | def __init__(self, headers=None):
51 | self.headers = headers or {}
52 |
53 | def urlopen(self, method, url, body=None, headers=None,
54 | encode_multipart=True, multipart_boundary=None,
55 | **kw): # Abstract
56 | raise NotImplemented("Classes extending RequestMethods must implement "
57 | "their own ``urlopen`` method.")
58 |
59 | def request(self, method, url, fields=None, headers=None, **urlopen_kw):
60 | """
61 | Make a request using :meth:`urlopen` with the appropriate encoding of
62 | ``fields`` based on the ``method`` used.
63 |
64 | This is a convenience method that requires the least amount of manual
65 | effort. It can be used in most situations, while still having the option
66 | to drop down to more specific methods when necessary, such as
67 | :meth:`request_encode_url`, :meth:`request_encode_body`,
68 | or even the lowest level :meth:`urlopen`.
69 | """
70 | method = method.upper()
71 |
72 | if method in self._encode_url_methods:
73 | return self.request_encode_url(method, url, fields=fields,
74 | headers=headers,
75 | **urlopen_kw)
76 | else:
77 | return self.request_encode_body(method, url, fields=fields,
78 | headers=headers,
79 | **urlopen_kw)
80 |
81 | def request_encode_url(self, method, url, fields=None, **urlopen_kw):
82 | """
83 | Make a request using :meth:`urlopen` with the ``fields`` encoded in
84 | the url. This is useful for request methods like GET, HEAD, DELETE, etc.
85 | """
86 | if fields:
87 | url += '?' + urlencode(fields)
88 | return self.urlopen(method, url, **urlopen_kw)
89 |
90 | def request_encode_body(self, method, url, fields=None, headers=None,
91 | encode_multipart=True, multipart_boundary=None,
92 | **urlopen_kw):
93 | """
94 | Make a request using :meth:`urlopen` with the ``fields`` encoded in
95 | the body. This is useful for request methods like POST, PUT, PATCH, etc.
96 |
97 | When ``encode_multipart=True`` (default), then
98 | :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode the
99 | payload with the appropriate content type. Otherwise
100 | :meth:`urllib.urlencode` is used with the
101 | 'application/x-www-form-urlencoded' content type.
102 |
103 | Multipart encoding must be used when posting files, and it's reasonably
104 | safe to use it in other times too. However, it may break request signing,
105 | such as with OAuth.
106 |
107 | Supports an optional ``fields`` parameter of key/value strings AND
108 | key/filetuple. A filetuple is a (filename, data, MIME type) tuple where
109 | the MIME type is optional. For example: ::
110 |
111 | fields = {
112 | 'foo': 'bar',
113 | 'fakefile': ('foofile.txt', 'contents of foofile'),
114 | 'realfile': ('barfile.txt', open('realfile').read()),
115 | 'typedfile': ('bazfile.bin', open('bazfile').read(),
116 | 'image/jpeg'),
117 | 'nonamefile': 'contents of nonamefile field',
118 | }
119 |
120 | When uploading a file, providing a filename (the first parameter of the
121 | tuple) is optional but recommended to best mimick behavior of browsers.
122 |
123 | Note that if ``headers`` are supplied, the 'Content-Type' header will be
124 | overwritten because it depends on the dynamic random boundary string
125 | which is used to compose the body of the request. The random boundary
126 | string can be explicitly set with the ``multipart_boundary`` parameter.
127 | """
128 | if encode_multipart:
129 | body, content_type = encode_multipart_formdata(fields or {},
130 | boundary=multipart_boundary)
131 | else:
132 | body, content_type = (urlencode(fields or {}),
133 | 'application/x-www-form-urlencoded')
134 |
135 | if headers is None:
136 | headers = self.headers
137 |
138 | headers_ = {'Content-Type': content_type}
139 | headers_.update(headers)
140 |
141 | return self.urlopen(method, url, body=body, headers=headers_,
142 | **urlopen_kw)
143 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/poolmanager.py:
--------------------------------------------------------------------------------
1 | # urllib3/poolmanager.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | import logging
8 |
9 | from ._collections import RecentlyUsedContainer
10 | from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool
11 | from .connectionpool import connection_from_url, port_by_scheme
12 | from .request import RequestMethods
13 | from .util import parse_url
14 |
15 |
16 | __all__ = ['PoolManager', 'ProxyManager', 'proxy_from_url']
17 |
18 |
19 | pool_classes_by_scheme = {
20 | 'http': HTTPConnectionPool,
21 | 'https': HTTPSConnectionPool,
22 | }
23 |
24 | log = logging.getLogger(__name__)
25 |
26 |
27 | class PoolManager(RequestMethods):
28 | """
29 | Allows for arbitrary requests while transparently keeping track of
30 | necessary connection pools for you.
31 |
32 | :param num_pools:
33 | Number of connection pools to cache before discarding the least
34 | recently used pool.
35 |
36 | :param headers:
37 | Headers to include with all requests, unless other headers are given
38 | explicitly.
39 |
40 | :param \**connection_pool_kw:
41 | Additional parameters are used to create fresh
42 | :class:`urllib3.connectionpool.ConnectionPool` instances.
43 |
44 | Example: ::
45 |
46 | >>> manager = PoolManager(num_pools=2)
47 | >>> r = manager.request('GET', 'http://google.com/')
48 | >>> r = manager.request('GET', 'http://google.com/mail')
49 | >>> r = manager.request('GET', 'http://yahoo.com/')
50 | >>> len(manager.pools)
51 | 2
52 |
53 | """
54 |
55 | def __init__(self, num_pools=10, headers=None, **connection_pool_kw):
56 | RequestMethods.__init__(self, headers)
57 | self.connection_pool_kw = connection_pool_kw
58 | self.pools = RecentlyUsedContainer(num_pools,
59 | dispose_func=lambda p: p.close())
60 |
61 | def _new_pool(self, scheme, host, port):
62 | """
63 | Create a new :class:`ConnectionPool` based on host, port and scheme.
64 |
65 | This method is used to actually create the connection pools handed out
66 | by :meth:`connection_from_url` and companion methods. It is intended
67 | to be overridden for customization.
68 | """
69 | pool_cls = pool_classes_by_scheme[scheme]
70 | return pool_cls(host, port, **self.connection_pool_kw)
71 |
72 | def clear(self):
73 | """
74 | Empty our store of pools and direct them all to close.
75 |
76 | This will not affect in-flight connections, but they will not be
77 | re-used after completion.
78 | """
79 | self.pools.clear()
80 |
81 | def connection_from_host(self, host, port=None, scheme='http'):
82 | """
83 | Get a :class:`ConnectionPool` based on the host, port, and scheme.
84 |
85 | If ``port`` isn't given, it will be derived from the ``scheme`` using
86 | ``urllib3.connectionpool.port_by_scheme``.
87 | """
88 | scheme = scheme or 'http'
89 | port = port or port_by_scheme.get(scheme, 80)
90 |
91 | pool_key = (scheme, host, port)
92 |
93 | # If the scheme, host, or port doesn't match existing open connections,
94 | # open a new ConnectionPool.
95 | pool = self.pools.get(pool_key)
96 | if pool:
97 | return pool
98 |
99 | # Make a fresh ConnectionPool of the desired type
100 | pool = self._new_pool(scheme, host, port)
101 | self.pools[pool_key] = pool
102 | return pool
103 |
104 | def connection_from_url(self, url):
105 | """
106 | Similar to :func:`urllib3.connectionpool.connection_from_url` but
107 | doesn't pass any additional parameters to the
108 | :class:`urllib3.connectionpool.ConnectionPool` constructor.
109 |
110 | Additional parameters are taken from the :class:`.PoolManager`
111 | constructor.
112 | """
113 | u = parse_url(url)
114 | return self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
115 |
116 | def urlopen(self, method, url, redirect=True, **kw):
117 | """
118 | Same as :meth:`urllib3.connectionpool.HTTPConnectionPool.urlopen`
119 | with custom cross-host redirect logic and only sends the request-uri
120 | portion of the ``url``.
121 |
122 | The given ``url`` parameter must be absolute, such that an appropriate
123 | :class:`urllib3.connectionpool.ConnectionPool` can be chosen for it.
124 | """
125 | u = parse_url(url)
126 | conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
127 |
128 | kw['assert_same_host'] = False
129 | kw['redirect'] = False
130 | if 'headers' not in kw:
131 | kw['headers'] = self.headers
132 |
133 | response = conn.urlopen(method, u.request_uri, **kw)
134 |
135 | redirect_location = redirect and response.get_redirect_location()
136 | if not redirect_location:
137 | return response
138 |
139 | if response.status == 303:
140 | method = 'GET'
141 |
142 | log.info("Redirecting %s -> %s" % (url, redirect_location))
143 | kw['retries'] = kw.get('retries', 3) - 1 # Persist retries countdown
144 | return self.urlopen(method, redirect_location, **kw)
145 |
146 |
147 | class ProxyManager(RequestMethods):
148 | """
149 | Given a ConnectionPool to a proxy, the ProxyManager's ``urlopen`` method
150 | will make requests to any url through the defined proxy. The ProxyManager
151 | class will automatically set the 'Host' header if it is not provided.
152 | """
153 |
154 | def __init__(self, proxy_pool):
155 | self.proxy_pool = proxy_pool
156 |
157 | def _set_proxy_headers(self, url, headers=None):
158 | """
159 | Sets headers needed by proxies: specifically, the Accept and Host
160 | headers. Only sets headers not provided by the user.
161 | """
162 | headers_ = {'Accept': '*/*'}
163 |
164 | host = parse_url(url).host
165 | if host:
166 | headers_['Host'] = host
167 |
168 | if headers:
169 | headers_.update(headers)
170 |
171 | return headers_
172 |
173 | def urlopen(self, method, url, **kw):
174 | "Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute."
175 | kw['assert_same_host'] = False
176 | kw['headers'] = self._set_proxy_headers(url, headers=kw.get('headers'))
177 | return self.proxy_pool.urlopen(method, url, **kw)
178 |
179 |
180 | def proxy_from_url(url, **pool_kw):
181 | proxy_pool = connection_from_url(url, **pool_kw)
182 | return ProxyManager(proxy_pool)
183 |
--------------------------------------------------------------------------------
/requests/packages/charade/universaldetector.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 2001
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | #
13 | # This library is free software; you can redistribute it and/or
14 | # modify it under the terms of the GNU Lesser General Public
15 | # License as published by the Free Software Foundation; either
16 | # version 2.1 of the License, or (at your option) any later version.
17 | #
18 | # This library is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | # Lesser General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU Lesser General Public
24 | # License along with this library; if not, write to the Free Software
25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 | # 02110-1301 USA
27 | ######################### END LICENSE BLOCK #########################
28 |
29 | from . import constants
30 | import sys
31 | from .latin1prober import Latin1Prober # windows-1252
32 | from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets
33 | from .sbcsgroupprober import SBCSGroupProber # single-byte character sets
34 | from .escprober import EscCharSetProber # ISO-2122, etc.
35 | import re
36 |
37 | MINIMUM_THRESHOLD = 0.20
38 | ePureAscii = 0
39 | eEscAscii = 1
40 | eHighbyte = 2
41 |
42 |
43 | class UniversalDetector:
44 | def __init__(self):
45 | self._highBitDetector = re.compile(b'[\x80-\xFF]')
46 | self._escDetector = re.compile(b'(\033|~{)')
47 | self._mEscCharSetProber = None
48 | self._mCharSetProbers = []
49 | self.reset()
50 |
51 | def reset(self):
52 | self.result = {'encoding': None, 'confidence': 0.0}
53 | self.done = False
54 | self._mStart = True
55 | self._mGotData = False
56 | self._mInputState = ePureAscii
57 | self._mLastChar = b''
58 | if self._mEscCharSetProber:
59 | self._mEscCharSetProber.reset()
60 | for prober in self._mCharSetProbers:
61 | prober.reset()
62 |
63 | def feed(self, aBuf):
64 | if self.done:
65 | return
66 |
67 | aLen = len(aBuf)
68 | if not aLen:
69 | return
70 |
71 | if not self._mGotData:
72 | # If the data starts with BOM, we know it is UTF
73 | if aBuf[:3] == '\xEF\xBB\xBF':
74 | # EF BB BF UTF-8 with BOM
75 | self.result = {'encoding': "UTF-8", 'confidence': 1.0}
76 | elif aBuf[:4] == '\xFF\xFE\x00\x00':
77 | # FF FE 00 00 UTF-32, little-endian BOM
78 | self.result = {'encoding': "UTF-32LE", 'confidence': 1.0}
79 | elif aBuf[:4] == '\x00\x00\xFE\xFF':
80 | # 00 00 FE FF UTF-32, big-endian BOM
81 | self.result = {'encoding': "UTF-32BE", 'confidence': 1.0}
82 | elif aBuf[:4] == '\xFE\xFF\x00\x00':
83 | # FE FF 00 00 UCS-4, unusual octet order BOM (3412)
84 | self.result = {
85 | 'encoding': "X-ISO-10646-UCS-4-3412",
86 | 'confidence': 1.0
87 | }
88 | elif aBuf[:4] == '\x00\x00\xFF\xFE':
89 | # 00 00 FF FE UCS-4, unusual octet order BOM (2143)
90 | self.result = {
91 | 'encoding': "X-ISO-10646-UCS-4-2143",
92 | 'confidence': 1.0
93 | }
94 | elif aBuf[:2] == '\xFF\xFE':
95 | # FF FE UTF-16, little endian BOM
96 | self.result = {'encoding': "UTF-16LE", 'confidence': 1.0}
97 | elif aBuf[:2] == '\xFE\xFF':
98 | # FE FF UTF-16, big endian BOM
99 | self.result = {'encoding': "UTF-16BE", 'confidence': 1.0}
100 |
101 | self._mGotData = True
102 | if self.result['encoding'] and (self.result['confidence'] > 0.0):
103 | self.done = True
104 | return
105 |
106 | if self._mInputState == ePureAscii:
107 | if self._highBitDetector.search(aBuf):
108 | self._mInputState = eHighbyte
109 | elif ((self._mInputState == ePureAscii) and
110 | self._escDetector.search(self._mLastChar + aBuf)):
111 | self._mInputState = eEscAscii
112 |
113 | self._mLastChar = aBuf[-1:]
114 |
115 | if self._mInputState == eEscAscii:
116 | if not self._mEscCharSetProber:
117 | self._mEscCharSetProber = EscCharSetProber()
118 | if self._mEscCharSetProber.feed(aBuf) == constants.eFoundIt:
119 | self.result = {
120 | 'encoding': self._mEscCharSetProber.get_charset_name(),
121 | 'confidence': self._mEscCharSetProber.get_confidence()
122 | }
123 | self.done = True
124 | elif self._mInputState == eHighbyte:
125 | if not self._mCharSetProbers:
126 | self._mCharSetProbers = [MBCSGroupProber(), SBCSGroupProber(),
127 | Latin1Prober()]
128 | for prober in self._mCharSetProbers:
129 | if prober.feed(aBuf) == constants.eFoundIt:
130 | self.result = {'encoding': prober.get_charset_name(),
131 | 'confidence': prober.get_confidence()}
132 | self.done = True
133 | break
134 |
135 | def close(self):
136 | if self.done:
137 | return
138 | if not self._mGotData:
139 | if constants._debug:
140 | sys.stderr.write('no data received!\n')
141 | return
142 | self.done = True
143 |
144 | if self._mInputState == ePureAscii:
145 | self.result = {'encoding': 'ascii', 'confidence': 1.0}
146 | return self.result
147 |
148 | if self._mInputState == eHighbyte:
149 | proberConfidence = None
150 | maxProberConfidence = 0.0
151 | maxProber = None
152 | for prober in self._mCharSetProbers:
153 | if not prober:
154 | continue
155 | proberConfidence = prober.get_confidence()
156 | if proberConfidence > maxProberConfidence:
157 | maxProberConfidence = proberConfidence
158 | maxProber = prober
159 | if maxProber and (maxProberConfidence > MINIMUM_THRESHOLD):
160 | self.result = {'encoding': maxProber.get_charset_name(),
161 | 'confidence': maxProber.get_confidence()}
162 | return self.result
163 |
164 | if constants._debug:
165 | sys.stderr.write('no probers hit minimum threshhold\n')
166 | for prober in self._mCharSetProbers[0].mProbers:
167 | if not prober:
168 | continue
169 | sys.stderr.write('%s confidence = %s\n' %
170 | (prober.get_charset_name(),
171 | prober.get_confidence()))
172 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/response.py:
--------------------------------------------------------------------------------
1 | # urllib3/response.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 | import gzip
8 | import logging
9 | import zlib
10 |
11 | from io import BytesIO
12 |
13 | from .exceptions import DecodeError
14 | from .packages.six import string_types as basestring
15 |
16 |
17 | log = logging.getLogger(__name__)
18 |
19 |
20 | def decode_gzip(data):
21 | gzipper = gzip.GzipFile(fileobj=BytesIO(data))
22 | return gzipper.read()
23 |
24 |
25 | def decode_deflate(data):
26 | try:
27 | return zlib.decompress(data)
28 | except zlib.error:
29 | return zlib.decompress(data, -zlib.MAX_WBITS)
30 |
31 |
32 | class HTTPResponse(object):
33 | """
34 | HTTP Response container.
35 |
36 | Backwards-compatible to httplib's HTTPResponse but the response ``body`` is
37 | loaded and decoded on-demand when the ``data`` property is accessed.
38 |
39 | Extra parameters for behaviour not present in httplib.HTTPResponse:
40 |
41 | :param preload_content:
42 | If True, the response's body will be preloaded during construction.
43 |
44 | :param decode_content:
45 | If True, attempts to decode specific content-encoding's based on headers
46 | (like 'gzip' and 'deflate') will be skipped and raw data will be used
47 | instead.
48 |
49 | :param original_response:
50 | When this HTTPResponse wrapper is generated from an httplib.HTTPResponse
51 | object, it's convenient to include the original for debug purposes. It's
52 | otherwise unused.
53 | """
54 |
55 | CONTENT_DECODERS = {
56 | 'gzip': decode_gzip,
57 | 'deflate': decode_deflate,
58 | }
59 |
60 | def __init__(self, body='', headers=None, status=0, version=0, reason=None,
61 | strict=0, preload_content=True, decode_content=True,
62 | original_response=None, pool=None, connection=None):
63 | self.headers = headers or {}
64 | self.status = status
65 | self.version = version
66 | self.reason = reason
67 | self.strict = strict
68 |
69 | self._decode_content = decode_content
70 | self._body = body if body and isinstance(body, basestring) else None
71 | self._fp = None
72 | self._original_response = original_response
73 |
74 | self._pool = pool
75 | self._connection = connection
76 |
77 | if hasattr(body, 'read'):
78 | self._fp = body
79 |
80 | if preload_content and not self._body:
81 | self._body = self.read(decode_content=decode_content)
82 |
83 | def get_redirect_location(self):
84 | """
85 | Should we redirect and where to?
86 |
87 | :returns: Truthy redirect location string if we got a redirect status
88 | code and valid location. ``None`` if redirect status and no
89 | location. ``False`` if not a redirect status code.
90 | """
91 | if self.status in [301, 302, 303, 307]:
92 | return self.headers.get('location')
93 |
94 | return False
95 |
96 | def release_conn(self):
97 | if not self._pool or not self._connection:
98 | return
99 |
100 | self._pool._put_conn(self._connection)
101 | self._connection = None
102 |
103 | @property
104 | def data(self):
105 | # For backwords-compat with earlier urllib3 0.4 and earlier.
106 | if self._body:
107 | return self._body
108 |
109 | if self._fp:
110 | return self.read(cache_content=True)
111 |
112 | def read(self, amt=None, decode_content=None, cache_content=False):
113 | """
114 | Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
115 | parameters: ``decode_content`` and ``cache_content``.
116 |
117 | :param amt:
118 | How much of the content to read. If specified, decoding and caching
119 | is skipped because we can't decode partial content nor does it make
120 | sense to cache partial content as the full response.
121 |
122 | :param decode_content:
123 | If True, will attempt to decode the body based on the
124 | 'content-encoding' header. (Overridden if ``amt`` is set.)
125 |
126 | :param cache_content:
127 | If True, will save the returned data such that the same result is
128 | returned despite of the state of the underlying file object. This
129 | is useful if you want the ``.data`` property to continue working
130 | after having ``.read()`` the file object. (Overridden if ``amt`` is
131 | set.)
132 | """
133 | # Note: content-encoding value should be case-insensitive, per RFC 2616
134 | # Section 3.5
135 | content_encoding = self.headers.get('content-encoding', '').lower()
136 | decoder = self.CONTENT_DECODERS.get(content_encoding)
137 | if decode_content is None:
138 | decode_content = self._decode_content
139 |
140 | if self._fp is None:
141 | return
142 |
143 | try:
144 | if amt is None:
145 | # cStringIO doesn't like amt=None
146 | data = self._fp.read()
147 | else:
148 | data = self._fp.read(amt)
149 | if amt != 0 and not data: # Platform-specific: Buggy versions of Python.
150 | # Close the connection when no data is returned
151 | #
152 | # This is redundant to what httplib/http.client _should_
153 | # already do. However, versions of python released before
154 | # December 15, 2012 (http://bugs.python.org/issue16298) do not
155 | # properly close the connection in all cases. There is no harm
156 | # in redundantly calling close.
157 | self._fp.close()
158 | return data
159 |
160 | try:
161 | if decode_content and decoder:
162 | data = decoder(data)
163 | except (IOError, zlib.error):
164 | raise DecodeError("Received response with content-encoding: %s, but "
165 | "failed to decode it." % content_encoding)
166 |
167 | if cache_content:
168 | self._body = data
169 |
170 | return data
171 |
172 | finally:
173 | if self._original_response and self._original_response.isclosed():
174 | self.release_conn()
175 |
176 | @classmethod
177 | def from_httplib(ResponseCls, r, **response_kw):
178 | """
179 | Given an :class:`httplib.HTTPResponse` instance ``r``, return a
180 | corresponding :class:`urllib3.response.HTTPResponse` object.
181 |
182 | Remaining parameters are passed to the HTTPResponse constructor, along
183 | with ``original_response=r``.
184 | """
185 |
186 | # Normalize headers between different versions of Python
187 | headers = {}
188 | for k, v in r.getheaders():
189 | # Python 3: Header keys are returned capitalised
190 | k = k.lower()
191 |
192 | has_value = headers.get(k)
193 | if has_value: # Python 3: Repeating header keys are unmerged.
194 | v = ', '.join([has_value, v])
195 |
196 | headers[k] = v
197 |
198 | # HTTPResponse objects in Python 3 don't have a .strict attribute
199 | strict = getattr(r, 'strict', 0)
200 | return ResponseCls(body=r,
201 | headers=headers,
202 | status=r.status,
203 | version=r.version,
204 | reason=r.reason,
205 | strict=strict,
206 | original_response=r,
207 | **response_kw)
208 |
209 | # Backwards-compatibility methods for httplib.HTTPResponse
210 | def getheaders(self):
211 | return self.headers
212 |
213 | def getheader(self, name, default=None):
214 | return self.headers.get(name, default)
215 |
--------------------------------------------------------------------------------
/requests/adapters.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | requests.adapters
5 | ~~~~~~~~~~~~~~~~~
6 |
7 | This module contains the transport adapters that Requests uses to define
8 | and maintain connections.
9 | """
10 |
11 | import socket
12 |
13 | from .models import Response
14 | from .packages.urllib3.poolmanager import PoolManager, ProxyManager
15 | from .packages.urllib3.response import HTTPResponse
16 | from .compat import urlparse, basestring, urldefrag, unquote
17 | from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
18 | prepend_scheme_if_needed, get_auth_from_url)
19 | from .structures import CaseInsensitiveDict
20 | from .packages.urllib3.exceptions import MaxRetryError
21 | from .packages.urllib3.exceptions import TimeoutError
22 | from .packages.urllib3.exceptions import SSLError as _SSLError
23 | from .packages.urllib3.exceptions import HTTPError as _HTTPError
24 | from .cookies import extract_cookies_to_jar
25 | from .exceptions import ConnectionError, Timeout, SSLError
26 | from .auth import _basic_auth_str
27 |
28 | DEFAULT_POOLSIZE = 10
29 | DEFAULT_RETRIES = 0
30 |
31 |
32 | class BaseAdapter(object):
33 | """The Base Transport Adapter"""
34 |
35 | def __init__(self):
36 | super(BaseAdapter, self).__init__()
37 |
38 | def send(self):
39 | raise NotImplementedError
40 |
41 | def close(self):
42 | raise NotImplementedError
43 |
44 |
45 | class HTTPAdapter(BaseAdapter):
46 | """Built-In HTTP Adapter for Urllib3."""
47 | def __init__(self, pool_connections=DEFAULT_POOLSIZE, pool_maxsize=DEFAULT_POOLSIZE):
48 | self.max_retries = DEFAULT_RETRIES
49 | self.config = {}
50 |
51 | super(HTTPAdapter, self).__init__()
52 |
53 | self.init_poolmanager(pool_connections, pool_maxsize)
54 |
55 | def init_poolmanager(self, connections, maxsize):
56 | self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)
57 |
58 | def cert_verify(self, conn, url, verify, cert):
59 | if url.startswith('https') and verify:
60 |
61 | cert_loc = None
62 |
63 | # Allow self-specified cert location.
64 | if verify is not True:
65 | cert_loc = verify
66 |
67 | if not cert_loc:
68 | cert_loc = DEFAULT_CA_BUNDLE_PATH
69 |
70 | if not cert_loc:
71 | raise Exception("Could not find a suitable SSL CA certificate bundle.")
72 |
73 | conn.cert_reqs = 'CERT_REQUIRED'
74 | conn.ca_certs = cert_loc
75 | else:
76 | conn.cert_reqs = 'CERT_NONE'
77 | conn.ca_certs = None
78 |
79 | if cert:
80 | if not isinstance(cert, basestring):
81 | conn.cert_file = cert[0]
82 | conn.key_file = cert[1]
83 | else:
84 | conn.cert_file = cert
85 |
86 | def build_response(self, req, resp):
87 | response = Response()
88 |
89 | # Fallback to None if there's no status_code, for whatever reason.
90 | response.status_code = getattr(resp, 'status', None)
91 |
92 | # Make headers case-insensitive.
93 | response.headers = CaseInsensitiveDict(getattr(resp, 'headers', {}))
94 |
95 | # Set encoding.
96 | response.encoding = get_encoding_from_headers(response.headers)
97 | response.raw = resp
98 | response.reason = response.raw.reason
99 |
100 | if isinstance(req.url, bytes):
101 | response.url = req.url.decode('utf-8')
102 | else:
103 | response.url = req.url
104 |
105 | # Add new cookies from the server.
106 | extract_cookies_to_jar(response.cookies, req, resp)
107 |
108 | # Give the Response some context.
109 | response.request = req
110 | response.connection = self
111 |
112 | return response
113 |
114 | def get_connection(self, url, proxies=None):
115 | """Returns a connection for the given URL."""
116 | proxies = proxies or {}
117 | proxy = proxies.get(urlparse(url).scheme)
118 |
119 | if proxy:
120 | proxy = prepend_scheme_if_needed(proxy, urlparse(url).scheme)
121 | conn = ProxyManager(self.poolmanager.connection_from_url(proxy))
122 | else:
123 | conn = self.poolmanager.connection_from_url(url)
124 |
125 | return conn
126 |
127 | def close(self):
128 | """Dispose of any internal state.
129 |
130 | Currently, this just closes the PoolManager, which closes pooled
131 | connections.
132 | """
133 | self.poolmanager.clear()
134 |
135 | def request_url(self, request, proxies):
136 | """Obtain the url to use when making the final request.
137 |
138 | If the message is being sent through a proxy, the full URL has to be
139 | used. Otherwise, we should only use the path portion of the URL."""
140 | proxies = proxies or {}
141 | proxy = proxies.get(urlparse(request.url).scheme)
142 |
143 | if proxy:
144 | url, _ = urldefrag(request.url)
145 | else:
146 | url = request.path_url
147 |
148 | return url
149 |
150 | def add_headers(self, request, **kwargs):
151 | """Add any headers needed by the connection. Currently this adds a
152 | Proxy-Authorization header."""
153 | proxies = kwargs.get('proxies', {})
154 |
155 | if proxies is None:
156 | proxies = {}
157 |
158 | proxy = proxies.get(urlparse(request.url).scheme)
159 | username, password = get_auth_from_url(proxy)
160 |
161 | if username and password:
162 | # Proxy auth usernames and passwords will be urlencoded, we need
163 | # to decode them.
164 | username = unquote(username)
165 | password = unquote(password)
166 | request.headers['Proxy-Authorization'] = _basic_auth_str(username,
167 | password)
168 |
169 | def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
170 | """Sends PreparedRequest object. Returns Response object."""
171 |
172 | conn = self.get_connection(request.url, proxies)
173 |
174 | self.cert_verify(conn, request.url, verify, cert)
175 | url = self.request_url(request, proxies)
176 | self.add_headers(request, proxies=proxies)
177 |
178 | chunked = not (request.body is None or 'Content-Length' in request.headers)
179 |
180 | try:
181 | if not chunked:
182 | resp = conn.urlopen(
183 | method=request.method,
184 | url=url,
185 | body=request.body,
186 | headers=request.headers,
187 | redirect=False,
188 | assert_same_host=False,
189 | preload_content=False,
190 | decode_content=False,
191 | retries=self.max_retries,
192 | timeout=timeout
193 | )
194 |
195 | # Send the request.
196 | else:
197 | if hasattr(conn, 'proxy_pool'):
198 | conn = conn.proxy_pool
199 |
200 | low_conn = conn._get_conn(timeout=timeout)
201 | low_conn.putrequest(request.method, url, skip_accept_encoding=True)
202 |
203 | for header, value in request.headers.items():
204 | low_conn.putheader(header, value)
205 |
206 | low_conn.endheaders()
207 |
208 | for i in request.body:
209 | low_conn.send(hex(len(i))[2:].encode('utf-8'))
210 | low_conn.send(b'\r\n')
211 | low_conn.send(i)
212 | low_conn.send(b'\r\n')
213 | low_conn.send(b'0\r\n\r\n')
214 |
215 | r = low_conn.getresponse()
216 | resp = HTTPResponse.from_httplib(r,
217 | pool=conn,
218 | connection=low_conn,
219 | preload_content=False,
220 | decode_content=False
221 | )
222 |
223 | except socket.error as sockerr:
224 | raise ConnectionError(sockerr)
225 |
226 | except MaxRetryError as e:
227 | raise ConnectionError(e)
228 |
229 | except (_SSLError, _HTTPError) as e:
230 | if isinstance(e, _SSLError):
231 | raise SSLError(e)
232 | elif isinstance(e, TimeoutError):
233 | raise Timeout(e)
234 | else:
235 | raise
236 |
237 | r = self.build_response(request, resp)
238 |
239 | if not stream:
240 | r.content
241 |
242 | return r
243 |
--------------------------------------------------------------------------------
/requests/packages/charade/escsm.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is mozilla.org code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .constants import eStart, eError, eItsMe
29 |
30 | HZ_cls = (
31 | 1,0,0,0,0,0,0,0, # 00 - 07
32 | 0,0,0,0,0,0,0,0, # 08 - 0f
33 | 0,0,0,0,0,0,0,0, # 10 - 17
34 | 0,0,0,1,0,0,0,0, # 18 - 1f
35 | 0,0,0,0,0,0,0,0, # 20 - 27
36 | 0,0,0,0,0,0,0,0, # 28 - 2f
37 | 0,0,0,0,0,0,0,0, # 30 - 37
38 | 0,0,0,0,0,0,0,0, # 38 - 3f
39 | 0,0,0,0,0,0,0,0, # 40 - 47
40 | 0,0,0,0,0,0,0,0, # 48 - 4f
41 | 0,0,0,0,0,0,0,0, # 50 - 57
42 | 0,0,0,0,0,0,0,0, # 58 - 5f
43 | 0,0,0,0,0,0,0,0, # 60 - 67
44 | 0,0,0,0,0,0,0,0, # 68 - 6f
45 | 0,0,0,0,0,0,0,0, # 70 - 77
46 | 0,0,0,4,0,5,2,0, # 78 - 7f
47 | 1,1,1,1,1,1,1,1, # 80 - 87
48 | 1,1,1,1,1,1,1,1, # 88 - 8f
49 | 1,1,1,1,1,1,1,1, # 90 - 97
50 | 1,1,1,1,1,1,1,1, # 98 - 9f
51 | 1,1,1,1,1,1,1,1, # a0 - a7
52 | 1,1,1,1,1,1,1,1, # a8 - af
53 | 1,1,1,1,1,1,1,1, # b0 - b7
54 | 1,1,1,1,1,1,1,1, # b8 - bf
55 | 1,1,1,1,1,1,1,1, # c0 - c7
56 | 1,1,1,1,1,1,1,1, # c8 - cf
57 | 1,1,1,1,1,1,1,1, # d0 - d7
58 | 1,1,1,1,1,1,1,1, # d8 - df
59 | 1,1,1,1,1,1,1,1, # e0 - e7
60 | 1,1,1,1,1,1,1,1, # e8 - ef
61 | 1,1,1,1,1,1,1,1, # f0 - f7
62 | 1,1,1,1,1,1,1,1, # f8 - ff
63 | )
64 |
65 | HZ_st = (
66 | eStart,eError, 3,eStart,eStart,eStart,eError,eError,# 00-07
67 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 08-0f
68 | eItsMe,eItsMe,eError,eError,eStart,eStart, 4,eError,# 10-17
69 | 5,eError, 6,eError, 5, 5, 4,eError,# 18-1f
70 | 4,eError, 4, 4, 4,eError, 4,eError,# 20-27
71 | 4,eItsMe,eStart,eStart,eStart,eStart,eStart,eStart,# 28-2f
72 | )
73 |
74 | HZCharLenTable = (0, 0, 0, 0, 0, 0)
75 |
76 | HZSMModel = {'classTable': HZ_cls,
77 | 'classFactor': 6,
78 | 'stateTable': HZ_st,
79 | 'charLenTable': HZCharLenTable,
80 | 'name': "HZ-GB-2312"}
81 |
82 | ISO2022CN_cls = (
83 | 2,0,0,0,0,0,0,0, # 00 - 07
84 | 0,0,0,0,0,0,0,0, # 08 - 0f
85 | 0,0,0,0,0,0,0,0, # 10 - 17
86 | 0,0,0,1,0,0,0,0, # 18 - 1f
87 | 0,0,0,0,0,0,0,0, # 20 - 27
88 | 0,3,0,0,0,0,0,0, # 28 - 2f
89 | 0,0,0,0,0,0,0,0, # 30 - 37
90 | 0,0,0,0,0,0,0,0, # 38 - 3f
91 | 0,0,0,4,0,0,0,0, # 40 - 47
92 | 0,0,0,0,0,0,0,0, # 48 - 4f
93 | 0,0,0,0,0,0,0,0, # 50 - 57
94 | 0,0,0,0,0,0,0,0, # 58 - 5f
95 | 0,0,0,0,0,0,0,0, # 60 - 67
96 | 0,0,0,0,0,0,0,0, # 68 - 6f
97 | 0,0,0,0,0,0,0,0, # 70 - 77
98 | 0,0,0,0,0,0,0,0, # 78 - 7f
99 | 2,2,2,2,2,2,2,2, # 80 - 87
100 | 2,2,2,2,2,2,2,2, # 88 - 8f
101 | 2,2,2,2,2,2,2,2, # 90 - 97
102 | 2,2,2,2,2,2,2,2, # 98 - 9f
103 | 2,2,2,2,2,2,2,2, # a0 - a7
104 | 2,2,2,2,2,2,2,2, # a8 - af
105 | 2,2,2,2,2,2,2,2, # b0 - b7
106 | 2,2,2,2,2,2,2,2, # b8 - bf
107 | 2,2,2,2,2,2,2,2, # c0 - c7
108 | 2,2,2,2,2,2,2,2, # c8 - cf
109 | 2,2,2,2,2,2,2,2, # d0 - d7
110 | 2,2,2,2,2,2,2,2, # d8 - df
111 | 2,2,2,2,2,2,2,2, # e0 - e7
112 | 2,2,2,2,2,2,2,2, # e8 - ef
113 | 2,2,2,2,2,2,2,2, # f0 - f7
114 | 2,2,2,2,2,2,2,2, # f8 - ff
115 | )
116 |
117 | ISO2022CN_st = (
118 | eStart, 3,eError,eStart,eStart,eStart,eStart,eStart,# 00-07
119 | eStart,eError,eError,eError,eError,eError,eError,eError,# 08-0f
120 | eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,# 10-17
121 | eItsMe,eItsMe,eItsMe,eError,eError,eError, 4,eError,# 18-1f
122 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 20-27
123 | 5, 6,eError,eError,eError,eError,eError,eError,# 28-2f
124 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 30-37
125 | eError,eError,eError,eError,eError,eItsMe,eError,eStart,# 38-3f
126 | )
127 |
128 | ISO2022CNCharLenTable = (0, 0, 0, 0, 0, 0, 0, 0, 0)
129 |
130 | ISO2022CNSMModel = {'classTable': ISO2022CN_cls,
131 | 'classFactor': 9,
132 | 'stateTable': ISO2022CN_st,
133 | 'charLenTable': ISO2022CNCharLenTable,
134 | 'name': "ISO-2022-CN"}
135 |
136 | ISO2022JP_cls = (
137 | 2,0,0,0,0,0,0,0, # 00 - 07
138 | 0,0,0,0,0,0,2,2, # 08 - 0f
139 | 0,0,0,0,0,0,0,0, # 10 - 17
140 | 0,0,0,1,0,0,0,0, # 18 - 1f
141 | 0,0,0,0,7,0,0,0, # 20 - 27
142 | 3,0,0,0,0,0,0,0, # 28 - 2f
143 | 0,0,0,0,0,0,0,0, # 30 - 37
144 | 0,0,0,0,0,0,0,0, # 38 - 3f
145 | 6,0,4,0,8,0,0,0, # 40 - 47
146 | 0,9,5,0,0,0,0,0, # 48 - 4f
147 | 0,0,0,0,0,0,0,0, # 50 - 57
148 | 0,0,0,0,0,0,0,0, # 58 - 5f
149 | 0,0,0,0,0,0,0,0, # 60 - 67
150 | 0,0,0,0,0,0,0,0, # 68 - 6f
151 | 0,0,0,0,0,0,0,0, # 70 - 77
152 | 0,0,0,0,0,0,0,0, # 78 - 7f
153 | 2,2,2,2,2,2,2,2, # 80 - 87
154 | 2,2,2,2,2,2,2,2, # 88 - 8f
155 | 2,2,2,2,2,2,2,2, # 90 - 97
156 | 2,2,2,2,2,2,2,2, # 98 - 9f
157 | 2,2,2,2,2,2,2,2, # a0 - a7
158 | 2,2,2,2,2,2,2,2, # a8 - af
159 | 2,2,2,2,2,2,2,2, # b0 - b7
160 | 2,2,2,2,2,2,2,2, # b8 - bf
161 | 2,2,2,2,2,2,2,2, # c0 - c7
162 | 2,2,2,2,2,2,2,2, # c8 - cf
163 | 2,2,2,2,2,2,2,2, # d0 - d7
164 | 2,2,2,2,2,2,2,2, # d8 - df
165 | 2,2,2,2,2,2,2,2, # e0 - e7
166 | 2,2,2,2,2,2,2,2, # e8 - ef
167 | 2,2,2,2,2,2,2,2, # f0 - f7
168 | 2,2,2,2,2,2,2,2, # f8 - ff
169 | )
170 |
171 | ISO2022JP_st = (
172 | eStart, 3,eError,eStart,eStart,eStart,eStart,eStart,# 00-07
173 | eStart,eStart,eError,eError,eError,eError,eError,eError,# 08-0f
174 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 10-17
175 | eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eError,eError,# 18-1f
176 | eError, 5,eError,eError,eError, 4,eError,eError,# 20-27
177 | eError,eError,eError, 6,eItsMe,eError,eItsMe,eError,# 28-2f
178 | eError,eError,eError,eError,eError,eError,eItsMe,eItsMe,# 30-37
179 | eError,eError,eError,eItsMe,eError,eError,eError,eError,# 38-3f
180 | eError,eError,eError,eError,eItsMe,eError,eStart,eStart,# 40-47
181 | )
182 |
183 | ISO2022JPCharLenTable = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
184 |
185 | ISO2022JPSMModel = {'classTable': ISO2022JP_cls,
186 | 'classFactor': 10,
187 | 'stateTable': ISO2022JP_st,
188 | 'charLenTable': ISO2022JPCharLenTable,
189 | 'name': "ISO-2022-JP"}
190 |
191 | ISO2022KR_cls = (
192 | 2,0,0,0,0,0,0,0, # 00 - 07
193 | 0,0,0,0,0,0,0,0, # 08 - 0f
194 | 0,0,0,0,0,0,0,0, # 10 - 17
195 | 0,0,0,1,0,0,0,0, # 18 - 1f
196 | 0,0,0,0,3,0,0,0, # 20 - 27
197 | 0,4,0,0,0,0,0,0, # 28 - 2f
198 | 0,0,0,0,0,0,0,0, # 30 - 37
199 | 0,0,0,0,0,0,0,0, # 38 - 3f
200 | 0,0,0,5,0,0,0,0, # 40 - 47
201 | 0,0,0,0,0,0,0,0, # 48 - 4f
202 | 0,0,0,0,0,0,0,0, # 50 - 57
203 | 0,0,0,0,0,0,0,0, # 58 - 5f
204 | 0,0,0,0,0,0,0,0, # 60 - 67
205 | 0,0,0,0,0,0,0,0, # 68 - 6f
206 | 0,0,0,0,0,0,0,0, # 70 - 77
207 | 0,0,0,0,0,0,0,0, # 78 - 7f
208 | 2,2,2,2,2,2,2,2, # 80 - 87
209 | 2,2,2,2,2,2,2,2, # 88 - 8f
210 | 2,2,2,2,2,2,2,2, # 90 - 97
211 | 2,2,2,2,2,2,2,2, # 98 - 9f
212 | 2,2,2,2,2,2,2,2, # a0 - a7
213 | 2,2,2,2,2,2,2,2, # a8 - af
214 | 2,2,2,2,2,2,2,2, # b0 - b7
215 | 2,2,2,2,2,2,2,2, # b8 - bf
216 | 2,2,2,2,2,2,2,2, # c0 - c7
217 | 2,2,2,2,2,2,2,2, # c8 - cf
218 | 2,2,2,2,2,2,2,2, # d0 - d7
219 | 2,2,2,2,2,2,2,2, # d8 - df
220 | 2,2,2,2,2,2,2,2, # e0 - e7
221 | 2,2,2,2,2,2,2,2, # e8 - ef
222 | 2,2,2,2,2,2,2,2, # f0 - f7
223 | 2,2,2,2,2,2,2,2, # f8 - ff
224 | )
225 |
226 | ISO2022KR_st = (
227 | eStart, 3,eError,eStart,eStart,eStart,eError,eError,# 00-07
228 | eError,eError,eError,eError,eItsMe,eItsMe,eItsMe,eItsMe,# 08-0f
229 | eItsMe,eItsMe,eError,eError,eError, 4,eError,eError,# 10-17
230 | eError,eError,eError,eError, 5,eError,eError,eError,# 18-1f
231 | eError,eError,eError,eItsMe,eStart,eStart,eStart,eStart,# 20-27
232 | )
233 |
234 | ISO2022KRCharLenTable = (0, 0, 0, 0, 0, 0)
235 |
236 | ISO2022KRSMModel = {'classTable': ISO2022KR_cls,
237 | 'classFactor': 6,
238 | 'stateTable': ISO2022KR_st,
239 | 'charLenTable': ISO2022KRCharLenTable,
240 | 'name': "ISO-2022-KR"}
241 |
242 | # flake8: noqa
243 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/packages/ordered_dict.py:
--------------------------------------------------------------------------------
1 | # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
2 | # Passes Python2.7's test suite and incorporates all the latest updates.
3 | # Copyright 2009 Raymond Hettinger, released under the MIT License.
4 | # http://code.activestate.com/recipes/576693/
5 |
6 | try:
7 | from thread import get_ident as _get_ident
8 | except ImportError:
9 | from dummy_thread import get_ident as _get_ident
10 |
11 | try:
12 | from _abcoll import KeysView, ValuesView, ItemsView
13 | except ImportError:
14 | pass
15 |
16 |
17 | class OrderedDict(dict):
18 | 'Dictionary that remembers insertion order'
19 | # An inherited dict maps keys to values.
20 | # The inherited dict provides __getitem__, __len__, __contains__, and get.
21 | # The remaining methods are order-aware.
22 | # Big-O running times for all methods are the same as for regular dictionaries.
23 |
24 | # The internal self.__map dictionary maps keys to links in a doubly linked list.
25 | # The circular doubly linked list starts and ends with a sentinel element.
26 | # The sentinel element never gets deleted (this simplifies the algorithm).
27 | # Each link is stored as a list of length three: [PREV, NEXT, KEY].
28 |
29 | def __init__(self, *args, **kwds):
30 | '''Initialize an ordered dictionary. Signature is the same as for
31 | regular dictionaries, but keyword arguments are not recommended
32 | because their insertion order is arbitrary.
33 |
34 | '''
35 | if len(args) > 1:
36 | raise TypeError('expected at most 1 arguments, got %d' % len(args))
37 | try:
38 | self.__root
39 | except AttributeError:
40 | self.__root = root = [] # sentinel node
41 | root[:] = [root, root, None]
42 | self.__map = {}
43 | self.__update(*args, **kwds)
44 |
45 | def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
46 | 'od.__setitem__(i, y) <==> od[i]=y'
47 | # Setting a new item creates a new link which goes at the end of the linked
48 | # list, and the inherited dictionary is updated with the new key/value pair.
49 | if key not in self:
50 | root = self.__root
51 | last = root[0]
52 | last[1] = root[0] = self.__map[key] = [last, root, key]
53 | dict_setitem(self, key, value)
54 |
55 | def __delitem__(self, key, dict_delitem=dict.__delitem__):
56 | 'od.__delitem__(y) <==> del od[y]'
57 | # Deleting an existing item uses self.__map to find the link which is
58 | # then removed by updating the links in the predecessor and successor nodes.
59 | dict_delitem(self, key)
60 | link_prev, link_next, key = self.__map.pop(key)
61 | link_prev[1] = link_next
62 | link_next[0] = link_prev
63 |
64 | def __iter__(self):
65 | 'od.__iter__() <==> iter(od)'
66 | root = self.__root
67 | curr = root[1]
68 | while curr is not root:
69 | yield curr[2]
70 | curr = curr[1]
71 |
72 | def __reversed__(self):
73 | 'od.__reversed__() <==> reversed(od)'
74 | root = self.__root
75 | curr = root[0]
76 | while curr is not root:
77 | yield curr[2]
78 | curr = curr[0]
79 |
80 | def clear(self):
81 | 'od.clear() -> None. Remove all items from od.'
82 | try:
83 | for node in self.__map.itervalues():
84 | del node[:]
85 | root = self.__root
86 | root[:] = [root, root, None]
87 | self.__map.clear()
88 | except AttributeError:
89 | pass
90 | dict.clear(self)
91 |
92 | def popitem(self, last=True):
93 | '''od.popitem() -> (k, v), return and remove a (key, value) pair.
94 | Pairs are returned in LIFO order if last is true or FIFO order if false.
95 |
96 | '''
97 | if not self:
98 | raise KeyError('dictionary is empty')
99 | root = self.__root
100 | if last:
101 | link = root[0]
102 | link_prev = link[0]
103 | link_prev[1] = root
104 | root[0] = link_prev
105 | else:
106 | link = root[1]
107 | link_next = link[1]
108 | root[1] = link_next
109 | link_next[0] = root
110 | key = link[2]
111 | del self.__map[key]
112 | value = dict.pop(self, key)
113 | return key, value
114 |
115 | # -- the following methods do not depend on the internal structure --
116 |
117 | def keys(self):
118 | 'od.keys() -> list of keys in od'
119 | return list(self)
120 |
121 | def values(self):
122 | 'od.values() -> list of values in od'
123 | return [self[key] for key in self]
124 |
125 | def items(self):
126 | 'od.items() -> list of (key, value) pairs in od'
127 | return [(key, self[key]) for key in self]
128 |
129 | def iterkeys(self):
130 | 'od.iterkeys() -> an iterator over the keys in od'
131 | return iter(self)
132 |
133 | def itervalues(self):
134 | 'od.itervalues -> an iterator over the values in od'
135 | for k in self:
136 | yield self[k]
137 |
138 | def iteritems(self):
139 | 'od.iteritems -> an iterator over the (key, value) items in od'
140 | for k in self:
141 | yield (k, self[k])
142 |
143 | def update(*args, **kwds):
144 | '''od.update(E, **F) -> None. Update od from dict/iterable E and F.
145 |
146 | If E is a dict instance, does: for k in E: od[k] = E[k]
147 | If E has a .keys() method, does: for k in E.keys(): od[k] = E[k]
148 | Or if E is an iterable of items, does: for k, v in E: od[k] = v
149 | In either case, this is followed by: for k, v in F.items(): od[k] = v
150 |
151 | '''
152 | if len(args) > 2:
153 | raise TypeError('update() takes at most 2 positional '
154 | 'arguments (%d given)' % (len(args),))
155 | elif not args:
156 | raise TypeError('update() takes at least 1 argument (0 given)')
157 | self = args[0]
158 | # Make progressively weaker assumptions about "other"
159 | other = ()
160 | if len(args) == 2:
161 | other = args[1]
162 | if isinstance(other, dict):
163 | for key in other:
164 | self[key] = other[key]
165 | elif hasattr(other, 'keys'):
166 | for key in other.keys():
167 | self[key] = other[key]
168 | else:
169 | for key, value in other:
170 | self[key] = value
171 | for key, value in kwds.items():
172 | self[key] = value
173 |
174 | __update = update # let subclasses override update without breaking __init__
175 |
176 | __marker = object()
177 |
178 | def pop(self, key, default=__marker):
179 | '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
180 | If key is not found, d is returned if given, otherwise KeyError is raised.
181 |
182 | '''
183 | if key in self:
184 | result = self[key]
185 | del self[key]
186 | return result
187 | if default is self.__marker:
188 | raise KeyError(key)
189 | return default
190 |
191 | def setdefault(self, key, default=None):
192 | 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
193 | if key in self:
194 | return self[key]
195 | self[key] = default
196 | return default
197 |
198 | def __repr__(self, _repr_running={}):
199 | 'od.__repr__() <==> repr(od)'
200 | call_key = id(self), _get_ident()
201 | if call_key in _repr_running:
202 | return '...'
203 | _repr_running[call_key] = 1
204 | try:
205 | if not self:
206 | return '%s()' % (self.__class__.__name__,)
207 | return '%s(%r)' % (self.__class__.__name__, self.items())
208 | finally:
209 | del _repr_running[call_key]
210 |
211 | def __reduce__(self):
212 | 'Return state information for pickling'
213 | items = [[k, self[k]] for k in self]
214 | inst_dict = vars(self).copy()
215 | for k in vars(OrderedDict()):
216 | inst_dict.pop(k, None)
217 | if inst_dict:
218 | return (self.__class__, (items,), inst_dict)
219 | return self.__class__, (items,)
220 |
221 | def copy(self):
222 | 'od.copy() -> a shallow copy of od'
223 | return self.__class__(self)
224 |
225 | @classmethod
226 | def fromkeys(cls, iterable, value=None):
227 | '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
228 | and values equal to v (which defaults to None).
229 |
230 | '''
231 | d = cls()
232 | for key in iterable:
233 | d[key] = value
234 | return d
235 |
236 | def __eq__(self, other):
237 | '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
238 | while comparison to a regular mapping is order-insensitive.
239 |
240 | '''
241 | if isinstance(other, OrderedDict):
242 | return len(self)==len(other) and self.items() == other.items()
243 | return dict.__eq__(self, other)
244 |
245 | def __ne__(self, other):
246 | return not self == other
247 |
248 | # -- the following methods are only used in Python 2.7 --
249 |
250 | def viewkeys(self):
251 | "od.viewkeys() -> a set-like object providing a view on od's keys"
252 | return KeysView(self)
253 |
254 | def viewvalues(self):
255 | "od.viewvalues() -> an object providing a view on od's values"
256 | return ValuesView(self)
257 |
258 | def viewitems(self):
259 | "od.viewitems() -> a set-like object providing a view on od's items"
260 | return ItemsView(self)
261 |
--------------------------------------------------------------------------------
/requests/packages/charade/chardistribution.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Communicator client code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | from .euctwfreq import (EUCTWCharToFreqOrder, EUCTW_TABLE_SIZE,
29 | EUCTW_TYPICAL_DISTRIBUTION_RATIO)
30 | from .euckrfreq import (EUCKRCharToFreqOrder, EUCKR_TABLE_SIZE,
31 | EUCKR_TYPICAL_DISTRIBUTION_RATIO)
32 | from .gb2312freq import (GB2312CharToFreqOrder, GB2312_TABLE_SIZE,
33 | GB2312_TYPICAL_DISTRIBUTION_RATIO)
34 | from .big5freq import (Big5CharToFreqOrder, BIG5_TABLE_SIZE,
35 | BIG5_TYPICAL_DISTRIBUTION_RATIO)
36 | from .jisfreq import (JISCharToFreqOrder, JIS_TABLE_SIZE,
37 | JIS_TYPICAL_DISTRIBUTION_RATIO)
38 | from .compat import wrap_ord
39 |
40 | ENOUGH_DATA_THRESHOLD = 1024
41 | SURE_YES = 0.99
42 | SURE_NO = 0.01
43 |
44 |
45 | class CharDistributionAnalysis:
46 | def __init__(self):
47 | # Mapping table to get frequency order from char order (get from
48 | # GetOrder())
49 | self._mCharToFreqOrder = None
50 | self._mTableSize = None # Size of above table
51 | # This is a constant value which varies from language to language,
52 | # used in calculating confidence. See
53 | # http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
54 | # for further detail.
55 | self._mTypicalDistributionRatio = None
56 | self.reset()
57 |
58 | def reset(self):
59 | """reset analyser, clear any state"""
60 | # If this flag is set to True, detection is done and conclusion has
61 | # been made
62 | self._mDone = False
63 | self._mTotalChars = 0 # Total characters encountered
64 | # The number of characters whose frequency order is less than 512
65 | self._mFreqChars = 0
66 |
67 | def feed(self, aBuf, aCharLen):
68 | """feed a character with known length"""
69 | if aCharLen == 2:
70 | # we only care about 2-bytes character in our distribution analysis
71 | order = self.get_order(aBuf)
72 | else:
73 | order = -1
74 | if order >= 0:
75 | self._mTotalChars += 1
76 | # order is valid
77 | if order < self._mTableSize:
78 | if 512 > self._mCharToFreqOrder[order]:
79 | self._mFreqChars += 1
80 |
81 | def get_confidence(self):
82 | """return confidence based on existing data"""
83 | # if we didn't receive any character in our consideration range,
84 | # return negative answer
85 | if self._mTotalChars <= 0:
86 | return SURE_NO
87 |
88 | if self._mTotalChars != self._mFreqChars:
89 | r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)
90 | * self._mTypicalDistributionRatio))
91 | if r < SURE_YES:
92 | return r
93 |
94 | # normalize confidence (we don't want to be 100% sure)
95 | return SURE_YES
96 |
97 | def got_enough_data(self):
98 | # It is not necessary to receive all data to draw conclusion.
99 | # For charset detection, certain amount of data is enough
100 | return self._mTotalChars > ENOUGH_DATA_THRESHOLD
101 |
102 | def get_order(self, aBuf):
103 | # We do not handle characters based on the original encoding string,
104 | # but convert this encoding string to a number, here called order.
105 | # This allows multiple encodings of a language to share one frequency
106 | # table.
107 | return -1
108 |
109 |
110 | class EUCTWDistributionAnalysis(CharDistributionAnalysis):
111 | def __init__(self):
112 | CharDistributionAnalysis.__init__(self)
113 | self._mCharToFreqOrder = EUCTWCharToFreqOrder
114 | self._mTableSize = EUCTW_TABLE_SIZE
115 | self._mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
116 |
117 | def get_order(self, aBuf):
118 | # for euc-TW encoding, we are interested
119 | # first byte range: 0xc4 -- 0xfe
120 | # second byte range: 0xa1 -- 0xfe
121 | # no validation needed here. State machine has done that
122 | first_char = wrap_ord(aBuf[0])
123 | if first_char >= 0xC4:
124 | return 94 * (first_char - 0xC4) + wrap_ord(aBuf[1]) - 0xA1
125 | else:
126 | return -1
127 |
128 |
129 | class EUCKRDistributionAnalysis(CharDistributionAnalysis):
130 | def __init__(self):
131 | CharDistributionAnalysis.__init__(self)
132 | self._mCharToFreqOrder = EUCKRCharToFreqOrder
133 | self._mTableSize = EUCKR_TABLE_SIZE
134 | self._mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
135 |
136 | def get_order(self, aBuf):
137 | # for euc-KR encoding, we are interested
138 | # first byte range: 0xb0 -- 0xfe
139 | # second byte range: 0xa1 -- 0xfe
140 | # no validation needed here. State machine has done that
141 | first_char = wrap_ord(aBuf[0])
142 | if first_char >= 0xB0:
143 | return 94 * (first_char - 0xB0) + wrap_ord(aBuf[1]) - 0xA1
144 | else:
145 | return -1
146 |
147 |
148 | class GB2312DistributionAnalysis(CharDistributionAnalysis):
149 | def __init__(self):
150 | CharDistributionAnalysis.__init__(self)
151 | self._mCharToFreqOrder = GB2312CharToFreqOrder
152 | self._mTableSize = GB2312_TABLE_SIZE
153 | self._mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO
154 |
155 | def get_order(self, aBuf):
156 | # for GB2312 encoding, we are interested
157 | # first byte range: 0xb0 -- 0xfe
158 | # second byte range: 0xa1 -- 0xfe
159 | # no validation needed here. State machine has done that
160 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
161 | if (first_char >= 0xB0) and (second_char >= 0xA1):
162 | return 94 * (first_char - 0xB0) + second_char - 0xA1
163 | else:
164 | return -1
165 |
166 |
167 | class Big5DistributionAnalysis(CharDistributionAnalysis):
168 | def __init__(self):
169 | CharDistributionAnalysis.__init__(self)
170 | self._mCharToFreqOrder = Big5CharToFreqOrder
171 | self._mTableSize = BIG5_TABLE_SIZE
172 | self._mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
173 |
174 | def get_order(self, aBuf):
175 | # for big5 encoding, we are interested
176 | # first byte range: 0xa4 -- 0xfe
177 | # second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
178 | # no validation needed here. State machine has done that
179 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
180 | if first_char >= 0xA4:
181 | if second_char >= 0xA1:
182 | return 157 * (first_char - 0xA4) + second_char - 0xA1 + 63
183 | else:
184 | return 157 * (first_char - 0xA4) + second_char - 0x40
185 | else:
186 | return -1
187 |
188 |
189 | class SJISDistributionAnalysis(CharDistributionAnalysis):
190 | def __init__(self):
191 | CharDistributionAnalysis.__init__(self)
192 | self._mCharToFreqOrder = JISCharToFreqOrder
193 | self._mTableSize = JIS_TABLE_SIZE
194 | self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
195 |
196 | def get_order(self, aBuf):
197 | # for sjis encoding, we are interested
198 | # first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
199 | # second byte range: 0x40 -- 0x7e, 0x81 -- oxfe
200 | # no validation needed here. State machine has done that
201 | first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
202 | if (first_char >= 0x81) and (first_char <= 0x9F):
203 | order = 188 * (first_char - 0x81)
204 | elif (first_char >= 0xE0) and (first_char <= 0xEF):
205 | order = 188 * (first_char - 0xE0 + 31)
206 | else:
207 | return -1
208 | order = order + second_char - 0x40
209 | if second_char > 0x7F:
210 | order = -1
211 | return order
212 |
213 |
214 | class EUCJPDistributionAnalysis(CharDistributionAnalysis):
215 | def __init__(self):
216 | CharDistributionAnalysis.__init__(self)
217 | self._mCharToFreqOrder = JISCharToFreqOrder
218 | self._mTableSize = JIS_TABLE_SIZE
219 | self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
220 |
221 | def get_order(self, aBuf):
222 | # for euc-JP encoding, we are interested
223 | # first byte range: 0xa0 -- 0xfe
224 | # second byte range: 0xa1 -- 0xfe
225 | # no validation needed here. State machine has done that
226 | char = wrap_ord(aBuf[0])
227 | if char >= 0xA0:
228 | return 94 * (char - 0xA1) + wrap_ord(aBuf[1]) - 0xa1
229 | else:
230 | return -1
231 |
--------------------------------------------------------------------------------
/requests/packages/urllib3/util.py:
--------------------------------------------------------------------------------
1 | # urllib3/util.py
2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3 | #
4 | # This module is part of urllib3 and is released under
5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php
6 |
7 |
8 | from base64 import b64encode
9 | from collections import namedtuple
10 | from socket import error as SocketError
11 |
12 | try:
13 | from select import poll, POLLIN
14 | except ImportError: # `poll` doesn't exist on OSX and other platforms
15 | poll = False
16 | try:
17 | from select import select
18 | except ImportError: # `select` doesn't exist on AppEngine.
19 | select = False
20 |
21 | try: # Test for SSL features
22 | SSLContext = None
23 | HAS_SNI = False
24 |
25 | import ssl
26 | from ssl import wrap_socket, CERT_NONE, SSLError, PROTOCOL_SSLv23
27 | from ssl import SSLContext # Modern SSL?
28 | from ssl import HAS_SNI # Has SNI?
29 | except ImportError:
30 | pass
31 |
32 |
33 | from .packages import six
34 | from .exceptions import LocationParseError
35 |
36 |
37 | class Url(namedtuple('Url', ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment'])):
38 | """
39 | Datastructure for representing an HTTP URL. Used as a return value for
40 | :func:`parse_url`.
41 | """
42 | slots = ()
43 |
44 | def __new__(cls, scheme=None, auth=None, host=None, port=None, path=None, query=None, fragment=None):
45 | return super(Url, cls).__new__(cls, scheme, auth, host, port, path, query, fragment)
46 |
47 | @property
48 | def hostname(self):
49 | """For backwards-compatibility with urlparse. We're nice like that."""
50 | return self.host
51 |
52 | @property
53 | def request_uri(self):
54 | """Absolute path including the query string."""
55 | uri = self.path or '/'
56 |
57 | if self.query is not None:
58 | uri += '?' + self.query
59 |
60 | return uri
61 |
62 |
63 | def split_first(s, delims):
64 | """
65 | Given a string and an iterable of delimiters, split on the first found
66 | delimiter. Return two split parts and the matched delimiter.
67 |
68 | If not found, then the first part is the full input string.
69 |
70 | Example: ::
71 |
72 | >>> split_first('foo/bar?baz', '?/=')
73 | ('foo', 'bar?baz', '/')
74 | >>> split_first('foo/bar?baz', '123')
75 | ('foo/bar?baz', '', None)
76 |
77 | Scales linearly with number of delims. Not ideal for large number of delims.
78 | """
79 | min_idx = None
80 | min_delim = None
81 | for d in delims:
82 | idx = s.find(d)
83 | if idx < 0:
84 | continue
85 |
86 | if min_idx is None or idx < min_idx:
87 | min_idx = idx
88 | min_delim = d
89 |
90 | if min_idx is None or min_idx < 0:
91 | return s, '', None
92 |
93 | return s[:min_idx], s[min_idx+1:], min_delim
94 |
95 |
96 | def parse_url(url):
97 | """
98 | Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
99 | performed to parse incomplete urls. Fields not provided will be None.
100 |
101 | Partly backwards-compatible with :mod:`urlparse`.
102 |
103 | Example: ::
104 |
105 | >>> parse_url('http://google.com/mail/')
106 | Url(scheme='http', host='google.com', port=None, path='/', ...)
107 | >>> parse_url('google.com:80')
108 | Url(scheme=None, host='google.com', port=80, path=None, ...)
109 | >>> parse_url('/foo?bar')
110 | Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)
111 | """
112 |
113 | # While this code has overlap with stdlib's urlparse, it is much
114 | # simplified for our needs and less annoying.
115 | # Additionally, this imeplementations does silly things to be optimal
116 | # on CPython.
117 |
118 | scheme = None
119 | auth = None
120 | host = None
121 | port = None
122 | path = None
123 | fragment = None
124 | query = None
125 |
126 | # Scheme
127 | if '://' in url:
128 | scheme, url = url.split('://', 1)
129 |
130 | # Find the earliest Authority Terminator
131 | # (http://tools.ietf.org/html/rfc3986#section-3.2)
132 | url, path_, delim = split_first(url, ['/', '?', '#'])
133 |
134 | if delim:
135 | # Reassemble the path
136 | path = delim + path_
137 |
138 | # Auth
139 | if '@' in url:
140 | auth, url = url.split('@', 1)
141 |
142 | # IPv6
143 | if url and url[0] == '[':
144 | host, url = url[1:].split(']', 1)
145 |
146 | # Port
147 | if ':' in url:
148 | _host, port = url.split(':', 1)
149 |
150 | if not host:
151 | host = _host
152 |
153 | if not port.isdigit():
154 | raise LocationParseError("Failed to parse: %s" % url)
155 |
156 | port = int(port)
157 |
158 | elif not host and url:
159 | host = url
160 |
161 | if not path:
162 | return Url(scheme, auth, host, port, path, query, fragment)
163 |
164 | # Fragment
165 | if '#' in path:
166 | path, fragment = path.split('#', 1)
167 |
168 | # Query
169 | if '?' in path:
170 | path, query = path.split('?', 1)
171 |
172 | return Url(scheme, auth, host, port, path, query, fragment)
173 |
174 |
175 | def get_host(url):
176 | """
177 | Deprecated. Use :func:`.parse_url` instead.
178 | """
179 | p = parse_url(url)
180 | return p.scheme or 'http', p.hostname, p.port
181 |
182 |
183 | def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
184 | basic_auth=None):
185 | """
186 | Shortcuts for generating request headers.
187 |
188 | :param keep_alive:
189 | If ``True``, adds 'connection: keep-alive' header.
190 |
191 | :param accept_encoding:
192 | Can be a boolean, list, or string.
193 | ``True`` translates to 'gzip,deflate'.
194 | List will get joined by comma.
195 | String will be used as provided.
196 |
197 | :param user_agent:
198 | String representing the user-agent you want, such as
199 | "python-urllib3/0.6"
200 |
201 | :param basic_auth:
202 | Colon-separated username:password string for 'authorization: basic ...'
203 | auth header.
204 |
205 | Example: ::
206 |
207 | >>> make_headers(keep_alive=True, user_agent="Batman/1.0")
208 | {'connection': 'keep-alive', 'user-agent': 'Batman/1.0'}
209 | >>> make_headers(accept_encoding=True)
210 | {'accept-encoding': 'gzip,deflate'}
211 | """
212 | headers = {}
213 | if accept_encoding:
214 | if isinstance(accept_encoding, str):
215 | pass
216 | elif isinstance(accept_encoding, list):
217 | accept_encoding = ','.join(accept_encoding)
218 | else:
219 | accept_encoding = 'gzip,deflate'
220 | headers['accept-encoding'] = accept_encoding
221 |
222 | if user_agent:
223 | headers['user-agent'] = user_agent
224 |
225 | if keep_alive:
226 | headers['connection'] = 'keep-alive'
227 |
228 | if basic_auth:
229 | headers['authorization'] = 'Basic ' + \
230 | b64encode(six.b(basic_auth)).decode('utf-8')
231 |
232 | return headers
233 |
234 |
235 | def is_connection_dropped(conn):
236 | """
237 | Returns True if the connection is dropped and should be closed.
238 |
239 | :param conn:
240 | :class:`httplib.HTTPConnection` object.
241 |
242 | Note: For platforms like AppEngine, this will always return ``False`` to
243 | let the platform handle connection recycling transparently for us.
244 | """
245 | sock = getattr(conn, 'sock', False)
246 | if not sock: # Platform-specific: AppEngine
247 | return False
248 |
249 | if not poll: # Platform-specific
250 | if not select: # Platform-specific: AppEngine
251 | return False
252 |
253 | try:
254 | return select([sock], [], [], 0.0)[0]
255 | except SocketError:
256 | return True
257 |
258 | # This version is better on platforms that support it.
259 | p = poll()
260 | p.register(sock, POLLIN)
261 | for (fno, ev) in p.poll(0.0):
262 | if fno == sock.fileno():
263 | # Either data is buffered (bad), or the connection is dropped.
264 | return True
265 |
266 |
267 | def resolve_cert_reqs(candidate):
268 | """
269 | Resolves the argument to a numeric constant, which can be passed to
270 | the wrap_socket function/method from the ssl module.
271 | Defaults to :data:`ssl.CERT_NONE`.
272 | If given a string it is assumed to be the name of the constant in the
273 | :mod:`ssl` module or its abbrevation.
274 | (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
275 | If it's neither `None` nor a string we assume it is already the numeric
276 | constant which can directly be passed to wrap_socket.
277 | """
278 | if candidate is None:
279 | return CERT_NONE
280 |
281 | if isinstance(candidate, str):
282 | res = getattr(ssl, candidate, None)
283 | if res is None:
284 | res = getattr(ssl, 'CERT_' + candidate)
285 | return res
286 |
287 | return candidate
288 |
289 |
290 | def resolve_ssl_version(candidate):
291 | """
292 | like resolve_cert_reqs
293 | """
294 | if candidate is None:
295 | return PROTOCOL_SSLv23
296 |
297 | if isinstance(candidate, str):
298 | res = getattr(ssl, candidate, None)
299 | if res is None:
300 | res = getattr(ssl, 'PROTOCOL_' + candidate)
301 | return res
302 |
303 | return candidate
304 |
305 | if SSLContext is not None: # Python 3.2+
306 | def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
307 | ca_certs=None, server_hostname=None,
308 | ssl_version=None):
309 | """
310 | All arguments except `server_hostname` have the same meaning as for
311 | :func:`ssl.wrap_socket`
312 |
313 | :param server_hostname:
314 | Hostname of the expected certificate
315 | """
316 | context = SSLContext(ssl_version)
317 | context.verify_mode = cert_reqs
318 | if ca_certs:
319 | try:
320 | context.load_verify_locations(ca_certs)
321 | # Py32 raises IOError
322 | # Py33 raises FileNotFoundError
323 | except Exception as e: # Reraise as SSLError
324 | raise SSLError(e)
325 | if certfile:
326 | # FIXME: This block needs a test.
327 | context.load_cert_chain(certfile, keyfile)
328 | if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI
329 | return context.wrap_socket(sock, server_hostname=server_hostname)
330 | return context.wrap_socket(sock)
331 |
332 | else: # Python 3.1 and earlier
333 | def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
334 | ca_certs=None, server_hostname=None,
335 | ssl_version=None):
336 | return wrap_socket(sock, keyfile=keyfile, certfile=certfile,
337 | ca_certs=ca_certs, cert_reqs=cert_reqs,
338 | ssl_version=ssl_version)
339 |
--------------------------------------------------------------------------------
/requests/packages/charade/langthaimodel.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Communicator client code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Netscape Communications Corporation.
6 | # Portions created by the Initial Developer are Copyright (C) 1998
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | #
12 | # This library is free software; you can redistribute it and/or
13 | # modify it under the terms of the GNU Lesser General Public
14 | # License as published by the Free Software Foundation; either
15 | # version 2.1 of the License, or (at your option) any later version.
16 | #
17 | # This library is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | # Lesser General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU Lesser General Public
23 | # License along with this library; if not, write to the Free Software
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 | # 02110-1301 USA
26 | ######################### END LICENSE BLOCK #########################
27 |
28 | # 255: Control characters that usually does not exist in any text
29 | # 254: Carriage/Return
30 | # 253: symbol (punctuation) that does not belong to word
31 | # 252: 0 - 9
32 |
33 | # The following result for thai was collected from a limited sample (1M).
34 |
35 | # Character Mapping Table:
36 | TIS620CharToOrderMap = (
37 | 255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
38 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
39 | 253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
40 | 252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
41 | 253,182,106,107,100,183,184,185,101, 94,186,187,108,109,110,111, # 40
42 | 188,189,190, 89, 95,112,113,191,192,193,194,253,253,253,253,253, # 50
43 | 253, 64, 72, 73,114, 74,115,116,102, 81,201,117, 90,103, 78, 82, # 60
44 | 96,202, 91, 79, 84,104,105, 97, 98, 92,203,253,253,253,253,253, # 70
45 | 209,210,211,212,213, 88,214,215,216,217,218,219,220,118,221,222,
46 | 223,224, 99, 85, 83,225,226,227,228,229,230,231,232,233,234,235,
47 | 236, 5, 30,237, 24,238, 75, 8, 26, 52, 34, 51,119, 47, 58, 57,
48 | 49, 53, 55, 43, 20, 19, 44, 14, 48, 3, 17, 25, 39, 62, 31, 54,
49 | 45, 9, 16, 2, 61, 15,239, 12, 42, 46, 18, 21, 76, 4, 66, 63,
50 | 22, 10, 1, 36, 23, 13, 40, 27, 32, 35, 86,240,241,242,243,244,
51 | 11, 28, 41, 29, 33,245, 50, 37, 6, 7, 67, 77, 38, 93,246,247,
52 | 68, 56, 59, 65, 69, 60, 70, 80, 71, 87,248,249,250,251,252,253,
53 | )
54 |
55 | # Model Table:
56 | # total sequences: 100%
57 | # first 512 sequences: 92.6386%
58 | # first 1024 sequences:7.3177%
59 | # rest sequences: 1.0230%
60 | # negative sequences: 0.0436%
61 | ThaiLangModel = (
62 | 0,1,3,3,3,3,0,0,3,3,0,3,3,0,3,3,3,3,3,3,3,3,0,0,3,3,3,0,3,3,3,3,
63 | 0,3,3,0,0,0,1,3,0,3,3,2,3,3,0,1,2,3,3,3,3,0,2,0,2,0,0,3,2,1,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,0,0,0,0,0,0,0,0,0,0,0,
183 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,
184 | 1,0,0,0,0,0,0,0,0,1,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,
185 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
186 | 0,0,1,1,0,0,2,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
187 | 0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188 | 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
189 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
190 | )
191 |
192 | TIS620ThaiModel = {
193 | 'charToOrderMap': TIS620CharToOrderMap,
194 | 'precedenceMatrix': ThaiLangModel,
195 | 'mTypicalPositiveRatio': 0.926386,
196 | 'keepEnglishLetter': False,
197 | 'charsetName': "TIS-620"
198 | }
199 |
200 | # flake8: noqa
201 |
--------------------------------------------------------------------------------
/requests/packages/charade/langhebrewmodel.py:
--------------------------------------------------------------------------------
1 | ######################## BEGIN LICENSE BLOCK ########################
2 | # The Original Code is Mozilla Universal charset detector code.
3 | #
4 | # The Initial Developer of the Original Code is
5 | # Simon Montagu
6 | # Portions created by the Initial Developer are Copyright (C) 2005
7 | # the Initial Developer. All Rights Reserved.
8 | #
9 | # Contributor(s):
10 | # Mark Pilgrim - port to Python
11 | # Shy Shalom - original C code
12 | # Shoshannah Forbes - original C code (?)
13 | #
14 | # This library is free software; you can redistribute it and/or
15 | # modify it under the terms of the GNU Lesser General Public
16 | # License as published by the Free Software Foundation; either
17 | # version 2.1 of the License, or (at your option) any later version.
18 | #
19 | # This library is distributed in the hope that it will be useful,
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 | # Lesser General Public License for more details.
23 | #
24 | # You should have received a copy of the GNU Lesser General Public
25 | # License along with this library; if not, write to the Free Software
26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 | # 02110-1301 USA
28 | ######################### END LICENSE BLOCK #########################
29 |
30 | from . import constants
31 |
32 | # 255: Control characters that usually does not exist in any text
33 | # 254: Carriage/Return
34 | # 253: symbol (punctuation) that does not belong to word
35 | # 252: 0 - 9
36 |
37 | # Windows-1255 language model
38 | # Character Mapping Table:
39 | win1255_CharToOrderMap = (
40 | 255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
41 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
42 | 253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
43 | 252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
44 | 253, 69, 91, 79, 80, 92, 89, 97, 90, 68,111,112, 82, 73, 95, 85, # 40
45 | 78,121, 86, 71, 67,102,107, 84,114,103,115,253,253,253,253,253, # 50
46 | 253, 50, 74, 60, 61, 42, 76, 70, 64, 53,105, 93, 56, 65, 54, 49, # 60
47 | 66,110, 51, 43, 44, 63, 81, 77, 98, 75,108,253,253,253,253,253, # 70
48 | 124,202,203,204,205, 40, 58,206,207,208,209,210,211,212,213,214,
49 | 215, 83, 52, 47, 46, 72, 32, 94,216,113,217,109,218,219,220,221,
50 | 34,116,222,118,100,223,224,117,119,104,125,225,226, 87, 99,227,
51 | 106,122,123,228, 55,229,230,101,231,232,120,233, 48, 39, 57,234,
52 | 30, 59, 41, 88, 33, 37, 36, 31, 29, 35,235, 62, 28,236,126,237,
53 | 238, 38, 45,239,240,241,242,243,127,244,245,246,247,248,249,250,
54 | 9, 8, 20, 16, 3, 2, 24, 14, 22, 1, 25, 15, 4, 11, 6, 23,
55 | 12, 19, 13, 26, 18, 27, 21, 17, 7, 10, 5,251,252,128, 96,253,
56 | )
57 |
58 | # Model Table:
59 | # total sequences: 100%
60 | # first 512 sequences: 98.4004%
61 | # first 1024 sequences: 1.5981%
62 | # rest sequences: 0.087%
63 | # negative sequences: 0.0015%
64 | HebrewLangModel = (
65 | 0,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,2,3,2,1,2,0,1,0,0,
66 | 3,0,3,1,0,0,1,3,2,0,1,1,2,0,2,2,2,1,1,1,1,2,1,1,1,2,0,0,2,2,0,1,
67 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,
68 | 1,2,1,2,1,2,0,0,2,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,
69 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,
70 | 1,2,1,3,1,1,0,0,2,0,0,0,1,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,
71 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,0,1,2,2,1,3,
72 | 1,2,1,1,2,2,0,0,2,2,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,1,0,
73 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,2,2,2,2,3,2,
74 | 1,2,1,2,2,2,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,
75 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,2,3,2,2,3,2,2,2,1,2,2,2,2,
76 | 1,2,1,1,2,2,0,1,2,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,
77 | 3,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,
181 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,
183 | 0,1,0,0,2,0,2,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,
184 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
185 | 1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
186 | 0,0,0,0,0,0,0,0,1,0,1,1,2,0,1,0,0,1,1,1,0,1,0,0,1,0,0,0,1,0,0,1,
187 | 1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188 | 1,0,0,0,0,0,0,0,1,0,1,1,0,0,1,0,0,2,1,1,1,1,1,0,1,0,0,0,0,1,0,1,
189 | 0,1,1,1,2,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,
190 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
191 | 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
192 | 0,0,0,0,0,0,0,0,0,0,1,2,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,1,1,0,0,
193 | )
194 |
195 | Win1255HebrewModel = {
196 | 'charToOrderMap': win1255_CharToOrderMap,
197 | 'precedenceMatrix': HebrewLangModel,
198 | 'mTypicalPositiveRatio': 0.984004,
199 | 'keepEnglishLetter': False,
200 | 'charsetName': "windows-1255"
201 | }
202 |
203 | # flake8: noqa
204 |
--------------------------------------------------------------------------------