File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525
2626import string
2727import posixpath
28+ import urllib
2829
2930knownfiles = [
3031 "/usr/local/etc/httpd/conf/mime.types" ,
@@ -53,6 +54,26 @@ def guess_type(url):
5354 """
5455 if not inited :
5556 init ()
57+ scheme , url = urllib .splittype (url )
58+ if scheme == 'data' :
59+ # syntax of data URLs:
60+ # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
61+ # mediatype := [ type "/" subtype ] *( ";" parameter )
62+ # data := *urlchar
63+ # parameter := attribute "=" value
64+ # type/subtype defaults to "text/plain"
65+ comma = string .find (url , ',' )
66+ if comma < 0 :
67+ # bad data URL
68+ return None , None
69+ semi = string .find (url , ';' , 0 , comma )
70+ if semi >= 0 :
71+ type = url [:semi ]
72+ else :
73+ type = url [:comma ]
74+ if '=' in type or '/' not in type :
75+ type = 'text/plain'
76+ return type , None # never compressed, so encoding is None
5677 base , ext = posixpath .splitext (url )
5778 while suffix_map .has_key (ext ):
5879 base , ext = posixpath .splitext (base + suffix_map [ext ])
You can’t perform that action at this time.
0 commit comments