Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 #7

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/.pydevproject
/.mr.developer.cfg
/src/plone*
/src/collective*
*.mo
*~
docs/Makefile
docs/make.bat
docs/doctrees
Expand Down
11 changes: 9 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
use the -c option to specify an alternate configuration file.
"""

import os, shutil, sys, tempfile, urllib, urllib2, subprocess
import os
import shutil
import sys
import tempfile
import urllib
import urllib2
import subprocess
from optparse import OptionParser

if sys.platform == 'win32':
Expand Down Expand Up @@ -212,6 +218,7 @@ def normalize_to_url(option, opt_str, value, parser):
import setuptools.package_index
_final_parts = '*final-', '*final'


def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
Expand Down Expand Up @@ -240,7 +247,7 @@ def _final_version(parsed_version):
version = best[-1].version

if version:
requirement += '=='+version
requirement += '==' + version
else:
requirement += '<2dev'

Expand Down
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys
import os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def read(*rnames):
read('docs', 'HISTORY.txt'),
)))


setup(
name='collective.transmogrifier',
version=version,
Expand Down
1 change: 1 addition & 0 deletions src/collective/transmogrifier/genericsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

IMPORT_CONTEXT = 'collective.transmogrifier.genericsetup.import_context'


def importTransmogrifier(context):
"""Run named transmogrifier pipelines read from transmogrifier.txt

Expand Down
16 changes: 9 additions & 7 deletions src/collective/transmogrifier/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import zope.interface


class ITransmogrifier(zope.interface.Interface):
"""The transmogrifier transforms objects through a pipeline"""

context = zope.interface.Attribute("The targeted IFolderish context")

def __call__(self, configuration_id, **overrides):
"""Load and execute the named pipeline configuration

Expand All @@ -13,20 +14,20 @@ def __call__(self, configuration_id, **overrides):
accepted.

"""

def __getitem__(section):
"""Retrieve a section from the pipeline configuration"""

def keys():
"""List all sections in the pipeline configuration"""

def __iter__():
"""Iterate over all the section names in the pipeline configuration"""


class ISectionBlueprint(zope.interface.Interface):
"""Blueprints create pipe sections"""

def __call__(transmogrifier, name, options, previous):
"""Create a named pipe section for a transmogrifier

Expand All @@ -35,9 +36,10 @@ def __call__(transmogrifier, name, options, previous):

"""


class ISection(zope.interface.Interface):
"""A section in a transmogrifier pipe"""

