summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
committerShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
commit68df54d6629ec019142eb149dd037774f2d11e7c (patch)
tree345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py
new file mode 100644
index 0000000..d9e234a
--- /dev/null
+++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/html5lib/filters/alphabeticalattributes.py
@@ -0,0 +1,29 @@
1from __future__ import absolute_import, division, unicode_literals
2
3from . import base
4
5from collections import OrderedDict
6
7
8def _attr_key(attr):
9 """Return an appropriate key for an attribute for sorting
10
11 Attributes have a namespace that can be either ``None`` or a string. We
12 can't compare the two because they're different types, so we convert
13 ``None`` to an empty string first.
14
15 """
16 return (attr[0][0] or ''), attr[0][1]
17
18
19class Filter(base.Filter):
20 """Alphabetizes attributes for elements"""
21 def __iter__(self):
22 for token in base.Filter.__iter__(self):
23 if token["type"] in ("StartTag", "EmptyTag"):
24 attrs = OrderedDict()
25 for name, value in sorted(token["data"].items(),
26 key=_attr_key):
27 attrs[name] = value
28 token["data"] = attrs
29 yield token