This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2 raises an UnboundLocalError if "auth-int" is the qop
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, jjlee, varmaa
Priority: normal Keywords: patch

Created on 2007-02-24 15:19 by varmaa, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
urllib2_patch.diff varmaa, 2007-02-26 01:33 Patch to fix the UnboundLocalError bug, w/ consistent line endings and PEP 8 conformance
test_urllib2_localnet.py varmaa, 2007-02-26 01:38 stdlib testing suite for urllib2 using loopback http proxy w/ tests for qop types "auth" and "auth-int"
test_urllib2_localnet.py varmaa, 2007-04-14 21:27 stdlib testing suite for urllib2 using loopback http proxy w/ tests for qop types "auth" and "auth-int" and failure cases
test_urllib2_localnet.py varmaa, 2007-06-02 21:35 stdlib testing suite for urllib2 using loopback http proxy, fixes broken pipe errors
Messages (12)
msg51940 - (view) Author: Atul Varma (varmaa) Date: 2007-02-24 15:19
If a proxy server is connected to that specifies the "auth-int" quality of protection (qop) code--or any qop code aside from "auth", actually--urllib2 raises an UnboundLocalError exception.  While this patch doesn't implement auth-int, it does modify the behavior of urllib2 such that it raises a URLError with the reason "qop '%s' is not supported', where %s is the name of the qop code.

Two unit tests that test urllib2's functionality with an in-process proxy can be found at:

  http://varmaa.googlepages.com/Urllib2ProxyTests.py

I will try to attach this file to this patch ticket if I can.  I am also interested in integrating this unit testing suite with the Python standard lib unit tests, and am willing to work with you if this is desirable.  One of the unit tests in this suite succeeds with the standard version of urllib2.py, but the other fails unless this patch is applied.

This patch (and the unit test suite) applies to Python 2.4 and 2.5.
msg51941 - (view) Author: Atul Varma (varmaa) Date: 2007-02-24 15:20
File Added: Urllib2ProxyTests.py
msg51942 - (view) Author: John J Lee (jjlee) Date: 2007-02-25 17:37
This looks useful.

It would be nice to test failure cases too (e.g. wrong password, .add_password() not called, ...).

I think if this goes into a new file (which might be reasonable), it should be named something like test_urllib2_localnet.py , to allow for adding more loopback tests, which will not always involve proxy handling.  I suppose it should NOT depend on the network resource flag (Lib/test/regrtest.py -u network) since it's only localhost.

Style (see PEP 8):

Don't put whitespace inside brackets -- e.g. bad: fn( arg ) good: fn(arg)

Use this_kind_of_name or thiskind if short, not thisKind.

Imports and classes etc. don't need comments to label them as such.  Probably is useful to label the BaseHTTPServer code though (maybe '# Local proxy test infrastructure').

See e.g. end of Lib/test/test_urllib2net.py for appropriate stdlib test boilerplate.

Your patch has inconsistent line endings, BTW.
msg51943 - (view) Author: Atul Varma (varmaa) Date: 2007-02-26 01:33
File Added: urllib2_patch.diff
msg51944 - (view) Author: Atul Varma (varmaa) Date: 2007-02-26 01:38
File Added: test_urllib2_localnet.py
msg51945 - (view) Author: Atul Varma (varmaa) Date: 2007-02-26 01:42
Thanks for the feedback, John--I've applied your suggestions to the testing suite (including renaming the file name) and the patch file.  The only thing I haven't done yet is add tests for failure cases, but I wanted to submit the "refactored" version of the test suite before doing that so I know I'm on the right track.
msg51946 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-13 08:08
The new test file looks good, so if you complete the patch I'll apply it.
msg51947 - (view) Author: Atul Varma (varmaa) Date: 2007-04-14 21:27
Sorry for the delay; I've added two failure cases to the testing suite--one which supplies bad password information and another that has no password information to supply--so the patch should now be complete.  Please let me know if you need anything else.

File Added: test_urllib2_localnet.py
msg51948 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-05-11 11:38
I get this error with the newest test file:

test_urllib2_localnet
Traceback (most recent call last):
  File "/home/gbr/devel/python/Lib/SocketServer.py", line 222, in handle_request
    self.process_request(request, client_address)
  File "/home/gbr/devel/python/Lib/SocketServer.py", line 241, in process_request
    self.finish_request(request, client_address)
  File "/home/gbr/devel/python/Lib/SocketServer.py", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/gbr/devel/python/Lib/SocketServer.py", line 523, in __init__
    self.handle()
  File "/home/gbr/devel/python/Lib/BaseHTTPServer.py", line 316, in handle
    self.handle_one_request()
  File "/home/gbr/devel/python/Lib/BaseHTTPServer.py", line 310, in handle_one_request
    method()
  File "/home/gbr/devel/python/Lib/test/test_urllib2_localnet.py", line 220, in do_GET
    self.wfile.write("Our apologies, but our server is down due to "
  File "/home/gbr/devel/python/Lib/socket.py", line 263, in write
    self.flush()
  File "/home/gbr/devel/python/Lib/socket.py", line 250, in flush
    self._sock.sendall(buffer)
error: (32, 'Broken pipe')
test test_urllib2_localnet produced unexpected output:
**********************************************************************
*** lines 2-4 of actual output doesn't appear in expected output after line 1:
+ ----------------------------------------
+ Exception happened during processing of request from ('127.0.0.1', 33141)
+ ----------------------------------------
**********************************************************************
1 test failed:
    test_urllib2_localnet
msg51949 - (view) Author: Atul Varma (varmaa) Date: 2007-05-11 15:07
Ack, sorry about that Georg--I'll investigate and fix this over the weekend.
msg51950 - (view) Author: Atul Varma (varmaa) Date: 2007-06-02 21:35
Okay, the broken pipe bug should be fixed now--let me know if there are any other problems, or if the broken pipe bug persists.
File Added: test_urllib2_localnet.py
msg51951 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-06-07 13:35
Okay, accepted as rev. 55805, 55806 (2.5).

Thanks for your continuous efforts!
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44607
2007-02-24 15:19:04varmaacreate