示例#1
0
def handle_start(message):
    markup = types.ReplyKeyboardMarkup()
    markup.row('/Квесты', '/Концерты')
    markup.row('/Стендап', '/Фестивали')
    markup.row('/Знания', '/Выставки')
    markup.row('/Ярмарки', '/Дети')
    markup.row('/Постоянные выставки')
    bot.send_message(message.chat.id,
                     constants.startAnswer,
                     reply_markup=markup)
    log(message, constants.startAnswer)
示例#2
0
async def select(sql, args, size=None):
    from cgi import log
    '''输出sql语句'''
    log(sql, args)
    global __pool
    with (await __pool) as conn:
        cur = await conn.cursor(aiomysql.DictCursor)
        await cur.execute(sql.replace('?', '%s'), args or ())
        if size:
            rs = await cur.fetchmany(size)
        else:
            rs = await cur.fetchall()
        await cur.close()
        logging.info('rows returned {}'.format(len(rs)))
        return rs
示例#3
0
    def process_item(self, item, spider):
        try:
            # 查重处理
            self.cursor.execute(
                """select * from doubanmovie where move_name = %s""",
                item['move_name'])
            # 是否有重复数据
            repetition = self.cursor.fetchone()

            # 重复
            if repetition:
                pass
            self.cursor.execute(
                """insert into  doubanmovie (serial_number, movie_name, introduce, star, evaluate, describes)value(%s, %s, %s, %s, %s, %s) """,
                (item['serial_number'], item['movie_name'], item['introduce'],
                 item['star'], item['evaluate'], item['describes']))
            # 提交sql语句
            self.connect.commit()
        except Exception as error:
            # 出现错误时打印错误日志
            log(error)
        return item
示例#4
0
    def test_log(self):
        cgi.log("Testing")

        cgi.logfp = StringIO()
        cgi.initlog("%s", "Testing initlog 1")
        cgi.log("%s", "Testing log 2")
        self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
        if os.path.exists("/dev/null"):
            cgi.logfp = None
            cgi.logfile = "/dev/null"
            cgi.initlog("%s", "Testing log 3")
            cgi.log("Testing log 4")
示例#5
0
    def test_log(self):
        cgi.log("Testing")

        cgi.logfp = StringIO()
        cgi.initlog("%s", "Testing initlog 1")
        cgi.log("%s", "Testing log 2")
        self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
        if os.path.exists(os.devnull):
            cgi.logfp = None
            cgi.logfile = os.devnull
            cgi.initlog("%s", "Testing log 3")
            self.addCleanup(cgi.closelog)
            cgi.log("Testing log 4")
示例#6
0
 def test_log(self):
     cgi.log('Testing')
     cgi.logfp = StringIO()
     cgi.initlog('%s', 'Testing initlog 1')
     cgi.log('%s', 'Testing log 2')
     self.assertEqual(cgi.logfp.getvalue(),
         'Testing initlog 1\nTesting log 2\n')
     if os.path.exists(os.devnull):
         cgi.logfp = None
         cgi.logfile = os.devnull
         cgi.initlog('%s', 'Testing log 3')
         self.addCleanup(cgi.closelog)
         cgi.log('Testing log 4')
示例#7
0
    def test_log(self):
        cgi.log("Testing")

        cgi.logfp = StringIO()
        cgi.initlog("%s", "Testing initlog 1")
        cgi.log("%s", "Testing log 2")
        self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
        if os.path.exists(os.devnull):
            cgi.logfp = None
            cgi.logfile = os.devnull
            cgi.initlog("%s", "Testing log 3")
            self.addCleanup(cgi.closelog)
            cgi.log("Testing log 4")
    def test_log(self):
        cgi.log("Testing")

        cgi.logfp = StringIO()
        cgi.initlog("%s", "Testing initlog 1")
        cgi.log("%s", "Testing log 2")
        self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
        if os.path.exists("/dev/null"):
            cgi.logfp = None
            cgi.logfile = "/dev/null"
            cgi.initlog("%s", "Testing log 3")
            def log_cleanup():
                """Restore the global state of the log vars."""
                cgi.logfile = ''
                cgi.logfp.close()
                cgi.logfp = None
                cgi.log = cgi.initlog
            self.addCleanup(log_cleanup)
            cgi.log("Testing log 4")
