Ejemplo n.º 1
0
    def test_syntaxerror(self):
        i = interpreter.Interp()
        a = []

        def append_to_a(message):
            a.append(message)

        i.write = append_to_a
        i.runsource('1.1.1.1')

        if pypy:
            expected = (
                '  File ' + green('"<input>"') +
                ', line ' + bold(magenta('1')) + '\n    1.1.1.1\n      ^\n' +
                bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') +
                '\n')
        else:
            expected = (
                '  File ' + green('"<input>"') +
                ', line ' + bold(magenta('1')) + '\n    1.1.1.1\n        ^\n' +
                bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') +
                '\n')

        self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
        self.assertEquals(plain('').join(a), expected)
Ejemplo n.º 2
0
    def test_unhighlight_paren_bugs(self):
        """two previous bugs, parent didn't highlight until next render
        and paren didn't unhighlight until enter"""
        self.assertEqual(self.repl.rl_history.entries, [''])
        self.enter('(')
        self.assertEqual(self.repl.rl_history.entries, [''])
        screen = [">>> (",
                  "... "]
        self.assertEqual(self.repl.rl_history.entries, [''])
        self.assert_paint_ignoring_formatting(screen)
        self.assertEqual(self.repl.rl_history.entries, [''])

        with output_to_repl(self.repl):
            self.assertEqual(self.repl.rl_history.entries, [''])
            self.repl.process_event(')')
            self.assertEqual(self.repl.rl_history.entries, [''])
        screen = fsarray([cyan(">>> ") + on_magenta(bold(red('('))),
                         green("... ") + on_magenta(bold(red(')')))])
        self.assert_paint(screen, (1, 5))

        with output_to_repl(self.repl):
            self.repl.process_event(' ')
        screen = fsarray([cyan(">>> ") + yellow('('),
                         green("... ") + yellow(')') + bold(cyan(" "))])
        self.assert_paint(screen, (1, 6))
Ejemplo n.º 3
0
 def __init__(self, width, height):
     self.width = width
     self.height = height
     n = 10
     self.player = Entity(on_blue(green(bold('5'))), width // 2, height // 2 - 2, speed=5)
     self.npcs = [Entity(on_blue(red('X')), i * width // (n * 2), j * height // (n * 2)) for i in range(1, 2*n, 2) for j in range(1, 2*n, 2)]
     self.turn = 0
Ejemplo n.º 4
0
    def test_traceback(self):
        i = interpreter.Interp()
        a = []

        def append_to_a(message):
            a.append(message)

        i.write = append_to_a

        def f():
            return 1/0

        def g():
            return f()

        i.runsource('g()', encode=False)

        if pypy:
            global_not_found = "global name 'g' is not defined"
        else:
            global_not_found = "name 'g' is not defined"

        expected = 'Traceback (most recent call last):\n  File ' + \
            green('"%s"' % _last_console_filename()) + ', line ' + bold(magenta('1')) + ', in ' + \
            cyan('<module>') + '\n    g()\n' + bold(red('NameError')) + ': ' + \
            cyan(global_not_found) + '\n'

        self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
        self.assertEquals(plain('').join(a), expected)
Ejemplo n.º 5
0
    def test_syntaxerror(self):
        i, a = self.interp_errlog()

        i.runsource('1.1.1.1')

        if pypy:
            expected = (
                '  File ' + green('"<input>"') +
                ', line ' + bold(magenta('1')) + '\n    1.1.1.1\n      ^\n' +
                bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') +
                '\n')
        else:
            expected = (
                '  File ' + green('"<input>"') +
                ', line ' + bold(magenta('1')) + '\n    1.1.1.1\n        ^\n' +
                bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') +
                '\n')

        self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
        self.assertEqual(plain('').join(a), expected)
Ejemplo n.º 6
0
 def __repr__(self):
     s = fmtfuncs.bold(type(self).__name__)
     s += (': '+fmtfuncs.bold(self.title.title()) if self.title else '')
     s += '\n'
     s += fmtfuncs.gray(self.question)
     s += '\n'
     s += fmtfuncs.gray('\n').join(fmtfuncs.green(repr(x) if not isinstance(x, basestring) else x) for x in self.corrects)
     s += '\n'
     s += fmtfuncs.gray('\n').join(fmtfuncs.red(repr(x) if not isinstance(x, basestring) else x) for x in self.wrongs)
     s += '\n'
     return str(s)
Ejemplo n.º 7
0
 def deathSequence(self):
     a = FSArray(self.height, self.width)
     a[10,10] = red('X')
     a[10,14] = red('X')
     a[12, 10] = red('_')
     a[12, 11] = red('_')
     a[12, 12] = red('_')
     a[12, 13] = red('_')
     a[12, 14] = red('_')
     return a
Ejemplo n.º 8
0
def check_version():
    """Tests if Python version is >= 3.5.x and print user instructions if it is not."""

    message = (
        "Hey asshole, did you even read the README? You're using the wrong Python "
        "version and are going to be very sad when I don't save your score."
    )
    prompt = "Would you like to leave and restart after opening with the correct version [y,n]?:"

    if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 5):
        print(red(message))
        if input(prompt).lower() in ["y", "yes"]:
            print(bold("Remember to type 'python3'"))
            exit()
Ejemplo n.º 9
0
def check_if_want_quit_game(user_answer, time_start, game):
    """Encourages the user to continue playing if they ask to exit."""

    prompt = "Are you sure you want to leave? (y,n)"

    if user_answer in ["quit", "exit"]:
        while True:
            action = input(prompt).lower()
            if action in ["y", "yes"]:
                fancy_print("Ok, hope to see you soon!")
                end_game(time_start, game)
                exit(0)
            if action in ["n", "no"]:
                fancy_print("Great! Let's do some more!")
                break
            else:
                print(red("Invalid input: y or n, please!"))
Ejemplo n.º 10
0
def main(host, port):
    client = socket.socket()
    client.connect((host, port))
    client.setblocking(False)

    conn = Connection(client)
    keypresses = []

    with FullscreenWindow() as window:
        with Input() as input_generator:
            while True:
                a = FSArray(10, 80)
                in_text = ''.join(keypresses)[:80]
                a[9:10, 0:len(in_text)] = [red(in_text)]
                for i, line in zip(reversed(range(2,7)), reversed(conn.render())):
                    a[i:i+1, 0:len(line)] = [line]
                text = 'connected to %s:%d' % (host if len(host) < 50 else host[:50]+'...', port)
                a[0:1, 0:len(text)] = [blue(text)]

                window.render_to_terminal(a)
                ready_to_read, _, _ = select.select([conn, input_generator], [], [])
                for r in ready_to_read:
                    if r is conn:
                        r.on_read()
                    else:
                        e = input_generator.send(0)
                        if e == '<ESC>':
                            return
                        elif e == '<RETURN>':
                            keypresses.append('\n')
                            client.send((''.join(keypresses)).encode('latin-1'))
                            keypresses = []
                        elif e == '<SPACE>':
                            keypresses.append(' ')
                        elif e == '<DELETE>':
                            keypresses = keypresses[:-1]
                        elif e is not None:
                            keypresses.append(e)
Ejemplo n.º 11
0
    def test_traceback(self):
        i, a = self.interp_errlog()

        def f():
            return 1 / 0

        def gfunc():
            return f()

        i.runsource("gfunc()")

        if pypy and not py3:
            global_not_found = "global name 'gfunc' is not defined"
        else:
            global_not_found = "name 'gfunc' is not defined"

        expected = ("Traceback (most recent call last):\n  File " +
                    green('"<input>"') + ", line " + bold(magenta("1")) +
                    ", in " + cyan("<module>") + "\n    gfunc()\n" +
                    bold(red("NameError")) + ": " + cyan(global_not_found) +
                    "\n")

        self.assertMultiLineEqual(str(plain("").join(a)), str(expected))
        self.assertEqual(plain("").join(a), expected)
    def test_traceback(self):
        i = interpreter.Interp()
        a = []

        def append_to_a(message):
            a.append(message)

        i.write = append_to_a

        def f():
            return 1/0

        def g():
            return f()

        i.runsource('g()')

        expected = 'Traceback (most recent call last):\n  File ' + \
            green('"<input>"') + ', line ' + bold(magenta('1')) + ', in ' + \
            cyan('<module>') + '\n' + bold(red('NameError')) + ': ' + \
            cyan("name 'g' is not defined") + '\n'

        self.assertEquals(str(plain('').join(a)), str(expected))
        self.assertEquals(plain('').join(a), expected)
Ejemplo n.º 13
0
    def test_traceback(self):
        i = interpreter.Interp()
        a = []

        def append_to_a(message):
            a.append(message)

        i.write = append_to_a

        def f():
            return 1 / 0

        def g():
            return f()

        i.runsource('g()')

        expected = 'Traceback (most recent call last):\n  File ' + \
            green('"<input>"') + ', line ' + bold(magenta('1')) + ', in ' + \
            cyan('<module>') + '\n' + bold(red('NameError')) + ': ' + \
            cyan("name 'g' is not defined") + '\n'

        self.assertEquals(str(plain('').join(a)), str(expected))
        self.assertEquals(plain('').join(a), expected)
Ejemplo n.º 14
0
    def test_traceback(self):
        i, a = self.interp_errlog()

        def f():
            return 1 / 0

        def gfunc():
            return f()

        i.runsource('gfunc()')

        if pypy and not py3:
            global_not_found = "global name 'gfunc' is not defined"
        else:
            global_not_found = "name 'gfunc' is not defined"

        expected = (
            'Traceback (most recent call last):\n  File ' +
            green('"<input>"') + ', line ' +
            bold(magenta('1')) + ', in ' + cyan('<module>') + '\n    gfunc()\n' +
            bold(red('NameError')) + ': ' + cyan(global_not_found) + '\n')

        self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
        self.assertEqual(plain('').join(a), expected)
Ejemplo n.º 15
0
    def test_traceback(self):
        i, a = self.interp_errlog()

        def f():
            return 1 / 0

        def gfunc():
            return f()

        i.runsource('gfunc()')

        if pypy:
            global_not_found = "global name 'gfunc' is not defined"
        else:
            global_not_found = "name 'gfunc' is not defined"

        expected = ('Traceback (most recent call last):\n  File ' +
                    green('"<input>"') + ', line ' + bold(magenta('1')) +
                    ', in ' + cyan('<module>') + '\n    gfunc()\n' +
                    bold(red('NameError')) + ': ' + cyan(global_not_found) +
                    '\n')

        self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
        self.assertEqual(plain('').join(a), expected)
    start_time -= 86400

    result = g.search_repositories(query)

    print(
        result.totalCount
    )  # Printing the total value of github repos for Python(Problem: API not returning 1.2 million search results instead returning 1000 results.)

    for repository in result:
        print(f"{repository.clone_url}")
        #print(f"{repository.tags_url}")
        #print(dir(repository))

        os.system(
            f"git clone {repository.clone_url} repos/{repository.owner.login}/{repository.name}"
        )
        d = "repos"

        for dirpath, dirnames, filenames in os.walk("repos"):
            for f in filenames:
                full_path = os.path.join(dirpath, f)

                if full_path.endswith(".py"):
                    pass
                else:
                    print(red(f"Deleting {full_path}"))
                    if d in full_path:
                        os.remove(full_path)
                    else:
                        print(yellow("Something is wrong"))
Ejemplo n.º 17
0
from direct.showbase.ShowBase import ShowBase


base = ShowBase()
base.setSleep(0.001)


import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow
r = 0

print(yellow('the following code takes over the screen'))
with FullscreenWindow() as window:
    print(red(on_blue(bold('Press escape to exit'))))
    with Input() as input_generator:
        a = FSArray(window.height, window.width)
        a[r, 0] = [repr("Test " + str(r))]
        window.render_to_terminal(a)
        r += 1
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(repr(c))))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(repr(c))] = [color(repr(c))]
Ejemplo n.º 18
0
 def test_repr(self):
     self.assertEqual(fmtstr("hello", "red", bold=False), red("hello"))
     self.assertEqual(fmtstr("hello", "red", bold=True), bold(red("hello")))
