python类make()的实例源码

__init__.py 文件源码 项目:RoboLCD 作者: victorevector 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _write_qr_to_file(self, api_key):
        folder = self.get_plugin_data_folder()
        img = qrcode.make(api_key)
        img.save('{}/{}'.format(folder, 'qr_code.png'))
test9.py 文件源码 项目:python_learn 作者: jetty-guo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_QR():
    img = qrcode.make(
        'hello, qrcode111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111')
    img.save(pic_url)
models.py 文件源码 项目:lenuage 作者: laboiteproject 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def generate_qrcode(self):
        url = 'http://'
        url += str(Site.objects.get_current())
        url += '/boites/redirect/'
        url += str(self.api_key)
        img = qrcode.make(url)

        buffer = BytesIO()
        img.save(buffer)

        filename = 'qrcode-%s.png' % str(self.api_key)
        filebuffer = InMemoryUploadedFile(buffer, None, filename,
                                          'image/png', len(buffer.getvalue()), None)
        self.qrcode.save(filename, filebuffer)
qr.py 文件源码 项目:xf 作者: red-green 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def generate():
    txt = raw_input('text to encode> ')
    path = raw_input('path to write out file to (include an extension)> ').strip()
    img = qrcode.make(txt)
    img.save(path)
Qrcode.py 文件源码 项目:Wox.Plugin.Py.Qrcode 作者: ousui 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _genBarcode(self, content):
        md5 = hashlib.md5(bytes(content, 'utf-8')).hexdigest()
        path = os.path.join(PKG_DIR, 'images', 'qrcodes', '{}.png'.format(md5))
        # ??????md5????????????????????
        if os.path.isfile(path):
            return path
        qrcode.make(content).save(path)
        return path
__init__.py 文件源码 项目:king-phisher-plugins 作者: securestate 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def enrollment_remove(self, _):
        rpc = self.application.rpc
        this_user = rpc.remote_table_row('users', rpc.username)
        if this_user.otp_secret is None:
            gui_utilities.show_dialog_info(
                'Not Enrolled',
                self.application.get_active_window(),
                'This account is not currently enrolled in two factor\n'\
                + 'authentication. There are no changes to make.'
            )
            return
        remove = gui_utilities.show_dialog_yes_no(
            'Already Enrolled',
            self.application.get_active_window(),
            'Are you sure you want to unenroll in TOTP? This will remove\n'\
            + 'two factor authentication on your account.'
        )
        if not remove:
            return
        this_user.otp_secret = None
        this_user.commit()
        gui_utilities.show_dialog_info(
            'TOTP Unenrollment',
            self.application.get_active_window(),
            'Successfully removed the TOTP secret. Your account is now unenrolled\n'\
            + 'in two factor authentication. You will no longer be prompted to enter\n'\
            + 'the value when you login.'
        )
__init__.py 文件源码 项目:king-phisher-plugins 作者: securestate 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def enrollment_setup(self, _):
        rpc = self.application.rpc
        this_user = rpc.remote_table_row('users', rpc.username)
        if this_user.otp_secret is not None:
            reset = gui_utilities.show_dialog_yes_no(
                'Already Enrolled',
                self.application.get_active_window(),
                'This account is already enrolled in TOTP,\nreset the existing TOTP token?'
            )
            if not reset:
                return
        new_otp = pyotp.TOTP(pyotp.random_base32())
        provisioning_uri = rpc.username + '@' + self.application.config['server'].split(':', 1)[0]
        provisioning_uri = new_otp.provisioning_uri(provisioning_uri) + '&issuer=King%20Phisher'
        bytes_io = io.BytesIO()
        qrcode_ = qrcode.make(provisioning_uri).get_image()
        qrcode_.save(bytes_io, 'PNG')
        pixbuf_loader = GdkPixbuf.PixbufLoader.new()
        pixbuf_loader.write(bytes_io.getvalue())
        pixbuf_loader.close()
        pixbuf = pixbuf_loader.get_pixbuf()

        self.logger.debug('loading gtk builder file from: ' + gtk_builder_file)
        builder = Gtk.Builder()
        builder.add_from_file(gtk_builder_file)
        window = builder.get_object('TOTPEnrollment.window')
        window.set_transient_for(self.application.get_active_window())

        self.application.add_window(window)

        image = builder.get_object('TOTPEnrollment.image_qrcode')
        image.set_from_pixbuf(pixbuf)

        button_check = builder.get_object('TOTPEnrollment.button_check')
        entry_totp = builder.get_object('TOTPEnrollment.entry_totp')
        button_check.connect('clicked', self.check_totp, window, entry_totp, new_otp, this_user)
        entry_totp.connect('activate', self.check_totp, window, entry_totp, new_otp, this_user)

        window.show_all()
