Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 04 01:05
    webknjaz locked #1584
  • Dec 04 01:04
    webknjaz commented #1584
  • Dec 02 11:56
    alfredodeza commented #1825
  • Nov 30 02:19
    exocomet commented #1584
  • Nov 28 16:56
    jaraco closed #1831
  • Nov 28 16:56

    jaraco on master

    Mark test_HTTP11_Timeout_after_… Fix test_HTTP11_Timeout_after_r… Consolidate error message templ… and 2 more (compare)

  • Nov 28 16:55

    jaraco on 17.x

    Fix test_HTTP11_Timeout_after_r… Consolidate error message templ… Remove xfail after cherry-picki… (compare)

  • Nov 28 16:50
    jaraco commented #1831
  • Nov 28 16:49

    jaraco on 17.x

    Mark test_HTTP11_Timeout_after_… (compare)

  • Nov 28 16:45
    jaraco edited #1831
  • Nov 28 16:45
    jaraco commented #1831
  • Nov 28 16:44
    jaraco commented #1831
  • Nov 28 16:43
    triage-new-issues[bot] unlabeled #1831
  • Nov 28 16:43
    webknjaz labeled #1831
  • Nov 28 16:43
    webknjaz commented #1831
  • Nov 28 16:41
    jaraco commented #1831
  • Nov 28 16:39
    triage-new-issues[bot] labeled #1831
  • Nov 28 16:39
    jaraco opened #1831
  • Nov 27 16:03

    jaraco on v18.5.0

    (compare)

  • Nov 27 15:49

    jaraco on v18.4.0.post.centos8.p1

    (compare)

Sviatoslav Sydorenko
@webknjaz
It's also recommended to create feature-branches in your fork and avoid sending PRs from master because you can't submit separate PRs while updating only one branch
MikHulk
@MikHulk
Hi. Is there a mean to execute specific code when the server get shutdown in cherrypy ?
Sviatoslav Sydorenko
@webknjaz
try/finally?
MikHulk
@MikHulk
ah, ok
thx
bmxp
@bmxp
I got a little problem again, it's with a response and a strange behaviour of a dict. As soon as I give the HeaderReader an existing dict it turns out to have strange keys and values:
Consider the following code snippet running on debian buster with Python 3.7.3 with cherrypy 18.4.0:
import tempfile
import cherrypy
from cheroot import server

response = tempfile.SpooledTemporaryFile(max_size = 1000, mode = "w+b")

response.write(b'Status: 302 Found\r\nLocation: index.php?\r\nContent-type: text/html; charset=UTF-8\r\n\r\n')

emptydict ={} 
response.seek(0)
hr = server.HeaderReader()
headers = hr(response,cherrypy.serving.response.headers)
print(headers)

print(80*'-')

response.seek(0)
headers = hr(response,emptydict)
print(headers)
print(80*'-')

otherdict ={ 'Content-Type':'text/html'} 
response.seek(0)
headers = hr(response,otherdict)
print(headers)
It will give
{'Content-Type': 'text/html', 'Server': 'CherryPy/18.4.0', 'Date': 'Sat, 23 Nov 2019 20:10:51 GMT', "B'Status'": b'302 Found', "B'Location'": b'index.php?', "B'Content-Type'": b'text/html; charset=UTF-8'}
--------------------------------------------------------------------------------
{b'Status': b'302 Found', b'Location': b'index.php?', b'Content-Type': b'text/html; charset=UTF-8'}
--------------------------------------------------------------------------------
{'Content-Type': 'text/html', b'Status': b'302 Found', b'Location': b'index.php?', b'Content-Type': b'text/html; charset=UTF-8'}
The "B'Status'": b'302 Found' does not look right ...
Sviatoslav Sydorenko
@webknjaz
Interesting. Perhaps there's something like str(b'status').upper() inside...
@bmxp do you want to submit a PR with these test cases to Cheroot?
Also, a full bug report in the Cheroot repo would be very helpful. We need to keep the records of such things in one place and have it well-googlable for history.
bmxp
@bmxp
I opened up an issue on github cherrypy/cheroot#250. Unfortunately I can't help with a PR to fix this since I do not have enough understanding of what's under the hood of cheroot/cherrypy and any coding idea might break other things. Thus I can not help with a test case besides from the code provided above to reproduce. Sorry I can be of no further help ...
bmxp
@bmxp
Just a small followup:
  • The dict used by cherrypy.serving.response.headers is from cherrypy.lib.httputil.HeaderMap()
  • There is a member function:
    @staticmethod
      def transform_key(key):
          return str(key).title()
    This will cause a bytes object like b'status' to result in "B'Status'" which I would think is wrong. At this place I think it must be decided to first transform the bytes into a string using encoding and not using simply str()
Sviatoslav Sydorenko
@webknjaz

@bmxp thanks for opening an issue! It seems like you feel unqualified or somehow afraid to contribute PRs but you're still very welcome to try :) Even if your contribution isn't accepted as is, it's still very useful for everyone because it's a good demo.

What I meant earlier is adding a failing test to the project and marking it as "expected to fail" (@pytest.mark.xfail). This way, we'd have some tests that wouldn't crash our CI but also would be a great starting point for somebody else to fix the issue in the future. I'll show you how it'd look in a bit.

Sviatoslav Sydorenko
@webknjaz
oh...
@bmxp so it looks that this is happening because CherryPy is already Python-3-only and Cheroot is not
What is your use-case anyway?
bmxp
@bmxp
I wand to use the cgi for an external program to handle non static and non python script files.
Sviatoslav Sydorenko
@webknjaz
But why did you want to mix headers like this?
bmxp
@bmxp
Well I don't want to mix headers.
Sviatoslav Sydorenko
@webknjaz
Let's rephrase: how did you hit this error? It seems to me like you're only using Cheroot and for some reason importing one helper from CherryPy. Right?
bmxp
@bmxp
Yes.
Sviatoslav Sydorenko
@webknjaz
I'm pretty sure that Cheroot just operates on bytes (it's usually what we want when working with HTTP)
And CherryPy should have some adapter for this
bmxp
@bmxp
Wait a minute, I need to log in at home to get the code.
Sviatoslav Sydorenko
@webknjaz
You should probably just feed it with unicode:
-headers = hr(response, cherrypy.serving.response.headers)
+headers = hr(response.decode(), cherrypy.serving.response.headers)
bmxp
@bmxp
I needed a function to read the headers returned from the cgi program and found that cheroot.HeaderReader() would do the job.
Sviatoslav Sydorenko
@webknjaz
I see
well, decoding bytes should do the job
Oh, wait. I was looking at the HeaderMap, not HeaderReader. Let me check it closer
And why do you need cherrypy.serving.response.headers?
Sviatoslav Sydorenko
@webknjaz
So I think you just need bytes in that initial headers dict. Why do you use it in the first place? That arg is optional.
-otherdict = {'Content-Type': 'text/html'}
+otherdict = {b'Content-Type': b'text/html'}
bmxp
@bmxp

And why do you need cherrypy.serving.response.headers?

I thought it was a good idea to use the standard headers as a start....

Sviatoslav Sydorenko
@webknjaz
define "standard"
bmxp
@bmxp
Like info on version of cherrypy e.g.
Sviatoslav Sydorenko
@webknjaz
Also, cherrypy.serving.response.headers is something that is populated on each request that CherryPy processes. It may give weird results if used outside.
But if you don't use CherryPy in the first place, why do you need to hit this?
bmxp
@bmxp
Well I need CherryPy in other sections of the software anyway. It serves other things like dynamic data.
Sviatoslav Sydorenko
@webknjaz
Are you sure you don't need to separate projects?
bmxp
@bmxp
Jep :-)
Sviatoslav Sydorenko
@webknjaz
Or maybe just use CherryPy's capabilities instead of directly using its dependency
bmxp
@bmxp
I am working on a plugin to extend the bigger project
Sviatoslav Sydorenko
@webknjaz
If you tell the details, maybe I could point you to some better way
bmxp
@bmxp
Jep. I could also just change the encoding of the source for HeaderReader.
I will try some things during the week and let you know about the forthcoming. Got to proceed with my normal job now ;-)
Sviatoslav Sydorenko
@webknjaz
:+1:
bmxp
@bmxp
I decided to Clone the functionality of HeaderReader together with direkt conversion to a utf-8 str.