Source code for api.lcp.utils
from core.lcp.exceptions import LCPError
[docs]def get_target_extension(input_extension):
if input_extension == '.epub':
target_extension = '.epub'
elif input_extension == '.pdf':
target_extension = '.lcpdf'
elif input_extension == '.lpf':
target_extension = ".audiobook"
elif input_extension == '.audiobook':
target_extension = ".audiobook"
else:
raise LCPError('Unknown extension "{0}"'.format(input_extension))
return target_extension
[docs]def bind_method(instance, func, as_name=None):
"""Bind the function *func* to *instance*, with either provided name *as_name*
or the existing name of *func*. The provided *func* should accept the
instance as the first argument, i.e. "self".
"""
if as_name is None:
as_name = func.__name__
bound_method = func.__get__(instance, instance.__class__)
setattr(instance, as_name, bound_method)
return bound_method