0
werkzeug에서 오는 요청 오브젝트가 있습니다. 이 요청 개체의 값을 변경하고 싶습니다. werkzeug 요청 오브젝트가 불변이므로 이는 불가능합니다. 이 디자인 결정을 이해하지만 값을 변경해야합니다. 어떻게해야합니까? werkzeug 요청 오브젝트의 값 변경
>>> request
<Request 'http://localhost:5000/new' [POST]>
>>> request.method
'POST'
>>> request.method = 'GET'
*** AttributeError: read only property
은 내가
deepcopy
을 수행했지만, 결과 사본은 불변이다. 나는 내 자신의 mock 객체를 만들고 수동으로 값을 채울 수 있다고 생각하지만 이것이 나의 최후의 해결책이다. 더 좋은 방법이 있습니까?
def make_duplicate_request(request):
"""
Since werkzeug request objects are immutable, this is needed to create an
identical request object with mutable values
"""
class Req(object):
method = 'GET'
path = ''
headers = []
args = []
r = Req()
r.path = request.path
r.headers = request.headers
r.is_xhr = request.is_xhr
r.args = request.args
return r
어쩌면
없는 가장 우아한 솔루션,하지만 작동이 내가 생각 해낸 것입니다