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
fd32fffa
Kaydet (Commit)
fd32fffa
authored
Kas 18, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #8402: Added the escape() function to the glob module.
üst
e3010fd7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
2 deletions
+49
-2
glob.rst
Doc/library/glob.rst
+11
-0
glob.py
Lib/glob.py
+14
-2
test_glob.py
Lib/test/test_glob.py
+22
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/glob.rst
Dosyayı görüntüle @
fd32fffa
...
...
@@ -40,6 +40,17 @@ For example, ``'[?]'`` matches the character ``'?'``.
without actually storing them all simultaneously.
.. function:: escape(pathname)
Escape all special characters (``'?'``, ``'*'`` and ``'['``).
This is useful if you want to match an arbitrary literal string that may
have special characters in it. Special characters in drive/UNC
sharepoints are not escaped, e.g. on Windows
``escape('//?/c:/Quo vadis?.txt')`` returns ``'//?/c:/Quo vadis[?].txt'``.
.. versionadded:: 3.4
For example, consider a directory containing only the following files:
:file:`1.gif`, :file:`2.txt`, and :file:`card.gif`. :func:`glob` will produce
the following results. Notice how any leading components of the path are
...
...
Lib/glob.py
Dosyayı görüntüle @
fd32fffa
...
...
@@ -79,8 +79,8 @@ def glob0(dirname, basename):
return
[]
magic_check
=
re
.
compile
(
'
[*?[]
'
)
magic_check_bytes
=
re
.
compile
(
b
'
[*?[]
'
)
magic_check
=
re
.
compile
(
'
([*?[])
'
)
magic_check_bytes
=
re
.
compile
(
b
'
([*?[])
'
)
def
has_magic
(
s
):
if
isinstance
(
s
,
bytes
):
...
...
@@ -91,3 +91,15 @@ def has_magic(s):
def
_ishidden
(
path
):
return
path
[
0
]
in
(
'.'
,
b
'.'
[
0
])
def
escape
(
pathname
):
"""Escape all special characters.
"""
# Escaping is done by wrapping any of "*?[" between square brackets.
# Metacharacters do not work in the drive part and shouldn't be escaped.
drive
,
pathname
=
os
.
path
.
splitdrive
(
pathname
)
if
isinstance
(
pathname
,
bytes
):
pathname
=
magic_check_bytes
.
sub
(
br
'[
\1
]'
,
pathname
)
else
:
pathname
=
magic_check
.
sub
(
r'[\1]'
,
pathname
)
return
drive
+
pathname
Lib/test/test_glob.py
Dosyayı görüntüle @
fd32fffa
...
...
@@ -169,6 +169,28 @@ class GlobTests(unittest.TestCase):
eq
(
glob
.
glob
(
'
\\\\
*
\\
*
\\
'
),
[])
eq
(
glob
.
glob
(
b
'
\\\\
*
\\
*
\\
'
),
[])
def
check_escape
(
self
,
arg
,
expected
):
self
.
assertEqual
(
glob
.
escape
(
arg
),
expected
)
self
.
assertEqual
(
glob
.
escape
(
os
.
fsencode
(
arg
)),
os
.
fsencode
(
expected
))
def
test_escape
(
self
):
check
=
self
.
check_escape
check
(
'abc'
,
'abc'
)
check
(
'['
,
'[[]'
)
check
(
'?'
,
'[?]'
)
check
(
'*'
,
'[*]'
)
check
(
'[[_/*?*/_]]'
,
'[[][[]_/[*][?][*]/_]]'
)
check
(
'/[[_/*?*/_]]/'
,
'/[[][[]_/[*][?][*]/_]]/'
)
@unittest.skipUnless
(
sys
.
platform
==
"win32"
,
"Win32 specific test"
)
def
test_escape_windows
(
self
):
check
=
self
.
check_escape
check
(
'?:?'
,
'?:[?]'
)
check
(
'*:*'
,
'*:[*]'
)
check
(
r'\\?\c:\?'
,
r'\\?\c:\[?]'
)
check
(
r'\\*\*\*'
,
r'\\*\*\[*]'
)
check
(
'//?/c:/?'
,
'//?/c:/[?]'
)
check
(
'//*/*/*'
,
'//*/*/[*]'
)
def
test_main
():
run_unittest
(
GlobTests
)
...
...
Misc/NEWS
Dosyayı görüntüle @
fd32fffa
...
...
@@ -50,6 +50,8 @@ Core and Builtins
Library
-------
-
Issue
#
8402
:
Added
the
escape
()
function
to
the
glob
module
.
-
Issue
#
17618
:
Add
Base85
and
Ascii85
encoding
/
decoding
to
the
base64
module
.
-
Issue
#
19634
:
time
.
strftime
(
"%y"
)
now
raises
a
ValueError
on
AIX
when
given
a
...
...
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