Skip to content

Commit

Permalink
Merge e799064 into 20331fe
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Oct 12, 2020
2 parents 20331fe + e799064 commit 9984f74
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 340 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
language: python
sudo: false
python:
- 2.7
- 3.6
- pypy
- pypy3

matrix:
include:
- name: "lint"
python: 3.6
env: TOXENV="lint"

install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
- pip install -U -e .[test,docs]

script:
- coverage run -m zope.testrunner --test-path=src
- coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest
Expand Down
5 changes: 2 additions & 3 deletions src/zope/dublincore/annotatableadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
##############################################################################
"""Dublin Core Annotatable Adapter
"""
__docformat__ = 'restructuredtext'

from persistent.dict import PersistentDict

from zope.annotation.interfaces import IAnnotatable
Expand Down Expand Up @@ -94,6 +92,7 @@ def __set__(self, inst, value):
if oldvalue != value:
setattr(context, self.__attrname, value)


def partialAnnotatableAdapterFactory(direct_fields):
if not direct_fields:
raise ValueError("only use partialAnnotatableAdapterFactory()"
Expand Down Expand Up @@ -121,7 +120,7 @@ def __init__(self, context):
if oldprop is None:
raise ValueError("%r is not a valid DC field" % dcname)
if (isinstance(oldprop, DateProperty)
or not isinstance(oldprop, ScalarProperty)):
or not isinstance(oldprop, ScalarProperty)):
raise ValueError("%r is not a supported DC field" % dcname)
prop = DirectProperty(dcname, attrname)
setattr(ZDCPartialAnnotatableAdapter, dcname, prop)
Expand Down
24 changes: 15 additions & 9 deletions src/zope/dublincore/browser/metadataedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
##############################################################################
"""Dublin Core Meta Data View
"""
__docformat__ = 'restructuredtext'

from datetime import datetime
from zope.event import notify
from zope.dublincore.interfaces import IZopeDublinCore
from zope.lifecycleevent import ObjectModifiedEvent, Attributes
from zope.i18nmessageid import MessageFactory

_ = MessageFactory('zope')

try:
unicode
except NameError:
unicode = str # PY3


text_type = type(u'') #PY3

Expand All @@ -31,24 +35,26 @@ class MetaDataEdit(object):

def edit(self):
request = self.request
formatter = self.request.locale.dates.getFormatter('dateTime', 'medium')
formatter = self.request.locale.dates.getFormatter(
'dateTime', 'medium')
dc = IZopeDublinCore(self.context)
message=''
message = ''

if 'dctitle' in request:
dc.title = text_type(request['dctitle'])
dc.description = text_type(request['dcdescription'])
description = Attributes(IZopeDublinCore, 'title', 'description')
notify(ObjectModifiedEvent(self.context, description))
message = _("Changed data ${datetime}",
mapping={'datetime': formatter.format(datetime.utcnow())})
message = _(
"Changed data ${datetime}",
mapping={'datetime': formatter.format(datetime.utcnow())})

return {
'message': message,
'dctitle': dc.title,
'dcdescription': dc.description,
'modified': (dc.modified or dc.created) and \
formatter.format(dc.modified or dc.created) or '',
'modified': ((dc.modified or dc.created) and
formatter.format(dc.modified or dc.created) or ''),
'created': dc.created and formatter.format(dc.created) or '',
'creators': dc.creators
}
}
5 changes: 2 additions & 3 deletions src/zope/dublincore/creatorannotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
##############################################################################
"""Object that takes care of annotating the dublin core creator field.
"""
__docformat__ = 'restructuredtext'

from zope.dublincore.interfaces import IZopeDublinCore
from zope.security.management import queryInteraction
from zope.security.proxy import removeSecurityProxy
Expand All @@ -25,6 +23,7 @@
# Py3: Make unicode available.
unicode = str


def CreatorAnnotator(object, event=None):
"""Update Dublin-Core creator property"""
if event is None:
Expand All @@ -47,5 +46,5 @@ def CreatorAnnotator(object, event=None):
if participation.principal is None:
continue
principalid = participation.principal.id
if not principalid in dc.creators:
if principalid not in dc.creators:
dc.creators = dc.creators + (unicode(principalid), )
19 changes: 8 additions & 11 deletions src/zope/dublincore/dcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@
http://dublincore.org/documents/dcmi-dcsv/
"""
__docformat__ = 'restructuredtext'

import re

__all__ = "encode", "decode"

try:
basestring
unicode
except NameError:
# define basestring in Python 2.2.x:
try:
unicode
except NameError:
basestring = str
else:
basestring = str, unicode
basestring = str # PY3
else:
basestring = str, unicode # noqa: F821


def encode(items):
Expand All @@ -56,6 +50,7 @@ def encode(items):
L.append(s)
return " ".join(L)


def _encode_string(s, what):
if s.strip() != s:
raise ValueError("%s may not include leading or trailing spaces: %r"
Expand All @@ -75,7 +70,7 @@ def decode(text):
items.append(('', prefix))
text = text[m.end():].lstrip()
continue
else: # char == "="
else: # char == "="
text = text[m.end():].lstrip()
# else we have a label
m = _find_value(text)
Expand All @@ -91,10 +86,12 @@ def decode(text):
break
return items


_prefix = r"((?:[^;\\=]|\\.)*)"
_find_interesting = re.compile(_prefix + "([;=])").match
_find_value = re.compile(_prefix + ";").match


def _decode_string(s):
if "\\" not in s:
return s.rstrip()
Expand Down
Loading

0 comments on commit 9984f74

Please sign in to comment.