mirror of https://gitlab.com/bashrc2/epicyon
More efficient detection of non-empty strings
parent
a895212a04
commit
7b6eb5a414
|
@ -110,8 +110,7 @@ def _create_accept_reject(federation_list: [],
|
|||
'object': object_json
|
||||
}
|
||||
if cc_url:
|
||||
if len(cc_url) > 0:
|
||||
new_accept['cc'] = [cc_url]
|
||||
new_accept['cc'] = [cc_url]
|
||||
return new_accept
|
||||
|
||||
|
||||
|
|
|
@ -206,8 +206,7 @@ def create_announce(session, base_dir: str, federation_list: [],
|
|||
'type': 'Announce'
|
||||
}
|
||||
if cc_url:
|
||||
if len(cc_url) > 0:
|
||||
new_announce['cc'] = [cc_url]
|
||||
new_announce['cc'] = [cc_url]
|
||||
if save_to_file:
|
||||
outbox_dir = create_outbox_dir(nickname, domain, base_dir)
|
||||
filename = \
|
||||
|
|
|
@ -234,7 +234,7 @@ def post_login_screen(self, calling_domain: str, cookie: str,
|
|||
login_str += login_prm + '='
|
||||
else:
|
||||
len_str = login_prm.split('&')[0]
|
||||
if len(len_str) > 0:
|
||||
if len_str:
|
||||
login_str += login_prm + '*'
|
||||
len_str = ''
|
||||
if '&' in login_prm:
|
||||
|
|
3
like.py
3
like.py
|
@ -104,8 +104,7 @@ def _create_like(recent_posts_cache: {},
|
|||
'object': object_url
|
||||
}
|
||||
if cc_list:
|
||||
if len(cc_list) > 0:
|
||||
new_like_json['cc'] = cc_list
|
||||
new_like_json['cc'] = cc_list
|
||||
|
||||
# Extract the domain and nickname from a statuses link
|
||||
liked_post_nickname = None
|
||||
|
|
4
pgp.py
4
pgp.py
|
@ -917,7 +917,7 @@ def actor_to_vcard(actor: {}, domain: str, translate: {}) -> str:
|
|||
vcard_str += \
|
||||
'EXPERTISE;LEVEL=' + level_str + ':' + skill_name + '\n'
|
||||
if actor.get('hasOccupation'):
|
||||
if len(actor['hasOccupation']) > 0:
|
||||
if actor['hasOccupation']:
|
||||
if actor['hasOccupation'][0].get('name'):
|
||||
vcard_str += \
|
||||
'ROLE:' + \
|
||||
|
@ -1048,7 +1048,7 @@ def actor_to_vcard_xml(actor: {}, domain: str, translate: {}) -> str:
|
|||
'</parameters>' + \
|
||||
'<text>' + pgp_key_encoded + '</text></key>\n'
|
||||
if actor.get('hasOccupation'):
|
||||
if len(actor['hasOccupation']) > 0:
|
||||
if actor['hasOccupation']:
|
||||
if actor['hasOccupation'][0].get('name'):
|
||||
vcard_str += \
|
||||
' <role><text>' + \
|
||||
|
|
2
posts.py
2
posts.py
|
@ -5692,7 +5692,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
|||
print('EX: archive_posts_for_person unable to read ' +
|
||||
index_filename + ' ' + str(ex))
|
||||
# save the new index file
|
||||
if len(new_index) > 0:
|
||||
if new_index:
|
||||
try:
|
||||
with open(index_filename, 'w+',
|
||||
encoding='utf-8') as fp_index:
|
||||
|
|
|
@ -567,7 +567,7 @@ def prepend_base(base, iri):
|
|||
# directory from base
|
||||
if rel.path != '':
|
||||
path = path[0:path.rfind('/') + 1]
|
||||
if len(path) > 0 and not path.endswith('/'):
|
||||
if path and not path.endswith('/'):
|
||||
path += '/'
|
||||
path += rel.path
|
||||
|
||||
|
@ -779,7 +779,7 @@ class JsonLdProcessor(object):
|
|||
tmp = ctx
|
||||
ctx = []
|
||||
for v in tmp:
|
||||
if not _is_object(v) or len(v) > 0:
|
||||
if not _is_object(v) or v:
|
||||
ctx.append(v)
|
||||
|
||||
# remove array if only one context
|
||||
|
@ -1265,7 +1265,7 @@ class JsonLdProcessor(object):
|
|||
"""
|
||||
if property in subject:
|
||||
value = subject[property]
|
||||
return not _is_array(value) or len(value) > 0
|
||||
return not _is_array(value) or value
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -190,7 +190,7 @@ def get_instance_software(base_dir: str, session,
|
|||
nodeinfo_url = None
|
||||
if nodeinfo1_json.get('links'):
|
||||
if isinstance(nodeinfo1_json['links'], list):
|
||||
if len(nodeinfo1_json['links']) > 0:
|
||||
if nodeinfo1_json['links']:
|
||||
if nodeinfo1_json['links'][0].get('href'):
|
||||
href = nodeinfo1_json['links'][0]['href']
|
||||
if isinstance(href, str):
|
||||
|
|
|
@ -1336,12 +1336,13 @@ def html_profile(signing_priv_key_pem: str,
|
|||
with open(follow_requests_filename, 'r',
|
||||
encoding='utf-8') as fp_foll:
|
||||
for line in fp_foll:
|
||||
if len(line) > 0:
|
||||
follow_approvals = True
|
||||
followers_button = 'buttonhighlighted'
|
||||
if selected == 'followers':
|
||||
followers_button = 'buttonselectedhighlighted'
|
||||
break
|
||||
if not line:
|
||||
continue
|
||||
follow_approvals = True
|
||||
followers_button = 'buttonhighlighted'
|
||||
if selected == 'followers':
|
||||
followers_button = 'buttonselectedhighlighted'
|
||||
break
|
||||
except OSError as exc:
|
||||
print('EX: html_profile unable to read ' +
|
||||
follow_requests_filename + ' ' + str(exc))
|
||||
|
@ -1352,59 +1353,60 @@ def html_profile(signing_priv_key_pem: str,
|
|||
with open(follow_requests_filename, 'r',
|
||||
encoding='utf-8') as fp_req:
|
||||
for follower_handle in fp_req:
|
||||
if len(follower_handle) > 0:
|
||||
follower_handle = \
|
||||
remove_eol(follower_handle)
|
||||
if '://' in follower_handle:
|
||||
follower_actor = follower_handle
|
||||
else:
|
||||
nick = follower_handle.split('@')[0]
|
||||
dom = follower_handle.split('@')[1]
|
||||
follower_actor = \
|
||||
local_actor_url(http_prefix, nick, dom)
|
||||
if not follower_handle:
|
||||
continue
|
||||
follower_handle = \
|
||||
remove_eol(follower_handle)
|
||||
if '://' in follower_handle:
|
||||
follower_actor = follower_handle
|
||||
else:
|
||||
nick = follower_handle.split('@')[0]
|
||||
dom = follower_handle.split('@')[1]
|
||||
follower_actor = \
|
||||
local_actor_url(http_prefix, nick, dom)
|
||||
|
||||
# is this a new domain?
|
||||
# if so then append a new instance indicator
|
||||
follower_domain, _ = \
|
||||
get_domain_from_actor(follower_actor)
|
||||
new_follower_domain = ''
|
||||
if follower_domain not in curr_follower_domains:
|
||||
new_follower_domain = ' ✨'
|
||||
# is this a new domain?
|
||||
# if so then append a new instance indicator
|
||||
follower_domain, _ = \
|
||||
get_domain_from_actor(follower_actor)
|
||||
new_follower_domain = ''
|
||||
if follower_domain not in curr_follower_domains:
|
||||
new_follower_domain = ' ✨'
|
||||
|
||||
# Show the handle of the potential follower
|
||||
# being approved, linking to search on that handle
|
||||
base_path = '/users/' + nickname
|
||||
follow_approvals_section += \
|
||||
'<div class="container">\n' + \
|
||||
' <form method="POST" action="' + \
|
||||
base_path + '/searchhandle?page=1">\n' + \
|
||||
' <input type="hidden" ' + \
|
||||
'name="actor" value="' + actor + '">\n' + \
|
||||
' <input type="hidden" ' + \
|
||||
'name="searchtext" value="' + \
|
||||
follower_actor + \
|
||||
'">\n <button type="submit" ' + \
|
||||
'class="followApproveHandle" ' + \
|
||||
'name="submitSearch" tabindex="2">' + \
|
||||
follower_handle + new_follower_domain + \
|
||||
'</button>\n </form>\n'
|
||||
# Show the handle of the potential follower
|
||||
# being approved, linking to search on that handle
|
||||
base_path = '/users/' + nickname
|
||||
follow_approvals_section += \
|
||||
'<div class="container">\n' + \
|
||||
' <form method="POST" action="' + \
|
||||
base_path + '/searchhandle?page=1">\n' + \
|
||||
' <input type="hidden" ' + \
|
||||
'name="actor" value="' + actor + '">\n' + \
|
||||
' <input type="hidden" ' + \
|
||||
'name="searchtext" value="' + \
|
||||
follower_actor + \
|
||||
'">\n <button type="submit" ' + \
|
||||
'class="followApproveHandle" ' + \
|
||||
'name="submitSearch" tabindex="2">' + \
|
||||
follower_handle + new_follower_domain + \
|
||||
'</button>\n </form>\n'
|
||||
|
||||
# show Approve and Deny buttons
|
||||
follow_approvals_section += \
|
||||
'<a href="' + base_path + \
|
||||
'/followapprove=' + follower_handle + \
|
||||
'" tabindex="2">'
|
||||
follow_approvals_section += \
|
||||
'<button class="followApprove">' + \
|
||||
translate['Approve'] + '</button></a><br><br>'
|
||||
follow_approvals_section += \
|
||||
'<a href="' + base_path + \
|
||||
'/followdeny=' + follower_handle + \
|
||||
'" tabindex="3">'
|
||||
follow_approvals_section += \
|
||||
'<button class="followDeny">' + \
|
||||
translate['Deny'] + '</button></a>'
|
||||
follow_approvals_section += '</div>'
|
||||
# show Approve and Deny buttons
|
||||
follow_approvals_section += \
|
||||
'<a href="' + base_path + \
|
||||
'/followapprove=' + follower_handle + \
|
||||
'" tabindex="2">'
|
||||
follow_approvals_section += \
|
||||
'<button class="followApprove">' + \
|
||||
translate['Approve'] + '</button></a><br><br>'
|
||||
follow_approvals_section += \
|
||||
'<a href="' + base_path + \
|
||||
'/followdeny=' + follower_handle + \
|
||||
'" tabindex="3">'
|
||||
follow_approvals_section += \
|
||||
'<button class="followDeny">' + \
|
||||
translate['Deny'] + '</button></a>'
|
||||
follow_approvals_section += '</div>'
|
||||
|
||||
profile_description_short = \
|
||||
_get_profile_short_description(profile_description)
|
||||
|
@ -1950,7 +1952,7 @@ def _html_profile_roles(translate: {}, nickname: str, domain: str,
|
|||
else:
|
||||
profile_str += '<h3>' + role + '</h3>\n'
|
||||
profile_str += '</div></div>\n'
|
||||
if len(profile_str) == 0:
|
||||
if not profile_str:
|
||||
profile_str += \
|
||||
'<p>@' + nickname + '@' + domain + ' has no roles assigned</p>\n'
|
||||
else:
|
||||
|
@ -1967,7 +1969,7 @@ def _html_profile_skills(skills_json: {}) -> str:
|
|||
'<div>' + skill + \
|
||||
'<br><div id="myProgress"><div id="myBar" style="width:' + \
|
||||
str(level) + '%"></div></div></div>\n<br>\n'
|
||||
if len(profile_str) > 0:
|
||||
if profile_str:
|
||||
profile_str = '<center><div class="skill-title">' + \
|
||||
profile_str + '</div></center>\n'
|
||||
return profile_str
|
||||
|
@ -1984,7 +1986,7 @@ def _html_profile_shares(actor: str, translate: {},
|
|||
actor, item, translate,
|
||||
False, False,
|
||||
shares_file_type)
|
||||
if len(profile_str) > 0:
|
||||
if profile_str:
|
||||
profile_str = '<div class="share-title">' + profile_str + '</div>\n'
|
||||
return profile_str
|
||||
|
||||
|
|
|
@ -707,20 +707,21 @@ def html_timeline(default_timeline: str,
|
|||
with open(follow_requests_filename, 'r',
|
||||
encoding='utf-8') as fp_foll:
|
||||
for line in fp_foll:
|
||||
if len(line) > 0:
|
||||
# show follow approvals icon
|
||||
follow_approvals = \
|
||||
'<a href="' + users_path + \
|
||||
'/followers#buttonheader" ' + \
|
||||
'accesskey="' + \
|
||||
access_keys['followButton'] + '">' + \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timelineicon" alt="' + \
|
||||
translate['Approve follow requests'] + \
|
||||
'" title="' + \
|
||||
translate['Approve follow requests'] + \
|
||||
'" src="/icons/person.png"/></a>\n'
|
||||
break
|
||||
if not line:
|
||||
continue
|
||||
# show follow approvals icon
|
||||
follow_approvals = \
|
||||
'<a href="' + users_path + \
|
||||
'/followers#buttonheader" ' + \
|
||||
'accesskey="' + \
|
||||
access_keys['followButton'] + '">' + \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timelineicon" alt="' + \
|
||||
translate['Approve follow requests'] + \
|
||||
'" title="' + \
|
||||
translate['Approve follow requests'] + \
|
||||
'" src="/icons/person.png"/></a>\n'
|
||||
break
|
||||
except OSError:
|
||||
print('EX: html_timeline unable to read ' +
|
||||
follow_requests_filename)
|
||||
|
|
|
@ -1457,7 +1457,7 @@ def get_post_attachments_as_html(base_dir: str,
|
|||
media_creator = attach['schema:creator']
|
||||
elif attach.get('attribution'):
|
||||
if isinstance(attach['attribution'], list):
|
||||
if len(attach['attribution']) > 0:
|
||||
if attach['attribution']:
|
||||
attrib_str = attach['attribution'][0]
|
||||
if not dangerous_markup(attrib_str, False, []):
|
||||
if not is_filtered(base_dir, nickname, domain,
|
||||
|
|
Loading…
Reference in New Issue