mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 20:12:33 +01:00
Remove shlex_split utility
This works around a bug that does not exist in Python 3.x, and the workaround (by calling the underlying shlex.split function with bytes) was causing crashes on some versions of Python 3. Seemed to work fine on 3.10-dev, though, oddly.
This commit is contained in:
parent
f545cd3830
commit
2f5f9ea174
5 changed files with 10 additions and 25 deletions
|
|
@ -24,6 +24,7 @@ import time
|
|||
import re
|
||||
import six
|
||||
import string
|
||||
import shlex
|
||||
|
||||
from beets import logging
|
||||
from mediafile import MediaFile, UnreadableFileError
|
||||
|
|
@ -1391,7 +1392,7 @@ def parse_query_string(s, model_cls):
|
|||
message = u"Query is not unicode: {0!r}".format(s)
|
||||
assert isinstance(s, six.text_type), message
|
||||
try:
|
||||
parts = util.shlex_split(s)
|
||||
parts = shlex.split(s)
|
||||
except ValueError as exc:
|
||||
raise dbcore.InvalidQueryError(s, exc)
|
||||
return parse_query_parts(parts, model_cls)
|
||||
|
|
|
|||
|
|
@ -924,25 +924,6 @@ def editor_command():
|
|||
return open_anything()
|
||||
|
||||
|
||||
def shlex_split(s):
|
||||
"""Split a Unicode or bytes string according to shell lexing rules.
|
||||
|
||||
Raise `ValueError` if the string is not a well-formed shell string.
|
||||
This is a workaround for a bug in some versions of Python.
|
||||
"""
|
||||
if isinstance(s, bytes): # Shlex works fine.
|
||||
return shlex.split(s)
|
||||
|
||||
elif isinstance(s, six.text_type):
|
||||
# Work around a Python bug.
|
||||
# http://bugs.python.org/issue6988
|
||||
bs = s.encode('utf-8')
|
||||
return [c.decode('utf-8') for c in shlex.split(bs)]
|
||||
|
||||
else:
|
||||
raise TypeError(u'shlex_split called with non-string')
|
||||
|
||||
|
||||
def interactive_open(targets, command):
|
||||
"""Open the files in `targets` by `exec`ing a new `command`, given
|
||||
as a Unicode string. (The new program takes over, and Python
|
||||
|
|
@ -954,7 +935,7 @@ def interactive_open(targets, command):
|
|||
|
||||
# Split the command string into its arguments.
|
||||
try:
|
||||
args = shlex_split(command)
|
||||
args = shlex.split(command)
|
||||
except ValueError: # Malformed shell tokens.
|
||||
args = [command]
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import yaml
|
|||
from tempfile import NamedTemporaryFile
|
||||
import os
|
||||
import six
|
||||
import shlex
|
||||
|
||||
|
||||
# These "safe" types can avoid the format/parse cycle that most fields go
|
||||
|
|
@ -45,7 +46,7 @@ class ParseError(Exception):
|
|||
def edit(filename, log):
|
||||
"""Open `filename` in a text editor.
|
||||
"""
|
||||
cmd = util.shlex_split(util.editor_command())
|
||||
cmd = shlex.split(util.editor_command())
|
||||
cmd.append(filename)
|
||||
log.debug(u'invoking editor command: {!r}', cmd)
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ from __future__ import division, absolute_import, print_function
|
|||
|
||||
import string
|
||||
import subprocess
|
||||
import shlex
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.util import shlex_split, arg_encoding
|
||||
from beets.util import arg_encoding
|
||||
|
||||
|
||||
class CodingFormatter(string.Formatter):
|
||||
|
|
@ -95,7 +96,7 @@ class HookPlugin(BeetsPlugin):
|
|||
# Use a string formatter that works on Unicode strings.
|
||||
formatter = CodingFormatter(arg_encoding())
|
||||
|
||||
command_pieces = shlex_split(command)
|
||||
command_pieces = shlex.split(command)
|
||||
|
||||
for i, piece in enumerate(command_pieces):
|
||||
command_pieces[i] = formatter.format(piece, event=event,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ from beets import util
|
|||
from os.path import relpath
|
||||
from tempfile import NamedTemporaryFile
|
||||
import subprocess
|
||||
import shlex
|
||||
|
||||
# Indicate where arguments should be inserted into the command string.
|
||||
# If this is missing, they're placed at the end.
|
||||
|
|
@ -44,7 +45,7 @@ def play(command_str, selection, paths, open_args, log, item_type='track',
|
|||
|
||||
try:
|
||||
if keep_open:
|
||||
command = util.shlex_split(command_str)
|
||||
command = shlex.split(command_str)
|
||||
command = command + open_args
|
||||
subprocess.call(command)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue