web/request.py
changeset 9897 fa44db7da2dc
parent 9821 2077c8da1893
parent 9884 5ad1c3a9c4a1
child 10001 1245357b3b3e
equal deleted inserted replaced
9892:928732ec00dd 9897:fa44db7da2dc
    28 from Cookie import SimpleCookie
    28 from Cookie import SimpleCookie
    29 from calendar import timegm
    29 from calendar import timegm
    30 from datetime import date, datetime
    30 from datetime import date, datetime
    31 from urlparse import urlsplit
    31 from urlparse import urlsplit
    32 import httplib
    32 import httplib
    33 from itertools import count
       
    34 from warnings import warn
    33 from warnings import warn
    35 
    34 
    36 from rql.utils import rqlvar_maker
    35 from rql.utils import rqlvar_maker
    37 
    36 
    38 from logilab.common.decorators import cached
    37 from logilab.common.decorators import cached
    79         value = ()
    78         value = ()
    80     elif not isinstance(value, (list, tuple)):
    79     elif not isinstance(value, (list, tuple)):
    81         value = [value]
    80         value = [value]
    82     return [v for v in value if v != INTERNAL_FIELD_VALUE]
    81     return [v for v in value if v != INTERNAL_FIELD_VALUE]
    83 
    82 
       
    83 
       
    84 class Counter(object):
       
    85     """A picklable counter object, usable for e.g. page tab index count"""
       
    86     __slots__ = ('value',)
       
    87 
       
    88     def __init__(self, initialvalue=0):
       
    89         self.value = initialvalue
       
    90 
       
    91     def __call__(self):
       
    92         value = self.value
       
    93         self.value += 1
       
    94         return value
       
    95 
       
    96     def __getstate__(self):
       
    97         return {'value': self.value}
       
    98 
       
    99     def __setstate__(self, state):
       
   100         self.value = state['value']
    84 
   101 
    85 
   102 
    86 class _CubicWebRequestBase(RequestSessionBase):
   103 class _CubicWebRequestBase(RequestSessionBase):
    87     """abstract HTTP request, should be extended according to the HTTP backend
   104     """abstract HTTP request, should be extended according to the HTTP backend
    88     Immutable attributes that describe the received query and generic configuration
   105     Immutable attributes that describe the received query and generic configuration
   199         return self.set_varmaker()
   216         return self.set_varmaker()
   200 
   217 
   201     def next_tabindex(self):
   218     def next_tabindex(self):
   202         nextfunc = self.get_page_data('nexttabfunc')
   219         nextfunc = self.get_page_data('nexttabfunc')
   203         if nextfunc is None:
   220         if nextfunc is None:
   204             nextfunc = count(1).next
   221             nextfunc = Counter(1)
   205             self.set_page_data('nexttabfunc', nextfunc)
   222             self.set_page_data('nexttabfunc', nextfunc)
   206         return nextfunc()
   223         return nextfunc()
   207 
   224 
   208     def set_varmaker(self):
   225     def set_varmaker(self):
   209         varmaker = self.get_page_data('rql_varmaker')
   226         varmaker = self.get_page_data('rql_varmaker')