Skip to content

Commit

Permalink
autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Dec 10, 2015
1 parent 63437f9 commit 151405a
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 202 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ New:

Fixes:

- PEP 8.
[thet]

- Depend on zope.testrunner, which was moved out from
zope.testing.testrunner.
[thet]
Expand Down
158 changes: 80 additions & 78 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,91 +1,93 @@
# -*- coding: utf-8 -*-
import os
import os.path
import sys
from setuptools import setup, find_packages

version = '4.1.0.dev0'

install_requires = ['setuptools',
'zope.testing',
]
install_requires = [
'setuptools',
'zope.testing',
]


if sys.version_info < (2, 7):
install_requires.append('unittest2')

tests_require = ['zope.component',
'zope.interface',
'zope.publisher',
'zope.security',
'zope.event',
'zope.configuration',
'zope.testbrowser',
'zope.testrunner',
'zope.app.publisher', # XXX: Can probably go away in Zope 2.13
'ZODB3',
'Zope2',
]
tests_require = [
'zope.component',
'zope.interface',
'zope.publisher',
'zope.security',
'zope.event',
'zope.configuration',
'zope.testbrowser',
'zope.testrunner',
'zope.app.publisher', # XXX: Can probably go away in Zope 2.13
'ZODB3',
'Zope2',
]

