Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _provandfmts(self, text):
providers = list(registry.services.keys())
cmds = []
cmds.extend(providers)
cmds.extend(fmts)
if not text:
completions = cmds
else:
completions = [p for p in cmds if p.startswith(text)]
return completions
def parse_args(args):
"""Parse args from command line."""
service = None
api = None
fmt = None
isbn = get_canonical_isbn(canonical(clean(args[0])))
if len(args) == 1 and isbn:
return (isbn, service, fmt, api)
if isbn:
del args[0]
providers = list(registry.services.keys())
for a in args:
match = get_close_matches(a, fmts)
if len(match) == 1:
fmt = match[0]
args.remove(a)
break
for a in args:
match = get_close_matches(a, providers)
if len(match) == 1:
service = match[0]
args.remove(a)
break
api = args[0] if args else None
return (isbn, service, fmt, api)
def main():
sys.excepthook = quiet_errors
success = ren(sys.argv[1:]) if len(sys.argv) > 1 else False
if success:
return
providers = list(registry.services.keys())
if 'default' in providers:
providers.remove('default')
available = '|'.join(providers)
usage(available)
def parse_args(args):
"""Parse and return a tuple of the command line arguments."""
fn = args[-1]
service = None
key = None
isbn = None
pattern = None
if len(args) == 1:
return (isbn, service, key, pattern, fn)
isbn = get_canonical_isbn(canonical(clean(args[0])))
providers = list(registry.services.keys())
if isbn:
args.pop(0)
if args[0] != fn:
service = args[0]
match = get_close_matches(service, providers)
if len(match) == 1 and '{' not in args[0]: # <- rule out placeholders
service = match[0]
else:
service = None
pattern = args[0]
key = None if args[1] == fn else args[1]
if key and '{' in key:
pattern = key
key = None
if not args[1] == fn:
pattern = pattern if args[2] == fn else args[2]
fmtbib = lambda x, y: registry.bibformatters[x](y)
fmts = list(registry.bibformatters.keys())
def lscovers():
try:
cache = registry.covers_cache
for fp in cache.files():
if 'index' in fp:
continue
print(os.path.basename(fp))
except:
pass
goom, info, mask, meta, to_isbn10, to_isbn13, validate, version)
from .. import __version__
from ..app import CONF_PATH, get_canonical_isbn, registry
from ..contrib.modules.uxcolors import BOLD, RESET
CMDS = [
'audit', 'BIBFORMATS', 'conf', 'doi', 'doi2tex', 'ean13', 'editions',
'goom', 'info', 'mask', 'meta', 'from_words', 'PROVIDERS', 'shell',
'validate'
]
PREFIX = ''
PY2 = sys.version < '3'
WINDOWS = os.name == 'nt'
EOL = '\r\n' if WINDOWS and not PY2 else '\n'
fmts = list(registry.bibformatters.keys())
class ISBNRepl(cmd.Cmd):
"""REPL main class."""
# TODO refactor boilerplate, write a 'dispatcher'!
last_isbn = ''
last_isbn_ph = '#'
doc_header = 'Commands available (type ? to get help):'
intro = r'''
Welcome to the %sisbntools %s%s REPL.
** For help type 'help' or '?'
** To exit type 'exit' :)
** To run a shell command, type '!'
** Use '%s' in place of the last ISBN