File tree Expand file tree Collapse file tree 3 files changed +19
-16
lines changed Expand file tree Collapse file tree 3 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 3
3
4
4
def demo_to ():
5
5
print ("demo_to" )
6
- print (useTo .to_string ('https://www.baidu.com' ))
7
- print (useTo .to_string (b'https://www.baidu.com' ))
8
- print (useTo .to_string (123 ))
9
- print (useTo .to_string (123.456 ))
10
- print (useTo .to_string (True ))
11
- print (useTo .to_string (None ))
12
- print (useTo .to_string ([1 , 2 , 3 ]))
13
- print (useTo .to_string ({'a' : 1 , 'b' : 2 , 'c' : 3 }))
6
+ print (useTo .string ('https://www.baidu.com' ))
7
+ print (useTo .string (b'https://www.baidu.com' ))
8
+ print (useTo .string (123 ))
9
+ print (useTo .string (123.456 ))
10
+ print (useTo .string (True ))
11
+ print (useTo .string (None ))
12
+ print (useTo .string ([1 , 2 , 3 ]))
13
+ print (useTo .string ({'a' : 1 , 'b' : 2 , 'c' : 3 }))
14
14
pass
15
15
16
16
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def cookie_to_dict(cookies: str) -> dict:
13
13
:param cookies: cookie字符串
14
14
:return: dict
15
15
"""
16
- return { cookie . split ( '=' )[ 0 ]: cookie .split ('=' )[ - 1 ] for cookie in cookies .split ('; ' )}
16
+ return dict ( x .split ('=' ) for x in cookies .split ('; ' )) # noqa
17
17
18
18
19
19
def headers_to_dict (headers : str ) -> dict :
@@ -22,12 +22,7 @@ def headers_to_dict(headers: str) -> dict:
22
22
:param headers: headers字符串
23
23
:return: dict
24
24
"""
25
- header_dict = {}
26
- for line in headers .split ('\n ' ):
27
- if ':' in line :
28
- key , value = line .split (':' , 1 )
29
- header_dict [key .strip ()] = value .strip ()
30
- return header_dict
25
+ return dict (map (lambda x : x .strip (), line .split (':' )) for line in headers .split ('\n ' ) if ':' in line ) # noqa
31
26
32
27
33
28
def data_to_dict (data : str ) -> dict :
@@ -36,7 +31,7 @@ def data_to_dict(data: str) -> dict:
36
31
:param data: data字符串。格式为`key1=value1&key2=value2`
37
32
:return: dict
38
33
"""
39
- return { item . split ( '=' )[ 0 ]: item .split ('=' )[ - 1 ] for item in data .split ('&' )}
34
+ return dict ( x .split ('=' ) for x in data .split ('&' )) # noqa
40
35
41
36
42
37
def gen_unique_id ():
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ def test_cookie_to_dict():
33
33
}
34
34
35
35
36
+ def test_data_to_dict ():
37
+ data_str = "key1=value1&key2=value2"
38
+ assert useDataToDict (data_str ) == {
39
+ "key1" : "value1" ,
40
+ "key2" : "value2" ,
41
+ }
42
+
43
+
36
44
def test_header_to_dict ():
37
45
header_str = """sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Microsoft Edge";v="108"
38
46
sec-ch-ua-platform: "macOS"
You can’t perform that action at this time.
0 commit comments