views.py 文件源码 项目:bctip 作者: norn 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def qrcode_view(request, key):
    wallet = get_object_or_404(Wallet, key=key)
    img = qrcode.make(
        wallet.bcaddr_uri, box_size=6, error_correction=qrcode.ERROR_CORRECT_M)
    output = StringIO.StringIO()
    img.save(output, "PNG")
    c = output.getvalue()
    return HttpResponse(c, content_type="image/png")
tasks.py 文件源码 项目:bctip 作者: norn 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def qrcode_img(text):
    img = qrcode.make(text, box_size=2, error_correction=qrcode.ERROR_CORRECT_M)
    output = StringIO.StringIO()
    img.save(output, "PNG")
    c = output.getvalue()
    return c
pyzcto.py 文件源码 项目:pyzcto 作者: miguelmarco 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def showzcpqr(self):
        fd = open('./hidden_service/hostname')
        oniondom = fd.readline().split()[0]
        fd.close()
        username = str(self.line_user.text())
        password = str(self.line_password.text())
        img = qrcode.make(username+':'+password+'@'+oniondom)
        img.save('qrcode.png', 'PNG')
        qrc = QPixmap('qrcode.png')
        os.remove('qrcode.png')
        self.onionlabelname.setText(username+':'+password+'@'+oniondom)
        self.onionlabelname.show()
        self.onionlabel.setPixmap(qrc.scaled(self.onionlabel.size(), Qt.KeepAspectRatio))
        self.onionlabel.show()
pyzcto.py 文件源码 项目:pyzcto 作者: miguelmarco 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def showorbotqr(self):
        fd = open('./hidden_service/hostname')
        line = fd.readline()
        oniondom =line.split()[0]
        cookie = line.split()[1]
        fd.close()
        jsonstring = '{'+'"auth_cookie_value": "{}", "domain":"{}"'.format(cookie, oniondom)+'}'
        img = qrcode.make(jsonstring)
        img.save('qrcode.png', 'PNG')
        qrc = QPixmap('qrcode.png')
        os.remove('qrcode.png')
        self.onionlabelname.setText(jsonstring)
        self.onionlabelname.show()
        self.onionlabel.setPixmap(qrc.scaled(self.onionlabel.size(), Qt.KeepAspectRatio))
        self.onionlabel.show()
pyzcto.py 文件源码 项目:pyzcto 作者: miguelmarco 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def geneartereceiveqr(self):
        try:
            address = self.receiveaddresses[self.listaddresses_receive.currentIndex().row()]
        except:
            address = ''
        amount = self.line_receiveamount.text()
        comment = self.line_receivedesc.text()
        if address and amount:
            if comment:
                try:
                    string = 'zcash:{}?amount={}&message={}'.format(address,amount,comment)
                except:
                    self.label_qrreceive.hide()
                    self.label_textreceive.hide()
                    return
            else:
                string = 'zcash:{}?amount={}'.format(address,amount)
            img = qrcode.make(string)
            img.save('qrcode.png', 'PNG')
            qrc = QPixmap('qrcode.png')
            os.remove('qrcode.png')
            self.label_textreceive.setText(string)
            self.label_textreceive.show()
            self.label_qrreceive.setPixmap(qrc.scaled(self.onionlabel.size(), Qt.KeepAspectRatio))
            self.label_qrreceive.show()
        else:
            self.label_qrreceive.hide()
            self.label_textreceive.hide()
handlers.py 文件源码 项目:qrcode_track 作者: flingjie 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def post(self):
        name = self.request.arguments.get('name')[0]
        post_type = self.request.arguments.get('type')[0]
        if int(post_type) == LINK_TYPE:
            data = self.request.arguments.get('info')[0]
            url = add_http(data.decode("utf-8"))
        else:
            b64img = self.request.arguments.get('image')[0]
            img = BytesIO(base64.b64decode(b64img))
            scanner = zbar.ImageScanner()
            scanner.parse_config('enable')
            pil = Image.open(img).convert('L')
            width, height = pil.size
            raw = pil.tobytes()
            image = zbar.Image(width, height, 'Y800', raw)
            scanner.scan(image)
            for symbol in image:
                url = add_http(symbol.data)

        cur_user = self.get_current_user()
        if cur_user:
            users = self.db[USER_COLLECTION]
            users.update({'phone': cur_user['phone']}, {'$addToSet': {'qrcode': url}})
        stat_col = self.db[STATISTIC_COLLECTION]
        if not stat_col.find_one({'url': url}):
            stat_col.insert({
                'name': name,
                'url': url,
                'visit': []
            })
        else:
            stat_col.update({'url': url}, {"$set": {'name': name}})
        img = qrcode.make(gen_new_url(url))
        o = BytesIO()
        img.save(o, "JPEG")
        s = base64.b64encode(o.getvalue())

        img = qrcode.make(gen_statistic_url(url))
        o = BytesIO()
        img.save(o, "JPEG")
        s2 = base64.b64encode(o.getvalue())

        self.write({
            "qrcode": s.decode('utf-8'),
            "statistic": s2.decode('utf-8')
        })
