defget(name, code=None, writer=None, options=None):"""Helper method for getting a generator or even a generated code.
:param str name: The name of the type of barcode desired.
:param str code: The actual information to encode. If this parameter is
provided, a generated barcode is returned. Otherwise, the barcode class
is returned.
:param Writer writer: An alternative writer to use when generating the
barcode.
:param dict options: Aditional options to be passed on to the barcode when
generating.
"""# 注释翻译:# :param name:要使用的条形码类型的名称。# :param code:要编码到条形码中的数据。# :param writer:要使用的写入程序(例如:ImageWriter或SVGWriter)。# :param output:保存生成条形码的目标文件或路径。# :param writer_options:传递到writer实例的选项。# :param text:要在条形码下呈现的文本。
options = options or{}try:
barcode = __BARCODE_MAP[name.lower()]except KeyError:raise BarcodeNotFoundError("The barcode {!r} you requested is not known.".format(name))if code isnotNone:return barcode(code, writer,**options)else:return barcode
defget_class(name):return get_barcode(name)
get_barcode = get
get_barcode_class = get_class
# 理解:1、get_barcode_class实际调用的是get_class,而get_class由返回的是get_barcode,get_barcode由调用的get,所以实际还是get生成条形码
2、get_barcode_class()接受一个参数(条形码格式),返回的是get_barcode=get,所以get_barcode_class("ean13")== get("ean13")