17
17
from urllib .parse import urlsplit
18
18
19
19
20
- log = logging .getLogger (' sasctl.betamax' )
20
+ log = logging .getLogger (" sasctl.betamax" )
21
21
22
22
23
23
class BinarySerializer (BaseSerializer ):
@@ -32,17 +32,18 @@ class BinarySerializer(BaseSerializer):
32
32
by the compression.
33
33
34
34
"""
35
- name = 'binary'
35
+
36
+ name = "binary"
36
37
stored_as_binary = False
37
38
38
39
@staticmethod
39
40
def generate_cassette_name (cassette_library_dir , cassette_name ):
40
- return os .path .join (cassette_library_dir , f' { cassette_name } .lzma' )
41
+ return os .path .join (cassette_library_dir , f" { cassette_name } .lzma" )
41
42
42
43
def serialize (self , cassette_data ):
43
44
data = pickle .dumps (cassette_data )
44
45
data = lzma .compress (data )
45
- return base64 .b85encode (data ).decode (' utf-8' )
46
+ return base64 .b85encode (data ).decode (" utf-8" )
46
47
47
48
def deserialize (self , cassette_data ):
48
49
try :
@@ -60,37 +61,37 @@ class RedactedPathMatcher(PathMatcher):
60
61
ession ids in the path are ignored.
61
62
"""
62
63
63
- name = ' redacted_path'
64
+ name = " redacted_path"
64
65
65
66
def _strip_session_id (self , path ):
66
- match = re .search (r' (?<=sessions/)[0-9a-f\-]*' , path )
67
+ match = re .search (r" (?<=sessions/)[0-9a-f\-]*" , path )
67
68
if match :
68
- path = path .replace (match .group (0 ), '' )
69
+ path = path .replace (match .group (0 ), "" )
69
70
return path
70
71
71
72
def match (self , request , recorded_request ):
72
73
request_path = self ._strip_session_id (urlsplit (request .url ).path )
73
- recorded_path = self ._strip_session_id (urlsplit (recorded_request [' uri' ]).path )
74
+ recorded_path = self ._strip_session_id (urlsplit (recorded_request [" uri" ]).path )
74
75
return request_path == recorded_path
75
76
76
77
77
78
class PartialBodyMatcher (BaseMatcher ):
78
79
# Matches based on the body of the request
79
- name = ' partial_body'
80
+ name = " partial_body"
80
81
81
82
def match (self , request , recorded_request ):
82
83
recorded_request = util .deserialize_prepared_request (recorded_request )
83
84
84
- request_body = b''
85
+ request_body = b""
85
86
if request .body :
86
87
request_body = util .coerce_content (request .body )
87
88
88
- recorded_body = b''
89
+ recorded_body = b""
89
90
if recorded_request .body :
90
91
recorded_body = util .coerce_content (recorded_request .body )
91
92
92
93
if recorded_body != request_body :
93
94
diff = difflib .context_diff (recorded_body , request_body )
94
- log .debug (' ** Cassette Differences: **\n ' + ' \n ' .join (diff ))
95
+ log .debug (" ** Cassette Differences: **\n " + " \n " .join (diff ))
95
96
96
- return recorded_body == request_body
97
+ return recorded_body == request_body
0 commit comments