Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Dijkstra probably hates me (Linus Torvalds, in kernel/sched.c)


devel / comp.lang.python / Re: Behavior of the for-else construct

SubjectAuthor
o Re: Behavior of the for-else constructChris Angelico

1
Re: Behavior of the for-else construct

<mailman.164.1646415988.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17349&group=comp.lang.python#17349

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Sat, 5 Mar 2022 04:46:14 +1100
Lines: 94
Message-ID: <mailman.164.1646415988.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<621325684.471007.1646354302946@mail.yahoo.com>
<CAPTjJmpNT4TTRiYRD2G73EsDp3O+_Tg_sF2vp3Tf0vC-EJWqAA@mail.gmail.com>
<20220304083852.28142cce@bigbox.attlocal.net>
<CAPTjJmrNeOKRan_1w-du5M_EygmMiz0jct4mGQ3B6QQBS_=i+Q@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de ak6LhbQRAOsFF5t5cCl/6A82rl6GPnKCOyTunAKrUfWw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=mIPkxiqu;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; '(which':
0.04; '2022': 0.05; 'bunch': 0.05; 'random': 0.05; ';-)': 0.07;
'mar': 0.07; 'matches': 0.07; 'spaces': 0.07; 'translate': 0.07;
'angelico': 0.09; 'apparently': 0.09; 'labs': 0.09;
'received:209.85.166.47': 0.09; 'received:mail-
io1-f47.google.com': 0.09; 'token': 0.09; '\xe2\x86\x92': 0.09;
'that.': 0.15; '*too*': 0.16; 'apis': 0.16; 'because,': 0.16;
'bits': 0.16; 'chrisa': 0.16; 'declared': 0.16; 'elsewhere': 0.16;
'filenames': 0.16; 'filesystem': 0.16; 'found,': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'humans': 0.16; 'ms-dos': 0.16; 'ntfs': 0.16; 'printer': 0.16;
'printer.': 0.16; 'subject:else': 0.16; 'url-
ip:104.215.148.63/32': 0.16; 'url-ip:104.215.148/24': 0.16; 'url-
ip:104.215/16': 0.16; 'url-ip:13.77.161.179/32': 0.16; 'url-
ip:13.77.161/24': 0.16; 'url-ip:13.77/16': 0.16; 'url-
ip:151.101.130.49/32': 0.16; 'url-ip:151.101.194.49/32': 0.16;
'url-ip:151.101.2.49/32': 0.16; 'url-ip:151.101.66.49/32': 0.16;
'url-ip:40.112.72.205/32': 0.16; 'url-ip:40.112.72/24': 0.16;
'url-ip:40.113.200.201/32': 0.16; 'url-ip:40.113.200/24': 0.16;
'url-ip:40.113/16': 0.16; 'url-ip:40.76.4.15/32': 0.16; 'url-
ip:40.76.4/24': 0.16; 'url-ip:40.76/16': 0.16; 'urls': 0.16;
'wrote:': 0.16; 'name.': 0.19; 'to:addr:python-list': 0.20;
'issue': 0.21; "i've": 0.22; 'creates': 0.22; 'maybe': 0.22;
'returns': 0.22; 'sat,': 0.22; 'school': 0.24; 'anything': 0.25;
'actual': 0.25; 'extension': 0.25; 'space': 0.26; 'listing': 0.26;
'tim': 0.26; 'bit': 0.27; 'done': 0.28; 'chris': 0.28; 'computer':
0.29; 'it,': 0.29; 'error': 0.29; 'putting': 0.31; 'think': 0.32;
"doesn't": 0.32; 'question': 0.32; 'point,': 0.32; "wouldn't":
0.32; 'message-id:@mail.gmail.com': 0.32; 'mark': 0.32; 'unless':
0.32; 'but': 0.32; "i'm": 0.33; 'subject:for': 0.33; 'path': 0.33;
'windows': 0.34; 'same': 0.34; "didn't": 0.34; 'skip:" 20': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'invalid': 0.35; 'received:209.85.166': 0.35;
'from:addr:gmail.com': 0.35; 'change': 0.36; 'those': 0.36;
'couple': 0.37; "it's": 0.37; 'received:209.85': 0.37;
'directory': 0.37; 'hard': 0.37; 'this.': 0.37; 'though': 0.37;
'file': 0.38; 'way': 0.38; 'could': 0.38; '8bit%:14': 0.38;
'received:209': 0.39; 'day,': 0.62; 'ever': 0.63; 'simply': 0.63;
'send': 0.63; 'copy': 0.63; '8bit%:17': 0.63; 'clear': 0.64;
'full': 0.64; 'your': 0.64; 'look': 0.65; 'worked': 0.67; 'back':
0.67; 'increasingly': 0.67; 'that,': 0.67; 'perfectly': 0.69;
'skip:\xe2 20': 0.69; 'receive': 0.71; 'skip:\xe2 10': 0.71;
"you'll": 0.73; 'demand': 0.75; 'chase': 0.76; 'eight': 0.76;
'hacked': 0.76; 'attacks.': 0.84; 'calls.': 0.84; 'characters':
0.84; 'device,': 0.84; 'dos': 0.84; 'rid': 0.84; 'those,': 0.84;
'tricky': 0.84; 'was.': 0.84; 'caused': 0.86; 'avoiding': 0.91;
'notice.': 0.93; 'turned': 0.95; 'worry': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=WpeAjvX4fJb/KsYVfmz4K0pzDXEG43ZQKZJaSnY5sr4=;
b=mIPkxiquua2wH9D9rL3di1AQXjBbeN/WCfi6HHplsH8ePn8irK6P7002bggQI++EWC
E5t4St22Vk5xyML1WkN0szgj+zUnH+b1g0M1YDI/AzKlMZQ3OvPOkeCb2lsHMHvdJdmG
xK+kP5gm2oyOgRKmBoudtqXAfIYGJNR6Oxxwz70AL2FRovfqR+RCr8D8Wj06T2TwMFT9
3+kVXQyFjnbySTzzSNRNH8UZHWbbPlZa6LU2QfK5AfP29wczbPVziiWG16rW2oMC3lSf
VW0OBFkR5hTreddxI6wjbfDnOhtgd+USj6WoTPoyy+XH52FSWGlcqTfh15XlM+4Pxyod
qnbw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=WpeAjvX4fJb/KsYVfmz4K0pzDXEG43ZQKZJaSnY5sr4=;
b=Ar78O8xgq8u+BJkmHRpaoQ89cIawtBk8RgcJLWlNongYLkOOQdUL99VVyTNAk/wI78
yz/1kz52JO2o0DZFptJkA4v9k4vcW0N8hzQV0NjLa1wOU96d2vD5EbOefRUTTOErnujQ
UozRS25yCEa08Q+2BTXNzK3drndbbJjoMgTNHAtX8XOHtn7fv3PkaowHfEOPNkUNdHd4
Lky4HXVC8fRE6rzTDyi4BPaI9dadgFFaVunNh5jJfgSNFDK/kd/9ymDQHKBHeuf3tlyr
egHqkNi1PMVGRhlqzPGPT9T3bF0wIr7H+ryAcKCj8kyP1sPWDOp5WKDP3LHed9FPeJNN
qTjw==
X-Gm-Message-State: AOAM530wyMXni6PGKu3VlTYXJ2u3goMnLSJI5sasPZd+mx/eSAu722Wu
x0OEBJ6Uwxlk1bNHkd6nfXDV09wUObiJ3Yl2ETyVRB+oJ+g=
X-Google-Smtp-Source: ABdhPJxCahTihC6ZNCsWFJ0jlFK8Q8nrXBfgbEol9sbJ8F49El9KNyQwcj92bWzvNJK6h/3VJNzB8DDB6AIlhbSQpio=
X-Received: by 2002:a05:6638:218e:b0:314:80f4:b31c with SMTP id
s14-20020a056638218e00b0031480f4b31cmr34393920jaj.85.1646415985645; Fri, 04
Mar 2022 09:46:25 -0800 (PST)
In-Reply-To: <20220304083852.28142cce@bigbox.attlocal.net>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrNeOKRan_1w-du5M_EygmMiz0jct4mGQ3B6QQBS_=i+Q@mail.gmail.com>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<621325684.471007.1646354302946@mail.yahoo.com>
<CAPTjJmpNT4TTRiYRD2G73EsDp3O+_Tg_sF2vp3Tf0vC-EJWqAA@mail.gmail.com>
<20220304083852.28142cce@bigbox.attlocal.net>
 by: Chris Angelico - Fri, 4 Mar 2022 17:46 UTC

