Skip to content

Commit

Permalink
have the name unicode available in python 3 in this module
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Jan 3, 2018
1 parent 789784e commit c59b919
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/grokcore/security/meta/permission.py
Expand Up @@ -21,12 +21,18 @@
from zope.security.interfaces import IPermission
from martian.error import GrokError


PY2 = sys.version_info[0] == 2


if not PY2:
unicode = lambda s: s


def default_fallback_to_name(factory, module, name, **data):
return name


class PermissionGrokker(martian.ClassGrokker):
martian.component(grokcore.security.Permission)
martian.priority(1500)
Expand All @@ -40,20 +46,13 @@ def execute(self, factory, config, name, title, description, **kw):
raise GrokError(
"A permission needs to have a dotted name for its id. Use "
"grok.name to specify one.", factory)
if PY2:
# We can safely convert to unicode, since the directives make sure
# it is either unicode already or ASCII.
permission = factory(
unicode(name),
unicode(title),
unicode(description))
else:
permission = factory(name, title, description)
permission = factory(
unicode(name), unicode(title), unicode(description))

config.action(
discriminator=('utility', IPermission, name),
callable=grokcore.component.provideUtility,
args=(permission, IPermission, name),
order=-1 # need to do this early in the process
order=-1 # need to do this early in the process
)
return True

0 comments on commit c59b919

Please sign in to comment.