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
d6fbc099
Commit
d6fbc099
authored
Jan 28, 2012
by
Gabriel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework result objects.
parent
5a5d96ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
21 deletions
+46
-21
rfc6266.py
+46
-21
No files found.
rfc6266.py
View file @
d6fbc099
...
@@ -7,13 +7,45 @@ from urllib import unquote
...
@@ -7,13 +7,45 @@ from urllib import unquote
from
string
import
hexdigits
from
string
import
hexdigits
import
re
import
re
__all__
=
(
'
parse_header
'
,
)
__all__
=
(
'
ContentDisposition
'
,
)
separator_chars
=
"()<>@,;:
\\\"
/[]?={}
\t
"
separator_chars
=
"()<>@,;:
\\\"
/[]?={}
\t
"
non_attr_chars
=
separator_chars
+
"*'
%
"
non_attr_chars
=
separator_chars
+
"*'
%
"
LangTagged
=
namedtuple
(
'LangTagged'
,
'string langtag'
)
LangTagged
=
namedtuple
(
'LangTagged'
,
'string langtag'
)
Assoc
=
namedtuple
(
'Assoc'
,
'variable value'
)
class
ContentDisposition
(
object
):
def
__init__
(
self
,
disposition
=
'inline'
,
assocs
=
None
):
self
.
disposition
=
disposition
if
assocs
is
None
:
self
.
assocs
=
{}
else
:
# XXX Check that headers aren't repeated
self
.
assocs
=
dict
(
assocs
)
@property
def
filename
(
self
):
if
'filename*'
in
self
.
assocs
:
return
self
.
assocs
[
'filename*'
]
# Allow None
return
self
.
assocs
.
get
(
'filename'
)
def
__str__
(
self
):
return
'
%
s
%
s'
%
(
self
.
disposition
,
self
.
assocs
)
def
__repr__
(
self
):
return
'ContentDisposition(
%
r,
%
r)'
%
(
self
.
disposition
,
self
.
assocs
)
@classmethod
def
from_header
(
cls
,
hdrval
):
# Require hdrval to be ascii bytes (0-127),
# or characters in the ascii range
hdrval
=
hdrval
.
encode
(
'ascii'
)
return
content_disposition_value
.
parse
(
hdrval
)
def
parse_ext_value
(
val
):
def
parse_ext_value
(
val
):
...
@@ -27,6 +59,13 @@ def parse_ext_value(val):
...
@@ -27,6 +59,13 @@ def parse_ext_value(val):
return
LangTagged
(
decoded
,
langtag
)
return
LangTagged
(
decoded
,
langtag
)
def
parse_assignment
(
val
):
return
Assoc
(
*
val
)
def
parse_cdv
(
val
):
return
ContentDisposition
(
disposition
=
val
[
0
],
assocs
=
val
[
1
:])
# Currently LEPL doesn't handle case-insensivitity:
# Currently LEPL doesn't handle case-insensivitity:
# https://groups.google.com/group/lepl/browse_thread/thread/68e7b136038772ca
# https://groups.google.com/group/lepl/browse_thread/thread/68e7b136038772ca
...
@@ -62,34 +101,20 @@ if True:
...
@@ -62,34 +101,20 @@ if True:
# Adapted/simplified from https://tools.ietf.org/html/rfc6266
# Adapted/simplified from https://tools.ietf.org/html/rfc6266
with
DroppedSpace
():
with
DroppedSpace
():
disposition_parm
=
(
ext_token
&
'='
&
ext_value
)
|
(
noext_token
&
'='
&
value
)
disposition_parm
=
(
ext_token
&
Drop
(
'='
)
&
ext_value
)
|
(
noext_token
&
Drop
(
'='
)
&
value
)
>
parse_assignment
disposition_type
=
Literal
(
'inline'
)
|
Literal
(
'attachment'
)
|
token
disposition_type
=
Literal
(
'inline'
)
|
Literal
(
'attachment'
)
|
token
content_disposition_value
=
disposition_type
&
Star
(
';'
&
disposition_parm
)
content_disposition_value
=
disposition_type
&
Star
(
Drop
(
';'
)
&
disposition_parm
)
>
parse_cdv
class
ContentDisposition
(
object
):
# inline indicates default processing
disposition
=
'inline'
filename
=
None
extra_parms
=
None
def
parse_header
(
hdrval
):
# Require hdrval to be ascii bytes (0-127),
# or characters in the ascii range
hdrval
=
hdrval
.
encode
(
'ascii'
)
#content_disposition_value.config.clear().record_deepest()
return
content_disposition_value
.
parse
(
hdrval
)
def
selftest
():
def
selftest
():
sys
.
stderr
.
write
(
'
%
s
\n
'
%
disposition_parm
.
parse
(
'a=b'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
disposition_parm
.
parse
(
'a=b'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
parse
_header
(
'attachment'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
ContentDisposition
.
from
_header
(
'attachment'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
parse
_header
(
'attachment; a=b'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
ContentDisposition
.
from
_header
(
'attachment; a=b'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
parse
_header
(
'attachment; filename=simple'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
ContentDisposition
.
from
_header
(
'attachment; filename=simple'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
parse
_header
(
'attachment; filename="EURO rates"; filename*=utf-8
\'\'
%
e2
%82%
ac
%20
rates'
))
sys
.
stderr
.
write
(
'
%
s
\n
'
%
ContentDisposition
.
from
_header
(
'attachment; filename="EURO rates"; filename*=utf-8
\'\'
%
e2
%82%
ac
%20
rates'
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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