示例#9
0
    def test_log(self):
        cgi.log("Testing")

        cgi.logfp = StringIO()
        cgi.initlog("%s", "Testing initlog 1")
        cgi.log("%s", "Testing log 2")
        self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
        if os.path.exists("/dev/null"):
            cgi.logfp = None
            cgi.logfile = "/dev/null"
            cgi.initlog("%s", "Testing log 3")
            def log_cleanup():
                """Restore the global state of the log vars."""
                cgi.logfile = ''
                cgi.logfp.close()
                cgi.logfp = None
                cgi.log = cgi.initlog
            self.addCleanup(log_cleanup)
            cgi.log("Testing log 4")
示例#10
0
文件: test_cgi.py 项目: B-Rich/breve
def main():
    for orig, expect in parse_qsl_test_cases:
        result = cgi.parse_qsl(orig, keep_blank_values=True)
        print repr(orig), '=>', result
        verify(result == expect, "Error parsing %s" % repr(orig))

    for orig, expect in parse_strict_test_cases:
        # Test basic parsing
        print repr(orig)
        d = do_test(orig, "GET")
        verify(d == expect, "Error parsing %s" % repr(orig))
        d = do_test(orig, "POST")
        verify(d == expect, "Error parsing %s" % repr(orig))

        env = {'QUERY_STRING': orig}
        fcd = cgi.FormContentDict(env)
        sd = cgi.SvFormContentDict(env)
        fs = cgi.FieldStorage(environ=env)
        if type(expect) == type({}):
            # test dict interface
            verify(len(expect) == len(fcd))
            verify(norm(expect.keys()) == norm(fcd.keys()))
            verify(norm(expect.values()) == norm(fcd.values()))
            verify(norm(expect.items()) == norm(fcd.items()))
            verify(fcd.get("nonexistent field", "default") == "default")
            verify(len(sd) == len(fs))
            verify(norm(sd.keys()) == norm(fs.keys()))
            verify(fs.getvalue("nonexistent field", "default") == "default")
            # test individual fields
            for key in expect.keys():
                expect_val = expect[key]
                verify(fcd.has_key(key))
                verify(norm(fcd[key]) == norm(expect[key]))
                verify(fcd.get(key, "default") == fcd[key])
                verify(fs.has_key(key))
                if len(expect_val) > 1:
                    single_value = 0
                else:
                    single_value = 1
                try:
                    val = sd[key]
                except IndexError:
                    verify(not single_value)
                    verify(fs.getvalue(key) == expect_val)
                else:
                    verify(single_value)
                    verify(val == expect_val[0])
                    verify(fs.getvalue(key) == expect_val[0])
                verify(norm(sd.getlist(key)) == norm(expect_val))
                if single_value:
                    verify(norm(sd.values()) == \
                           first_elts(norm(expect.values())))
                    verify(norm(sd.items()) == \
                           first_second_elts(norm(expect.items())))

    # Test the weird FormContentDict classes
    env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
    expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
    d = cgi.InterpFormContentDict(env)
    for k, v in expect.items():
        verify(d[k] == v)
    for k, v in d.items():
        verify(expect[k] == v)
    verify(norm(expect.values()) == norm(d.values()))

    print "Testing log"
    cgi.log("Testing")
    cgi.logfp = sys.stdout
    cgi.initlog("%s", "Testing initlog 1")
    cgi.log("%s", "Testing log 2")
    if os.path.exists("/dev/null"):
        cgi.logfp = None
        cgi.logfile = "/dev/null"
        cgi.initlog("%s", "Testing log 3")
        cgi.log("Testing log 4")

    print "Test FieldStorage methods that use readline"
    # FieldStorage uses readline, which has the capacity to read all
    # contents of the input file into memory; we use readline's size argument
    # to prevent that for files that do not contain any newlines in
    # non-GET/HEAD requests
    class TestReadlineFile:
        def __init__(self, file):
            self.file = file
            self.numcalls = 0

        def readline(self, size=None):
            self.numcalls += 1
            if size:
                return self.file.readline(size)
            else:
                return self.file.readline()

        def __getattr__(self, name):
            file = self.__dict__['file']
            a = getattr(file, name)
            if not isinstance(a, int):
                setattr(self, name, a)
            return a

    f = TestReadlineFile(tempfile.TemporaryFile())
    f.write('x' * 256 * 1024)
    f.seek(0)
    env = {'REQUEST_METHOD':'PUT'}
    fs = cgi.FieldStorage(fp=f, environ=env)
    # if we're not chunking properly, readline is only called twice
    # (by read_binary); if we are chunking properly, it will be called 5 times
    # as long as the chunksize is 1 << 16.
    verify(f.numcalls > 2)

    print "Test basic FieldStorage multipart parsing"
    env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'}
    postdata = """-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="id"

1234
-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="title"


-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

Testing 123.

-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="submit"

 Add\x20
-----------------------------721837373350705526688164684--
"""
    fs = cgi.FieldStorage(fp=StringIO(postdata), environ=env)
    verify(len(fs.list) == 4)
    expect = [{'name':'id', 'filename':None, 'value':'1234'},
              {'name':'title', 'filename':None, 'value':''},
              {'name':'file', 'filename':'test.txt','value':'Testing 123.\n'},
              {'name':'submit', 'filename':None, 'value':' Add '}]
    for x in range(len(fs.list)):
        for k, exp in expect[x].items():
            got = getattr(fs.list[x], k)
            verify(got == exp)
