Skip to content

Commit

Permalink
Fixed incorrect implementation of _or_default properties in operation…
Browse files Browse the repository at this point in the history
…s classes. Fixed handling of List[Structure] | None type in structures.
  • Loading branch information
smelamud committed Nov 2, 2023
1 parent 3540f26 commit d93b9f7
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 179 deletions.
11 changes: 6 additions & 5 deletions py-moera-api/pymoeraapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def doc_wrap(s: str, indent: int) -> str:
max_length = 120 - indent * 4
result = ''
while True:
if len(s) <= max_length:
if len(s) < max_length:
result += s
break
pos = 0
while True:
next = s.find(' ', pos + 1)
if next < 0 or next > max_length:
if next < 0 or next >= max_length:
break
pos = next
result += s[:pos] + '\n' + ind(indent)
Expand Down Expand Up @@ -164,10 +164,11 @@ def generate_operations(operations: Any, tfile: TextIO, sfile: TextIO) -> None:
tfile.write(' def %s_or_default(self) -> PrincipalValue:\n' % py_name)
doc = doc_wrap(
field['description'] + ' (this property always returns default value instead of ``None``)', 2)
if len(doc) >= 110:
if len(doc) >= 107:
doc = f'\n{ind(2)}{doc}\n{ind(2)}'
tfile.write(' """%s"""\n' % doc)
tfile.write(' return getattr(self, "%s", "%s")\n\n' % (py_name, field['default']))
tfile.write(' return self.%s if self.%s is not None else "%s"\n'
% (py_name, py_name, field['default']))

