Skip to content

Commit

Permalink
Merge pull request #26 from NextThought/import-sorts
Browse files Browse the repository at this point in the history
Sort all the imports with isort
  • Loading branch information
papachoco committed Sep 20, 2017
2 parents e0644b9 + 49fbcf7 commit ba1c526
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 385 deletions.
13 changes: 13 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[settings]
multi_line_output = 5
# Do not allow grouped imports
force_single_line = True
line_length = 100
forced_separate = hamcrest
known_third_party = zope, hamcrest
known_first_party = nti
default_section = THIRDPARTY
order_by_type = True
atomic = True
import_heading_stdlib = stdlib imports
force_sort_within_sections = True
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _read(fname):
tests_require=TESTS_REQUIRE,
install_requires=[
'setuptools',
'Acquisition',
'BTrees',
'isodate',
'nti.schema',
Expand All @@ -61,6 +62,7 @@ def _read(fname):
'zope.cachedescriptors',
'zope.component',
'zope.configuration',
'zope.container',
'zope.deferredimport',
'zope.deprecation',
'zope.dottedname',
Expand All @@ -73,6 +75,7 @@ def _read(fname):
'zope.location',
'zope.mimetype',
'zope.preference',
'zope.proxy',
'zope.schema',
'zope.security',
],
Expand Down
8 changes: 6 additions & 2 deletions src/nti/externalization/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
.. $Id$
"""

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

import six

__docformat__ = "restructuredtext en"

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

import six

if six.PY3: # pragma: no cover
def _unicode(s): return str(s)
Expand Down
5 changes: 4 additions & 1 deletion src/nti/externalization/_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
.. $Id$
"""

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

__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)
Expand Down
19 changes: 12 additions & 7 deletions src/nti/externalization/autopackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
.. $Id$
"""

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

from ZODB.loglevels import TRACE
from zope import interface
from zope.dottedname import resolve as dottedname
from zope.mimetype.interfaces import IContentTypeAware

from nti.externalization.datastructures import ModuleScopedInterfaceObjectIO
from nti.externalization.internalization import register_legacy_search_module

__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)
Expand All @@ -14,17 +25,11 @@
# is probably not what we want
# import ExtensionClass

from zope import interface

from zope.dottedname import resolve as dottedname

from zope.mimetype.interfaces import IContentTypeAware

from ZODB.loglevels import TRACE

from nti.externalization.datastructures import ModuleScopedInterfaceObjectIO

from nti.externalization.internalization import register_legacy_search_module


class AutoPackageSearchingScopedInterfaceObjectIO(ModuleScopedInterfaceObjectIO):
Expand Down
31 changes: 13 additions & 18 deletions src/nti/externalization/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,31 @@
.. $Id$
"""

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

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

import six
import sys
# stdlib imports
import numbers

from zope import schema
from ZODB.POSException import POSError
import six
from zope import interface

from zope import schema
import zope.deferredimport
from zope.schema.interfaces import SchemaNotProvided

from ZODB.POSException import POSError

from nti.externalization.externalization import toExternalObject
from nti.externalization.externalization import to_standard_external_dictionary
from nti.externalization.externalization import to_minimal_standard_external_dictionary

from nti.externalization.externalization import to_standard_external_dictionary
from nti.externalization.externalization import toExternalObject
from nti.externalization.interfaces import IInternalObjectIO
from nti.externalization.interfaces import StandardInternalFields
from nti.externalization.interfaces import StandardExternalFields

from nti.externalization.interfaces import StandardInternalFields
from nti.externalization.internalization import validate_named_field_value

from nti.schema.interfaces import find_most_derived_interface

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


def _syntheticKeys():
return ('OID', 'ID', 'Last Modified', 'Creator', 'ContainerId', 'Class')
Expand Down Expand Up @@ -535,9 +532,7 @@ def _ext_schemas_to_consider(self, ext_self):
if x.__module__ == self._ext_search_module.__name__
and not x.queryTaggedValue('_ext_is_marker_interface'))


# Things that have moved
import zope.deferredimport
zope.deferredimport.initialize()
zope.deferredimport.deprecatedFrom(
"Moved to nti.externalization.interfaces",
Expand Down
12 changes: 5 additions & 7 deletions src/nti/externalization/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
See the :mod:`datetime` module, as well as the :mod:`zope.interface.common.idatetime`
module for types of objects.
.. $Id$
"""

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

# stdlib imports
from datetime import datetime
import sys
import time
from datetime import datetime

import isodate
import pytz
import six

from zope import component
from zope import interface

from zope.interface.common.idatetime import IDate
from zope.interface.common.idatetime import IDateTime
from zope.interface.common.idatetime import ITimeDelta

from nti.externalization.interfaces import IInternalObjectExternalizer

from nti.schema.interfaces import InvalidValue


Expand Down
13 changes: 5 additions & 8 deletions src/nti/externalization/dublincore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@
.. $Id$
"""

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

logger = __import__('logging').getLogger(__name__)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from zope import component
from zope import interface

from zope.dublincore.interfaces import IDCExtended
from zope.dublincore.interfaces import IDCDescriptiveProperties
from zope.dublincore.interfaces import IDCExtended

from nti.externalization.interfaces import StandardExternalFields
from nti.externalization.interfaces import IExternalMappingDecorator

from nti.externalization.interfaces import StandardExternalFields
from nti.externalization.singleton import SingletonDecorator


Expand Down
81 changes: 25 additions & 56 deletions src/nti/externalization/externalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,47 @@
.. $Id$
"""

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

import numbers
# stdlib imports
from calendar import timegm as _calendar_gmtime
import collections
from collections import defaultdict
import numbers

import BTrees.OOBTree
from ZODB.POSException import POSKeyError
import persistent
import six
from six import iteritems

from zope import component
from zope import interface
from zope import deprecation

from zope import interface
from zope.cachedescriptors.property import CachedProperty
import zope.deferredimport
from zope.dublincore.interfaces import IDCTimes
from zope.hookable import hookable

from zope.interface.common.sequence import IFiniteSequence

from zope.dublincore.interfaces import IDCTimes

from zope.security.interfaces import IPrincipal
from zope.security.management import system_user

from ZODB.POSException import POSKeyError

import persistent

import BTrees.OOBTree

from nti.externalization._compat import to_unicode

from nti.externalization._pyramid import ThreadLocalManager
from nti.externalization._pyramid import get_current_request
from nti.externalization.interfaces import IExternalMappingDecorator
from nti.externalization.interfaces import IExternalObject
from nti.externalization.interfaces import LocatedExternalDict
from nti.externalization.interfaces import StandardExternalFields
from nti.externalization.interfaces import StandardInternalFields
from nti.externalization.interfaces import IExternalObjectDecorator
from nti.externalization.interfaces import ILocatedExternalSequence
from nti.externalization.interfaces import IExternalMappingDecorator
from nti.externalization.interfaces import INonExternalizableReplacer
from nti.externalization.interfaces import INonExternalizableReplacement

from nti.externalization.interfaces import INonExternalizableReplacer
from nti.externalization.interfaces import LocatedExternalDict
from nti.externalization.interfaces import StandardExternalFields
from nti.externalization.interfaces import StandardInternalFields
from nti.externalization.oids import to_external_oid


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

# Local for speed
Expand Down Expand Up @@ -81,7 +79,6 @@ def is_system_user(obj):
# the name that was established at the top level.
_NotGiven = object()

from nti.externalization._pyramid import ThreadLocalManager

_manager = ThreadLocalManager(default=lambda: {'name': _NotGiven, 'memos': None})

Expand Down Expand Up @@ -143,7 +140,6 @@ def _DevmodeNonExternalizableObjectReplacer(_):
BTrees.OOBTree.OOBTree,
collections.Mapping)

from zope.cachedescriptors.property import CachedProperty


class _ExternalizationState(object):
Expand Down Expand Up @@ -310,8 +306,7 @@ def toExternalObject(obj,
decorate=True,
useCache=True,
decorate_callback=None,
default_non_externalizable_replacer=DefaultNonExternalizableReplacer,
**kwargs):
default_non_externalizable_replacer=DefaultNonExternalizableReplacer):
"""
Translates the object into a form suitable for
external distribution, through some data formatting process. See :const:`SEQUENCE_TYPES`
Expand Down Expand Up @@ -344,8 +339,7 @@ def toExternalObject(obj,
return obj

v = dict(locals())
v.pop('obj', None)
[v.pop(x, None) for x in kwargs]
v.pop('obj')
state = _ExternalizationState(**v)

if name is _NotGiven:
Expand All @@ -357,9 +351,7 @@ def toExternalObject(obj,
if memos is None:
memos = defaultdict(dict)

data = dict(kwargs)
data.update({'name': name, 'memos': memos})
_manager.push(data)
_manager.push({'name': name, 'memos': memos})

state.name = name
state.memo = memos[name]
Expand All @@ -377,26 +369,6 @@ def toExternalObject(obj,
to_external_object = toExternalObject


def get_externals():
"""
Return the externalization params
"""
state = dict(_manager.get())
[state.pop(x, None) for x in ('request', 'registry', 'name', 'memos')]
return state
getExternals = get_externals


def get_external_param(name, default=None):
"""
Return the currently value for an externalization param or default
"""
try:
return get_externals()[name]
except KeyError:
return default
getExternalParam = get_external_param


def stripSyntheticKeysFromExternalDictionary(external):
"""
Expand All @@ -421,7 +393,6 @@ def _isMagicKey(key):
isSyntheticKey = _isMagicKey


from calendar import timegm as _calendar_gmtime


def datetime_to_epoch(dt):
Expand Down Expand Up @@ -524,7 +495,6 @@ def _ext_class_if_needed(self, result):
result[StandardExternalFields_CLASS] = self.__class__.__name__


from nti.externalization._pyramid import get_current_request


def setExternalIdentifiers(self, result):
Expand Down Expand Up @@ -662,9 +632,8 @@ def _clean(m):
_clean(ext)
return ext


# Things that have moved
import zope.deferredimport

zope.deferredimport.initialize()
zope.deferredimport.deprecatedFrom(
"Import from .persistence",
Expand Down
Loading

0 comments on commit ba1c526

Please sign in to comment.