示例#1
0
def reset_debug_level(level):
    import uwsgi
    if level == '-1':
        uwsgi.cache_del("DEBUG")
    else:
        if uwsgi.cache_exists("DEBUG"):
            uwsgi.cache_update("DEBUG", level)
        else:
            uwsgi.cache_set("DEBUG", level)
    return redirect(url_for('tell_me_if_im_going_to_die', lat=39.9708657, lon=-75.1427425, meters=1000))
示例#2
0
    def test_multi_delete(self):
        for i in range(0, 100):
            self.assertTrue(uwsgi.cache_set('key1', 'X' * 50 , 0, 'items_4_10'))
            self.assertTrue(uwsgi.cache_del('key1', 'items_4_10'))

        for i in range(0, 100):
            self.assertIsNone(uwsgi.cache_set('key1', 'X' * 51 , 0, 'items_4_10'))
            self.assertIsNone(uwsgi.cache_del('key1', 'items_4_10'))

        for i in range(0, 100):
            self.assertTrue(uwsgi.cache_set('key1', 'X' * 50 , 0, 'items_4_10'))
            self.assertTrue(uwsgi.cache_del('key1', 'items_4_10'))
示例#3
0
 def test_big_random(self):
     blob = self.rand_blob(100000)
     self.assertTrue(uwsgi.cache_set('KEY', blob, 0, 'items_1_100000'))
     get_blob = uwsgi.cache_get('KEY', 'items_1_100000')
     self.assertEqual(blob, get_blob)
     self.assertTrue(uwsgi.cache_del('KEY', 'items_1_100000'))
     self.assertIsNone(uwsgi.cache_set('KEY', 'X' * 100001, 0, 'items_1_100000'))
     self.assertTrue(uwsgi.cache_set('KEY', 'X' * 10000, 0, 'items_1_100000'))
示例#4
0
 def test_big_delete(self):
     self.assertTrue(uwsgi.cache_set('key1', 'X' * 50 , 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_del('key1', 'items_4_10'))
     self.assertTrue(uwsgi.cache_set('key1', 'HELLOHELLO', 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_set('key2', 'HELLOHELLO', 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_set('key3', 'HELLOHELLO', 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_set('key4', 'HELLOHELLO', 0, 'items_4_10'))
     self.assertIsNone(uwsgi.cache_set('key5', 'HELLOHELLO', 0, 'items_4_10'))
示例#5
0
def get_url(url):
    """Download a file from url to cache_dir."""
    # set a lock to prevent multiple simultaneous downloads of the same
    # file
    mypid = os.getpid()
    uwsgi.lock()
    otherpid = uwsgi.cache_get(url)
    if otherpid:
        uwsgi.unlock()
        while otherpid:
            log('D: pid %d waiting for pid %s to download %s' %
                (mypid, otherpid, url))
            time.sleep(1)
            otherpid = uwsgi.cache_get(url)
        return 200
    else:
        uwsgi.cache_set(url, str(mypid))
        uwsgi.unlock()

    dest = localfile(url)
    log('D: pid %d downloading %s' % (mypid, url))
    curl = pycurl.Curl()
    curl.setopt(curl.URL, url)
    path = '/'.join(dest.split('/')[:-1])
    if not os.path.exists(path):
        # parallel download of rpms in subdir will create it right now
        try:
            os.makedirs(path)
        except OSError as e:
            # this catches duplicate creation (so just W not E)
            # TODO: need to bypass the open() on real errors
            # like permissions
            log('W: OS error(%d): %s' % (e.errno, e.strerror))
    with open(dest, 'wb') as fil:
        curl.setopt(curl.WRITEFUNCTION, fil.write)
        curl.perform()
    uwsgi.cache_del(url)
    return curl.getinfo(curl.HTTP_CODE)
示例#6
0
		def delete(self, key):
			'''
			Deletes the given key from the cache. Returns True if the key existed and was deleted, False otherwise
			'''
			return uwsgi.cache_del(key) is not None
示例#7
0
文件: core.py 项目: morozd/isso
 def delete(self, cache, key):
     uwsgi.cache_del(key, cache)
示例#8
0
 def test_non_bitmap(self):
     self.assertTrue(uwsgi.cache_set('KEY', 'X' * 20, 0, 'items_non_bitmap'))
     self.assertTrue(uwsgi.cache_del('KEY', 'items_non_bitmap'))
     self.assertIsNone(uwsgi.cache_set('KEY', 'X' * 21, 0, 'items_non_bitmap'))
     self.assertTrue(uwsgi.cache_set('KEY', 'X' * 20, 0, 'items_non_bitmap'))
示例#9
0
 def test_big_update(self):
     self.assertTrue(uwsgi.cache_set('key1', 'X' * 40 , 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_update('key1', 'X' * 10 , 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_del('key1', 'items_4_10'))
     self.assertIsNone(uwsgi.cache_update('key1', 'X' * 51 , 0, 'items_4_10'))
     self.assertTrue(uwsgi.cache_update('key1', 'X' * 50 , 0, 'items_4_10'))
示例#10
0
 def test_set(self):
     self.assertTrue(uwsgi.cache_set('key1', 'HELLO', 0, 'items_17'))
     self.assertIsNone(uwsgi.cache_set('key1', 'HELLO', 0, 'items_17'))
     self.assertTrue(uwsgi.cache_del('key1', 'items_17'))
     self.assertTrue(uwsgi.cache_set('key1', 'HELLO', 0, 'items_17'))
     self.assertIsNone(uwsgi.cache_set('key1', 'HELLO', 0, 'items_17'))
示例#11
0
 def test_overlapping(self):
     self.assertTrue(uwsgi.cache_update('key1', 'HE', 0, 'items_2'))
     self.assertIsNone(uwsgi.cache_update('key1', 'HELL', 0, 'items_2'))
     self.assertTrue(uwsgi.cache_del('key1', 'items_2')) 
     self.assertTrue(uwsgi.cache_update('key1', 'HELL', 0, 'items_2'))
示例#12
0
 def test_two_items_using_four_blocks(self):
     self.assertTrue(uwsgi.cache_update('key1', 'HE', 0, 'items_2'))
     self.assertTrue(uwsgi.cache_update('key2', 'LL', 0, 'items_2'))
     self.assertTrue(uwsgi.cache_del('key1', 'items_2'))
     self.assertIsNone(uwsgi.cache_update('key1', 'HEL', 0, 'items_2'))
     self.assertTrue(uwsgi.cache_update('key1', 'HE', 0, 'items_2'))
示例#13
0
 def save(self):
     cheapskate_raw = "/".join([key + "=" + value for key, value in self.cheapskate.items() if key in Instance.CHEAPSKATE.keys()])
     subprocess.check_output(["aws", "ec2", "create-tags", "--resources", self.instance_id, "--tags", 'Key=cheapskate,Value="{}"'.format(cheapskate_raw)])
     uwsgi.cache_del("raw_aws")
示例#14
0
 def __delitem__(self, item):
     uwsgi.cache_del(item)
示例#15
0
文件: route.py 项目: muromec/shogoki
 def clear(cls):
     uwsgi.cache_del('binds')