mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Add a read_body helper function
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from six.moves import urllib, xmlrpc_client
|
from six.moves import urllib, xmlrpc_client
|
||||||
from .util import CaseInsensitiveDict
|
from .util import CaseInsensitiveDict, read_body
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -34,18 +34,12 @@ def query(r1, r2):
|
|||||||
|
|
||||||
|
|
||||||
def raw_body(r1, r2):
|
def raw_body(r1, r2):
|
||||||
if hasattr(r1.body, 'read') and hasattr(r2.body, 'read'):
|
return read_body(r1) == read_body(r2)
|
||||||
return r1.body.read() == r2.body.read()
|
|
||||||
return r1.body == r2.body
|
|
||||||
|
|
||||||
|
|
||||||
def body(r1, r2):
|
def body(r1, r2):
|
||||||
if hasattr(r1.body, 'read') and hasattr(r2.body, 'read'):
|
r1_body = read_body(r1)
|
||||||
r1_body = r1.body.read()
|
r2_body = read_body(r2)
|
||||||
r2_body = r2.body.read()
|
|
||||||
else:
|
|
||||||
r1_body = r1.body
|
|
||||||
r2_body = r2.body
|
|
||||||
r1_headers = CaseInsensitiveDict(r1.headers)
|
r1_headers = CaseInsensitiveDict(r1.headers)
|
||||||
r2_headers = CaseInsensitiveDict(r2.headers)
|
r2_headers = CaseInsensitiveDict(r2.headers)
|
||||||
if r1_headers.get('Content-Type') == r2_headers.get('Content-Type') == 'application/x-www-form-urlencoded':
|
if r1_headers.get('Content-Type') == r2_headers.get('Content-Type') == 'application/x-www-form-urlencoded':
|
||||||
|
|||||||
@@ -85,3 +85,8 @@ def compose(*functions):
|
|||||||
res = function(res)
|
res = function(res)
|
||||||
return res
|
return res
|
||||||
return composed
|
return composed
|
||||||
|
|
||||||
|
def read_body(request):
|
||||||
|
if hasattr(request.body, 'read'):
|
||||||
|
return request.body.read()
|
||||||
|
return request.body
|
||||||
|
|||||||
Reference in New Issue
Block a user