Skip to content

Commit

Permalink
Merge 290022f into 9d6e6d2
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 17, 2017
2 parents 9d6e6d2 + 290022f commit 0a37a9f
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 207 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ python:
# - 3.4
# - 3.5
# - 3.6
# - pypy-5.4.1
- pypy-5.4.1
script:
- coverage run `which zope-testrunner` --test-path=src --auto-color --auto-progress
- coverage run -m zope.testrunner --test-path=src --auto-color --auto-progress

after_success:
- coveralls
notifications:
email: false

install:
- pip install -U pip "setuptools"
# setuptools 35 apparently fails to properly include data files in the
# wheels it builds, at least when used through pip
- pip install -U pip "setuptools<35"
- pip install -U coveralls coverage
- pip install -U -e ".[test]"
- pip install -e ".[test]"


cache: pip
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.txt → CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ CHANGES
0.6.3 (unreleased)
------------------

- Remove unneeded test dependencies zope.app.server and
zope.app.component
- Remove unneeded test dependencies zope.app.server,
zope.app.component, zope.app.container, and others.
- Test on Travis CI. Only Python 2.7 is supported.
- Update to work with zope.testbrowser 5.
- Add PyPy support.

0.6.2 (2012-06-04)
------------------
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include *.py
include *.txt
include *.rst
include LICENSE
include buildout.cfg
include setup.cfg
include .coveragerc
recursive-include src *.pt
recursive-include src *.rst
recursive-include src *.zcml
File renamed without changes.
41 changes: 27 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def read(*rnames):
author_email='zope-dev@zope.org',
description='Efficient File Implementation for Zope Applications',
long_description=(
read('README.txt')
read('README.rst')
+ '\n\n' +
'.. contents::'
+ '\n\n' +
read('src', 'zope', 'file', 'README.txt')
read('src', 'zope', 'file', 'README.rst')
+ '\n\n' +
read('src', 'zope', 'file', 'download.txt')
read('src', 'zope', 'file', 'download.rst')
+ '\n\n' +
read('src', 'zope', 'file', 'upload.txt')
read('src', 'zope', 'file', 'upload.rst')
+ '\n\n' +
read('src', 'zope', 'file', 'contenttype.txt')
read('src', 'zope', 'file', 'contenttype.rst')
+ '\n\n' +
read('src', 'zope', 'file', 'browser.txt')
read('src', 'zope', 'file', 'browser.rst')
+ '\n\n' +
read('CHANGES.txt')
read('CHANGES.rst')
),
keywords="zope3 web html ui file pattern",
classifiers=[
Expand All @@ -54,6 +54,7 @@ def read(*rnames):
'Programming Language :: Python:: 2 :: Only',
'Programming Language :: Python:: 2.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
Expand All @@ -66,25 +67,37 @@ def read(*rnames):
namespace_packages=['zope'],
extras_require=dict(
test=[
'zope.app.testing',
'zope.app.zcmlfiles',
'zope.app.basicskin',
'zope.app.http',
'zope.app.pagetemplate',
'zope.app.principalannotation',
'zope.app.publisher',
'zope.app.publication',
'zope.app.wsgi',
'zope.applicationcontrol',
'zope.copypastemove',
'zope.browser',
'zope.browsermenu',
'zope.login',
'zope.password',
'zope.principalregistry',
'zope.securitypolicy',
'zope.testbrowser>5',
'zope.testrunner',
],
browser=[
'zope.browser',
]
),
install_requires=[
'setuptools',
'ZODB3',
'zope.component>=3.8',
'zope.browser',
'ZODB',
'zope.component',
'zope.container',
'zope.contenttype>=3.5',
'zope.contenttype',
'zope.event',
'zope.filerepresentation',
'zope.formlib>=4',
'zope.formlib',
'zope.i18nmessageid',
'zope.lifecycleevent',
'zope.interface',
Expand Down
File renamed without changes.
19 changes: 8 additions & 11 deletions src/zope/file/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import zope.filerepresentation.interfaces
from zope.file import interfaces

@component.adapter(interfaces.IFile)
@interface.implementer(zope.filerepresentation.interfaces.IReadFile)
class ReadFileAdapter(object):
component.adapts(interfaces.IFile)
interface.implements(zope.filerepresentation.interfaces.IReadFile)

def __init__(self, context):
self.context = context
Expand All @@ -25,19 +25,16 @@ def size(self):
return self.context.size

def read(self):
f = self.context.open()
val = f.read()
f.close()
return val
with self.context.open() as f:
return f.read()

@component.adapter(interfaces.IFile)
@interface.implementer(zope.filerepresentation.interfaces.IWriteFile)
class WriteFileAdapter(object):
component.adapts(interfaces.IFile)
interface.implements(zope.filerepresentation.interfaces.IWriteFile)

def __init__(self, context):
self.context = context

def write(self, data):
f = self.context.open('w')
f.write(data)
f.close()
with self.context.open('w') as f:
f.write(data)
2 changes: 1 addition & 1 deletion src/zope/file/adapters.txt → src/zope/file/adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ regular `File` object:

>>> from zope.file.file import File
>>> f = File(parameters=dict(charset='utf-8'))
>>> f.open('w').write("hello")
>>> with f.open('w') as _: _.write("hello")

Now we can turn this file into a read-only file which we can read and
whose size we can get:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/zope/file/browser.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
name="zope.file.File"
class=".upload.Upload"
permission="zope.ManageContent"
zcml:condition="installed zope.browser"
/>

<!-- Register menu related stuff if z.a.zcmlfiles is available only -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ content. We'll upload a bit of HTML as a sample document:

>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
>>> browser.addHeader("Authorization", "Basic mgr:mgrpw")
>>> browser.addHeader("Accept-Language", "en-US")
>>> browser.open("http://localhost/@@+/zope.file.File")
Expand Down Expand Up @@ -104,5 +105,5 @@ that's not going to work, and no changes are saved:

>>> browser.getControl("Save").click()

>>> print browser.contents
>>> print(browser.contents)
<...Selected encoding cannot decode document...
8 changes: 4 additions & 4 deletions src/zope/file/download.txt → src/zope/file/download.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Body

We use DownloadResult to deliver the content to the browser. Since
there's no data in this file, there are no body chunks:

>>> transaction.commit()
>>> from zope.file.download import DownloadResult
>>> result = DownloadResult(f)
Expand Down Expand Up @@ -179,7 +179,7 @@ result:
... GET /abcdefg/@@download HTTP/1.1
... Authorization: Basic mgr:mgrpw
... """, handle_errors=False)
HTTP/1.1 200 Ok
HTTP/1.0 200 Ok
Content-Disposition: attachment; filename="abcdefg"
Content-Length: 9
Content-Type: text/plain
Expand All @@ -201,7 +201,7 @@ nothing:
... GET /abcdefg/@@inline HTTP/1.1
... Authorization: Basic mgr:mgrpw
... """, handle_errors=False)
HTTP/1.1 200 Ok
HTTP/1.0 200 Ok
Content-Disposition: inline; filename="abcdefg"
Content-Length: 9
Content-Type: text/plain
Expand All @@ -220,7 +220,7 @@ handling of the data in the current context to be applied:
... GET /abcdefg/@@display HTTP/1.1
... Authorization: Basic mgr:mgrpw
... """, handle_errors=False)
HTTP/1.1 200 Ok
HTTP/1.0 200 Ok
Content-Length: 9
Content-Type: text/plain
<BLANKLINE>
Expand Down
81 changes: 51 additions & 30 deletions src/zope/file/ftesting.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,67 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="zope.file"
>
<include package="zope.app.publisher" file="meta.zcml" />

<include
zcml:condition="installed zope.app.zcmlfiles"
package="zope.app.zcmlfiles"
/>
<include
zcml:condition="not-installed zope.app.zcmlfiles"
package="zope.app"
/>
<include package="zope.browsermenu" file="meta.zcml" />

<include package="zope.login"/>
<include package="zope.password"/>

<include package="zope.mimetype" file="meta.zcml"/>
<include package="zope.mimetype"/>
<include package="zope.file"/>
<include package="zope.formlib"/>
<include package="zope.app.publication" file="ftesting.zcml" />

<!-- Security -->
<browser:menu
id="zmi_views"
title="Views"
description="Menu for displaying alternate representations of an object"
/>

<include package="zope.securitypolicy" file="meta.zcml" />
<include package="zope.securitypolicy" />
<browser:menu
id="zmi_actions"
title="Actions"
description="Menu for displaying actions to be performed"
/>

<securityPolicy
component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
<browser:menu
id="zope.app.container.add"
title="Add"
description="Menu for objects to be added according to
containment constraints"
interface="zope.app.publisher.interfaces.browser.AddMenu"
/>

<role
id="zope.Anonymous"
title="Everybody"
description="All users have this role implicitly"
/>
<role id="zope.Manager" title="Site Manager" />

<grantAll role="zope.Manager" />
<include package="zope.app.basicskin" />

<include package="zope.site" />
<include package="zope.container" />

<unauthenticatedPrincipal id="zope.anybody" title="Unauthenticated User" />
<include package="zope.app.pagetemplate" />
<include package="zope.app.principalannotation" />
<include package="zope.app.publisher" />
<include package="zope.applicationcontrol" />
<include package="zope.copypastemove" />

<principal id="zope.mgr" title="Manager" login="mgr" password="mgrpw" />
<include package="zope.file" file="browser.zcml"/>
<include package="zope.file" file="menus.zcml"/>
<include package="zope.file"/>

<grant role="zope.Manager" principal="zope.mgr" />
<include package="zope.formlib"/>
<include package="zope.mimetype" file="meta.zcml"/>
<include package="zope.mimetype"/>
<include package="zope.traversing" />
<include package="zope.traversing.browser" />

<browser:view
name="+"
menu="zmi_actions" title="Add"
for="zope.site.interfaces.IFolder"
permission="zope.ManageContent"
class=".testing.Adding"
/>
<browser:page
for="zope.site.interfaces.IFolder"
name="contents.html"
class=".testing.Contents"
permission="zope.ManageContent"
attribute="contents"
/>

</configure>
4 changes: 4 additions & 0 deletions src/zope/file/menus.zcml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="zope.file"
>

<!--
Menu related configuration.
Loaded from configure.zcml only if zope.app.zcmlfiles is available.
That's the (old) default location that defines these menus.
-->

<browser:view
for=".interfaces.IFile"
menu="zmi_views" title="Upload"
Expand All @@ -30,6 +33,7 @@
title="Zope File"
class="zope.file.file.File"
permission="zope.ManageContent"
zcml:condition="installed zope.browser"
/>

</configure>

0 comments on commit 0a37a9f

Please sign in to comment.