setup(name='plone.testing',
version=version,
description="Testing infrastructure for Zope and Plone projects.",
long_description=(open(os.path.join("src", "plone", "testing", "README.rst")).read() + "\n\n" +
open("CHANGES.rst").read() + "\n\n" +
"Detailed documentation\n" +
"======================\n\n" +
open(os.path.join("src", "plone", "testing", "layer.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "zca.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "security.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "publisher.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "zodb.txt")).read()),
classifiers=[
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: 4.2",
"Framework :: Plone :: 4.3",
"Framework :: Plone :: 5.0",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"License :: OSI Approved :: BSD License",
],
keywords='plone zope testing',
author='Plone Foundation',
author_email='plone-developers@lists.sourceforge.net',
url='https://github.com/plone/plone.testing',
license='BSD',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['plone'],
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'test': tests_require,
'zodb': [
'ZODB3',
],
'zca': [
'zope.component',
'zope.event',
'zope.configuration',
],
'security': [
'zope.security',
],
'publisher': [
'zope.configuration',
'zope.security',
'zope.app.publisher', # XXX: Can probably go away in Zope 2.13
],
'z2': [
'Zope2',
'zope.site',
'zope.testbrowser',
'zope.publisher',
],
},
)
setup(
name='plone.testing',
version=version,
description="Testing infrastructure for Zope and Plone projects.",
long_description=(open(os.path.join("src", "plone", "testing", "README.rst")).read() + "\n\n" +
open("CHANGES.rst").read() + "\n\n" +
"Detailed documentation\n" +
"======================\n\n" +
open(os.path.join("src", "plone", "testing", "layer.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "zca.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "security.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "publisher.txt")).read() + "\n\n" +
open(os.path.join("src", "plone", "testing", "zodb.txt")).read()),
classifiers=[
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: 4.2",
"Framework :: Plone :: 4.3",
"Framework :: Plone :: 5.0",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"License :: OSI Approved :: BSD License",
],
keywords='plone zope testing',
author='Plone Foundation',
author_email='plone-developers@lists.sourceforge.net',
url='https://github.com/plone/plone.testing',
license='BSD',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['plone'],
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'test': tests_require,
'zodb': ['ZODB3'],
'zca': [
'zope.component',
'zope.event',
'zope.configuration',
],
'security': [
'zope.security',
],
'publisher': [
'zope.configuration',
'zope.security',
'zope.app.publisher', # XXX: Can probably go away in Zope 2.13
],
'z2': [
'Zope2',
'zope.site',
'zope.testbrowser',
'zope.publisher',
],
},
)
1 change: 1 addition & 0 deletions src/plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
8 changes: 3 additions & 5 deletions src/plone/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Convenience imports

from plone.testing.layer import (
Layer,
layered
)
from plone.testing.layer import Layer # noqa
from plone.testing.layer import layered # noqa
62 changes: 44 additions & 18 deletions src/plone/testing/_z2_testbrowser.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import sys
import re
# -*- coding: utf-8 -*-
from cStringIO import StringIO
import base64
import mechanize
import pkg_resources
import re
import rfc822
import sys
import urllib
import urllib2

from cStringIO import StringIO

import mechanize
import pkg_resources

# Using a from-import here to avoid an AttributeError below when using
# zope.testbrowser 4.x without zope.app.testing:
from zope.testbrowser.testing import PublisherConnection, PublisherResponse
Expand All @@ -18,6 +17,7 @@

try:
pkg_resources.get_distribution('Zope2>=2.13')

def get_cookies(request):
return request.response._cookie_list()
except (pkg_resources.VersionConflict, pkg_resources.DistributionNotFound):
Expand All @@ -31,15 +31,30 @@ class Browser(zope.testbrowser.browser.Browser):
"""

def __init__(self, app, url=None):
super(Browser, self).__init__(url=url, mech_browser=Zope2MechanizeBrowser(app))
super(
Browser,
self).__init__(
url=url,
mech_browser=Zope2MechanizeBrowser(app))


class Zope2MechanizeBrowser(mechanize.Browser):
"""A mechanize browser class that uses the Zope 2 publisher to talk HTTP
"""

default_schemes = ['http']
default_others = ['_http_error', '_http_request_upgrade', '_http_default_error']
default_features = ['_redirect', '_cookies', '_referer', '_refresh','_equiv', '_basicauth', '_digestauth' ]
default_schemes = ['http']
default_others = [
'_http_error',
'_http_request_upgrade',
'_http_default_error']
default_features = [
'_redirect',
'_cookies',
'_referer',
'_refresh',
'_equiv',
'_basicauth',
'_digestauth']

def __init__(self, app, *args, **kws):

Expand All @@ -52,6 +67,7 @@ def httpHandlerFactory():
if cls in mechanize.Browser.handler_classes]
mechanize.Browser.__init__(self, *args, **kws)


class Zope2HTTPHandler(urllib2.HTTPHandler):
"""A protocol handler that uses the Zope 2 publisher to talk HTTP
"""
Expand All @@ -65,6 +81,7 @@ def connectionFactory(host, timeout=None):
return Zope2Connection(self.app, host, timeout=timeout)
return self.do_open(connectionFactory, req)


class Zope2Connection(PublisherConnection):
"""A urllib2-compatible connection that can talk to the Zope 2 publisher.
"""
Expand Down Expand Up @@ -92,9 +109,11 @@ def getresponse(self):
# only change non-literal header names
key = "%s%s" % (key[:1].upper(), key[1:])
start = 0
l = key.find('-',start)
l = key.find('-', start)
while l >= start:
key = "%s-%s%s" % (key[:l],key[l+1:l+2].upper(),key[l+2:])
key = "%s-%s%s" % (key[:l],
key[l + 1:l + 2].upper(),
key[l + 2:])
start = l + 1
l = key.find('-', start)
headers.append((key, val))
Expand All @@ -109,6 +128,7 @@ def getresponse(self):

return PublisherResponse(content, headers, status, reason)


def saveState(func):
"""Save threadlocal state (security manager, local component site) before
exectuting a decorated function, and restore it after.
Expand All @@ -128,10 +148,14 @@ def wrapped_func(*args, **kw):
return wrapped_func

HEADER_RE = re.compile('(\S+): (.+)$')


def splitHeader(header):
return HEADER_RE.match(header).group(1, 2)

BASIC_RE = re.compile('Basic (.+)?:(.+)?$')


def authHeader(header):
match = BASIC_RE.match(header)
if match:
Expand All @@ -144,6 +168,7 @@ def authHeader(header):
return 'Basic %s' % auth[:-1]
return header


class Zope2Caller(object):
"""Functional testing caller that can execute HTTP requests via the
Zope 2 publisher.
Expand Down Expand Up @@ -172,7 +197,7 @@ def setBody(self, body, title='', is_error=0, **kw):
# Split off and parse the command line
l = requestString.find('\n')
commandLine = requestString[:l].rstrip()
requestString = requestString[l+1:]
requestString = requestString[l + 1:]
method, url, protocol = commandLine.split()

instream = StringIO(requestString)
Expand All @@ -189,14 +214,15 @@ def setBody(self, body, title='', is_error=0, **kw):
elif len(p) == 2:
[env['PATH_INFO'], env['QUERY_STRING']] = p
else:
raise TypeError, ''
raise TypeError('')

# If you followed closely, you notice that one part of the url
# gets unquoted (PATH_INFO) while the other (QUERY_STRING)
# doesn't That complies with what the ZSERVER does.
env['PATH_INFO'] = urllib.unquote(env['PATH_INFO'])

headers = [splitHeader(header) for header in rfc822.Message(instream).headers]
headers = [splitHeader(header)
for header in rfc822.Message(instream).headers]

# Store request body without headers
instream = StringIO(instream.read())
Expand All @@ -207,7 +233,7 @@ def setBody(self, body, title='', is_error=0, **kw):
name = 'HTTP_' + name
env[name] = value.rstrip()

if env.has_key('HTTP_AUTHORIZATION'):
if 'HTTP_AUTHORIZATION' in env:
env['HTTP_AUTHORIZATION'] = authHeader(env['HTTP_AUTHORIZATION'])

outstream = StringIO()
Expand All @@ -218,7 +244,7 @@ def setBody(self, body, title='', is_error=0, **kw):
stdin=instream,
environ=env,
debug=not handle_errors,
)
)

self.app._p_jar.sync()

Expand Down
Loading

0 comments on commit 151405a

Please sign in to comment.