diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index 14117f9af..39ff0dc77 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -148,6 +148,8 @@ class MatchQuery(FieldQuery): class NoneQuery(FieldQuery): + """A query that checks whether a field is null.""" + def __init__(self, field, fast=True): super(NoneQuery, self).__init__(field, None, fast) diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 290f25b48..635c2f5a8 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -217,12 +217,20 @@ def all_items(): @app.route('/item//file') def item_file(item_id): item = g.lib.get_item(item_id) + + # On Windows under Python 2, Flask wants a Unicode path. On Python 3, it + # *always* wants a Unicode path. + if os.name == 'nt': + item_path = util.syspath(item.path) + else: + item_path = util.py3_path(item.path) + response = flask.send_file( - util.py3_path(item.path), + item_path, as_attachment=True, attachment_filename=os.path.basename(util.py3_path(item.path)), ) - response.headers['Content-Length'] = os.path.getsize(item.path) + response.headers['Content-Length'] = os.path.getsize(item_path) return response diff --git a/docs/changelog.rst b/docs/changelog.rst index 299d380f9..b3bee8a44 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -28,6 +28,8 @@ Fixes: * :doc:`/plugins/lastgenre`: Fix a crash when using the `prefer_specific` and `canonical` options together. Thanks to :user:`yacoob`. :bug:`2459` :bug:`2583` +* :doc:`/plugins/web`: Fix a crash on Windows under Python 2 when serving + non-ASCII filenames. Thanks to :user:`robot3498712`. :bug:`2592` :bug:`2593` 1.4.4 (June 10, 2017)