Skip to content

Commit

Permalink
Added support for Python 3.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Feb 20, 2013
1 parent 4205fb2 commit a220e4c
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 69 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,8 @@ Changes
4.0.0 (unreleased)
==================

- Added support for Python 3.3.

- Replaced deprecated ``zope.component.adapts`` usage with equivalent
``zope.component.adapter`` decorator.

Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,9 @@
include *.rst
include *.txt
include bootstrap.py
include buildout.cfg
include tox.ini

recursive-include src *

global-exclude *.pyc
155 changes: 135 additions & 20 deletions bootstrap.py
Expand Up @@ -18,33 +18,148 @@
use the -c option to specify an alternate configuration file.
"""

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

tmpeggs = tempfile.mkdtemp()

ez = {}
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
).read() in ez
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
import pkg_resources
Bootstraps a buildout-based project.
cmd = 'from setuptools.command.easy_install import main; main()'
if sys.platform == 'win32':
cmd = '"%s"' % cmd # work around spawn lamosity on windows
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
ws = pkg_resources.working_set
assert os.spawnle(
os.P_WAIT, sys.executable, sys.executable,
'-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
dict(os.environ,
PYTHONPATH=
ws.find(pkg_resources.Requirement.parse('setuptools')).location
),
) == 0
Note that by using --setup-source and --download-base to point to
local resources, you can keep this script from going over the network.
'''

parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")

parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))


options, args = parser.parse_args()

######################################################################
# load/install distribute

to_reload = False
try:
import pkg_resources, setuptools
if not hasattr(pkg_resources, '_distribute'):
to_reload = True
raise ImportError
except ImportError:
ez = {}

try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen

exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
ez['use_setuptools'](**setup_args)

if to_reload:
reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)

######################################################################
# Install buildout

ws = pkg_resources.working_set

cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]

find_links = os.environ.get(
'bootstrap-testing-find-links',
options.find_links or
('http://downloads.buildout.org/'
if options.accept_buildout_test_releases else None)
)
if find_links:
cmd.extend(['-f', find_links])

distribute_path = ws.find(
pkg_resources.Requirement.parse('distribute')).location

requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
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):
return False
return True
index = setuptools.package_index.PackageIndex(
search_path=[distribute_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
if index.obtain(req) is not None:
best = []
bestv = None
for dist in index[req.project_name]:
distv = dist.parsed_version
if _final_version(distv):
if bestv is None or distv > bestv:
best = [dist]
bestv = distv
elif distv == bestv:
best.append(dist)
if best:
best.sort()
version = best[-1].version
if version:
requirement = '=='.join((requirement, version))
cmd.append(requirement)

import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
raise Exception(
"Failed to execute command:\n%s",
repr(cmd)[1:-1])

######################################################################
# Import and run buildout

ws.add_entry(tmpeggs)
ws.require('zc.buildout')
ws.require(requirement)
import zc.buildout.buildout
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])

if not [a for a in args if '=' not in a]:
args.append('bootstrap')

# if -c was provided, we push it back into args for buildout' main function
if options.config_file is not None:
args[0:0] = ['-c', options.config_file]

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
7 changes: 0 additions & 7 deletions buildout.cfg
@@ -1,14 +1,7 @@
[buildout]
extends =
http://download.zope.org/zopetoolkit/index/1.1.2/zopeapp-versions.cfg
http://download.zope.org/zopetoolkit/index/1.1.2/ztk-versions.cfg
versions = versions
develop = .
parts = test

[versions]
zope.dublincore =

[test]
recipe = zc.recipe.testrunner
eggs = zope.dublincore [test]
53 changes: 39 additions & 14 deletions setup.py
Expand Up @@ -24,7 +24,20 @@
def read(*path):
return open(os.path.join(*path)).read() + '\n\n'

version = '4.0.0dev'
def alltests():
import os
import sys
import unittest
# use the zope.testrunner machinery to find all the
# test suites we've put under ourselves
import zope.testrunner.find
import zope.testrunner.options
here = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))
args = sys.argv[:]
defaults = ["--test-path", here]
options = zope.testrunner.options.get_options(args, defaults)
suites = list(zope.testrunner.find.find_suites(options))
return unittest.TestSuite(suites)

long_description = (
'.. contents::\n\n' +
Expand All @@ -40,7 +53,7 @@ def read(*path):

setup(
name="zope.dublincore",
version=version,
version='4.0.0dev',
url='http://pypi.python.org/pypi/zope.dublincore',
license='ZPL 2.1',
description='Zope Dublin Core implementation',
Expand All @@ -51,12 +64,15 @@ def read(*path):
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development',
],
Expand All @@ -67,19 +83,28 @@ def read(*path):
include_package_data=True,
extras_require=dict(
test=['zope.testing >= 3.8',
'zope.testrunner',
'zope.annotation',
'zope.configuration',
]
),
install_requires = ['setuptools',
'pytz',
'zope.component[zcml]',
'zope.datetime',
'zope.interface',
'zope.lifecycleevent',
'zope.location',
'zope.schema',
'zope.security[zcml]>=3.8',
],
install_requires = [
'pytz',
'setuptools',
'six',
'zope.component[zcml]',
'zope.datetime',
'zope.interface',
'zope.lifecycleevent',
'zope.location',
'zope.schema',
'zope.security[zcml]>=3.8',
],
tests_require = [
'zope.testing',
'zope.testrunner',
'zope.annotation',
'zope.configuration'],
test_suite = '__main__.alltests',
zip_safe = False
)
9 changes: 8 additions & 1 deletion src/zope/dublincore/annotatableadapter.py
Expand Up @@ -26,9 +26,16 @@
from zope.dublincore.zopedublincore import DateProperty
from zope.dublincore.zopedublincore import ScalarProperty
from zope.dublincore.zopedublincore import ZopeDublinCore
import six

DCkey = "zope.app.dublincore.ZopeDublinCore"

try:
unicode
except NameError:
# Py3: Make unicode available.
unicode = str


@implementer(IWriteZopeDublinCore)
@adapter(IAnnotatable)
Expand Down Expand Up @@ -109,7 +116,7 @@ def __init__(self, context):
# can't use super() since this isn't a globally available class
ZDCAnnotatableAdapter.__init__(self, context)

for dcname, attrname in fieldmap.iteritems():
for dcname, attrname in six.iteritems(fieldmap):
oldprop = ZopeDublinCore.__dict__.get(dcname)
if oldprop is None:
raise ValueError("%r is not a valid DC field" % dcname)
Expand Down
6 changes: 6 additions & 0 deletions src/zope/dublincore/creatorannotator.py
Expand Up @@ -19,6 +19,12 @@
from zope.security.management import queryInteraction
from zope.security.proxy import removeSecurityProxy

try:
unicode
except NameError:
# Py3: Make unicode available.
unicode = str

def CreatorAnnotator(object, event=None):
"""Update Dublin-Core creator property"""
if event is None:
Expand Down
3 changes: 2 additions & 1 deletion src/zope/dublincore/dcterms.py
Expand Up @@ -16,6 +16,7 @@
__docformat__ = 'restructuredtext'

from zope.dublincore import dcsv
import six

# useful namespace URIs
DC_NS = "http://purl.org/dc/elements/1.1/"
Expand Down Expand Up @@ -183,7 +184,7 @@ def check_rfc3066(value):
}

element_to_name = {}
for name, (qname, attrs) in name_to_element.iteritems():
for name, (qname, attrs) in six.iteritems(name_to_element):
prefix, localname = qname.split(":")
elem_name = _prefix_to_ns[prefix], localname
element_to_name[elem_name] = name
Expand Down
4 changes: 2 additions & 2 deletions src/zope/dublincore/property.py
Expand Up @@ -61,7 +61,7 @@ def __set__(self, inst, value):
else:
value = (value,)
field.validate(value)
if field.readonly and inst.__dict__.has_key(name):
if field.readonly and name in inst.__dict__:
raise ValueError(name, 'field is readonly')
setattr(inst, name, value)

Expand Down Expand Up @@ -98,7 +98,7 @@ def __set__(self, inst, value):
if isinstance(field, schema.Tuple):
value = tuple(value)
field.validate(value)
if field.readonly and inst.__dict__.has_key(name):
if field.readonly and name in inst.__dict__:
raise ValueError(name, 'field is readonly')
setattr(inst, name, value)

16 changes: 13 additions & 3 deletions src/zope/dublincore/testing.py
Expand Up @@ -14,11 +14,21 @@
"""Testing support
"""
__docformat__ = 'restructuredtext'

import re
from zope import component
from zope.testing import renormalizing

from .annotatableadapter import ZDCAnnotatableAdapter
from .interfaces import IWriteZopeDublinCore

checker = renormalizing.RENormalizing([
# Python 3 unicode removed the "u".
(re.compile("u('.*?')"),
r"\1"),
(re.compile('u(".*?")'),
r"\1"),
])

from annotatableadapter import ZDCAnnotatableAdapter
from interfaces import IWriteZopeDublinCore

def setUpDublinCore():
component.provideAdapter(ZDCAnnotatableAdapter,
Expand Down

0 comments on commit a220e4c

Please sign in to comment.