Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197890 > unrolled thread
| Started by | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| First post | 2026-08-21 07:04 +0000 |
| Last post | 2026-08-21 07:04 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: PSA: A python script to clone your phone exactly, over Wi-Fi or USB Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-08-21 07:04 +0000
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-08-21 07:04 +0000 |
| Subject | Re: PSA: A python script to clone your phone exactly, over Wi-Fi or USB |
| Message-ID | <1168t9k$403a$1@dont-email.me> |
On Fri, 21 Aug 2026 04:20:33 -0000 (UTC), Chris wrote:
> Especially python where the lack of whitespace consistency completely
> breaks the code.
However:
def netstring_encode(s, as_str = False) :
"encodes a string or bytes object as a netstring. Returns the encoded" \
" format as a string or bytes object, depending on as_str."
if isinstance(s, str) :
sb = s.encode()
elif isinstance(s, (bytes, bytearray)) :
sb = s
else :
raise TypeError("input value should be str or bytes")
if len(sb) > MAX_NETSTRING_LEN :
raise ValueError("netstring length of %d exceeds %d bytes" % (len(sb), MAX_NETSTRING_LEN))
result = b"%d:%s," % (len(sb), sb)
if as_str :
result = result.decode()
return \
result
Hopeless gibberish. But:
def netstring_encode(s, as_str = False) :
"encodes a string or bytes object as a netstring. Returns the encoded" \
" format as a string or bytes object, depending on as_str."
if isinstance(s, str) :
sb = s.encode()
elif isinstance(s, (bytes, bytearray)) :
sb = s
else :
raise TypeError("input value should be str or bytes")
#end if
if len(sb) > MAX_NETSTRING_LEN :
raise ValueError("netstring length of %d exceeds %d bytes" % (len(sb), MAX_NETSTRING_LEN))
#end if
result = b"%d:%s," % (len(sb), sb)
if as_str :
result = result.decode()
#end if
return \
result
#end netstring_encode
Some chance of restoring meaning.
Back to top | Article view | comp.lang.python
csiph-web