health_qrcodes.py 文件源码 项目:health-mosconi 作者: GNUHealth-Mosconi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def make_qrcode(self, name):
    # Create the QR code

        patient_puid = self.puid or ''

        patient_blood_type = self.blood_type or ''

        patient_rh = self.rh or ''

        patient_gender = self.gender or ''

        patient_dob = self.dob or ''

        patient_id = self.puid or ''

        if self.lastname:
            patient_lastname = self.lastname + ', '
        else:
            patient_lastname = ''

        qr_string = 'ID: ' + patient_id \
            + '\nName: ' + patient_lastname + ',' \
                + self.name.name \
            + '\nPUID: ' + patient_puid \
            + '\nGender: ' + patient_gender \
            + '\nDoB: ' + str(patient_dob) \
            + '\nBlood Type: ' + patient_blood_type \
                + ' ' + patient_rh


        qr_image = qrcode.make(qr_string)

        # Make a PNG image from PIL without the need to create a temp file

        holder = StringIO.StringIO()
        qr_image.save(holder)
        qr_png = holder.getvalue()
        holder.close()

        return bytearray(qr_png)

# Add the QR code field and image to the Newborn
health_qrcodes.py 文件源码 项目:health-mosconi 作者: GNUHealth-Mosconi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def make_qrcode(self, name):
    # Create the QR code

        if self.mother:
            if self.mother.name.lastname:
                newborn_mother_lastname = self.mother.name.lastname + ', '
            else:
                newborn_mother_lastname = ''

            newborn_mother_name = self.mother.name.name or ''

            newborn_mother_id = self.mother.puid or ''

        else:
            newborn_mother_lastname = ''
            newborn_mother_name = ''
            newborn_mother_id = ''

        newborn_name = self.name or ''

        newborn_sex = self.sex or ''

        newborn_birth_date = self.birth_date or ''

        qr_string = 'PUID: ' + newborn_name \
            + '\nMother: ' + newborn_mother_lastname \
                    + newborn_mother_name \
            + '\nMother\'s PUID: ' + newborn_mother_id \
            + '\nSex: ' + newborn_sex \
            + '\nDoB: ' + str(newborn_birth_date)


        qr_image = qrcode.make(qr_string)

        # Make a PNG image from PIL without the need to create a temp file

        holder = StringIO.StringIO()
        qr_image.save(holder)
        qr_png = holder.getvalue()
        holder.close()

        return bytearray(qr_png)
views.py 文件源码 项目:SpongeAuth 作者: lukegb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setup_totp(request):
    if twofa.models.TOTPDevice.objects.active_for_user(request.user).exists():
        messages.error(request, _('You may not have multiple Google Authenticators attached to your account.'))
        return redirect('twofa:list')

    setup_signer = TimestampSigner('twofa.views.setup_totp:{}'.format(request.user.pk))

    if request.method == 'POST' and 'secret' in request.POST:
        try:
            b32_secret = setup_signer.unsign(request.POST['secret'], max_age=600)
        except SignatureExpired:
            messages.error(request, _('That took too long and your challenge expired. Here\'s a new one.'))
            return redirect('twofa:setup-totp')
        except BadSignature:
            messages.error(request, _('Whoops - something went wrong. Please try again.'))
            return redirect('twofa:setup-totp')
    else:
        b32_secret = base64.b32encode(secrets.token_bytes(10))
    signed_secret = setup_signer.sign(b32_secret)

    url = 'otpauth://totp/Sponge:{}?{}'.format(
        urlquote(request.user.username),
        urlencode({
            'secret': b32_secret,
            'issuer': 'Sponge'}))
    img = qrcode.make(url, image_factory=qrcode.image.svg.SvgPathFillImage)
    img_buf = io.BytesIO()
    img.save(img_buf)

    device = twofa.models.TOTPDevice(base32_secret=b32_secret, owner=request.user)
    device.activated_at = timezone.now()  # this won't be saved unless the form is valid
    form = device.verify_form(secret=signed_secret)
    if request.method == 'POST':
        form = device.verify_form(request.POST, secret=signed_secret)

        if form.is_valid():
            # relying on verify_form to save the new device
            request.user.twofa_enabled = True
            request.user.save()

            messages.success(request, _('Your authenticator has been added to your account.'))
            return _generate_paper_codes_if_needed(request.user, reverse('twofa:list'))

    return render(request, 'twofa/setup/totp.html', {
        'form': form, 'qr_code_svg': img_buf.getvalue(), 'b32_secret': b32_secret})
health_qrcodes.py 文件源码 项目:gnuhealth-live 作者: kret0s 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def make_qrcode(self, name):
    # Create the QR code

        patient_puid = self.puid or ''

        patient_blood_type = self.blood_type or ''

        patient_rh = self.rh or ''

        patient_gender = self.gender or ''

        patient_dob = self.dob or ''

        patient_id = self.puid or ''

        if self.lastname:
            patient_lastname = self.lastname + ', '
        else:
            patient_lastname = ''

        qr_string = 'ID: ' + patient_id \
            + '\nName: ' + patient_lastname + ',' \
                + self.name.name \
            + '\nPUID: ' + patient_puid \
            + '\nGender: ' + patient_gender \
            + '\nDoB: ' + str(patient_dob) \
            + '\nBlood Type: ' + patient_blood_type \
                + ' ' + patient_rh


        qr_image = qrcode.make(qr_string)

        # Make a PNG image from PIL without the need to create a temp file

        holder = StringIO.StringIO()
        qr_image.save(holder)
        qr_png = holder.getvalue()
        holder.close()

        return bytearray(qr_png)

# Add the QR code field and image to the Newborn
health_qrcodes.py 文件源码 项目:gnuhealth-live 作者: kret0s 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_qrcode(self, name):
    # Create the QR code

        if self.mother:
            if self.mother.name.lastname:
                newborn_mother_lastname = self.mother.name.lastname + ', '
            else:
                newborn_mother_lastname = ''

            newborn_mother_name = self.mother.name.name or ''

            newborn_mother_id = self.mother.puid or ''

        else:
            newborn_mother_lastname = ''
            newborn_mother_name = ''
            newborn_mother_id = ''

        newborn_name = self.name or ''

        newborn_sex = self.sex or ''

        newborn_birth_date = self.birth_date or ''

        qr_string = 'PUID: ' + newborn_name \
            + '\nMother: ' + newborn_mother_lastname \
                    + newborn_mother_name \
            + '\nMother\'s PUID: ' + newborn_mother_id \
            + '\nSex: ' + newborn_sex \
            + '\nDoB: ' + str(newborn_birth_date)


        qr_image = qrcode.make(qr_string)

        # Make a PNG image from PIL without the need to create a temp file

        holder = StringIO.StringIO()
        qr_image.save(holder)
        qr_png = holder.getvalue()
        holder.close()

        return bytearray(qr_png)
wallet.py 文件源码 项目:bitcoin_tools 作者: sr-gi 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def sk_to_wif(sk, compressed=True, mode='image', v='test'):
    """ Generates a Wallet Import Format (WIF) representation of a provided elliptic curve private key.

    :param sk: elliptic curve private key.
    :type sk: hex str
    :param compressed: Whether the WIF will be used with a compressed or uncompressed public key
    :type compressed: bool
    :param mode: defines the type of return.
    :type mode: str
    :param v: version (prefix) used to calculate the WIF, it depends on the type of network.
    :type v: str
    :return: The WIF representation of the private key.

        - main network WIF if v is 'main'.
        - testnet WIF otherwise.
    :rtype:

        - qrcode is mode is 'image'.
        - str otherwise.
    """

    # Choose the proper version depending on the provided 'v'.
    if v in ['mainnet', 'main']:
        v = WIF
    elif v in ['testnet', 'test']:
        v = TESTNET_WIF
    else:
        raise Exception("Invalid version, use either 'main' or 'test'.")

    # Add the network version leading the private key (in hex).
    e_pkey = chr(v) + unhexlify(sk)
    # Flag compressed pk when needed
    if compressed:
        e_pkey += unhexlify('01')
    # Double sha256.
    h = sha256(sha256(e_pkey).digest()).digest()
    # Add the two first bytes of the result as a checksum tailing the encoded key.
    wif = e_pkey + h[0:4]
    # Enconde the result in base58.
    wif = b58encode(wif)

    # Choose the proper return mode depending on 'mode'.
    if mode is 'image':
        response = qr_make(wif)
    elif mode is 'text':
        response = wif
    else:
        raise Exception("Invalid mode, used either 'image' or 'text'.")

    return response


问题


面经


文章

微信
公众号

扫码关注公众号