Esempio n. 1
0
def generate_barcode(barcode_type, data, options=None):
    if barcode_type not in barcode_types:
        raise NotImplementedError('unsupported barcode type {!r}'.format(barcode_type))
    if options is None:
        options = {}
    code = _format_code(barcode_type, data, options)
    bbox_lines = _get_bbox(code)
    full_code = EPS_TEMPLATE.format(bbox=bbox_lines, bwipp=BWIPP, code=code)
    return EpsImagePlugin.EpsImageFile(io.BytesIO(full_code.encode('utf8')))
Esempio n. 2
0
def generate_barcode(
    barcode_type: str,
    data: str | bytes,
    options: dict[str, str | bool] | None = None,
) -> EpsImagePlugin.EpsImageFile:
    if barcode_type not in barcode_types:
        raise NotImplementedError(f"unsupported barcode type {barcode_type!r}")
    if options is None:
        options = {}
    code = _format_code(barcode_type, data, options)
    bbox_lines = _get_bbox(code)
    full_code = EPS_TEMPLATE.format(bbox=bbox_lines, bwipp=BWIPP, code=code)
    return EpsImagePlugin.EpsImageFile(io.BytesIO(full_code.encode()))
Esempio n. 3
0
def generate_barcode(barcode_type, data, options=None, template_options=None):
    if barcode_type not in barcode_types:
        raise NotImplementedError(
            "unsupported barcode type {!r}".format(barcode_type))
    if options is None:
        options = {}

    template_options_with_defaults = dict(scale_x=2, scale_y=2)
    if template_options is not None:
        template_options_with_defaults.update(template_options)
    code = _format_code(barcode_type, data, options)
    bbox_lines = _get_bbox(code, template_options_with_defaults)
    full_code = EPS_TEMPLATE.format(bbox=bbox_lines,
                                    bwipp=BWIPP,
                                    code=code,
                                    **template_options_with_defaults)
    return EpsImagePlugin.EpsImageFile(io.BytesIO(full_code.encode("utf8")))
Esempio n. 4
0
    def test_invalid_file(self):
        invalid_file = "Tests/images/flower.jpg"

        self.assertRaises(SyntaxError,
                          lambda: EpsImagePlugin.EpsImageFile(invalid_file))
Esempio n. 5
0
def test_invalid_file():
    invalid_file = "Tests/images/flower.jpg"

    with pytest.raises(SyntaxError):
        EpsImagePlugin.EpsImageFile(invalid_file)
Esempio n. 6
0
def generate_barcode(barcode_type, data, options):
    code = _format_code(barcode_type, data, options)
    bbox_lines = _get_bbox(code)
    full_code = EPS_TEMPLATE.format(bbox=bbox_lines, bwipp=BWIPP, code=code)
    return EpsImagePlugin.EpsImageFile(io.BytesIO(full_code.encode('utf8')))