Skip to content

Commit 79a1327

Browse files
committed
merge change to roundup issue tracker reg form
2 parents e7eb220 + 0cab750 commit 79a1327

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

roundup/dehtml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from __future__ import print_function
33
from roundup.anypy.strings import u2s, uchr
44

5+
import sys
6+
_pyver = sys.version_info[0]
57

68
class dehtml:
79
def __init__(self, converter):
@@ -32,12 +34,10 @@ def html2text(html):
3234
# Python 3+.
3335
from html.parser import HTMLParser
3436
from html.entities import name2codepoint
35-
pyver = 3
3637
except ImportError:
3738
# Python 2.
3839
from HTMLParser import HTMLParser
3940
from htmlentitydefs import name2codepoint
40-
pyver = 2
4141

4242
class DumbHTMLParser(HTMLParser):
4343
# class attribute
@@ -83,7 +83,7 @@ def handle_entityref(self, name):
8383
self.text = self.text + ' '
8484

8585
def html2text(html):
86-
if pyver == 3:
86+
if _pyver == 3:
8787
parser = DumbHTMLParser(convert_charrefs=True)
8888
else:
8989
parser = DumbHTMLParser()

roundup/rest.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -473,39 +473,40 @@ def prop_from_arg(self, cl, key, value, itemid=None):
473473
def transitive_props (self, class_name, props):
474474
"""Construct a list of transitive properties from the given
475475
argument, and return it after permission check. Raises
476-
Unauthorised if no permission. Permission is checked by checking
477-
search-permission on the path (delimited by '.') excluding the
478-
last component and then checking View permission on the last
479-
component. We do not allow to traverse multilinks -- the last
480-
item of an expansion *may* be a multilink but in the middle of a
481-
transitive prop.
476+
Unauthorised if no permission. Permission is checked by
477+
checking View permission on each component. We do not allow to
478+
traverse multilinks -- the last item of an expansion *may* be a
479+
multilink but in the middle of a transitive prop.
482480
"""
483481
checked_props = []
484482
uid = self.db.getuid()
485483
for p in props:
486484
pn = p
487485
cn = class_name
488486
if '.' in p:
489-
path, lc = p.rsplit('.', 1)
490-
if not self.db.security.hasSearchPermission(uid, class_name, p):
491-
raise (Unauthorised
492-
('User does not have permission on "%s.%s"'
493-
% (class_name, p)))
494-
prev = prop = None
495-
# This shouldn't raise any errors, otherwise the search
496-
# permission check above would have failed
497-
for pn in path.split('.'):
487+
prop = None
488+
for pn in p.split('.'):
489+
# Tried to dereference a non-Link property
490+
if cn is None:
491+
raise AttributeError("Unknown: %s" % p)
498492
cls = self.db.getclass(cn)
499-
prop = cls.getprops(protected=True)[pn]
493+
# This raises a KeyError for unknown prop:
494+
try:
495+
prop = cls.getprops(protected=True)[pn]
496+
except KeyError:
497+
raise AttributeError("Unknown: %s" % p)
500498
if isinstance(prop, hyperdb.Multilink):
501499
raise UsageError(
502500
'Multilink Traversal not allowed: %s' % p)
503-
cn = prop.classname
504-
cls = self.db.getclass(cn)
505-
# Now we have the classname in cn and the prop name in pn.
506-
if not self.db.security.hasPermission('View', uid, cn, pn):
507-
raise(Unauthorised
508-
('User does not have permission on "%s.%s"' % (cn, pn)))
501+
# Now we have the classname in cn and the prop name in pn.
502+
if not self.db.security.hasPermission('View', uid, cn, pn):
503+
raise(Unauthorised
504+
('User does not have permission on "%s.%s"'
505+
% (cn, pn)))
506+
try:
507+
cn = prop.classname
508+
except AttributeError:
509+
cn = None
509510
checked_props.append (p)
510511
return checked_props
511512

test/test_templating.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,10 @@ def test_string_markdown_link(self):
429429
self.assertEqual(p.markdown().strip(), u2s(u'<p>A link <a href="http://localhost">http://localhost</a></p>'))
430430

431431
def test_string_markdown_link(self):
432-
# markdown2 and markdown
432+
# markdown2 and markdown escape the email address
433433
try:
434-
import html
435-
html_unescape = html.unescape
436-
except AttributeError:
434+
from html import unescape as html_unescape
435+
except ImportError:
437436
from HTMLParser import HTMLParser
438437
html_unescape = HTMLParser().unescape
439438

0 commit comments

Comments
 (0)