Ejemplo n.º 19
0
 def test_fg(self):
     red("asdf")
     blue("asdf")
     self.assertTrue(True)
Ejemplo n.º 20
0
import os
import time
from curtsies.fmtfuncs import cyan, bold, green, red, yellow

d = 'repos'
for dirpath, dirnames, filenames in os.walk("repos"):
    for f in filenames:
        path = os.path.join(dirpath, f)

        if path.endswith('.py'):
            print(green(f"Keeping {path}"))
        else:
            print(red(f"Deleting {path}"))

            if d in path:
                os.remove(path)
            else:
                print(yellow("Something went wrong"))
                time.sleep(60)
    # time.sleep(0.5)
Ejemplo n.º 21
0
import sys

from curtsies.fmtfuncs import blue, red, bold, on_red

from curtsies.window import Window
from curtsies.terminal import Terminal

if __name__ == '__main__':

    print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))

    with Terminal(sys.stdin, sys.stdout) as tc:
        with Window(tc) as t:
            rows, columns = t.tc.get_screen_size()
            while True:
                c = t.tc.get_event()
                if c == "":
                    sys.exit() # same as raise SystemExit()
                elif c == "a":
                    a = [blue(on_red(c*columns)) for _ in range(rows)]
                elif c == "b":
                    a = t.array_from_text("a small array")
                else:
                    a = t.array_from_text("try a, b, or ctrl-D")
                t.render_to_terminal(a)


