Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rfc6266
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
rfc6266
Commits
afa51e9e
Commit
afa51e9e
authored
Jan 29, 2012
by
Gabriel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow sending other dispositions. Comment and style.
parent
1f21c680
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
rfc6266.py
+18
-8
No files found.
rfc6266.py
View file @
afa51e9e
...
@@ -230,14 +230,19 @@ ext_value = (
...
@@ -230,14 +230,19 @@ ext_value = (
ext_token
=
token
+
'*'
ext_token
=
token
+
'*'
noext_token
=
~
Lookahead
(
ext_token
)
&
token
noext_token
=
~
Lookahead
(
ext_token
)
&
token
# Adapted/simplified from https://tools.ietf.org/html/rfc6266
# Adapted from https://tools.ietf.org/html/rfc6266
# Mostly this was simplified to fold filename / filename*
# into the normal handling of ext_token / noext_token
with
DroppedSpace
():
with
DroppedSpace
():
disposition_parm
=
(
disposition_parm
=
(
(
ext_token
&
Drop
(
'='
)
&
ext_value
)
(
ext_token
&
Drop
(
'='
)
&
ext_value
)
|
(
noext_token
&
Drop
(
'='
)
&
value
))
>
tuple
|
(
noext_token
&
Drop
(
'='
)
&
value
))
>
tuple
disposition_type
=
Literal
(
'inline'
)
|
Literal
(
'attachment'
)
|
token
disposition_type
=
(
CaseInsensitiveLiteral
(
'inline'
)
|
CaseInsensitiveLiteral
(
'attachment'
)
|
token
)
content_disposition_value
=
(
content_disposition_value
=
(
disposition_type
&
Star
(
Drop
(
';'
)
&
disposition_parm
))
#> parse_cdv
disposition_type
&
Star
(
Drop
(
';'
)
&
disposition_parm
))
def
is_token_char
(
ch
):
def
is_token_char
(
ch
):
...
@@ -250,14 +255,16 @@ def is_token_char(ch):
...
@@ -250,14 +255,16 @@ def is_token_char(ch):
def
usesonlycharsfrom
(
candidate
,
chars
):
def
usesonlycharsfrom
(
candidate
,
chars
):
# Found that shortcut in urllib.quote
# Found that shortcut in urllib.quote
return
not
candidate
.
rstrip
(
chars
)
return
candidate
.
rstrip
(
chars
)
==
''
def
is_token
(
candidate
):
def
is_token
(
candidate
):
return
all
(
is_token_char
(
ch
)
for
ch
in
candidate
)
return
all
(
is_token_char
(
ch
)
for
ch
in
candidate
)
def
header_for_filename
(
filename
,
compat
=
'ignore'
,
filename_compat
=
None
):
def
header_for_filename
(
filename
,
disposition
=
'attachment'
,
compat
=
'ignore'
,
filename_compat
=
None
):
# https://tools.ietf.org/html/rfc6266#appendix-D
# Compat methods (fallback for receivers that can't handle filename*):
# Compat methods (fallback for receivers that can't handle filename*):
# - ignore (give only filename*);
# - ignore (give only filename*);
# - strip accents using unicode's decomposing normalisations,
# - strip accents using unicode's decomposing normalisations,
...
@@ -273,11 +280,14 @@ def header_for_filename(filename, compat='ignore', filename_compat=None):
...
@@ -273,11 +280,14 @@ def header_for_filename(filename, compat='ignore', filename_compat=None):
if
compat
!=
'ignore'
:
if
compat
!=
'ignore'
:
raise
NotImplementedError
raise
NotImplementedError
if
disposition
!=
'attachment'
:
assert
is_token
(
disposition
)
if
is_token
(
filename
):
if
is_token
(
filename
):
return
'
attachment; filename=
%
s'
%
filename
return
'
%
s; filename=
%
s'
%
(
disposition
,
filename
)
return
"
attachment; filename*=utf-8''
%
s"
%
quote
(
return
"
%
s; filename*=utf-8''
%
s"
%
(
disposition
,
quote
(
filename
.
encode
(
'utf-8'
),
safe
=
attr_chars_nonalnum
)
filename
.
encode
(
'utf-8'
),
safe
=
attr_chars_nonalnum
)
)
def
test_cdfh
():
def
test_cdfh
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment