Esempio n. 1
0
def qrcode(req, width):
    import qr

    url = req.GET.get('url')
    if url is None:
        raise Http404

    try:
        data = url.encode('ascii')
    except UnicodeError:
        # only supports URLs properly urlencoded
        raise Http404

    if width == "480":
        magnify = 8
    else:
        magnify = 4

    buf = StringIO()
    try:
        qr.qrcode(data, buf, format=qr.GIF, magnify=magnify)
    except ValueError:
        # qr module wasn't be compiled with GD library
        raise Http404

    content = buf.getvalue()

    CACHE_TIMEOUT = 86400
    res = HttpResponse(content, content_type='image/gif')
    res['Content-Length'] = str(len(content))
    res['ETag']           = '"%s"' % md5(content).hexdigest()
    res['Last-Modified']  = http_date()
    res['Expires'] = http_date(time.time() + CACHE_TIMEOUT)
    patch_cache_control(res, max_age=CACHE_TIMEOUT)
    return res
Esempio n. 2
0
def qrcode(req, width):
    import qr

    url = req.GET.get('url')
    if url is None:
        raise Http404

    try:
        data = url.encode('ascii')
    except UnicodeError:
        # only supports URLs properly urlencoded
        raise Http404

    if width == "480":
        magnify = 8
    else:
        magnify = 4

    buf = StringIO()
    try:
        qr.qrcode(data, buf, format=qr.GIF, magnify=magnify)
    except ValueError:
        # qr module wasn't be compiled with GD library
        raise Http404

    content = buf.getvalue()

    CACHE_TIMEOUT = 86400
    res = HttpResponse(content, content_type='image/gif')
    res['Content-Length'] = str(len(content))
    res['ETag'] = '"%s"' % md5(content).hexdigest()
    res['Last-Modified'] = http_date()
    res['Expires'] = http_date(time.time() + CACHE_TIMEOUT)
    patch_cache_control(res, max_age=CACHE_TIMEOUT)
    return res
Esempio n. 3
0
 def test3(self):
     ''' This test is to ensure that an alphanumeric message is recognised
     
     '''
     msg = 'hi'
     self.block = qrcode (msg = msg)
     assert (self.block.msgtype == 1)# test 3 fails, alphanumeric message in not recongised
Esempio n. 4
0
 def test2(self):
     '''This test is to make sure that a block can regognise what type of data it is handling
     
     '''
     msg = 0
     self.block = qrcode (msg = msg)
     assert (self.block.msgtype == 0)#test 2 fails, numeric message is not recognised
Esempio n. 5
0
 def test1(self):
     with open('sizetestData.txt', 'w') as ofile:
         msg = ''
         self.ver = 0
         while self.ver<40:
             msg = msg + random.choice(self.letters)
             code = qrcode(msg = msg)
             if self.ver < code.size:
                 ofile.write('msg of length {0} generates a version {1} code \n'.format(len(msg),code.size))
                 self.ver = code.size
Esempio n. 6
0
def get_qr_layout(txt):
    digitqr = qr.qrcode(txt, format=qr.FMT_DIGIT, scale=1, separator=1)

    cnt = 0
    pc = None
    lst = digitqr.split(' ')
    lines = []
    global LINE_WIDTH
    LINE_WIDTH = len(lst)
    for row in lst:
        line = []
        for c in row:
            if c != pc:
                if pc:
                    line.append((int(pc), cnt))
                cnt = 0
            cnt += 1
            pc = c

        if cnt:
            line.append((int(pc), cnt))
            lines.append(line)
            cnt = 0
    return lines
Esempio n. 7
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr, cStringIO
from PIL import Image

buf = cStringIO.StringIO()
qr.qrcode('spam, egg', buf, format=qr.BMP, magnify=2)
buf.seek(0)
Image.open(buf).save('spam.png', 'PNG')
Esempio n. 8
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

f = open('spam' + qr.extension(qr.SVG), 'wb')
f.write(qr.qrcode('spam, egg', format=qr.SVG, separator=0))
f.close()
Esempio n. 9
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

qr.qrcode("spam, egg", open("spam" + qr.extension(qr.JSON), "w"), format=qr.JSON, separator=0)
Esempio n. 10
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import print_function
import qr

print('Content-Type: ' + qr.mimetype(qr.FMT_ASCII))
print(qr.qrcode('spam, egg', format=qr.FMT_ASCII))
Esempio n. 11
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

f = open('spam.png', 'w')
f.write(qr.qrcode('spam, egg', format = qr.FMT_PNG, magnify = 2))
f.close()
Esempio n. 12
0
 def test1(self):
     ''' This test checks that a qrcode object can be made
     '''
 
     self.block = qrcode( msg = 'hello', quality = 'M')
     assert(str(self.block) =='hello') #Test 1 fails - qr object not created, and does not have correct string representation.
Esempio n. 13
0
 def test5(self):
     ''' simple integrity test for the list of block sizes'''
     self.block = qrcode(msg = '0')
     numberOfVersions = 40
     assert (len(self.block.sizeList)==numberOfVersions)#test5 fails - data items not correct
Esempio n. 14
0
 def test4(self):
     '''This test checks that the version number chosen for a very short messgae in 1'''
     msg = 123
     expver = 1
     self.block = qrcode(msg = msg)
     assert (self.block.size == expver)#Test 4 fails, short message version not 1
Esempio n. 15
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

print('Content-Type: ' + qr.mimetype(qr.FMT_ASCII))
print(qr.qrcode('spam, egg', format = qr.FMT_ASCII))
Esempio n. 16
0
File: png.py Progetto: zmm20/qrcode
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

f = open('spam.png', 'wb')
f.write(qr.qrcode('spam, egg. spam, egg', format = qr.FMT_PNG, scale = 8))
f.close()
Esempio n. 17
0
File: svg.py Progetto: Joesun/qrcode
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr

f = open('spam' + qr.extension(qr.SVG) , 'wb')
f.write(qr.qrcode('spam, egg', format = qr.SVG, separator = 0))
f.close()
Esempio n. 18
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import qr, cStringIO
from PIL import Image

buf = cStringIO.StringIO(qr.qrcode('spam, egg', format=qr.BMP, scale=2))
Image.open(buf).save('spam.gif', 'GIF')
Esempio n. 19
0
 def test2(self):
     code = qrcode('1')
     assert (code.size ==1)