Skip to content

*: add some API for RPC server #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions feeluown/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ def _write_metadata_if_needed(self, f):
f.write('\n')
f.write(TOML_DELIMLF)

def raw_data(self):
"""Return the raw data of the collection file.

.. versionadded:: 4.1.11
"""
with open(self.fpath, encoding='utf-8') as f:
return f.read()

def overwrite_with_raw_data(self, raw_data):
"""Overwrite the collection file with the provided raw data.

.. versionadded:: 4.1.11
"""
with open(self.fpath, 'w', encoding='utf-8') as f:
f.write(raw_data)
self.load()


class CollectionManager:

Expand Down
17 changes: 15 additions & 2 deletions feeluown/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,21 @@ def _serialize(self, f):
from feeluown.library import reverse

js = f(self)
js.pop('meta')
js.pop('state')
# FIXME: pydantic >=2.11 has a bug that it may call this method
# multiple times -> https://github.com/pydantic/pydantic/issues/11505
# So the `js` may not have `meta` and `state` field sometimes.
# What's even more buggy is that it does not raise exception when
# `js` does not have `meta` and `state`.
#
# For example, SongModel has a field album with TAlbum type,
# pydantic may try to serialize the model with BriefAlbumModel even
# if the model is actually AlbumModel.
#
# Without this workaround, the test case `test_serialize_model`
# will fail with pydantic >=2.11. See
# https://github.com/feeluown/FeelUOwn/pull/922 for more details.
js.pop('meta', None)
js.pop('state', None)
js['provider'] = js['source']
js['uri'] = reverse(self)
js['__type__'] = f'feeluown.library.{self.__class__.__name__}'
Expand Down
4 changes: 0 additions & 4 deletions feeluown/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def register_deserializer(type_, deserializer_cls):


def get_serializer(format_):
global _MAPPING

if not _MAPPING:
register_serializer('plain', PlainSerializer)
register_serializer('json', JsonSerializer)
Expand All @@ -31,8 +29,6 @@ def get_serializer(format_):


def get_deserializer(format_: str):
global _DE_MAPPING

if not _DE_MAPPING:
register_deserializer('python', PythonDeserializer)
if format_ not in _DE_MAPPING:
Expand Down
2 changes: 1 addition & 1 deletion feeluown/serializers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def serialize_search_result_list(self, list_):

class SimpleTypeSerializer(PythonSerializer, metaclass=SerializerMeta):
class Meta:
types = (str, int, float, type(None))
types = (str, int, float, type(None), dict)

def serialize(self, object):
return object
Loading