コード例 #1
0
 def test_ascii(self):
     config = {
         'Image': {
             'Background': [0, 0, 0],
             'Palette': '$8o:. ',
             'Resize': 'none',
             'Src': ['logo-mini.png'],
             'Type': 'ascii',
         }
     }
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'out': [
                 '                ',
                 '     :8$8o..88: ',
                 ' .oo.    .oo.   ',
                 ' .::.    :88:   ',
                 '   .o8$$o: .oo. ',
                 '       :8$8o.   ',
                 '     .:oo88o.   ',
                 '                ',
             ],
             'width':
             16
         })
     self.assertEqual(returned, expected)
コード例 #2
0
ファイル: wsgi.py プロジェクト: Yossi/sets-card-game
def image(environment, start_response, code):
    # qsl not qs because qs gives a dict of lists, and we need a dict of strings
    query = dict(urlparse.parse_qsl(environment['QUERY_STRING']))
    try:
        result = cache.get(tuple(sorted(query.values())), False)
        if not result:
            print 'cache miss'
            result = draw(**query)
            cache[tuple(sorted(query.values()))] = result
    except: # errors should have been dealt with upstream in image.py. if not, KA-BOOM!
        raise
    start_response('%s %s' % (code, description[code]), [('content-type', 'image/png')])
    return result.getvalue()
コード例 #3
0
def image(environment, start_response, code):
    # qsl not qs because qs gives a dict of lists, and we need a dict of strings
    query = dict(urllib.parse.parse_qsl(environment['QUERY_STRING']))
    try:
        result = cache.get(tuple(sorted(query.values())), False)
        if not result:
            print('cache miss')
            result = draw(**query)
            cache[tuple(sorted(query.values()))] = result
    except:  # errors should have been dealt with upstream in image.py. if not, KA-BOOM!
        raise
    start_response('%s %s' % (code, description[code]),
                   [('content-type', 'image/png')])
    return result.getvalue()
コード例 #4
0
 def test_text(self):
     config = {'Image': {'Type': 'text', 'Src': ['img.txt']}}
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'out': [
                 '    ',
                 '\x1b[1;30;40m▄\x1b[1;31;41m▄\x1b[1;32;42m▄\x1b[1;34;44m▄\x1b[0m',
                 '\x1b[1;37;47m▄\x1b[1;33;43m▀\x1b[1;36;46m▀\x1b[1;35;45m▀\x1b[0m',
                 '    ', ''
             ],
             'width':
             4
         })
     self.assertEqual(returned, expected)
コード例 #5
0
 def test_file_error(self):
     config = {
         'Image': {
             'Src': ['/dev/null/fail'],
             'Type': 'ASCII',
         }
     }
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'err': [
                 ('W', "Unable to open file '/dev/null/fail'"),
                 ('E', 'Could not open any file'),
             ]
         })
     self.assertEqual(returned, expected)
コード例 #6
0
 def test_background(self):
     config = {
         'Image': {
             'Background': [255, 255, 255],
             'Palette': '$8o:. ',
             'Resize': 'none',
             'Src': ['logo-mini.png'],
             'Type': 'ascii',
         }
     }
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'out': [
                 '$$$$$8.      .8$', '$8.  .ooo: .oo. ', ' .::.    .::.   ',
                 ' .::.    .oo.   ', '$8. :ooo:. .::. ', '$$$8.  .ooo: .8$',
                 '$$$8. .::oo: .8$', '$$$$$8.    .8$$$'
             ],
             'width':
             16
         })
     self.assertEqual(returned, expected)
コード例 #7
0
 def test_resize_stretch(self):
     config = {
         'Image': {
             'Background': [0, 0, 0],
             'Lines': 4,
             'Palette': '$8o:. ',
             'Resize': 'stretch',
             'Src': ['logo-mini.png'],
             'Type': 'ascii',
             'Width': 8,
         }
     }
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'out': [
                 ' . 8o.8 ',
                 ' $.o:$: ',
                 ' .o8$8o ',
                 '   o88  ',
             ],
             'width': 8
         })
     self.assertEqual(returned, expected)
コード例 #8
0
 def test_ansi(self):
     config = {
         'Image': {
             'Background': [0, 0, 0],
             'Force_Truecolor': True,
             'Resize': 'none',
             'Src': ['logo-mini.png'],
             'Type': 'ansi',
         }
     }
     returned = image.draw(config)
     expected = image.ImageOutput(
         **{
             'out': [
                 '\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀' +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;170;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;170;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 + '\x01\x1b[0m\x02',
                 '\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀' +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;85;85;85m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;170;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 + '\x01\x1b[0m\x02',
                 '\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀' +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;170;170;170m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;85;85;85m\x02\x01\x1b[48;2;170;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;170;170m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 + '\x01\x1b[0m\x02',
                 '\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀' +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;85;85;85m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;170;170m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 +
                 '\x01\x1b[0m\x02\x01\x1b[38;2;0;0;0m\x02\x01\x1b[48;2;0;0;0m\x02▀'
                 + '\x01\x1b[0m\x02'
             ],
             'width':
             8
         })
     self.assertEqual(returned, expected)
コード例 #9
0
 def test_no_image(self):
     config = {'Image': {'Type': 'None'}}
     returned = image.draw(config)
     expected = image.ImageOutput()
     self.assertEqual(returned, expected)
コード例 #10
0
import functools
import image


@functools.lru_cache(maxsize=None)
def choose(n, k):
    if k in (0, n):
        return 1
    return choose(n - 1, k - 1) + choose(n - 1, k)


res = []
for row in range(20):
    for k in range(row + 1):
        res.append(choose(row, k))

image.draw(res)
コード例 #11
0
#!/usr/bin/python3
# wraith.py

# Entry point
#
# Parses command-line arguments and hooks up the other modules.

import os

import load_conf
import run_commands
import image
import output

os.environ ['WRAITH_PATH'] = os.path.dirname (__file__)

conf_file = os.path.join (os.path.expandvars ('${WRAITH_PATH}'), 'config.toml')
#conf_file = os.path.join (os.path.expandvars ('${WRAITH_PATH}'), 'terroo.toml')

config = load_conf.load (conf_file)

img = image.draw (config)

info = run_commands.run (config)

output.show (config, img, info)

# TODO:
#   Handle errors