On Sat, 5 Mar 2022 at 02:02, Tim Chase <python.list@tim.thechases.com> wrote:
>
> On 2022-03-04 11:55, Chris Angelico wrote:
> > In MS-DOS, it was perfectly possible to have spaces in file names
>
> DOS didn't allow space (0x20) in filenames unless you hacked it by
> hex-editing your filesystem (which I may have done a couple times).
> However it did allow you to use 0xFF in filenames which *appeared* as
> a space in most character-sets.

Hmm, I'm not sure which APIs worked which way, but I do believe that I
messed something up at one point and made a file with an included
space (not FF, an actual 20) in it. Maybe it's something to do with
the (ancient) FCB-based calls. It was tricky to get rid of that file,
though I think it turned out that it could be removed by globbing,
putting a question mark where the space was.

(Of course, internally, MS-DOS considered that the base name was
padded to eight with spaces, and the extension padded to three with
spaces, so "READ.ME" would be "READ\x20\x20\x20\x20ME\x20", but that
doesn't count, since anything that enumerates the contents of a
directory would translate that into the way humans think of it.)

> I may have caused a mild bit of consternation in school computer labs
> doing this. ;-)

Nice :)

> > Windows forbade a bunch of characters in file names
>
> Both DOS and Windows also had certain reserved filenames
>
> https://www.howtogeek.com/fyi/windows-10-still-wont-let-you-use-these-file-names-reserved-in-1974/
>
> that could cause issues if passed to programs.

