code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
with self.pipe as pipe:
return pipe.object(infotype, self.redis_key(key)) | def object(self, infotype, key) | get the key's info stats
:param name: str the name of the redis key
:param subcommand: REFCOUNT | ENCODING | IDLETIME
:return: Future() | 7.455272 | 6.651416 | 1.120855 |
f = Future()
if self.keyspace is None:
with self.pipe as pipe:
res = pipe.scan(cursor=cursor, match=match, count=count)
def cb():
f.set((res[0], [self.keyparse.decode(v) for v in res[1]]))
pipe.on_execute(cb)
... | def scan(self, cursor=0, match=None, count=None) | Incrementally return lists of key names. Also return a cursor
indicating the scan position.
``match`` allows for filtering the keys by pattern
``count`` allows for hint the minimum number of returns | 2.55106 | 2.575332 | 0.990575 |
with self.pipe as pipe:
res = pipe.sort(self.redis_key(name), start=start, num=num,
by=by, get=get, desc=desc, alpha=alpha,
store=store, groups=groups)
if store:
return res
f = Future()
... | def sort(self, name, start=None, num=None, by=None, get=None,
desc=False, alpha=False, store=None, groups=False) | Sort and return the list, set or sorted set at ``name``.
``start`` and ``num`` allow for paging through the sorted data
``by`` allows using an external key to weight and sort the items.
Use an "*" to indicate where in the key the item value is located
``get`` allows for returning ... | 4.013614 | 4.759529 | 0.84328 |
keys = [self.redis_key(k) for k in self._parse_values(keys, args)]
with self.pipe as pipe:
f = Future()
res = pipe.mget(keys)
def cb():
decode = self.valueparse.decode
f.set([None if r is None else decode(r) for r in res.resul... | def mget(self, keys, *args) | Returns a list of values ordered identically to ``keys`` | 5.534532 | 5.585235 | 0.990922 |
with self.pipe as pipe:
value = self.valueparse.encode(value)
return pipe.set(self.redis_key(name), value,
ex=ex, px=px, nx=nx, xx=xx) | def set(self, name, value, ex=None, px=None, nx=False, xx=False) | Set the value at key ``name`` to ``value``
``ex`` sets an expire flag on key ``name`` for ``ex`` seconds.
``px`` sets an expire flag on key ``name`` for ``px`` milliseconds.
``nx`` if set to True, set the value at key ``name`` to ``value`` if it
does not already exist.
``xx``... | 4.378314 | 5.104927 | 0.857665 |
with self.pipe as pipe:
return pipe.setnx(self.redis_key(name),
self.valueparse.encode(value)) | def setnx(self, name, value) | Set the value as a string in the key only if the key doesn't exist.
:param name: str the name of the redis key
:param value:
:return: Future() | 8.606144 | 8.931113 | 0.963614 |
with self.pipe as pipe:
return pipe.setex(self.redis_key(name),
value=self.valueparse.encode(value),
time=time) | def setex(self, name, value, time) | Set the value of key to ``value`` that expires in ``time``
seconds. ``time`` can be represented by an integer or a Python
timedelta object.
:param name: str the name of the redis key
:param value: str
:param time: secs
:return: Future() | 6.877781 | 6.957582 | 0.98853 |
with self.pipe as pipe:
return pipe.psetex(self.redis_key(name), time_ms=time_ms,
value=self.valueparse.encode(value=value)) | def psetex(self, name, value, time_ms) | Set the value of key ``name`` to ``value`` that expires in ``time_ms``
milliseconds. ``time_ms`` can be represented by an integer or a Python
timedelta object | 6.530608 | 8.231701 | 0.793349 |
with self.pipe as pipe:
return pipe.append(self.redis_key(name),
self.valueparse.encode(value)) | def append(self, name, value) | Appends the string ``value`` to the value at ``key``. If ``key``
doesn't already exist, create it with a value of ``value``.
Returns the new length of the value at ``key``.
:param name: str the name of the redis key
:param value: str
:return: Future() | 12.60727 | 10.162823 | 1.240528 |
with self.pipe as pipe:
return pipe.strlen(self.redis_key(name)) | def strlen(self, name) | Return the number of bytes stored in the value of the key
:param name: str the name of the redis key
:return: Future() | 9.521312 | 6.362952 | 1.496367 |
with self.pipe as pipe:
f = Future()
res = pipe.substr(self.redis_key(name), start=start, end=end)
def cb():
f.set(self.valueparse.decode(res.result))
pipe.on_execute(cb)
return f | def substr(self, name, start, end=-1) | Return a substring of the string at key ``name``. ``start`` and ``end``
are 0-based integers specifying the portion of the string to return.
:param name: str the name of the redis key
:param start: int
:param end: int
:return: Future() | 6.376853 | 4.985616 | 1.27905 |
with self.pipe as pipe:
return pipe.setrange(self.redis_key(name), offset, value) | def setrange(self, name, offset, value) | Overwrite bytes in the value of ``name`` starting at ``offset`` with
``value``. If ``offset`` plus the length of ``value`` exceeds the
length of the original value, the new value will be larger
than before.
If ``offset`` exceeds the length of the original value, null bytes
will b... | 5.407148 | 4.647405 | 1.163477 |
with self.pipe as pipe:
return pipe.setbit(self.redis_key(name), offset, value) | def setbit(self, name, offset, value) | Flag the ``offset`` in the key as ``value``. Returns a boolean
indicating the previous value of ``offset``.
:param name: str the name of the redis key
:param offset: int
:param value:
:return: Future() | 5.346113 | 4.606442 | 1.160573 |
with self.pipe as pipe:
return pipe.getbit(self.redis_key(name), offset) | def getbit(self, name, offset) | Returns a boolean indicating the value of ``offset`` in key
:param name: str the name of the redis key
:param offset: int
:return: Future() | 7.204951 | 5.017619 | 1.43593 |
with self.pipe as pipe:
return pipe.bitcount(self.redis_key(name), start=start, end=end) | def bitcount(self, name, start=None, end=None) | Returns the count of set bits in the value of ``key``. Optional
``start`` and ``end`` paramaters indicate which bytes to consider
:param name: str the name of the redis key
:param start: int
:param end: int
:return: Future() | 4.729884 | 4.156928 | 1.137831 |
with self.pipe as pipe:
return pipe.incr(self.redis_key(name), amount=amount) | def incr(self, name, amount=1) | increment the value for key by 1
:param name: str the name of the redis key
:param amount: int
:return: Future() | 6.279089 | 5.430674 | 1.156227 |
with self.pipe as pipe:
return pipe.incrby(self.redis_key(name), amount=amount) | def incrby(self, name, amount=1) | increment the value for key by value: int
:param name: str the name of the redis key
:param amount: int
:return: Future() | 5.539664 | 5.267106 | 1.051747 |
with self.pipe as pipe:
return pipe.incrbyfloat(self.redis_key(name), amount=amount) | def incrbyfloat(self, name, amount=1.0) | increment the value for key by value: float
:param name: str the name of the redis key
:param amount: int
:return: Future() | 5.466258 | 4.862602 | 1.124142 |
keys = [self.redis_key(k) for k in self._parse_values(keys)]
with self.pipe as pipe:
return pipe.sdiffstore(self.redis_key(dest), *keys) | def sdiffstore(self, dest, *keys) | Store the difference of sets specified by ``keys`` into a new
set named ``dest``. Returns the number of keys in the new set. | 4.527028 | 5.231448 | 0.865349 |
keys = [self.redis_key(k) for k in self._parse_values(keys, args)]
with self.pipe as pipe:
return pipe.sunionstore(self.redis_key(dest), *keys) | def sunionstore(self, dest, keys, *args) | Store the union of sets specified by ``keys`` into a new
set named ``dest``. Returns the number of members in the new set. | 4.330703 | 4.96361 | 0.872491 |
with self.pipe as pipe:
values = [self.valueparse.encode(v) for v in
self._parse_values(values, args)]
return pipe.sadd(self.redis_key(name), *values) | def sadd(self, name, values, *args) | Add the specified members to the Set.
:param name: str the name of the redis key
:param values: a list of values or a simple value.
:return: Future() | 5.919549 | 5.933077 | 0.99772 |
with self.pipe as pipe:
return pipe.scard(self.redis_key(name)) | def scard(self, name) | How many items in the set?
:param name: str the name of the redis key
:return: Future() | 5.921664 | 5.189627 | 1.141058 |
with self.pipe as pipe:
return pipe.sismember(self.redis_key(name),
self.valueparse.encode(value)) | def sismember(self, name, value) | Is the provided value is in the ``Set``?
:param name: str the name of the redis key
:param value: str
:return: Future() | 8.146777 | 7.754068 | 1.050646 |
with self.pipe as pipe:
f = Future()
res = pipe.srandmember(self.redis_key(name), number=number)
def cb():
if number is None:
f.set(self.valueparse.decode(res.result))
else:
f.set([self.valuepar... | def srandmember(self, name, number=None) | Return a random member of the set.
:param name: str the name of the redis key
:return: Future() | 3.69728 | 3.425266 | 1.079414 |
with self.pipe as pipe:
f = Future()
res = pipe.sscan(self.redis_key(name), cursor=cursor,
match=match, count=count)
def cb():
f.set((res[0], [self.valueparse.decode(v) for v in res[1]]))
pipe.on_execute(cb)
... | def sscan(self, name, cursor=0, match=None, count=None) | Incrementally return lists of elements in a set. Also return a cursor
indicating the scan position.
``match`` allows for filtering the keys by pattern
``count`` allows for hint the minimum number of returns
:param name: str the name of the redis key
:param cursor: int
... | 4.45565 | 5.16093 | 0.863342 |
if self._pipe is not None:
raise InvalidOperation('cannot pipeline scan operations')
cursor = '0'
while cursor != 0:
cursor, data = self.sscan(name, cursor=cursor,
match=match, count=count)
for item in data:
... | def sscan_iter(self, name, match=None, count=None) | Make an iterator using the SSCAN command so that the client doesn't
need to remember the cursor position.
``match`` allows for filtering the keys by pattern
``count`` allows for hint the minimum number of returns
:param name: str the name of the redis key
:param match: str... | 4.277506 | 4.568905 | 0.936221 |
map = {self.redis_key(k): k for k in self._parse_values(keys)}
keys = map.keys()
with self.pipe as pipe:
f = Future()
res = pipe.blpop(keys, timeout=timeout)
def cb():
if res.result:
k = map[res.result[0]]
... | def blpop(self, keys, timeout=0) | LPOP a value off of the first non-empty list
named in the ``keys`` list.
If none of the lists in ``keys`` has a value to LPOP, then block
for ``timeout`` seconds, or until a value gets pushed on to one
of the lists.
If timeout is 0, then block indefinitely. | 4.053048 | 4.571476 | 0.886595 |
with self.pipe as pipe:
return pipe.llen(self.redis_key(name)) | def llen(self, name) | Returns the length of the list.
:param name: str the name of the redis key
:return: Future() | 7.452789 | 5.887135 | 1.265945 |
with self.pipe as pipe:
f = Future()
res = pipe.lrange(self.redis_key(name), start, stop)
def cb():
f.set([self.valueparse.decode(v) for v in res.result])
pipe.on_execute(cb)
return f | def lrange(self, name, start, stop) | Returns a range of items.
:param name: str the name of the redis key
:param start: integer representing the start index of the range
:param stop: integer representing the size of the list.
:return: Future() | 5.677291 | 4.951479 | 1.146585 |
with self.pipe as pipe:
v_encode = self.valueparse.encode
values = [v_encode(v) for v in self._parse_values(values)]
return pipe.rpush(self.redis_key(name), *values) | def rpush(self, name, *values) | Push the value into the list from the *right* side
:param name: str the name of the redis key
:param values: a list of values or single value to push
:return: Future() | 5.143517 | 5.565763 | 0.924135 |
with self.pipe as pipe:
f = Future()
res = pipe.lpop(self.redis_key(name))
def cb():
f.set(self.valueparse.decode(res.result))
pipe.on_execute(cb)
return f | def lpop(self, name) | Pop the first object from the left.
:param name: str the name of the redis key
:return: Future() | 6.442774 | 5.417717 | 1.189205 |
with self.pipe as pipe:
f = Future()
res = pipe.rpoplpush(self.redis_key(src), self.redis_key(dst))
def cb():
f.set(self.valueparse.decode(res.result))
pipe.on_execute(cb)
return f | def rpoplpush(self, src, dst) | RPOP a value off of the ``src`` list and atomically LPUSH it
on to the ``dst`` list. Returns the value. | 4.986117 | 4.951437 | 1.007004 |
with self.pipe as pipe:
value = self.valueparse.encode(value)
return pipe.execute_command('LREM', self.redis_key(name),
num, value) | def lrem(self, name, value, num=1) | Remove first occurrence of value.
Can't use redis-py interface. It's inconstistent between
redis.Redis and redis.StrictRedis in terms of the kwargs.
Better to use the underlying execute_command instead.
:param name: str the name of the redis key
:param num:
:param v... | 7.082292 | 6.545565 | 1.081999 |
with self.pipe as pipe:
return pipe.ltrim(self.redis_key(name), start, end) | def ltrim(self, name, start, end) | Trim the list from start to end.
:param name: str the name of the redis key
:param start:
:param end:
:return: Future() | 5.694559 | 4.121742 | 1.38159 |
with self.pipe as pipe:
value = self.valueparse.encode(value)
return pipe.lset(self.redis_key(name), index, value) | def lset(self, name, index, value) | Set the value in the list at index *idx*
:param name: str the name of the redis key
:param value:
:param index:
:return: Future() | 6.337396 | 5.350111 | 1.184535 |
if nx:
_args = ['NX']
elif xx:
_args = ['XX']
else:
_args = []
if ch:
_args.append('CH')
if incr:
_args.append('INCR')
if isinstance(members, dict):
for member, score in members.items():
... | def zadd(self, name, members, score=1, nx=False,
xx=False, ch=False, incr=False) | Add members in the set and assign them the score.
:param name: str the name of the redis key
:param members: a list of item or a single item
:param score: the score the assign to the item(s)
:param nx:
:param xx:
:param ch:
:param incr:
:return: Futur... | 2.76654 | 2.815257 | 0.982695 |
with self.pipe as pipe:
return pipe.zincrby(self.redis_key(name),
value=self.valueparse.encode(value),
amount=amount) | def zincrby(self, name, value, amount=1) | Increment the score of the item by `value`
:param name: str the name of the redis key
:param value:
:param amount:
:return: | 6.243103 | 7.249387 | 0.86119 |
with self.pipe as pipe:
return pipe.zrevrank(self.redis_key(name),
self.valueparse.encode(value)) | def zrevrank(self, name, value) | Returns the ranking in reverse order for the member
:param name: str the name of the redis key
:param member: str | 7.579888 | 10.371478 | 0.73084 |
with self.pipe as pipe:
f = Future()
res = pipe.zrange(
self.redis_key(name), start, end, desc=desc,
withscores=withscores, score_cast_func=score_cast_func)
def cb():
if withscores:
f.set([(self.val... | def zrange(self, name, start, end, desc=False, withscores=False,
score_cast_func=float) | Returns all the elements including between ``start`` (non included)
and ``stop`` (included).
:param name: str the name of the redis key
:param start:
:param end:
:param desc:
:param withscores:
:param score_cast_func:
:return: | 3.118463 | 3.332734 | 0.935707 |
with self.pipe as pipe:
f = Future()
res = pipe.zrangebyscore(self.redis_key(name), min, max,
start=start, num=num,
withscores=withscores,
score_cast_func=score_cast_fu... | def zrangebyscore(self, name, min, max, start=None, num=None,
withscores=False, score_cast_func=float) | Returns the range of elements included between the scores (min and max)
:param name: str the name of the redis key
:param min:
:param max:
:param start:
:param num:
:param withscores:
:param score_cast_func:
:return: Future() | 2.782237 | 2.739811 | 1.015485 |
with self.pipe as pipe:
return pipe.zcard(self.redis_key(name)) | def zcard(self, name) | Returns the cardinality of the SortedSet.
:param name: str the name of the redis key
:return: Future() | 5.994072 | 5.748384 | 1.04274 |
with self.pipe as pipe:
return pipe.zcount(self.redis_key(name), min, max) | def zcount(self, name, min, max) | Returns the number of elements in the sorted set at key ``name`` with
a score between ``min`` and ``max``.
:param name: str
:param min: float
:param max: float
:return: Future() | 4.798388 | 6.29684 | 0.762031 |
with self.pipe as pipe:
return pipe.zscore(self.redis_key(name),
self.valueparse.encode(value)) | def zscore(self, name, value) | Return the score of an element
:param name: str the name of the redis key
:param value: the element in the sorted set key
:return: Future() | 8.8833 | 7.727228 | 1.14961 |
with self.pipe as pipe:
return pipe.zremrangebyrank(self.redis_key(name), min, max) | def zremrangebyrank(self, name, min, max) | Remove a range of element between the rank ``start`` and
``stop`` both included.
:param name: str the name of the redis key
:param min:
:param max:
:return: Future() | 4.053837 | 4.320144 | 0.938357 |
with self.pipe as pipe:
return pipe.zremrangebyscore(self.redis_key(name), min, max) | def zremrangebyscore(self, name, min, max) | Remove a range of element by between score ``min_value`` and
``max_value`` both included.
:param name: str the name of the redis key
:param min:
:param max:
:return: Future() | 3.988577 | 4.292539 | 0.929188 |
with self.pipe as pipe:
value = self.valueparse.encode(value)
return pipe.zrank(self.redis_key(name), value) | def zrank(self, name, value) | Returns the rank of the element.
:param name: str the name of the redis key
:param value: the element in the sorted set | 6.973853 | 8.086412 | 0.862416 |
with self.pipe as pipe:
return pipe.zlexcount(self.redis_key(name), min, max) | def zlexcount(self, name, min, max) | Return the number of items in the sorted set between the
lexicographical range ``min`` and ``max``.
:param name: str the name of the redis key
:param min: int or '-inf'
:param max: int or '+inf'
:return: Future() | 4.902706 | 4.766024 | 1.028679 |
with self.pipe as pipe:
f = Future()
res = pipe.zrevrangebylex(self.redis_key(name), max, min,
start=start, num=num)
def cb():
f.set([self.valueparse.decode(v) for v in res])
pipe.on_execute(cb)
... | def zrevrangebylex(self, name, max, min, start=None, num=None) | Return the reversed lexicographical range of values from the sorted set
between ``max`` and ``min``.
If ``start`` and ``num`` are specified, then return a slice of the
range.
:param name: str the name of the redis key
:param max: int or '+inf'
:param min: int or '-... | 4.372047 | 4.193177 | 1.042657 |
with self.pipe as pipe:
return pipe.zremrangebylex(self.redis_key(name), min, max) | def zremrangebylex(self, name, min, max) | Remove all elements in the sorted set between the
lexicographical range specified by ``min`` and ``max``.
Returns the number of elements removed.
:param name: str the name of the redis key
:param min: int or -inf
:param max: into or +inf
:return: Future() | 3.783694 | 4.086477 | 0.925906 |
with self.pipe as pipe:
keys = [self.redis_key(k) for k in keys]
return pipe.zunionstore(self.redis_key(dest), keys,
aggregate=aggregate) | def zunionstore(self, dest, keys, aggregate=None) | Union multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided. | 3.455218 | 3.954804 | 0.873676 |
with self.pipe as pipe:
f = Future()
res = pipe.zscan(self.redis_key(name), cursor=cursor,
match=match, count=count,
score_cast_func=score_cast_func)
def cb():
f.set((res[0], [(self.valueparse... | def zscan(self, name, cursor=0, match=None, count=None,
score_cast_func=float) | Incrementally return lists of elements in a sorted set. Also return a
cursor indicating the scan position.
``match`` allows for filtering the members by pattern
``count`` allows for hint the minimum number of returns
``score_cast_func`` a callable used to cast the score return value | 3.632604 | 5.068698 | 0.716674 |
if self._pipe is not None:
raise InvalidOperation('cannot pipeline scan operations')
cursor = '0'
while cursor != 0:
cursor, data = self.zscan(name, cursor=cursor, match=match,
count=count,
... | def zscan_iter(self, name, match=None, count=None,
score_cast_func=float) | Make an iterator using the ZSCAN command so that the client doesn't
need to remember the cursor position.
``match`` allows for filtering the keys by pattern
``count`` allows for hint the minimum number of returns
``score_cast_func`` a callable used to cast the score return value | 3.164255 | 4.124876 | 0.767115 |
try:
field_validator = cls.fields[member]
except KeyError:
return cls.valueparse.encode(value)
return field_validator.encode(value) | def _value_encode(cls, member, value) | Internal method used to encode values into the hash.
:param member: str
:param value: multi
:return: bytes | 5.831045 | 6.998676 | 0.833164 |
if value is None:
return None
try:
field_validator = cls.fields[member]
except KeyError:
return cls.valueparse.decode(value)
return field_validator.decode(value) | def _value_decode(cls, member, value) | Internal method used to decode values from redis hash
:param member: str
:param value: bytes
:return: multi | 4.96109 | 5.641665 | 0.879366 |
with self.pipe as pipe:
return pipe.hlen(self.redis_key(name)) | def hlen(self, name) | Returns the number of elements in the Hash.
:param name: str the name of the redis key
:return: Future() | 7.442523 | 5.544691 | 1.342279 |
with self.pipe as pipe:
return pipe.hstrlen(self.redis_key(name), key) | def hstrlen(self, name, key) | Return the number of bytes stored in the value of ``key``
within hash ``name`` | 5.173167 | 6.961902 | 0.743068 |
with self.pipe as pipe:
value = self._value_encode(key, value)
key = self.memberparse.encode(key)
return pipe.hset(self.redis_key(name), key, value) | def hset(self, name, key, value) | Set ``member`` in the Hash at ``value``.
:param name: str the name of the redis key
:param value:
:param key: the member of the hash key
:return: Future() | 5.960878 | 6.299878 | 0.946189 |
with self.pipe as pipe:
m_encode = self.memberparse.encode
keys = [m_encode(m) for m in self._parse_values(keys)]
return pipe.hdel(self.redis_key(name), *keys) | def hdel(self, name, *keys) | Delete one or more hash field.
:param name: str the name of the redis key
:param keys: on or more members to remove from the key.
:return: Future() | 6.895482 | 7.126886 | 0.967531 |
with self.pipe as pipe:
f = Future()
res = pipe.hkeys(self.redis_key(name))
def cb():
m_decode = self.memberparse.decode
f.set([m_decode(v) for v in res.result])
pipe.on_execute(cb)
return f | def hkeys(self, name) | Returns all fields name in the Hash.
:param name: str the name of the redis key
:return: Future | 6.817817 | 6.089191 | 1.119659 |
with self.pipe as pipe:
f = Future()
res = pipe.hgetall(self.redis_key(name))
def cb():
data = {}
m_decode = self.memberparse.decode
v_decode = self._value_decode
for k, v in res.result.items():
... | def hgetall(self, name) | Returns all the fields and values in the Hash.
:param name: str the name of the redis key
:return: Future() | 4.021454 | 3.653886 | 1.100597 |
with self.pipe as pipe:
f = Future()
res = pipe.hget(self.redis_key(name),
self.memberparse.encode(key))
def cb():
f.set(self._value_decode(key, res.result))
pipe.on_execute(cb)
return f | def hget(self, name, key) | Returns the value stored in the field, None if the field doesn't exist.
:param name: str the name of the redis key
:param key: the member of the hash
:return: Future() | 7.010395 | 6.171947 | 1.135848 |
with self.pipe as pipe:
return pipe.hexists(self.redis_key(name),
self.memberparse.encode(key)) | def hexists(self, name, key) | Returns ``True`` if the field exists, ``False`` otherwise.
:param name: str the name of the redis key
:param key: the member of the hash
:return: Future() | 9.506326 | 9.62804 | 0.987358 |
with self.pipe as pipe:
return pipe.hincrby(self.redis_key(name),
self.memberparse.encode(key),
amount) | def hincrby(self, name, key, amount=1) | Increment the value of the field.
:param name: str the name of the redis key
:param increment: int
:param field: str
:return: Future() | 7.798491 | 8.594195 | 0.907414 |
member_encode = self.memberparse.encode
keys = [k for k in self._parse_values(keys, args)]
with self.pipe as pipe:
f = Future()
res = pipe.hmget(self.redis_key(name),
[member_encode(k) for k in keys])
def cb():
... | def hmget(self, name, keys, *args) | Returns the values stored in the fields.
:param name: str the name of the redis key
:param fields:
:return: Future() | 5.178611 | 4.956488 | 1.044815 |
with self.pipe as pipe:
m_encode = self.memberparse.encode
mapping = {m_encode(k): self._value_encode(k, v)
for k, v in mapping.items()}
return pipe.hmset(self.redis_key(name), mapping) | def hmset(self, name, mapping) | Sets or updates the fields with their corresponding values.
:param name: str the name of the redis key
:param mapping: a dict with keys and values
:return: Future() | 5.004479 | 5.457565 | 0.91698 |
with self.pipe as pipe:
f = Future()
res = pipe.hscan(self.redis_key(name), cursor=cursor,
match=match, count=count)
def cb():
data = {}
m_decode = self.memberparse.decode
for k, v in res[1... | def hscan(self, name, cursor=0, match=None, count=None) | Incrementally return key/value slices in a hash. Also return a cursor
indicating the scan position.
``match`` allows for filtering the keys by pattern
``count`` allows for hint the minimum number of returns | 3.928316 | 4.789117 | 0.820259 |
sources = [self.redis_key(s) for s in sources]
with self.pipe as pipe:
return pipe.execute_command('PFCOUNT', *sources) | def pfcount(self, *sources) | Return the approximated cardinality of
the set observed by the HyperLogLog at key(s).
Using the execute_command because redis-py-cluster disabled it
unnecessarily. but you can only send one key at a time in that case,
or only keys that map to the same keyslot.
Use at your own ri... | 4.735233 | 6.02775 | 0.785572 |
sources = [self.redis_key(k) for k in sources]
with self.pipe as pipe:
return pipe.pfmerge(self.redis_key(dest), *sources) | def pfmerge(self, dest, *sources) | Merge N different HyperLogLogs into a single one.
:param dest:
:param sources:
:return: | 4.311575 | 5.478809 | 0.786955 |
stats_dict = {}
with os.popen('bjobs -o "jobid run_time cpu_used queue slots stat exit_code start_time estimated_start_time finish_time delimiter=\'|\'" -noheader ' + str(job_id)) as f:
try:
line = f.readline()
cols = line.split('|')
stats_dict['job_id'] = cols... | def job_stats_enhanced(job_id) | Get full job and step stats for job_id | 2.795787 | 2.763106 | 1.011828 |
self._emt_id = emt_id
self._emt_pass = emt_pass
# Initialize modules
self.bus = BusApi(self)
self.geo = GeoApi(self)
self.parking = ParkingApi(self) | def initialize(self, emt_id, emt_pass) | Manual initialization of the interface attributes.
This is useful when the interface must be declare but initialized later
on with parsed configuration values.
Args:
emt_id (str): ID given by the server upon registration
emt_pass (str): Token given by the server upon re... | 3.120222 | 3.410403 | 0.914913 |
if service == 'bus':
endpoints = ENDPOINTS_BUS
elif service == 'geo':
endpoints = ENDPOINTS_GEO
else:
# Unknown service
return None
if endpoint not in endpoints:
# Unknown endpoint
return None
ur... | def request_openbus(self, service, endpoint, **kwargs) | Make a request to the given endpoint of the ``openbus`` server.
This returns the plain JSON (dict) response which can then be parsed
using one of the implemented types.
Args:
service (str): Service to fetch ('bus' or 'geo').
endpoint (str): Endpoint to send the request ... | 4.358946 | 4.35194 | 1.00161 |
if endpoint not in ENDPOINTS_PARKING:
# Unknown endpoint
return None
url = URL_OPENBUS + ENDPOINTS_PARKING[endpoint]
# Append additional info to URL
lang = url_args.get('lang', 'ES')
address = url_args.get('address', '')
url = url.forma... | def request_parking(self, endpoint, url_args={}, **kwargs) | Make a request to the given endpoint of the ``parking`` server.
This returns the plain JSON (dict) response which can then be parsed
using one of the implemented types.
Args:
endpoint (str): Endpoint to send the request to.
This string corresponds to the key in the ... | 6.365916 | 6.908209 | 0.9215 |
terms = []
keywords = {}
for word in term.split():
if word.count(':') == 1:
k, v = word.split(u':')
if k and v:
keywords[k] = v
elif k or v:
terms.append(k or v)
else:
terms.append(word)
term = u' '.join... | def parseSearchTerm(term) | Turn a string search query into a two-tuple of a search term and a
dictionary of search keywords. | 2.501665 | 2.271449 | 1.101352 |
try:
return util.getPassword(prompt=prompt,
confirmPrompt=confirmPassword,
confirm=True)
except TypeError:
return util.getPassword(prompt=prompt,
confirm=True) | def gtpswd(prompt, confirmPassword) | Temporary wrapper for Twisted's getPassword until a version that supports
customizing the 'confirm' prompt is released. | 3.938399 | 3.136309 | 1.255744 |
privateKey = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend())
publicKey = privateKey.public_key()
name = x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, hostname)])
certificate = (
... | def _createCert(self, hostname, serial) | Create a self-signed X.509 certificate.
@type hostname: L{unicode}
@param hostname: The hostname this certificate should be valid for.
@type serial: L{int}
@param serial: The serial number the certificate should have.
@rtype: L{bytes}
@return: The serialized certificat... | 1.350441 | 1.372752 | 0.983748 |
certPath = siteStore.filesdir.child("server.pem")
if generateCert and not certPath.exists():
certPath.setContent(self._createCert(domain, genSerial()))
# Install the base Mantissa offering.
IOfferingTechnician(siteStore).installOffering(baseOffering)
# Make... | def installSite(self, siteStore, domain, publicURL, generateCert=True) | Create the necessary items to run an HTTP server and an SSH server. | 5.760328 | 5.587714 | 1.030892 |
api = self.doapi_manager
return api._tag(api.request(self.url)["tag"]) | def fetch(self) | Fetch & return a new `Tag` object representing the tag's current state
:rtype: Tag
:raises DOAPIError: if the API endpoint replies with an error (e.g., if
the tag no longer exists) | 45.433018 | 28.637682 | 1.586477 |
# The `_tag` is to avoid conflicts with MutableMapping.update.
api = self.doapi_manager
return api._tag(api.request(self.url, method='PUT',
data={"name": name})["tag"]) | def update_tag(self, name) | Update (i.e., rename) the tag
:param str name: the new name for the tag
:return: an updated `Tag` object
:rtype: Tag
:raises DOAPIError: if the API endpoint replies with an error | 19.293745 | 23.728605 | 0.813101 |
self.doapi_manager.request(self.url + '/resources', method='POST',
data={"resources": _to_taggable(resources)}) | def add(self, *resources) | Apply the tag to one or more resources
:param resources: one or more `Resource` objects to which tags can be
applied
:return: `None`
:raises DOAPIError: if the API endpoint replies with an error | 18.718409 | 13.479099 | 1.388699 |
r
api = self.doapi_manager
return map(api._action, api.request('/v2/droplets/actions', method='POST', params={"tag_name": self.name}, data=data)["actions"]) | def act_on_droplets(self, **data) | r"""
Perform an arbitrary action on all of the droplets to which the tag is
applied. ``data`` will be serialized as JSON and POSTed to the proper
API endpoint. All currently-documented actions require the POST body
to be a JSON object containing, at a minimum, a ``"type"`` field.
... | 14.576025 | 11.437521 | 1.274404 |
from docutils.nodes import inline, make_id
from docutils.parsers.rst.roles import set_classes
def create_badge_role(color=None):
def badge_role(name, rawtext, text, lineno, inliner,
options=None, content=None):
options = options or {}
set_classes(... | def add_badge_roles(app) | Add ``badge`` role to your sphinx documents. It can create
a colorful badge inline. | 1.869754 | 1.793158 | 1.042716 |
from docutils.nodes import reference
from docutils.parsers.rst.roles import set_classes
base_url = 'https://github.com/{}'.format(repo)
def github_role(name, rawtext, text, lineno, inliner,
options=None, content=None):
if '#' in text:
t, n = text.split('#',... | def add_github_roles(app, repo) | Add ``gh`` role to your sphinx documents. It can generate GitHub
links easily::
:gh:`issue#57` will generate the issue link
:gh:`PR#85` will generate the pull request link
Use this function in ``conf.py`` to enable this feature::
def setup(app):
sphinx_typlog_theme.add_git... | 2.020287 | 2.001146 | 1.009565 |
task = cls.task(target=fn, args=args, kwargs=kwargs)
task.start()
return task | def promise(cls, fn, *args, **kwargs) | Used to build a task based on a callable function and the arguments.
Kick it off and start execution of the task.
:param fn: callable
:param args: tuple
:param kwargs: dict
:return: SynchronousTask or AsynchronousTask | 3.954502 | 5.318185 | 0.743581 |
if interfaces is ALL_IMPLEMENTED:
names = ALL_IMPLEMENTED_DB
else:
_checkConflictingNames(interfaces)
names = u','.join(map(qual, interfaces))
return names | def _interfacesToNames(interfaces) | Convert from a list of interfaces to a unicode string of names suitable for
storage in the database.
@param interfaces: an iterable of Interface objects.
@return: a unicode string, a comma-separated list of names of interfaces.
@raise ConflictingNames: if any of the names conflict: see
L{_checkCo... | 11.883242 | 11.950835 | 0.994344 |
"Upgrader from Share version 1 to version 2."
sharedInterfaces = []
attrs = set(oldShare.sharedAttributeNames.split(u','))
for iface in implementedBy(oldShare.sharedItem.__class__):
if set(iface) == attrs or attrs == set('*'):
sharedInterfaces.append(iface)
newShare = oldShare.u... | def upgradeShare1to2(oldShare) | Upgrader from Share version 1 to version 2. | 5.765236 | 5.255495 | 1.096992 |
def tx():
def addToEveryone(newAuthenticatedRole):
newAuthenticatedRole.becomeMemberOf(getEveryoneRole(store))
return newAuthenticatedRole
return store.findOrCreate(Role, addToEveryone, externalID=u'Authenticated')
return store.transact(tx) | def getAuthenticatedRole(store) | Get the base 'Authenticated' role for this store, which is the role that is
given to every user who is explicitly identified by a non-anonymous
username. | 10.187109 | 10.413342 | 0.978275 |
if not primaryRoleName:
return getEveryoneRole(store)
ff = store.findUnique(Role, Role.externalID == primaryRoleName, default=None)
if ff is not None:
return ff
authRole = getAuthenticatedRole(store)
if createIfNotFound:
role = Role(store=store,
exter... | def getPrimaryRole(store, primaryRoleName, createIfNotFound=False) | Get Role object corresponding to an identifier name. If the role name
passed is the empty string, it is assumed that the user is not
authenticated, and the 'Everybody' role is primary. If the role name
passed is non-empty, but has no corresponding role, the 'Authenticated'
role - which is a member of ... | 4.05043 | 3.272703 | 1.237641 |
for (localpart, domain) in accountNames:
return getPrimaryRole(store, u'%s@%s' % (localpart, domain),
createIfNotFound=True)
raise ValueError("Cannot get named role for unnamed account.") | def getAccountRole(store, accountNames) | Retrieve the first Role in the given store which corresponds an account
name in C{accountNames}.
Note: the implementation currently ignores all of the values in
C{accountNames} except for the first.
@param accountNames: A C{list} of two-tuples of account local parts and
domains.
@raise Va... | 8.11272 | 7.224526 | 1.122941 |
warnings.warn("Use Role.shareItem() instead of sharing.shareItem().",
PendingDeprecationWarning,
stacklevel=2)
if toRole is None:
if toName is not None:
toRole = getPrimaryRole(sharedItem.store, toName, True)
else:
toRole = getEver... | def shareItem(sharedItem, toRole=None, toName=None, shareID=None,
interfaces=ALL_IMPLEMENTED) | Share an item with a given role. This provides a way to expose items to
users for later retrieval with L{Role.getShare}.
This API is slated for deprecation. Prefer L{Role.shareItem} in new code.
@param sharedItem: an item to be shared.
@param toRole: a L{Role} instance which represents the group th... | 3.421571 | 3.501132 | 0.977276 |
L = [interface]
for baseInterface in interface.__bases__:
if baseInterface is not Interface:
L.extend(_linearize(baseInterface))
return L | def _linearize(interface) | Return a list of all the bases of a given interface in depth-first order.
@param interface: an Interface object.
@return: a L{list} of Interface objects, the input in all its bases, in
subclass-to-base-class, depth-first order. | 4.316882 | 4.598524 | 0.938754 |
shorter, longer = sorted([_linearize(x)[::-1] for x in zi1, zi2],
key=len)
for n in range(len(shorter)):
if shorter[n] != longer[n]:
if n == 0:
return None
return shorter[n-1]
return shorter[-1] | def _commonParent(zi1, zi2) | Locate the common parent of two Interface objects.
@param zi1: a zope Interface object.
@param zi2: another Interface object.
@return: the rightmost common parent of the two provided Interface objects,
or None, if they have no common parent other than Interface itself. | 4.280279 | 5.047709 | 0.847965 |
names = {}
for interface in interfaces:
for name in interface:
if name in names:
otherInterface = names[name]
parent = _commonParent(interface, otherInterface)
if parent is None or name not in parent:
raise ConflictingN... | def _checkConflictingNames(interfaces) | Raise an exception if any of the names present in the given interfaces
conflict with each other.
@param interfaces: a list of Zope Interface objects.
@return: None
@raise ConflictingNames: if any of the attributes of the provided
interfaces are the same, and they do not have a common base interfa... | 3.459358 | 3.400951 | 1.017174 |
warnings.warn("Use Role.getShare() instead of sharing.getShare().",
PendingDeprecationWarning,
stacklevel=2)
return role.getShare(shareID) | def getShare(store, role, shareID) | Retrieve the accessible facet of an Item previously shared with
L{shareItem}.
This method is pending deprecation, and L{Role.getShare} should be
preferred in new code.
@param store: an axiom store (XXX must be the same as role.store)
@param role: a L{Role}, the primary role for a user attempting ... | 5.076705 | 6.784111 | 0.748323 |
warnings.warn(
"Use Role.asAccessibleTo() instead of sharing.asAccessibleTo().",
PendingDeprecationWarning,
stacklevel=2)
return role.asAccessibleTo(query) | def asAccessibleTo(role, query) | Return an iterable which yields the shared proxies that are available to
the given role, from the given query.
This method is pending deprecation, and L{Role.asAccessibleTo} should be
preferred in new code.
@param role: The role to retrieve L{SharedProxy}s for.
@param query: An Axiom query descri... | 4.593656 | 4.868026 | 0.943638 |
sharedItem.store.query(Share, Share.sharedItem == sharedItem).deleteFromStore() | def unShare(sharedItem) | Remove all instances of this item from public or shared view. | 12.746648 | 15.276835 | 0.834378 |
for r in role.allRoles():
share = store.findFirst(Share, Share.sharedTo == r,
sort=Share.storeID.ascending)
if share is not None:
return share.sharedItem
raise NoSuchShare("Why, that user hasn't shared anything at all!") | def randomEarlyShared(store, role) | If there are no explicitly-published public index pages to display, find a
shared item to present to the user as first. | 9.663421 | 9.124369 | 1.059078 |
localpart = None
for (localpart, domain) in userbase.getAccountNames(sharedItem.store):
break
if localpart is None:
raise NoSuchShare()
for share in sharedItem.store.query(Share,
Share.sharedItem == sharedItem):... | def fromSharedItem(cls, sharedItem) | Return an instance of C{cls} derived from the given L{Item} that has
been shared.
Note that this API does not provide any guarantees of which result it
will choose. If there are are multiple possible return values, it will
select and return only one. Items may be shared under multiple... | 4.993896 | 4.207154 | 1.187001 |
return Box(shareID=obj.shareID.encode('utf-8'),
localpart=obj.localpart.encode('utf-8'),
domain=obj.domain.encode('utf-8')).serialize() | def toString(self, obj) | Convert the given L{Identifier} to a string. | 6.114024 | 5.607667 | 1.090297 |
box = parseString(inString)[0]
return Identifier(shareID=box['shareID'].decode('utf-8'),
localpart=box['localpart'].decode('utf-8'),
domain=box['domain'].decode('utf-8')) | def fromString(self, inString) | Convert the given string to an L{Identifier}. | 5.529715 | 4.147334 | 1.333318 |
self.store.findOrCreate(RoleRelationship,
group=groupRole,
member=self) | def becomeMemberOf(self, groupRole) | Instruct this (user or group) Role to become a member of a group role.
@param groupRole: The role that this group should become a member of. | 11.051174 | 12.029752 | 0.918654 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.