Commit graph

120 commits

Author SHA1 Message Date
Šarūnas Nejus
4a361bd501
Replace format calls with f-strings 2025-08-30 18:42:26 +01:00
Šarūnas Nejus
4260162d44
Remove all Python 2 references 2025-07-08 11:37:34 +01:00
Šarūnas Nejus
7cada1c9f8
Remove no-op decargs 2025-07-08 11:37:33 +01:00
Šarūnas Nejus
1a045c9166
Copy paste query, types from library to dbcore 2025-07-06 16:03:46 +01:00
Šarūnas Nejus
179ed13e09
Say bye to util._fsencoding 2025-04-21 12:41:57 +01:00
Andrew Rogl
04ee04150a
Reworked #4709 after latest release (#5447)
Fixes #4709 SQL use of Double Quoted Strings.
2024-09-30 10:28:15 +01:00
Šarūnas Nejus
f388ff6ec1
Replace py3_path with builtin os.fsdecode
`os.fsdecode` has only been available since Python 3.2.
2024-06-16 00:52:37 +01:00
Max Goltzsche
6b929c6e72
web: fix range request support
Do not let the web plugin overwrite the Content-Length header with the full file length since flask/werkzeug sets the requested range's/chunk's size when handling a range request.
This allows to play large audio/opus files using e.g. a browser/firefox or gstreamer/mopidy without making a reverse-proxy/nginx emulate range request support and hide range-related headers from the backend.
2023-12-20 01:23:13 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
wisp3rwind
4ae1e8278c web: fix for breaking werkzeug change
cf. https://github.com/pallets/werkzeug/issues/2506

didn't check when part_isolating was introduced, but presumably, it
should be harmless to set this attribute for old werkzeug versions that
didn't have it yet
2023-04-29 11:37:46 +02:00
wisp3rwind
d24cf69269 remove old Python: remove util.text_string
This was a helper for situations when Python 2 and 3 APIs returned bytes
and unicode, respectively. In these situation, we should nowadays know
which of the two we receive, so there's no need to wrap & hide the
`bytes.decode()` anymore (when it is still required).

Detailed justification:

beets/ui/__init__.py:
- command line options are always parsed to str

beets/ui/commands.py:
- confuse's config.dump always returns str
- open(...) defaults to text mode, read()ing str

beetsplug/keyfinder.py:
- ...

beetsplug/web/__init__.py:
- internally, paths are always bytestrings
- additionally, I took the liberty to slighlty re-arrange the code: it
  makes sense to split off the basename first, since we're only
  interested in the unicode conversion of that part.

test/helper.py:
- capture_stdout() gives a StringIO, which yields str

test/test_ui.py:
- self.io, from _common.TestCase, ultimately contains a
  _common.DummyOut, which appears to be dealing with str (cf.
  DummyOut.get)
2022-12-24 13:09:26 +01:00
wisp3rwind
3510e6311d web: slight refactor to make path handling more readable
(at least, more readable to me)
2022-12-24 13:09:26 +01:00
vicholp
fde2ad3f65 fix get item file of web plugin 2022-08-03 01:22:35 -04:00
Lars Kruse
a09c80447a beetsplug/web: fix translation of query path
The routing map translator `QueryConverter` was misconfigured:
* decoding (parsing a path): splitting with "/" as tokenizer
* encoding (translating back to a path): joining items with "," as separator

This caused queries containing more than one condition (separated by a
slash) to return an empty result.  Queries with only a single condition
were not affected.

Instead the encoding should have used the same delimiter (the slash) for the
backward conversion.

How to reproduce:
* query: `/album/query/albumartist::%5Efoo%24/original_year%2B/year%2B/album%2B`
* resulting content in parsed argument `queries` in the `album_query` function:
    * previous (wrong): `['albumartist::^foo$,original_year+,year+,album+']`
    * new (correct): `['albumartist::^foo$', 'original_year+', 'year+', 'album+']`
