Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197890
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Newsgroups | comp.sys.mac.system, alt.os.linux, comp.lang.python |
| Subject | Re: PSA: A python script to clone your phone exactly, over Wi-Fi or USB |
| Date | 2026-08-21 07:04 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <1168t9k$403a$1@dont-email.me> (permalink) |
| References | <116673g$ptq$1@nnrp.usenet.blueworldhosting.com> <11673rv$3iopn$3@dont-email.me> <20260820190640.20824006bb95f4403a2158d8@127.0.0.1> <1168jmh$1glq$1@dont-email.me> |
Cross-posted to 3 groups.
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
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
csiph-web