Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/werkzeug/user_agent.py: 65%
17 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1import typing as t
4class UserAgent:
5 """Represents a parsed user agent header value.
7 The default implementation does no parsing, only the :attr:`string`
8 attribute is set. A subclass may parse the string to set the
9 common attributes or expose other information. Set
10 :attr:`werkzeug.wrappers.Request.user_agent_class` to use a
11 subclass.
13 :param string: The header value to parse.
15 .. versionadded:: 2.0
16 This replaces the previous ``useragents`` module, but does not
17 provide a built-in parser.
18 """
20 platform: t.Optional[str] = None
21 """The OS name, if it could be parsed from the string."""
23 browser: t.Optional[str] = None
24 """The browser name, if it could be parsed from the string."""
26 version: t.Optional[str] = None
27 """The browser version, if it could be parsed from the string."""
29 language: t.Optional[str] = None
30 """The browser language, if it could be parsed from the string."""
32 def __init__(self, string: str) -> None:
33 self.string: str = string
34 """The original header value."""
36 def __repr__(self) -> str:
37 return f"<{type(self).__name__} {self.browser}/{self.version}>"
39 def __str__(self) -> str:
40 return self.string
42 def __bool__(self) -> bool:
43 return bool(self.browser)
45 def to_header(self) -> str:
46 """Convert to a header value."""
47 return self.string