equal
deleted
inserted
replaced
21 import random |
21 import random |
22 import base64 |
22 import base64 |
23 from hashlib import sha1 # pylint: disable=E0611 |
23 from hashlib import sha1 # pylint: disable=E0611 |
24 from calendar import timegm |
24 from calendar import timegm |
25 from datetime import date, datetime |
25 from datetime import date, datetime |
|
26 import http.client |
26 from io import BytesIO |
27 from io import BytesIO |
27 |
28 from urllib.parse import urlsplit, quote as urlquote |
28 from six import PY2, text_type, string_types |
29 from http.cookies import SimpleCookie |
29 from six.moves import http_client |
|
30 from six.moves.urllib.parse import urlsplit, quote as urlquote |
|
31 from six.moves.http_cookies import SimpleCookie |
|
32 |
30 |
33 from rql.utils import rqlvar_maker |
31 from rql.utils import rqlvar_maker |
34 |
32 |
35 from logilab.common.decorators import cached |
33 from logilab.common.decorators import cached |
36 |
34 |
206 if params is None: |
204 if params is None: |
207 return |
205 return |
208 encoding = self.encoding |
206 encoding = self.encoding |
209 for param, val in params.items(): |
207 for param, val in params.items(): |
210 if isinstance(val, (tuple, list)): |
208 if isinstance(val, (tuple, list)): |
211 if PY2: |
|
212 val = [unicode(x, encoding) for x in val] |
|
213 if len(val) == 1: |
209 if len(val) == 1: |
214 val = val[0] |
210 val = val[0] |
215 elif PY2 and isinstance(val, str): |
|
216 val = unicode(val, encoding) |
|
217 if param in self.no_script_form_params and val: |
211 if param in self.no_script_form_params and val: |
218 val = self.no_script_form_param(param, val) |
212 val = self.no_script_form_param(param, val) |
219 if param == '_cwmsgid': |
213 if param == '_cwmsgid': |
220 self.set_message_id(val) |
214 self.set_message_id(val) |
221 else: |
215 else: |
272 return self._msg |
266 return self._msg |
273 except AttributeError: |
267 except AttributeError: |
274 return None |
268 return None |
275 |
269 |
276 def set_message(self, msg): |
270 def set_message(self, msg): |
277 assert isinstance(msg, text_type) |
271 assert isinstance(msg, str) |
278 self.reset_message() |
272 self.reset_message() |
279 self._msg = msg |
273 self._msg = msg |
280 |
274 |
281 def set_message_id(self, msgid): |
275 def set_message_id(self, msgid): |
282 self._msgid = msgid |
276 self._msgid = msgid |
285 def redirect_message_id(self): |
279 def redirect_message_id(self): |
286 return make_uid() |
280 return make_uid() |
287 |
281 |
288 def set_redirect_message(self, msg): |
282 def set_redirect_message(self, msg): |
289 # TODO - this should probably be merged with append_to_redirect_message |
283 # TODO - this should probably be merged with append_to_redirect_message |
290 assert isinstance(msg, text_type) |
284 assert isinstance(msg, str) |
291 msgid = self.redirect_message_id() |
285 msgid = self.redirect_message_id() |
292 self.session.data[msgid] = msg |
286 self.session.data[msgid] = msg |
293 return msgid |
287 return msgid |
294 |
288 |
295 def append_to_redirect_message(self, msg): |
289 def append_to_redirect_message(self, msg): |
372 form = self.form |
366 form = self.form |
373 try: |
367 try: |
374 eids = form['eid'] |
368 eids = form['eid'] |
375 except KeyError: |
369 except KeyError: |
376 raise NothingToEdit(self._('no selected entities')) |
370 raise NothingToEdit(self._('no selected entities')) |
377 if isinstance(eids, string_types): |
371 if isinstance(eids, str): |
378 eids = (eids,) |
372 eids = (eids,) |
379 for peid in eids: |
373 for peid in eids: |
380 if withtype: |
374 if withtype: |
381 typekey = '__type:%s' % peid |
375 typekey = '__type:%s' % peid |
382 assert typekey in form, 'no entity type specified' |
376 assert typekey in form, 'no entity type specified' |
521 |
515 |
522 :param jsfiles: a JS filename or a list of JS filenames |
516 :param jsfiles: a JS filename or a list of JS filenames |
523 :param localfile: if True, the default data dir prefix is added to the |
517 :param localfile: if True, the default data dir prefix is added to the |
524 JS filename |
518 JS filename |
525 """ |
519 """ |
526 if isinstance(jsfiles, string_types): |
520 if isinstance(jsfiles, str): |
527 jsfiles = (jsfiles,) |
521 jsfiles = (jsfiles,) |
528 for jsfile in jsfiles: |
522 for jsfile in jsfiles: |
529 if localfile: |
523 if localfile: |
530 jsfile = self.data_url(jsfile) |
524 jsfile = self.data_url(jsfile) |
531 self.html_headers.add_js(jsfile) |
525 self.html_headers.add_js(jsfile) |
541 :param ieonly: True if this css is specific to IE |
535 :param ieonly: True if this css is specific to IE |
542 :param iespec: conditional expression that will be used around |
536 :param iespec: conditional expression that will be used around |
543 the css inclusion. cf: |
537 the css inclusion. cf: |
544 http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx |
538 http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx |
545 """ |
539 """ |
546 if isinstance(cssfiles, string_types): |
540 if isinstance(cssfiles, str): |
547 cssfiles = (cssfiles,) |
541 cssfiles = (cssfiles,) |
548 if ieonly: |
542 if ieonly: |
549 if self.ie_browser(): |
543 if self.ie_browser(): |
550 extraargs = [iespec] |
544 extraargs = [iespec] |
551 add_css = self.html_headers.add_ie_css |
545 add_css = self.html_headers.add_ie_css |
611 def build_url_path(self, *args): |
605 def build_url_path(self, *args): |
612 path = super(_CubicWebRequestBase, self).build_url_path(*args) |
606 path = super(_CubicWebRequestBase, self).build_url_path(*args) |
613 lang_prefix = '' |
607 lang_prefix = '' |
614 if self.lang is not None and self.vreg.config.get('language-mode') == 'url-prefix': |
608 if self.lang is not None and self.vreg.config.get('language-mode') == 'url-prefix': |
615 lang_prefix = '%s/' % self.lang |
609 lang_prefix = '%s/' % self.lang |
616 return lang_prefix + path |
610 return lang_prefix + str(path) |
617 |
611 |
618 def url(self, includeparams=True): |
612 def url(self, includeparams=True): |
619 """return currently accessed url""" |
613 """return currently accessed url""" |
620 return self.base_url() + self.relative_path(includeparams) |
614 return self.base_url() + self.relative_path(includeparams) |
621 |
615 |
664 # Forge expected response |
658 # Forge expected response |
665 if not modified: |
659 if not modified: |
666 # overwrite headers_out to forge a brand new not-modified response |
660 # overwrite headers_out to forge a brand new not-modified response |
667 self.headers_out = self._forge_cached_headers() |
661 self.headers_out = self._forge_cached_headers() |
668 if self.http_method() in ('HEAD', 'GET'): |
662 if self.http_method() in ('HEAD', 'GET'): |
669 self.status_out = http_client.NOT_MODIFIED |
663 self.status_out = http.client.NOT_MODIFIED |
670 else: |
664 else: |
671 self.status_out = http_client.PRECONDITION_FAILED |
665 self.status_out = http.client.PRECONDITION_FAILED |
672 # XXX replace by True once validate_cache bw compat method is dropped |
666 # XXX replace by True once validate_cache bw compat method is dropped |
673 return self.status_out |
667 return self.status_out |
674 # XXX replace by False once validate_cache bw compat method is dropped |
668 # XXX replace by False once validate_cache bw compat method is dropped |
675 return None |
669 return None |
676 |
670 |