2022-01-06 22:00:26 +01:00
Andrew Rogl
1ec87a3bdd pyupgrade beetsplug and tests
All tests working
More tidy up to be done
2021-08-26 19:12:51 +10:00
Graham R. Cobb
4ffe9a2c45 Fixed bug where readonly value was not being read from config file.
Also simplified the setup of the `readonly` value in the tests which
fixes a test ordering issue found using --random-order.

Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
2021-03-12 17:58:35 +00:00
Graham R. Cobb
51d22b765e Add tests for delete operations
Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
2021-03-11 18:02:38 +00:00
Graham R. Cobb
4a9652a9e4 Only allow DELETE or PATCH operations if "readonly" is set to true.
Note: default is false which is a **NOT BACKWARDS COMPATIBLE** change.

Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
2021-03-11 18:02:38 +00:00
Graham R. Cobb
553e38fc11 Do not do backslash substitution on regex queries
As discussed in bug #3867, backslash replacement in query strings is a bit of a
hack but it is useful (see #3566 and #3567 for more discussion). However,
it breaks many regular expressions so this patch stops the replacement if the
query term contains '::', indicating it is a regex match.

This commit fixes #3867.

Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
2021-03-08 16:58:05 +00:00
Graham R. Cobb
9986b9892c Fix bug where album artpath not returned when INCLUDE_PATHS is set
Track item paths and album artpaths should be removed from results unless
INCLUDE_PATHS is set. This works for items but for albums the artpath is always
removed.

This patch makes the artpath removal conditional on INCLUDE_PATHS not being set
and includes a regression test. Note: the default value for INCLUDE_PATHS is
False so no changes will be seen by users unless they already have
INCLUDE_PATHS set.

Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
2021-03-06 15:25:48 +00:00
Cadel Watson
d1f93a26a6 Fix lint errors 2020-09-20 11:30:12 +10:00
Cadel Watson
a18b317240 Add PATCH method to item queries 2020-09-20 10:46:48 +10:00
Cadel Watson
afcde697e0 Add PATCH method to Items 2020-09-20 10:45:12 +10:00
Cadel Watson
29672a434f Add DELETE method to resource queries 2020-09-20 10:23:25 +10:00
Cadel Watson
76220fb148 Add DELETE method for items and albums 2020-09-20 10:18:07 +10:00
Sören Tempel
6a03afc65d web plugin: support path queries by separating them with a backslash
Without this change the web plugin does not support path queries as
slashes are currently used for joining keywords in the QueryConverter.
Moreover, flask cannot distinguish between an URL encoded and a plain
'/' character during routing [0]. To work around this issue without
introducing a breaking change (i.e. removing the QueryConverter) use the
backslash character for path queries and convert it later on.

Fixes #3566

[0]: https://github.com/pallets/flask/issues/900
2020-04-27 13:36:36 +02:00
Adrian Sampson
d43d54e21c Try to work around a Werkzeug change? 2020-02-06 22:22:54 -05:00
Ryan Veach
1505ff071d changed flask cors import 2018-07-10 10:32:21 -05:00
Waweic
06d4fe254d Implement recommendations by sampsyo
Implemented all recommendations.
2018-03-06 17:49:20 +01:00
Waweic
3c3e579dcc Make programming style pep8 compliant 2018-03-01 20:20:38 +01:00
Waweic
d0fd41b474 Add unicode support for Python 2 and 3
Converts bytes to unicode using util.text_string, assuming that the
string is a UTF-8 string.
If that fails, it falls back to a hardcoded fallback filename.
2018-03-01 19:45:44 +01:00
Waweic
4df313e3ce Fix unicode problems in web plugin
Added Exception to the web plugin to catch non latin-1 characters and change them to ascii chars.
Added Description to the changelog file
2018-03-01 11:56:38 +01:00
Waweic
b94227a53d Merge https://github.com/waweic/beets into patch-2
Catch up
2018-02-27 22:03:50 +01:00
Adrian Sampson
453fd372a3 Flatten a config view (#2821) 2018-02-26 18:00:59 -05:00
Samuel Loury
e3599742b4 Add a support for supports_credentials
If the web plugin is behind a credential based http server and is
accessed by another in-browser client in another domain, the
specification of CORS requires the server to indicate it supports
such credentials.
2018-02-26 21:08:02 +01:00
waweic
be96c1022a
Fix album_art() in __init__.py
flask.send_file() expects a string, g.lib.get_album() returns bytes. Added decode() to album_art(). 

If g.lib.get_album() gets a non-existing id, it returns None. Python would throw an error in this case. Added check to prevent this.
2018-02-26 18:33:30 +01:00
Adrian Sampson
009c6a4f6d Slightly clearer layout for #2593, and comments 2017-06-15 17:51:14 -04:00
robot3498712
cafbb2438e fixed failing test - line too long 2017-06-15 13:27:28 +02:00
robot3498712
bc8a8ecf5f fix /issues/2592: web: Use Unicode paths to send files on Windows under Python 2 2017-06-15 12:49:00 +02:00
Adrian Sampson
b57c49d738 Add a period to a comment, simplify one expression
w.r.t. #2542
2017-05-04 09:29:27 -04:00
Mark Stenglein
22f07b91e9 web: __init__: _rep: Make the looping more pythonic
As suggested, changes around the for loop to make it a bit more
pythonic by using an if loop inside a normal for loop.

Signed-off-by: Mark Stenglein <mark@stengle.in>
2017-05-03 16:36:40 -04:00
Mark Stenglein
9394e0ac63 web: __init__: _rep: change to base64 encoding
As suggested, this commit adds base64 encoding for the bytes
encoding.

Signed-off-by: Mark Stenglein <mark@stengle.in>
2017-05-03 16:34:30 -04:00
Mark Stenglein
471d46d67e web: __init__: _rep: Filter all bytes for serializer
This commit fixes issue #2532 by filtering out any byte values
added by any other extensions and decoding them to strings for the
JSON serializer.

It does not remove any of the keys, instead opting to just convert
them.

Signed-off-by: Mark Stenglein <mark@stengle.in>
2017-05-03 00:03:05 -04:00
Olivier Biesmans
cf384109f0 Make falke8 happy and reference flask doc for the ReverseProxied class 2017-03-19 21:16:26 +00:00
Olivier Biesmans
aa847e52ac Add reverse proxy support 2017-03-19 20:08:39 +00:00
Steve Johnson
926dce241c Use util.displayable_path instead of naive .decode() 2017-01-15 11:25:03 -08:00
Steve Johnson
e3707e45f3 Maybe fix code and tests for Windows 2017-01-15 11:21:59 -08:00
Steve Johnson
e2be6ba781 Query path with bytestring. Might fix tests. 2017-01-15 11:21:59 -08:00
Steve Johnson
4434569ddc beets.library.Library adds custom bytelower function to all connections, not just one 2017-01-15 11:21:59 -08:00
Steve Johnson
866a650bc0 Rename /item/by_path to /item/path and use PathQuery instead of direct file access 2017-01-15 11:21:33 -08:00