Browse Source
Conflicts: couchpotato/core/media/movie/_base/main.py couchpotato/core/providers/torrent/bitsoup/main.py couchpotato/core/providers/torrent/iptorrents/main.py couchpotato/core/providers/torrent/sceneaccess/main.py couchpotato/core/providers/torrent/torrentleech/main.py couchpotato/core/providers/torrent/torrentshack/main.pyold/tv
99 changed files with 7485 additions and 4198 deletions
File diff suppressed because it is too large
@ -0,0 +1,7 @@ |
|||||
|
''' |
||||
|
support ';python -m charade <file1> [file2] ...' package execution syntax (2.7+) |
||||
|
''' |
||||
|
|
||||
|
from charade import charade_cli |
||||
|
|
||||
|
charade_cli() |
@ -0,0 +1,107 @@ |
|||||
|
# urllib3/connection.py |
||||
|
# Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) |
||||
|
# |
||||
|
# This module is part of urllib3 and is released under |
||||
|
# the MIT License: http://www.opensource.org/licenses/mit-license.php |
||||
|
|
||||
|
import socket |
||||
|
from socket import timeout as SocketTimeout |
||||
|
|
||||
|
try: # Python 3 |
||||
|
from http.client import HTTPConnection, HTTPException |
||||
|
except ImportError: |
||||
|
from httplib import HTTPConnection, HTTPException |
||||
|
|
||||
|
class DummyConnection(object): |
||||
|
"Used to detect a failed ConnectionCls import." |
||||
|
pass |
||||
|
|
||||
|
try: # Compiled with SSL? |
||||
|
ssl = None |
||||
|
HTTPSConnection = DummyConnection |
||||
|
|
||||
|
class BaseSSLError(BaseException): |
||||
|
pass |
||||
|
|
||||
|
try: # Python 3 |
||||
|
from http.client import HTTPSConnection |
||||
|
except ImportError: |
||||
|
from httplib import HTTPSConnection |
||||
|
|
||||
|
import ssl |
||||
|
BaseSSLError = ssl.SSLError |
||||
|
|
||||
|
except (ImportError, AttributeError): # Platform-specific: No SSL. |
||||
|
pass |
||||
|
|
||||
|
from .exceptions import ( |
||||
|
ConnectTimeoutError, |
||||
|
) |
||||
|
from .packages.ssl_match_hostname import match_hostname |
||||
|
from .util import ( |
||||
|
assert_fingerprint, |
||||
|
resolve_cert_reqs, |
||||
|
resolve_ssl_version, |
||||
|
ssl_wrap_socket, |
||||
|
) |
||||
|
|
||||
|
class VerifiedHTTPSConnection(HTTPSConnection): |
||||
|
""" |
||||
|
Based on httplib.HTTPSConnection but wraps the socket with |
||||
|
SSL certification. |
||||
|
""" |
||||
|
cert_reqs = None |
||||
|
ca_certs = None |
||||
|
ssl_version = None |
||||
|
|
||||
|
def set_cert(self, key_file=None, cert_file=None, |
||||
|
cert_reqs=None, ca_certs=None, |
||||
|
assert_hostname=None, assert_fingerprint=None): |
||||
|
|
||||
|
self.key_file = key_file |
||||
|
self.cert_file = cert_file |
||||
|
self.cert_reqs = cert_reqs |
||||
|
self.ca_certs = ca_certs |
||||
|
self.assert_hostname = assert_hostname |
||||
|
self.assert_fingerprint = assert_fingerprint |
||||
|
|
||||
|
def connect(self): |
||||
|
# Add certificate verification |
||||
|
try: |
||||
|
sock = socket.create_connection( |
||||
|
address=(self.host, self.port), |
||||
|
timeout=self.timeout, |
||||
|
) |
||||
|
except SocketTimeout: |
||||
|
raise ConnectTimeoutError( |
||||
|
self, "Connection to %s timed out. (connect timeout=%s)" % |
||||
|
(self.host, self.timeout)) |
||||
|
|
||||
|
resolved_cert_reqs = resolve_cert_reqs(self.cert_reqs) |
||||
|
resolved_ssl_version = resolve_ssl_version(self.ssl_version) |
||||
|
|
||||
|
if self._tunnel_host: |
||||
|
self.sock = sock |
||||
|
# Calls self._set_hostport(), so self.host is |
||||
|
# self._tunnel_host below. |
||||
|
self._tunnel() |
||||
|
|
||||
|
# Wrap socket using verification with the root certs in |
||||
|
# trusted_root_certs |
||||
|
self.sock = ssl_wrap_socket(sock, self.key_file, self.cert_file, |
||||
|
cert_reqs=resolved_cert_reqs, |
||||
|
ca_certs=self.ca_certs, |
||||
|
server_hostname=self.host, |
||||
|
ssl_version=resolved_ssl_version) |
||||
|
|
||||
|
if resolved_cert_reqs != ssl.CERT_NONE: |
||||
|
if self.assert_fingerprint: |
||||
|
assert_fingerprint(self.sock.getpeercert(binary_form=True), |
||||
|
self.assert_fingerprint) |
||||
|
elif self.assert_hostname is not False: |
||||
|
match_hostname(self.sock.getpeercert(), |
||||
|
self.assert_hostname or self.host) |
||||
|
|
||||
|
|
||||
|
if ssl: |
||||
|
HTTPSConnection = VerifiedHTTPSConnection |
@ -0,0 +1,177 @@ |
|||||
|
# urllib3/fields.py |
||||
|
# Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt) |
||||
|
# |
||||
|
# This module is part of urllib3 and is released under |
||||
|
# the MIT License: http://www.opensource.org/licenses/mit-license.php |
||||
|
|
||||
|
import email.utils |
||||
|
import mimetypes |
||||
|
|
||||
|
from .packages import six |
||||
|
|
||||
|
|
||||
|
def guess_content_type(filename, default='application/octet-stream'): |
||||
|
""" |
||||
|
Guess the "Content-Type" of a file. |
||||
|
|
||||
|
:param filename: |
||||
|
The filename to guess the "Content-Type" of using :mod:`mimetimes`. |
||||
|
:param default: |
||||
|
If no "Content-Type" can be guessed, default to `default`. |
||||
|
""" |
||||
|
if filename: |
||||
|
return mimetypes.guess_type(filename)[0] or default |
||||
|
return default |
||||
|
|
||||
|
|
||||
|
def format_header_param(name, value): |
||||
|
""" |
||||
|
Helper function to format and quote a single header parameter. |
||||
|
|
||||
|
Particularly useful for header parameters which might contain |
||||
|
non-ASCII values, like file names. This follows RFC 2231, as |
||||
|
suggested by RFC 2388 Section 4.4. |
||||
|
|
||||
|
:param name: |
||||
|
The name of the parameter, a string expected to be ASCII only. |
||||
|
:param value: |
||||
|
The value of the parameter, provided as a unicode string. |
||||
|
""" |
||||
|
if not any(ch in value for ch in '"\\\r\n'): |
||||
|
result = '%s="%s"' % (name, value) |
||||
|
try: |
||||
|
result.encode('ascii') |
||||
|
except UnicodeEncodeError: |
||||
|
pass |
||||
|
else: |
||||
|
return result |
||||
|
if not six.PY3: # Python 2: |
||||
|
value = value.encode('utf-8') |
||||
|
value = email.utils.encode_rfc2231(value, 'utf-8') |
||||
|
value = '%s*=%s' % (name, value) |
||||
|
return value |
||||
|
|
||||
|
|
||||
|
class RequestField(object): |
||||
|
""" |
||||
|
A data container for request body parameters. |
||||
|
|
||||
|
:param name: |
||||
|
The name of this request field. |
||||
|
:param data: |
||||
|
The data/value body. |
||||
|
:param filename: |
||||
|
An optional filename of the request field. |
||||
|
:param headers: |
||||
|
An optional dict-like object of headers to initially use for the field. |
||||
|
""" |
||||
|
def __init__(self, name, data, filename=None, headers=None): |
||||
|
self._name = name |
||||
|
self._filename = filename |
||||
|
self.data = data |
||||
|
self.headers = {} |
||||
|
if headers: |
||||
|
self.headers = dict(headers) |
||||
|
|
||||
|
@classmethod |
||||
|
def from_tuples(cls, fieldname, value): |
||||
|
""" |
||||
|
A :class:`~urllib3.fields.RequestField` factory from old-style tuple parameters. |
||||
|
|
||||
|
Supports constructing :class:`~urllib3.fields.RequestField` from parameter |
||||
|
of key/value strings AND key/filetuple. A filetuple is a (filename, data, MIME type) |
||||
|
tuple where the MIME type is optional. For example: :: |
||||
|
|
||||
|
'foo': 'bar', |
||||
|
'fakefile': ('foofile.txt', 'contents of foofile'), |
||||
|
'realfile': ('barfile.txt', open('realfile').read()), |
||||
|
'typedfile': ('bazfile.bin', open('bazfile').read(), 'image/jpeg'), |
||||
|
'nonamefile': 'contents of nonamefile field', |
||||
|
|
||||
|
Field names and filenames must be unicode. |
||||
|
""" |
||||
|
if isinstance(value, tuple): |
||||
|
if len(value) == 3: |
||||
|
filename, data, content_type = value |
||||
|
else: |
||||
|
filename, data = value |
||||
|
content_type = guess_content_type(filename) |
||||
|
else: |
||||
|
filename = None |
||||
|
content_type = None |
||||
|
data = value |
||||
|
|
||||
|
request_param = cls(fieldname, data, filename=filename) |
||||
|
request_param.make_multipart(content_type=content_type) |
||||
|
|
||||
|
return request_param |
||||
|
|
||||
|
def _render_part(self, name, value): |
||||
|
""" |
||||
|
Overridable helper function to format a single header parameter. |
||||
|
|
||||
|
:param name: |
||||
|
The name of the parameter, a string expected to be ASCII only. |
||||
|
:param value: |
||||
|
The value of the parameter, provided as a unicode string. |
||||
|
""" |
||||
|
return format_header_param(name, value) |
||||
|
|
||||
|
def _render_parts(self, header_parts): |
||||
|
""" |
||||
|
Helper function to format and quote a single header. |
||||
|
|
||||
|
Useful for single headers that are composed of multiple items. E.g., |
||||
|
'Content-Disposition' fields. |
||||
|
|
||||
|
:param header_parts: |
||||
|
A sequence of (k, v) typles or a :class:`dict` of (k, v) to format as |
||||
|
`k1="v1"; k2="v2"; ...`. |
||||
|
""" |
||||
|
parts = [] |
||||
|
iterable = header_parts |
||||
|
if isinstance(header_parts, dict): |
||||
|
iterable = header_parts.items() |
||||
|
|
||||
|
for name, value in iterable: |
||||
|
if value: |
||||
|
parts.append(self._render_part(name, value)) |
||||
|
|
||||
|
return '; '.join(parts) |
||||
|
|
||||
|
def render_headers(self): |
||||
|
""" |
||||
|
Renders the headers for this request field. |
||||
|
""" |
||||
|
lines = [] |
||||
|
|
||||
|
sort_keys = ['Content-Disposition', 'Content-Type', 'Content-Location'] |
||||
|
for sort_key in sort_keys: |
||||
|
if self.headers.get(sort_key, False): |
||||
|
lines.append('%s: %s' % (sort_key, self.headers[sort_key])) |
||||
|
|
||||
|
for header_name, header_value in self.headers.items(): |
||||
|
if header_name not in sort_keys: |
||||
|
if header_value: |
||||
|
lines.append('%s: %s' % (header_name, header_value)) |
||||
|
|
||||
|
lines.append('\r\n') |
||||
|
return '\r\n'.join(lines) |
||||
|
|
||||
|
def make_multipart(self, content_disposition=None, content_type=None, content_location=None): |
||||
|
""" |
||||
|
Makes this request field into a multipart request field. |
||||
|
|
||||
|
This method overrides "Content-Disposition", "Content-Type" and |
||||
|
"Content-Location" headers to the request parameter. |
||||
|
|
||||
|
:param content_type: |
||||
|
The 'Content-Type' of the request body. |
||||
|
:param content_location: |
||||
|
The 'Content-Location' of the request body. |
||||
|
|
||||
|
""" |
||||
|
self.headers['Content-Disposition'] = content_disposition or 'form-data' |
||||
|
self.headers['Content-Disposition'] += '; '.join(['', self._render_parts((('name', self._name), ('filename', self._filename)))]) |
||||
|
self.headers['Content-Type'] = content_type |
||||
|
self.headers['Content-Location'] = content_location |
@ -1,61 +1,13 @@ |
|||||
"""The match_hostname() function from Python 3.2, essential when using SSL.""" |
try: |
||||
|
# Python 3.2+ |
||||
import re |
from ssl import CertificateError, match_hostname |
||||
|
except ImportError: |
||||
__version__ = '3.2.2' |
try: |
||||
|
# Backport of the function from a pypi module |
||||
class CertificateError(ValueError): |
from backports.ssl_match_hostname import CertificateError, match_hostname |
||||
pass |
except ImportError: |
||||
|
# Our vendored copy |
||||
def _dnsname_to_pat(dn): |
from _implementation import CertificateError, match_hostname |
||||
pats = [] |
|
||||
for frag in dn.split(r'.'): |
# Not needed, but documenting what we provide. |
||||
if frag == '*': |
__all__ = ('CertificateError', 'match_hostname') |
||||
# When '*' is a fragment by itself, it matches a non-empty dotless |
|
||||
# fragment. |
|
||||
pats.append('[^.]+') |
|
||||
else: |
|
||||
# Otherwise, '*' matches any dotless fragment. |
|
||||
frag = re.escape(frag) |
|
||||
pats.append(frag.replace(r'\*', '[^.]*')) |
|
||||
return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) |
|
||||
|
|
||||
def match_hostname(cert, hostname): |
|
||||
"""Verify that *cert* (in decoded format as returned by |
|
||||
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules |
|
||||
are mostly followed, but IP addresses are not accepted for *hostname*. |
|
||||
|
|
||||
CertificateError is raised on failure. On success, the function |
|
||||
returns nothing. |
|
||||
""" |
|
||||
if not cert: |
|
||||
raise ValueError("empty or no certificate") |
|
||||
dnsnames = [] |
|
||||
san = cert.get('subjectAltName', ()) |
|
||||
for key, value in san: |
|
||||
if key == 'DNS': |
|
||||
if _dnsname_to_pat(value).match(hostname): |
|
||||
return |
|
||||
dnsnames.append(value) |
|
||||
if not dnsnames: |
|
||||
# The subject is only checked when there is no dNSName entry |
|
||||
# in subjectAltName |
|
||||
for sub in cert.get('subject', ()): |
|
||||
for key, value in sub: |
|
||||
# XXX according to RFC 2818, the most specific Common Name |
|
||||
# must be used. |
|
||||
if key == 'commonName': |
|
||||
if _dnsname_to_pat(value).match(hostname): |
|
||||
return |
|
||||
dnsnames.append(value) |
|
||||
if len(dnsnames) > 1: |
|
||||
raise CertificateError("hostname %r " |
|
||||
"doesn't match either of %s" |
|
||||
% (hostname, ', '.join(map(repr, dnsnames)))) |
|
||||
elif len(dnsnames) == 1: |
|
||||
raise CertificateError("hostname %r " |
|
||||
"doesn't match %r" |
|
||||
% (hostname, dnsnames[0])) |
|
||||
else: |
|
||||
raise CertificateError("no appropriate commonName or " |
|
||||
"subjectAltName fields were found") |
|
||||
|
@ -0,0 +1,105 @@ |
|||||
|
"""The match_hostname() function from Python 3.3.3, essential when using SSL.""" |
||||
|
|
||||
|
# Note: This file is under the PSF license as the code comes from the python |
||||
|
# stdlib. http://docs.python.org/3/license.html |
||||
|
|
||||
|
import re |
||||
|
|
||||
|
__version__ = '3.4.0.2' |
||||
|
|
||||
|
class CertificateError(ValueError): |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
def _dnsname_match(dn, hostname, max_wildcards=1): |
||||
|
"""Matching according to RFC 6125, section 6.4.3 |
||||
|
|
||||
|
http://tools.ietf.org/html/rfc6125#section-6.4.3 |
||||
|
""" |
||||
|
pats = [] |
||||
|
if not dn: |
||||
|
return False |
||||
|
|
||||
|
# Ported from python3-syntax: |
||||
|
# leftmost, *remainder = dn.split(r'.') |
||||
|
parts = dn.split(r'.') |
||||
|
leftmost = parts[0] |
||||
|
remainder = parts[1:] |
||||
|
|
||||
|
wildcards = leftmost.count('*') |
||||
|
if wildcards > max_wildcards: |
||||
|
# Issue #17980: avoid denials of service by refusing more |
||||
|
# than one wildcard per fragment. A survey of established |
||||
|
# policy among SSL implementations showed it to be a |
||||
|
# reasonable choice. |
||||
|
raise CertificateError( |
||||
|
"too many wildcards in certificate DNS name: " + repr(dn)) |
||||
|
|
||||
|
# speed up common case w/o wildcards |
||||
|
if not wildcards: |
||||
|
return dn.lower() == hostname.lower() |
||||
|
|
||||
|
# RFC 6125, section 6.4.3, subitem 1. |
||||
|
# The client SHOULD NOT attempt to match a presented identifier in which |
||||
|
# the wildcard character comprises a label other than the left-most label. |
||||
|
if leftmost == '*': |
||||
|
# When '*' is a fragment by itself, it matches a non-empty dotless |
||||
|
# fragment. |
||||
|
pats.append('[^.]+') |
||||
|
elif leftmost.startswith('xn--') or hostname.startswith('xn--'): |
||||
|
# RFC 6125, section 6.4.3, subitem 3. |
||||
|
# The client SHOULD NOT attempt to match a presented identifier |
||||
|
# where the wildcard character is embedded within an A-label or |
||||
|
# U-label of an internationalized domain name. |
||||
|
pats.append(re.escape(leftmost)) |
||||
|
else: |
||||
|
# Otherwise, '*' matches any dotless string, e.g. www* |
||||
|
pats.append(re.escape(leftmost).replace(r'\*', '[^.]*')) |
||||
|
|
||||
|
# add the remaining fragments, ignore any wildcards |
||||
|
for frag in remainder: |
||||
|
pats.append(re.escape(frag)) |
||||
|
|
||||
|
pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) |
||||
|
return pat.match(hostname) |
||||
|
|
||||
|
|
||||
|
def match_hostname(cert, hostname): |
||||
|
"""Verify that *cert* (in decoded format as returned by |
||||
|
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 |
||||
|
rules are followed, but IP addresses are not accepted for *hostname*. |
||||
|
|
||||
|
CertificateError is raised on failure. On success, the function |
||||
|
returns nothing. |
||||
|
""" |
||||
|
if not cert: |
||||
|
raise ValueError("empty or no certificate") |
||||
|
dnsnames = [] |
||||
|
san = cert.get('subjectAltName', ()) |
||||
|
for key, value in san: |
||||
|
if key == 'DNS': |
||||
|
if _dnsname_match(value, hostname): |
||||
|
return |
||||
|
dnsnames.append(value) |
||||
|
if not dnsnames: |
||||
|
# The subject is only checked when there is no dNSName entry |
||||
|
# in subjectAltName |
||||
|
for sub in cert.get('subject', ()): |
||||
|
for key, value in sub: |
||||
|
# XXX according to RFC 2818, the most specific Common Name |
||||
|
# must be used. |
||||
|
if key == 'commonName': |
||||
|
if _dnsname_match(value, hostname): |
||||
|
return |
||||
|
dnsnames.append(value) |
||||
|
if len(dnsnames) > 1: |
||||
|
raise CertificateError("hostname %r " |
||||
|
"doesn't match either of %s" |
||||
|
% (hostname, ', '.join(map(repr, dnsnames)))) |
||||
|
elif len(dnsnames) == 1: |
||||
|
raise CertificateError("hostname %r " |
||||
|
"doesn't match %r" |
||||
|
% (hostname, dnsnames[0])) |
||||
|
else: |
||||
|
raise CertificateError("no appropriate commonName or " |
||||
|
"subjectAltName fields were found") |
Loading…
Reference in new issue