Beispiel #1
0
    def exists(cls, id):
        if not hasattr(cls, '__prefix__'):
            raise AttributeError("Models must define the attribute: __prefix__ or define one of the model keys as primary")

        if not id.startswith(cls.__prefix__):
            id = cls.__prefix__ + id

        return redis.exists(id)
Beispiel #2
0
    def exists(cls, id):
        if not hasattr(cls, '__prefix__'):
            raise AttributeError(
                "Models must define the attribute: __prefix__ or define one of the model keys as primary"
            )

        if not id.startswith(cls.__prefix__):
            id = cls.__prefix__ + id

        return redis.exists(id)
def index():
	if request.method == 'GET':
		return render_template('index.html')

	elif request.method == 'POST':
		# ipdb.set_trace()
		filename = request.form['filename']
		passwd = request.form['pass']
		# ipdb.set_trace()
		try:
			# check if file already exists
			# if doesnt exists then create a new file and enter details in redis
			if not r.exists(filename) or r.exists == None:
				r.hmset(filename,{request.remote_addr:filename})
				r.set(filename+'pass',passwd)
				a=soldier.run('touch app/files/' + filename)
				# start queue for sending data to clients 
				start_queue(filename)
			# if exists check for password
			else:
				if r.exists(filename+'pass'):
					if r.get(filename+'pass')!=passwd:
						return redirect('/')
		except:
			# exception will be if file is not present hence create the file
			r.hmset(filename,{request.remote_addr:filename})
			r.set(filename+'pass',passwd)
			a=soldier.run('touch app/files/' + filename)
			# start queue for sending data to clients 
			start_queue(filename)
			if r.get(filename+'pass')!=passwd:
				return redirect('/')

		# add filename to curr ip and vice versa in redis
		ip_file_map = r.hgetall(filename)
		ip_file_map[request.remote_addr] = filename
		r.hmset(filename,ip_file_map)
		r.set(request.remote_addr, filename)
		# store that user is logged in 
		session['logged_in'] = filename
		return redirect('/edit/' + filename)
Beispiel #4
0
def assert_does_not_exist(listing_id):
    """Asserts that listing data does not exist for listing_id."""
    assert not r.exists('listings.%s.data' % listing_id)
    assert not r.exists('listings.%s.users' % listing_id)
    assert r.zrank('treasures', listing_id) is None
Beispiel #5
0
 def __contains__(self, key):
     return redis.exists(self.__keytransform__(key))
Beispiel #6
0
 def __contains__(self, key):
     return redis.exists(self.__keytransform__(key))