Skip to content

Commit

Permalink
Nuke trailing white space.
Browse files Browse the repository at this point in the history
svn path=/plone.outputfilters/trunk/; revision=46767
  • Loading branch information
mauritsvanrees committed Jan 5, 2011
1 parent d345baa commit 341f068
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions plone/outputfilters/browser/captioned_image.py
Expand Up @@ -4,7 +4,7 @@
class CaptionedImageView(BrowserView):
"""Captioned image template.
"""

@lazy_property
def template(self):
try:
Expand All @@ -13,6 +13,6 @@ def template(self):
except:
template = self.index
return template

def __call__(self, **options):
return self.template(**options)
2 changes: 1 addition & 1 deletion plone/outputfilters/browser/configure.zcml
@@ -1,7 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

<browser:page
name="plone.outputfilters_captioned_image"
for="*"
Expand Down
10 changes: 5 additions & 5 deletions plone/outputfilters/browser/resolveuid.py
Expand Up @@ -12,7 +12,7 @@

def BBB_uuidToURL(uuid):
"""Resolves a UUID to a URL via the UID catalog index.
Provided for compatibility when plone.app.uuid is not present.
"""
catalog = getToolByName(getSite(), 'portal_catalog')
Expand All @@ -22,7 +22,7 @@ def BBB_uuidToURL(uuid):

def BBB_uuidToObject(uuid):
"""Resolves a UUID to an object via the UID catalog index.
Provided for compatibility when plone.app.uuid is not present.
"""
catalog = getToolByName(getSite(), 'portal_catalog')
Expand All @@ -48,11 +48,11 @@ class ResolveUIDView(BrowserView):
"""Resolve a URL like /resolveuid/<uuid> to a normalized URL.
"""
implements(IPublishTraverse)

def publishTraverse(self, request, name):
uuid = name
url = uuidToURL(uuid)

if not url:
# BBB for kupu
hook = getattr(self.context, 'kupu_resolveuid_hook', None)
Expand All @@ -61,7 +61,7 @@ def publishTraverse(self, request, name):
if not obj:
raise NotFound("The link you followed is broken")
url = obj.absolute_url()

if not url:
raise NotFound("The link you followed is broken")

Expand Down
2 changes: 1 addition & 1 deletion plone/outputfilters/configure.zcml
Expand Up @@ -13,7 +13,7 @@
description="Framework for applying filters to HTML as it is rendered."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<gs:importStep
name="plone_outputfilters_various"
title="HTML Output Filters installation"
Expand Down
4 changes: 2 additions & 2 deletions plone/outputfilters/filters/configure.zcml
@@ -1,12 +1,12 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

<adapter
provides="..interfaces.IFilter"
name="resolveuid_and_caption"
for="* *"
factory=".resolveuid_and_caption.ResolveUIDAndCaptionFilter"
/>

</configure>
6 changes: 3 additions & 3 deletions plone/outputfilters/filters/example.py
Expand Up @@ -5,13 +5,13 @@
class EmDashAdder(object):
implements(IFilter)
order = 1000

def __init__(self, context, request):
pass

def is_enabled(self):
return True

pattern = re.compile(r'--')
def __call__(self, data):
return self.pattern.sub('\xe2\x80\x94', data)
22 changes: 11 additions & 11 deletions plone/outputfilters/filters/resolveuid_and_caption.py
Expand Up @@ -30,7 +30,7 @@ class IResolveUidsEnabler(Interface):
class ResolveUIDAndCaptionFilter(SGMLParser):
""" Parser to convert UUID links and captioned images """
implements(IFilter)

def __init__(self, context=None, request=None):
SGMLParser.__init__(self)
self.current_status = None
Expand All @@ -49,7 +49,7 @@ def captioned_images(self):
if u.available:
return True
return False

@lazy_property
def resolve_uids(self):
for u in getAllUtilitiesRegisteredFor(IResolveUidsEnabler):
Expand Down Expand Up @@ -113,23 +113,23 @@ def resolve_link(self, href):
obj = None
subpath = ''
appendix = ''

