Skip to content

Commit

Permalink
Merge pull request #9131 from pymedusa/release/release-0.5.6
Browse files Browse the repository at this point in the history
Release/release 0.5.6
  • Loading branch information
p0psicles authored Jan 27, 2021
2 parents 0b60e12 + 9301d90 commit 2ab9d45
Show file tree
Hide file tree
Showing 42 changed files with 306 additions and 155 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.5.6 (27-01-2021)

#### Fixes
- Fix trakt authentication ([9130](https://github.com/pymedusa/Medusa/pull/9130))

-----

## 0.5.5 (25-01-2021)

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion ext/dogpile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.1.1"
__version__ = "1.1.2"

from .lock import Lock # noqa
from .lock import NeedRegenerationException # noqa
11 changes: 11 additions & 0 deletions ext/dogpile/cache/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def release(self) -> None:

raise NotImplementedError()

@abc.abstractmethod
def locked(self) -> bool:
"""Check if the mutex was acquired.
:return: true if the lock is acquired.
.. versionadded:: 1.1.2
"""
raise NotImplementedError()

@classmethod
def __subclasshook__(cls, C):
return hasattr(C, "acquire") and hasattr(C, "release")
Expand Down
5 changes: 5 additions & 0 deletions ext/dogpile/cache/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"dogpile.cache.backends.memcached",
"MemcachedBackend",
)
register_backend(
"dogpile.cache.pymemcache",
"dogpile.cache.backends.memcached",
"PyMemcacheBackend",
)
register_backend(
"dogpile.cache.memory", "dogpile.cache.backends.memory", "MemoryBackend"
)
Expand Down
106 changes: 105 additions & 1 deletion ext/dogpile/cache/backends/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
import memcache
import pylibmc
import bmemcached
import pymemcache
else:
# delayed import
memcache = None
pylibmc = None
bmemcached = None
pymemcache = None

__all__ = (
"GenericMemcachedBackend",
"MemcachedBackend",
"PylibmcBackend",
"PyMemcacheBackend",
"BMemcachedBackend",
"MemcachedLock",
)
Expand Down Expand Up @@ -58,6 +61,10 @@ def acquire(self, wait=True):
if i < 15:
i += 1

def locked(self):
client = self.client_fn()
return client.get(self.key) is not None

def release(self):
client = self.client_fn()
client.delete(self.key)
Expand Down Expand Up @@ -188,7 +195,11 @@ def get(self, key):

def get_multi(self, keys):
values = self.client.get_multi(keys)
return [NO_VALUE if key not in values else values[key] for key in keys]

return [
NO_VALUE if val is None else val
for val in [values.get(key, NO_VALUE) for key in keys]
]

def set(self, key, value):
self.client.set(key, value, **self.set_arguments)
Expand Down Expand Up @@ -417,3 +428,96 @@ def delete_multi(self, keys):
"""python-binary-memcached api does not implements delete_multi"""
for key in keys:
self.delete(key)


pymemcache = None


class PyMemcacheBackend(GenericMemcachedBackend):
"""A backend for the
`pymemcache <https://github.com/pinterest/pymemcache>`_
memcached client.
A comprehensive, fast, pure Python memcached client
.. versionadded:: 1.1.2
pymemcache supports the following features:
* Complete implementation of the memcached text protocol.
* Configurable timeouts for socket connect and send/recv calls.
* Access to the "noreply" flag, which can significantly increase
the speed of writes.
* Flexible, simple approach to serialization and deserialization.
* The (optional) ability to treat network and memcached errors as
cache misses.
dogpile.cache uses the ``HashClient`` from pymemcache in order to reduce
API differences when compared to other memcached client drivers. In short,
this allows the user to provide a single server or a list of memcached
servers.
The ``serde`` param defaults to ``pymemcache.serde.pickle_serde`` as the
legacy ``serde`` would always convert the stored data to binary.
The ``default_noreply`` param defaults to False, otherwise the add command
would always return True causing the mutex not to work.
SSL/TLS is a security layer on end-to-end communication.
It provides following benefits:
* Encryption: Data is encrypted on the wire between
Memcached client and server.
* Authentication: Optionally, both server and client
authenticate each other.
* Integrity: Data is not tampered or altered when
transmitted between client and server
A typical configuration using tls_context::
import ssl
from dogpile.cache import make_region
ctx = ssl.create_default_context(cafile="/path/to/my-ca.pem")
region = make_region().configure(
'dogpile.cache.pymemcache',
expiration_time = 3600,
arguments = {
'url':["127.0.0.1"],
'tls_context':ctx,
}
)
For advanced ways to configure TLS creating a more complex
tls_context visit https://docs.python.org/3/library/ssl.html
Arguments which can be passed to the ``arguments``
dictionary include:
:param tls_context: optional TLS context, will be used for
TLS connections.
:param serde: optional "serde". Defaults to
``pymemcache.serde.pickle_serde``
:param default_noreply: Defaults to False
"""

def __init__(self, arguments):
super().__init__(arguments)

self.serde = arguments.get("serde", pymemcache.serde.pickle_serde)
self.default_noreply = arguments.get("default_noreply", False)
self.tls_context = arguments.get("tls_context", None)

def _imports(self):
global pymemcache
import pymemcache

def _create_client(self):
return pymemcache.client.hash.HashClient(
self.url,
serde=self.serde,
default_noreply=self.default_noreply,
tls_context=self.tls_context,
)
3 changes: 3 additions & 0 deletions ext/dogpile/cache/backends/null.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def acquire(self, wait=True):
def release(self):
pass

def locked(self):
return False


class NullBackend(CacheBackend):
"""A "null" backend that effectively disables all cache operations.
Expand Down
14 changes: 14 additions & 0 deletions ext/dogpile/cache/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ def acquire(self, wait=True):
def release(self):
self.lock.release()

def locked(self):
return self.lock.locked()

def _create_mutex(self, key):
mutex = self.backend.get_mutex(key)
if mutex is not None:
Expand Down Expand Up @@ -865,6 +868,17 @@ def _is_cache_miss(self, value, orig_key):

return True

def key_is_locked(self, key: KeyType) -> bool:
"""Return True if a particular cache key is currently being generated
within the dogpile lock.
.. versionadded:: 1.1.2
"""
mutex = self._mutex(key)
locked: bool = mutex.locked()
return locked

def get_or_create(
self,
key: KeyType,
Expand Down
7 changes: 7 additions & 0 deletions ext/dogpile/util/langhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ def release(self):
# the thread ident and unlock.
del self.keys[current_thread]
self.mutex.release()

def locked(self):
current_thread = threading.get_ident()
keys = self.keys.get(current_thread)
if keys is None:
return False
return self.key in keys
22 changes: 11 additions & 11 deletions ext/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# not yet sure if there implications with this. Compare 'pydoc sre'
# and 'perldoc perlre'.

__version_info__ = (2, 3, 10)
__version_info__ = (2, 4, 0)
__version__ = '.'.join(map(str, __version_info__))
__author__ = "Trent Mick"

Expand Down Expand Up @@ -452,7 +452,7 @@ def preprocess(self, text):
r"(.*:\s+>\n\s+[\S\s]+?)(?=\n\w+\s*:\s*\w+\n|\Z)", re.MULTILINE
)
_key_val_list_pat = re.compile(
r"^-(?:[ \t]*([^:\s]*)(?:[ \t]*[:-][ \t]*(\S+))?)(?:\n((?:[ \t]+[^\n]+\n?)+))?",
r"^-(?:[ \t]*([^\n]*)(?:[ \t]*[:-][ \t]*(\S+))?)(?:\n((?:[ \t]+[^\n]+\n?)+))?",
re.MULTILINE,
)
_key_val_dict_pat = re.compile(
Expand Down Expand Up @@ -532,7 +532,7 @@ def parse_structured_value(value):

return tail

_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*([^\r\n]*?)\s*-\*-", re.UNICODE)
_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*(?:(\S[^\r\n]*?)([\r\n]\s*)?)?-\*-", re.UNICODE)
# This regular expression is intended to match blocks like this:
# PREFIX Local Variables: SUFFIX
# PREFIX mode: Tcl SUFFIX
Expand Down Expand Up @@ -892,8 +892,8 @@ def _do_numbering(self, text):
'''
# First pass to define all the references
self.regex_defns = re.compile(r'''
\[\#(\w+)\s* # the counter. Open square plus hash plus a word \1
([^@]*)\s* # Some optional characters, that aren't an @. \2
\[\#(\w+) # the counter. Open square plus hash plus a word \1
([^@]*) # Some optional characters, that aren't an @. \2
@(\w+) # the id. Should this be normed? \3
([^\]]*)\] # The rest of the text up to the terminating ] \4
''', re.VERBOSE)
Expand All @@ -908,7 +908,7 @@ def _do_numbering(self, text):
if len(match.groups()) != 4:
continue
counter = match.group(1)
text_before = match.group(2)
text_before = match.group(2).strip()
ref_id = match.group(3)
text_after = match.group(4)
number = counters.get(counter, 1)
Expand Down Expand Up @@ -1884,7 +1884,7 @@ def unhash_code(codeblock):
pre_class_str = self._html_class_str_from_tag("pre")

if "highlightjs-lang" in self.extras and lexer_name:
code_class_str = ' class="%s"' % lexer_name
code_class_str = ' class="%s language-%s"' % (lexer_name, lexer_name)
else:
code_class_str = self._html_class_str_from_tag("code")

Expand Down Expand Up @@ -1926,9 +1926,9 @@ def _do_code_blocks(self, text):

_fenced_code_block_re = re.compile(r'''
(?:\n+|\A\n?)
^```\s*?([\w+-]+)?\s*?\n # opening fence, $1 = optional lang
(.*?) # $2 = code block content
^```[ \t]*\n # closing fence
^```\s{0,99}([\w+-]+)?\s{0,99}\n # opening fence, $1 = optional lang
(.*?) # $2 = code block content
^```[ \t]*\n # closing fence
''', re.M | re.X | re.S)

def _fenced_code_block_sub(self, match):
Expand Down Expand Up @@ -2232,7 +2232,7 @@ def _encode_amps_and_angles(self, text):
text = self._naked_gt_re.sub('&gt;', text)
return text

_incomplete_tags_re = re.compile("<(/?\w+?(?!\w).+?[\s/]+?)")
_incomplete_tags_re = re.compile(r"<(/?\w+?(?!\w).+?[\s/]+?)")

def _encode_incomplete_tags(self, text):
if self.safe_mode not in ("replace", "escape"):
Expand Down
8 changes: 4 additions & 4 deletions ext/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext | `deluge-client` | [1.9.0](https://pypi.org/project/deluge-client/1.9.0/) |
ext | **`deprecated`** | [1.2.3](https://pypi.org/project/deprecated/1.2.3/) | `PyGithub` | -
ext | **`dirtyjson`** | [1.0.7](https://pypi.org/project/dirtyjson/1.0.7/) | **`medusa`** | -
ext | **`diskcache`** | [2.9.0](https://pypi.org/project/diskcache/2.9.0/) | `imdbpie` | -
ext | `dogpile.cache` | [1.1.1](https://pypi.org/project/dogpile.cache/1.1.1/) | **`medusa`**, `subliminal` | Module: `dogpile`
ext | `dogpile.cache` | [1.1.2](https://pypi.org/project/dogpile.cache/1.1.2/) | **`medusa`**, `subliminal` | Module: `dogpile`
ext | **`enzyme`** | pymedusa/[665cf69](https://github.com/pymedusa/enzyme/tree/665cf6948aab1c249dcc99bd9624a81d17b3302a) | `knowit`, `subliminal` | -
ext | **`feedparser`** | [6.0.2](https://pypi.org/project/feedparser/6.0.2/) | **`medusa`** | Requires `sgmllib3k` on Python 3
ext | **`gntp`** | [1.0.3](https://pypi.org/project/gntp/1.0.3/) | **`medusa`** | -
Expand All @@ -30,7 +30,7 @@ ext | **`imdbpie`** | [5.6.4](https://pypi.org/project/imdbpie/5.6.4/) | **`medu
ext | `jsonrpclib-pelix` | [0.4.2](https://pypi.org/project/jsonrpclib-pelix/0.4.2/) | **`medusa`** | Module: `jsonrpclib`
ext | **`knowit`** | [eea9ac1](https://github.com/ratoaq2/knowit/tree/eea9ac18e38c930230cf81b5dca4a9af9fb10d4e) | **`medusa`** | -
ext | `Mako` | [1.1.4](https://pypi.org/project/Mako/1.1.4/) | **`medusa`** | Module: `mako`
ext | `markdown2` | [2.3.10](https://pypi.org/project/markdown2/2.3.10/) | **`medusa`** | File: `markdown2.py`
ext | `markdown2` | [2.4.0](https://pypi.org/project/markdown2/2.4.0/) | **`medusa`** | File: `markdown2.py`
ext | `MarkupSafe` | [1.1.1](https://pypi.org/project/MarkupSafe/1.1.1/) | `Mako` | Module: `markupsafe`
ext | **`msgpack`** | [0.5.6](https://pypi.org/project/msgpack/0.5.6/) | `CacheControl` | -
ext | **`oauthlib`** | [3.0.0](https://pypi.org/project/oauthlib/3.0.0/) | `requests-oauthlib` | -
Expand All @@ -55,10 +55,10 @@ ext | `six` | [1.15.0](https://pypi.org/project/six/1.15.0/) | **`medusa`**, `ad
ext | **`soupsieve`** | [1.9.6](https://pypi.org/project/soupsieve/1.9.6/) | `beautifulsoup4` | -
ext | **`stevedore`** | [1.30.1](https://pypi.org/project/stevedore/1.30.1/) | `subliminal` | -
ext | **`subliminal`** | [2.1.0](https://pypi.org/project/subliminal/2.1.0/) | **`medusa`** | -
ext | **`tmdbsimple`** | [2.7.0](https://pypi.org/project/tmdbsimple/2.7.0/) | **`medusa`** | -
ext | **`tmdbsimple`** | [2.8.0](https://pypi.org/project/tmdbsimple/2.8.0/) | **`medusa`** | -
ext | **`tornado`** | [6.1](https://pypi.org/project/tornado/6.1/) | **`medusa`**, `tornroutes` | -
ext | **`tornroutes`** | [0.5.1](https://pypi.org/project/tornroutes/0.5.1/) | **`medusa`** | -
ext | **`trakt`** | p0psicles/[8de5bfb](https://github.com/p0psicles/PyTrakt/tree/8de5bfb04b3d5ee54e4a3b25db0e4c341cc31384) | **`medusa`** | -
ext | **`trakt`** | [2d7dc0e](https://github.com/p0psicles/PyTrakt/tree/2d7dc0e7fb5d284444c5d16c7fe7f2b8e56188ef) | **`medusa`** | -
ext | `trans` | [2.1.0](https://pypi.org/project/trans/2.1.0/) | `imdbpie` | File: `trans.py`
ext | `ttl-cache` | [1.6](https://pypi.org/project/ttl-cache/1.6/) | **`medusa`** | File: `ttl_cache.py`
ext | **`tvdbapiv2`** | pymedusa/[d6d0e9d](https://github.com/pymedusa/tvdbv2/tree/d6d0e9d98071c2d646beb997b336edbb0e98dfb7) | **`medusa`** | -
Expand Down
4 changes: 2 additions & 2 deletions ext/tmdbsimple/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

__title__ = 'tmdbsimple'
__version__ = '2.7.0'
__version__ = '2.8.0'
__author__ = 'Celia Oakley'
__copyright__ = 'Copyright (c) 2013-2020 Celia Oakley'
__license__ = 'GPLv3'
Expand Down Expand Up @@ -52,4 +52,4 @@

API_KEY = os.environ.get('TMDB_API_KEY', None)
API_VERSION = '3'
REQUESTS_SESSION = requests.Session()
REQUESTS_SESSION = None
24 changes: 20 additions & 4 deletions ext/tmdbsimple/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import json
import requests


class APIKeyError(Exception):
Expand Down Expand Up @@ -80,10 +81,25 @@ def _request(self, method, path, params=None, payload=None):
url = self._get_complete_url(path)
params = self._get_params(params)

response = self.session.request(
method, url, params=params,
data=json.dumps(payload) if payload else payload,
headers=self.headers)
# Create a new request session if no global session is defined
if self.session is None:
response = requests.request(
method,
url,
params=params,
data=json.dumps(payload) if payload else payload,
headers=self.headers,
)

# Use the global requests session the user provided
else:
response = self.session.request(
method,
url,
params=params,
data=json.dumps(payload) if payload else payload,
headers=self.headers,
)

response.raise_for_status()
response.encoding = 'utf-8'
Expand Down
Loading

0 comments on commit 2ab9d45

Please sign in to comment.