示例#11
0
from test_support import verify, verbose
示例#12
0
from test_support import verify, verbose
        def cost(self, Y, A):
            """"""
            n = A.shape[1]
            logLoss = -(1 / n) * sum(Y * log(A) + (1 - Y) * log(1.0000001 - A))

            return logLoss
示例#14
0
def handle_text(message):
    bot.send_message(message.chat.id, constants.helpAnswer)
    log(message, constants.helpAnswer)
示例#15
0
def main():
    for orig, expect in parse_qsl_test_cases:
        result = cgi.parse_qsl(orig, keep_blank_values=True)
        print repr(orig), '=>', result
        verify(result == expect, "Error parsing %s" % repr(orig))

    for orig, expect in parse_strict_test_cases:
        # Test basic parsing
        print repr(orig)
        d = do_test(orig, "GET")
        verify(d == expect, "Error parsing %s" % repr(orig))
        d = do_test(orig, "POST")
        verify(d == expect, "Error parsing %s" % repr(orig))

        env = {'QUERY_STRING': orig}
        fcd = cgi.FormContentDict(env)
        sd = cgi.SvFormContentDict(env)
        fs = cgi.FieldStorage(environ=env)
        if type(expect) == type({}):
            # test dict interface
            verify(len(expect) == len(fcd))
            verify(norm(expect.keys()) == norm(fcd.keys()))
            verify(norm(expect.values()) == norm(fcd.values()))
            verify(norm(expect.items()) == norm(fcd.items()))
            verify(fcd.get("nonexistent field", "default") == "default")
            verify(len(sd) == len(fs))
            verify(norm(sd.keys()) == norm(fs.keys()))
            verify(fs.getvalue("nonexistent field", "default") == "default")
            # test individual fields
            for key in expect.keys():
                expect_val = expect[key]
                verify(fcd.has_key(key))
                verify(norm(fcd[key]) == norm(expect[key]))
                verify(fcd.get(key, "default") == fcd[key])
                verify(fs.has_key(key))
                if len(expect_val) > 1:
                    single_value = 0
                else:
                    single_value = 1
                try:
                    val = sd[key]
                except IndexError:
                    verify(not single_value)
                    verify(fs.getvalue(key) == expect_val)
                else:
                    verify(single_value)
                    verify(val == expect_val[0])
                    verify(fs.getvalue(key) == expect_val[0])
                verify(norm(sd.getlist(key)) == norm(expect_val))
                if single_value:
                    verify(norm(sd.values()) == \
                           first_elts(norm(expect.values())))
                    verify(norm(sd.items()) == \
                           first_second_elts(norm(expect.items())))

    # Test the weird FormContentDict classes
    env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
    expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
    d = cgi.InterpFormContentDict(env)
    for k, v in expect.items():
        verify(d[k] == v)
    for k, v in d.items():
        verify(expect[k] == v)
    verify(norm(expect.values()) == norm(d.values()))

    print "Testing log"
    cgi.log("Testing")
    cgi.logfp = sys.stdout
    cgi.initlog("%s", "Testing initlog 1")
    cgi.log("%s", "Testing log 2")
    if os.path.exists("/dev/null"):
        cgi.logfp = None
        cgi.logfile = "/dev/null"
        cgi.initlog("%s", "Testing log 3")
        cgi.log("Testing log 4")

    print "Test FieldStorage methods that use readline"

    # FieldStorage uses readline, which has the capacity to read all
    # contents of the input file into memory; we use readline's size argument
    # to prevent that for files that do not contain any newlines in
    # non-GET/HEAD requests
    class TestReadlineFile:
        def __init__(self, file):
            self.file = file
            self.numcalls = 0

        def readline(self, size=None):
            self.numcalls += 1
            if size:
                return self.file.readline(size)
            else:
                return self.file.readline()

        def __getattr__(self, name):
            file = self.__dict__['file']
            a = getattr(file, name)
            if not isinstance(a, int):
                setattr(self, name, a)
            return a

    f = TestReadlineFile(tempfile.TemporaryFile())
    f.write('x' * 256 * 1024)
    f.seek(0)
    env = {'REQUEST_METHOD': 'PUT'}
    fs = cgi.FieldStorage(fp=f, environ=env)
    # if we're not chunking properly, readline is only called twice
    # (by read_binary); if we are chunking properly, it will be called 5 times
    # as long as the chunksize is 1 << 16.
    verify(f.numcalls > 2)

    print "Test basic FieldStorage multipart parsing"
    env = {
        'REQUEST_METHOD': 'POST',
        'CONTENT_TYPE':
        'multipart/form-data; boundary=---------------------------721837373350705526688164684',
        'CONTENT_LENGTH': '558'
    }
    postdata = """-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="id"

1234
-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="title"


-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

Testing 123.

-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="submit"

 Add\x20
-----------------------------721837373350705526688164684--
"""
    fs = cgi.FieldStorage(fp=StringIO(postdata), environ=env)
    verify(len(fs.list) == 4)
    expect = [{
        'name': 'id',
        'filename': None,
        'value': '1234'
    }, {
        'name': 'title',
        'filename': None,
        'value': ''
    }, {
        'name': 'file',
        'filename': 'test.txt',
        'value': 'Testing 123.\n'
    }, {
        'name': 'submit',
        'filename': None,
        'value': ' Add '
    }]
    for x in range(len(fs.list)):
        for k, exp in expect[x].items():
            got = getattr(fs.list[x], k)
            verify(got == exp)
