本文整理匯總了Python中qrcode.make方法的典型用法代碼示例。如果您正苦於以下問題:Python qrcode.make方法的具體用法?Python qrcode.make怎麽用?Python qrcode.make使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qrcode
的用法示例。
在下文中一共展示了qrcode.make方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _setup_view
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def _setup_view(request, next_page):
'''
Common logic to set up these views: make sure Django auth is done and check our conditions.
'''
if not next_page and 'next' in request.GET:
next_page = request.GET['next']
if not next_page:
next_page = get_redirect_url(request)
if not request.maybe_stale_user.is_authenticated:
# Not authenticated at all. Force standard-Django auth.
return next_page, False, False
good_auth, good_2fa = request.session_info.okay_auth(request, request.maybe_stale_user)
return next_page, good_auth, good_2fa
示例2: make_qr
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def make_qr(qr_data, img_name='qrcode', method='basic'):
if method == 'basic':
# Simple factory, just a set of rects.
factory = qrcode.image.svg.SvgImage
elif method == 'fragment':
# Fragment factory (also just a set of rects)
factory = qrcode.image.svg.SvgFragmentImage
elif method == 'path':
# Combined path factory, fixes white space that may occur when zooming
factory = qrcode.image.svg.SvgPathImage
# Set data to qrcode
img = qrcode.make(qr_data, image_factory = factory)
# Save svg file somewhere
filename = "static/"+img_name+".svg"
img.save(filename)
return filename
示例3: do_mfa_view
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def do_mfa_view():
if 'username' not in g.session:
return redirect('/user/login')
if libmfa.mfa_is_enabled(g.session['username']):
return render_template('mfa.disable.html')
else:
libmfa.mfa_reset_secret(g.session['username'])
secret = libmfa.mfa_get_secret(g.session['username'])
secret_url = pyotp.totp.TOTP(secret).provisioning_uri(g.session['username'], issuer_name="Vulpy")
img = qrcode.make(secret_url)
buffered = BytesIO()
img.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode()
return render_template('mfa.enable.html', secret_url=secret_url, img_str=img_str)
示例4: make_qr_data
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def make_qr_data(text):
qr_image = qrcode.make(
text, box_size=1, border=0,
error_correction=qrcode.ERROR_CORRECT_M)
qr_pet = []
print(qr_image.size)
for y in range(25):
for x in range(40):
pattern = (
get_pix(qr_image, x*2, y*2),
get_pix(qr_image, x*2+1, y*2),
get_pix(qr_image, x*2, y*2+1),
get_pix(qr_image, x*2+1, y*2+1),
)
p = charmap[pattern]
qr_pet.append(p)
return bytes(qr_pet)
示例5: qr_include_string
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def qr_include_string(match):
string = match.group(1)
try:
width = match.group(2)
assert width != 'None'
width = re.sub(r'^(.*)px', convert_pixels, width)
if width == "full":
width = '\\textwidth'
except:
width = DEFAULT_IMAGE_WIDTH
im = qrcode.make(string)
the_image = tempfile.NamedTemporaryFile(prefix="datemp", suffix=".png", delete=False)
#docassemble.base.functions.this_thread.temporary_resources.add(the_image.name)
im.save(the_image.name)
output = '\\mbox{\\includegraphics[width=' + width + ']{' + the_image.name + '}}'
if width == '\\textwidth':
output = '\\clearpage ' + output + '\\clearpage '
#logmessage("Output is " + output)
return(output)
示例6: qr_include_docx
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def qr_include_docx(match):
string = match.group(1)
try:
width = match.group(2)
assert width != 'None'
width = re.sub(r'^(.*)px', convert_pixels, width)
if width == "full":
width = '100%'
except:
width = DEFAULT_IMAGE_WIDTH
im = qrcode.make(string)
the_image = tempfile.NamedTemporaryFile(prefix="datemp", suffix=".png", delete=False)
#docassemble.base.functions.this_thread.temporary_resources.add(the_image.name)
im.save(the_image.name)
output = '![](' + the_image.name + '){width=' + width + '}'
return(output)
示例7: qrcode_view
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def qrcode_view(self, request, pk):
if settings.OTP_ADMIN_HIDE_SENSITIVE_DATA:
raise PermissionDenied()
device = TOTPDevice.objects.get(pk=pk)
if not self.has_view_or_change_permission(request, device):
raise PermissionDenied()
try:
import qrcode
import qrcode.image.svg
img = qrcode.make(device.config_url, image_factory=qrcode.image.svg.SvgImage)
response = HttpResponse(content_type='image/svg+xml')
img.save(response)
except ImportError:
response = HttpResponse('', status=503)
return response
示例8: qrcode_view
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def qrcode_view(self, request, pk):
if settings.OTP_ADMIN_HIDE_SENSITIVE_DATA:
raise PermissionDenied()
device = HOTPDevice.objects.get(pk=pk)
if not self.has_view_or_change_permission(request, device):
raise PermissionDenied()
try:
import qrcode
import qrcode.image.svg
img = qrcode.make(device.config_url, image_factory=qrcode.image.svg.SvgImage)
response = HttpResponse(content_type='image/svg+xml')
img.save(response)
except ImportError:
response = HttpResponse('', status=503)
return response
示例9: get_qr_img
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def get_qr_img(data):
for i in range(6, 1, -1):
time.sleep(1.0)
qr_img = qrcode.make(data, box_size=i)
log.info("Box Size: {}, Image Size: {}".format(i, qr_img.size[0]))
if qr_img.size[0] <= SCREEN_HEIGHT:
break
else:
raise Exception("none found")
return qr_img
示例10: main
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def main():
# make sure CTRL+C works
signal.signal(signal.SIGINT, signal.SIG_DFL)
description = """BlitzTUI - the Touch-User-Interface for the RaspiBlitz project
Keep on stacking SATs..! :-D"""
parser = argparse.ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
parser.add_argument("-V", "--version",
help="print version", action="version",
version=__version__)
parser.add_argument('-d', '--debug', help="enable debug logging", action="store_true")
# parse args
args = parser.parse_args()
if args.debug:
setup_logging(log_level="DEBUG")
else:
setup_logging()
log.info("Starting BlitzTUI v{}".format(__version__))
# initialize app
app = QApplication(sys.argv)
w = AppWindow()
w.show()
# run app
sys.exit(app.exec_())
示例11: add_topt
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def add_topt(request, next_page=None):
next_page, okay_auth, okay_2fa = _setup_view(request, next_page)
if not okay_auth:
return ForbiddenResponse(request)
# This enforces that users have exactly one TOTP. That *seems* like the best practice.
devices = TOTPDevice.objects.devices_for_user(request.maybe_stale_user, confirmed=True)
if devices:
return ForbiddenResponse(request, "You have already configured an authenticator with this account, and cannot add another. Contact %s if you are unable to authenticate with CourSys", (help_email(request),))
device = TOTPDevice(user=request.maybe_stale_user, name='Authenticator, enabled %s' % (datetime.date.today()))
device.save()
l = LogEntry(userid=request.user.username,
description=("Added TOPT from %s") % (ip.get_ip(request),),
related_object=device)
l.save()
# build QR code
uri = totpauth_url(device)
qr = qrcode.make(uri, image_factory=qrcode.image.svg.SvgPathImage)
qrdata = BytesIO()
qr.save(qrdata)
# This is the OTP secret (bits) encoded as base32, wrapped in an otpauth URL, encoded as a QR code, encoded as an
# SVG, encoded as base64, wrapped in a data URL. I'm strangely proud.
dataurl = (b'data:image/svg+xml;base64,' + base64.b64encode(qrdata.getvalue())).decode("utf-8")
context = {
'device': device,
'dataurl': dataurl,
'next_page': next_page,
}
return render(request, 'otp/add_topt.html', context)
示例12: generate_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def generate_qrcode(request, data):
img = qrcode.make(data)
buf = BytesIO()
img.save(buf)
image_stream = buf.getvalue()
response = HttpResponse(image_stream, content_type="image/png")
return response
示例13: inline_base64_qrcode
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def inline_base64_qrcode(address):
qr = qrcode.make("bitcoin:{0}".format(address), error_correction=qrcode.constants.ERROR_CORRECT_L)
output = io.BytesIO()
qr.save(output,'PNG')
output.seek(0)
qr_base64 = base64.b64encode(output.read()).decode()
return qr_base64
示例14: create_png
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def create_png(data, alt=None):
img = qrcode.make(data)
output = BytesIO()
img.save(output)
o_data = output.getvalue()
output.close()
return o_data
示例15: test_basic
# 需要導入模塊: import qrcode [as 別名]
# 或者: from qrcode import make [as 別名]
def test_basic(self):
qr = qrcode.QRCode(version=1)
qr.add_data('a')
qr.make(fit=False)