I want to expand werkzeug UserAgent class with one more browser. How can I do it without modifying the source code of werkzeug library? I'm new in python so I have small idea about mixins, inheritance, modules and so on. I've found in docs:
It’s a good idea to create a custom subclass of the BaseRequest and add missing functionality either via mixins or direct implementation. Here an example for such subclasses:
from werkzeug.wrappers import BaseRequest, ETagRequestMixin
class Request(BaseRequest, ETagRequestMixin):
pass
At which part of my code should I put this and how to expand standart UserAgent class? Also I'm using werkzeug with Flask. Thanks in advance.
Amazing. Once you ask question the answer comes up itself :)
Flask.request_class
is the answer:
from werkzeug.wrappers import BaseRequest, ETagRequestMixin
class Request(BaseRequest, ETagRequestMixin):
pass
app = Flask(__name__)
app.request_class = Request