def __iter__():
"""Pipe sections are iterables.

Expand Down
3 changes: 2 additions & 1 deletion src/collective/transmogrifier/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class IRegisterConfigDirective(Interface):
description=u"The pipeline configuration file to register.",
required=True)


_configuration_regs = []


def registerConfig(_context, configuration, name=u'default', title=None,
description=None):
"""Add a new configuration to the registry"""
Expand Down
3 changes: 1 addition & 2 deletions src/collective/transmogrifier/sections/breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# Breaks on a condition.


class BreakpointSection(object):
classProvides(ISectionBlueprint)
implements(ISection)
Expand All @@ -20,7 +19,7 @@ def __init__(self, transmogrifier, name, options, previous):
condition = options['condition']
self.condition = Condition(condition, transmogrifier, name, options)
self.previous = previous

def __iter__(self):
for item in self.previous:
if self.condition(item):
Expand Down
32 changes: 18 additions & 14 deletions src/collective/transmogrifier/sections/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,60 @@
from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.utils import Matcher, Condition


def _get_default_encoding(site):
from Products.CMFPlone.utils import getSiteEncoding
return getSiteEncoding(site)


class CodecSection(object):
classProvides(ISectionBlueprint)
implements(ISection)

from_ = None
from_error_handler = 'strict'
to = None
to_error_handler = 'strict'

def __init__(self, transmogrifier, name, options, previous):
self.previous = previous

if options.get('from'):
from_ = options['from'].strip().lower()
if from_ != 'unicode':
if from_ == 'default':
from_ = _get_default_encoding(transmogrifier.context)

# Test if the decoder is available
codecs.getdecoder(from_)

self.from_ = from_

self.from_error_handler = options.get(
'from-error-handler', self.from_error_handler).strip().lower()
# Test if the error handler is available
codecs.lookup_error(self.from_error_handler)

if options.get('to'):
to = options['to'].strip().lower()
if to != 'unicode':
if to == 'default':
to = _get_default_encoding(transmogrifier.context)

# Test if the encoder is available
codecs.getencoder(to)

self.to = to

self.to_error_handler = options.get(
'to-error-handler', self.to_error_handler).strip().lower()
# Test if the error handler is available
codecs.lookup_error(self.to_error_handler)

self.matcher = Matcher(*options['keys'].splitlines())
self.condition = Condition(options.get('condition', 'python:True'),
transmogrifier, name, options)

def __iter__(self):
from_ = self.from_
if from_ is None:
Expand All @@ -65,9 +67,10 @@ def decode(value):
return value
else:
from_error_handler = self.from_error_handler

def decode(value):
return value.decode(from_, from_error_handler)

to = self.to
if to is None:
def encode(value):
Expand All @@ -76,9 +79,10 @@ def encode(value):
return value
else:
to_error_handler = self.to_error_handler

def encode(value):
return value.encode(to, to_error_handler)

for item in self.previous:
for key in item:
match = self.matcher(key)[1]
Expand Down
5 changes: 3 additions & 2 deletions src/collective/transmogrifier/sections/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.utils import Condition


class ConditionSection(object):
classProvides(ISectionBlueprint)
implements(ISection)

def __init__(self, transmogrifier, name, options, previous):
condition = options['condition']
self.condition = Condition(condition, transmogrifier, name, options)
self.previous = previous

def __iter__(self):
for item in self.previous:
if self.condition(item):
Expand Down
44 changes: 28 additions & 16 deletions src/collective/transmogrifier/sections/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,46 @@
import logging
logger = logging.getLogger('collective.transmogrifier.constructor')


class ConstructorSection(object):
"""
For imports: construct ZODB objects

Needs type information, e.g. created by ... <XXX>

Currently doesn't create missing containers;
see .folders.FoldersSection
"""
classProvides(ISectionBlueprint)
implements(ISection)

def __init__(self, transmogrifier, name, options, previous):
self.previous = previous
self.context = transmogrifier.context
self.ttool = getToolByName(self.context, 'portal_types')
self.typekey = defaultMatcher(options, 'type-key', name, 'type',

self.typekey = defaultMatcher(options, 'type-key', name, 'type',
('portal_type', 'Type'))
self.pathkey = defaultMatcher(options, 'path-key', name, 'path')
self.required = bool(options.get('required'))

def __iter__(self):
for item in self.previous:
keys = item.keys()
typekey = self.typekey(*keys)[0]
pathkey = self.pathkey(*keys)[0]

if not (typekey and pathkey): # not enough info
yield item; continue

yield item
continue

type_, path = item[typekey], item[pathkey]

fti = self.ttool.getTypeInfo(type_)
if fti is None: # not an existing type
yield item; continue

yield item
continue

path = path.encode('ASCII')
container, id = posixpath.split(path.strip('/'))
context = traverse(self.context, container, None)
Expand All @@ -53,16 +64,17 @@ def __iter__(self):
yield item
continue

if getattr(aq_base(context), id, None) is not None: # item exists
yield item; continue

if getattr(aq_base(context), id, None) is not None: # item exists
yield item
continue

obj = fti._constructInstance(context, id)

# For CMF <= 2.1 (aka Plone 3)
if hasattr(fti, '_finishConstruction'):
obj = fti._finishConstruction(obj)

if obj.getId() != id:
item[pathkey] = posixpath.join(container, obj.getId())

yield item
Loading