32 from six.moves.http_cookies import SimpleCookie |
32 from six.moves.http_cookies import SimpleCookie |
33 |
33 |
34 from rql.utils import rqlvar_maker |
34 from rql.utils import rqlvar_maker |
35 |
35 |
36 from logilab.common.decorators import cached |
36 from logilab.common.decorators import cached |
37 from logilab.common.deprecation import deprecated |
|
38 |
37 |
39 from cubicweb import AuthenticationError |
38 from cubicweb import AuthenticationError |
40 from cubicweb.req import RequestSessionBase |
39 from cubicweb.req import RequestSessionBase |
41 from cubicweb.uilib import remove_html_tags, js |
40 from cubicweb.uilib import remove_html_tags, js |
42 from cubicweb.utils import HTMLHead, make_uid |
41 from cubicweb.utils import HTMLHead, make_uid |
160 if pid is None: |
159 if pid is None: |
161 pid = make_uid(id(self)) |
160 pid = make_uid(id(self)) |
162 self.html_headers.define_var('pageid', pid, override=False) |
161 self.html_headers.define_var('pageid', pid, override=False) |
163 self.pageid = pid |
162 self.pageid = pid |
164 |
163 |
165 def _get_json_request(self): |
|
166 warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead', |
|
167 DeprecationWarning, stacklevel=2) |
|
168 return self.ajax_request |
|
169 def _set_json_request(self, value): |
|
170 warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead', |
|
171 DeprecationWarning, stacklevel=2) |
|
172 self.ajax_request = value |
|
173 json_request = property(_get_json_request, _set_json_request) |
|
174 |
|
175 @property |
164 @property |
176 def authmode(self): |
165 def authmode(self): |
177 """Authentification mode of the instance |
166 """Authentification mode of the instance |
178 (see :ref:`WebServerConfig`)""" |
167 (see :ref:`WebServerConfig`)""" |
179 return self.vreg.config['auth-mode'] |
168 return self.vreg.config['auth-mode'] |
694 # XXX replace by True once validate_cache bw compat method is dropped |
683 # XXX replace by True once validate_cache bw compat method is dropped |
695 return self.status_out |
684 return self.status_out |
696 # XXX replace by False once validate_cache bw compat method is dropped |
685 # XXX replace by False once validate_cache bw compat method is dropped |
697 return None |
686 return None |
698 |
687 |
699 @deprecated('[3.18] use .is_client_cache_valid() method instead') |
|
700 def validate_cache(self): |
|
701 """raise a `StatusResponse` exception if a cached page along the way |
|
702 exists and is still usable. |
|
703 """ |
|
704 status_code = self.is_client_cache_valid() |
|
705 if status_code is not None: |
|
706 raise StatusResponse(status_code) |
|
707 |
|
708 # abstract methods to override according to the web front-end ############# |
688 # abstract methods to override according to the web front-end ############# |
709 |
689 |
710 def http_method(self): |
690 def http_method(self): |
711 """returns 'POST', 'GET', 'HEAD', etc.""" |
691 """returns 'POST', 'GET', 'HEAD', etc.""" |
712 raise NotImplementedError() |
692 raise NotImplementedError() |
810 value_parser = value_sort_key = None |
790 value_parser = value_sort_key = None |
811 accepteds = self.get_header(header, '') |
791 accepteds = self.get_header(header, '') |
812 values = _parse_accept_header(accepteds, value_parser, value_sort_key) |
792 values = _parse_accept_header(accepteds, value_parser, value_sort_key) |
813 return (raw_value for (raw_value, parsed_value, score) in values) |
793 return (raw_value for (raw_value, parsed_value, score) in values) |
814 |
794 |
815 @deprecated('[3.17] demote_to_html is deprecated as we always serve html') |
|
816 def demote_to_html(self): |
|
817 """helper method to dynamically set request content type to text/html |
|
818 |
|
819 The global doctype and xmldec must also be changed otherwise the browser |
|
820 will display '<[' at the beginning of the page |
|
821 """ |
|
822 pass |
|
823 |
|
824 |
|
825 # xml doctype ############################################################# |
795 # xml doctype ############################################################# |
826 |
796 |
827 def set_doctype(self, doctype, reset_xmldecl=None): |
797 def set_doctype(self, doctype): |
828 """helper method to dynamically change page doctype |
798 """helper method to dynamically change page doctype |
829 |
799 |
830 :param doctype: the new doctype, e.g. '<!DOCTYPE html>' |
800 :param doctype: the new doctype, e.g. '<!DOCTYPE html>' |
831 """ |
801 """ |
832 if reset_xmldecl is not None: |
|
833 warn('[3.17] reset_xmldecl is deprecated as we only serve html', |
|
834 DeprecationWarning, stacklevel=2) |
|
835 self.main_stream.set_doctype(doctype) |
802 self.main_stream.set_doctype(doctype) |
836 |
803 |
837 # page data management #################################################### |
804 # page data management #################################################### |
838 |
805 |
839 def get_page_data(self, key, default=None): |
806 def get_page_data(self, key, default=None): |
875 return self.get_header('User-Agent', None) |
842 return self.get_header('User-Agent', None) |
876 |
843 |
877 def ie_browser(self): |
844 def ie_browser(self): |
878 useragent = self.useragent() |
845 useragent = self.useragent() |
879 return useragent and 'MSIE' in useragent |
846 return useragent and 'MSIE' in useragent |
880 |
|
881 @deprecated('[3.17] xhtml_browser is deprecated (xhtml is no longer served)') |
|
882 def xhtml_browser(self): |
|
883 """return True if the browser is considered as xhtml compatible. |
|
884 |
|
885 If the instance is configured to always return text/html and not |
|
886 application/xhtml+xml, this method will always return False, even though |
|
887 this is semantically different |
|
888 """ |
|
889 return False |
|
890 |
847 |
891 def html_content_type(self): |
848 def html_content_type(self): |
892 return 'text/html' |
849 return 'text/html' |
893 |
850 |
894 def negotiated_language(self): |
851 def negotiated_language(self): |