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
ca804955
Kaydet (Commit)
ca804955
authored
May 29, 2019
tarafından
Bo Bayles
Kaydeden (comit)
Vinay Sajip
May 29, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-22454: Add shlex.join() (the opposite of shlex.split()) (GH-7605)
üst
f83d1dbd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
1 deletion
+48
-1
shlex.rst
Doc/library/shlex.rst
+15
-0
3.8.rst
Doc/whatsnew/3.8.rst
+5
-0
shlex.py
Lib/shlex.py
+6
-1
test_shlex.py
Lib/test/test_shlex.py
+20
-0
2018-06-10-17-48-07.bpo-22454.qeiy_X.rst
...S.d/next/Library/2018-06-10-17-48-07.bpo-22454.qeiy_X.rst
+2
-0
No files found.
Doc/library/shlex.rst
Dosyayı görüntüle @
ca804955
...
...
@@ -37,6 +37,21 @@ The :mod:`shlex` module defines the following functions:
standard input.
.. function:: join(split_command)
Concatenate the tokens of the list *split_command* and return a string.
This function is the inverse of :func:`split`.
>>> from shlex import join
>>> print(join(['echo', '-n', 'Multiple words']))
echo -n 'Multiple words'
The returned value is shell-escaped to protect against injection
vulnerabilities (see :func:`quote`).
.. versionadded:: 3.8
.. function:: quote(s)
Return a shell-escaped version of the string *s*. The returned value is a
...
...
Doc/whatsnew/3.8.rst
Dosyayı görüntüle @
ca804955
...
...
@@ -552,6 +552,11 @@ convenience functions to automate the necessary tasks usually involved when
creating a server socket, including accepting both IPv4 and IPv6 connections
on the same socket. (Contributed by Giampaolo Rodola in :issue:`17561`.)
shlex
----------
The new :func:`shlex.join` function acts as the inverse of :func:`shlex.split`.
(Contributed by Bo Bayles in :issue:`32102`.)
shutil
------
...
...
Lib/shlex.py
Dosyayı görüntüle @
ca804955
...
...
@@ -14,7 +14,7 @@ from collections import deque
from
io
import
StringIO
__all__
=
[
"shlex"
,
"split"
,
"quote"
]
__all__
=
[
"shlex"
,
"split"
,
"quote"
,
"join"
]
class
shlex
:
"A lexical analyzer class for simple shell-like syntaxes."
...
...
@@ -305,6 +305,11 @@ def split(s, comments=False, posix=True):
return
list
(
lex
)
def
join
(
split_command
):
"""Return a shell-escaped string from *split_command*."""
return
' '
.
join
(
quote
(
arg
)
for
arg
in
split_command
)
_find_unsafe
=
re
.
compile
(
r'[^\w@
%+
=:,./-]'
,
re
.
ASCII
)
.
search
def
quote
(
s
):
...
...
Lib/test/test_shlex.py
Dosyayı görüntüle @
ca804955
...
...
@@ -308,6 +308,26 @@ class ShlexTest(unittest.TestCase):
self
.
assertEqual
(
shlex
.
quote
(
"test
%
s'name'"
%
u
),
"'test
%
s'
\"
'
\"
'name'
\"
'
\"
''"
%
u
)
def
testJoin
(
self
):
for
split_command
,
command
in
[
([
'a '
,
'b'
],
"'a ' b"
),
([
'a'
,
' b'
],
"a ' b'"
),
([
'a'
,
' '
,
'b'
],
"a ' ' b"
),
([
'"a'
,
'b"'
],
'
\'
"a
\'
\'
b"
\'
'
),
]:
with
self
.
subTest
(
command
=
command
):
joined
=
shlex
.
join
(
split_command
)
self
.
assertEqual
(
joined
,
command
)
def
testJoinRoundtrip
(
self
):
all_data
=
self
.
data
+
self
.
posix_data
for
command
,
*
split_command
in
all_data
:
with
self
.
subTest
(
command
=
command
):
joined
=
shlex
.
join
(
split_command
)
resplit
=
shlex
.
split
(
joined
)
self
.
assertEqual
(
split_command
,
resplit
)
# Allow this test to be used with old shlex.py
if
not
getattr
(
shlex
,
"split"
,
None
):
for
methname
in
dir
(
ShlexTest
):
...
...
Misc/NEWS.d/next/Library/2018-06-10-17-48-07.bpo-22454.qeiy_X.rst
0 → 100644
Dosyayı görüntüle @
ca804955
The :mod:`shlex` module now exposes :func:`shlex.join`, the inverse of
:func:`shlex.split`. Patch by Bo Bayles.
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