本文整理汇总了Python中segno.make_qr函数的典型用法代码示例。如果您正苦于以下问题:Python make_qr函数的具体用法?Python make_qr怎么用?Python make_qr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_qr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_output2
def test_output2():
out = io.BytesIO()
segno.make_qr('Good Times', error='M').save(out, kind='png', scale=10, color='red')
f = tempfile.NamedTemporaryFile('w', suffix='.png', delete=False)
f.close()
cli.main(['-e=M', '--scale=10', '--color=red', '--output={0}'.format(f.name), 'Good', 'Times'])
f = open(f.name, 'rb')
content = f.read()
f.close()
os.unlink(f.name)
assert out.getvalue() == content
示例2: test_background_set
def test_background_set():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='pdf', background='yellow')
graphic = _find_graphic(out)
assert 'rg' in graphic
assert 're' in graphic
示例3: test_background_none
def test_background_none():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='pdf')
graphic = _find_graphic(out)
assert 'rg' not in graphic
assert 're' not in graphic
示例4: test_scale_float
def test_scale_float():
qr = segno.make_qr('test')
out = io.BytesIO()
scale = 1.34
scale_cmd = '{0} 0 0 {0} 0 0 cm'.format(scale)
qr.save(out, kind='pdf', scale=scale, compresslevel=0)
assert scale_cmd in _find_graphic(out)
示例5: test_default_scale
def test_default_scale():
qr = segno.make_qr('test')
out = io.BytesIO()
scale = 1
scale_cmd = '{0} 0 0 {0} 0 0 cm'.format(scale)
qr.save(out, kind='pdf', compresslevel=0)
assert scale_cmd not in _find_graphic(out)
示例6: test_data_svg_minimal_encoding
def test_data_svg_minimal_encoding():
qr = segno.make_qr('A')
val = qr.svg_data_uri(encode_minimal=True)
assert val
expected = "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='"
assert expected == val[:len(expected)]
assert val.endswith('%3C/svg%3E')
示例7: test_write_xpm_indicator
def test_write_xpm_indicator():
qr = segno.make_qr('test', error='m', boost_error=False)
out = io.StringIO()
qr.save(out, kind='xpm')
expected = '/* XPM */\n'
val = out.getvalue()
assert expected == val[:len(expected)]
示例8: test_no_line_class_empty_str
def test_no_line_class_empty_str():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='svg', lineclass='')
root = _parse_xml(out)
path_el = _get_path(root)
assert 'class' not in path_el.attrib
示例9: test_custom_svg_class
def test_custom_svg_class():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='svg', svgclass='test-class')
root = _parse_xml(out)
assert 'class' in root.attrib
assert 'test-class' == root.attrib.get('class')
示例10: create
def create(content, error='H', version=None, mode=None, encoding=None):
def translate_error(pyqrcode_error):
try:
if pyqrcode_error.upper() in ('L', 'M', 'Q', 'H'):
return pyqrcode_error
except AttributeError:
pass
try:
return _ERROR_LEVEL[pyqrcode_error]
except KeyError:
raise ValueError('Unknown error level "{0}"'.format(pyqrcode_error))
def translate_mode(pyqrcode_mode):
mode = pyqrcode_mode
try:
mode = pyqrcode_mode.lower()
except AttributeError:
pass
return mode if mode != 'binary' else 'byte'
return PyQRCode(segno.make_qr(content, error=translate_error(error),
version=version,
mode=translate_mode(mode),
encoding=encoding, boost_error=False),
content, encoding)
示例11: test_data_svg_no_charset
def test_data_svg_no_charset():
qr = segno.make_qr('A')
val = qr.svg_data_uri(omit_charset=True)
assert val
expected = "data:image/svg+xml,%3Csvg%20xmlns%3D%27"
assert expected == val[:len(expected)]
assert val.endswith('%3C%2Fsvg%3E')
示例12: test_svgid
def test_svgid():
qr = segno.make_qr('test')
out = io.BytesIO()
ident = 'svgid'
qr.save(out, kind='svg', svgid=ident)
root = _parse_xml(out)
assert 'id' in root.attrib
assert ident == root.attrib['id']
示例13: test_write_svg_background_rgba_svg2
def test_write_svg_background_rgba_svg2():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='svg', background='#0000ffcc', svgversion=2.0)
assert b'fill-opacity' not in out.getvalue()
root = _parse_xml(out)
path = _get_path(root)
assert path.attrib['fill'].startswith('rgba')
示例14: test_dpi
def test_dpi():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='png', dpi=300)
out.seek(0)
assert b'pHYs' in out.getvalue()
# pHYs 11811 (11811 meters = 300 dpi / 0.0254)
assert b'\x70\x48\x59\x73\x00\x00\x2E\x23\x00\x00\x2E\x23\x01\x78\xA5\x3F\x76' in out.getvalue()
示例15: test_write_txt
def test_write_txt():
# Test with default options
qr = segno.make_qr('test', error='m', boost_error=False)
out = io.StringIO()
qr.save(out, kind='txt', border=0)
expected = '11111110011'
val = out.getvalue()
assert expected == val[:len(expected)]