Substitute append(), extend() with concatenation
This commit is contained in:
parent
84df17ee38
commit
ba5a81084a
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -29,6 +29,8 @@ This is more important than your design or code! Users check this first.
|
||||
- *Single quote, single quote, single all the way!*
|
||||
- A single line should be less than 80 chars in length.
|
||||
- No trailing whitespaces.
|
||||
- Avoid append(), extend() and use concatenation if possible.
|
||||
- Use string concatenation than substitution if possible, except (logger) prints.
|
||||
- Add new API documentation, reasonable code comments.
|
||||
- If possible, add test cases for your new API under `tests/`. We are Travis integrated.
|
||||
- If possible, squash everything to a single commit.
|
||||
|
29
buku.py
29
buku.py
@ -2244,33 +2244,32 @@ def to_temp_file_content(url, title_in, tags_in, desc):
|
||||
:return: lines as newline separated string
|
||||
'''
|
||||
|
||||
strings = []
|
||||
strings = [('# Lines beginning with "#" will be stripped.\n'
|
||||
'# Add URL in next line (single line).'), ]
|
||||
|
||||
# URL
|
||||
strings.extend(['# Lines beginning with "#" will be stripped.\n\
|
||||
# Add URL in next line (single line).', ])
|
||||
if url is not None:
|
||||
strings.append(url)
|
||||
strings += (url,)
|
||||
|
||||
# TITLE
|
||||
strings.extend(['# Add TITLE in next line (single line). \
|
||||
Leave blank to web fetch, "-" for no title.'])
|
||||
strings += (('# Add TITLE in next line (single line). '
|
||||
'Leave blank to web fetch, "-" for no title.'),)
|
||||
if title_in is None:
|
||||
title_in = ''
|
||||
elif title_in == '':
|
||||
title_in = '-'
|
||||
strings.append(title_in)
|
||||
strings += (title_in,)
|
||||
|
||||
# TAGS
|
||||
strings.extend(['# Add comma-separated TAGS in next line (single line).'])
|
||||
strings.append(tags_in.strip(DELIM) if not None else '')
|
||||
strings += ('# Add comma-separated TAGS in next line (single line).',)
|
||||
strings += (tags_in.strip(DELIM),) if not None else ''
|
||||
|
||||
# DESC
|
||||
strings.append('# Add COMMENTS in next line(s).')
|
||||
strings += ('# Add COMMENTS in next line(s).',)
|
||||
if desc is not None and desc != '':
|
||||
strings.append(desc)
|
||||
strings += (desc,)
|
||||
else:
|
||||
strings.append('\n')
|
||||
strings += ('\n',)
|
||||
return '\n'.join(strings)
|
||||
|
||||
|
||||
@ -2349,7 +2348,7 @@ def edit_rec(editor, url, title_in, tags_in, desc):
|
||||
logdbg('Edited content written to %s', tmpfile)
|
||||
|
||||
cmd = editor.split(' ')
|
||||
cmd.append(tmpfile)
|
||||
cmd += (tmpfile,)
|
||||
subprocess.call(cmd)
|
||||
|
||||
with open(tmpfile, 'r', encoding='utf-8') as f:
|
||||
@ -2404,9 +2403,9 @@ def setup_logger(logger):
|
||||
# Handle piped input
|
||||
def piped_input(argv, pipeargs=None):
|
||||
if not sys.stdin.isatty():
|
||||
pipeargs.extend(argv)
|
||||
pipeargs += argv
|
||||
for s in sys.stdin.readlines():
|
||||
pipeargs.extend(s.split())
|
||||
pipeargs += s.split()
|
||||
|
||||
|
||||
# main starts here
|
||||
|
Loading…
Reference in New Issue
Block a user