示例#16
0
def main():
    for orig, expect in parse_test_cases:
        # Test basic parsing
        print repr(orig)
        d = do_test(orig, "GET")
        verify(d == expect, "Error parsing %s" % repr(orig))
        d = do_test(orig, "POST")
        verify(d == expect, "Error parsing %s" % repr(orig))

        env = {'QUERY_STRING': orig}
        fcd = cgi.FormContentDict(env)
        sd = cgi.SvFormContentDict(env)
        fs = cgi.FieldStorage(environ=env)
        if type(expect) == type({}):
            # test dict interface
            verify(len(expect) == len(fcd))
            verify(norm(expect.keys()) == norm(fcd.keys()))
            verify(norm(expect.values()) == norm(fcd.values()))
            verify(norm(expect.items()) == norm(fcd.items()))
            verify(fcd.get("nonexistent field", "default") == "default")
            verify(len(sd) == len(fs))
            verify(norm(sd.keys()) == norm(fs.keys()))
            verify(fs.getvalue("nonexistent field", "default") == "default")
            # test individual fields
            for key in expect.keys():
                expect_val = expect[key]
                verify(fcd.has_key(key))
                verify(norm(fcd[key]) == norm(expect[key]))
                verify(fcd.get(key, "default") == fcd[key])
                verify(fs.has_key(key))
                if len(expect_val) > 1:
                    single_value = 0
                else:
                    single_value = 1
                try:
                    val = sd[key]
                except IndexError:
                    verify(not single_value)
                    verify(fs.getvalue(key) == expect_val)
                else:
                    verify(single_value)
                    verify(val == expect_val[0])
                    verify(fs.getvalue(key) == expect_val[0])
                verify(norm(sd.getlist(key)) == norm(expect_val))
                if single_value:
                    verify(norm(sd.values()) == \
                           first_elts(norm(expect.values())))
                    verify(norm(sd.items()) == \
                           first_second_elts(norm(expect.items())))

    # Test the weird FormContentDict classes
    env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
    expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
    d = cgi.InterpFormContentDict(env)
    for k, v in expect.items():
        verify(d[k] == v)
    for k, v in d.items():
        verify(expect[k] == v)
    verify(norm(expect.values()) == norm(d.values()))

    print "Testing log"
    cgi.initlog()
    cgi.log("Testing")
    cgi.logfp = sys.stdout
    cgi.initlog("%s", "Testing initlog 1")
    cgi.log("%s", "Testing log 2")
    if os.path.exists("/dev/null"):
        cgi.logfp = None
        cgi.logfile = "/dev/null"
        cgi.initlog("%s", "Testing log 3")
        cgi.log("Testing log 4")
