27 from contextlib import contextmanager |
27 from contextlib import contextmanager |
28 from inspect import isgeneratorfunction |
28 from inspect import isgeneratorfunction |
29 from itertools import chain |
29 from itertools import chain |
30 from warnings import warn |
30 from warnings import warn |
31 |
31 |
32 from six import text_type, string_types, reraise |
32 from six import binary_type, text_type, string_types, reraise |
33 from six.moves import range |
33 from six.moves import range |
34 from six.moves.urllib.parse import urlparse, parse_qs, unquote as urlunquote |
34 from six.moves.urllib.parse import urlparse, parse_qs, unquote as urlunquote |
35 |
35 |
36 import yams.schema |
36 import yams.schema |
37 |
37 |
756 """parses `url` and builds the corresponding CW-web request |
756 """parses `url` and builds the corresponding CW-web request |
757 |
757 |
758 req.form will be setup using the url's query string |
758 req.form will be setup using the url's query string |
759 """ |
759 """ |
760 req = self.request(url=url) |
760 req = self.request(url=url) |
761 if isinstance(url, unicode): |
761 if isinstance(url, text_type): |
762 url = url.encode(req.encoding) # req.setup_params() expects encoded strings |
762 url = url.encode(req.encoding) # req.setup_params() expects encoded strings |
763 querystring = urlparse(url)[-2] |
763 querystring = urlparse(url)[-2] |
764 params = parse_qs(querystring) |
764 params = parse_qs(querystring) |
765 req.setup_params(params) |
765 req.setup_params(params) |
766 return req |
766 return req |
770 """parses `url` and builds the corresponding CW-web request |
770 """parses `url` and builds the corresponding CW-web request |
771 |
771 |
772 req.form will be setup using the url's query string |
772 req.form will be setup using the url's query string |
773 """ |
773 """ |
774 with self.admin_access.web_request(url=url) as req: |
774 with self.admin_access.web_request(url=url) as req: |
775 if isinstance(url, unicode): |
775 if isinstance(url, text_type): |
776 url = url.encode(req.encoding) # req.setup_params() expects encoded strings |
776 url = url.encode(req.encoding) # req.setup_params() expects encoded strings |
777 querystring = urlparse(url)[-2] |
777 querystring = urlparse(url)[-2] |
778 params = parse_qs(querystring) |
778 params = parse_qs(querystring) |
779 req.setup_params(params) |
779 req.setup_params(params) |
780 yield req |
780 yield req |
1022 msg += str_exc.encode(sys.getdefaultencoding(), 'replace') |
1022 msg += str_exc.encode(sys.getdefaultencoding(), 'replace') |
1023 if content is not None: |
1023 if content is not None: |
1024 position = getattr(exc, "position", (0,))[0] |
1024 position = getattr(exc, "position", (0,))[0] |
1025 if position: |
1025 if position: |
1026 # define filter |
1026 # define filter |
1027 if isinstance(content, str): |
1027 if isinstance(content, binary_type): |
1028 content = unicode(content, sys.getdefaultencoding(), 'replace') |
1028 content = text_type(content, sys.getdefaultencoding(), 'replace') |
1029 content = validator.preprocess_data(content) |
1029 content = validator.preprocess_data(content) |
1030 content = content.splitlines() |
1030 content = content.splitlines() |
1031 width = int(log(len(content), 10)) + 1 |
1031 width = int(log(len(content), 10)) + 1 |
1032 line_template = " %" + ("%i" % width) + "i: %s" |
1032 line_template = " %" + ("%i" % width) + "i: %s" |
1033 # XXX no need to iterate the whole file except to get |
1033 # XXX no need to iterate the whole file except to get |