Ejemplo n.º 22
0
 def test_fg(self):
     red('asdf')
     blue('asdf')
     self.assertTrue(True)
Ejemplo n.º 23
0
from __future__ import unicode_literals # convenient for Python 2
import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        window.render_to_terminal(a)
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c)
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(s)] = [color(s)]
            window.render_to_terminal(a)
Ejemplo n.º 24
0
 def test_repr(self):
     self.assertEqual(fmtstr('hello', 'red', bold=False), red('hello'))
     self.assertEqual(fmtstr('hello', 'red', bold=True), bold(red('hello')))
Ejemplo n.º 25
0
 def test_change_color(self):
     a = blue(red('hello'))
     self.assertEqual(a, blue('hello'))
Ejemplo n.º 26
0
from __future__ import unicode_literals # convenient for Python 2
import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        window.render_to_terminal(a)
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c)
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(s)] = [color(s)]
            window.render_to_terminal(a)
Ejemplo n.º 27
0
import sys
import os

from curtsies.fmtfuncs import blue, red, bold, on_red

from curtsies.window import FullscreenWindow

import time

if __name__ == '__main__':

    print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))
    n = int(sys.argv[1]) if len(sys.argv) > 1 else 100

    with FullscreenWindow() as window:
        rows, columns = window.get_term_hw()
        t0 = time.time()
        for i in range(n):
            a = [
                blue(on_red('qwertyuiop'[i % 10] * columns))
                for _ in range(rows)
            ]
            window.render_to_terminal(a)
        t1 = time.time()
        t2 = time.time()
        for i in range(n):
            a = [blue(on_red('q'[i % 1] * columns)) for _ in range(rows)]
            window.render_to_terminal(a)
        t3 = time.time()
        t4 = time.time()
        a = [blue(on_red('q' * columns)) for _ in range(rows)]
Ejemplo n.º 28
0
    def test_syntaxerror(self):
        i = interpreter.Interp()
        a = []

        def append_to_a(message):
            a.append(message)

        i.write = append_to_a
        i.runsource('1.1.1.1')

        expected = ''+u''+u'  File '+green(u'"<input>"')+u', line '+bold(magenta(u'1'))+u'\n'+u'    '+u'1.1'+u'.'+u'1.1'+u'\n'+u'    '+u'    '+u'^'+u'\n'+bold(red(u'SyntaxError'))+u': '+cyan(u'invalid syntax')+u'\n'

        self.assertEquals(str(plain('').join(a)), str(expected))
        self.assertEquals(plain('').join(a), expected)