sfile.write('\n')
sfile.write('{name}_SCHEMA: Any = {{\n'.format(name=to_snake(operations['name']).upper()))
Expand Down Expand Up @@ -252,7 +253,7 @@ def generate_class(self, tfile: TextIO) -> None:
tfile.write(tmpl % (to_snake(field['name']), t))
if 'description' in field:
doc = doc_wrap(html_to_doc(field["description"]), 1)
if len(doc) >= 110:
if len(doc) >= 107:
doc = f'\n{ind(1)}{doc}\n{ind(1)}'
tfile.write(f'{ind(1)}"""{doc}"""\n')

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "moeralib"
version = "0.14.2"
version = "0.14.3"
authors = [
{name = "Shmuel Leib Melamud", email = "[email protected]"},
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = moeralib
version = 0.14.2
version = 0.14.3

[options]
install_requires =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='moeralib',
version='0.14.2',
version='0.14.3',
install_requires=[
'requests>=2.31.0',
'camel-converter',
Expand Down
72 changes: 36 additions & 36 deletions src/moeralib/node/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def search_activity_reactions(self, filter: types.ActivityReactionFilter) -> Lis
"""
location = "/activity/reactions/search"
data = self.call(
"search_activity_reactions", location, method="GET", body=filter,
"search_activity_reactions", location, method="POST", body=filter,
schema=schemas.ACTIVITY_REACTION_INFO_ARRAY_SCHEMA
)
return structure_list(data, types.ActivityReactionInfo)
Expand Down Expand Up @@ -66,8 +66,8 @@ def get_avatars(self) -> List[types.AvatarInfo]:
def create_avatar(self, avatar: types.AvatarAttributes) -> types.AvatarInfo:
"""
Create a new avatar from a public media file that exists on the node. New public media file is created for the
avatar. If avatar's ordinal is not provided in the input, the avatar is assigned an ordinal that is greater than
ordinals of all existing avatars.
avatar. If avatar's ordinal is not provided in the input, the avatar is assigned an ordinal that is greater
than ordinals of all existing avatars.
:param avatar:
"""
Expand Down Expand Up @@ -97,8 +97,8 @@ def delete_avatar(self, id: str) -> types.Result:

def reorder_avatars(self, order: types.AvatarsOrdered) -> List[types.AvatarOrdinal]:
"""
Reorder avatars. Every avatar mentioned in the input is assigned an ordinal in ascending order as they appear in
the input. Ordinals of avatars not mentioned in the input are not touched.
Reorder avatars. Every avatar mentioned in the input is assigned an ordinal in ascending order as they appear
in the input. Ordinals of avatars not mentioned in the input are not touched.
:param order:
"""
Expand Down Expand Up @@ -199,8 +199,8 @@ def search_blocked_users(self, filter: types.BlockedUserFilter) -> List[types.Bl

def get_blocked_users_checksums(self) -> types.BlockedUsersChecksums:
"""
Get checksums of the information about the blocked users. This request may be used to quickly detect the changes
in the blocked users list to update the cache on the client side.
Get checksums of the information about the blocked users. This request may be used to quickly detect the
changes in the blocked users list to update the cache on the client side.
"""
location = "/people/blocked-users/checksums"
data = self.call(
Expand Down Expand Up @@ -395,8 +395,8 @@ def create_comment_reaction(
"""
Add a reaction to the given comment. The reaction owner must authenticate in some way. Only one reaction is
allowed from each owner to a particular comment. If a reaction from the same owner to this comment already
exists, it is overwritten. If the reaction is not signed, the reaction will be kept for a limited period of time
and then erased (the previous reaction of the same owner will be restored, if any).
exists, it is overwritten. If the reaction is not signed, the reaction will be kept for a limited period of
time and then erased (the previous reaction of the same owner will be restored, if any).
:param posting_id: ID of the posting
:param comment_id: ID of the comment
Expand Down Expand Up @@ -435,9 +435,9 @@ def get_comment_reactions_slice(
) -> types.ReactionsSliceInfo:
"""
Get a slice of the list of reactions to the given comment, optionally filtered by reaction type, delimited by
``before`` moment and the given ``limit``. If ``before`` is not provided, the latest reactions are returned. The
node may decide to return less reactions than the given ``limit``. The reactions are always sorted by moment,
descending.
``before`` moment and the given ``limit``. If ``before`` is not provided, the latest reactions are returned.
The node may decide to return less reactions than the given ``limit``. The reactions are always sorted by
moment, descending.
:param posting_id: ID of the posting
:param comment_id: ID of the comment
Expand Down Expand Up @@ -693,8 +693,8 @@ def get_domains(self) -> List[types.DomainInfo]:

def get_domain(self, name: str) -> types.DomainInfo:
"""
Get information about the domain with the given hostname. If domain registration for this server is public, this
request does not require authentication.
Get information about the domain with the given hostname. If domain registration for this server is public,
this request does not require authentication.
:param name: domain name
"""
Expand Down Expand Up @@ -877,9 +877,9 @@ def get_feed_slice(
self, feed_name: str, after: int | None = None, before: int | None = None, limit: int | None = None
) -> types.FeedSliceInfo:
"""
Get a slice of the feed, delimited by ``before`` or ``after`` moments (but not both) and the given ``limit``. If
neither ``before`` nor ``after`` are provided, the latest stories are returned. The node may decide to return
less stories than the given ``limit``. The stories are always sorted by moment, descending.
Get a slice of the feed, delimited by ``before`` or ``after`` moments (but not both) and the given ``limit``.
If neither ``before`` nor ``after`` are provided, the latest stories are returned. The node may decide to
return less stories than the given ``limit``. The stories are always sorted by moment, descending.
:param feed_name: name of the feed
:param after: filter stories posted strongly after this moment
Expand Down Expand Up @@ -969,9 +969,9 @@ def get_friend(self, name: str) -> types.FriendInfo:

def update_friends(self, friends: List[types.FriendDescription]) -> List[types.FriendInfo]:
"""
Update the friendship status of the nodes passed in the input. If some of the nodes passed in the input is not a
member of some of the groups of friends listed for it, the node is added to them. If it is a member of some of
the groups of friends that are not listed for it, the node is removed from them.
Update the friendship status of the nodes passed in the input. If some of the nodes passed in the input is not
a member of some of the groups of friends listed for it, the node is added to them. If it is a member of some
of the groups of friends that are not listed for it, the node is removed from them.
:param friends:
"""
Expand Down Expand Up @@ -1162,8 +1162,8 @@ def get_people_general(self) -> types.PeopleGeneralInfo:

def register_plugin(self, plugin: types.PluginDescription) -> types.PluginInfo:
"""
Register the plugin. If the plugin authenticates as root admin, the plugin is registered at the server level. If
the plugin authenticates as node admin, the plugin is registered at the node level.
Register the plugin. If the plugin authenticates as root admin, the plugin is registered at the server level.
If the plugin authenticates as node admin, the plugin is registered at the node level.
:param plugin:
"""
Expand Down Expand Up @@ -1201,10 +1201,10 @@ def unregister_plugin(self, plugin_name: str) -> types.Result:

def create_posting(self, posting: types.PostingText) -> types.PostingInfo:
"""
Create a new posting from the text given and publish it in the given feeds (if any). The heading and the preview
of the posting are created automatically, if needed. The posting owner must authenticate in some way. If the
posting is not signed, it will be kept for a limited period of time and then erased. If authenticated as admin,
the posting is signed by the node.
Create a new posting from the text given and publish it in the given feeds (if any). The heading and the
preview of the posting are created automatically, if needed. The posting owner must authenticate in some way.
If the posting is not signed, it will be kept for a limited period of time and then erased. If authenticated as
admin, the posting is signed by the node.
:param posting:
"""
Expand Down Expand Up @@ -1270,8 +1270,8 @@ def get_postings_attached_to_posting(self, id: str) -> List[types.PostingInfo]:

def get_posting_revisions(self, posting_id: str, limit: int | None = None) -> List[types.PostingRevisionInfo]:
"""
Get all revisions of the posting, but not more than ``limit``. The node may decide to return less revisions than
the given ``limit``.
Get all revisions of the posting, but not more than ``limit``. The node may decide to return less revisions
than the given ``limit``.
:param posting_id: ID of the posting
:param limit: maximum number of revisions returned
Expand Down Expand Up @@ -1317,8 +1317,8 @@ def create_posting_reaction(self, posting_id: str, reaction: types.ReactionDescr
"""
Add a reaction to the given posting. The reaction owner must authenticate in some way. Only one reaction is
allowed from each owner to a particular posting. If a reaction from the same owner to this posting already
exists, it is overwritten. If the reaction is not signed, the reaction will be kept for a limited period of time
and then erased (the previous reaction of the same owner will be restored, if any).
exists, it is overwritten. If the reaction is not signed, the reaction will be kept for a limited period of
time and then erased (the previous reaction of the same owner will be restored, if any).
:param posting_id: ID of the posting
:param reaction:
Expand All @@ -1335,9 +1335,9 @@ def get_posting_reactions_slice(
) -> types.ReactionsSliceInfo:
"""
Get a slice of the list of reactions to the given posting, optionally filtered by reaction type, delimited by
``before`` moment and the given ``limit``. If ``before`` is not provided, the latest reactions are returned. The
node may decide to return less reactions than the given ``limit``. The reactions are always sorted by moment,
descending.
``before`` moment and the given ``limit``. If ``before`` is not provided, the latest reactions are returned.
The node may decide to return less reactions than the given ``limit``. The reactions are always sorted by
moment, descending.
:param posting_id: ID of the posting
:param negative: ``True``, to filter negative reactions, ``False``, to filter positive ones
Expand Down Expand Up @@ -1463,8 +1463,8 @@ def get_profile(self, with_source: bool = False) -> types.ProfileInfo:

def update_profile(self, profile: types.ProfileAttributes) -> types.ProfileInfo:
"""
Update the profile. Fields that are not set in the request body are left intact. Fields that are set to an empty
value are reset to their defaults.
Update the profile. Fields that are not set in the request body are left intact. Fields that are set to an
empty value are reset to their defaults.
:param profile:
"""
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def search_subscriptions(self, filter: types.SubscriptionFilter) -> List[types.S
"""
location = "/people/subscriptions/search"
data = self.call(
"search_subscriptions", location, method="GET", body=filter, schema=schemas.SUBSCRIPTION_INFO_ARRAY_SCHEMA
"search_subscriptions", location, method="POST", body=filter, schema=schemas.SUBSCRIPTION_INFO_ARRAY_SCHEMA
)
return structure_list(data, types.SubscriptionInfo)

Expand Down
Loading

0 comments on commit d93b9f7

Please sign in to comment.