_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q277100
BoltArraySpark.repartition
test
def repartition(self, npartitions): """ Repartitions the underlying RDD Parameters ---------- npartitions : int Number of partitions to repartion the underlying RDD to """ rdd = self._rdd.repartition(npartitions) return self._constructor(rdd,...
python
{ "resource": "" }
q277101
BoltArraySpark.stack
test
def stack(self, size=None): """ Aggregates records of a distributed array. Stacking should improve the performance of vectorized operations, but the resulting StackedArray object only exposes a restricted set of operations (e.g. map, reduce). The unstack method can be used ...
python
{ "resource": "" }
q277102
BoltArraySpark._align
test
def _align(self, axis): """ Align spark bolt array so that axes for iteration are in the keys. This operation is applied before most functional operators. It ensures that the specified axes are valid, and swaps key/value axes so that functional operators can be applied o...
python
{ "resource": "" }
q277103
BoltArraySpark.first
test
def first(self): """ Return the first element of an array """ from bolt.local.array import BoltArrayLocal rdd = self._rdd if self._ordered else self._rdd.sortByKey() return BoltArrayLocal(rdd.values().first())
python
{ "resource": "" }
q277104
BoltArraySpark._stat
test
def _stat(self, axis=None, func=None, name=None, keepdims=False): """ Compute a statistic over an axis. Can provide either a function (for use in a reduce) or a name (for use by a stat counter). Parameters ---------- axis : tuple or int, optional, default=None ...
python
{ "resource": "" }
q277105
BoltArraySpark.mean
test
def mean(self, axis=None, keepdims=False): """ Return the mean of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes keepdims : boole...
python
{ "resource": "" }
q277106
BoltArraySpark.var
test
def var(self, axis=None, keepdims=False): """ Return the variance of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes keepdims : bo...
python
{ "resource": "" }
q277107
BoltArraySpark.std
test
def std(self, axis=None, keepdims=False): """ Return the standard deviation of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes kee...
python
{ "resource": "" }
q277108
BoltArraySpark.sum
test
def sum(self, axis=None, keepdims=False): """ Return the sum of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes keepdims : boolean...
python
{ "resource": "" }
q277109
BoltArraySpark.max
test
def max(self, axis=None, keepdims=False): """ Return the maximum of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes keepdims : boo...
python
{ "resource": "" }
q277110
BoltArraySpark.min
test
def min(self, axis=None, keepdims=False): """ Return the minimum of the array over the given axis. Parameters ---------- axis : tuple or int, optional, default=None Axis to compute statistic over, if None will compute over all axes keepdims : boo...
python
{ "resource": "" }
q277111
BoltArraySpark.chunk
test
def chunk(self, size="150", axis=None, padding=None): """ Chunks records of a distributed array. Chunking breaks arrays into subarrays, using an specified size of chunks along each value dimension. Can alternatively specify an average chunk byte size (in kilobytes) and the size ...
python
{ "resource": "" }
q277112
BoltArraySpark.swap
test
def swap(self, kaxes, vaxes, size="150"): """ Swap axes from keys to values. This is the core operation underlying shape manipulation on the Spark bolt array. It exchanges an arbitrary set of axes between the keys and the valeus. If either is None, will only move axes in...
python
{ "resource": "" }
q277113
BoltArraySpark.transpose
test
def transpose(self, *axes): """ Return an array with the axes transposed. This operation will incur a swap unless the desiured permutation can be obtained only by transpoing the keys or the values. Parameters ---------- axes : None, tuple of ints, or n i...
python
{ "resource": "" }
q277114
BoltArraySpark.swapaxes
test
def swapaxes(self, axis1, axis2): """ Return the array with two axes interchanged. Parameters ---------- axis1 : int The first axis to swap axis2 : int The second axis to swap """ p = list(range(self.ndim)) p[axis1] = axis...
python
{ "resource": "" }
q277115
BoltArraySpark.reshape
test
def reshape(self, *shape): """ Return an array with the same data but a new shape. Currently only supports reshaping that independently reshapes the keys, or the values, or both. Parameters ---------- shape : tuple of ints, or n ints New shape ...
python
{ "resource": "" }
q277116
BoltArraySpark._reshapebasic
test
def _reshapebasic(self, shape): """ Check if the requested reshape can be broken into independant reshapes on the keys and values. If it can, returns the index in the new shape separating keys from values, otherwise returns -1 """ new = tupleize(shape) old_key_siz...
python
{ "resource": "" }
q277117
BoltArraySpark.squeeze
test
def squeeze(self, axis=None): """ Remove one or more single-dimensional axes from the array. Parameters ---------- axis : tuple or int One or more singleton axes to remove. """ if not any([d == 1 for d in self.shape]): return self ...
python
{ "resource": "" }
q277118
BoltArraySpark.astype
test
def astype(self, dtype, casting='unsafe'): """ Cast the array to a specified type. Parameters ---------- dtype : str or dtype Typecode or data-type to cast the array to (see numpy) """ rdd = self._rdd.mapValues(lambda v: v.astype(dtype, 'K', casting))...
python
{ "resource": "" }
q277119
BoltArraySpark.clip
test
def clip(self, min=None, max=None): """ Clip values above and below. Parameters ---------- min : scalar or array-like Minimum value. If array, will be broadcasted max : scalar or array-like Maximum value. If array, will be broadcasted. ""...
python
{ "resource": "" }
q277120
BoltArraySpark.toarray
test
def toarray(self): """ Returns the contents as a local array. Will likely cause memory problems for large objects. """ rdd = self._rdd if self._ordered else self._rdd.sortByKey() x = rdd.values().collect() return asarray(x).reshape(self.shape)
python
{ "resource": "" }
q277121
tupleize
test
def tupleize(arg): """ Coerce singletons and lists and ndarrays to tuples. Parameters ---------- arg : tuple, list, ndarray, or singleton Item to coerce """ if arg is None: return None if not isinstance(arg, (tuple, list, ndarray, Iterable)): return tuple((arg,))...
python
{ "resource": "" }
q277122
argpack
test
def argpack(args): """ Coerce a list of arguments to a tuple. Parameters ---------- args : tuple or nested tuple Pack arguments into a tuple, converting ((,...),) or (,) -> (,) """ if isinstance(args[0], (tuple, list, ndarray)): return tupleize(args[0]) elif isinstance(a...
python
{ "resource": "" }
q277123
inshape
test
def inshape(shape, axes): """ Checks to see if a list of axes are contained within an array shape. Parameters ---------- shape : tuple[int] the shape of a BoltArray axes : tuple[int] the axes to check against shape """ valid = all([(axis < len(shape)) and (axis >= 0) fo...
python
{ "resource": "" }
q277124
allclose
test
def allclose(a, b): """ Test that a and b are close and match in shape. Parameters ---------- a : ndarray First array to check b : ndarray First array to check """ from numpy import allclose return (a.shape == b.shape) and allclose(a, b)
python
{ "resource": "" }
q277125
listify
test
def listify(lst, dim): """ Flatten lists of indices and ensure bounded by a known dim. Parameters ---------- lst : list List of integer indices dim : tuple Bounds for indices """ if not all([l.dtype == int for l in lst]): raise ValueError("indices must be intege...
python
{ "resource": "" }
q277126
slicify
test
def slicify(slc, dim): """ Force a slice to have defined start, stop, and step from a known dim. Start and stop will always be positive. Step may be negative. There is an exception where a negative step overflows the stop needs to have the default value set to -1. This is the only case of a negativ...
python
{ "resource": "" }
q277127
istransposeable
test
def istransposeable(new, old): """ Check to see if a proposed tuple of axes is a valid permutation of an old set of axes. Checks length, axis repetion, and bounds. Parameters ---------- new : tuple tuple of proposed axes old : tuple tuple of old axes """ new, old =...
python
{ "resource": "" }
q277128
isreshapeable
test
def isreshapeable(new, old): """ Check to see if a proposed tuple of axes is a valid reshaping of the old axes by ensuring that they can be factored. Parameters ---------- new : tuple tuple of proposed axes old : tuple tuple of old axes """ new, old = tupleize(new)...
python
{ "resource": "" }
q277129
allstack
test
def allstack(vals, depth=0): """ If an ndarray has been split into multiple chunks by splitting it along each axis at a number of locations, this function rebuilds the original array from chunks. Parameters ---------- vals : nested lists of ndarrays each level of nesting of the list...
python
{ "resource": "" }
q277130
iterexpand
test
def iterexpand(arry, extra): """ Expand dimensions by iteratively append empty axes. Parameters ---------- arry : ndarray The original array extra : int The number of empty axes to append """ for d in range(arry.ndim, arry.ndim+extra): arry = expand_dims(arry, a...
python
{ "resource": "" }
q277131
zip_with_index
test
def zip_with_index(rdd): """ Alternate version of Spark's zipWithIndex that eagerly returns count. """ starts = [0] if rdd.getNumPartitions() > 1: nums = rdd.mapPartitions(lambda it: [sum(1 for _ in it)]).collect() count = sum(nums) for i in range(len(nums) - 1): ...
python
{ "resource": "" }
q277132
wrapped
test
def wrapped(f): """ Decorator to append routed docstrings """ import inspect def extract(func): append = "" args = inspect.getargspec(func) for i, a in enumerate(args.args): if i < (len(args) - len(args.defaults)): append += str(a) + ", " ...
python
{ "resource": "" }
q277133
lookup
test
def lookup(*args, **kwargs): """ Use arguments to route constructor. Applies a series of checks on arguments to identify constructor, starting with known keyword arguments, and then applying constructor-specific checks """ if 'mode' in kwargs: mode = kwargs['mode'] if mode n...
python
{ "resource": "" }
q277134
Keys.reshape
test
def reshape(self, *shape): """ Reshape just the keys of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- shape : tuple New proposed axes. """ new = argpack(shape) old = self.shape isreshapeable(new, old...
python
{ "resource": "" }
q277135
Keys.transpose
test
def transpose(self, *axes): """ Transpose just the keys of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- axes : tuple New proposed axes. """ new = argpack(axes) old = range(self.ndim) istransposeable(...
python
{ "resource": "" }
q277136
Values.reshape
test
def reshape(self, *shape): """ Reshape just the values of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- shape : tuple New proposed axes. """ new = argpack(shape) old = self.shape isreshapeable(new, o...
python
{ "resource": "" }
q277137
Values.transpose
test
def transpose(self, *axes): """ Transpose just the values of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- axes : tuple New proposed axes. """ new = argpack(axes) old = range(self.ndim) istransposeabl...
python
{ "resource": "" }
q277138
ConstructLocal.ones
test
def ones(shape, dtype=float64, order='C'): """ Create a local bolt array of ones. Parameters ---------- shape : tuple Dimensions of the desired array dtype : data-type, optional, default=float64 The desired data-type for the array. (see numpy) ...
python
{ "resource": "" }
q277139
ConstructLocal.zeros
test
def zeros(shape, dtype=float64, order='C'): """ Create a local bolt array of zeros. Parameters ---------- shape : tuple Dimensions of the desired array. dtype : data-type, optional, default=float64 The desired data-type for the array. (see numpy)...
python
{ "resource": "" }
q277140
ConstructLocal.concatenate
test
def concatenate(arrays, axis=0): """ Join a sequence of arrays together. Parameters ---------- arrays : tuple A sequence of array-like e.g. (a1, a2, ...) axis : int, optional, default=0 The axis along which the arrays will be joined. Ret...
python
{ "resource": "" }
q277141
discrete_likelihood
test
def discrete_likelihood(data, xmin, alpha): """ Equation B.8 in Clauset Given a data set, an xmin value, and an alpha "scaling parameter", computes the log-likelihood (the value to be maximized) """ if not scipyOK: raise ImportError("Can't import scipy. Need scipy for zeta function.") ...
python
{ "resource": "" }
q277142
most_likely_alpha
test
def most_likely_alpha(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Return the most likely alpha for the data given an xmin """ alpha_vector = np.linspace(alpharange[0],alpharange[1],n_alpha) return alpha_vector[discrete_max_likelihood_arg(data, xmin, ...
python
{ "resource": "" }
q277143
discrete_alpha_mle
test
def discrete_alpha_mle(data, xmin): """ Equation B.17 of Clauset et al 2009 The Maximum Likelihood Estimator of the "scaling parameter" alpha in the discrete case is similar to that in the continuous case """ # boolean indices of positive data gexmin = (data>=xmin) nn = gexmin.sum() ...
python
{ "resource": "" }
q277144
discrete_best_alpha
test
def discrete_best_alpha(data, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True): """ Use the maximum L to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from ...
python
{ "resource": "" }
q277145
plfit.discrete_best_alpha
test
def discrete_best_alpha(self, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True, finite=True): """ Use the maximum likelihood to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multipli...
python
{ "resource": "" }
q277146
plfit.plotppf
test
def plotppf(self,x=None,xmin=None,alpha=None,dolog=True,**kwargs): """ Plots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality. """ if not(xmin): xmin=self._xmin if not(alpha): alp...
python
{ "resource": "" }
q277147
plfit.lognormal
test
def lognormal(self,doprint=True): """ Use the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parameters """ # N = float(self.data.shape[0]) # mu = log(self.data).sum() / N # sigmasquared = ( ( log(self.data) - mu )**2 )...
python
{ "resource": "" }
q277148
sanitize_turbo
test
def sanitize_turbo(html, allowed_tags=TURBO_ALLOWED_TAGS, allowed_attrs=TURBO_ALLOWED_ATTRS): """Sanitizes HTML, removing not allowed tags and attributes. :param str|unicode html: :param list allowed_tags: List of allowed tags. :param dict allowed_attrs: Dictionary with attributes allowed for tags. ...
python
{ "resource": "" }
q277149
YandexTurboFeed.configure_analytics_yandex
test
def configure_analytics_yandex(self, ident, params=None): """Configure Yandex Metrika analytics counter. :param str|unicode ident: Metrika counter ID. :param dict params: Additional params. """ params = params or {} data = { 'type': 'Yandex', '...
python
{ "resource": "" }
q277150
LabelWidget.tag_list
test
def tag_list(self, tags): """ Generates a list of tags identifying those previously selected. Returns a list of tuples of the form (<tag name>, <CSS class name>). Uses the string names rather than the tags themselves in order to work with tag lists built from forms not fully su...
python
{ "resource": "" }
q277151
SSHKey.hash_md5
test
def hash_md5(self): """Calculate md5 fingerprint. Shamelessly copied from http://stackoverflow.com/questions/6682815/deriving-an-ssh-fingerprint-from-a-public-key-in-python For specification, see RFC4716, section 4.""" fp_plain = hashlib.md5(self._decoded_key).hexdigest() retur...
python
{ "resource": "" }
q277152
SSHKey.hash_sha256
test
def hash_sha256(self): """Calculate sha256 fingerprint.""" fp_plain = hashlib.sha256(self._decoded_key).digest() return (b"SHA256:" + base64.b64encode(fp_plain).replace(b"=", b"")).decode("utf-8")
python
{ "resource": "" }
q277153
SSHKey.hash_sha512
test
def hash_sha512(self): """Calculates sha512 fingerprint.""" fp_plain = hashlib.sha512(self._decoded_key).digest() return (b"SHA512:" + base64.b64encode(fp_plain).replace(b"=", b"")).decode("utf-8")
python
{ "resource": "" }
q277154
SSHKey._parse_long
test
def _parse_long(cls, data): """Calculate two's complement.""" if sys.version < '3': # this does not exist in python 3 - undefined-variable disabled to make pylint happier. ret = long(0) # pylint:disable=undefined-variable for byte in data: ret = (ret ...
python
{ "resource": "" }
q277155
SSHKey.decode_key
test
def decode_key(cls, pubkey_content): """Decode base64 coded part of the key.""" try: decoded_key = base64.b64decode(pubkey_content.encode("ascii")) except (TypeError, binascii.Error): raise MalformedDataError("Unable to decode the key") return decoded_key
python
{ "resource": "" }
q277156
SSHKey.parse_options
test
def parse_options(self, options): """Parses ssh options string.""" quote_open = False parsed_options = {} def parse_add_single_option(opt): """Parses and validates a single option, and adds it to parsed_options field.""" if "=" in opt: opt_name, o...
python
{ "resource": "" }
q277157
SSHKey._process_ssh_rsa
test
def _process_ssh_rsa(self, data): """Parses ssh-rsa public keys.""" current_position, raw_e = self._unpack_by_int(data, 0) current_position, raw_n = self._unpack_by_int(data, current_position) unpacked_e = self._parse_long(raw_e) unpacked_n = self._parse_long(raw_n) sel...
python
{ "resource": "" }
q277158
SSHKey._process_ssh_dss
test
def _process_ssh_dss(self, data): """Parses ssh-dsa public keys.""" data_fields = {} current_position = 0 for item in ("p", "q", "g", "y"): current_position, value = self._unpack_by_int(data, current_position) data_fields[item] = self._parse_long(value) q...
python
{ "resource": "" }
q277159
SSHKey._process_ecdsa_sha
test
def _process_ecdsa_sha(self, data): """Parses ecdsa-sha public keys.""" current_position, curve_information = self._unpack_by_int(data, 0) if curve_information not in self.ECDSA_CURVE_DATA: raise NotImplementedError("Invalid curve type: %s" % curve_information) curve, hash_al...
python
{ "resource": "" }
q277160
SSHKey._process_ed25516
test
def _process_ed25516(self, data): """Parses ed25516 keys. There is no (apparent) way to validate ed25519 keys. This only checks data length (256 bits), but does not try to validate the key in any way.""" current_position, verifying_key = self._unpack_by_int(data, 0) ver...
python
{ "resource": "" }
q277161
SSHKey.parse
test
def parse(self, keydata=None): """Validates SSH public key. Throws exception for invalid keys. Otherwise returns None. Populates key_type, bits and bits fields. For rsa keys, see field "rsa" for raw public key data. For dsa keys, see field "dsa". For ecdsa keys, see fi...
python
{ "resource": "" }
q277162
InitContext.step
test
def step(self, input_token=None): """Performs a step to establish the context as an initiator. This method should be called in a loop and fed input tokens from the acceptor, and its output tokens should be sent to the acceptor, until this context's :attr:`established` attribute is True....
python
{ "resource": "" }
q277163
AcceptContext.step
test
def step(self, input_token): """Performs a step to establish the context as an acceptor. This method should be called in a loop and fed input tokens from the initiator, and its output tokens should be sent to the initiator, until this context's :attr:`established` attribute is True. ...
python
{ "resource": "" }
q277164
Credential.mechs
test
def mechs(self): """ The set of mechanisms supported by the credential. :type: :class:`~gssapi.oids.OIDSet` """ if not self._mechs: self._mechs = self._inquire(False, False, False, True)[3] return self._mechs
python
{ "resource": "" }
q277165
Credential.store
test
def store(self, usage=None, mech=None, overwrite=False, default=False, cred_store=None): """ Stores this credential into a 'credential store'. It can either store this credential in the default credential store, or into a specific credential store specified by a set of mechanism-specific...
python
{ "resource": "" }
q277166
main
test
def main(properties=properties, options=options, **custom_options): """Imports and runs setup function with given properties.""" return init(**dict(options, **custom_options))(**properties)
python
{ "resource": "" }
q277167
init
test
def init( dist='dist', minver=None, maxver=None, use_markdown_readme=True, use_stdeb=False, use_distribute=False, ): """Imports and returns a setup function. If use_markdown_readme is set, then README.md is added to setuptools READMES list. If use_stdeb is set on a Debian b...
python
{ "resource": "" }
q277168
_create_file
test
def _create_file(): """ Returns a file handle which is used to record audio """ f = wave.open('audio.wav', mode='wb') f.setnchannels(2) p = pyaudio.PyAudio() f.setsampwidth(p.get_sample_size(pyaudio.paInt16)) f.setframerate(p.get_default_input_device_info()['defaultSampleRate']) try:...
python
{ "resource": "" }
q277169
djfrontend_h5bp_css
test
def djfrontend_h5bp_css(version=None): """ Returns HTML5 Boilerplate CSS file. Included in HTML5 Boilerplate. """ if version is None: version = getattr(settings, 'DJFRONTEND_H5BP_CSS', DJFRONTEND_H5BP_CSS_DEFAULT) return format_html( '<link rel="stylesheet" href="{0}djfrontend/c...
python
{ "resource": "" }
q277170
djfrontend_normalize
test
def djfrontend_normalize(version=None): """ Returns Normalize CSS file. Included in HTML5 Boilerplate. """ if version is None: version = getattr(settings, 'DJFRONTEND_NORMALIZE', DJFRONTEND_NORMALIZE_DEFAULT) return format_html( '<link rel="stylesheet" href="{0}djfrontend/css/no...
python
{ "resource": "" }
q277171
djfrontend_fontawesome
test
def djfrontend_fontawesome(version=None): """ Returns Font Awesome CSS file. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: version = getattr(settings, 'DJFRONTEND_FONTAWESOME', DJFRONTEND_FONTAWESOME_DEFAULT) return format_html( '<lin...
python
{ "resource": "" }
q277172
djfrontend_modernizr
test
def djfrontend_modernizr(version=None): """ Returns Modernizr JavaScript file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file. Included in HTML5 Boilerplate. """ if version is None: version = getattr(settings, 'DJFRONTEND_MODERNIZR', DJFRONT...
python
{ "resource": "" }
q277173
djfrontend_jquery
test
def djfrontend_jquery(version=None): """ Returns jQuery JavaScript file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file from Google CDN with local fallback. Included in HTML5 Boilerplate. """ if version is None: version = getattr(settings, '...
python
{ "resource": "" }
q277174
djfrontend_jqueryui
test
def djfrontend_jqueryui(version=None): """ Returns the jQuery UI plugin file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file from Google CDN with local fallback. """ if version is None: version = getattr(settings, 'DJFRONTEND_JQUERYUI', DJFRONTE...
python
{ "resource": "" }
q277175
djfrontend_jquery_datatables
test
def djfrontend_jquery_datatables(version=None): """ Returns the jQuery DataTables plugin file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: if not getattr(settings, 'DJFRONTEND_JQUERY_DATATABLES', False): v...
python
{ "resource": "" }
q277176
djfrontend_jquery_datatables_css
test
def djfrontend_jquery_datatables_css(version=None): """ Returns the jQuery DataTables CSS file according to version number. """ if version is None: if not getattr(settings, 'DJFRONTEND_JQUERY_DATATABLES_CSS', False): version = getattr(settings, 'DJFRONTEND_JQUERY_DATATABLES_VERSION',...
python
{ "resource": "" }
q277177
djfrontend_jquery_datatables_themeroller
test
def djfrontend_jquery_datatables_themeroller(version=None): """ Returns the jQuery DataTables ThemeRoller CSS file according to version number. """ if version is None: if not getattr(settings, 'DJFRONTEND_JQUERY_DATATABLES_THEMEROLLER', False): version = getattr(settings, 'DJFRONTEND...
python
{ "resource": "" }
q277178
djfrontend_jquery_formset
test
def djfrontend_jquery_formset(version=None): """ Returns the jQuery Dynamic Formset plugin file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: version = getattr(settings, 'DJFRONTEND_JQUERY_FORMSET', DJFRONTEND_JQUERY_F...
python
{ "resource": "" }
q277179
djfrontend_jquery_scrollto
test
def djfrontend_jquery_scrollto(version=None): """ Returns the jQuery ScrollTo plugin file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: version = getattr(settings, 'DJFRONTEND_JQUERY_SCROLLTO', DJFRONTEND_JQUERY_SCROLL...
python
{ "resource": "" }
q277180
djfrontend_jquery_smoothscroll
test
def djfrontend_jquery_smoothscroll(version=None): """ Returns the jQuery Smooth Scroll plugin file according to version number. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: version = getattr(settings, 'DJFRONTEND_JQUERY_SMOOTHSCROLL', DJFRONTEND_...
python
{ "resource": "" }
q277181
djfrontend_twbs_css
test
def djfrontend_twbs_css(version=None): """ Returns Twitter Bootstrap CSS file. TEMPLATE_DEBUG returns full file, otherwise returns minified file. """ if version is None: if not getattr(settings, 'DJFRONTEND_TWBS_CSS', False): version = getattr(settings, 'DJFRONTEND_TWBS_VERSION',...
python
{ "resource": "" }
q277182
djfrontend_ga
test
def djfrontend_ga(account=None): """ Returns Google Analytics asynchronous snippet. Use DJFRONTEND_GA_SETDOMAINNAME to set domain for multiple, or cross-domain tracking. Set DJFRONTEND_GA_SETALLOWLINKER to use _setAllowLinker method on target site for cross-domain tracking. Included in HTML5 Boilerp...
python
{ "resource": "" }
q277183
CodeMirrorTextarea.render
test
def render(self, name, value, attrs=None): u"""Render CodeMirrorTextarea""" if self.js_var_format is not None: js_var_bit = 'var %s = ' % (self.js_var_format % name) else: js_var_bit = '' output = [super(CodeMirrorTextarea, self).render(name, value, attrs), ...
python
{ "resource": "" }
q277184
iter_auth_hashes
test
def iter_auth_hashes(user, purpose, minutes_valid): """ Generate auth tokens tied to user and specified purpose. The hash expires at midnight on the minute of now + minutes_valid, such that when minutes_valid=1 you get *at least* 1 minute to use the token. """ now = timezone.now().replace(micro...
python
{ "resource": "" }
q277185
calc_expiry_time
test
def calc_expiry_time(minutes_valid): """Return specific time an auth_hash will expire.""" return ( timezone.now() + datetime.timedelta(minutes=minutes_valid + 1) ).replace(second=0, microsecond=0)
python
{ "resource": "" }
q277186
get_user_token
test
def get_user_token(user, purpose, minutes_valid): """Return login token info for given user.""" token = ''.join( dumps([ user.get_username(), get_auth_hash(user, purpose), ]).encode('base64').split('\n') ) return { 'id': get_meteor_id(user), 'token...
python
{ "resource": "" }
q277187
Users.serialize
test
def serialize(self, obj, *args, **kwargs): """Serialize user as per Meteor accounts serialization.""" # use default serialization, then modify to suit our needs. data = super(Users, self).serialize(obj, *args, **kwargs) # everything that isn't handled explicitly ends up in `profile` ...
python
{ "resource": "" }
q277188
Users.deserialize_profile
test
def deserialize_profile(profile, key_prefix='', pop=False): """De-serialize user profile fields into concrete model fields.""" result = {} if pop: getter = profile.pop else: getter = profile.get def prefixed(name): """Return name prefixed by `...
python
{ "resource": "" }
q277189
Users.update
test
def update(self, selector, update, options=None): """Update user data.""" # we're ignoring the `options` argument at this time del options user = get_object( self.model, selector['_id'], pk=this.user_id, ) profile_update = self.deserialize_profile(...
python
{ "resource": "" }
q277190
Auth.auth_failed
test
def auth_failed(**credentials): """Consistent fail so we don't provide attackers with valuable info.""" if credentials: user_login_failed.send_robust( sender=__name__, credentials=auth._clean_credentials(credentials), ) raise MeteorError(40...
python
{ "resource": "" }
q277191
Auth.validated_user
test
def validated_user(cls, token, purpose, minutes_valid): """Resolve and validate auth token, returns user object.""" try: username, auth_hash = loads(token.decode('base64')) except (ValueError, Error): cls.auth_failed(token=token) try: user = cls.user_m...
python
{ "resource": "" }
q277192
Auth.check_secure
test
def check_secure(): """Check request, return False if using SSL or local connection.""" if this.request.is_secure(): return True # using SSL elif this.request.META['REMOTE_ADDR'] in [ 'localhost', '127.0.0.1', ]: return True # loc...
python
{ "resource": "" }
q277193
Auth.get_username
test
def get_username(self, user): """Retrieve username from user selector.""" if isinstance(user, basestring): return user elif isinstance(user, dict) and len(user) == 1: [(key, val)] = user.items() if key == 'username' or (key == self.user_model.USERNAME_FIELD): ...
python
{ "resource": "" }
q277194
Auth.create_user
test
def create_user(self, params): """Register a new user account.""" receivers = create_user.send( sender=__name__, request=this.request, params=params, ) if len(receivers) == 0: raise NotImplementedError( 'Handler for `create_...
python
{ "resource": "" }
q277195
Auth.do_login
test
def do_login(self, user): """Login a user.""" this.user_id = user.pk this.user_ddp_id = get_meteor_id(user) # silent subscription (sans sub/nosub msg) to LoggedInUser pub this.user_sub_id = meteor_random_id() API.do_sub(this.user_sub_id, 'LoggedInUser', silent=True) ...
python
{ "resource": "" }
q277196
Auth.do_logout
test
def do_logout(self): """Logout a user.""" # silent unsubscription (sans sub/nosub msg) from LoggedInUser pub API.do_unsub(this.user_sub_id, silent=True) del this.user_sub_id self.update_subs(None) user_logged_out.send( sender=self.user_model, request=this.requ...
python
{ "resource": "" }
q277197
Auth.login
test
def login(self, params): """Login either with resume token or password.""" if 'password' in params: return self.login_with_password(params) elif 'resume' in params: return self.login_with_resume_token(params) else: self.auth_failed(**params)
python
{ "resource": "" }
q277198
Auth.login_with_password
test
def login_with_password(self, params): """Authenticate using credentials supplied in params.""" # never allow insecure login self.check_secure() username = self.get_username(params['user']) password = self.get_password(params['password']) user = auth.authenticate(userna...
python
{ "resource": "" }
q277199
Auth.login_with_resume_token
test
def login_with_resume_token(self, params): """ Login with existing resume token. Either the token is valid and the user is logged in, or the token is invalid and a non-specific ValueError("Login failed.") exception is raised - don't be tempted to give clues to attackers as to wh...
python
{ "resource": "" }