Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/werkzeug/user_agent.py: 67%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3import typing as t
4from typing import Any
7class _UserAgent(str):
8 """Represents a parsed user agent header value.
10 The default implementation does no parsing, only the :attr:`string`
11 attribute is set. A subclass may parse the string to set the
12 common attributes or expose other information. Set
13 :attr:`werkzeug.wrappers.Request.user_agent_class` to use a
14 subclass.
16 :param string: The header value to parse.
18 .. deprecated:: 3.2
19 Will be removed in Werkzeug 4.0. ``Request.user_agent`` is a string and
20 can be parsed directly if needed.
22 .. versionadded:: 2.0
23 This replaces the previous ``useragents`` module, but does not
24 provide a built-in parser.
25 """
27 platform: str | None = None
28 """The OS name, if it could be parsed from the string."""
30 browser: str | None = None
31 """The browser name, if it could be parsed from the string."""
33 version: str | None = None
34 """The browser version, if it could be parsed from the string."""
36 language: str | None = None
37 """The browser language, if it could be parsed from the string."""
39 @property
40 def string(self) -> str:
41 """The original header value."""
42 return str(self)
44 def to_header(self) -> str:
45 """Convert to a header value."""
46 return str(self)
48 def __getattribute__(self, name: str, /) -> Any:
49 if hasattr(str, name):
50 return super().__getattribute__(name)
52 import warnings
54 warnings.warn(
55 "The 'UserAgent' class is deprecated and will be removed in"
56 " Werkzeug 4.0. 'Request.user_agent' is a string and can be"
57 " parsed directly if needed.",
58 DeprecationWarning,
59 stacklevel=2,
60 )
61 return object.__getattribute__(self, name)
64if not t.TYPE_CHECKING:
66 def __getattr__(name: str) -> t.Any:
67 if name == "UserAgent":
68 import warnings
70 warnings.warn(
71 "The 'UserAgent' class is deprecated and will be removed in"
72 " Werkzeug 4.0. 'Request.user_agent' is a string and can be"
73 " parsed directly if needed.",
74 DeprecationWarning,
75 stacklevel=2,
76 )
77 return _UserAgent
79 raise AttributeError(name)