Skip to content

Commit

Permalink
Merge d1ea6e0 into ba1c526
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 21, 2017
2 parents ba1c526 + d1ea6e0 commit 0026028
Show file tree
Hide file tree
Showing 36 changed files with 2,842 additions and 709 deletions.
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[run]
source = nti.externalization

omit =
*/flycheck_*py

[report]
exclude_lines =
pragma: no cover
raise NotImplementedError
raise AssertionError
if __name__ == .__main__.:
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
- Add support for Python 3.
- Drop support for externalizing to plists. See
https://github.com/NextThought/nti.externalization/issues/21
- Reach 100% test coverage and ensure we remain there through CI.
12 changes: 10 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ Datastructures
==============

.. automodule:: nti.externalization.datastructures
:private-members:

Datetime
==========
========

.. automodule:: nti.externalization.datetime

Expand All @@ -43,7 +44,7 @@ Internalization
.. automodule:: nti.externalization.internalization

OIDs
===============
====

.. automodule:: nti.externalization.oids

Expand Down Expand Up @@ -71,3 +72,10 @@ ZCML
====

.. automodule:: nti.externalization.zcml

Package IO
==========

.. automodule:: nti.externalization.autopackage
:private-members:
:special-members:
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
#'https://ntiwref.readthedocs.io/en/latest': None,
'https://persistent.readthedocs.io/en/latest': None,
'https://zopecomponent.readthedocs.io/en/latest': None,
'https://zopedublincore.readthedocs.io/en/latest': None,
'https://zodb.readthedocs.io/en/latest': None,
}

Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ def _read(fname):
'zope.security',
],
extras_require={
':platform_python_implementation=="CPython"': [
'cytoolz >= 0.8.2',
],
':platform_python_implementation=="PyPy"': [
'toolz',
],
'test': TESTS_REQUIRE,
'docs': [
'Sphinx',
'repoze.sphinx.autointerface',
'sphinx_rtd_theme',
]
],

},
entry_points=entry_points,
)
7 changes: 1 addition & 6 deletions src/nti/externalization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. $Id$
Externalization
"""

from __future__ import print_function, absolute_import, division
__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)
45 changes: 9 additions & 36 deletions src/nti/externalization/_compat.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. $Id$
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import six

__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)


if six.PY3: # pragma: no cover
def _unicode(s): return str(s)
else:
_unicode = unicode


def to_unicode(s, encoding='utf-8', err='strict'):
"""
Decode a byte sequence and unicode result
"""
s = s.decode(encoding, err) if isinstance(s, bytes) else s
return _unicode(s) if s is not None else None
return s.decode(encoding, err) if isinstance(s, bytes) else s

text_ = to_unicode


Expand All @@ -35,26 +23,11 @@ def bytes_(s, encoding='utf-8', errors='strict'):
If ``s`` is an instance of ``text_type``, return
``s.encode(encoding, errors)``, otherwise return ``s``
"""
if isinstance(s, six.text_type):
return s.encode(encoding, errors)
if not isinstance(s, bytes) and s is not None:
s = s.encode(encoding, errors)
return s


if six.PY3:
def native_(s, encoding='latin-1', errors='strict'):
"""
If ``s`` is an instance of ``text_type``, return
``s``, otherwise return ``str(s, encoding, errors)``
"""
if isinstance(s, six.text_type):
return s
return str(s, encoding, errors)
else:
def native_(s, encoding='latin-1', errors='strict'):
"""
If ``s`` is an instance of ``text_type``, return
``s.encode(encoding, errors)``, otherwise return ``str(s)``
"""
if isinstance(s, six.text_type):
return s.encode(encoding, errors)
return str(s)
try:
from cytoolz import identity
except ImportError: # PyPy pragma: no cover
from toolz import identity
56 changes: 25 additions & 31 deletions src/nti/externalization/_pyramid.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. $Id$
Extension points for connecting to Pyramid.
XXX TODO: Define get_current_request as a zope.hookable function
and let the application determine what framework to connect to.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)
# stdlib imports
import threading

try:
from pyramid.threadlocal import ThreadLocalManager
from pyramid.threadlocal import get_current_request

ThreadLocalManager = ThreadLocalManager
get_current_request = get_current_request

except ImportError:
import threading

class ThreadLocalManager(threading.local):

def __init__(self, default=None):
self.stack = []
self.default = default
def get_current_request():
return None
else: # pragma: no cover
get_current_request = get_current_request

def push(self, info):
self.stack.append(info)
class ThreadLocalManager(threading.local):

set = push # b/c
def __init__(self, default=None):
self.stack = []
self.default = default

def pop(self):
if self.stack:
return self.stack.pop()
def push(self, info):
self.stack.append(info)

def get(self):
try:
return self.stack[-1]
except IndexError:
return self.default()
set = push # b/c

def clear(self):
self.stack[:] = []
def pop(self):
if self.stack:
return self.stack.pop()

def get_current_request():
return None
def get(self):
try:
return self.stack[-1]
except IndexError:
return self.default()
Loading

0 comments on commit 0026028

Please sign in to comment.