Yup. All because, way back in the day, they didn't want to demand the
colon. If you actually *want* to use the printer device, for instance,
you could get a hard copy of a directory listing like this:

DIR >LPT1:

and it's perfectly clear that you don't want to create a file called
"LPT1", you want to send it to the printer. But noooooo it had to be
that you could just write "LPT1" and it would go to the printer.

> To this day, if you poke around on microsoft.com and change random
> bits of URLs to include one of those reserved filenames in the GET
> path, you'll often trigger a 5xx error rather than a 404 that you
> receive with random jibberish in the same place.
>
> https://microsoft.com/…/asdfjkl → 404
> https://microsoft.com/…/lpt1 → 5xx
> https://microsoft.com/…/asdfjkl/some/path → 404
> https://microsoft.com/…/lpt1/some/path → 5xx
>
> Just in case you aspire to stir up some trouble.
>

In theory, file system based URLs could be parsed such that, if you
ever hit one of those, it returns "Directory not found". In
practice... apparently they didn't do that.

As a side point, I've been increasingly avoiding any sort of system
whereby I take anything from the user and hand it to the file system.
The logic is usually more like:

If path matches "/static/%s":
1) Get a full directory listing of the declared static-files directory
2) Search that for the token given
3) If not found, return 404
4) Return the contents of the file, with cache markers

Since Windows will never return "lpt1" in that directory listing, I
would simply never find it, never even try to open it. This MIGHT be
an issue with something that accepts file *uploads*, but I've been
getting paranoid about those too, so, uhh... my file upload system now
creates URLs that look like this:

https://sikorsky.rosuav.com/static/upload-49497888-6bede802d13c8d2f7b92ca9fac7c

That was uploaded as "pie.gif" but stored on the file system as
~/stillebot/httpstatic/uploads/49497888-6bede802d13c8d2f7b92ca9fac7c
with some metadata stored elsewhere about the user-specified file
name. So hey, if you were to try to upload a file that had an NTFS
invalid character in it, I wouldn't even notice.

Maybe I'm *too* paranoid, but at least I don't have to worry about
file system attacks.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor