> On Jun 12, 2023, at 12:42, Jonathan Vanasco <[email protected]> wrote:
> 
> I've been updating my session library to utilize typing/mypy and this 
> implementation detail surfaced between mypy integration and some new tests.
> 
> I hope someone can enlighten me on this and some best testing practices...
> 
> Webob's SignedSerializer expects to dump to, and load from, `bytes`.  The 
> default behavior is handled by taking json.dumps/loads - which operates on 
> strings - and transcoding it between bytes and string. (See 
> https://github.com/Pylons/webob/blob/main/src/webob/cookies.py)
> 
> Webob's set_cookie is designed to accept strings, and transcodes it to bytes 
> with utf8 encoding.
> (https://github.com/Pylons/webob/blob/main/src/webob/response.py)
> 
> Webob's request does a lot of transcoding between bytes and str for the 
> cookies, and both utf8 and latin1 charsets are used.
> 
> Can anyone share why these design decisions were made?  There just seems to 
> be a lot of needless transcoding going around, and the design decisions in 
> webob/pyramid tend to be very deliberate and thought out - so I must be 
> missing something.
> 
> Can anyone also share exactly why there are some latin-1 charsets in the 
> webob cookie logic?

I can’t directly comment on what part of the code you are looking at, but it is 
likely because Cookies are set using HTTP headers, and HTTP headers are limited 
in subset to latin-1 only (minus a bunch of other characters/control 
characters/whatnot). The reality is that they tend to get mangled and eaten 
alive, and or modified every which way. The only safe set is ASCII characters.

The same is true for other parts of the HTTP request and response.

> 
> Thank you in advance.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pylons-discuss/c2c36996-39c3-434a-91a9-a77bb2343027n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/pylons-discuss/c2c36996-39c3-434a-91a9-a77bb2343027n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/0B39E3A7-23AB-419D-9212-8B509CD0268C%400x58.com.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to