Skip to content

Commit

Permalink
Merge pull request #20 from plone/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
jensens authored Oct 23, 2018
2 parents be2a02b + c7ad474 commit 264dbef
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 88 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
1.1.5 (unreleased)
------------------

Prepare for Python 2 / 3 compatibility [jmevissen]

Breaking changes:

- *add item here*
Expand Down
5 changes: 3 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use the -c option to specify an alternate configuration file.
"""

from __future__ import print_function
import os
import shutil
import sys
Expand Down Expand Up @@ -73,7 +74,7 @@

options, args = parser.parse_args()
if options.version:
print("bootstrap.py version %s" % __version__)
print(("bootstrap.py version %s" % __version__))
sys.exit(0)


Expand All @@ -83,7 +84,7 @@
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from six.moves.urllib.request import urlopen

ez = {}
if os.path.exists('ez_setup.py'):
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
keywords='plone debug toolbar',
author='Martin Aspeli',
Expand All @@ -46,6 +48,7 @@
'zope.annotation',
'plone.transformchain',
'Paste',
'six'
],
extras_require={'test': ['plone.app.testing']},
entry_points="""
Expand Down
5 changes: 3 additions & 2 deletions src/plone/app/debugtoolbar/browser/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import types
import inspect
import six

from zope.interface import Interface
from zope.interface import providedBy, directlyProvidedBy
Expand Down Expand Up @@ -44,7 +45,7 @@ def update(self):
generator = getAdapters((self.context, self.request,), Interface)
while True:
try:
name, view = generator.next()
name, view = next(generator)

if not IView.providedBy(view):
continue
Expand Down Expand Up @@ -94,7 +95,7 @@ def update(self):
continue

# FIXME: Should we include ComputedAttribute here ? [glenfant]
if isinstance(attr, (int, long, float, basestring, bool, list, tuple, dict, set, frozenset)):
if isinstance(attr, (int, float, six.string_types, bool, list, tuple, dict, set, frozenset)):
self.variables.append({
'name': name,
'primitive': True,
Expand Down
38 changes: 20 additions & 18 deletions src/plone/app/debugtoolbar/browser/global.pt
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@
This panel shows information about the Zope server where Plone is running.
</p>

<h3 i18n:translate="">Servers</h3>
<tal:servers condition="view/servers">
<h3 i18n:translate="">Servers</h3>

<table class="zebra-striped">
<thead>
<tr>
<th i18n:translate="">Name</th>
<th i18n:translate="">IP</th>
<th i18n:translate="">Port</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="item view/servers">
<td tal:content="item/server_name" />
<td><code tal:content="item/ip" /></td>
<td><code tal:content="item/port" /></td>
</tr>
</tbody>
</table>
<table class="zebra-striped">
<thead>
<tr>
<th i18n:translate="">Name</th>
<th i18n:translate="">IP</th>
<th i18n:translate="">Port</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="item view/servers">
<td tal:content="item/server_name" />
<td><code tal:content="item/ip" /></td>
<td><code tal:content="item/port" /></td>
</tr>
</tbody>
</table>
</tal:servers>

<h3 i18n:translate="">Environment</h3>

Expand All @@ -52,7 +54,7 @@
<td i18n:translate="">Process</td>
<td tal:content="view/appInfo/process_id" />
</tr>
<tr>
<tr tal:condition="view/appInfo/process_time|nothing">
<td i18n:translate="">Running for</td>
<td tal:content="view/appInfo/process_time" />
</tr>
Expand Down
49 changes: 36 additions & 13 deletions src/plone/app/debugtoolbar/browser/global.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from zope.viewlet.viewlet import ViewletBase
from zc.lockfile import LockError

class GlobalViewlet(ViewletBase):

Expand All @@ -20,21 +21,43 @@ def update(self):

self.config.append((name, getattr(config, name)))

self.servers = config.servers
# BBB: import for Zope2
try:
self.servers = config.servers
except AttributeError:
self.servers = []

self.appInfo = self.context.getPhysicalRoot()['Control_Panel']
# BBB: import for Zope2
try:
self.appInfo = self.context.getPhysicalRoot()['Control_Panel']
except KeyError:
self.appInfo = self.context.getPhysicalRoot().Control_Panel

self.databases = []
paths = dict([(x[1], x[0],) for x in config.dbtab.mount_paths.items()])

for name in self.appInfo.Database.getDatabaseNames():
db = self.appInfo.Database[name]
dbtabEntry = config.dbtab.databases[name]

self.databases.append({
'name': name,
'location': db.db_name(),
'size': db.db_size(),
'cacheSize': dbtabEntry.getCacheSize(),
'mount': paths.get(name, None),
})
for db in config.databases:
name = db.name
# BBB: import for Zope2
try:
real_db = self.appInfo.Database[name]
dbtabEntry = config.dbtab.databases[name]

self.databases.append({
'name': name,
'location': real_db.db_name(),
'size': real_db.db_size(),
'cacheSize': dbtabEntry.getCacheSize(),
'mount': paths.get(name, None),
})
except LockError:
# lock error when trying to access database
# https://github.com/zopefoundation/Zope/issues/360
db_config = db.config
self.databases.append({
'name': name,
'location': 'TODO could not access db',
'size': 'TODO could not access db',
'cacheSize': db_config.cache_size,
'mount': paths.get(name, None),
})
3 changes: 2 additions & 1 deletion src/plone/app/debugtoolbar/browser/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cgi
import threading
import traceback
import six

from zope.component import queryMultiAdapter
from zope.publisher.browser import BrowserView
Expand Down Expand Up @@ -133,7 +134,7 @@ def __call__(self):
except:
output = "%s" % traceback.format_exc()

if isinstance(output, unicode):
if isinstance(output, six.text_type):
output = output.encode('ascii', 'xmlcharrefreplace')
elif not isinstance(output, str):
output = repr(output)
Expand Down
6 changes: 4 additions & 2 deletions src/plone/app/debugtoolbar/browser/resources/debugtoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function InteractivePrompt(target, path) {
this.historyPosition = -1;

if (path == undefined) {
path = "./@@plone.app.debugtoolbar.interactive.response";
// path = "./@@plone.app.debugtoolbar.interactive.response";
path = location.href + "/@@plone.app.debugtoolbar.interactive.response";
}
this.path = path;
};
Expand All @@ -53,7 +54,8 @@ function TalesTester(target, path) {
this.historyPosition = -1;

if (path == undefined) {
path = "./@@plone.app.debugtoolbar.interactive.tales";
// path = "./@@plone.app.debugtoolbar.interactive.tales";
path = location.href + "/@@plone.app.debugtoolbar.interactive.tales";
}
this.path = path;
};
Expand Down
1 change: 1 addition & 0 deletions src/plone/app/debugtoolbar/profiles/default/viewlets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
<viewlet name="plone.app.debugtoolbar.versions"/>
<viewlet name="plone.app.debugtoolbar.reload"/>
</order>
<hidden manager="plone.debugtoolbar" skinname="*" purge="True"/>
</object>
19 changes: 8 additions & 11 deletions src/plone/app/debugtoolbar/testing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from plone.app.testing import applyProfile
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import IntegrationTesting
from plone.app.testing import FunctionalTesting
from plone.app.testing import applyProfile

from zope.configuration import xmlconfig

class PloneAppDebugtoolbar(PloneSandboxLayer):

Expand All @@ -14,15 +12,14 @@ class PloneAppDebugtoolbar(PloneSandboxLayer):
def setUpZope(self, app, configurationContext):
# Load ZCML for this package
import plone.app.debugtoolbar
xmlconfig.file('configure.zcml',
plone.app.debugtoolbar,
context=configurationContext)

self.loadZCML(package=plone.app.debugtoolbar)

def setUpPloneSite(self, portal):
applyProfile(portal, 'plone.app.debugtoolbar:default')


PLONE_APP_DEBUGTOOLBAR_FIXTURE = PloneAppDebugtoolbar()
PLONE_APP_DEBUGTOOLBAR_INTEGRATION_TESTING = \
IntegrationTesting(bases=(PLONE_APP_DEBUGTOOLBAR_FIXTURE, ),
name="PloneAppDebugtoolbar:Integration")
PLONE_APP_DEBUGTOOLBAR_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_DEBUGTOOLBAR_FIXTURE, ),
name="PloneAppDebugtoolbar:Integration",
)
26 changes: 0 additions & 26 deletions src/plone/app/debugtoolbar/tests/test_example.py

This file was deleted.

26 changes: 13 additions & 13 deletions src/plone/app/debugtoolbar/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# -*- coding: utf-8 -*-
import unittest

from Products.CMFCore.utils import getToolByName
from plone.app.debugtoolbar.testing import PLONE_APP_DEBUGTOOLBAR_INTEGRATION_TESTING # noqa: E501
from Products.CMFPlone.utils import get_installer

from plone.app.debugtoolbar.testing import\
PLONE_APP_DEBUGTOOLBAR_INTEGRATION_TESTING
import unittest


class TestExample(unittest.TestCase):
class TestSetup(unittest.TestCase):

layer = PLONE_APP_DEBUGTOOLBAR_INTEGRATION_TESTING

def setUp(self):
self.app = self.layer['app']
self.portal = self.layer['portal']
self.qi_tool = getToolByName(self.portal, 'portal_quickinstaller')

self.request = self.layer['request']
self.qi_tool = get_installer(self.portal, self.request)

def test_product_is_installed(self):
""" Validate that our products GS profile has been run and the product
""" Validate that our products GS profile has been run and the product
installed
"""
pid = 'plone.app.debugtoolbar'
installed = [p['id'] for p in self.qi_tool.listInstalledProducts()]
self.assertTrue(pid in installed,
'package appears not to have been installed')
self.assertTrue(
self.qi_tool.is_product_installed(pid),
'package appears not to have been installed',
)

0 comments on commit 264dbef

Please sign in to comment.