Skip to content

Commit

Permalink
Prepare for Python 2 / 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davilima6 committed Jan 29, 2018
1 parent ceab344 commit da78e5b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
1.1.4 (unreleased)
------------------

- Nothing changed yet.
- Prepare for Python 2 / 3 compatibility [davilima6]


1.1.3 (2017-02-14)
Expand Down
13 changes: 7 additions & 6 deletions Products/ExternalEditor/ExternalEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from string import join # For Zope 2.3 compatibility
import types
import urllib
import six
from six.moves import urllib
from Acquisition import aq_inner, aq_base, aq_parent, Implicit
try:
from App.class_init import InitializeClass
Expand Down Expand Up @@ -56,11 +57,11 @@ def __init__(self, data):
def __iter__(self):
return self

def next(self):
def __next__(self):
if self.data is None:
raise StopIteration
data = self.data.data
self.data = self.data.next
self.data = next(self.data)
return data


Expand Down Expand Up @@ -129,8 +130,8 @@ def index_html(self, REQUEST, RESPONSE, path=None):
if title is not None:
if callable(title):
title = title()
if isinstance(title, types.UnicodeType):
title = unicode.encode(title, 'utf-8')
if isinstance(title, six.text_type):
title = title.encode('utf-8')
r.append('title:%s' % title)

if hasattr(aq_base(ob), 'content_type'):
Expand Down Expand Up @@ -292,7 +293,7 @@ def EditLink(self, object, borrow_lock=0, skip_data=0):
if skip_data:
query['skip_data'] = 1
url = "%s/externalEdit_/%s%s%s" % (aq_parent(aq_inner(object)).absolute_url(),
urllib.quote(object.getId()),
urllib.parse.quote(object.getId()),
ext, querystr(query))
return ('<a href="%s" '
'title="Edit using external editor">'
Expand Down
64 changes: 32 additions & 32 deletions Products/ExternalEditor/tests/edit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ External Editor:

>>> self.folder.manage_addFile('some-file', file='some content')

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file.zem HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: 167
Content-Type: application/x-zope-edit
Expand All @@ -38,7 +38,7 @@ External Editor:
Lock the file, should now send out the lock-token in the metadata:

>>> self.folder['some-file'].wl_clearLocks()
>>> print http(r"""
>>> print(http(r"""
... LOCK /test_folder_1_/some-file HTTP/1.1
... Content-Type: text/xml; charset="utf-8"
... Depth: 0
Expand All @@ -48,15 +48,15 @@ Lock the file, should now send out the lock-token in the metadata:
... <DAV:lockinfo xmlns:DAV="DAV:">
... <DAV:lockscope><DAV:exclusive/></DAV:lockscope>
... <DAV:locktype><DAV:write/></DAV:locktype>
... </DAV:lockinfo>""" % (user_name, user_password))
... </DAV:lockinfo>""" % (user_name, user_password)))
HTTP/1.1 200 OK
...
Lock-Token: ...

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: application/x-zope-edit
Expand All @@ -77,16 +77,16 @@ Lock the file, should now send out the lock-token in the metadata:
If 'borrow_lock' is found in the request, then a 'borrow_lock:1' is
appended to the metadata along with the lock-token:

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file?borrow_lock=1 HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/some-file
meta_type:File
Expand All @@ -102,16 +102,16 @@ appended to the metadata along with the lock-token:
If 'skip_data' is found in the request, then the file data is **not**
appended after the metadata:

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file?skip_data=1 HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/some-file
meta_type:File
Expand All @@ -131,16 +131,16 @@ A user that is not the lock owner will not get the 'lock-token' or
>>> uf = self.folder.acl_users
>>> uf.userFolderAddUser(user_name_2, user_password_2, ['Manager'], [])

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file?borrow_lock=1 HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name_2, user_password_2))
... """ % (user_name_2, user_password_2)))
HTTP/1.1 200 OK
Content-Length: 163
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/some-file
meta_type:File
Expand All @@ -163,16 +163,16 @@ to 'application/x-zope-edit':
>>> from Products.ExternalEditor.tests.test_functional import SideEffects
>>> _ = self.folder._setObject('another-file', SideEffects('another-file', 'some content'))

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/another-file HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: 140
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/another-file
meta_type:Side Effects
Expand All @@ -195,16 +195,16 @@ that is sent out:
>>> old_cb = _callbacks[:]
>>> registerCallback(md_callback)

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file?borrow_lock=1 HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: 191
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/some-file
meta_type:File
Expand All @@ -227,16 +227,16 @@ REQUEST, for example the 'skip_data' parameter:
>>> old_cb = _callbacks[:]
>>> registerCallback(req_callback)

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Length: 155
Content-Type: application/x-zope-edit
Expires:...
Last-Modified:...
Pragma: no-cache
Pragma: no-cache
<BLANKLINE>
url:http://localhost/test_folder_1_/some-file
meta_type:File
Expand All @@ -257,10 +257,10 @@ the RESPONSE:
>>> old_cb = _callbacks[:]
>>> registerCallback(resp_callback)

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file HTTP/1.1
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 159
Expand All @@ -270,18 +270,18 @@ the RESPONSE:
Pragma:...

>>> _callbacks[:] = old_cb


MSIE cache behaviour
====================

We set the user agent at `MSIE` and look at the cache headers.

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file.zem HTTP/1.1
... User-Agent: MSIE
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Cache-Control: must-revalidate, post-check=0, pre-check=0
Content-Length: 167
Expand All @@ -302,11 +302,11 @@ We set the user agent at `MSIE` and look at the cache headers.
Because we also are IE 1.0 compliant, we try with `Microsoft Internet Explorer'
Cheers JNUT !! ;)

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/externalEdit_/some-file.zem HTTP/1.1
... User-Agent: Microsoft Internet Explorer
... Authorization: Basic %s:%s
... """ % (user_name, user_password))
... """ % (user_name, user_password)))
HTTP/1.1 200 OK
Cache-Control: must-revalidate, post-check=0, pre-check=0
Content-Length: 167
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
zip_safe=False,
install_requires=[
'setuptools',
'six',
],
entry_points="""
[console_scripts]
Expand Down

0 comments on commit da78e5b

Please sign in to comment.