def timeout(function_, *args, **table):

    try:
        response = None

        f = repr(function_)
        f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f)

        a = hashlib.md5()
        for i in args: a.update(str(i))
        a = str(a.hexdigest())
    except BaseException:
        pass

    try:
        table = table['table']
    except BaseException:
        table = 'rel_list'

    try:
        control.makeFile(control.dataPath)
        dbcon = database.connect(control.cacheFile)
        dbcur = dbcon.cursor()
        dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a))
        match = dbcur.fetchone()
        return int(match[3])
    except BaseException:
        return
Example #2
0
    def run(self, url, source):

        path = os.path.join(control.dataPath, 'temp')
        path = path.decode('utf-8')

        control.deleteDir(os.path.join(path, ''), force=True)

        control.makeFile(control.dataPath)

        control.makeFile(path)

        if source == 's4f':

            subtitle = s4f.s4f().download(path, url)

        elif source == 'subztv':

            subtitle = subztv.subztv().download(path, url)

        elif source == 'yifi':

            subtitle = yifi.yifi().download(path, url)

        else:

            subtitle = None

        if subtitle is not None:
            item = control.item(label=subtitle)
            control.addItem(handle=syshandle,
                            url=subtitle,
                            listitem=item,
                            isFolder=False)

        control.directory(syshandle)
def get(function_, time_out, *args, **table):
    try:
        response = None

        f = repr(function_)
        f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f)

        a = hashlib.md5()
        for i in args: a.update(str(i))
        a = str(a.hexdigest())
    except BaseException:
        pass

    try:
        table = table['table']
    except BaseException:
        table = 'rel_list'

    try:
        control.makeFile(control.dataPath)
        dbcon = database.connect(control.cacheFile)
        dbcur = dbcon.cursor()
        dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a))
        match = dbcur.fetchone()

        try:
            response = eval(match[2].encode('utf-8'))
        except BaseException:
            response = eval(match[2])

        t1 = int(match[3])
        t2 = int(time.time())
        update = (abs(t2 - t1) / 3600) >= int(time_out)
        if not update:
            return response
    except BaseException:
        pass

    try:
        r = function_(*args)
        if (r is None or r == []) and response is not None:
            return response

        elif r is None or r == []:
            return r
    except BaseException:
        return

    try:
        r = repr(r)
        t = int(time.time())
        dbcur.execute("CREATE TABLE IF NOT EXISTS %s (""func TEXT, ""args TEXT, ""response TEXT, ""added TEXT, ""UNIQUE(func, args)"");" % table)
        dbcur.execute("DELETE FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a))
        dbcur.execute("INSERT INTO %s Values (?, ?, ?, ?)" % table, (f, a, r, t))
        dbcon.commit()
    except BaseException:
        pass

    try:
        return eval(r.encode('utf-8'))
    except BaseException:
        return eval(r)