[zope2-tracker] [Bug 1152193] Re: ZPublisher.Client.call discards HTTP method argument

l0b0 victor.engmark at gmail.com
Mon Mar 18 09:37:29 UTC 2013


** Patch added: "Zope patch"
   https://bugs.launchpad.net/zope2/+bug/1152193/+attachment/3581093/+files/Client.py.diff

** Description changed:

  From <http://stackoverflow.com/questions/15272221/how-to-set-http-
  method-with-zpublisher-client-call>:
  
  I've tried calling Zope 2.10.9's ZPublisher.Client.call
  <https://github.com/zopefoundation/Zope/blob/master/src/ZPublisher/Client.py>
  with the `method` argument to set the HTTP method (`GET`, `POST`, etc.),
  but it's not working as expected: It always sends a POST request. If I
  don't supply the `method` argument it always sends a GET request.
  
  Application code:
  
-     Client.call(
-         'http://...',
-         username = 'jdoe',
-         password = 'mypw',
-         method = 'GET')
+     Client.call(
+         'http://...',
+         username = 'jdoe',
+         password = 'mypw',
+         method = 'GET')
  
  I've traced it a bit in Client.py:
  
-     def call(url,username=None, password=None, **kw):
-         return apply(Function(url,username=username, password=password), (), kw)
+     def call(url,username=None, password=None, **kw):
+         return apply(Function(url,username=username, password=password), (), kw)
  
  OK, so `kw = { 'method': 'GET' }`. As far as I can tell this translates
  to
  
-     Function.__init__(
-         'http://...',
-         username = 'jdoe',
-         password = 'mypw'
-     ).__call__(
-         method = 'GET')
+     Function.__init__(
+         'http://...',
+         username = 'jdoe',
+         password = 'mypw'
+     ).__call__(
+         method = 'GET')
  
  `Function.__init__` expects `method` as part of its arguments but it's
  not passed there:
  
-         def __init__(self,url,
-                      arguments=(),method=None,username=None,password=None,
-                      timeout=None,
-                      **headers):
-             ...
-             if method is not None: self.method=method
+         def __init__(self,url,
+                      arguments=(),method=None,username=None,password=None,
+                      timeout=None,
+                      **headers):
+             ...
+             if method is not None: self.method=method
  
  `Function.__call__` expects `method` to be set already:
  
-         def __call__(self,*args,**kw):
-             method=self.method
+         def __call__(self,*args,**kw):
+             method=self.method
  
  Should `call`'s signature and the `apply` call be modified to fit
- `__init__`, or am I misunderstanding something? If it's really an error,
- here's a proposed patch (Works For Me™):
- 
-     --- Client.py.orig
-     +++ Client.py
-     @@ -271,9 +271,9 @@
-      
-              return f
-      
-     -def call(url,username=None, password=None, **kw):
-     +def call(url, arguments=(), method=None, username=None, password=None, timeout=None, **kw):
-      
-     -    return apply(Function(url,username=username, password=password), (), kw)
-     +    return apply(Function(url, arguments=arguments, method=method, username=username, password=password, timeout=timeout), (), kw)
-      
-      ##############################################################################
-      # Implementation details below here
+ `__init__`, or am I misunderstanding something? Attached is a patch
+ which seems to work for me.

** Patch removed: "Zope patch"
   https://bugs.launchpad.net/zope2/+bug/1152193/+attachment/3581092/+files/Client.py.diff

-- 
You received this bug notification because you are a member of Zope 2
Developers, which is subscribed to Zope 2.
https://bugs.launchpad.net/bugs/1152193

Title:
  ZPublisher.Client.call discards HTTP method argument

To manage notifications about this bug go to:
https://bugs.launchpad.net/zope2/+bug/1152193/+subscriptions


More information about the zope2-tracker mailing list