Datasets:

Modalities:
Text
Formats:
text
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
zdy023 commited on
Commit
ffdd509
1 Parent(s): 8adac26

ver Nov13th

Browse files

fixed two missed modules for flow replay

Files changed (2) hide show
  1. classify_url.py +46 -0
  2. load_response.py +35 -0
classify_url.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+
3
+ # Created by Danyang Zhang @X-Lance
4
+
5
+ def classify(url: str) -> str:
6
+ # URL Classification {{{ #
7
+ if url.startswith("/x/collect?t="):
8
+ if url[13:].startswith("first") or url[13:].startswith("later"):
9
+ url_key = r"/x/collect\?t={first,later}&*"
10
+ elif url[13:].startswith("exit") or url[13:].startswith("amp"):
11
+ url_key = r"/x/collect\?t={exit,amp}&*"
12
+ else:
13
+ print("\x1b[1;31mClassification Error!\x1b[0m")
14
+ raise ValueError("Unseen URL Pattern: {:}".format(url))
15
+ elif url=="/x/zscsucgm?":
16
+ url_key = r"/x/zscsucgm\?"
17
+ elif url.startswith("/x/amp-view?"):
18
+ url_key = r"/x/amp-view\?*"
19
+ elif url.startswith("/ev/"):
20
+ url_key = r"/ev/*"
21
+ elif url.startswith("/load.php?"):
22
+ if "only=styles" in url:
23
+ url_key = r"/load.php\?*only=styles*"
24
+ else:
25
+ url_key = r"R /load.php?.\+$\(only=styles\)\@!"
26
+ elif url.startswith("/video/"):
27
+ url_key = r"/video/*"
28
+ elif url=="/Special:SherlockController":
29
+ url_key = r"/Special:SherlockController"
30
+ elif url.startswith("/Special:RCWidget?"):
31
+ url_key = r"/Special:RCWidget\?*"
32
+ elif url.startswith("/extensions/wikihow/"):
33
+ url_key = r"/extensions/wikihow/*"
34
+ elif url.startswith("/images/"):
35
+ url_key = r"/images/*"
36
+ elif url.startswith("/skins/"):
37
+ url_key = r"/skins/*"
38
+ else:
39
+ url_key = "[[:others:]]"
40
+
41
+ return url_key
42
+ # }}} URL Classification #
43
+
44
+ if __name__ == "__main__":
45
+ import sys
46
+ print(classify(sys.argv[1]))
load_response.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Created by Danyang Zhang @X-Lance
2
+
3
+ from typing import Tuple, Dict
4
+ from typing import Union
5
+ import functools
6
+
7
+ def load_response(filename, decodes: bool = False) ->\
8
+ Tuple[ int
9
+ , Dict[str, Union[bytes, str]]
10
+ , bytes
11
+ ]:
12
+ """
13
+ Args:
14
+ filename: str
15
+ decodes: bool indicating whether the value of the headers dict should
16
+ be decoded into str
17
+
18
+ Returns:
19
+ - int as the status code
20
+ - dict like {str: bytes or str} as the headers dict
21
+ - bytes as the packet load
22
+ """
23
+
24
+ with open(filename, "rb") as f:
25
+ response = f.read()
26
+
27
+ header_bytes, _, content = response.partition(b"\r\n\r\n")
28
+ header_items = header_bytes.split(b"\r\n")
29
+ status_code = int(header_items[0].split()[1].strip())
30
+ header = {k.decode().lower(): (val.decode() if decodes else val)
31
+ for k, val in
32
+ map(functools.partial(bytes.split, sep=b": ", maxsplit=1),
33
+ header_items[1:])}
34
+
35
+ return status_code, header, content