Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
600c8b0d9c |
@@ -1,15 +1,17 @@
|
|||||||
# User-Agent Parsing Done Right
|
# User-Agent parsed Right
|
||||||
|
|
||||||
This module takes a smaller, faster, modern approach to User-Agent parsing. It's a dependency-free pure-Python parser weighing only 25 kB, with strong handling of current browsers and crawlers. Despite its light weight, uarite identifies both browsers and crawlers more accurately than any competing implementation tested here.
|
User-Agent parsing in Python has a long lineage. ua-parser is the official Python implementation of the ua-parser project, built around uap-core: the regex database extracted from BrowserScope's original parser and shared by implementations in many languages. user-agents wraps ua-parser with higher-level device and capability detection but its last release was in 2020. user-agent-parser is a separate implementation first released in 2022 and substantially updated in 2026, taking its own approach rather than building on uap-core. None of the three has further dependencies, but the regex databases weigh something: ua-parser and user-agents each install about half a megabyte, while user-agent-parser installs at 166 kB. We are merely 29 kB and yet perform better especially with the new crawlers of the AI boom.
|
||||||
|
|
||||||
It returns structured classification, but also the thing most applications eventually need: **a short pretty description**.
|
This module is another take on the same problem: a small, dependency-free, compact pure-Python parser. It returns structured classifications, but also the thing most applications eventually need: **a short human-readable pretty description**.
|
||||||
|
|
||||||
Add it to your project:
|
Add to your project:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
uv add uarite
|
uv add uarite
|
||||||
```
|
```
|
||||||
|
|
||||||
|
We correctly detect disguised crawlers and distinguish traffic of AI learning from search engines and social media share previews. We handle HarmonyOS and bots without calling them Android, resolve common device model codes to phone models like Galaxy Z Fold8, and fall back to reasonable output even when all else fails.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@@ -21,90 +23,83 @@ r.pretty # "Chrome/152 Windows"
|
|||||||
r.engine # "Chromium"
|
r.engine # "Chromium"
|
||||||
r.os # "Windows"
|
r.os # "Windows"
|
||||||
r.kind # "browser"
|
r.kind # "browser"
|
||||||
|
r.bot # ""
|
||||||
r.url # ""
|
r.url # ""
|
||||||
|
|
||||||
r = uaparse("Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6885.65 Mobile Safari/537.36; compatible; facebookexternalhit/1.1; +http://www.facebook.com/externalhit_uatext.php")
|
r = uaparse("Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6885.65 Mobile Safari/537.36; compatible; facebookexternalhit/1.1; +http://www.facebook.com/externalhit_uatext.php")
|
||||||
|
|
||||||
r.pretty # "Facebook"
|
r.pretty # "Facebook"
|
||||||
r.kind # "social"
|
r.kind # "preview"
|
||||||
r.provider # "Meta"
|
r.bot # "Facebook"
|
||||||
r.url # "http://www.facebook.com/externalhit_uatext.php"
|
r.url # "http://www.facebook.com/externalhit_uatext.php"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
|
||||||
`uaparse(ua)` returns a `UA` dataclass with string fields. Any field may be empty when the information is unavailable.
|
`uaparse(ua)` returns a `UA` dataclass with string values:
|
||||||
|
|
||||||
| Field | Content |
|
| Field | Content |
|
||||||
| -------- | ------------------------------------------------ |
|
| ------ | ------------------------------------------------------------------------------------------------- |
|
||||||
| pretty | Compact display string; raw UA when unrecognized |
|
| pretty | Compact display string (below); empty for empty/missing UAs, the raw UA when unrecognized |
|
||||||
| engine | Chromium, Gecko, Safari, ArkWeb |
|
| engine | Chromium, Gecko, Safari, ArkWeb (HarmonyOS), or empty |
|
||||||
| os | Windows, macOS, Linux, iOS, Android, HarmonyOS |
|
| os | Windows, macOS, Linux, iOS, Android, HarmonyOS, or empty |
|
||||||
| kind | browser, ai, search, social, analytics, spider |
|
| bot | Crawler/previewer display name, or empty |
|
||||||
| url | Crawler information URL |
|
| kind | browser, ai, search, preview, spider, or empty (scripts/HTTP libraries) |
|
||||||
| provider | Provider of a known crawler family |
|
| url | The crawler's info URL (the +https://… pointer), or empty; not part of pretty — link it in the UI |
|
||||||
|
|
||||||
The pretty field is intended for UIs and logs. The url can be attached to it as a link when available.
|
The pretty field is intended to be shown in UI and logging as a conscise description. The url may be included as a link on that text when found, mainly to allow finding out what the bot is used for.
|
||||||
|
|
||||||
The engine and os fields are intentionally broad. The kind field distinguishes browsers from AI collectors, search engines, social previews, monitoring tools, generic spiders, and ordinary HTTP clients. Any non-browser kind represents automated traffic.
|
The engine and os fields are meant for broad selection of operation, like which OS installer to offer, or which compatibility hacks are needed. Operating System is the major OS only, no version. Every recognized browser is Chromium except Firefox derivatives (Gecko), Safari (macOS, anything on iOS) and Harmony Browser (ArkWeb).
|
||||||
|
|
||||||
Detection is necessarily limited by what the User-Agent reveals. Crawlers can masquerade as ordinary browsers or other crawlers, so sites that need stronger identification should use additional methods rather than relying on UA detection alone.
|
The kind field describes our detection of visitor type: browser for actual browsers, ai for training data collectors (GPTBot, ClaudeBot, Google-Extended, ...), search for search-engine indexing (Googlebot, Bingbot, ...), preview for social link previews (Facebook, WhatsApp, Slack, ...), spider for generic or unknown crawlers, and empty for scripts and HTTP libraries. Any value other than browser means the visitor is automated.
|
||||||
|
|
||||||
## Comparison
|
We deliberately ignore masquerading as browser-compatible (common with crawlers) and fake information like the frozen Android 10; K values that appear on all new mobiles, when the UA provides extra hints of it being something else. These are not reported as engine, os etc., and the pretty field aims to accurately explain only what it actually is.
|
||||||
|
|
||||||
There are plenty of UA parsers for Python. This comparison includes the ua-parser family — the official port of the large upstream project, benchmarked with all three of its regex backends (Python, RE2, Rust) — plus user-agents, which builds on it with higher-level device detection, and fastuaparser, a single-file heuristic parser in the same weight class as uarite. Among those excluded: user-agent-parser crashes on real-world strings; httpagentparser misidentifies most bots and browser OSes; device-detector has a massive 26 MB install and extremely slow parsing; and crawlerdetect only distinguishes bots from non-bots. The user-agents package has been unmaintained since 2020 but is kept as a reference point.
|
Obviously all information is limited to that of the User-Agent string given. There are crawlers that masquerade using exact browser strings, or even strings indicating other crawlers than what they actually are, to bypass website protections (e.g. Google bots can often avoid paywalls given to ordinary browsers). You will require other methods to detect them because UA based detection is impossible.
|
||||||
|
|
||||||
Installed size tracks the design. The minimal heuristic parsers are tiny: fastuaparser installs in 15 kB, uarite in 30 kB. Everything built on ua-parser's regex database starts around half a megabyte, and its accelerated backends add several megabytes of native code.
|
## Accuracy
|
||||||
|
|
||||||
The benchmark and test scripts are available in the repository's scripts folder.
|
The table below compares various representative User-Agent formats with the two main contenders. We note that user-agents produces virtually identical results to ua-parser and is thus left out from the comparison, like other worse performing parsers.
|
||||||
|
|
||||||
### Accuracy
|
| Case | uarite¹ | ua-parser² |
|
||||||
|
| ---------------------------- | ------------------------- | --------------------------------------------- |
|
||||||
|
| Chrome, Windows | Chrome/152 Windows | Chrome/152 Windows |
|
||||||
|
| Safari, macOS | Safari/18 macOS | Safari/18 Mac OS X Mac |
|
||||||
|
| Opera, Linux | Opera/106 Linux | Opera/106 Linux |
|
||||||
|
| Chrome, Android (no model) | Chrome/152 Android | Chrome Mobile/152 Android K❌ |
|
||||||
|
| Chrome, Android (Pixel) | Chrome/118 Pixel 6 | Chrome Mobile/118 Android Pixel 6 |
|
||||||
|
| Edge, Android (model code) | Edge/110 Galaxy S7 | Edge Mobile/110 Android Samsung SM-G930P |
|
||||||
|
| Firefox, Android | Firefox/154 Android 15 | Firefox Mobile/154 Android Generic Smartphone |
|
||||||
|
| Safari, iPhone | iPhone iOS 17 | Mobile Safari/17 iOS iPhone |
|
||||||
|
| Huawei HarmonyOS phone | HuaweiBrowser/6 HarmonyOS | Huawei Browser/6 Android❌ Huawei Browser |
|
||||||
|
| GPTBot | GPTBot (AI) | GPTBot/1 Spider |
|
||||||
|
| Googlebot (disguised) | Googlebot (search) | Googlebot/2 Android❌ Spider |
|
||||||
|
| Facebook preview (disguised) | Facebook | FacebookBot/1 Android Pixel 7 ❌ |
|
||||||
|
| Meta crawler (disguised) | Meta | Chrome/145 Windows ❌ |
|
||||||
|
| WhatsApp preview | WhatsApp | WhatsApp/10 Spider |
|
||||||
|
| Bytespider | Bytespider | Bytespider/ Android❌ Generic Smartphone |
|
||||||
|
| BingPreview | BingPreview (preview) | BingPreview/1 Windows❌ Spider |
|
||||||
|
| AhrefsBot | AhrefsBot | AhrefsBot/7 Spider |
|
||||||
|
| python-requests | python-requests/2.32.5 | Python Requests/2 |
|
||||||
|
|
||||||
The table below compares representative User-Agent formats with fastuaparser and ua-parser. The user-agents wrapper produces nearly identical results to ua-parser and is left out.
|
- ❌ marks an incorrect browser, OS, or device interpretation.
|
||||||
|
- ¹ r.pretty shown as is
|
||||||
|
- ² {user_agent.family}/{user_agent.major} {os.family} {device.family}
|
||||||
|
|
||||||
| Case | uarite¹ | fastuaparser² | ua-parser³ |
|
Measured on modern browser UAs, **uarite resolves family, version and OS at 100%**. ua-parser and user-agents land at 80%, while user-agent-parser does slightly better at 92%.
|
||||||
| ---------------------------- | ------------------------- | ------------------------- | --------------------------------------------- |
|
|
||||||
| Chrome, Windows | Chrome/152 Windows | Chrome - Windows | Chrome/152 Windows |
|
|
||||||
| Safari, macOS | Safari/18 macOS | Safari - Mac OS X | Safari/18 Mac OS X Mac |
|
|
||||||
| Opera, Linux | Opera/106 Linux | Opera - Linux | Opera/106 Linux |
|
|
||||||
| Chrome, Android (no model) | Chrome/152 Android | Chrome - Android Mobile | Chrome Mobile/152 Android K❌ |
|
|
||||||
| Chrome, Android (Pixel) | Chrome/118 Pixel 6 | Chrome - Android Mobile | Chrome Mobile/118 Android Pixel 6 |
|
|
||||||
| Edge, Android (model code) | Edge/110 Galaxy S7 | Edge - Android Mobile | Edge Mobile/110 Android Samsung SM-G930P |
|
|
||||||
| Firefox, Android | Firefox/154 Android 15 | Firefox - Android Mobile | Firefox Mobile/154 Android Generic Smartphone |
|
|
||||||
| Safari, iPhone | iPhone iOS 17 | Safari - iOS Mobile | Mobile Safari/17 iOS iPhone |
|
|
||||||
| Huawei HarmonyOS phone | HuaweiBrowser/6 HarmonyOS | Chrome - Android Mobile❌ | Huawei Browser/6 Android❌ Huawei Browser |
|
|
||||||
| GPTBot | GPTBot (AI) | Bot | GPTBot/1 Spider |
|
|
||||||
| Googlebot (disguised) | Googlebot (search) | Bot | Googlebot/2 Android❌ Spider |
|
|
||||||
| Facebook preview (disguised) | Facebook | Chrome - Android Mobile❌ | FacebookBot/1 Android Pixel 7 ❌ |
|
|
||||||
| Meta crawler (disguised) | Meta-ExternalAgent (AI) | Bot | Chrome/145 Windows ❌ |
|
|
||||||
| WhatsApp preview | WhatsApp | Browser - Other❌ | WhatsApp/10 Spider |
|
|
||||||
| Bytespider | Bytespider | Bot | Bytespider/ Android❌ Generic Smartphone |
|
|
||||||
| BingPreview | BingPreview | Browser - Windows❌ | BingPreview/1 Windows❌ Spider |
|
|
||||||
| AhrefsBot | AhrefsBot | Bot | AhrefsBot/7 Spider |
|
|
||||||
| python-requests | python-requests/2.32.5 | Other | Python Requests/2 |
|
|
||||||
|
|
||||||
- ❌ marks incorrect data such as an OS from disguise, Android 10; K (compat) on modern devices, or a missed identity
|
Crawler detection was also tested against real-world crawler UAs from [monperrus/crawler-user-agents](https://github.com/monperrus/crawler-user-agents). Here user-agent-parser got only 32% right and worse, crashed on 5 UAs. A slight difference was found with the other contenders, user-agents coming at 60% and ua-parser at 64% correct. Our module **uarite scores 95%**, and could detect _which_ crawler it is for 80% (bot field set).
|
||||||
- ¹ `r.pretty` shown as is
|
|
||||||
- ² `parse_ua(ua)` shown as is
|
|
||||||
- ³ `{r.user_agent.family}/{r.user_agent.major} {r.os.family} {r.device.family}`
|
|
||||||
|
|
||||||
On our modern-browser test set, scoring only fully correct results (family, version, and OS all right): **uarite 100%**, ua-parser and user-agents 79%. The fastuaparser heuristic resolves the family and OS in 91% of cases, but reports no version numbers at all, so it cannot be scored on the full criterion.
|
## Performance
|
||||||
|
|
||||||
Crawler detection was tested against [real world UAs](https://github.com/monperrus/crawler-user-agents): **uarite 97%**, fastuaparser 84%, ua-parser 64%, user-agents 60%.
|
All compared parsers cache repeated User-Agents, making cache hits effectively free. The useful difference is therefore the first parse of a new string.
|
||||||
|
|
||||||
### Performance
|
In our benchmarks, uncached uarite parses take roughly **3–7 µs**. user-agent-parser is in the same general range at **~7 µs**, while the pure-Python ua-parser/user-agents path takes roughly **130–250 µs**, which can be a considerable slowdown.
|
||||||
|
|
||||||
Import and first parse takes about **10 ms** for uarite and effectively nothing for fastuaparser, compared with 50–90 ms for ua-parser depending on backend.
|
## Design
|
||||||
|
|
||||||

|
Rather than a large regex database trying to match any possible UA to given fields, we actually parse the modern forms of UA strings, and take the most specific interpretation of them to avoid the mess of compatibility tags they usually contain. This is built against modern traffic, including the AI crawlers that make up a large part of today's traffic, and for modern browsers — purposefully ignoring the decades of history other UA parser frameworks carry.
|
||||||
_User-Agents parsed per second per CPU core, first parse of unseen strings, with equal shares of browser and crawler UAs. One-off setup costs excluded. Cached results and fastuaparser (1 million) are left out of the graph._
|
|
||||||
|
|
||||||
On raw speed fastuaparser wins: a few string searches per UA, no cache needed. The trade-off shows in the accuracy table above — no versions, no crawler names. All other parsers cache results. With cache hits, **uarite reaches about 36 million lookups per second**, compared with about 5 million for ua-parser and 600 000 for user-agents.
|
The most important feature, absent from others, are the built-in pretty UA strings suitable for user interfaces and logging. Hopefully you will find use for that. And in case something could be better, please report an issue.
|
||||||
|
|
||||||
## Why yet another UA parser
|
Until now I had been using those other modules, building my own pretty UA formatting on top of them. Where the modules had misdetections, I have tried reporting bugs but the upstream didn't have any interest in fixing their database. Therefore, I found it easier to write my own completely from a modern starting point, and uarite is that thing, done right, as I think. Hopefully this helps you too.
|
||||||
|
|
||||||
Rather than relying on a large historical regex database, the parser focuses on modern UA formats and parses them directly, choosing the most specific interpretation available. This keeps the implementation small while handling today's browsers and crawler traffic well. Until now, I had been using those other modules and building my own pretty-UA formatting on top of them, fixing by post processing issues the upstream didn't care of.
|
|
||||||
|
|
||||||
Eventually it became easier to start over with a parser designed around modern traffic. The result is uarite.
|
|
||||||
|
|
||||||
Hopefully it helps you too. Star my [GitHub](https://github.com/leovasanko/uarite) if it did.
|
|
||||||
|
|||||||
@@ -1,694 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
|
||||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
||||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="758.3677pt" height="86.04pt" viewBox="0 0 758.3677 86.04" xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
||||||
<metadata>
|
|
||||||
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
||||||
<cc:Work>
|
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
|
||||||
<dc:date>2026-09-09T18:32:39.096963</dc:date>
|
|
||||||
<dc:format>image/svg+xml</dc:format>
|
|
||||||
<dc:creator>
|
|
||||||
<cc:Agent>
|
|
||||||
<dc:title>Matplotlib v3.11.1, https://matplotlib.org/</dc:title>
|
|
||||||
</cc:Agent>
|
|
||||||
</dc:creator>
|
|
||||||
</cc:Work>
|
|
||||||
</rdf:RDF>
|
|
||||||
</metadata>
|
|
||||||
<defs>
|
|
||||||
<style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
|
|
||||||
</defs>
|
|
||||||
<g id="figure_1">
|
|
||||||
<g id="patch_1">
|
|
||||||
<path d="M 0 86.04
|
|
||||||
L 758.3677 86.04
|
|
||||||
L 758.3677 0
|
|
||||||
L 0 0
|
|
||||||
L 0 86.04
|
|
||||||
z
|
|
||||||
" style="fill: none"/>
|
|
||||||
</g>
|
|
||||||
<g id="axes_1">
|
|
||||||
<g id="patch_2">
|
|
||||||
<path d="M 1.44 80.82
|
|
||||||
L 38.571238 80.82
|
|
||||||
L 38.571238 67.958589
|
|
||||||
L 1.44 67.958589
|
|
||||||
z
|
|
||||||
" clip-path="url(#p4041b231bc)" style="fill: #6e6e6e"/>
|
|
||||||
</g>
|
|
||||||
<g id="patch_3">
|
|
||||||
<path d="M 1.44 65.135353
|
|
||||||
L 40.996285 65.135353
|
|
||||||
L 40.996285 52.273942
|
|
||||||
L 1.44 52.273942
|
|
||||||
z
|
|
||||||
" clip-path="url(#p4041b231bc)" style="fill: #6e6e6e"/>
|
|
||||||
</g>
|
|
||||||
<g id="patch_4">
|
|
||||||
<path d="M 1.44 49.450705
|
|
||||||
L 169.540418 49.450705
|
|
||||||
L 169.540418 36.589295
|
|
||||||
L 1.44 36.589295
|
|
||||||
z
|
|
||||||
" clip-path="url(#p4041b231bc)" style="fill: #6e6e6e"/>
|
|
||||||
</g>
|
|
||||||
<g id="patch_5">
|
|
||||||
<path d="M 1.44 33.766058
|
|
||||||
L 317.786457 33.766058
|
|
||||||
L 317.786457 20.904647
|
|
||||||
L 1.44 20.904647
|
|
||||||
z
|
|
||||||
" clip-path="url(#p4041b231bc)" style="fill: #6e6e6e"/>
|
|
||||||
</g>
|
|
||||||
<g id="patch_6">
|
|
||||||
<path d="M 1.44 18.081411
|
|
||||||
L 671.04 18.081411
|
|
||||||
L 671.04 5.22
|
|
||||||
L 1.44 5.22
|
|
||||||
z
|
|
||||||
" clip-path="url(#p4041b231bc)" style="fill: #2b6cb0"/>
|
|
||||||
</g>
|
|
||||||
<g id="text_1">
|
|
||||||
<!-- 3 100 user-agents -->
|
|
||||||
<g style="fill: #767676" transform="translate(46.606438 78.658335) scale(0.11 -0.11)">
|
|
||||||
<defs>
|
|
||||||
<path id="DejaVuSans-16" d="M 2597 2516
|
|
||||||
Q 3050 2419 3304 2112
|
|
||||||
Q 3559 1806 3559 1356
|
|
||||||
Q 3559 666 3084 287
|
|
||||||
Q 2609 -91 1734 -91
|
|
||||||
Q 1441 -91 1130 -33
|
|
||||||
Q 819 25 488 141
|
|
||||||
L 488 750
|
|
||||||
Q 750 597 1062 519
|
|
||||||
Q 1375 441 1716 441
|
|
||||||
Q 2309 441 2620 675
|
|
||||||
Q 2931 909 2931 1356
|
|
||||||
Q 2931 1769 2642 2001
|
|
||||||
Q 2353 2234 1838 2234
|
|
||||||
L 1294 2234
|
|
||||||
L 1294 2753
|
|
||||||
L 1863 2753
|
|
||||||
Q 2328 2753 2575 2939
|
|
||||||
Q 2822 3125 2822 3475
|
|
||||||
Q 2822 3834 2567 4026
|
|
||||||
Q 2313 4219 1838 4219
|
|
||||||
Q 1578 4219 1281 4162
|
|
||||||
Q 984 4106 628 3988
|
|
||||||
L 628 4550
|
|
||||||
Q 988 4650 1302 4700
|
|
||||||
Q 1616 4750 1894 4750
|
|
||||||
Q 2613 4750 3031 4423
|
|
||||||
Q 3450 4097 3450 3541
|
|
||||||
Q 3450 3153 3228 2886
|
|
||||||
Q 3006 2619 2597 2516
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-62" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-14" d="M 794 531
|
|
||||||
L 1825 531
|
|
||||||
L 1825 4091
|
|
||||||
L 703 3866
|
|
||||||
L 703 4441
|
|
||||||
L 1819 4666
|
|
||||||
L 2450 4666
|
|
||||||
L 2450 531
|
|
||||||
L 3481 531
|
|
||||||
L 3481 0
|
|
||||||
L 794 0
|
|
||||||
L 794 531
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-13" d="M 2034 4250
|
|
||||||
Q 1547 4250 1301 3770
|
|
||||||
Q 1056 3291 1056 2328
|
|
||||||
Q 1056 1369 1301 889
|
|
||||||
Q 1547 409 2034 409
|
|
||||||
Q 2525 409 2770 889
|
|
||||||
Q 3016 1369 3016 2328
|
|
||||||
Q 3016 3291 2770 3770
|
|
||||||
Q 2525 4250 2034 4250
|
|
||||||
z
|
|
||||||
M 2034 4750
|
|
||||||
Q 2819 4750 3233 4129
|
|
||||||
Q 3647 3509 3647 2328
|
|
||||||
Q 3647 1150 3233 529
|
|
||||||
Q 2819 -91 2034 -91
|
|
||||||
Q 1250 -91 836 529
|
|
||||||
Q 422 1150 422 2328
|
|
||||||
Q 422 3509 836 4129
|
|
||||||
Q 1250 4750 2034 4750
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-3" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-58" d="M 544 1381
|
|
||||||
L 544 3500
|
|
||||||
L 1119 3500
|
|
||||||
L 1119 1403
|
|
||||||
Q 1119 906 1312 657
|
|
||||||
Q 1506 409 1894 409
|
|
||||||
Q 2359 409 2629 706
|
|
||||||
Q 2900 1003 2900 1516
|
|
||||||
L 2900 3500
|
|
||||||
L 3475 3500
|
|
||||||
L 3475 0
|
|
||||||
L 2900 0
|
|
||||||
L 2900 538
|
|
||||||
Q 2691 219 2414 64
|
|
||||||
Q 2138 -91 1772 -91
|
|
||||||
Q 1169 -91 856 284
|
|
||||||
Q 544 659 544 1381
|
|
||||||
z
|
|
||||||
M 1991 3584
|
|
||||||
L 1991 3584
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-56" d="M 2834 3397
|
|
||||||
L 2834 2853
|
|
||||||
Q 2591 2978 2328 3040
|
|
||||||
Q 2066 3103 1784 3103
|
|
||||||
Q 1356 3103 1142 2972
|
|
||||||
Q 928 2841 928 2578
|
|
||||||
Q 928 2378 1081 2264
|
|
||||||
Q 1234 2150 1697 2047
|
|
||||||
L 1894 2003
|
|
||||||
Q 2506 1872 2764 1633
|
|
||||||
Q 3022 1394 3022 966
|
|
||||||
Q 3022 478 2636 193
|
|
||||||
Q 2250 -91 1575 -91
|
|
||||||
Q 1294 -91 989 -36
|
|
||||||
Q 684 19 347 128
|
|
||||||
L 347 722
|
|
||||||
Q 666 556 975 473
|
|
||||||
Q 1284 391 1588 391
|
|
||||||
Q 1994 391 2212 530
|
|
||||||
Q 2431 669 2431 922
|
|
||||||
Q 2431 1156 2273 1281
|
|
||||||
Q 2116 1406 1581 1522
|
|
||||||
L 1381 1569
|
|
||||||
Q 847 1681 609 1914
|
|
||||||
Q 372 2147 372 2553
|
|
||||||
Q 372 3047 722 3315
|
|
||||||
Q 1072 3584 1716 3584
|
|
||||||
Q 2034 3584 2315 3537
|
|
||||||
Q 2597 3491 2834 3397
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-48" d="M 3597 1894
|
|
||||||
L 3597 1613
|
|
||||||
L 953 1613
|
|
||||||
Q 991 1019 1311 708
|
|
||||||
Q 1631 397 2203 397
|
|
||||||
Q 2534 397 2845 478
|
|
||||||
Q 3156 559 3463 722
|
|
||||||
L 3463 178
|
|
||||||
Q 3153 47 2828 -22
|
|
||||||
Q 2503 -91 2169 -91
|
|
||||||
Q 1331 -91 842 396
|
|
||||||
Q 353 884 353 1716
|
|
||||||
Q 353 2575 817 3079
|
|
||||||
Q 1281 3584 2069 3584
|
|
||||||
Q 2775 3584 3186 3129
|
|
||||||
Q 3597 2675 3597 1894
|
|
||||||
z
|
|
||||||
M 3022 2063
|
|
||||||
Q 3016 2534 2758 2815
|
|
||||||
Q 2500 3097 2075 3097
|
|
||||||
Q 1594 3097 1305 2825
|
|
||||||
Q 1016 2553 972 2059
|
|
||||||
L 3022 2063
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-55" d="M 2631 2963
|
|
||||||
Q 2534 3019 2420 3045
|
|
||||||
Q 2306 3072 2169 3072
|
|
||||||
Q 1681 3072 1420 2755
|
|
||||||
Q 1159 2438 1159 1844
|
|
||||||
L 1159 0
|
|
||||||
L 581 0
|
|
||||||
L 581 3500
|
|
||||||
L 1159 3500
|
|
||||||
L 1159 2956
|
|
||||||
Q 1341 3275 1631 3429
|
|
||||||
Q 1922 3584 2338 3584
|
|
||||||
Q 2397 3584 2469 3576
|
|
||||||
Q 2541 3569 2628 3553
|
|
||||||
L 2631 2963
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-10" d="M 313 2009
|
|
||||||
L 1997 2009
|
|
||||||
L 1997 1497
|
|
||||||
L 313 1497
|
|
||||||
L 313 2009
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-44" d="M 2194 1759
|
|
||||||
Q 1497 1759 1228 1600
|
|
||||||
Q 959 1441 959 1056
|
|
||||||
Q 959 750 1161 570
|
|
||||||
Q 1363 391 1709 391
|
|
||||||
Q 2188 391 2477 730
|
|
||||||
Q 2766 1069 2766 1631
|
|
||||||
L 2766 1759
|
|
||||||
L 2194 1759
|
|
||||||
z
|
|
||||||
M 3341 1997
|
|
||||||
L 3341 0
|
|
||||||
L 2766 0
|
|
||||||
L 2766 531
|
|
||||||
Q 2569 213 2275 61
|
|
||||||
Q 1981 -91 1556 -91
|
|
||||||
Q 1019 -91 701 211
|
|
||||||
Q 384 513 384 1019
|
|
||||||
Q 384 1609 779 1909
|
|
||||||
Q 1175 2209 1959 2209
|
|
||||||
L 2766 2209
|
|
||||||
L 2766 2266
|
|
||||||
Q 2766 2663 2505 2880
|
|
||||||
Q 2244 3097 1772 3097
|
|
||||||
Q 1472 3097 1187 3025
|
|
||||||
Q 903 2953 641 2809
|
|
||||||
L 641 3341
|
|
||||||
Q 956 3463 1253 3523
|
|
||||||
Q 1550 3584 1831 3584
|
|
||||||
Q 2591 3584 2966 3190
|
|
||||||
Q 3341 2797 3341 1997
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-4a" d="M 2906 1791
|
|
||||||
Q 2906 2416 2648 2759
|
|
||||||
Q 2391 3103 1925 3103
|
|
||||||
Q 1463 3103 1205 2759
|
|
||||||
Q 947 2416 947 1791
|
|
||||||
Q 947 1169 1205 825
|
|
||||||
Q 1463 481 1925 481
|
|
||||||
Q 2391 481 2648 825
|
|
||||||
Q 2906 1169 2906 1791
|
|
||||||
z
|
|
||||||
M 3481 434
|
|
||||||
Q 3481 -459 3084 -895
|
|
||||||
Q 2688 -1331 1869 -1331
|
|
||||||
Q 1566 -1331 1297 -1286
|
|
||||||
Q 1028 -1241 775 -1147
|
|
||||||
L 775 -588
|
|
||||||
Q 1028 -725 1275 -790
|
|
||||||
Q 1522 -856 1778 -856
|
|
||||||
Q 2344 -856 2625 -561
|
|
||||||
Q 2906 -266 2906 331
|
|
||||||
L 2906 616
|
|
||||||
Q 2728 306 2450 153
|
|
||||||
Q 2172 0 1784 0
|
|
||||||
Q 1141 0 747 490
|
|
||||||
Q 353 981 353 1791
|
|
||||||
Q 353 2603 747 3093
|
|
||||||
Q 1141 3584 1784 3584
|
|
||||||
Q 2172 3584 2450 3431
|
|
||||||
Q 2728 3278 2906 2969
|
|
||||||
L 2906 3500
|
|
||||||
L 3481 3500
|
|
||||||
L 3481 434
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-51" d="M 3513 2113
|
|
||||||
L 3513 0
|
|
||||||
L 2938 0
|
|
||||||
L 2938 2094
|
|
||||||
Q 2938 2591 2744 2837
|
|
||||||
Q 2550 3084 2163 3084
|
|
||||||
Q 1697 3084 1428 2787
|
|
||||||
Q 1159 2491 1159 1978
|
|
||||||
L 1159 0
|
|
||||||
L 581 0
|
|
||||||
L 581 3500
|
|
||||||
L 1159 3500
|
|
||||||
L 1159 2956
|
|
||||||
Q 1366 3272 1645 3428
|
|
||||||
Q 1925 3584 2291 3584
|
|
||||||
Q 2894 3584 3203 3211
|
|
||||||
Q 3513 2838 3513 2113
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-57" d="M 1172 4494
|
|
||||||
L 1172 3500
|
|
||||||
L 2356 3500
|
|
||||||
L 2356 3053
|
|
||||||
L 1172 3053
|
|
||||||
L 1172 1153
|
|
||||||
Q 1172 725 1289 603
|
|
||||||
Q 1406 481 1766 481
|
|
||||||
L 2356 481
|
|
||||||
L 2356 0
|
|
||||||
L 1766 0
|
|
||||||
Q 1100 0 847 248
|
|
||||||
Q 594 497 594 1153
|
|
||||||
L 594 3053
|
|
||||||
L 172 3053
|
|
||||||
L 172 3500
|
|
||||||
L 594 3500
|
|
||||||
L 594 4494
|
|
||||||
L 1172 4494
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
</defs>
|
|
||||||
<use xlink:href="#DejaVuSans-16"/>
|
|
||||||
<use xlink:href="#DejaVuSans-62" transform="translate(63.625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-14" transform="translate(95.40625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(159.03125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(222.65625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(286.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(318.0625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(349.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(413.21875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(465.3125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(526.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-10" transform="translate(561.5625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(597.640625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-4a" transform="translate(658.921875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(722.40625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-51" transform="translate(783.9375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-57" transform="translate(847.3125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(886.515625 0)"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g id="text_2">
|
|
||||||
<!-- 3 300 ua-parser -->
|
|
||||||
<g style="fill: #767676" transform="translate(49.031485 62.973687) scale(0.11 -0.11)">
|
|
||||||
<defs>
|
|
||||||
<path id="DejaVuSans-53" d="M 1159 525
|
|
||||||
L 1159 -1331
|
|
||||||
L 581 -1331
|
|
||||||
L 581 3500
|
|
||||||
L 1159 3500
|
|
||||||
L 1159 2969
|
|
||||||
Q 1341 3281 1617 3432
|
|
||||||
Q 1894 3584 2278 3584
|
|
||||||
Q 2916 3584 3314 3078
|
|
||||||
Q 3713 2572 3713 1747
|
|
||||||
Q 3713 922 3314 415
|
|
||||||
Q 2916 -91 2278 -91
|
|
||||||
Q 1894 -91 1617 61
|
|
||||||
Q 1341 213 1159 525
|
|
||||||
z
|
|
||||||
M 3116 1747
|
|
||||||
Q 3116 2381 2855 2742
|
|
||||||
Q 2594 3103 2138 3103
|
|
||||||
Q 1681 3103 1420 2742
|
|
||||||
Q 1159 2381 1159 1747
|
|
||||||
Q 1159 1113 1420 752
|
|
||||||
Q 1681 391 2138 391
|
|
||||||
Q 2594 391 2855 752
|
|
||||||
Q 3116 1113 3116 1747
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
</defs>
|
|
||||||
<use xlink:href="#DejaVuSans-16"/>
|
|
||||||
<use xlink:href="#DejaVuSans-62" transform="translate(63.625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-16" transform="translate(95.40625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(159.03125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(222.65625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(286.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(318.0625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(349.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(413.21875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-10" transform="translate(474.5 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-53" transform="translate(510.578125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(574.0625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(635.34375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(676.453125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(728.546875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(790.078125 0)"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g id="text_3">
|
|
||||||
<!-- 14 000 ua-parser (RE2) -->
|
|
||||||
<g style="fill: #767676" transform="translate(177.575618 47.28904) scale(0.11 -0.11)">
|
|
||||||
<defs>
|
|
||||||
<path id="DejaVuSans-17" d="M 2419 4116
|
|
||||||
L 825 1625
|
|
||||||
L 2419 1625
|
|
||||||
L 2419 4116
|
|
||||||
z
|
|
||||||
M 2253 4666
|
|
||||||
L 3047 4666
|
|
||||||
L 3047 1625
|
|
||||||
L 3713 1625
|
|
||||||
L 3713 1100
|
|
||||||
L 3047 1100
|
|
||||||
L 3047 0
|
|
||||||
L 2419 0
|
|
||||||
L 2419 1100
|
|
||||||
L 313 1100
|
|
||||||
L 313 1709
|
|
||||||
L 2253 4666
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-b" d="M 1984 4856
|
|
||||||
Q 1566 4138 1362 3434
|
|
||||||
Q 1159 2731 1159 2009
|
|
||||||
Q 1159 1288 1364 580
|
|
||||||
Q 1569 -128 1984 -844
|
|
||||||
L 1484 -844
|
|
||||||
Q 1016 -109 783 600
|
|
||||||
Q 550 1309 550 2009
|
|
||||||
Q 550 2706 781 3412
|
|
||||||
Q 1013 4119 1484 4856
|
|
||||||
L 1984 4856
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-35" d="M 2841 2188
|
|
||||||
Q 3044 2119 3236 1894
|
|
||||||
Q 3428 1669 3622 1275
|
|
||||||
L 4263 0
|
|
||||||
L 3584 0
|
|
||||||
L 2988 1197
|
|
||||||
Q 2756 1666 2539 1819
|
|
||||||
Q 2322 1972 1947 1972
|
|
||||||
L 1259 1972
|
|
||||||
L 1259 0
|
|
||||||
L 628 0
|
|
||||||
L 628 4666
|
|
||||||
L 2053 4666
|
|
||||||
Q 2853 4666 3247 4331
|
|
||||||
Q 3641 3997 3641 3322
|
|
||||||
Q 3641 2881 3436 2590
|
|
||||||
Q 3231 2300 2841 2188
|
|
||||||
z
|
|
||||||
M 1259 4147
|
|
||||||
L 1259 2491
|
|
||||||
L 2053 2491
|
|
||||||
Q 2509 2491 2742 2702
|
|
||||||
Q 2975 2913 2975 3322
|
|
||||||
Q 2975 3731 2742 3939
|
|
||||||
Q 2509 4147 2053 4147
|
|
||||||
L 1259 4147
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-28" d="M 628 4666
|
|
||||||
L 3578 4666
|
|
||||||
L 3578 4134
|
|
||||||
L 1259 4134
|
|
||||||
L 1259 2753
|
|
||||||
L 3481 2753
|
|
||||||
L 3481 2222
|
|
||||||
L 1259 2222
|
|
||||||
L 1259 531
|
|
||||||
L 3634 531
|
|
||||||
L 3634 0
|
|
||||||
L 628 0
|
|
||||||
L 628 4666
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-15" d="M 1228 531
|
|
||||||
L 3431 531
|
|
||||||
L 3431 0
|
|
||||||
L 469 0
|
|
||||||
L 469 531
|
|
||||||
Q 828 903 1448 1529
|
|
||||||
Q 2069 2156 2228 2338
|
|
||||||
Q 2531 2678 2651 2914
|
|
||||||
Q 2772 3150 2772 3378
|
|
||||||
Q 2772 3750 2511 3984
|
|
||||||
Q 2250 4219 1831 4219
|
|
||||||
Q 1534 4219 1204 4116
|
|
||||||
Q 875 4013 500 3803
|
|
||||||
L 500 4441
|
|
||||||
Q 881 4594 1212 4672
|
|
||||||
Q 1544 4750 1819 4750
|
|
||||||
Q 2544 4750 2975 4387
|
|
||||||
Q 3406 4025 3406 3419
|
|
||||||
Q 3406 3131 3298 2873
|
|
||||||
Q 3191 2616 2906 2266
|
|
||||||
Q 2828 2175 2409 1742
|
|
||||||
Q 1991 1309 1228 531
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-c" d="M 513 4856
|
|
||||||
L 1013 4856
|
|
||||||
Q 1481 4119 1714 3412
|
|
||||||
Q 1947 2706 1947 2009
|
|
||||||
Q 1947 1309 1714 600
|
|
||||||
Q 1481 -109 1013 -844
|
|
||||||
L 513 -844
|
|
||||||
Q 928 -128 1133 580
|
|
||||||
Q 1338 1288 1338 2009
|
|
||||||
Q 1338 2731 1133 3434
|
|
||||||
Q 928 4138 513 4856
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
</defs>
|
|
||||||
<use xlink:href="#DejaVuSans-14"/>
|
|
||||||
<use xlink:href="#DejaVuSans-17" transform="translate(63.625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-62" transform="translate(127.25 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(159.03125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(222.65625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(286.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(349.90625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(381.6875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(413.46875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(476.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-10" transform="translate(538.125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-53" transform="translate(574.203125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(637.6875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(698.96875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(740.078125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(792.171875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(853.703125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(894.8125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-b" transform="translate(926.59375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-35" transform="translate(965.609375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-28" transform="translate(1035.09375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-15" transform="translate(1098.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-c" transform="translate(1161.90625 0)"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g id="text_4">
|
|
||||||
<!-- 26 000 ua-parser (Rust) -->
|
|
||||||
<g style="fill: #767676" transform="translate(325.821657 31.604393) scale(0.11 -0.11)">
|
|
||||||
<defs>
|
|
||||||
<path id="DejaVuSans-19" d="M 2113 2584
|
|
||||||
Q 1688 2584 1439 2293
|
|
||||||
Q 1191 2003 1191 1497
|
|
||||||
Q 1191 994 1439 701
|
|
||||||
Q 1688 409 2113 409
|
|
||||||
Q 2538 409 2786 701
|
|
||||||
Q 3034 994 3034 1497
|
|
||||||
Q 3034 2003 2786 2293
|
|
||||||
Q 2538 2584 2113 2584
|
|
||||||
z
|
|
||||||
M 3366 4563
|
|
||||||
L 3366 3988
|
|
||||||
Q 3128 4100 2886 4159
|
|
||||||
Q 2644 4219 2406 4219
|
|
||||||
Q 1781 4219 1451 3797
|
|
||||||
Q 1122 3375 1075 2522
|
|
||||||
Q 1259 2794 1537 2939
|
|
||||||
Q 1816 3084 2150 3084
|
|
||||||
Q 2853 3084 3261 2657
|
|
||||||
Q 3669 2231 3669 1497
|
|
||||||
Q 3669 778 3244 343
|
|
||||||
Q 2819 -91 2113 -91
|
|
||||||
Q 1303 -91 875 529
|
|
||||||
Q 447 1150 447 2328
|
|
||||||
Q 447 3434 972 4092
|
|
||||||
Q 1497 4750 2381 4750
|
|
||||||
Q 2619 4750 2861 4703
|
|
||||||
Q 3103 4656 3366 4563
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
</defs>
|
|
||||||
<use xlink:href="#DejaVuSans-15"/>
|
|
||||||
<use xlink:href="#DejaVuSans-19" transform="translate(63.625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-62" transform="translate(127.25 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(159.03125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(222.65625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(286.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(349.90625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(381.6875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(413.46875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(476.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-10" transform="translate(538.125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-53" transform="translate(574.203125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(637.6875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(698.96875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(740.078125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(792.171875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(853.703125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(894.8125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-b" transform="translate(926.59375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-35" transform="translate(965.609375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(1030.609375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-56" transform="translate(1093.984375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-57" transform="translate(1146.078125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-c" transform="translate(1185.28125 0)"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g id="text_5">
|
|
||||||
<!-- 56 000 uarite -->
|
|
||||||
<g style="fill: #767676" transform="translate(679.0752 15.920175) scale(0.11 -0.11)">
|
|
||||||
<defs>
|
|
||||||
<path id="DejaVuSans-18" d="M 691 4666
|
|
||||||
L 3169 4666
|
|
||||||
L 3169 4134
|
|
||||||
L 1269 4134
|
|
||||||
L 1269 2991
|
|
||||||
Q 1406 3038 1543 3061
|
|
||||||
Q 1681 3084 1819 3084
|
|
||||||
Q 2600 3084 3056 2656
|
|
||||||
Q 3513 2228 3513 1497
|
|
||||||
Q 3513 744 3044 326
|
|
||||||
Q 2575 -91 1722 -91
|
|
||||||
Q 1428 -91 1123 -41
|
|
||||||
Q 819 9 494 109
|
|
||||||
L 494 744
|
|
||||||
Q 775 591 1075 516
|
|
||||||
Q 1375 441 1709 441
|
|
||||||
Q 2250 441 2565 725
|
|
||||||
Q 2881 1009 2881 1497
|
|
||||||
Q 2881 1984 2565 2268
|
|
||||||
Q 2250 2553 1709 2553
|
|
||||||
Q 1456 2553 1204 2497
|
|
||||||
Q 953 2441 691 2322
|
|
||||||
L 691 4666
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
<path id="DejaVuSans-4c" d="M 603 3500
|
|
||||||
L 1178 3500
|
|
||||||
L 1178 0
|
|
||||||
L 603 0
|
|
||||||
L 603 3500
|
|
||||||
z
|
|
||||||
M 603 4863
|
|
||||||
L 1178 4863
|
|
||||||
L 1178 4134
|
|
||||||
L 603 4134
|
|
||||||
L 603 4863
|
|
||||||
z
|
|
||||||
" transform="scale(0.015625)"/>
|
|
||||||
</defs>
|
|
||||||
<use xlink:href="#DejaVuSans-18"/>
|
|
||||||
<use xlink:href="#DejaVuSans-19" transform="translate(63.625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-62" transform="translate(127.25 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(159.03125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(222.65625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-13" transform="translate(286.28125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(349.90625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-3" transform="translate(381.6875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-58" transform="translate(413.46875 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-44" transform="translate(476.84375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-55" transform="translate(538.125 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-4c" transform="translate(579.234375 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-57" transform="translate(607.015625 0)"/>
|
|
||||||
<use xlink:href="#DejaVuSans-48" transform="translate(646.21875 0)"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<defs>
|
|
||||||
<clipPath id="p4041b231bc">
|
|
||||||
<rect x="1.44" y="1.44" width="669.6" height="83.16"/>
|
|
||||||
</clipPath>
|
|
||||||
</defs>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 19 KiB |
+2
-2
@@ -17,7 +17,7 @@ benchmark-only dependencies, pulled ad hoc via `uv run --with`.
|
|||||||
- `prettytable.py` — prints the accuracy-comparison markdown table:
|
- `prettytable.py` — prints the accuracy-comparison markdown table:
|
||||||
|
|
||||||
```
|
```
|
||||||
uv run --with ua-parser --with fastuaparser python scripts/prettytable.py
|
uv run --with ua-parser --with user-agents python scripts/prettytable.py
|
||||||
```
|
```
|
||||||
|
|
||||||
- `bench.py` — prints browser-accuracy counts, crawler-detection rates,
|
- `bench.py` — prints browser-accuracy counts, crawler-detection rates,
|
||||||
@@ -25,6 +25,6 @@ benchmark-only dependencies, pulled ad hoc via `uv run --with`.
|
|||||||
mix, bot storm) with cache statistics:
|
mix, bot storm) with cache statistics:
|
||||||
|
|
||||||
```
|
```
|
||||||
uv run --with ua-parser --with user-agents --with fastuaparser \
|
uv run --with ua-parser --with user-agents --with user-agent-parser \
|
||||||
python scripts/bench.py
|
python scripts/bench.py
|
||||||
```
|
```
|
||||||
|
|||||||
+49
-133
@@ -1,25 +1,14 @@
|
|||||||
# /// script
|
"""Benchmark uarite vs ua-parser vs user-agents vs user-agent-parser.
|
||||||
# requires-python = ">=3.14"
|
|
||||||
# dependencies = [
|
|
||||||
# "fastuaparser>=0.1.4",
|
|
||||||
# "ua-parser[re2,regex]>=1.0.2",
|
|
||||||
# "uarite",
|
|
||||||
# "user-agents>=2.2.0",
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# [tool.uv.sources]
|
|
||||||
# uarite = { path = "..", editable = true }
|
|
||||||
# ///
|
|
||||||
"""Benchmark uarite vs ua-parser vs user-agents vs fastuaparser.
|
|
||||||
|
|
||||||
Reproduces the README's numbers: browser accuracy on 100 modern UAs,
|
Reproduces the README's numbers: browser accuracy on 100 modern UAs,
|
||||||
crawler detection on 2163 real-world crawler UAs, and timing (unique UAs,
|
crawler detection on 2163 real-world crawler UAs, and timing (unique UAs,
|
||||||
a realistic repeat/unique mix, a pure bot storm) with cache introspection.
|
a realistic repeat/unique mix, a pure bot storm) with cache introspection.
|
||||||
|
|
||||||
Data lives in scripts/data (see download_data.py). All dependencies,
|
Data lives in scripts/data (see download_data.py). Requires uarite
|
||||||
including uarite itself (editable), are declared inline:
|
(installed) plus the benchmark-only reference parsers:
|
||||||
|
|
||||||
uv run scripts/bench.py
|
uv run --with ua-parser --with user-agents --with user-agent-parser \
|
||||||
|
python scripts/bench.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@@ -28,56 +17,17 @@ import re
|
|||||||
import timeit
|
import timeit
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import ua_parser
|
|
||||||
from fastuaparser import parse_ua as fua_parse
|
|
||||||
from ua_parser import parse as ua_parse
|
from ua_parser import parse as ua_parse
|
||||||
|
from user_agent_parser import parse as uap_parse
|
||||||
from user_agents import parse as uas_parse
|
from user_agents import parse as uas_parse
|
||||||
|
|
||||||
from uarite import uaparse
|
from uarite import uaparse
|
||||||
|
from uarite.core import _parse_client
|
||||||
ALL_DOMAINS = (
|
|
||||||
ua_parser.Domain.USER_AGENT | ua_parser.Domain.OS | ua_parser.Domain.DEVICE
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
_VARIANTS = {}
|
|
||||||
|
|
||||||
|
|
||||||
def ua_variant(name):
|
|
||||||
"""ua-parser with a specific resolver backend (pure/re2/rust), lazily
|
|
||||||
built so its one-time database load lands in the untimed warm-up call.
|
|
||||||
The default parse() picks whichever native backend is installed, so
|
|
||||||
backends must be forced explicitly to benchmark them separately."""
|
|
||||||
if name not in _VARIANTS:
|
|
||||||
ctor = {
|
|
||||||
"pure": ua_parser.BasicResolver,
|
|
||||||
"re2": ua_parser.Re2Resolver,
|
|
||||||
"rust": ua_parser.RegexResolver,
|
|
||||||
}[name]
|
|
||||||
parser = ua_parser.Parser(
|
|
||||||
ua_parser.CachingResolver(
|
|
||||||
ctor(ua_parser.load_builtins()), ua_parser.Cache(2000)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
_VARIANTS[name] = lambda ua: parser(ua, ALL_DOMAINS)
|
|
||||||
return _VARIANTS[name]
|
|
||||||
|
|
||||||
|
|
||||||
def uap_pure(ua):
|
|
||||||
return ua_variant("pure")(ua)
|
|
||||||
|
|
||||||
|
|
||||||
def uap_re2(ua):
|
|
||||||
return ua_variant("re2")(ua)
|
|
||||||
|
|
||||||
|
|
||||||
def uap_rust(ua):
|
|
||||||
return ua_variant("rust")(ua)
|
|
||||||
|
|
||||||
|
|
||||||
DATA = Path(__file__).parent / "data"
|
DATA = Path(__file__).parent / "data"
|
||||||
BROWSERS = json.loads((DATA / "top-user-agents.json").read_text())
|
BROWSERS = json.loads((DATA / "top-user-agents.json").read_text())
|
||||||
CRAWLERS = json.loads((DATA / "crawler-user-agents.json").read_text())
|
CRAWLERS = json.loads((DATA / "crawler-user-agents.json").read_text())
|
||||||
|
OWN = (DATA / "ua.txt").read_text().splitlines()
|
||||||
CRAWLER_UAS = [ua for c in CRAWLERS for ua in (c.get("instances") or [c["pattern"]])]
|
CRAWLER_UAS = [ua for c in CRAWLERS for ua in (c.get("instances") or [c["pattern"]])]
|
||||||
|
|
||||||
|
|
||||||
@@ -126,6 +76,7 @@ def score_browsers():
|
|||||||
for name, fn in (
|
for name, fn in (
|
||||||
("ua-parser", ua_parse),
|
("ua-parser", ua_parse),
|
||||||
("user-agents", uas_parse),
|
("user-agents", uas_parse),
|
||||||
|
("user-agent-parser", uap_parse),
|
||||||
):
|
):
|
||||||
fam_ok = ver_ok = os_ok = 0
|
fam_ok = ver_ok = os_ok = 0
|
||||||
for ua in BROWSERS:
|
for ua in BROWSERS:
|
||||||
@@ -135,6 +86,10 @@ def score_browsers():
|
|||||||
fam = r.user_agent.family or ""
|
fam = r.user_agent.family or ""
|
||||||
maj = r.user_agent.major or ""
|
maj = r.user_agent.major or ""
|
||||||
osf = r.os.family or ""
|
osf = r.os.family or ""
|
||||||
|
elif name == "user-agent-parser":
|
||||||
|
fam = r[0] or ""
|
||||||
|
maj = (r[1] or "").split(".")[0]
|
||||||
|
osf = r[2] or ""
|
||||||
else:
|
else:
|
||||||
fam = r.browser.family or ""
|
fam = r.browser.family or ""
|
||||||
maj = str(r.browser.version[0]) if r.browser.version else ""
|
maj = str(r.browser.version[0]) if r.browser.version else ""
|
||||||
@@ -144,29 +99,6 @@ def score_browsers():
|
|||||||
ver_ok += emaj == maj
|
ver_ok += emaj == maj
|
||||||
os_ok += eos == norm_os(osf)
|
os_ok += eos == norm_os(osf)
|
||||||
res[name] = (fam_ok, ver_ok, os_ok)
|
res[name] = (fam_ok, ver_ok, os_ok)
|
||||||
# fastuaparser returns one pretty string ("Chrome - Windows") and no
|
|
||||||
# version numbers, so score it on the substrings it does produce.
|
|
||||||
fam_ok = ver_ok = os_ok = 0
|
|
||||||
for ua in BROWSERS:
|
|
||||||
efam, emaj, eos = expected(ua)
|
|
||||||
pretty = fua_parse(ua)
|
|
||||||
fam_ok += efam.split()[0].lower() in pretty.lower()
|
|
||||||
ver_ok += bool(emaj) and emaj in pretty
|
|
||||||
os_ok += bool(
|
|
||||||
re.search(
|
|
||||||
{
|
|
||||||
"ios": r"iOS|iPhone|iPad",
|
|
||||||
"macos": r"Mac",
|
|
||||||
"windows": r"Windows",
|
|
||||||
"linux": r"Linux",
|
|
||||||
"android": r"Android",
|
|
||||||
}[eos],
|
|
||||||
pretty,
|
|
||||||
)
|
|
||||||
if eos
|
|
||||||
else True
|
|
||||||
)
|
|
||||||
res["fastuaparser"] = (fam_ok, ver_ok, os_ok)
|
|
||||||
fam_ok = ver_ok = os_ok = 0
|
fam_ok = ver_ok = os_ok = 0
|
||||||
for ua in BROWSERS:
|
for ua in BROWSERS:
|
||||||
efam, emaj, eos = expected(ua)
|
efam, emaj, eos = expected(ua)
|
||||||
@@ -202,7 +134,7 @@ def score_browsers():
|
|||||||
def score_crawlers():
|
def score_crawlers():
|
||||||
out = {}
|
out = {}
|
||||||
crashes = 0
|
crashes = 0
|
||||||
for name in ("ua-parser", "user-agents", "fastuaparser", "uarite"):
|
for name in ("ua-parser", "user-agents", "user-agent-parser", "uarite"):
|
||||||
det = 0
|
det = 0
|
||||||
for ua in CRAWLER_UAS:
|
for ua in CRAWLER_UAS:
|
||||||
try:
|
try:
|
||||||
@@ -214,16 +146,12 @@ def score_crawlers():
|
|||||||
)
|
)
|
||||||
elif name == "user-agents":
|
elif name == "user-agents":
|
||||||
bot = uas_parse(ua).is_bot
|
bot = uas_parse(ua).is_bot
|
||||||
elif name == "fastuaparser":
|
elif name == "user-agent-parser":
|
||||||
# "Bot" is a real verdict; "Other" is a non-browser
|
bot = uap_parse(ua)[4] == "Bot"
|
||||||
# client (wget etc.), which is automated traffic too.
|
|
||||||
bot = fua_parse(ua).split(" - ")[0] in ("Bot", "Other")
|
|
||||||
else:
|
else:
|
||||||
# Anything not recognized as a real browser is automated:
|
bot = bool(uaparse(ua).bot)
|
||||||
# known bots, generic spiders, clients, spoofed claims.
|
|
||||||
bot = uaparse(ua).kind != "browser"
|
|
||||||
except Exception:
|
except Exception:
|
||||||
crashes += name == "fastuaparser"
|
crashes += name == "user-agent-parser"
|
||||||
continue
|
continue
|
||||||
det += bot
|
det += bot
|
||||||
out[name] = det
|
out[name] = det
|
||||||
@@ -265,11 +193,9 @@ def bench_realistic():
|
|||||||
f" with 2000 mostly-unique bots)"
|
f" with 2000 mostly-unique bots)"
|
||||||
)
|
)
|
||||||
for name, fn in (
|
for name, fn in (
|
||||||
("ua-parser", uap_pure),
|
("ua-parser", ua_parse),
|
||||||
("ua-parser (re2)", uap_re2),
|
|
||||||
("ua-parser (rust)", uap_rust),
|
|
||||||
("user-agents", uas_parse),
|
("user-agents", uas_parse),
|
||||||
("fastuaparser", fua_parse),
|
("user-agent-parser", uap_parse),
|
||||||
("uarite", uaparse),
|
("uarite", uaparse),
|
||||||
):
|
):
|
||||||
fn = safe(fn)
|
fn = safe(fn)
|
||||||
@@ -278,11 +204,9 @@ def bench_realistic():
|
|||||||
print(f"{name:20} {t / len(mix) * 1e6:7.1f} µs/UA cache: {info}")
|
print(f"{name:20} {t / len(mix) * 1e6:7.1f} µs/UA cache: {info}")
|
||||||
print(f"\n## pure bot storm ({len(storm)} unique UAs, zero cache value)")
|
print(f"\n## pure bot storm ({len(storm)} unique UAs, zero cache value)")
|
||||||
for name, fn in (
|
for name, fn in (
|
||||||
("ua-parser", uap_pure),
|
("ua-parser", ua_parse),
|
||||||
("ua-parser (re2)", uap_re2),
|
|
||||||
("ua-parser (rust)", uap_rust),
|
|
||||||
("user-agents", uas_parse),
|
("user-agents", uas_parse),
|
||||||
("fastuaparser", fua_parse),
|
("user-agent-parser", uap_parse),
|
||||||
("uarite", uaparse),
|
("uarite", uaparse),
|
||||||
):
|
):
|
||||||
fn = safe(fn)
|
fn = safe(fn)
|
||||||
@@ -304,64 +228,56 @@ def safe(fn):
|
|||||||
|
|
||||||
def cache_info(name):
|
def cache_info(name):
|
||||||
if name == "uarite":
|
if name == "uarite":
|
||||||
i = uaparse.cache_info()
|
i = _parse_client.cache_info()
|
||||||
return f"{i.hits} hits / {i.misses} misses (cap 1024)"
|
return f"{i.hits} hits / {i.misses} misses (cap 1024, browsers only)"
|
||||||
if name == "fastuaparser":
|
if name == "user-agent-parser":
|
||||||
return "none (branch parser, ~1 µs flat)"
|
from user_agent_parser.parser import _cached_parse_user_agent
|
||||||
|
|
||||||
|
i = _cached_parse_user_agent.cache_info()
|
||||||
|
return f"{i.hits} hits / {i.misses} misses (cap 512 LRU)"
|
||||||
if name == "user-agents":
|
if name == "user-agents":
|
||||||
from ua_parser.user_agent_parser import _PARSE_CACHE
|
from ua_parser.user_agent_parser import _PARSE_CACHE
|
||||||
|
|
||||||
return f"{len(_PARSE_CACHE)} entries (cap 200, CLEARS when full)"
|
return f"{len(_PARSE_CACHE)} entries (cap 200, CLEARS when full)"
|
||||||
if name.startswith("ua-parser"):
|
if name == "ua-parser":
|
||||||
return "cap 2000 S3-FIFO (scan-resistant)"
|
return "cap 2000 S3-FIFO (scan-resistant)"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def bench():
|
def bench():
|
||||||
"""Cold-cache speed: a single pass over previously unseen UAs, with
|
alluas = BROWSERS + CRAWLER_UAS + OWN
|
||||||
equal shares of realistic browser and crawler strings since they take
|
n = 3
|
||||||
different parse paths. Runs before the accuracy passes, which would
|
|
||||||
otherwise warm every parser's cache with these very strings.
|
|
||||||
|
|
||||||
Each parser first parses one dummy UA (untimed) so that lazy regex
|
|
||||||
compilation and database loading do not land on the first real item —
|
|
||||||
ua-parser's first parse alone costs ~59 ms loading its database. The
|
|
||||||
cache gains nothing from it since all timed UAs are unique."""
|
|
||||||
rng = random.Random(7)
|
|
||||||
work = BROWSERS + rng.sample(CRAWLER_UAS, len(BROWSERS))
|
|
||||||
rng.shuffle(work)
|
|
||||||
res = {}
|
res = {}
|
||||||
for name, fn in (
|
for name, fn in (
|
||||||
("ua-parser", uap_pure),
|
("ua-parser", ua_parse),
|
||||||
("ua-parser (re2)", uap_re2),
|
|
||||||
("ua-parser (rust)", uap_rust),
|
|
||||||
("user-agents", uas_parse),
|
("user-agents", uas_parse),
|
||||||
("fastuaparser", fua_parse),
|
("user-agent-parser", uap_parse),
|
||||||
("uarite", uaparse),
|
("uarite", uaparse),
|
||||||
):
|
):
|
||||||
fn = safe(fn)
|
fn = safe(fn)
|
||||||
fn("Warmup/1.0 (+https://example.com/warmup)")
|
t = timeit.timeit(lambda: [fn(u) for u in alluas], number=n)
|
||||||
uaparse.cache_clear()
|
res[name] = t / n / len(alluas) * 1e6
|
||||||
t = timeit.timeit(lambda: [fn(u) for u in work], number=1)
|
# warm cache: repeat a small realistic working set many times
|
||||||
res[name] = t / len(work) * 1e6
|
working = (BROWSERS + OWN[:50]) * 10
|
||||||
return res, len(work)
|
t = timeit.timeit(lambda: [uaparse(u) for u in working], number=n)
|
||||||
|
res["uarite (warm cache)"] = t / n / len(working) * 1e6
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
res, nwork = bench()
|
print(f"## browser accuracy (n={len(BROWSERS)}): family / version / OS correct")
|
||||||
print(
|
|
||||||
f"## speed (µs per cold parse, {nwork} unique UAs,"
|
|
||||||
" half browsers / half crawlers)"
|
|
||||||
)
|
|
||||||
for k, v in res.items():
|
|
||||||
print(f"{k:20} {v:8.1f}")
|
|
||||||
print(f"\n## browser accuracy (n={len(BROWSERS)}): family / version / OS correct")
|
|
||||||
for k, (f, v, o) in score_browsers().items():
|
for k, (f, v, o) in score_browsers().items():
|
||||||
print(f"{k:14} {f:3}/100 {v:3}/100 {o:3}/100")
|
print(f"{k:14} {f:3}/100 {v:3}/100 {o:3}/100")
|
||||||
det, url_have, url_got, crashes = score_crawlers()
|
det, url_have, url_got, crashes = score_crawlers()
|
||||||
print(f"\n## crawler detection (n={len(CRAWLER_UAS)})")
|
print(f"\n## crawler detection (n={len(CRAWLER_UAS)})")
|
||||||
for k, v in det.items():
|
for k, v in det.items():
|
||||||
print(f"{k:18} {v:5} ({v / len(CRAWLER_UAS):.1%})")
|
print(f"{k:18} {v:5} ({v / len(CRAWLER_UAS):.1%})")
|
||||||
print(f"fastuaparser crashed on {crashes} UAs")
|
print(f"user-agent-parser crashed on {crashes} UAs")
|
||||||
print(f"\nuarite URL extraction: {url_got}/{url_have} of instances carrying a URL")
|
print(f"\nuarite URL extraction: {url_got}/{url_have} of instances carrying a URL")
|
||||||
|
print(
|
||||||
|
"\n## speed (µs per parse, mixed set of %d UAs)"
|
||||||
|
% (len(BROWSERS) + len(CRAWLER_UAS) + len(OWN))
|
||||||
|
)
|
||||||
|
for k, v in bench().items():
|
||||||
|
print(f"{k:20} {v:8.1f}")
|
||||||
bench_realistic()
|
bench_realistic()
|
||||||
|
|||||||
+19
-8
@@ -1,15 +1,15 @@
|
|||||||
"""Print the README's accuracy-comparison table as markdown.
|
"""Print the README's accuracy-comparison table as markdown.
|
||||||
|
|
||||||
uarite's and fastuaparser's columns are simply their pretty-string output.
|
uarite's column is simply `r.pretty`. The reference modules have no
|
||||||
ua-parser has no display format; its column uses one plain format string
|
display format; their columns use one plain format string each on their
|
||||||
on the structured output (footnotes ¹² in the README). Requires uarite
|
structured output (footnotes ²³ in the README). Requires uarite (installed)
|
||||||
(installed) plus the benchmark-only reference parsers:
|
plus the benchmark-only reference parsers:
|
||||||
|
|
||||||
uv run --with ua-parser --with fastuaparser python scripts/prettytable.py
|
uv run --with ua-parser --with user-agents python scripts/prettytable.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastuaparser import parse_ua as fua_parse
|
|
||||||
from ua_parser import parse as ua_parse
|
from ua_parser import parse as ua_parse
|
||||||
|
from user_agents import parse as uas_parse
|
||||||
|
|
||||||
from uarite import uaparse
|
from uarite import uaparse
|
||||||
|
|
||||||
@@ -55,6 +55,10 @@ CASES = [
|
|||||||
"Googlebot (disguised)",
|
"Googlebot (disguised)",
|
||||||
"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"Claude-SearchBot (disguised)",
|
||||||
|
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.3245.171 Mobile Safari/537.36; compatible; Claude-SearchBot/1.0; +https://www.anthropic.com/claude-searchbot",
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"Facebook preview (disguised)",
|
"Facebook preview (disguised)",
|
||||||
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6885.65 Mobile Safari/537.36; compatible; facebookexternalhit/1.1; +http://www.facebook.com/externalhit_uatext.php",
|
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6885.65 Mobile Safari/537.36; compatible; facebookexternalhit/1.1; +http://www.facebook.com/externalhit_uatext.php",
|
||||||
@@ -86,8 +90,15 @@ def imitate_uaparser(ua):
|
|||||||
return f"{fam}/{maj} {osf} {dev}"
|
return f"{fam}/{maj} {osf} {dev}"
|
||||||
|
|
||||||
|
|
||||||
print("| Case | uarite¹ | fastuaparser² | ua-parser³ |")
|
def imitate_useragents(ua):
|
||||||
|
r = uas_parse(ua)
|
||||||
|
fam = r.browser.family or ""
|
||||||
|
maj = str(r.browser.version[0]) if r.browser.version else ""
|
||||||
|
return f"{fam}/{maj} {r.os.family or ''} {r.device.family or ''}"
|
||||||
|
|
||||||
|
|
||||||
|
print("| Case | uarite¹ | ua-parser² | user-agents³ |")
|
||||||
print("|---|---|---|---|")
|
print("|---|---|---|---|")
|
||||||
for name, ua in CASES:
|
for name, ua in CASES:
|
||||||
ours = uaparse(ua).pretty or "—"
|
ours = uaparse(ua).pretty or "—"
|
||||||
print(f"| {name} | {ours} | {fua_parse(ua)} | {imitate_uaparser(ua)} |")
|
print(f"| {name} | {ours} | {imitate_uaparser(ua)} | {imitate_useragents(ua)} |")
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
# /// script
|
|
||||||
# requires-python = ">=3.14"
|
|
||||||
# dependencies = ["matplotlib"]
|
|
||||||
# ///
|
|
||||||
"""Bar chart of cold-parse throughput for the README's Performance section.
|
|
||||||
|
|
||||||
Numbers are pasted from `uv run scripts/bench.py` (the cold 50/50
|
|
||||||
browser/crawler mix, µs per parse) and shown as parses per second.
|
|
||||||
Transparent SVG, text baked to paths, neutral grays: renders the same
|
|
||||||
on light and dark themes. All labels sit on the bars themselves.
|
|
||||||
Very wide aspect ratio: forges render images at full content width,
|
|
||||||
so height alone controls how tall it appears.
|
|
||||||
|
|
||||||
uv run scripts/speedplot.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import matplotlib
|
|
||||||
|
|
||||||
matplotlib.use("Agg")
|
|
||||||
matplotlib.rcParams["svg.fonttype"] = "path" # text as paths: renders anywhere
|
|
||||||
import matplotlib.pyplot as plt # noqa: E402
|
|
||||||
|
|
||||||
# µs per cold parse, from scripts/bench.py.
|
|
||||||
# fastuaparser (~1 µs, 1M parses/s) and cached results are too far off
|
|
||||||
# this scale to draw meaningfully and are only mentioned in the README.
|
|
||||||
US = {
|
|
||||||
"uarite": 18.0,
|
|
||||||
"ua-parser (Rust)": 38.1,
|
|
||||||
"ua-parser (RE2)": 71.7,
|
|
||||||
"ua-parser": 304.7,
|
|
||||||
"user-agents": 324.6,
|
|
||||||
}
|
|
||||||
|
|
||||||
#: Readable on both white and dark backgrounds.
|
|
||||||
OUTSIDE = "#767676"
|
|
||||||
|
|
||||||
data = sorted(((n, 1e6 / us) for n, us in US.items()), key=lambda t: -t[1])
|
|
||||||
names = [n for n, _ in data][::-1]
|
|
||||||
values = [v for _, v in data][::-1]
|
|
||||||
colors = ["#6e6e6e"] * len(data)
|
|
||||||
colors[names.index("uarite")] = "#2b6cb0"
|
|
||||||
|
|
||||||
fig, ax = plt.subplots(figsize=(12, 1.5), dpi=100)
|
|
||||||
bars = ax.barh(names, values, color=colors, height=0.82)
|
|
||||||
xmax = max(values)
|
|
||||||
ax.set_xlim(0, xmax)
|
|
||||||
ax.axis("off")
|
|
||||||
|
|
||||||
for bar, name, v in zip(bars, names, values):
|
|
||||||
# Round to two significant digits: 121951 -> "120 000".
|
|
||||||
rounded = round(v, 1 - int(f"{v:.0e}".split("e")[1]))
|
|
||||||
label = f"{rounded:,.0f} {name}".replace(",", " ")
|
|
||||||
# va="center" centers the font bbox incl. descender space, which leaves
|
|
||||||
# the glyphs slightly high; nudge down to optically center on the bar.
|
|
||||||
y = bar.get_y() + bar.get_height() / 2 - 0.09
|
|
||||||
# All labels after the bar: theme-neutral gray, number before name.
|
|
||||||
# The longest bar's label overflows the axes; bbox_inches="tight"
|
|
||||||
# below expands the canvas to include it, so no dead space remains.
|
|
||||||
ax.text(bar.get_width() + xmax * 0.012, y, label,
|
|
||||||
va="center", color=OUTSIDE, fontsize=11)
|
|
||||||
|
|
||||||
out = Path("docs/bench-speed.svg")
|
|
||||||
out.parent.mkdir(exist_ok=True)
|
|
||||||
fig.savefig(out, transparent=True, bbox_inches="tight", pad_inches=0.02)
|
|
||||||
print("wrote", out)
|
|
||||||
+42
-80
@@ -1,24 +1,19 @@
|
|||||||
"""Crawler and link-unfurler tables."""
|
"""Crawler and link-preview tables."""
|
||||||
|
|
||||||
#: Lowercase UA substring to (display name, kind). Ordered: first match
|
#: Lowercase UA substring to (display name, kind). Ordered: first match
|
||||||
#: wins, so overlapping names go from most to least specific.
|
#: wins, so overlapping names go from most to least specific.
|
||||||
BOTS = {
|
BOTS = {
|
||||||
# Qualys SSL Labs scanner: frozen on this exact Firefox/45 string since
|
|
||||||
# ~2016; the pinned Gecko date makes the substring distinctive.
|
|
||||||
"mozilla/5.0 (x11; linux x86_64; rv:45.0) gecko/20100101 firefox/45.0": (
|
|
||||||
"Qualys SSL Labs",
|
|
||||||
"spider",
|
|
||||||
),
|
|
||||||
"feedfetcher-google": ("Feedfetcher-Google", "search"),
|
"feedfetcher-google": ("Feedfetcher-Google", "search"),
|
||||||
"google-inspectiontool": ("Google-InspectionTool", "search"),
|
"google-inspectiontool": ("Google-InspectionTool", "search"),
|
||||||
"google-read-aloud": ("Google-Read-Aloud", "ai"),
|
"google-read-aloud": ("Google-Read-Aloud", "search"),
|
||||||
"mediapartners-google": ("Mediapartners-Google", "analytics"),
|
"mediapartners-google": ("Mediapartners-Google", "spider"),
|
||||||
"adsbot-google": ("AdsBot-Google", "analytics"),
|
"adsbot-google": ("AdsBot-Google", "spider"),
|
||||||
"apis-google": ("APIs-Google", "spider"),
|
"apis-google": ("APIs-Google", "spider"),
|
||||||
"storebot-google": ("Storebot-Google", "search"),
|
"storebot-google": ("Storebot-Google", "spider"),
|
||||||
|
"duplexweb-google": ("DuplexWeb-Google", "spider"),
|
||||||
"google-extended": ("Google-Extended", "ai"),
|
"google-extended": ("Google-Extended", "ai"),
|
||||||
"googlebot": ("Googlebot", "search"),
|
"googlebot": ("Googlebot", "search"),
|
||||||
"googleother": ("GoogleOther", "ai"),
|
"googleother": ("GoogleOther", "spider"),
|
||||||
"bingbot": ("Bingbot", "search"),
|
"bingbot": ("Bingbot", "search"),
|
||||||
"applebot": ("Applebot", "search"),
|
"applebot": ("Applebot", "search"),
|
||||||
"gptbot": ("GPTBot", "ai"),
|
"gptbot": ("GPTBot", "ai"),
|
||||||
@@ -34,39 +29,34 @@ BOTS = {
|
|||||||
"reflectionbot": ("Reflectionbot", "ai"),
|
"reflectionbot": ("Reflectionbot", "ai"),
|
||||||
"amzn-searchbot": ("Amzn-SearchBot", "search"),
|
"amzn-searchbot": ("Amzn-SearchBot", "search"),
|
||||||
"amazonbot": ("Amazonbot", "search"),
|
"amazonbot": ("Amazonbot", "search"),
|
||||||
"ahrefsbot": ("AhrefsBot", "search"),
|
"ahrefsbot": ("AhrefsBot", "spider"),
|
||||||
"mj12bot": ("MJ12bot", "analytics"),
|
"mj12bot": ("MJ12bot", "spider"),
|
||||||
"facebookexternalhit": ("Facebook", "social"),
|
"facebookexternalhit": ("Facebook", "preview"),
|
||||||
"meta-externalagent": ("Meta-ExternalAgent", "ai"),
|
"meta-externalagent": ("Meta", "preview"),
|
||||||
"meta-externalfetcher": ("Meta-ExternalFetcher", "ai"),
|
"skypeuripreview": ("Skype", "preview"),
|
||||||
"meta-webindexer": ("Meta-WebIndexer", "search"),
|
"bingpreview": ("BingPreview", "preview"),
|
||||||
"bingpreview": ("BingPreview", "search"),
|
"pinterest": ("Pinterest", "preview"),
|
||||||
"pinterest": ("Pinterest", "social"),
|
"embedly": ("Embedly", "preview"),
|
||||||
"embedly": ("Embedly", "social"),
|
"iframely": ("Iframely", "preview"),
|
||||||
"iframely": ("Iframely", "social"),
|
"discordbot": ("Discord", "preview"),
|
||||||
"discordbot": ("Discord", "social"),
|
"slackbot": ("Slack", "preview"),
|
||||||
"slackbot": ("Slack", "social"),
|
"telegrambot": ("Telegram", "preview"),
|
||||||
"telegrambot": ("Telegram", "social"),
|
"twitterbot": ("Twitter", "preview"),
|
||||||
"twitterbot": ("Twitter", "social"),
|
"linkedinbot": ("LinkedIn", "preview"),
|
||||||
"linkedinbot": ("LinkedIn", "social"),
|
"whatsapp": ("WhatsApp", "preview"),
|
||||||
"whatsapp": ("WhatsApp", "social"),
|
|
||||||
"headlesschrome": ("HeadlessChrome", "spider"),
|
"headlesschrome": ("HeadlessChrome", "spider"),
|
||||||
"uptimerobot": ("UptimeRobot", "analytics"),
|
"phantomjs": ("PhantomJS", "spider"),
|
||||||
"pingdom": ("Pingdom", "analytics"),
|
"uptimerobot": ("UptimeRobot", "spider"),
|
||||||
|
"pingdom": ("Pingdom", "spider"),
|
||||||
}
|
}
|
||||||
|
|
||||||
#: Pretty suffixes for the kinds more precise than a generic spider.
|
#: Pretty suffixes for the kinds more precise than a generic spider.
|
||||||
KIND_LABEL = {
|
KIND_LABEL = {"ai": "AI", "search": "search", "preview": "preview"}
|
||||||
"ai": "AI",
|
|
||||||
"search": "search",
|
|
||||||
"social": "social",
|
|
||||||
"analytics": "analytics",
|
|
||||||
}
|
|
||||||
|
|
||||||
#: Crawler product families: provider -> the display names of its bots.
|
#: Providers with more than one crawler product; the kind label is kept
|
||||||
#: The kind label is kept only where it distinguishes siblings within a family.
|
#: only where it distinguishes siblings within the group.
|
||||||
PROVIDERS = {
|
PROVIDERS = [
|
||||||
"Google": frozenset({
|
(
|
||||||
"Googlebot",
|
"Googlebot",
|
||||||
"Google-Extended",
|
"Google-Extended",
|
||||||
"GoogleOther",
|
"GoogleOther",
|
||||||
@@ -77,47 +67,19 @@ PROVIDERS = {
|
|||||||
"AdsBot-Google",
|
"AdsBot-Google",
|
||||||
"APIs-Google",
|
"APIs-Google",
|
||||||
"Storebot-Google",
|
"Storebot-Google",
|
||||||
}),
|
"DuplexWeb-Google",
|
||||||
"Anthropic": frozenset({"ClaudeBot", "Claude-User", "Claude-SearchBot"}),
|
),
|
||||||
"OpenAI": frozenset({"GPTBot", "OAI-SearchBot", "ChatGPT-User"}),
|
("ClaudeBot", "Claude-User", "Claude-SearchBot"),
|
||||||
"Perplexity": frozenset({"PerplexityBot", "Perplexity-User"}),
|
("GPTBot", "OAI-SearchBot", "ChatGPT-User"),
|
||||||
"Amazon": frozenset({"Amazonbot", "Amzn-SearchBot"}),
|
("PerplexityBot", "Perplexity-User"),
|
||||||
"Microsoft": frozenset({"Bingbot", "BingPreview"}),
|
("Amazonbot", "Amzn-SearchBot"),
|
||||||
"Meta": frozenset({
|
("Bingbot", "BingPreview"),
|
||||||
"Facebook",
|
]
|
||||||
"Meta-ExternalAgent",
|
|
||||||
"Meta-ExternalFetcher",
|
|
||||||
"Meta-WebIndexer",
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
#: Reverse lookup: bot display name -> provider.
|
#: Bot names whose kind label is displayed, computed from the groups.
|
||||||
PROVIDER_OF = {
|
|
||||||
name: provider for provider, names in PROVIDERS.items() for name in names
|
|
||||||
}
|
|
||||||
|
|
||||||
#: Per-bot pretty overrides: the full display string, replacing the
|
|
||||||
#: name-plus-kind-label composition entirely.
|
|
||||||
PRETTY_OVERRIDE = {
|
|
||||||
"Facebook": "Facebook",
|
|
||||||
"Feedfetcher-Google": "Google Feedfetcher (search)",
|
|
||||||
"Google-InspectionTool": "Google InspectionTool (search)",
|
|
||||||
"Google-Read-Aloud": "Google Read-Aloud (AI)",
|
|
||||||
"Mediapartners-Google": "Google Mediapartners (analytics)",
|
|
||||||
"AdsBot-Google": "Google AdsBot (analytics)",
|
|
||||||
"APIs-Google": "Google APIs",
|
|
||||||
"Storebot-Google": "Google Storebot (search)",
|
|
||||||
"Google-Extended": "Google Extended (AI)",
|
|
||||||
"GoogleOther": "Google Other (AI)",
|
|
||||||
}
|
|
||||||
|
|
||||||
#: Reverse lookup: bot display name -> kind.
|
|
||||||
NAME_KIND = {name: kind for name, kind in BOTS.values()}
|
|
||||||
|
|
||||||
#: Bot names whose kind label is displayed: those in families with mixed kinds.
|
|
||||||
LABELED = {
|
LABELED = {
|
||||||
name
|
name
|
||||||
for names in PROVIDERS.values()
|
for group in PROVIDERS
|
||||||
if len({NAME_KIND[name] for name in names}) > 1
|
if len({kind for n, kind in BOTS.values() if n in group}) > 1
|
||||||
for name in names
|
for name in group
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-54
@@ -4,18 +4,18 @@ import re
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from .bots import BOTS, KIND_LABEL, LABELED, PRETTY_OVERRIDE, PROVIDER_OF
|
from .bots import BOTS, KIND_LABEL, LABELED
|
||||||
from .clients import BROWSERS, SAMSUNG, SAMSUNG_SERIES
|
from .clients import BROWSERS, SAMSUNG, SAMSUNG_SERIES
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class UA:
|
class UA:
|
||||||
pretty: str = ""
|
pretty: str
|
||||||
engine: str = ""
|
engine: str
|
||||||
os: str = ""
|
os: str
|
||||||
kind: str = ""
|
bot: str
|
||||||
url: str = ""
|
kind: str
|
||||||
provider: str = ""
|
url: str
|
||||||
|
|
||||||
|
|
||||||
#: Fallback for unknown crawlers: a product token whose name says so.
|
#: Fallback for unknown crawlers: a product token whose name says so.
|
||||||
@@ -48,7 +48,7 @@ def url(ua: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def bot(ua: str) -> tuple[str, str]:
|
def bot(ua: str) -> tuple[str, str]:
|
||||||
"""(display name, kind) of the crawler/unfurler the UA claims."""
|
"""(display name, kind) of the crawler/previewer the UA claims."""
|
||||||
low = ua.lower()
|
low = ua.lower()
|
||||||
m = BOTS_RE.search(low)
|
m = BOTS_RE.search(low)
|
||||||
if m:
|
if m:
|
||||||
@@ -98,19 +98,6 @@ def browser(ua: str) -> str:
|
|||||||
#: Engines that differ from the Chromium default for recognized browsers.
|
#: Engines that differ from the Chromium default for recognized browsers.
|
||||||
ENGINES = {"Firefox": "Gecko", "LibreWolf": "Gecko", "Safari": "Safari"}
|
ENGINES = {"Firefox": "Gecko", "LibreWolf": "Gecko", "Safari": "Safari"}
|
||||||
|
|
||||||
#: Oldest plausible major versions (≈2023 releases). These browsers
|
|
||||||
#: auto-update, so anything older is a scanner's frozen string, not a real
|
|
||||||
#: installation. Safari is OS-tied and exempt; old Macs genuinely run it.
|
|
||||||
#: Bump the floors every few years.
|
|
||||||
ANCIENT = {"Firefox": 108, "Chrome": 108, "Edge": 108, "Opera": 95}
|
|
||||||
|
|
||||||
|
|
||||||
def spoofed(b: str) -> bool:
|
|
||||||
"""True when a ``Browser/major`` claims an impossibly old version."""
|
|
||||||
name, _, ver = b.partition("/")
|
|
||||||
floor = ANCIENT.get(name)
|
|
||||||
return floor is not None and ver.isdigit() and int(ver) < floor
|
|
||||||
|
|
||||||
|
|
||||||
def engine(b: str) -> str:
|
def engine(b: str) -> str:
|
||||||
"""Engine for a ``Browser/major`` result; Chromium is the modern default."""
|
"""Engine for a ``Browser/major`` result; Chromium is the modern default."""
|
||||||
@@ -153,45 +140,31 @@ def model_name(model: str) -> str:
|
|||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=1024)
|
def uaparse(ua: str) -> UA:
|
||||||
def uaparse(ua: str | None) -> UA:
|
|
||||||
"""Parse a User-Agent string into a compact ``UA`` record.
|
"""Parse a User-Agent string into a compact ``UA`` record.
|
||||||
|
|
||||||
``pretty`` is "" for empty/missing UAs and the original string when
|
``pretty`` is "" for empty/missing UAs and the original string when
|
||||||
nothing is recognized.
|
nothing is recognized.
|
||||||
|
|
||||||
Everything is cached: a dict lookup on the full UA string is far
|
Only the browser path is cached: real visitors repeat (cache hits),
|
||||||
cheaper than re-parsing, and the frozen ``UA`` is shared safely.
|
while crawlers and scripts are mostly one-hit wonders whose entries
|
||||||
|
would just flush the cache.
|
||||||
"""
|
"""
|
||||||
if not ua or not ua.strip() or ua in ("-", "null"):
|
if not ua or not ua.strip() or ua in ("-", "null"):
|
||||||
return UA()
|
return UA("", "", "", "", "", "")
|
||||||
name, kind = bot(ua)
|
name, kind = bot(ua)
|
||||||
if name:
|
if name:
|
||||||
# The browser/OS in crawler UAs is a disguise; the bot identity is
|
# The browser/OS in crawler UAs is a disguise; the bot identity is
|
||||||
# the relevant information, so ``engine`` and ``os`` are left empty.
|
# the relevant information, so ``engine`` and ``os`` are left empty.
|
||||||
pretty = PRETTY_OVERRIDE.get(name)
|
label = KIND_LABEL.get(kind, "") if name in LABELED else ""
|
||||||
if pretty is None:
|
pretty = f"{name} ({label})" if label else name
|
||||||
label = KIND_LABEL.get(kind, "") if name in LABELED else ""
|
return UA(pretty, "", "", name, kind, url(ua))
|
||||||
pretty = f"{name} ({label})" if label else name
|
|
||||||
return UA(
|
|
||||||
pretty=pretty, kind=kind, url=url(ua),
|
|
||||||
provider=PROVIDER_OF.get(name, ""),
|
|
||||||
)
|
|
||||||
return _parse_client(ua)
|
return _parse_client(ua)
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1024)
|
||||||
def _parse_client(ua: str) -> UA:
|
def _parse_client(ua: str) -> UA:
|
||||||
"""Browser/client parsing; ``uaparse`` filters bots out."""
|
"""Browser/client parsing behind the cache; ``uaparse`` filters bots out."""
|
||||||
r = _client(ua)
|
|
||||||
# Frozen ancient browser strings are scanners/scripts, not users: show
|
|
||||||
# the claimed browser, but mark it and drop the fake engine/os/kind.
|
|
||||||
if r.kind == "browser" and spoofed(browser(ua)):
|
|
||||||
return UA(pretty=f"{r.pretty} (spoofed)")
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
def _client(ua: str) -> UA:
|
|
||||||
"""Browser/client parsing; spoof marking is done by the caller."""
|
|
||||||
|
|
||||||
# Non-browser HTTP clients ("python-requests/2.32.5", "curl/8.0",
|
# Non-browser HTTP clients ("python-requests/2.32.5", "curl/8.0",
|
||||||
# "pip/24.3.1 {json…}"): the first product token, plus the OS when
|
# "pip/24.3.1 {json…}"): the first product token, plus the OS when
|
||||||
@@ -202,22 +175,22 @@ def _client(ua: str) -> UA:
|
|||||||
os_name = os(ua)
|
os_name = os(ua)
|
||||||
if os_name and os_name not in pretty:
|
if os_name and os_name not in pretty:
|
||||||
pretty = f"{pretty} {os_name}"
|
pretty = f"{pretty} {os_name}"
|
||||||
return UA(pretty=pretty, os=os_name)
|
return UA(pretty, "", os_name, "", "", "")
|
||||||
|
|
||||||
# HarmonyOS carries an "Android" compatibility token, so it must be
|
# HarmonyOS carries an "Android" compatibility token, so it must be
|
||||||
# detected before Android.
|
# detected before Android.
|
||||||
if "OpenHarmony" in ua or "HarmonyOS" in ua or "ArkWeb" in ua:
|
if "OpenHarmony" in ua or "HarmonyOS" in ua or "ArkWeb" in ua:
|
||||||
b = browser(ua)
|
b = browser(ua)
|
||||||
return UA(
|
return UA(
|
||||||
pretty=f"{b} HarmonyOS" if b else "HarmonyOS",
|
f"{b} HarmonyOS" if b else "HarmonyOS", "ArkWeb", "HarmonyOS",
|
||||||
engine="ArkWeb", os="HarmonyOS", kind="browser",
|
"", "browser", "",
|
||||||
)
|
)
|
||||||
|
|
||||||
if "iPhone" in ua or "iPad" in ua:
|
if "iPhone" in ua or "iPad" in ua:
|
||||||
device = "iPhone" if "iPhone" in ua else "iPad"
|
device = "iPhone" if "iPhone" in ua else "iPad"
|
||||||
m = re.search(r"OS (\d+)", ua)
|
m = re.search(r"OS (\d+)", ua)
|
||||||
pretty = f"{device} iOS {m.group(1)}" if m else device
|
pretty = f"{device} iOS {m.group(1)}" if m else device
|
||||||
return UA(pretty=pretty, engine="Safari", os="iOS", kind="browser")
|
return UA(pretty, "Safari", "iOS", "", "browser", "")
|
||||||
|
|
||||||
m = re.search(r"Android ([\d.]+)", ua)
|
m = re.search(r"Android ([\d.]+)", ua)
|
||||||
if m:
|
if m:
|
||||||
@@ -235,12 +208,14 @@ def _client(ua: str) -> UA:
|
|||||||
if token and token not in ("wv", "Mobile", "Tablet"):
|
if token and token not in ("wv", "Mobile", "Tablet"):
|
||||||
model = model_name(token)
|
model = model_name(token)
|
||||||
parts = [p for p in (b, model or f"Android {m.group(1)}") if p]
|
parts = [p for p in (b, model or f"Android {m.group(1)}") if p]
|
||||||
return UA(
|
return UA(" ".join(parts), engine(b), "Android", "", "browser", "")
|
||||||
pretty=" ".join(parts), engine=engine(b), os="Android",
|
|
||||||
kind="browser",
|
|
||||||
)
|
|
||||||
|
|
||||||
b = browser(ua)
|
b = browser(ua)
|
||||||
os_name = os(ua)
|
os_name = os(ua)
|
||||||
pretty = f"{b} {os_name}".strip()
|
pretty = f"{b} {os_name}".strip()
|
||||||
return UA(pretty=pretty or ua, engine=engine(b), os=os_name, kind="browser")
|
return UA(pretty or ua, engine(b), os_name, "", "browser", "")
|
||||||
|
|
||||||
|
|
||||||
|
def is_bot(ua: str) -> bool:
|
||||||
|
"""True when the UA claims a crawler or link-preview identity."""
|
||||||
|
return bool(uaparse(ua).bot)
|
||||||
|
|||||||
Reference in New Issue
Block a user