(file, base_uri,
select_default=False,
ignore_errors=False,
form_parser_class=FormParser,
request_class=_urllib.request.Request,
entitydefs=None,
backwards_compat=True,
encoding=DEFAULT_ENCODING,
_urljoin=_urllib.parse.urljoin,
_urlparse=_urllib.parse.urlparse,
_urlunparse=_urllib.parse.urlunparse,
)
| 1088 | return _ParseFileEx(file, base_uri, *args, **kwds)[1:] |
| 1089 | |
| 1090 | def _ParseFileEx(file, base_uri, |
| 1091 | select_default=False, |
| 1092 | ignore_errors=False, |
| 1093 | form_parser_class=FormParser, |
| 1094 | request_class=_urllib.request.Request, |
| 1095 | entitydefs=None, |
| 1096 | backwards_compat=True, |
| 1097 | encoding=DEFAULT_ENCODING, |
| 1098 | _urljoin=_urllib.parse.urljoin, |
| 1099 | _urlparse=_urllib.parse.urlparse, |
| 1100 | _urlunparse=_urllib.parse.urlunparse, |
| 1101 | ): |
| 1102 | if backwards_compat: |
| 1103 | deprecation("operating in backwards-compatibility mode", 1) |
| 1104 | fp = form_parser_class(entitydefs, encoding) |
| 1105 | while 1: |
| 1106 | data = file.read(CHUNK) |
| 1107 | try: |
| 1108 | fp.feed(data) |
| 1109 | except ParseError as e: |
| 1110 | e.base_uri = base_uri |
| 1111 | raise |
| 1112 | if len(data) != CHUNK: break |
| 1113 | fp.close() |
| 1114 | if fp.base is not None: |
| 1115 | # HTML BASE element takes precedence over document URI |
| 1116 | base_uri = fp.base |
| 1117 | labels = [] # Label(label) for label in fp.labels] |
| 1118 | id_to_labels = {} |
| 1119 | for l in fp.labels: |
| 1120 | label = Label(l) |
| 1121 | labels.append(label) |
| 1122 | for_id = l["for"] |
| 1123 | coll = id_to_labels.get(for_id) |
| 1124 | if coll is None: |
| 1125 | id_to_labels[for_id] = [label] |
| 1126 | else: |
| 1127 | coll.append(label) |
| 1128 | forms = [] |
| 1129 | for (name, action, method, enctype), attrs, controls in fp.forms: |
| 1130 | if action is None: |
| 1131 | action = base_uri |
| 1132 | else: |
| 1133 | action = six.text_type(action, "utf8") if action and isinstance(action, six.binary_type) else action |
| 1134 | action = _urljoin(base_uri, action) |
| 1135 | # would be nice to make HTMLForm class (form builder) pluggable |
| 1136 | form = HTMLForm( |
| 1137 | action, method, enctype, name, attrs, request_class, |
| 1138 | forms, labels, id_to_labels, backwards_compat) |
| 1139 | form._urlparse = _urlparse |
| 1140 | form._urlunparse = _urlunparse |
| 1141 | for ii in xrange(len(controls)): |
| 1142 | type, name, attrs = controls[ii] |
| 1143 | # index=ii*10 allows ImageControl to return multiple ordered pairs |
| 1144 | form.new_control( |
| 1145 | type, name, attrs, select_default=select_default, index=ii*10) |
| 1146 | forms.append(form) |
| 1147 | for form in forms: |
no test coverage detected
searching dependent graphs…