[issue46285] protocol_version in http.server.test can be ignored

2022-02-03 Thread Éric Araujo

Change by Éric Araujo :


--
dependencies: +Pass the -d/--directory command-line option to 
http.server.CGIHTTPRequestHandler
versions:  -Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-28 Thread Géry

Change by Géry :


--
keywords: +patch
pull_requests: +29181
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/30999

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-27 Thread Éric Araujo

Éric Araujo  added the comment:

There is no bug with partial itself.  I have tried to explain this and I can’t 
write it in another way.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-26 Thread Hugo Almeida

Hugo Almeida  added the comment:

Hi Éric, thank you so much.

I know only a little usage of closure and functools.partial but not the 
historical/relative knowledge of their design/feature, I mean this issue have 2 
visual, the partical object not working as it expected or we are not calling 
the partical as it expected:

1) partial is not working as its feature or design said, assume I guessed 
right, thus partial object behaviors should be totally equal to its 
wrapper/inside class called with properties applied in a standalone/outside way 
which we usually used, the use of partical at http.server.test should be okey.

"""
import functools

class Obj:
pass

obj = Obj(); obj.foo = bar  # usually used
jbo = functools.partial(Obj, foo=bar)

# if jbo totally equal to obj in anywhere
# (the so called Duck Type or
# maybe the LSP rule, Liskov
# Substitution Principle)
# the use of partical in http.server
# should also be ok
#
# I used the partical times the same
# as http.server's author did
# and I told myself I know its usage
# but now I do not think so
"""

2) solve this issue itself, to pass handler class directly to ignore partial 
object caused problem, this is a coding logic shelter/fixing because the way we 
used functools.partical is not as it expected. This is what cpython@github 
PR30701 already done. (so the use of partical in http.server is not ok, not 
welcome at least, so based what I said above, the feature/design of partical 
now confused me, unless its a bug of partical itself which I am not sure.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-23 Thread Géry

Géry  added the comment:

Thanks Hugo for opening this issue and Éric for inviting me.

As you guys pointed out, function test in module http.server expects a real 
handler class argument (SimpleHTTPRequestHandler or CGIHTTPRequestHandler), not 
a partial object partial(SimpleHTTPRequestHandler, directory=args.directory) or 
partial(CGIHTTPRequestHandler, directory=args.directory), so that the 
assignment of protocol_version class attribute in test is not ignored.

The partial object in the if __name__ == '__main__' branch of module 
http.server was introduced in the first place to pass the directory argument to 
the handler class’s __init__ method called in method BaseServer.finish_request:

def finish_request(self, request, client_address):
"""Finish one request by instantiating RequestHandlerClass."""
self.RequestHandlerClass(request, client_address, self)

But finish_request is a factory method of BaseServer (the abstract creator) so 
it is DESIGNED to be overridden in subclasses to customize the instantiation of 
the handler class BaseRequestHandler (the abstract product). So the proper way 
to instantiate SimpleHTTPRequestHandler and CGIHTTPRequestHandler with the 
directory argument is to override BaseServer.finish_request.

That is what I have just did by updating my PR here: 
https://github.com/python/cpython/pull/30701/commits/fc7f95f9d270a8a83cb2fd6d51eb0f904b85e0d9

It fixes both #46285 and #46436.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-22 Thread Éric Araujo

Change by Éric Araujo :


--
nosy: +maggyero, matrixise

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46285] protocol_version in http.server.test can be ignored

2022-01-22 Thread Éric Araujo

Éric Araujo  added the comment:

I think we have a valid bug, and you correctly attributed it to the use of 
partial!

(No worry about your English — thank you for reporting the problem here!)


To answer your questions:

1) partial:

Imagine we have a function with many parameters:

  def frob(source, target, backup=False): ...

and we want to call it many times without passing backup=True every time; we 
can make a lambda:

  frob_backup = lambda source, target: frob(source, target, backup=True)
  # later in the file
  frob_backup(src1, tgt1)
  frob_backup(src2, tgt2)

or a partial:

  frob_backup = partial(frob, backup=True)
  # then
  frob_backup(src3, tgt3)

As you can see, they both work in the same way.  They are equivalent ways of 
making a shortcut to call a function with some parameters pre-defined.  When 
called, the lambda will call the frob function and return its return value.  
When called, the partial object will call the frob function and return its 
return value.


2) closures:

Closures are variables that are resolved in the parent scope (namespace) of the 
normal scope.
A function (including a function created by a lambda) can have closures.

  def make_callback(backup_default):  
  callback = lambda source, target: frob(source, target, backup_default)
  return callback

Here when callback is called, the backup_default variable is not found in the 
local variables of the callback function, but in the scope of make_callback.  
It will be true or false depending on how make_callback was called.


3) http.server.test

There aren’t any closures in http.server.test; the issue is that HandlerClass 
(defined in the `if name is main` block and passed to `test`) is a proper 
handler class in one case, or a partial object!  So inside test, setting 
attributes on the passed handler class will do nothing if that class is 
actually a partial instance.  When it is called, it will return an instance of 
SimpleHttpRequestHandler, which won’t see the protocol attribute that we wanted.


Conclusion:
- maybe we should pass all parameters to test instead of smuggling through 
params
- setting class attributes seems fishy to me
- cgi handler and regular handler should have the same features (see #46436)

--
nosy: +Jelle Zijlstra
resolution: not a bug -> 
stage: resolved -> needs patch
status: closed -> open
title: http/server.py wont respect its protocol_version -> protocol_version in 
http.server.test can be ignored
versions: +Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com