Re: [Python] urlparse "da i numeri"
2016-06-22 15:10 GMT+02:00 Marco De Paoli: > > [...] >> urlparse('redis://localhost:65535').port >> > 65535 >> urlparse('redis://localhost:65536').port is None >> > True >> > >> >> Nell' RFC3986 non è prescritto nessun limite per la porta: >> >> port = *DIGIT > > > più prosaicamente mi ero fermato a wikipedia > https://en.wikipedia.org/wiki/Port_(computer_networking) > > che parla appunto di interi a 16-bit > > grazie della precisazione > Tieni conto che l'RFC 3986 è abbastanza "recente" e parla di identificatori di risorse. Le URL invece parlano di localizzatori di risorse, e se ci limitiamo a risorse disponibili via rete TCP/IP o UDP/IP, ha un senso assumere che la porta sia un intero a 16bit. Ciao Manlio ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] urlparse "da i numeri"
Il giorno 22 giugno 2016 14:43, Manlio Perilloha scritto: > 2016-06-22 12:43 GMT+02:00 Marco De Paoli : > > pare che urlparse nella lib standard abbia un comportamento un po' > strano... > > > > [...] > > > > 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 > > > > Nell' RFC3986 non è prescritto nessun limite per la porta: > > port = *DIGIT > a quanto pure in futuro python lancerà eccezione https://github.com/python/cpython/blob/master/Lib/urllib/parse.py#L159 beh, meglio di adesso, che è così https://github.com/python/cpython/blob/288becf5563483ae9da14c6fb5deb4f32e4cd3d5/Lib/urllib/parse.py#L160 In merito al vincolo sul range 0-65535, ecco la discussione relativa https://bugs.python.org/issue14036 -marco ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] urlparse "da i numeri"
Il giorno 22 giugno 2016 12:43, Marco De Paoliha 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 > > sorprendentemente su python 2.6 funziona correttamente! Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from urlparse import urlparse >>> urlparse('redis://localhost:638012').port 638012 -marco ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] urlparse "da i numeri"
Il giorno 22 giugno 2016 14:43, Manlio Perilloha scritto: > 2016-06-22 12:43 GMT+02:00 Marco De Paoli : > > pare che urlparse nella lib standard abbia un comportamento un po' > strano... > > > > [...] > > > > 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 > > > > Nell' RFC3986 non è prescritto nessun limite per la porta: > > port = *DIGIT > più prosaicamente mi ero fermato a wikipedia https://en.wikipedia.org/wiki/Port_(computer_networking) che parla appunto di interi a 16-bit grazie della precisazione M. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] urlparse "da i numeri"
2016-06-22 12:43 GMT+02:00 Marco De Paoli: > pare che urlparse nella lib standard abbia un comportamento un po' strano... > > [...] > > 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 > Nell' RFC3986 non è prescritto nessun limite per la porta: port = *DIGIT Ciao Manlio ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] urlparse "da i numeri"
Il giorno 22 giugno 2016 12:43, Marco De Paoliha 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 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python