equal
deleted
inserted
replaced
23 import os |
23 import os |
24 import hmac |
24 import hmac |
25 from uuid import uuid4 |
25 from uuid import uuid4 |
26 from os.path import dirname, join, exists, split, isdir |
26 from os.path import dirname, join, exists, split, isdir |
27 |
27 |
28 from six import text_type |
|
29 |
|
30 from logilab.common.decorators import cached, cachedproperty |
28 from logilab.common.decorators import cached, cachedproperty |
31 from logilab.common.configuration import Method, merge_options |
29 from logilab.common.configuration import Method, merge_options |
32 |
30 |
33 from cubicweb import ConfigurationError |
31 from cubicweb import ConfigurationError |
34 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options |
32 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options |
132 allowed or if an empty login is used in configuration |
130 allowed or if an empty login is used in configuration |
133 """ |
131 """ |
134 try: |
132 try: |
135 user = self['anonymous-user'] or None |
133 user = self['anonymous-user'] or None |
136 passwd = self['anonymous-password'] |
134 passwd = self['anonymous-password'] |
137 if user: |
|
138 user = text_type(user) |
|
139 except KeyError: |
135 except KeyError: |
140 user, passwd = None, None |
136 user, passwd = None, None |
141 except UnicodeDecodeError: |
137 except UnicodeDecodeError: |
142 raise ConfigurationError("anonymous information should only contains ascii") |
138 raise ConfigurationError("anonymous information should only contains ascii") |
143 return user, passwd |
139 return user, passwd |
299 return str(uuid4()).encode('ascii') |
295 return str(uuid4()).encode('ascii') |
300 |
296 |
301 def sign_text(self, text): |
297 def sign_text(self, text): |
302 """sign some text for later checking""" |
298 """sign some text for later checking""" |
303 # hmac.new expect bytes |
299 # hmac.new expect bytes |
304 if isinstance(text, text_type): |
300 if isinstance(text, str): |
305 text = text.encode('utf-8') |
301 text = text.encode('utf-8') |
306 # replace \r\n so we do not depend on whether a browser "reencode" |
302 # replace \r\n so we do not depend on whether a browser "reencode" |
307 # original message using \r\n or not |
303 # original message using \r\n or not |
308 return hmac.new(self._instance_salt, |
304 return hmac.new(self._instance_salt, |
309 text.strip().replace(b'\r\n', b'\n')).hexdigest() |
305 text.strip().replace(b'\r\n', b'\n')).hexdigest() |