[Python] urlparse "da i numeri"

Marco De Paoli depaolim a gmail.com
Mer 22 Giu 2016 12:45:54 CEST


Il giorno 22 giugno 2016 12:43, Marco De Paoli <depaolim a gmail.com> ha
scritto:

> pare che urlparse nella lib standard abbia un comportamento un po'
> strano...
>
> Python 2.7.6 (default, Jun 22 2015, 17:58:13)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from urlparse import urlparse
> >>> u = urlparse('redis://localhost:6380')
> >>> u.port
> 6380
> >>> u = urlparse('redis://localhost:63801')
> >>> u.port
> 63801
> >>> u = urlparse('redis://localhost:638012')
> >>> u.port
> >>> u.port is None
> True
>
> stessa cosa succede su python 3
> cambiando ovviamente l'import
> >>> from urllib.parse import urlparse
>
>
> Daccordo che il port number č un intero a 16-bit, per cui oltre 65535 non
> ha senso, perņ forse mi sarei aspettato un eccezione, mentre invece la port
> oltre un certo numero viene semplicemente interpretata come None
>
> >>> urlparse('redis://localhost:65535').port
> 65535
> >>> urlparse('redis://localhost:65536').port is None
> True
>
> Marco
>

ah, ho usato "redis" come scheme
ma redis non centra nulla, avessi usato "http" sarebbe stato lo stesso

-marco
-------------- parte successiva --------------
Un allegato HTML č stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20160622/0fc79827/attachment.html>


Maggiori informazioni sulla lista Python