forked from paylogic/pip-accel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Boto workaround only on Python 3.x (issue paylogic#68)
Refer to issue 68 on GitHub for details: paylogic#68
- Loading branch information
Showing
3 changed files
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Accelerator for pip, the Python package manager. | ||
# | ||
# Author: Peter Odding <[email protected]> | ||
# Last Change: February 19, 2016 | ||
# Last Change: March 4, 2016 | ||
# URL: https://github.com/paylogic/pip-accel | ||
# | ||
# TODO Permanently store logs in the pip-accel directory (think about log rotation). | ||
|
@@ -77,7 +77,7 @@ | |
from pip.req import InstallRequirement | ||
|
||
# Semi-standard module versioning. | ||
__version__ = '0.42.4' | ||
__version__ = '0.42.5' | ||
|
||
# Initialize a logger for this module. | ||
logger = logging.getLogger(__name__) | ||
|
@@ -781,27 +781,34 @@ class PatchedAttribute(object): | |
exited. | ||
""" | ||
|
||
def __init__(self, object, attribute, value): | ||
def __init__(self, object, attribute, value, enabled=True): | ||
""" | ||
Initialize a :class:`PatchedAttribute` object. | ||
:param object: The object whose attribute should be patched. | ||
:param attribute: The name of the attribute to be patched (a string). | ||
:param value: The temporary value for the attribute. | ||
:param enabled: :data:`True` to patch the attribute, :data:`False` to | ||
do nothing instead. This enables conditional attribute | ||
patching while unconditionally using the | ||
:keyword:`with` statement. | ||
""" | ||
self.object = object | ||
self.attribute = attribute | ||
self.patched_value = value | ||
self.original_value = None | ||
self.enabled = enabled | ||
|
||
def __enter__(self): | ||
"""Change the object attribute when entering the context.""" | ||
self.original_value = getattr(self.object, self.attribute) | ||
setattr(self.object, self.attribute, self.patched_value) | ||
if self.enabled: | ||
self.original_value = getattr(self.object, self.attribute) | ||
setattr(self.object, self.attribute, self.patched_value) | ||
|
||
def __exit__(self, exc_type=None, exc_value=None, traceback=None): | ||
"""Restore the object attribute when leaving the context.""" | ||
setattr(self.object, self.attribute, self.original_value) | ||
if self.enabled: | ||
setattr(self.object, self.attribute, self.original_value) | ||
|
||
|
||
class AttributeOverrides(object): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# Authors: | ||
# - Adam Feuer <[email protected]> | ||
# - Peter Odding <[email protected]> | ||
# Last Change: November 8, 2015 | ||
# Last Change: March 4, 2016 | ||
# URL: https://github.com/paylogic/pip-accel | ||
# | ||
# A word of warning: Do *not* use the cached_property decorator here, because | ||
|
@@ -99,7 +99,7 @@ | |
# Modules included in our package. | ||
from pip_accel import PatchedAttribute | ||
from pip_accel.caches import AbstractCacheBackend | ||
from pip_accel.compat import urlparse | ||
from pip_accel.compat import PY3, urlparse | ||
from pip_accel.exceptions import CacheBackendDisabledError, CacheBackendError | ||
from pip_accel.utils import AtomicReplace, makedirs | ||
|
||
|
@@ -361,6 +361,7 @@ def __init__(self): | |
object=Config, | ||
attribute='get', | ||
value=self.get, | ||
enabled=PY3, | ||
) | ||
|
||
def get(self, section, name, default=None, **kw): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Accelerator for pip, the Python package manager. | ||
# | ||
# Author: Peter Odding <[email protected]> | ||
# Last Change: November 8, 2015 | ||
# Last Change: March 4, 2016 | ||
# URL: https://github.com/paylogic/pip-accel | ||
|
||
"""Operating system detection and Python version compatibility.""" | ||
|
@@ -31,10 +31,12 @@ | |
from StringIO import StringIO | ||
from urllib import pathname2url | ||
from urlparse import urljoin, urlparse | ||
PY3 = False | ||
except (ImportError, NameError): | ||
# Python 3. | ||
basestring = str | ||
import configparser | ||
from io import StringIO | ||
from urllib.parse import urljoin, urlparse | ||
from urllib.request import pathname2url | ||
PY3 = True |