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

Imports are Python3 compatible #70

Merged
merged 4 commits into from
Feb 6, 2018
Merged
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
syntax: glob
*.egg-info
*.mo
*.swp
*.pyc
*.py.bak
.DS_Store
.idea
.installed.cfg
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Breaking changes:

New features:

- *add item here*
- Imports are Python3 compatible. Add six into install_requires set and sort
each file's imports with the isort package.
[b4oshany, @davilima6]

Bug fixes:

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from setuptools import setup
from setuptools import find_packages
from setuptools import setup

import sys

version = '1.1.3.dev0'
Expand Down Expand Up @@ -53,6 +54,7 @@ def indent(line):
'robotsuite', # not a direct dependency, but required for convenience
'selenium',
'setuptools',
'six',
'zope.component',
'zope.configuration',
'zope.i18n',
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/robotframework/autologin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def set_autologin_username(self, username):
raise Exception(u"Autologin is not enabled")
if len(self.acl_users.robot_login._domain_map) == 0:
raise Exception(u"Autologin is not enabled")
domain_map_key = self.acl_users.robot_login._domain_map.keys()[0]
domain_map_key = list(self.acl_users.robot_login._domain_map.keys())[0]
domain_map = self.acl_users.robot_login._domain_map[domain_map_key]
domain_map[0]['username'] = username
self.acl_users.robot_login._domain_map[domain_map_key] = domain_map
Expand Down
16 changes: 9 additions & 7 deletions src/plone/app/robotframework/content.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import os

from Products.CMFCore.utils import getToolByName
from plone.app.robotframework.config import HAS_BLOBS
from plone.app.robotframework.config import HAS_DEXTERITY
from plone.app.robotframework.config import HAS_DEXTERITY_RELATIONS
from plone.app.robotframework.remote import RemoteLibrary
from plone.app.robotframework.utils import disableCSRFProtection
from plone.i18n.normalizer.interfaces import IURLNormalizer
from plone.uuid.interfaces import IUUID
from Products.CMFCore.utils import getToolByName
from zope.component import ComponentLookupError
from zope.component import getUtility
from zope.component import queryUtility
Expand All @@ -18,6 +16,10 @@
from zope.globalrequest import getRequest
from zope.lifecycleevent import ObjectModifiedEvent

import os
import six


if HAS_DEXTERITY:
from plone.app.textfield.value import RichTextValue

Expand Down Expand Up @@ -137,10 +139,10 @@ def create_content(self, *args, **kwargs):
if widget and name in kwargs:
if not IFromUnicode.providedBy(field):
value = kwargs[name]
elif isinstance(kwargs[name], unicode):
elif isinstance(kwargs[name], six.text_type):
value = kwargs[name]
else:
value = unicode(str(kwargs[name]), 'utf-8',
value = six.text_type(str(kwargs[name]), 'utf-8',
errors='ignore')
converter = IDataConverter(widget)
dm = queryMultiAdapter((content, field), IDataManager)
Expand Down Expand Up @@ -283,7 +285,7 @@ def prefill_image_types(portal, kwargs):

def random_image():
import random
import StringIO
from six import StringIO
from PIL import Image
from PIL import ImageDraw

Expand All @@ -300,7 +302,7 @@ def random_image():
)
del draw

result = StringIO.StringIO()
result = StringIO()
img.save(result, 'PNG')
result.seek(0)
return result
Expand Down
9 changes: 7 additions & 2 deletions src/plone/app/robotframework/pybabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def populate(self):
if self._value or self._comments:
self._setter(self._value, self._comments.value)
try:
parts = map(unicode.lower, self._value)
parts = map(six.text_type.lower, self._value)
index = parts.index('translate')
comments = []
for part in filter(lambda x: x.startswith('default='), self._value):
Expand All @@ -19,10 +19,15 @@ def populate(self):
except IndexError:
pass

import robot
import robot.parsing.tablepopulators
import six


robot.parsing.tablepopulators.StepPopulator.populate = populate

import robot




def extract_robot(fileobj, keywords, comment_tags, options):
Expand Down
36 changes: 18 additions & 18 deletions src/plone/app/robotframework/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start(self):
registerHandler(signal.SIGTERM, self._exitHandler)

for path in self.paths:
print WAIT("Watchdog is watching for changes in %s" % path)
print(WAIT("Watchdog is watching for changes in %s" % path))
observer = Observer()
self.observers.append(observer)
observer.schedule(self, path=path, recursive=True)
Expand All @@ -62,16 +62,16 @@ def on_any_event(self, event):
break

if self.last_event + self.minimum_wait < time.time():
print WAIT("Watchdog got %s event on %s"
% (event_type, event_relpath))
print(WAIT("Watchdog got %s event on %s"
% (event_type, event_relpath)))
try:
self.forkloop.forkNewChild()
self.last_event = time.time()
except Exception as e:
print ERROR(str(e))
print(ERROR(str(e)))
else:
print WAIT("Watchdog skipped %s event on %s"
% (event_type, event_relpath))
print(WAIT("Watchdog skipped %s event on %s"
% (event_type, event_relpath)))


class ForkLoop(object):
Expand Down Expand Up @@ -132,7 +132,7 @@ def loop(self):

self.active = True

print WAIT("Fork loop now starting on parent process %i" % os.getpid())
print(WAIT("Fork loop now starting on parent process %i" % os.getpid()))
while True:
self.forking = False

Expand All @@ -147,12 +147,12 @@ def loop(self):
continue

if not self.killed_child:
print ERROR(
print(ERROR(
"Forked child process died on bootup. "
"Fix possible errors and save edits. "
"We are now paused until we detect the next file "
"change..."
)
))

# Child died because of unknown reason. Mark it as killed
# and go into pause mode.
Expand All @@ -175,7 +175,7 @@ def loop(self):

self.forking = False

print WAIT("Fork loop forked a new child process %i" % (os.getpid()))
print(WAIT("Fork loop forked a new child process %i" % (os.getpid())))

def forkNewChild(self):
"""STEP 1 (parent): New child process forking starts by killing the
Expand All @@ -201,7 +201,7 @@ def forkNewChild(self):
else:
# Ok, we already have sent the SIGINT the child, but asking for new
# child
print WAIT("Fork loop scheduling a new fork")
print(WAIT("Fork loop scheduling a new fork"))
self._scheduleFork()

self.killed_child = True
Expand All @@ -226,8 +226,8 @@ def _parentExitHandler(self, signum=None, frame=None):

while self.isChildAlive():
# XXX: Somehow this may get stuck if we don't print before kill
print WAIT("Fork loop is terminating its child process %s" %
self.child_pid)
print(WAIT("Fork loop is terminating its child process %s" %
self.child_pid))
self._killChild()
time.sleep(2)

Expand Down Expand Up @@ -259,14 +259,14 @@ def _waitChildToDieAndScheduleNew(self, signal=None, frame=None):
exit_flags.append("exited with code %d" % code)

if exit_status == 0:
print WAIT("Fork loop terminated child process %d" % pid)
print(WAIT("Fork loop terminated child process %d" % pid))

elif exit_flags:
print ERROR("Forked child process %d %s"
% (pid, ", ".join(exit_flags)))
print(ERROR("Forked child process %d %s"
% (pid, ", ".join(exit_flags))))
else:
print ERROR("Forked child process %d exited with code %s"
% (pid, exit_status))
print(ERROR("Forked child process %d exited with code %s"
% (pid, exit_status)))

except OSError:
# OSError: [Errno 10] No child processes
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/robotframework/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run_keyword(self, name, args, kwargs={}):
result = {'error': '', 'return': ''}
try:
retval = func(*args, **kwargs)
except Exception, e:
except Exception as e:
result['status'] = 'FAIL'
result['error'] = str(e)
else:
Expand Down
8 changes: 4 additions & 4 deletions src/plone/app/robotframework/robotentrypoints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys

from __future__ import print_function
from robot import run_cli
from robot import libdoc as ld

import pkg_resources
import sys

try:
pkg_resources.get_distribution('robotframework-ride')
Expand Down Expand Up @@ -47,7 +47,7 @@ def ride():
from robotide import main
main(*sys.argv[1:])
else:
print u"""\
print(u"""\
Package robotframework-ride was not found. Please, install
plone.app.robotframework with proper extras, like:

Expand All @@ -61,7 +61,7 @@ def ride():
wxPython installed, like:

/usr/bin/python bin/ride
"""
""")


def libdoc():
Expand Down
13 changes: 8 additions & 5 deletions src/plone/app/robotframework/saucelabs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# -*- coding: utf-8 -*-
import re
import os
import httplib
from robot.libraries.BuiltIn import BuiltIn
from six.moves.http_client import HTTPConnection

import base64
import os
import re


try:
import json
json # pyflakes
except ImportError:
import simplejson as json

from robot.libraries.BuiltIn import BuiltIn

USERNAME_ACCESS_KEY = re.compile('^(http|https):\/\/([^:]+):([^@]+)@')

Expand Down Expand Up @@ -39,7 +42,7 @@ def report_sauce_status(self, name, status, tags=[], remote_url=''):
'passed': status == 'PASS',
'tags': tags})

connection = httplib.HTTPConnection('saucelabs.com')
connection = HTTPConnection('saucelabs.com')
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (
username, job_id), body,
headers={'Authorization': 'Basic %s' % token}
Expand Down
Loading