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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// vim:fileencoding=utf-8:noet
//! Port of `powerline/bindings/pdb/__init__.py`.
//!
//! pdb integration: installs powerline as the pdb prompt by monkey-
//! patching `pdb.Pdb` with a subclass that overrides the `prompt`
//! property.
//!
//! Upstream's Py2 branch (`PowerlineRenderBytesResult` bytes-subclass
//! with method-override soup at py:11-104) is dead code for Python 3+
//! per upstream's own dispatch — the Py3 branch reduces to
//! `PowerlineRenderResult = str`. The Rust port models the type
//! alias + the `use_powerline_prompt` decorator + the `main()`
//! entry point.
// from __future__ import (unicode_literals, division, absolute_import, print_function) // py:2
// import sys // py:4
// import pdb // py:5
// from powerline.pdb import PDBPowerline // py:7
// from powerline.lib.encoding import get_preferred_output_encoding // py:8
// from powerline.lib.unicode import unicode // py:9
/// Port of `class PowerlineRenderResult` from
/// `powerline/bindings/pdb/__init__.py:122` (Py3 branch).
///
/// Python: `PowerlineRenderResult = str` — type alias for the render
/// result. Rust analog is `String`.
// py:12 if sys.version_info < (3,):
// py:13 # XXX The below classes make code compatible with PDBpp which uses pyrepl
// py:14 # which does not expect unicode or something above ASCII. They are
// py:15 # completely not needed if pdbpp is not used, but that's not always the
// py:16 # case.
// py:17 class PowerlineRenderBytesResult(bytes):
// py:18 def __new__(cls, s, encoding=None):
// py:19 encoding = encoding or s.encoding
// py:20 if isinstance(s, PowerlineRenderResult):
// py:21 return s.encode(encoding)
// py:22 self = bytes.__new__(cls, s.encode(encoding) if isinstance(s, unicode) else s)
// py:23 self.encoding = encoding
// py:24 return self
// py:51 def __len__(self):
// py:52 return len(self.decode(self.encoding))
// py:54 def __getitem__(self, *args):
// py:55 return PowerlineRenderBytesResult(bytes.__getitem__(self, *args), encoding=self.encoding)
// py:60 @staticmethod
// py:61 def add(encoding, *args):
// py:72 def __add__(self, other):
// py:73 return self.add(self.encoding, self, other)
// py:75 def __radd__(self, other):
// py:78 def __unicode__(self):
// py:79 return PowerlineRenderResult(self)
// py:81 class PowerlineRenderResult(unicode):
// py:82 def __new__(cls, s, encoding=None):
// py:95 def __str__(self):
// py:96 return PowerlineRenderBytesResult(self)
// py:98 def __getitem__(self, *args):
// py:99 return PowerlineRenderResult(unicode.__getitem__(self, *args))
// py:113 def __add__(self, other):
// py:119 def encode(self, *args, **kwargs):
// py:120 return PowerlineRenderBytesResult(unicode.encode(self, *args, **kwargs), args[0])
// py:121 else:
// py:122 PowerlineRenderResult = str
pub type PowerlineRenderResult = String;
/// Port of `use_powerline_prompt()` decorator from
/// `powerline/bindings/pdb/__init__.py:109`.
///
/// Decorator that installs powerline prompt to the class.
///
/// Python: `cls.prompt` becomes a `@property` that lazily constructs
/// a `PDBPowerline` instance, sets up against `self`, caches on
/// `self.powerline`, and returns the rendered left-side string.
///
/// Rust port: returns a "decorated" `PdbClass` carrying the prompt
/// generator closure. The actual `pdb.Pdb` monkey-patch is impossible
/// in Rust without a Python embedding; the decorator's data shape is
/// preserved so the `main()` binary can dispatch through it when the
/// Powerline orchestrator + pdb integration lands.
/// Port of the inner `prompt` property getter from
/// `powerline/bindings/pdb/__init__.py:135-143` (inside
/// `use_powerline_prompt`).
///
/// Python: `@property def prompt(self): … return
/// PowerlineRenderResult(powerline.render(side='left'))`.
/// Rust port returns the rendered left-side string when the caller
/// supplies a renderer closure. A None renderer mirrors the absence
/// of the embedded Powerline + pdb integration in pure Rust.
/// Port of the `add` static method from
/// `powerline/bindings/pdb/__init__.py:61-71` (inside
/// `PowerlineRenderBytesResult`) and `:105-112` (inside
/// `PowerlineRenderResult`).
///
/// Python: encodes string args to bytes in `encoding` and joins them.
/// In Python 3, `PowerlineRenderResult = str` (py:122), so this
/// reduces to ordinary string concatenation with `encoding` ignored
/// (matches py:103-105 behavior on the str path).
/// Port of the `encode` method from
/// `powerline/bindings/pdb/__init__.py:119-120` (inside
/// `PowerlineRenderResult`).
///
/// Python 2 branch only. In Py3 (`PowerlineRenderResult = str`) the
/// method is inherited from `str.encode`. Rust port mirrors that —
/// returns bytes per the given encoding label, ignoring exotic
/// encodings that aren't UTF-8 (matches the Py3 fallback path where
/// the encode happens at the C boundary).
/// Port of `main()` from `powerline/bindings/pdb/__init__.py:145`.
///
/// Run module as a script. Uses `pdb.main` function directly, but
/// prior to that it mocks `pdb.Pdb` class with powerline-specific
/// class instance.
///
/// Rust port stub: emits the message that would have been the
/// monkey-patch site and returns. A real port would either embed a
/// Python interpreter or implement a Rust-native pdb-like debugger
/// (out of scope).