signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def which(program, mode=os.F_OK | os.X_OK, path=None): | try:<EOL><INDENT>from shutil import which as shwhich<EOL>return shwhich(program, mode, path)<EOL><DEDENT>except ImportError:<EOL><INDENT>def is_exe(fpath):<EOL><INDENT>return os.path.isfile(fpath) and os.access(fpath, os.X_OK)<EOL><DEDENT>fpath, _ = os.path.split(program)<EOL>if fpath:<EOL><INDENT>if is_exe(program):<E... | Mimics the Unix utility which.
For python3.3+, shutil.which provides all of the required functionality.
An implementation is provided in case shutil.which does
not exist.
:param program: (required) string
Name of program (can be fully-qualified path as well)
:param mode: (optional) integer flag bits
Perm... | f10137:m2 |
def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2,<EOL>D1D2, D1R2, D2R1, R1R2,<EOL>estimator='<STR_LIT>'): | import numpy as np<EOL>pair_counts = dict()<EOL>fields = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>arrays = [D1D2, D1R2, D2R1, R1R2]<EOL>for (field, array) in zip(fields, arrays):<EOL><INDENT>try:<EOL><INDENT>npairs = array['<STR_LIT>']<EOL>pair_counts[field] = npairs<EOL><DEDENT>except IndexError:<EOL><... | Converts raw pair counts to a correlation function.
Parameters
----------
ND1 : integer
Number of points in the first dataset
ND2 : integer
Number of points in the second dataset
NR1 : integer
Number of points in the randoms for first dataset
NR2 : integer
Number of points in the randoms for second ... | f10139:m0 |
def convert_rp_pi_counts_to_wp(ND1, ND2, NR1, NR2,<EOL>D1D2, D1R2, D2R1, R1R2,<EOL>nrpbins, pimax, dpi=<NUM_LIT:1.0>,<EOL>estimator='<STR_LIT>'): | import numpy as np<EOL>if dpi <= <NUM_LIT:0.0>:<EOL><INDENT>msg = '<STR_LIT>''<STR_LIT>'.format(dpi)<EOL>raise ValueError(msg)<EOL><DEDENT>xirppi = convert_3d_counts_to_cf(ND1, ND2, NR1, NR2,<EOL>D1D2, D1R2, D2R1, R1R2,<EOL>estimator=estimator)<EOL>wp = np.empty(nrpbins)<EOL>npibins = len(xirppi) // nrpbins<EOL>if ((np... | Converts raw pair counts to a correlation function.
Parameters
----------
ND1 : integer
Number of points in the first dataset
ND2 : integer
Number of points in the second dataset
NR1 : integer
Number of points in the randoms for first dataset
NR2 : integer
Number of points in the randoms for second ... | f10139:m1 |
def return_file_with_rbins(rbins): | is_string = False<EOL>delete_after_use = False<EOL>try:<EOL><INDENT>if isinstance(rbins, basestring):<EOL><INDENT>is_string = True<EOL><DEDENT><DEDENT>except NameError:<EOL><INDENT>if isinstance(rbins, str):<EOL><INDENT>is_string = True<EOL><DEDENT><DEDENT>if is_string:<EOL><INDENT>if file_exists(rbins):<EOL><INDENT>de... | Helper function to ensure that the ``binfile`` required by the Corrfunc
extensions is a actually a string.
Checks if the input is a string and file; return if True. If not, and
the input is an array, then a temporary file is created and the contents
of rbins is written out.
Parameters
-----------
rbins: string or arr... | f10139:m2 |
def fix_cz(cz): | <EOL>max_cz_threshold = <NUM_LIT><EOL>try:<EOL><INDENT>input_dtype = cz.dtype<EOL><DEDENT>except:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT>if max(cz) < max_cz_threshold:<EOL><INDENT>speed_of_light = <NUM_LIT><EOL>cz *= speed_of_light<EOL><DEDENT>return cz.astype(input_dtype)<EOL> | Multiplies the input array by speed of light, if the input values are
too small.
Essentially, converts redshift into `cz`, if the user passed
redshifts instead of `cz`.
Parameters
-----------
cz: array-like, reals
An array containing ``[Speed of Light *] redshift`` values.
Returns
---------
cz: array-like
Actu... | f10139:m3 |
def fix_ra_dec(ra, dec): | try:<EOL><INDENT>input_dtype = ra.dtype<EOL><DEDENT>except:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT>if ra is None or dec is None:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>if min(ra) < <NUM_LIT:0.0>:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>ra += <NUM_LIT><... | Wraps input RA and DEC values into range expected by the extensions.
Parameters
------------
RA: array-like, units must be degrees
Right Ascension values (astronomical longitude)
DEC: array-like, units must be degrees
Declination values (astronomical latitude)
Returns
--------
Tuple (RA, DEC): array-like
... | f10139:m4 |
def translate_isa_string_to_enum(isa): | msg = "<STR_LIT>""<STR_LIT>".format(type(isa))<EOL>try:<EOL><INDENT>if not isinstance(isa, basestring):<EOL><INDENT>raise TypeError(msg)<EOL><DEDENT><DEDENT>except NameError:<EOL><INDENT>if not isinstance(isa, str):<EOL><INDENT>raise TypeError(msg)<EOL><DEDENT><DEDENT>valid_isa = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',... | Helper function to convert an user-supplied string to the
underlying enum in the C-API. The extensions only have specific
implementations for AVX, SSE42 and FALLBACK. Any other value
will raise a ValueError.
Parameters
------------
isa: string
A string containing the desired instruction set. Valid values are
['A... | f10139:m5 |
def compute_nbins(max_diff, binsize,<EOL>refine_factor=<NUM_LIT:1>,<EOL>max_nbins=None): | if max_diff <= <NUM_LIT:0> or binsize <= <NUM_LIT:0>:<EOL><INDENT>msg = '<STR_LIT>''<STR_LIT>'.format(max_diff, binsize)<EOL>raise ValueError(msg)<EOL><DEDENT>if max_nbins is not None and max_nbins < <NUM_LIT:1>:<EOL><INDENT>msg = '<STR_LIT>''<STR_LIT>'.format(max_nbins)<EOL>raise ValueError(msg)<EOL><DEDENT>if refine_... | Helper utility to find the number of bins for
that satisfies the constraints of (binsize, refine_factor, and max_nbins).
Parameters
------------
max_diff : double
Max. difference (spatial or angular) to be spanned,
(i.e., range of allowed domain values)
binsize : double
Min. allowed binsize (spatial or angu... | f10139:m6 |
def gridlink_sphere(thetamax,<EOL>ra_limits=None,<EOL>dec_limits=None,<EOL>link_in_ra=True,<EOL>ra_refine_factor=<NUM_LIT:1>, dec_refine_factor=<NUM_LIT:1>,<EOL>max_ra_cells=<NUM_LIT:100>, max_dec_cells=<NUM_LIT:200>,<EOL>return_num_ra_cells=False,<EOL>input_in_degrees=True): | from math import radians, pi<EOL>import numpy as np<EOL>if input_in_degrees:<EOL><INDENT>thetamax = radians(thetamax)<EOL>if ra_limits:<EOL><INDENT>ra_limits = [radians(x) for x in ra_limits]<EOL><DEDENT>if dec_limits:<EOL><INDENT>dec_limits = [radians(x) for x in dec_limits]<EOL><DEDENT><DEDENT>if not ra_limits:<EOL><... | A method to optimally partition spherical regions such that pairs of
points within a certain angular separation, ``thetamax``, can be quickly
computed.
Generates the binning scheme used in :py:mod:`Corrfunc.mocks.DDtheta_mocks`
for a spherical region in Right Ascension (RA), Declination (DEC)
and a maximum angula... | f10139:m7 |
def convert_to_native_endian(array): | if array is None:<EOL><INDENT>return array<EOL><DEDENT>import numpy as np<EOL>array = np.asanyarray(array)<EOL>system_is_little_endian = (sys.byteorder == '<STR_LIT>') <EOL>array_is_little_endian = (array.dtype.byteorder == '<STR_LIT:<>')<EOL>if (array_is_little_endian != system_is_little_endian) and not (array.dtype... | Returns the supplied array in native endian byte-order.
If the array already has native endianness, then the
same array is returned.
Parameters
----------
array: np.ndarray
The array to convert
Returns
-------
new_array: np.ndarray
The array in native-endian byte-order.
Example
-------
>>> import numpy as np... | f10139:m8 |
def is_native_endian(array): | if array is None:<EOL><INDENT>return True<EOL><DEDENT>import numpy as np<EOL>array = np.asanyarray(array)<EOL>system_is_little_endian = (sys.byteorder == '<STR_LIT>')<EOL>array_is_little_endian = (array.dtype.byteorder == '<STR_LIT:<>')<EOL>return (array_is_little_endian == system_is_little_endian) or (array.dtype.byte... | Checks whether the given array is native-endian.
None evaluates to True.
Parameters
----------
array: np.ndarray
The array to check
Returns
-------
is_native: bool
Whether the endianness is native
Example
-------
>>> import numpy as np
>>> import sys
>>> sys_is_le = sys.byteorder == 'little'
>>> native_code ... | f10139:m9 |
def sys_pipes(): | kwargs = {'<STR_LIT>':None if sys.stdout.isatty() else sys.stdout,<EOL>'<STR_LIT>':None if sys.stderr.isatty() else sys.stderr }<EOL>return wurlitzer.pipes(**kwargs)<EOL> | We can use the Wurlitzer package to redirect stdout and stderr
from the command line into a Jupyter notebook. But if we're not
in a notebook, this isn't safe because we can't redirect stdout
to itself. This function is a thin wrapper that checks if the
stdout/err streams are TTYs and enables output redirection
based ... | f10139:m10 |
def _convert_cell_timer(cell_time_lst): | import numpy as np<EOL>from future.utils import bytes_to_native_str<EOL>dtype = np.dtype([(bytes_to_native_str(b'<STR_LIT>'), np.int64),<EOL>(bytes_to_native_str(b'<STR_LIT>'), np.int64),<EOL>(bytes_to_native_str(b'<STR_LIT>'), np.int64),<EOL>(bytes_to_native_str(b'<STR_LIT>'), np.int32),<EOL>(bytes_to_native_str(b'<ST... | Converts a the cell timings list returned by the python extensions
into a more user-friendly numpy structured array.
The fields correspond to the C ``struct api_cell_timings`` defined
in ``utils/defs.h``.
Returns:
--------
cell_times : numpy structured array
The following fields are present in the ``cell_times``:... | f10145:m1 |
def read_fastfood_catalog(filename, return_dtype=None, need_header=None): | if return_dtype is None:<EOL><INDENT>return_dtype = np.float<EOL><DEDENT>if return_dtype not in [np.float32, np.float]:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>if not file_exists(filename):<EOL><INDENT>msg = "<STR_LIT>".format(filename)<EOL>raise IOError(msg)<EOL><DEDENT>import struct<EOL>tr... | Read a galaxy catalog from a fast-food binary file.
Parameters
-----------
filename: string
Filename containing the galaxy positions
return_dtype: numpy dtype for returned arrays. Default ``numpy.float``
Specifies the datatype for the returned arrays. Must be in
{np.float, np.float32}
need_header: boolea... | f10148:m0 |
def read_ascii_catalog(filename, return_dtype=None): | if return_dtype is None:<EOL><INDENT>return_dtype = np.float<EOL><DEDENT>if not file_exists(filename):<EOL><INDENT>msg = "<STR_LIT>".format(filename)<EOL>raise IOError(msg)<EOL><DEDENT>if pd is not None:<EOL><INDENT>df = pd.read_csv(filename, header=None,<EOL>engine="<STR_LIT:c>",<EOL>dtype={"<STR_LIT:x>": return_dtype... | Read a galaxy catalog from an ascii file.
Parameters
-----------
filename: string
Filename containing the galaxy positions
return_dtype: numpy dtype for returned arrays. Default ``numpy.float``
Specifies the datatype for the returned arrays. Must be in
{np.float, np.float32}
Returns
--------
X, Y, Z: nu... | f10148:m1 |
def read_catalog(filebase=None, return_dtype=np.float): | if filebase is None:<EOL><INDENT>filename = pjoin(dirname(abspath(__file__)),<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>allowed_exts = {'<STR_LIT>': read_fastfood_catalog,<EOL>'<STR_LIT>': read_ascii_catalog,<EOL>'<STR_LIT>': read_ascii_catalog,<EOL>'<STR_LIT>': read_ascii_catalog<EOL>}<EOL>for e in allowed_exts:<EOL><INDENT>i... | Reads a galaxy/randoms catalog and returns 3 XYZ arrays.
Parameters
-----------
filebase: string (optional)
The fully qualified path to the file. If omitted, reads the
theory galaxy catalog under ../theory/tests/data/
return_dtype: numpy dtype for returned arrays. Default ``numpy.float``
Specifies the da... | f10148:m2 |
def strip_line(line, sep=os.linesep): | try:<EOL><INDENT>return line.strip(sep)<EOL><DEDENT>except TypeError:<EOL><INDENT>return line.decode('<STR_LIT:utf-8>').strip(sep)<EOL><DEDENT> | Removes occurrence of character (sep) from a line of text | f10149:m0 |
def get_dict_from_buffer(buf, keys=['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']): | pairs = dict()<EOL>if keys is None:<EOL><INDENT>keys = "<STR_LIT>"<EOL>regex = re.compile(r'''<STR_LIT>'''.format(keys), re.VERBOSE)<EOL>validate = False<EOL><DEDENT>else:<EOL><INDENT>keys = [k.strip() for k in keys]<EOL>regex = re.compile(r'''<STR_LIT>'''.format('<STR_LIT:|>'.join(keys)), re.VERBOSE)<EOL>validate = Tr... | Parses a string buffer for key-val pairs for the supplied keys.
Returns: Python dictionary with all the keys (all keys in buffer
if None is passed for keys) with the values being a list
corresponding to each key.
Note: Return dict will contain all keys supplied (if not None).
If any key was no... | f10149:m2 |
def replace_first_key_in_makefile(buf, key, replacement, outfile=None): | regexp = re.compile(r'''<STR_LIT>'''.format(key), re.VERBOSE)<EOL>matches = regexp.findall(buf)<EOL>if matches is None:<EOL><INDENT>msg = "<STR_LIT>""<STR_LIT>".format(key, regexp.pattern)<EOL>raise ValueError(msg)<EOL><DEDENT>newbuf = regexp.sub(replacement, buf, count=<NUM_LIT:1>)<EOL>if outfile is not None:<EOL><IND... | Replaces first line in 'buf' matching 'key' with 'replacement'.
Optionally, writes out this new buffer into 'outfile'.
Returns: Buffer after replacement has been done | f10149:m3 |
def setup_packages(): | <EOL>src_path = dirname(abspath(sys.argv[<NUM_LIT:0>]))<EOL>old_path = os.getcwd()<EOL>os.chdir(src_path)<EOL>sys.path.insert(<NUM_LIT:0>, src_path)<EOL>python_dirs = ["<STR_LIT>",<EOL>"<STR_LIT>"]<EOL>extensions = generate_extensions(python_dirs)<EOL>common_dict = requirements_check()<EOL>if install_required():<EOL><I... | Custom setup for Corrfunc package.
Optional: Set compiler via 'CC=/path/to/compiler' or
'CC /path/to/compiler' or 'CC = /path/to/compiler'
All the CC options are removed from sys.argv after
being parsed. | f10149:m8 |
@contextmanager<EOL>def stderr_redirected(to=os.devnull): | fd = sys.stderr.fileno()<EOL>def _redirect_stderr(to):<EOL><INDENT>sys.stderr.close() <EOL>os.dup2(to.fileno(), fd) <EOL>sys.stderr = os.fdopen(fd, '<STR_LIT:w>') <EOL><DEDENT>with os.fdopen(os.dup(fd), '<STR_LIT:w>') as old_stderr:<EOL><INDENT>with open(to, '<STR_LIT:w>') as file:<EOL><INDENT>_redirect_stderr(to=fi... | import os
with stderr_redirected(to=filename):
print("from Python")
os.system("echo non-Python applications are also supported") | f10151:m0 |
@contextmanager<EOL>def stderr_redirected(to=os.devnull): | fd = sys.stderr.fileno()<EOL>def _redirect_stderr(to):<EOL><INDENT>sys.stderr.close() <EOL>os.dup2(to.fileno(), fd) <EOL>sys.stderr = os.fdopen(fd, '<STR_LIT:w>') <EOL><DEDENT>with os.fdopen(os.dup(fd), '<STR_LIT:w>') as old_stderr:<EOL><INDENT>with open(to, '<STR_LIT:w>') as file:<EOL><INDENT>_redirect_stderr(to=fi... | import os
with stderr_redirected(to=filename):
print("from Python")
os.system("echo non-Python applications are also supported") | f10152:m0 |
def read_file(filename): | dtype = np.dtype([('<STR_LIT>', np.int32),<EOL>('<STR_LIT>', np.int),<EOL>('<STR_LIT>', np.int),<EOL>('<STR_LIT:time>', np.float)<EOL>])<EOL>if pd is not None:<EOL><INDENT>timings = pd.read_csv(filename, header=None,<EOL>engine="<STR_LIT:c>",<EOL>dtype={'<STR_LIT>': np.int32,<EOL>'<STR_LIT>': np.int,<EOL>'<STR_LIT>': n... | Reads in the file I created manually (by recompiling and adding timers)
Not used any more but left for historical reasons (the first 'speedup'
plots were generated with this function) | f10154:m0 |
@contextmanager<EOL>def stderr_redirected(to=os.devnull): | fd = sys.stderr.fileno()<EOL>def _redirect_stderr(to):<EOL><INDENT>sys.stderr.close() <EOL>os.dup2(to.fileno(), fd) <EOL>sys.stderr = os.fdopen(fd, '<STR_LIT:w>') <EOL><DEDENT>with os.fdopen(os.dup(fd), '<STR_LIT:w>') as old_stderr:<EOL><INDENT>with open(to, '<STR_LIT:w>') as file:<EOL><INDENT>_redirect_stderr(to=fi... | import os
with stderr_redirected(to=filename):
print("from Python")
os.system("echo non-Python applications are also supported") | f10155:m0 |
def read_text_file(filename, encoding="<STR_LIT:utf-8>"): | try:<EOL><INDENT>with open(filename, '<STR_LIT:r>', encoding) as f:<EOL><INDENT>r = f.read()<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>with open(filename, '<STR_LIT:r>') as f:<EOL><INDENT>r = f.read()<EOL><DEDENT><DEDENT>return r<EOL> | Reads a file under python3 with encoding (default UTF-8).
Also works under python2, without encoding.
Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
principle. | f10156:m0 |
def read_catalog(filebase=None): | def read_ascii_catalog(filename, return_dtype=None):<EOL><INDENT>if return_dtype is None:<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise ValueError(msg)<EOL><DEDENT>print("<STR_LIT>")<EOL>try:<EOL><INDENT>import pandas as pd<EOL><DEDENT>except ImportError:<EOL><INDENT>pd = None<EOL><DEDENT>if pd is not None:<EOL><INDENT>df = ... | Reads a galaxy/randoms catalog.
:param filebase: (optional)
The fully qualified path to the file. If omitted, reads the
theory galaxy catalog under ../tests/data/
Returns:
* ``x y z`` - Unpacked numpy arrays compatible with the installed
version of ``Corrfunc``.
**Note** If the filename is omitted, then firs... | f10156:m1 |
def distance(self, loc): | assert type(loc) == type(self)<EOL>lon1, lat1, lon2, lat2 = map(radians, [<EOL>self.lon,<EOL>self.lat,<EOL>loc.lon,<EOL>loc.lat,<EOL>])<EOL>dlon = lon2 - lon1<EOL>dlat = lat2 - lat1<EOL>a = sin(dlat/<NUM_LIT:2>)**<NUM_LIT:2> + cos(lat1) * cos(lat2) * sin(dlon/<NUM_LIT:2>)**<NUM_LIT:2><EOL>c = <NUM_LIT:2> * asin(sqrt(a)... | Calculate the great circle distance between two points
on the earth (specified in decimal degrees) | f10158:c0:m1 |
def allow_key(self): | return '<STR_LIT>'.format(self.cls_key(), self.id)<EOL> | Gets the key associated with this user where we store permission
information | f10175:c0:m0 |
def value_or_default(self, value): | if value is None:<EOL><INDENT>if callable(self.default):<EOL><INDENT>return self.default()<EOL><DEDENT>else:<EOL><INDENT>return self.default<EOL><DEDENT><DEDENT>return value<EOL> | Returns the given value or the specified default value for this
field | f10176:c0:m1 |
def validate_required(self, value): | if self.required and (value is None or value=='<STR_LIT>'):<EOL><INDENT>raise MissingFieldError(self.name)<EOL><DEDENT> | Validates the given value agains this field's 'required' property | f10176:c0:m2 |
def init(self, value): | return self.value_or_default(value)<EOL> | Returns the value that will be set in the model when it is passed
as an __init__ attribute | f10176:c0:m3 |
def recover(self, data, redis=None): | value = data.get(self.name)<EOL>if value is None or value == '<STR_LIT:None>':<EOL><INDENT>return None<EOL><DEDENT>return str(value)<EOL> | Retrieve this field's value from the database | f10176:c0:m4 |
def prepare(self, value): | if value is None: return None<EOL>return str(value)<EOL> | Prepare this field's value to insert in database | f10176:c0:m5 |
def to_json(self, value): | return value<EOL> | Format the value to be presented in json format | f10176:c0:m6 |
def save(self, value, redis, *, commit=True): | value = self.prepare(value)<EOL>if value is not None:<EOL><INDENT>redis.hset(self.obj.key(), self.name, value)<EOL><DEDENT>else:<EOL><INDENT>redis.hdel(self.obj.key(), self.name)<EOL><DEDENT>if self.index:<EOL><INDENT>key = self.key()<EOL>if self.name in self.obj._old:<EOL><INDENT>redis.hdel(key, self.obj._old[self.nam... | Sets this fields value in the databse | f10176:c0:m7 |
def delete(self, redis): | if self.index:<EOL><INDENT>redis.hdel(self.key(), getattr(self.obj, self.name))<EOL><DEDENT> | Deletes this field's value from the databse. Should be implemented
in special cases | f10176:c0:m8 |
def validate(self, value, redis): | <EOL>if type(value) == str:<EOL><INDENT>value = value.strip()<EOL><DEDENT>value = self.value_or_default(value)<EOL>self.validate_required(value)<EOL>if self.regex and not re.match(self.regex, value, flags=re.ASCII):<EOL><INDENT>raise InvalidFieldError(self.name)<EOL><DEDENT>if self.forbidden and value in self.forbidden... | Validates data obtained from a request and returns it in the apropiate
format | f10176:c0:m9 |
def save(self, value, redis, *, commit=True): | value = self.prepare(value)<EOL>if value is not None:<EOL><INDENT>redis.hset(self.obj.key(), self.name, value)<EOL><DEDENT>else:<EOL><INDENT>redis.hdel(self.obj.key(), self.name)<EOL><DEDENT>key = self.key()<EOL>if self.name in self.obj._old:<EOL><INDENT>redis.hdel(key, self.obj._old[self.name])<EOL><DEDENT>redis.sadd(... | Sets this fields value in the databse | f10176:c2:m0 |
def delete(self, redis): | value = getattr(self.obj, self.name)<EOL>redis.srem(self.key() + '<STR_LIT::>' + value, self.obj.id)<EOL> | Deletes this field's value from the databse. Should be implemented
in special cases | f10176:c2:m1 |
def init(self, value): | value = self.value_or_default(value)<EOL>if value is None: return None<EOL>if is_hashed(value):<EOL><INDENT>return value<EOL><DEDENT>return make_password(value)<EOL> | hash passwords given in the constructor | f10176:c3:m0 |
def prepare(self, value): | if value is None:<EOL><INDENT>return None<EOL><DEDENT>if is_hashed(value):<EOL><INDENT>return value<EOL><DEDENT>return make_password(value)<EOL> | Prepare this field's value to insert in database | f10176:c3:m1 |
def validate(self, value, redis): | value = super().validate(value, redis)<EOL>if is_hashed(value):<EOL><INDENT>return value<EOL><DEDENT>return make_password(value)<EOL> | hash passwords given via http | f10176:c3:m2 |
def validate(self, value, redis): | value = self.value_or_default(value)<EOL>self.validate_required(value)<EOL>if value is None:<EOL><INDENT>return None<EOL><DEDENT>if type(value) == str:<EOL><INDENT>try:<EOL><INDENT>value = datetime.datetime.strptime(value, '<STR_LIT>')<EOL><DEDENT>except ValueError:<EOL><INDENT>raise InvalidFieldError(self.name)<EOL><D... | Validates data obtained from a request in ISO 8061 and returns it in Datetime data type | f10176:c7:m0 |
def recover(self, data, redis=None): | return []<EOL> | Don't read the database by default | f10176:c12:m3 |
def fill(self, **kwargs): | setattr(self.obj, self.name, self.get(**kwargs))<EOL> | Loads the relationships into this model. They are not loaded by
default | f10176:c12:m6 |
def get(self, **kwargs): | redis = type(self.obj).get_redis()<EOL>related = list(map(<EOL>lambda id : self.model().get(debyte_string(id)),<EOL>self.get_related_ids(redis, **kwargs)<EOL>))<EOL>return related<EOL> | Returns this relation | f10176:c12:m7 |
def make_filter(self, fieldname, query_func, expct_value): | def actual_filter(item):<EOL><INDENT>value = getattr(item, fieldname)<EOL>if query_func in NULL_AFFECTED_FILTERS and value is None:<EOL><INDENT>return False<EOL><DEDENT>if query_func == '<STR_LIT>':<EOL><INDENT>return value == expct_value<EOL><DEDENT>elif query_func == '<STR_LIT>':<EOL><INDENT>return value != expct_val... | makes a filter that will be appliead to an object's property based
on query_func | f10178:c0:m4 |
@classmethod<EOL><INDENT>def validate(cls, **kwargs):<DEDENT> | <EOL>errors = ValidationErrors()<EOL>obj = cls()<EOL>redis = cls.get_redis()<EOL>for fieldname, field in obj.proxy:<EOL><INDENT>if not field.fillable:<EOL><INDENT>value = field.default<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>value = field.validate(kwargs.get(fieldname), redis)<EOL><DEDENT>except BadField as e:<E... | Validates the data received as keyword arguments whose name match
this class attributes. | f10179:c1:m1 |
@classmethod<EOL><INDENT>def set_engine(cls, neweng):<DEDENT> | assert isinstance(neweng, Engine), '<STR_LIT>'<EOL>if hasattr(cls, '<STR_LIT:Meta>'):<EOL><INDENT>cls.Meta.engine = neweng<EOL><DEDENT>else:<EOL><INDENT>class Meta:<EOL><INDENT>engine = neweng<EOL><DEDENT>cls.Meta = Meta<EOL><DEDENT> | Sets the given coralillo engine so the model uses it to communicate
with the redis database | f10179:c1:m4 |
def save(self): | redis = type(self).get_redis()<EOL>pipe = to_pipeline(redis)<EOL>pipe.hset(self.key(), '<STR_LIT:id>', self.id)<EOL>for fieldname, field in self.proxy:<EOL><INDENT>if not isinstance(field, Relation):<EOL><INDENT>field.save(getattr(self, fieldname), pipe, commit=False)<EOL><DEDENT><DEDENT>pipe.sadd(type(self).members_ke... | Persists this object to the database. Each field knows how to store
itself so we don't have to worry about it | f10179:c2:m1 |
def update(self, **kwargs): | redis = type(self).get_redis()<EOL>errors = ValidationErrors()<EOL>for fieldname, field in self.proxy:<EOL><INDENT>if not field.fillable:<EOL><INDENT>continue<EOL><DEDENT>given = kwargs.get(fieldname)<EOL>if given is None:<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>value = field.validate(kwargs.get(fieldname), r... | validates the given data against this object's rules and then
updates | f10179:c2:m2 |
@staticmethod<EOL><INDENT>def is_object_key(key):<DEDENT> | return re.match('<STR_LIT>', key)<EOL> | checks if the given key belongs to an object. Its easy since it
depends on the key ending like: ':obj | f10179:c2:m3 |
@classmethod<EOL><INDENT>def get(cls, id):<DEDENT> | if not id:<EOL><INDENT>return None<EOL><DEDENT>redis = cls.get_redis()<EOL>key = '<STR_LIT>'.format(cls.cls_key(), id)<EOL>if not redis.exists(key):<EOL><INDENT>return None<EOL><DEDENT>obj = cls(id=id)<EOL>obj._persisted = True<EOL>data = debyte_hash(redis.hgetall(key))<EOL>for fieldname, field in obj.proxy:<EOL><INDEN... | Retrieves an object by id. Returns None in case of failure | f10179:c2:m4 |
@classmethod<EOL><INDENT>def q(cls, **kwargs):<DEDENT> | redis = cls.get_redis()<EOL>return QuerySet(cls, redis.sscan_iter(cls.members_key()))<EOL> | Creates an iterator over the members of this class that applies the
given filters and returns only the elements matching them | f10179:c2:m5 |
@classmethod<EOL><INDENT>def count(cls):<DEDENT> | redis = cls.get_redis()<EOL>return redis.scard(cls.members_key())<EOL> | returns object count for this model | f10179:c2:m6 |
def reload(self): | key = self.key()<EOL>redis = type(self).get_redis()<EOL>if not redis.exists(key):<EOL><INDENT>raise ModelNotFoundError('<STR_LIT>')<EOL><DEDENT>data = debyte_hash(redis.hgetall(key))<EOL>for fieldname, field in self.proxy:<EOL><INDENT>value = field.recover(data, redis)<EOL>setattr(<EOL>self,<EOL>fieldname,<EOL>value<EO... | reloads this object so if it was updated in the database it now
contains the new values | f10179:c2:m7 |
@classmethod<EOL><INDENT>def get_or_exception(cls, id):<DEDENT> | obj = cls.get(id)<EOL>if obj is None:<EOL><INDENT>raise ModelNotFoundError('<STR_LIT>')<EOL><DEDENT>return obj<EOL> | Tries to retrieve an instance of this model from the database or
raises an exception in case of failure | f10179:c2:m8 |
@classmethod<EOL><INDENT>def get_by(cls, field, value):<DEDENT> | redis = cls.get_redis()<EOL>key = cls.cls_key()+'<STR_LIT>'+field<EOL>id = redis.hget(key, value)<EOL>if id:<EOL><INDENT>return cls.get(debyte_string(id))<EOL><DEDENT>return None<EOL> | Tries to retrieve an isinstance of this model from the database
given a value for a defined index. Return None in case of failure | f10179:c2:m9 |
@classmethod<EOL><INDENT>def get_all(cls):<DEDENT> | redis = cls.get_redis()<EOL>return list(map(<EOL>lambda id: cls.get(id),<EOL>map(<EOL>debyte_string,<EOL>redis.smembers(cls.members_key())<EOL>)<EOL>))<EOL> | Gets all available instances of this model from the database | f10179:c2:m11 |
@classmethod<EOL><INDENT>def tree_match(cls, field, string):<DEDENT> | if not string:<EOL><INDENT>return set()<EOL><DEDENT>redis = cls.get_redis()<EOL>prefix = '<STR_LIT>'.format(cls.cls_key(), field)<EOL>pieces = string.split('<STR_LIT::>')<EOL>ans = redis.sunion(<EOL>prefix + '<STR_LIT::>' + '<STR_LIT::>'.join(pieces[<NUM_LIT:0>:i+<NUM_LIT:1>])<EOL>for i in range(len(pieces))<EOL>)<EOL... | Given a tree index, retrieves the ids atached to the given prefix,
think of if as a mechanism for pattern suscription, where two models
attached to the `a`, `a:b` respectively are found by the `a:b` string,
because both model's subscription key matches the string. | f10179:c2:m12 |
@classmethod<EOL><INDENT>def cls_key(cls):<DEDENT> | return snake_case(cls.__name__)<EOL> | Returns the redis key prefix assigned to this model | f10179:c2:m13 |
@classmethod<EOL><INDENT>def members_key(cls):<DEDENT> | return cls.cls_key() + '<STR_LIT>'<EOL> | This key holds a set whose members are the ids that exist of objects
from this class | f10179:c2:m14 |
def key(self): | prefix = type(self).cls_key()<EOL>return '<STR_LIT>'.format(prefix, self.id)<EOL> | Returns the redis key to access this object's values | f10179:c2:m15 |
def fqn(self): | prefix = type(self).cls_key()<EOL>return '<STR_LIT>'.format(prefix, self.id)<EOL> | Returns a fully qualified name for this object | f10179:c2:m16 |
def permission(self, restrict=None): | if restrict is None:<EOL><INDENT>return self.fqn()<EOL><DEDENT>return self.fqn() + '<STR_LIT:/>' + restrict<EOL> | Returns a fully qualified key name to a permission over this object | f10179:c2:m17 |
def to_json(self, *, include=None): | json = dict()<EOL>if include is None or '<STR_LIT:id>' in include or '<STR_LIT:*>' in include:<EOL><INDENT>json['<STR_LIT:id>'] = self.id<EOL><DEDENT>if include is None or '<STR_LIT>' in include or '<STR_LIT:*>' in include:<EOL><INDENT>json['<STR_LIT>'] = type(self).cls_key()<EOL><DEDENT>def fieldfilter(fieldtuple):<EO... | Serializes this model to a JSON representation so it can be sent
via an HTTP REST API | f10179:c2:m18 |
def __eq__(self, other): | if type(other) == str:<EOL><INDENT>return self.id == other<EOL><DEDENT>if type(self) != type(other):<EOL><INDENT>return False<EOL><DEDENT>return self.id == other.id<EOL> | Compares this object to another. Returns true if both are of the
same class and have the same properties. Returns false otherwise | f10179:c2:m19 |
def delete(self): | redis = type(self).get_redis()<EOL>for fieldname, field in self.proxy:<EOL><INDENT>field.delete(redis)<EOL><DEDENT>redis.delete(self.key())<EOL>redis.srem(type(self).members_key(), self.id)<EOL>if isinstance(self, PermissionHolder):<EOL><INDENT>redis.delete(self.allow_key())<EOL><DEDENT>if self.notify:<EOL><INDENT>data... | Deletes this model from the database, calling delete in each field
to properly delete special cases | f10179:c2:m20 |
def to_pipeline(redis): | if isinstance(redis, BasePipeline):<EOL><INDENT>return redis<EOL><DEDENT>return redis.pipeline()<EOL> | If the argument is a redis connection this function makes a redis
pipeline from it. Otherwise it returns the object passed, so it ensures
it is a pipeline | f10180:m0 |
def snake_case(string): | s1 = re.sub('<STR_LIT>', r'<STR_LIT>', string)<EOL>return re.sub('<STR_LIT>', r'<STR_LIT>', s1).lower()<EOL> | Takes a string that represents for example a class name and returns
the snake case version of it. It is used for model-to-key conversion | f10180:m1 |
def camelCase(string): | return '<STR_LIT>'.join(s[<NUM_LIT:0>].upper()+s[<NUM_LIT:1>:] for s in string.split('<STR_LIT:_>'))<EOL> | Takes a string that represents the redis key version of a model name
and returns its camel case version. It is used for key-to-model
conversion. | f10180:m2 |
def force_text(s, encoding='<STR_LIT:utf-8>', strings_only=False, errors='<STR_LIT:strict>'): | <EOL>if issubclass(type(s), str):<EOL><INDENT>return s<EOL><DEDENT>if strings_only and is_protected_type(s):<EOL><INDENT>return s<EOL><DEDENT>try:<EOL><INDENT>if isinstance(s, bytes):<EOL><INDENT>s = str(s, encoding, errors)<EOL><DEDENT>else:<EOL><INDENT>s = str(s)<EOL><DEDENT><DEDENT>except UnicodeDecodeError as e:<EO... | Similar to smart_text, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects. | f10181:m0 |
def force_bytes(s, encoding='<STR_LIT:utf-8>', strings_only=False, errors='<STR_LIT:strict>'): | <EOL>if isinstance(s, bytes):<EOL><INDENT>if encoding == '<STR_LIT:utf-8>':<EOL><INDENT>return s<EOL><DEDENT>else:<EOL><INDENT>return s.decode('<STR_LIT:utf-8>', errors).encode(encoding, errors)<EOL><DEDENT><DEDENT>if strings_only and is_protected_type(s):<EOL><INDENT>return s<EOL><DEDENT>if isinstance(s, memoryview):<... | Similar to smart_bytes, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects. | f10181:m1 |
def constant_time_compare(val1, val2): | return hmac.compare_digest(force_bytes(val1), force_bytes(val2))<EOL> | Return True if the two strings are equal, False otherwise. | f10181:m2 |
def get_random_string(length=<NUM_LIT:12>,<EOL>allowed_chars='<STR_LIT>'<EOL>'<STR_LIT>'): | if not using_sysrandom:<EOL><INDENT>random.seed(<EOL>hashlib.sha256(<EOL>('<STR_LIT>' % (random.getstate(), time.time(), settings.SECRET_KEY)).encode()<EOL>).digest()<EOL>)<EOL>return '<STR_LIT>'.join(random.choice(allowed_chars) for i in range(length))<EOL><DEDENT> | Return a securely generated random string.
The default length of 12 with the a-z, A-Z, 0-9 character set returns
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits | f10181:m3 |
def check_password(password, encoded, setter=None, preferred='<STR_LIT:default>'): | if password is None:<EOL><INDENT>return False<EOL><DEDENT>preferred = bCryptPasswordHasher<EOL>hasher = bCryptPasswordHasher<EOL>hasher_changed = hasher.algorithm != preferred.algorithm<EOL>must_update = hasher_changed or preferred.must_update(encoded)<EOL>is_correct = hasher.verify(password, encoded)<EOL>if not is_cor... | Return a boolean of whether the raw password matches the three
part encoded digest.
If setter is specified, it'll be called when you need to
regenerate the password. | f10181:m5 |
def make_password(password, salt=None, hasher='<STR_LIT:default>'): | if password is None:<EOL><INDENT>return UNUSABLE_PASSWORD_PREFIX + get_random_string(UNUSABLE_PASSWORD_SUFFIX_LENGTH)<EOL><DEDENT>hasher = bCryptPasswordHasher<EOL>if not salt:<EOL><INDENT>salt = hasher.salt()<EOL><DEDENT>return hasher.encode(password, salt)<EOL> | Turn a plain-text password into a hash for database storage
Same as encode() but generate a new random salt. If password is None then
return a concatenation of UNUSABLE_PASSWORD_PREFIX and a random string,
which disallows logins. Additional random string reduces chances of gaining
access to staff or superuser accounts.... | f10181:m6 |
def mask_hash(hash, show=<NUM_LIT:6>, char="<STR_LIT:*>"): | masked = hash[:show]<EOL>masked += char * len(hash[show:])<EOL>return masked<EOL> | Return the given hash, with only the first ``show`` number shown. The
rest are masked with ``char`` for security reasons. | f10181:m7 |
def salt(self): | return get_random_string()<EOL> | Generate a cryptographically secure nonce salt in ASCII. | f10181:c0:m1 |
def verify(self, password, encoded): | raise NotImplementedError('<STR_LIT>')<EOL> | Check if the given password is correct. | f10181:c0:m2 |
def encode(self, password, salt): | raise NotImplementedError('<STR_LIT>')<EOL> | Create an encoded database value.
The result is normally formatted as "algorithm$salt$hash" and
must be fewer than 128 characters. | f10181:c0:m3 |
def safe_summary(self, encoded): | raise NotImplementedError('<STR_LIT>')<EOL> | Return a summary of safe values.
The result is a dictionary and will be used where the password field
must be displayed to construct a safe representation of the password. | f10181:c0:m4 |
def harden_runtime(self, password, encoded): | warnings.warn('<STR_LIT>')<EOL> | Bridge the runtime gap between the work factor supplied in `encoded`
and the work factor suggested by this hasher.
Taking PBKDF2 as an example, if `encoded` contains 20000 iterations and
`self.iterations` is 30000, this method should run password through
another 10000 iterations of PBKDF2. Similar approaches should exi... | f10181:c0:m6 |
def __init__(self,<EOL>configfile,<EOL>refresh_cache=False,<EOL>boto_profile=None<EOL>): | <EOL>self.boto_profile = boto_profile<EOL>self.inventory = self._empty_inventory()<EOL>self.index = {}<EOL>self.read_settings(configfile)<EOL>if self.boto_profile:<EOL><INDENT>if not hasattr(boto.ec2.EC2Connection, '<STR_LIT>'):<EOL><INDENT>self.fail_with_error("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>if refres... | Initialize Ec2Inventory | f10185:c0:m1 |
def get_inventory(self): | return self.inventory<EOL> | Get full inventory | f10185:c0:m2 |
def is_cache_valid(self): | if os.path.isfile(self.cache_path_cache):<EOL><INDENT>mod_time = os.path.getmtime(self.cache_path_cache)<EOL>current_time = time()<EOL>if (mod_time + self.cache_max_age) > current_time:<EOL><INDENT>if os.path.isfile(self.cache_path_index):<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL> | Determines if the cache files have expired, or if it is still
valid | f10185:c0:m3 |
def read_settings(self, configfile): | if six.PY3:<EOL><INDENT>config = configparser.ConfigParser()<EOL><DEDENT>else:<EOL><INDENT>config = configparser.SafeConfigParser()<EOL><DEDENT>config.read(configfile)<EOL>self.eucalyptus_host = None<EOL>self.eucalyptus = False<EOL>if config.has_option('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>self.eucalyptus = config.get... | Reads the settings from the ec2.ini file | f10185:c0:m4 |
def do_api_calls_update_cache(self): | if self.route53_enabled:<EOL><INDENT>self.get_route53_records()<EOL><DEDENT>for region in self.regions:<EOL><INDENT>self.get_instances_by_region(region)<EOL>if self.rds_enabled:<EOL><INDENT>self.get_rds_instances_by_region(region)<EOL><DEDENT>if self.elasticache_enabled:<EOL><INDENT>self.get_elasticache_clusters_by_reg... | Do API calls to each region, and save data in cache files | f10185:c0:m5 |
def connect(self, region): | if self.eucalyptus:<EOL><INDENT>conn = boto.connect_euca(host=self.eucalyptus_host)<EOL>conn.APIVersion = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>conn = self.connect_to_aws(ec2, region)<EOL><DEDENT>return conn<EOL> | create connection to api server | f10185:c0:m6 |
def boto_fix_security_token_in_profile(self, connect_args): | profile = '<STR_LIT>' + self.boto_profile<EOL>if boto.config.has_option(profile, '<STR_LIT>'):<EOL><INDENT>connect_args['<STR_LIT>'] = boto.config.get(profile, '<STR_LIT>')<EOL><DEDENT>return connect_args<EOL> | monkey patch for boto issue boto/boto#2100 | f10185:c0:m7 |
def get_instances_by_region(self, region): | try:<EOL><INDENT>conn = self.connect(region)<EOL>reservations = []<EOL>if self.ec2_instance_filters:<EOL><INDENT>for filter_key, filter_values in self.ec2_instance_filters.items():<EOL><INDENT>reservations.extend(conn.get_all_instances(filters = { filter_key : filter_values }))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res... | Makes an AWS EC2 API call to the list of instances in a particular
region | f10185:c0:m9 |
def get_rds_instances_by_region(self, region): | try:<EOL><INDENT>conn = self.connect_to_aws(rds, region)<EOL>if conn:<EOL><INDENT>instances = conn.get_all_dbinstances()<EOL>for instance in instances:<EOL><INDENT>self.add_rds_instance(instance, region)<EOL><DEDENT><DEDENT><DEDENT>except boto.exception.BotoServerError as e:<EOL><INDENT>error = e.reason<EOL>if e.error_... | Makes an AWS API call to the list of RDS instances in a particular
region | f10185:c0:m10 |
def get_elasticache_clusters_by_region(self, region): | <EOL>try:<EOL><INDENT>conn = elasticache.connect_to_region(region)<EOL>if conn:<EOL><INDENT>response = conn.describe_cache_clusters(None, None, None, True)<EOL><DEDENT><DEDENT>except boto.exception.BotoServerError as e:<EOL><INDENT>error = e.reason<EOL>if e.error_code == '<STR_LIT>':<EOL><INDENT>error = self.get_auth_e... | Makes an AWS API call to the list of ElastiCache clusters (with
nodes' info) in a particular region. | f10185:c0:m11 |
def get_elasticache_replication_groups_by_region(self, region): | <EOL>try:<EOL><INDENT>conn = elasticache.connect_to_region(region)<EOL>if conn:<EOL><INDENT>response = conn.describe_replication_groups()<EOL><DEDENT><DEDENT>except boto.exception.BotoServerError as e:<EOL><INDENT>error = e.reason<EOL>if e.error_code == '<STR_LIT>':<EOL><INDENT>error = self.get_auth_error_message()<EOL... | Makes an AWS API call to the list of ElastiCache replication groups
in a particular region. | f10185:c0:m12 |
def get_auth_error_message(self): | errors = ["<STR_LIT>"]<EOL>if None in [os.environ.get('<STR_LIT>'), os.environ.get('<STR_LIT>')]:<EOL><INDENT>errors.append('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>errors.append('<STR_LIT>')<EOL><DEDENT>boto_paths = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>boto_config_found = list(p for p in boto_paths if os.path... | create an informative error message if there is an issue authenticating | f10185:c0:m13 |
def fail_with_error(self, err_msg, err_operation=None): | if err_operation:<EOL><INDENT>err_msg = '<STR_LIT>'.format(<EOL>err_msg=err_msg, err_operation=err_operation)<EOL><DEDENT>sys.stderr.write(err_msg)<EOL>sys.exit(<NUM_LIT:1>)<EOL> | log an error to std err for ansible-playbook to consume and exit | f10185:c0:m14 |
def add_instance(self, instance, region): | <EOL>if instance.state not in self.ec2_instance_states:<EOL><INDENT>return<EOL><DEDENT>if instance.subnet_id:<EOL><INDENT>dest = getattr(instance, self.vpc_destination_variable, None)<EOL>if dest is None:<EOL><INDENT>dest = getattr(instance, '<STR_LIT>').get(self.vpc_destination_variable, None)<EOL><DEDENT><DEDENT>else... | Adds an instance to the inventory and index, as long as it is
addressable | f10185:c0:m16 |
def add_rds_instance(self, instance, region): | <EOL>if not self.all_rds_instances and instance.status != '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>dest = instance.endpoint[<NUM_LIT:0>]<EOL>if not dest:<EOL><INDENT>return<EOL><DEDENT>self.index[dest] = [region, instance.id]<EOL>if self.group_by_instance_id:<EOL><INDENT>self.inventory[instance.id] = [dest]<EOL>if s... | Adds an RDS instance to the inventory and index, as long as it is
addressable | f10185:c0:m17 |
def add_elasticache_cluster(self, cluster, region): | <EOL>if not self.all_elasticache_clusters and cluster['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>if '<STR_LIT>' in cluster and cluster['<STR_LIT>']:<EOL><INDENT>dest = cluster['<STR_LIT>']['<STR_LIT>']<EOL>is_redis = False<EOL><DEDENT>else:<EOL><INDENT>dest = cluster['<STR_LIT>'][<NUM_LIT:0>]['<STR_LIT... | Adds an ElastiCache cluster to the inventory and index, as long as
it's nodes are addressable | f10185:c0:m18 |
def add_elasticache_node(self, node, cluster, region): | <EOL>if not self.all_elasticache_nodes and node['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>dest = node['<STR_LIT>']['<STR_LIT>']<EOL>if not dest:<EOL><INDENT>return<EOL><DEDENT>node_id = self.to_safe(cluster['<STR_LIT>'] + '<STR_LIT:_>' + node['<STR_LIT>'])<EOL>self.index[dest] = [region, node_id]<EOL>... | Adds an ElastiCache node to the inventory and index, as long as
it is addressable | f10185:c0:m19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.