# preserve querystring and/or appendix
for char in ('#', '?'):
parts = href.split(char)
href = parts[0]
if len(parts) > 1:
appendix += char + char.join(parts[1:])

if 'resolveuid' in href:
# get the UUID
parts = href.split('/')
uid = parts[1]
if len(parts) > 2:
subpath = '/'.join(parts[2:])

obj = self.lookup_uid(uid)

return obj, subpath, appendix

def resolve_image(self, src):
Expand All @@ -138,7 +138,7 @@ def resolve_image(self, src):
base = self.context
subpath = src
appendix = ''

if 'resolveuid' in src:
base, subpath, appendix = self.resolve_link(src)

Expand All @@ -147,7 +147,7 @@ def resolve_image(self, src):
image = base.restrictedTraverse(subpath)
except:
return None, None, src, ''

fullimage = image
src = image.absolute_url() + appendix
if image and hasattr(aq_base(image), 'Description'):
Expand All @@ -161,12 +161,12 @@ def resolve_image(self, src):
pass
if fullimage and hasattr(aq_base(fullimage), 'Description'):
description = fullimage.Description()

return image, fullimage, src, description

def unknown_starttag(self, tag, attrs):
"""Here we've got the actual conversion of links and images.
Convert UUID's to absolute URLs, and process captioned images to HTML.
"""
if tag in ['a', 'img', 'area']:
Expand Down Expand Up @@ -219,7 +219,7 @@ def unknown_starttag(self, tag, attrs):
if self.in_link:
# Must preserve original link, don't overwrite with a link to the image
options['isfullsize'] = True

captioned_html = self.captioned_image_template(**options)
if isinstance(captioned_html, unicode):
captioned_html = captioned_html.encode('utf8')
Expand Down
12 changes: 6 additions & 6 deletions plone/outputfilters/interfaces.py
Expand Up @@ -4,23 +4,23 @@

class IFilter(Interface):
"""A filter that accepts raw HTML and returns a filtered version.
Register a named multi-adapter from (context, request) to
this interface to install a new filter.
To control the order of filters, use the 'order' attribute. It may be
positive or negative."""

order = schema.Int(title=u"Order")

def is_enabled():
"""Returns a boolean indicating whether the filter should be applied."""

def __call__(data):
"""Apply the filter.
``data`` is a UTF-8-encoded string.
Return a UTF-8-encoded string, or ``None`` to indicate that the data
should remain unmodified.
"""
18 changes: 9 additions & 9 deletions plone/outputfilters/tests/test_apply_filters.py
Expand Up @@ -5,7 +5,7 @@

class DummyFilter(object):
order = 500

def is_enabled(self):
return True

Expand All @@ -16,13 +16,13 @@ def __call__(self, data):


class FilterTestCase(unittest.TestCase):

def setUp(self):
DummyFilter.called = []

def test_apply_filters(self):
filters = [DummyFilter()]

apply_filters(filters, '')
self.assertEqual([filters[0]], DummyFilter.called)

Expand All @@ -31,24 +31,24 @@ def test_apply_filters_ordering(self):
filter2 = DummyFilter()
filter2.order = 100
filters = [filter1, filter2]

apply_filters(filters, '')
self.assertEqual([filters[1], filters[0]], DummyFilter.called)

def test_apply_filters_checks_is_enabled(self):
filter = DummyFilter()
filter.is_enabled = lambda: False
filters = [filter]

apply_filters(filters, '')
self.assertEqual([], DummyFilter.called)

def test_apply_filters_handles_return_none(self):
class DummyFilterReturningNone(DummyFilter):
def __call__(self, data):
return None
filter = DummyFilterReturningNone()

res = apply_filters([filter], '')
self.assertEqual('', res)

Expand Down

0 comments on commit 341f068

Please sign in to comment.