Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4becf85d
Kaydet (Commit)
4becf85d
authored
Haz 29, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
don't allow unicode into type_map on Windows (closes #21652)
Patch from Vladimir Iofik.
üst
fd3ba7b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
16 deletions
+40
-16
mimetypes.py
Lib/mimetypes.py
+16
-13
test_mimetypes.py
Lib/test/test_mimetypes.py
+21
-3
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/mimetypes.py
Dosyayı görüntüle @
4becf85d
...
...
@@ -247,23 +247,26 @@ class MimeTypes:
break
i
+=
1
default_encoding
=
sys
.
getdefaultencoding
()
with
_winreg
.
OpenKey
(
_winreg
.
HKEY_CLASSES_ROOT
,
''
)
as
hkcr
:
for
subkeyname
in
enum_types
(
hkcr
):
# Only check file extensions, not all possible classes
if
not
subkeyname
.
startswith
(
"."
):
continue
with
_winreg
.
OpenKey
(
hkcr
,
subkeyname
)
as
subkey
:
# If there is no "Content Type" value, or if it is not
# a simple string, simply skip
try
:
try
:
with
_winreg
.
OpenKey
(
hkcr
,
subkeyname
)
as
subkey
:
# Only check file extensions
if
not
subkeyname
.
startswith
(
"."
):
continue
# raises EnvironmentError if no 'Content Type' value
mimetype
,
datatype
=
_winreg
.
QueryValueEx
(
subkey
,
'Content Type'
)
except
EnvironmentError
:
continue
if
datatype
!=
_winreg
.
REG_SZ
:
continue
self
.
add_type
(
mimetype
,
subkeyname
,
strict
)
if
datatype
!=
_winreg
.
REG_SZ
:
continue
try
:
mimetype
=
mimetype
.
encode
(
default_encoding
)
except
UnicodeEncodeError
:
continue
self
.
add_type
(
mimetype
,
subkeyname
,
strict
)
except
EnvironmentError
:
continue
def
guess_type
(
url
,
strict
=
True
):
"""Guess the type of a file based on its URL.
...
...
Lib/test/test_mimetypes.py
Dosyayı görüntüle @
4becf85d
# -*- coding: utf-8 -*-
import
mimetypes
import
StringIO
import
unittest
...
...
@@ -95,10 +97,10 @@ class Win32MimeTypesTestCase(unittest.TestCase):
def
__getattr__
(
self
,
name
):
if
name
==
'EnumKey'
:
return
lambda
key
,
i
:
_winreg
.
EnumKey
(
key
,
i
)
+
"
\xa3
"
elif
name
==
"OpenKey"
:
elif
name
==
'OpenKey'
:
return
lambda
key
,
name
:
_winreg
.
OpenKey
(
key
,
name
.
rstrip
(
"
\xa3
"
))
elif
name
==
'QueryValueEx'
:
return
lambda
subkey
,
label
:
(
label
+
"
\xa3
"
,
_winreg
.
REG_SZ
)
return
lambda
subkey
,
label
:
(
u'текст/простой'
,
_winreg
.
REG_SZ
)
return
getattr
(
_winreg
,
name
)
mimetypes
.
_winreg
=
MockWinreg
()
...
...
@@ -115,7 +117,7 @@ class Win32MimeTypesTestCase(unittest.TestCase):
class
MockWinreg
(
object
):
def
__getattr__
(
self
,
name
):
if
name
==
'QueryValueEx'
:
return
lambda
subkey
,
label
:
(
label
+
"
\xa3
"
,
_winreg
.
REG_SZ
)
return
lambda
subkey
,
label
:
(
u'текст/простой'
,
_winreg
.
REG_SZ
)
return
getattr
(
_winreg
,
name
)
mimetypes
.
_winreg
=
MockWinreg
()
...
...
@@ -126,6 +128,22 @@ class Win32MimeTypesTestCase(unittest.TestCase):
finally
:
mimetypes
.
_winreg
=
_winreg
def
test_type_map_values
(
self
):
import
_winreg
class
MockWinreg
(
object
):
def
__getattr__
(
self
,
name
):
if
name
==
'QueryValueEx'
:
return
lambda
subkey
,
label
:
(
u'text/plain'
,
_winreg
.
REG_SZ
)
return
getattr
(
_winreg
,
name
)
mimetypes
.
_winreg
=
MockWinreg
()
try
:
mimetypes
.
init
()
self
.
assertTrue
(
isinstance
(
mimetypes
.
types_map
.
values
()[
0
],
str
))
finally
:
mimetypes
.
_winreg
=
_winreg
def
test_main
():
test_support
.
run_unittest
(
MimeTypesTestCase
,
Win32MimeTypesTestCase
...
...
Misc/NEWS
Dosyayı görüntüle @
4becf85d
...
...
@@ -35,6 +35,9 @@ Core and Builtins
Library
-------
- Issue #21652: Prevent mimetypes.type_map from containing unicode keys on
Windows.
- Issue #21729: Used the "with" statement in the dbm.dumb module to ensure
files closing.
...
...
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