[Python-bugs-list] [Bug #112634] urllib doesn't look at self.version as documented

noreply@sourceforge.net noreply@sourceforge.net
Thu, 24 Aug 2000 09:20:53 -0700


Bug #112634, was updated on 2000-Aug-24 13:01
Here is a current snapshot of the bug.

Project: Python
Category: Library
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 5
Summary: urllib doesn't look at self.version as documented

Details: [The following came from a .cz domain so I'm posting for him. GvR]

(I believe this is actually easily fixable in the code to make the docs correct. GvR)

From: Dundáček Jan <Jan.Dundacek@pvt.cz>
To: guido@python.org
Date: Thu, 24 Aug 2000 13:06:15 +0200

There is an example on urllib in Python Library Reference Release 1.5.2
(p. 211, A4 pdf):

--
  For example, applications may want to specify a different
  user-agent header than URLopener defines. This can be
  accomplished with the following code:

  class AppURLopener(urllib.FancyURLopener):
    def __init__(self, *args):
      apply(urllib.FancyURLopener.__init__, (self,) + args)
      self.version = "App/1.7"
  urllib._urlopener = AppURLopener
--

I was trying it, but it doesn't work - may be that
error is in:

    self.version = "App/1.7"

When I looked at urllib.py, I found only:

    server_version = "Python-urllib/%s" % __version__
    self.addheaders = [('User-agent', server_version)]

in URLopener.__init__.

And when I redefined __init__ in such a way, it works.

Thanks for Python
      
        Jan

------------------------------------------------
   Jan Dundacek                PVT a.s.         
   Jan.Dundacek@pvt.cz         Veveri 102       
   +420-5-41558-347            659 10  Brno     
                               Czech republic   
------------------------------------------------ 




Follow-Ups:

Date: 2000-Aug-24 16:20
By: gvanrossum

Comment:
Fixed urllib.py and the example -- this can only be made to work if one assigns to self.version *before* calling the base class __init__().
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=112634&group_id=5470