equal
deleted
inserted
replaced
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 |
21 |
22 from warnings import warn |
22 from warnings import warn |
23 from functools import partial |
23 from functools import partial |
24 |
24 |
25 from six import string_types, integer_types |
25 from six import text_type, string_types, integer_types |
26 from six.moves import range |
26 from six.moves import range |
27 |
27 |
28 from logilab.common.decorators import cached |
28 from logilab.common.decorators import cached |
29 from logilab.common.deprecation import deprecated |
29 from logilab.common.deprecation import deprecated |
30 from logilab.common.registry import yes |
30 from logilab.common.registry import yes |
58 |
58 |
59 def can_use_rest_path(value): |
59 def can_use_rest_path(value): |
60 """return True if value can be used at the end of a Rest URL path""" |
60 """return True if value can be used at the end of a Rest URL path""" |
61 if value is None: |
61 if value is None: |
62 return False |
62 return False |
63 value = unicode(value) |
63 value = text_type(value) |
64 # the check for ?, /, & are to prevent problems when running |
64 # the check for ?, /, & are to prevent problems when running |
65 # behind Apache mod_proxy |
65 # behind Apache mod_proxy |
66 if value == u'' or u'?' in value or u'/' in value or u'&' in value: |
66 if value == u'' or u'?' in value or u'/' in value or u'&' in value: |
67 return False |
67 return False |
68 return True |
68 return True |
678 else: |
678 else: |
679 value = self.eid |
679 value = self.eid |
680 if path is None: |
680 if path is None: |
681 # fallback url: <base-url>/<eid> url is used as cw entities uri, |
681 # fallback url: <base-url>/<eid> url is used as cw entities uri, |
682 # prefer it to <base-url>/<etype>/eid/<eid> |
682 # prefer it to <base-url>/<etype>/eid/<eid> |
683 return unicode(value) |
683 return text_type(value) |
684 return '%s/%s' % (path, self._cw.url_quote(value)) |
684 return u'%s/%s' % (path, self._cw.url_quote(value)) |
685 |
685 |
686 def cw_attr_metadata(self, attr, metadata): |
686 def cw_attr_metadata(self, attr, metadata): |
687 """return a metadata for an attribute (None if unspecified)""" |
687 """return a metadata for an attribute (None if unspecified)""" |
688 value = getattr(self, '%s_%s' % (attr, metadata), None) |
688 value = getattr(self, '%s_%s' % (attr, metadata), None) |
689 if value is None and metadata == 'encoding': |
689 if value is None and metadata == 'encoding': |