示例#17
0
 def update_event(self, inp=-1):
     self.set_output_val(0, cgi.log())
示例#18
0
def main():
    for orig, expect in parse_test_cases:
        # Test basic parsing
        print repr(orig)
        d = do_test(orig, "GET")
        verify(d == expect, "Error parsing %s" % repr(orig))
        d = do_test(orig, "POST")
        verify(d == expect, "Error parsing %s" % repr(orig))

        env = {'QUERY_STRING': orig}
        fcd = cgi.FormContentDict(env)
        sd = cgi.SvFormContentDict(env)
        fs = cgi.FieldStorage(environ=env)
        if type(expect) == type({}):
            # test dict interface
            verify(len(expect) == len(fcd))
            verify(norm(expect.keys()) == norm(fcd.keys()))
            verify(norm(expect.values()) == norm(fcd.values()))
            verify(norm(expect.items()) == norm(fcd.items()))
            verify(fcd.get("nonexistent field", "default") == "default")
            verify(len(sd) == len(fs))
            verify(norm(sd.keys()) == norm(fs.keys()))
            verify(fs.getvalue("nonexistent field", "default") == "default")
            # test individual fields
            for key in expect.keys():
                expect_val = expect[key]
                verify(fcd.has_key(key))
                verify(norm(fcd[key]) == norm(expect[key]))
                verify(fcd.get(key, "default") == fcd[key])
                verify(fs.has_key(key))
                if len(expect_val) > 1:
                    single_value = 0
                else:
                    single_value = 1
                try:
                    val = sd[key]
                except IndexError:
                    verify(not single_value)
                    verify(fs.getvalue(key) == expect_val)
                else:
                    verify(single_value)
                    verify(val == expect_val[0])
                    verify(fs.getvalue(key) == expect_val[0])
                verify(norm(sd.getlist(key)) == norm(expect_val))
                if single_value:
                    verify(norm(sd.values()) == \
                           first_elts(norm(expect.values())))
                    verify(norm(sd.items()) == \
                           first_second_elts(norm(expect.items())))

    # Test the weird FormContentDict classes
    env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
    expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
    d = cgi.InterpFormContentDict(env)
    for k, v in expect.items():
        verify(d[k] == v)
    for k, v in d.items():
        verify(expect[k] == v)
    verify(norm(expect.values()) == norm(d.values()))

    print "Testing log"
    cgi.initlog()
    cgi.log("Testing")
    cgi.logfp = sys.stdout
    cgi.initlog("%s", "Testing initlog 1")
    cgi.log("%s", "Testing log 2")
    if os.path.exists("/dev/null"):
        cgi.logfp = None
        cgi.logfile = "/dev/null"
        cgi.initlog("%s", "Testing log 3")
        cgi.log("Testing log 4")