1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// vim:fileencoding=utf-8:noet
//! Port of `powerline/lib/url.py`.
//!
//! Used by the weather segment (`segments/common/wthr.py`) and the
//! IP-info / time-zone lookups in `segments/common/net.py` to fetch
//! small JSON responses from external APIs.
//!
//! Rust stdlib has no HTTP client. A faithful port would use `ureq`,
//! `reqwest`, or `hyper` — adding one of those is the right move when
//! the weather/net segments land. Until then, `urllib_read` is a
//! documented no-op returning `None` (which matches the upstream
//! HTTPError branch behaviour at py:16-17).
//!
//! `urllib_urlencode` is a pure-stdlib query-string formatter; it
//! ports independently of the HTTP client.
// from __future__ import (unicode_literals, division, absolute_import, print_function) // py:2
// try: // py:4
// from urllib.error import HTTPError // py:5
// from urllib.request import urlopen // py:6
// from urllib.parse import urlencode as urllib_urlencode // py:7
// except ImportError: // py:8
// from urllib2 import urlopen, HTTPError // py:9
// from urllib import urlencode as urllib_urlencode // py:10
/// Port of `urllib_read()` from `powerline/lib/url.py:13`.
///
/// Python:
/// ```python
/// def urllib_read(url):
/// try:
/// return urlopen(url, timeout=10).read().decode('utf-8')
/// except HTTPError:
/// return
/// ```
///
/// **Status:** stub — returns `None` (matches the HTTPError branch
/// behaviour at py:16-17). A real port requires an HTTP-client crate;
/// `ureq` is the recommended pick (smallest, blocking, no async
/// runtime baggage). The weather / IP-geolocation segments that
/// depend on this are deferred to Phase 3 of PORT_PLAN.md.
/// Port of module-level binding `urllib_urlencode` from
/// `powerline/lib/url.py:7` (aliased from `urllib.parse.urlencode`).
///
/// Builds an URL-encoded query string from an iterable of
/// `(key, value)` pairs. Python's stdlib implementation handles
/// percent-escaping per RFC 3986; we replicate it here against
/// `std::collections::HashMap` / iterables.
/// Inlined percent-encoding helper. Matches `urllib.parse.quote_plus`
/// for the `safe=''` default used by `urlencode`.