twisted / twisted/klein

Simpler request helper functions that accept bytes and unicode args

Open
#157 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
838
Forks
123
Avg merge
7h 58m
Merged PRs (30d)
12

Description

This is related to a bug I wrote a while back #108 for Klein and 8905 for Twisted. It would make writing code more pleasant if certain functions of the Request object would accept both bytes and unicode. This would also bridge gaps between writing Py2 and Py3 code. This issue was primarily created because there are inconsistencies with:

  • Headers (param can be bytes or unicode)
  • adding cookies (param can be bytes or unicode)
  • getting cookies (param can only be bytes)
  • getting request.args (param can only be bytes)

It is easy to do something like 'unicode or py2 str key'.encode('utf-8') before passing it to the various getter/setter functions, however the more popular Python web frameworks never force users to do this and Klein should follow suite. I'm well aware that these are upstream Twisted issues, but it's extremely noticeable in Klein. My hope is to deploy a solution here, test it out with the people who use Klein, then merge them upstream.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Klein's Request object and compare the handling of Headers, addCookie, cookie lookup, and request.args, then review related issues #108 and Twisted ticket 8905. The work is complete when the affected helpers consistently accept both bytes and unicode and the behavior has been tested with Klein users before considering an upstream change.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.