repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
arkottke/pysra | pysra/propagation.py | LinearElasticCalculator.calc_stress_tf | def calc_stress_tf(self, lin, lout, damped):
"""Compute the stress transfer function.
Parameters
----------
lin : :class:`~site.Location`
Location of input
lout : :class:`~site.Location`
Location of output. Note that this would typically be midheight
... | python | def calc_stress_tf(self, lin, lout, damped):
"""Compute the stress transfer function.
Parameters
----------
lin : :class:`~site.Location`
Location of input
lout : :class:`~site.Location`
Location of output. Note that this would typically be midheight
... | [
"def",
"calc_stress_tf",
"(",
"self",
",",
"lin",
",",
"lout",
",",
"damped",
")",
":",
"tf",
"=",
"self",
".",
"calc_strain_tf",
"(",
"lin",
",",
"lout",
")",
"if",
"damped",
":",
"tf",
"*=",
"lout",
".",
"layer",
".",
"comp_shear_mod",
"else",
":",... | Compute the stress transfer function.
Parameters
----------
lin : :class:`~site.Location`
Location of input
lout : :class:`~site.Location`
Location of output. Note that this would typically be midheight
of the layer. | [
"Compute",
"the",
"stress",
"transfer",
"function",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L380-L400 | train |
arkottke/pysra | pysra/propagation.py | LinearElasticCalculator.calc_strain_tf | def calc_strain_tf(self, lin, lout):
"""Compute the strain transfer function from `lout` to
`location_in`.
The strain transfer function from the acceleration at layer `n`
(outcrop) to the mid-height of layer `m` (within) is defined as
Parameters
----------
lin :... | python | def calc_strain_tf(self, lin, lout):
"""Compute the strain transfer function from `lout` to
`location_in`.
The strain transfer function from the acceleration at layer `n`
(outcrop) to the mid-height of layer `m` (within) is defined as
Parameters
----------
lin :... | [
"def",
"calc_strain_tf",
"(",
"self",
",",
"lin",
",",
"lout",
")",
":",
"assert",
"lout",
".",
"wave_field",
"==",
"WaveField",
".",
"within",
"ang_freqs",
"=",
"self",
".",
"motion",
".",
"angular_freqs",
"cterm",
"=",
"1j",
"*",
"self",
".",
"_wave_nu... | Compute the strain transfer function from `lout` to
`location_in`.
The strain transfer function from the acceleration at layer `n`
(outcrop) to the mid-height of layer `m` (within) is defined as
Parameters
----------
lin : :class:`~site.Location`
Location of... | [
"Compute",
"the",
"strain",
"transfer",
"function",
"from",
"lout",
"to",
"location_in",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L402-L448 | train |
arkottke/pysra | pysra/propagation.py | EquivalentLinearCalculator._estimate_strains | def _estimate_strains(self):
"""Compute an estimate of the strains."""
# Estimate the strain based on the PGV and shear-wave velocity
for l in self._profile:
l.reset()
l.strain = self._motion.pgv / l.initial_shear_vel | python | def _estimate_strains(self):
"""Compute an estimate of the strains."""
# Estimate the strain based on the PGV and shear-wave velocity
for l in self._profile:
l.reset()
l.strain = self._motion.pgv / l.initial_shear_vel | [
"def",
"_estimate_strains",
"(",
"self",
")",
":",
"for",
"l",
"in",
"self",
".",
"_profile",
":",
"l",
".",
"reset",
"(",
")",
"l",
".",
"strain",
"=",
"self",
".",
"_motion",
".",
"pgv",
"/",
"l",
".",
"initial_shear_vel"
] | Compute an estimate of the strains. | [
"Compute",
"an",
"estimate",
"of",
"the",
"strains",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L514-L519 | train |
arkottke/pysra | pysra/propagation.py | EquivalentLinearCalculator._calc_strain | def _calc_strain(self, loc_input, loc_layer, motion, *args):
"""Compute the strain used for iterations of material properties."""
strain_max = self._calc_strain_max(loc_input, loc_layer, motion, *args)
return self.strain_ratio * strain_max | python | def _calc_strain(self, loc_input, loc_layer, motion, *args):
"""Compute the strain used for iterations of material properties."""
strain_max = self._calc_strain_max(loc_input, loc_layer, motion, *args)
return self.strain_ratio * strain_max | [
"def",
"_calc_strain",
"(",
"self",
",",
"loc_input",
",",
"loc_layer",
",",
"motion",
",",
"*",
"args",
")",
":",
"strain_max",
"=",
"self",
".",
"_calc_strain_max",
"(",
"loc_input",
",",
"loc_layer",
",",
"motion",
",",
"*",
"args",
")",
"return",
"se... | Compute the strain used for iterations of material properties. | [
"Compute",
"the",
"strain",
"used",
"for",
"iterations",
"of",
"material",
"properties",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L557-L560 | train |
arkottke/pysra | pysra/propagation.py | EquivalentLinearCalculator._calc_strain_max | def _calc_strain_max(self, loc_input, loc_layer, motion, *args):
"""Compute the effective strain at the center of a layer."""
return motion.calc_peak(
self.calc_strain_tf(loc_input, loc_layer)) | python | def _calc_strain_max(self, loc_input, loc_layer, motion, *args):
"""Compute the effective strain at the center of a layer."""
return motion.calc_peak(
self.calc_strain_tf(loc_input, loc_layer)) | [
"def",
"_calc_strain_max",
"(",
"self",
",",
"loc_input",
",",
"loc_layer",
",",
"motion",
",",
"*",
"args",
")",
":",
"return",
"motion",
".",
"calc_peak",
"(",
"self",
".",
"calc_strain_tf",
"(",
"loc_input",
",",
"loc_layer",
")",
")"
] | Compute the effective strain at the center of a layer. | [
"Compute",
"the",
"effective",
"strain",
"at",
"the",
"center",
"of",
"a",
"layer",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L562-L565 | train |
arkottke/pysra | pysra/propagation.py | FrequencyDependentEqlCalculator._estimate_strains | def _estimate_strains(self):
"""Estimate the strains by running an EQL site response.
This step was recommended in Section 8.3.1 of Zalachoris (2014).
"""
eql = EquivalentLinearCalculator()
eql(self._motion, self._profile, self._loc_input) | python | def _estimate_strains(self):
"""Estimate the strains by running an EQL site response.
This step was recommended in Section 8.3.1 of Zalachoris (2014).
"""
eql = EquivalentLinearCalculator()
eql(self._motion, self._profile, self._loc_input) | [
"def",
"_estimate_strains",
"(",
"self",
")",
":",
"eql",
"=",
"EquivalentLinearCalculator",
"(",
")",
"eql",
"(",
"self",
".",
"_motion",
",",
"self",
".",
"_profile",
",",
"self",
".",
"_loc_input",
")"
] | Estimate the strains by running an EQL site response.
This step was recommended in Section 8.3.1 of Zalachoris (2014). | [
"Estimate",
"the",
"strains",
"by",
"running",
"an",
"EQL",
"site",
"response",
"."
] | c72fd389d6c15203c0c00728ac00f101bae6369d | https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/propagation.py#L606-L612 | train |
guaix-ucm/numina | numina/core/recipes.py | timeit | def timeit(method):
"""Decorator to measure the time used by the recipe"""
import datetime
@functools.wraps(method)
def timed_method(self, rinput):
time_start = datetime.datetime.utcnow()
result = method(self, rinput)
time_end = datetime.datetime.utcnow()
result.time_i... | python | def timeit(method):
"""Decorator to measure the time used by the recipe"""
import datetime
@functools.wraps(method)
def timed_method(self, rinput):
time_start = datetime.datetime.utcnow()
result = method(self, rinput)
time_end = datetime.datetime.utcnow()
result.time_i... | [
"def",
"timeit",
"(",
"method",
")",
":",
"import",
"datetime",
"@",
"functools",
".",
"wraps",
"(",
"method",
")",
"def",
"timed_method",
"(",
"self",
",",
"rinput",
")",
":",
"time_start",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"r... | Decorator to measure the time used by the recipe | [
"Decorator",
"to",
"measure",
"the",
"time",
"used",
"by",
"the",
"recipe"
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/recipes.py#L261-L276 | train |
guaix-ucm/numina | numina/core/recipes.py | BaseRecipe.save_intermediate_img | def save_intermediate_img(self, img, name):
"""Save intermediate FITS objects."""
if self.intermediate_results:
img.writeto(name, overwrite=True) | python | def save_intermediate_img(self, img, name):
"""Save intermediate FITS objects."""
if self.intermediate_results:
img.writeto(name, overwrite=True) | [
"def",
"save_intermediate_img",
"(",
"self",
",",
"img",
",",
"name",
")",
":",
"if",
"self",
".",
"intermediate_results",
":",
"img",
".",
"writeto",
"(",
"name",
",",
"overwrite",
"=",
"True",
")"
] | Save intermediate FITS objects. | [
"Save",
"intermediate",
"FITS",
"objects",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/recipes.py#L161-L164 | train |
guaix-ucm/numina | numina/core/recipes.py | BaseRecipe.save_intermediate_array | def save_intermediate_array(self, array, name):
"""Save intermediate array object as FITS."""
if self.intermediate_results:
fits.writeto(name, array, overwrite=True) | python | def save_intermediate_array(self, array, name):
"""Save intermediate array object as FITS."""
if self.intermediate_results:
fits.writeto(name, array, overwrite=True) | [
"def",
"save_intermediate_array",
"(",
"self",
",",
"array",
",",
"name",
")",
":",
"if",
"self",
".",
"intermediate_results",
":",
"fits",
".",
"writeto",
"(",
"name",
",",
"array",
",",
"overwrite",
"=",
"True",
")"
] | Save intermediate array object as FITS. | [
"Save",
"intermediate",
"array",
"object",
"as",
"FITS",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/recipes.py#L166-L169 | train |
guaix-ucm/numina | numina/core/recipes.py | BaseRecipe.build_recipe_input | def build_recipe_input(self, ob, dal):
"""Build a RecipeInput object."""
result = {}
# We have to decide if the ob input
# is a plain description (ObservingBlock)
# or if it contains the nested results (Obsres)
#
# it has to contain the tags corresponding to the ... | python | def build_recipe_input(self, ob, dal):
"""Build a RecipeInput object."""
result = {}
# We have to decide if the ob input
# is a plain description (ObservingBlock)
# or if it contains the nested results (Obsres)
#
# it has to contain the tags corresponding to the ... | [
"def",
"build_recipe_input",
"(",
"self",
",",
"ob",
",",
"dal",
")",
":",
"result",
"=",
"{",
"}",
"ob_query_skip",
"=",
"False",
"ob_query_field",
"=",
"'obresult'",
"if",
"isinstance",
"(",
"ob",
",",
"ObservingBlock",
")",
":",
"import",
"numina",
".",... | Build a RecipeInput object. | [
"Build",
"a",
"RecipeInput",
"object",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/recipes.py#L190-L255 | train |
guaix-ucm/numina | numina/tools/subsets_of_fileinfo_from_txt.py | subsets_of_fileinfo_from_txt | def subsets_of_fileinfo_from_txt(filename):
"""Returns a dictionary with subsets of FileInfo instances from a TXT file.
Each subset of files must be preceded by a line:
@ <number> <label>
where <number> indicates the number of files in that subset,
and <label> is a label for that subset. Any additi... | python | def subsets_of_fileinfo_from_txt(filename):
"""Returns a dictionary with subsets of FileInfo instances from a TXT file.
Each subset of files must be preceded by a line:
@ <number> <label>
where <number> indicates the number of files in that subset,
and <label> is a label for that subset. Any additi... | [
"def",
"subsets_of_fileinfo_from_txt",
"(",
"filename",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"raise",
"ValueError",
"(",
"\"File \"",
"+",
"filename",
"+",
"\" not found!\"",
")",
"with",
"open",
"(",
"filename"... | Returns a dictionary with subsets of FileInfo instances from a TXT file.
Each subset of files must be preceded by a line:
@ <number> <label>
where <number> indicates the number of files in that subset,
and <label> is a label for that subset. Any additional text
beyond <label> in the same line is ig... | [
"Returns",
"a",
"dictionary",
"with",
"subsets",
"of",
"FileInfo",
"instances",
"from",
"a",
"TXT",
"file",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/tools/subsets_of_fileinfo_from_txt.py#L10-L95 | train |
guaix-ucm/numina | numina/array/__init__.py | subarray_match | def subarray_match(shape, ref, sshape, sref=None):
"""Compute the slice representation of intersection of two arrays.
Given the shapes of two arrays and a reference point ref, compute the
intersection of the two arrays.
It returns a tuple of slices, that can be passed to the two \
images as indexes... | python | def subarray_match(shape, ref, sshape, sref=None):
"""Compute the slice representation of intersection of two arrays.
Given the shapes of two arrays and a reference point ref, compute the
intersection of the two arrays.
It returns a tuple of slices, that can be passed to the two \
images as indexes... | [
"def",
"subarray_match",
"(",
"shape",
",",
"ref",
",",
"sshape",
",",
"sref",
"=",
"None",
")",
":",
"ref1",
"=",
"asarray",
"(",
"ref",
",",
"dtype",
"=",
"'int'",
")",
"if",
"sref",
"is",
"not",
"None",
":",
"ref2",
"=",
"asarray",
"(",
"sref",
... | Compute the slice representation of intersection of two arrays.
Given the shapes of two arrays and a reference point ref, compute the
intersection of the two arrays.
It returns a tuple of slices, that can be passed to the two \
images as indexes
:param shape: the shape of the reference array
:... | [
"Compute",
"the",
"slice",
"representation",
"of",
"intersection",
"of",
"two",
"arrays",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L21-L74 | train |
guaix-ucm/numina | numina/array/__init__.py | rebin_scale | def rebin_scale(a, scale=1):
"""Scale an array to a new shape."""
newshape = tuple((side * scale) for side in a.shape)
return rebin(a, newshape) | python | def rebin_scale(a, scale=1):
"""Scale an array to a new shape."""
newshape = tuple((side * scale) for side in a.shape)
return rebin(a, newshape) | [
"def",
"rebin_scale",
"(",
"a",
",",
"scale",
"=",
"1",
")",
":",
"newshape",
"=",
"tuple",
"(",
"(",
"side",
"*",
"scale",
")",
"for",
"side",
"in",
"a",
".",
"shape",
")",
"return",
"rebin",
"(",
"a",
",",
"newshape",
")"
] | Scale an array to a new shape. | [
"Scale",
"an",
"array",
"to",
"a",
"new",
"shape",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L171-L176 | train |
guaix-ucm/numina | numina/array/__init__.py | rebin | def rebin(a, newshape):
"""Rebin an array to a new shape."""
slices = [slice(0, old, float(old)/new)
for old, new in zip(a.shape, newshape)]
coordinates = numpy.mgrid[slices]
# choose the biggest smaller integer index
indices = coordinates.astype('i')
return a[tuple(indices)] | python | def rebin(a, newshape):
"""Rebin an array to a new shape."""
slices = [slice(0, old, float(old)/new)
for old, new in zip(a.shape, newshape)]
coordinates = numpy.mgrid[slices]
# choose the biggest smaller integer index
indices = coordinates.astype('i')
return a[tuple(indices)] | [
"def",
"rebin",
"(",
"a",
",",
"newshape",
")",
":",
"slices",
"=",
"[",
"slice",
"(",
"0",
",",
"old",
",",
"float",
"(",
"old",
")",
"/",
"new",
")",
"for",
"old",
",",
"new",
"in",
"zip",
"(",
"a",
".",
"shape",
",",
"newshape",
")",
"]",
... | Rebin an array to a new shape. | [
"Rebin",
"an",
"array",
"to",
"a",
"new",
"shape",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L179-L187 | train |
guaix-ucm/numina | numina/array/__init__.py | fixpix | def fixpix(data, mask, kind='linear'):
"""Interpolate 2D array data in rows"""
if data.shape != mask.shape:
raise ValueError
if not numpy.any(mask):
return data
x = numpy.arange(0, data.shape[0])
for row, mrow in zip(data, mask):
if numpy.any(mrow): # Interpolate if there'... | python | def fixpix(data, mask, kind='linear'):
"""Interpolate 2D array data in rows"""
if data.shape != mask.shape:
raise ValueError
if not numpy.any(mask):
return data
x = numpy.arange(0, data.shape[0])
for row, mrow in zip(data, mask):
if numpy.any(mrow): # Interpolate if there'... | [
"def",
"fixpix",
"(",
"data",
",",
"mask",
",",
"kind",
"=",
"'linear'",
")",
":",
"if",
"data",
".",
"shape",
"!=",
"mask",
".",
"shape",
":",
"raise",
"ValueError",
"if",
"not",
"numpy",
".",
"any",
"(",
"mask",
")",
":",
"return",
"data",
"x",
... | Interpolate 2D array data in rows | [
"Interpolate",
"2D",
"array",
"data",
"in",
"rows"
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L190-L205 | train |
guaix-ucm/numina | numina/array/__init__.py | fixpix2 | def fixpix2(data, mask, iterations=3, out=None):
"""Substitute pixels in mask by a bilinear least square fitting.
"""
out = out if out is not None else data.copy()
# A binary mask, regions are ones
binry = mask != 0
# Label regions in the binary mask
lblarr, labl = ndimage.label(binry)
... | python | def fixpix2(data, mask, iterations=3, out=None):
"""Substitute pixels in mask by a bilinear least square fitting.
"""
out = out if out is not None else data.copy()
# A binary mask, regions are ones
binry = mask != 0
# Label regions in the binary mask
lblarr, labl = ndimage.label(binry)
... | [
"def",
"fixpix2",
"(",
"data",
",",
"mask",
",",
"iterations",
"=",
"3",
",",
"out",
"=",
"None",
")",
":",
"out",
"=",
"out",
"if",
"out",
"is",
"not",
"None",
"else",
"data",
".",
"copy",
"(",
")",
"binry",
"=",
"mask",
"!=",
"0",
"lblarr",
"... | Substitute pixels in mask by a bilinear least square fitting. | [
"Substitute",
"pixels",
"in",
"mask",
"by",
"a",
"bilinear",
"least",
"square",
"fitting",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L208-L247 | train |
guaix-ucm/numina | numina/array/__init__.py | numberarray | def numberarray(x, shape):
"""Return x if it is an array or create an array and fill it with x."""
try:
iter(x)
except TypeError:
return numpy.ones(shape) * x
else:
return x | python | def numberarray(x, shape):
"""Return x if it is an array or create an array and fill it with x."""
try:
iter(x)
except TypeError:
return numpy.ones(shape) * x
else:
return x | [
"def",
"numberarray",
"(",
"x",
",",
"shape",
")",
":",
"try",
":",
"iter",
"(",
"x",
")",
"except",
"TypeError",
":",
"return",
"numpy",
".",
"ones",
"(",
"shape",
")",
"*",
"x",
"else",
":",
"return",
"x"
] | Return x if it is an array or create an array and fill it with x. | [
"Return",
"x",
"if",
"it",
"is",
"an",
"array",
"or",
"create",
"an",
"array",
"and",
"fill",
"it",
"with",
"x",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/__init__.py#L291-L298 | train |
druids/django-chamber | chamber/multidomains/auth/middleware.py | get_token | def get_token(request):
"""
Returns the token model instance associated with the given request token key.
If no user is retrieved AnonymousToken is returned.
"""
if (not request.META.get(header_name_to_django(auth_token_settings.HEADER_NAME)) and
config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUT... | python | def get_token(request):
"""
Returns the token model instance associated with the given request token key.
If no user is retrieved AnonymousToken is returned.
"""
if (not request.META.get(header_name_to_django(auth_token_settings.HEADER_NAME)) and
config.CHAMBER_MULTIDOMAINS_OVERTAKER_AUT... | [
"def",
"get_token",
"(",
"request",
")",
":",
"if",
"(",
"not",
"request",
".",
"META",
".",
"get",
"(",
"header_name_to_django",
"(",
"auth_token_settings",
".",
"HEADER_NAME",
")",
")",
"and",
"config",
".",
"CHAMBER_MULTIDOMAINS_OVERTAKER_AUTH_COOKIE_NAME",
")"... | Returns the token model instance associated with the given request token key.
If no user is retrieved AnonymousToken is returned. | [
"Returns",
"the",
"token",
"model",
"instance",
"associated",
"with",
"the",
"given",
"request",
"token",
"key",
".",
"If",
"no",
"user",
"is",
"retrieved",
"AnonymousToken",
"is",
"returned",
"."
] | eef4169923557e96877a664fa254e8c0814f3f23 | https://github.com/druids/django-chamber/blob/eef4169923557e96877a664fa254e8c0814f3f23/chamber/multidomains/auth/middleware.py#L13-L25 | train |
druids/django-chamber | chamber/multidomains/auth/middleware.py | MultiDomainsTokenAuthenticationMiddleware.process_request | def process_request(self, request):
"""
Lazy set user and token
"""
request.token = get_token(request)
request.user = SimpleLazyObject(lambda: get_user(request))
request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request) | python | def process_request(self, request):
"""
Lazy set user and token
"""
request.token = get_token(request)
request.user = SimpleLazyObject(lambda: get_user(request))
request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request) | [
"def",
"process_request",
"(",
"self",
",",
"request",
")",
":",
"request",
".",
"token",
"=",
"get_token",
"(",
"request",
")",
"request",
".",
"user",
"=",
"SimpleLazyObject",
"(",
"lambda",
":",
"get_user",
"(",
"request",
")",
")",
"request",
".",
"_... | Lazy set user and token | [
"Lazy",
"set",
"user",
"and",
"token"
] | eef4169923557e96877a664fa254e8c0814f3f23 | https://github.com/druids/django-chamber/blob/eef4169923557e96877a664fa254e8c0814f3f23/chamber/multidomains/auth/middleware.py#L30-L36 | train |
guaix-ucm/numina | numina/array/display/ximplotxy.py | ximplotxy_jupyter | def ximplotxy_jupyter(x, y, fmt=None, **args):
"""Auxiliary function to call ximplotxy from a jupyter notebook.
"""
using_jupyter = True
if fmt is None:
return ximplotxy(x, y, using_jupyter=using_jupyter, **args)
else:
return ximplotxy(x, y, fmt, using_jupyter=using_jupyter, **args) | python | def ximplotxy_jupyter(x, y, fmt=None, **args):
"""Auxiliary function to call ximplotxy from a jupyter notebook.
"""
using_jupyter = True
if fmt is None:
return ximplotxy(x, y, using_jupyter=using_jupyter, **args)
else:
return ximplotxy(x, y, fmt, using_jupyter=using_jupyter, **args) | [
"def",
"ximplotxy_jupyter",
"(",
"x",
",",
"y",
",",
"fmt",
"=",
"None",
",",
"**",
"args",
")",
":",
"using_jupyter",
"=",
"True",
"if",
"fmt",
"is",
"None",
":",
"return",
"ximplotxy",
"(",
"x",
",",
"y",
",",
"using_jupyter",
"=",
"using_jupyter",
... | Auxiliary function to call ximplotxy from a jupyter notebook. | [
"Auxiliary",
"function",
"to",
"call",
"ximplotxy",
"from",
"a",
"jupyter",
"notebook",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/display/ximplotxy.py#L20-L27 | train |
druids/django-chamber | chamber/utils/transaction.py | atomic | def atomic(func):
"""
Decorator helper that overrides django atomic decorator and automatically adds create revision.
"""
try:
from reversion.revisions import create_revision
return transaction.atomic(create_revision()(func))
except ImportError:
return transaction.atomic(fun... | python | def atomic(func):
"""
Decorator helper that overrides django atomic decorator and automatically adds create revision.
"""
try:
from reversion.revisions import create_revision
return transaction.atomic(create_revision()(func))
except ImportError:
return transaction.atomic(fun... | [
"def",
"atomic",
"(",
"func",
")",
":",
"try",
":",
"from",
"reversion",
".",
"revisions",
"import",
"create_revision",
"return",
"transaction",
".",
"atomic",
"(",
"create_revision",
"(",
")",
"(",
"func",
")",
")",
"except",
"ImportError",
":",
"return",
... | Decorator helper that overrides django atomic decorator and automatically adds create revision. | [
"Decorator",
"helper",
"that",
"overrides",
"django",
"atomic",
"decorator",
"and",
"automatically",
"adds",
"create",
"revision",
"."
] | eef4169923557e96877a664fa254e8c0814f3f23 | https://github.com/druids/django-chamber/blob/eef4169923557e96877a664fa254e8c0814f3f23/chamber/utils/transaction.py#L14-L23 | train |
druids/django-chamber | chamber/utils/transaction.py | atomic_with_signals | def atomic_with_signals(func):
"""
Atomic decorator with transaction signals.
"""
try:
from reversion.revisions import create_revision
return transaction.atomic(create_revision()(transaction_signals(func)))
except ImportError:
return transaction.atomic(transaction_signals(fu... | python | def atomic_with_signals(func):
"""
Atomic decorator with transaction signals.
"""
try:
from reversion.revisions import create_revision
return transaction.atomic(create_revision()(transaction_signals(func)))
except ImportError:
return transaction.atomic(transaction_signals(fu... | [
"def",
"atomic_with_signals",
"(",
"func",
")",
":",
"try",
":",
"from",
"reversion",
".",
"revisions",
"import",
"create_revision",
"return",
"transaction",
".",
"atomic",
"(",
"create_revision",
"(",
")",
"(",
"transaction_signals",
"(",
"func",
")",
")",
")... | Atomic decorator with transaction signals. | [
"Atomic",
"decorator",
"with",
"transaction",
"signals",
"."
] | eef4169923557e96877a664fa254e8c0814f3f23 | https://github.com/druids/django-chamber/blob/eef4169923557e96877a664fa254e8c0814f3f23/chamber/utils/transaction.py#L116-L125 | train |
gatkin/declxml | declxml.py | parse_from_file | def parse_from_file(
root_processor, # type: RootProcessor
xml_file_path, # type: Text
encoding='utf-8' # type: Text
):
# type: (...) -> Any
"""
Parse the XML file using the processor starting from the root of the document.
:param root_processor: Root processor of the XML doc... | python | def parse_from_file(
root_processor, # type: RootProcessor
xml_file_path, # type: Text
encoding='utf-8' # type: Text
):
# type: (...) -> Any
"""
Parse the XML file using the processor starting from the root of the document.
:param root_processor: Root processor of the XML doc... | [
"def",
"parse_from_file",
"(",
"root_processor",
",",
"xml_file_path",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"with",
"open",
"(",
"xml_file_path",
",",
"'r'",
",",
"encoding",
"=",
"encoding",
")",
"as",
"xml_file",
":",
"xml_string",
"=",
"xml_file",
"... | Parse the XML file using the processor starting from the root of the document.
:param root_processor: Root processor of the XML document.
:param xml_file_path: Path to XML file to parse.
:param encoding: Encoding of the file.
:return: Parsed value. | [
"Parse",
"the",
"XML",
"file",
"using",
"the",
"processor",
"starting",
"from",
"the",
"root",
"of",
"the",
"document",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L264-L284 | train |
gatkin/declxml | declxml.py | parse_from_string | def parse_from_string(
root_processor, # type: RootProcessor
xml_string # type: Text
):
# type: (...) -> Any
"""
Parse the XML string using the processor starting from the root of the document.
:param xml_string: XML string to parse.
See also :func:`declxml.parse_from_file`
"... | python | def parse_from_string(
root_processor, # type: RootProcessor
xml_string # type: Text
):
# type: (...) -> Any
"""
Parse the XML string using the processor starting from the root of the document.
:param xml_string: XML string to parse.
See also :func:`declxml.parse_from_file`
"... | [
"def",
"parse_from_string",
"(",
"root_processor",
",",
"xml_string",
")",
":",
"if",
"not",
"_is_valid_root_processor",
"(",
"root_processor",
")",
":",
"raise",
"InvalidRootProcessor",
"(",
"'Invalid root processor'",
")",
"parseable_xml_string",
"=",
"xml_string",
"i... | Parse the XML string using the processor starting from the root of the document.
:param xml_string: XML string to parse.
See also :func:`declxml.parse_from_file` | [
"Parse",
"the",
"XML",
"string",
"using",
"the",
"processor",
"starting",
"from",
"the",
"root",
"of",
"the",
"document",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L287-L311 | train |
gatkin/declxml | declxml.py | serialize_to_file | def serialize_to_file(
root_processor, # type: RootProcessor
value, # type: Any
xml_file_path, # type: Text
encoding='utf-8', # type: Text
indent=None # type: Optional[Text]
):
# type: (...) -> None
"""
Serialize the value to an XML file using the root processor.... | python | def serialize_to_file(
root_processor, # type: RootProcessor
value, # type: Any
xml_file_path, # type: Text
encoding='utf-8', # type: Text
indent=None # type: Optional[Text]
):
# type: (...) -> None
"""
Serialize the value to an XML file using the root processor.... | [
"def",
"serialize_to_file",
"(",
"root_processor",
",",
"value",
",",
"xml_file_path",
",",
"encoding",
"=",
"'utf-8'",
",",
"indent",
"=",
"None",
")",
":",
"serialized_value",
"=",
"serialize_to_string",
"(",
"root_processor",
",",
"value",
",",
"indent",
")",... | Serialize the value to an XML file using the root processor.
:param root_processor: Root processor of the XML document.
:param value: Value to serialize.
:param xml_file_path: Path to the XML file to which the serialized value will be written.
:param encoding: Encoding of the file.
:param indent: I... | [
"Serialize",
"the",
"value",
"to",
"an",
"XML",
"file",
"using",
"the",
"root",
"processor",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L314-L334 | train |
gatkin/declxml | declxml.py | serialize_to_string | def serialize_to_string(
root_processor, # type: RootProcessor
value, # type: Any
indent=None # type: Optional[Text]
):
# type: (...) -> Text
"""
Serialize the value to an XML string using the root processor.
:return: The serialized XML string.
See also :func:`declxml.se... | python | def serialize_to_string(
root_processor, # type: RootProcessor
value, # type: Any
indent=None # type: Optional[Text]
):
# type: (...) -> Text
"""
Serialize the value to an XML string using the root processor.
:return: The serialized XML string.
See also :func:`declxml.se... | [
"def",
"serialize_to_string",
"(",
"root_processor",
",",
"value",
",",
"indent",
"=",
"None",
")",
":",
"if",
"not",
"_is_valid_root_processor",
"(",
"root_processor",
")",
":",
"raise",
"InvalidRootProcessor",
"(",
"'Invalid root processor'",
")",
"state",
"=",
... | Serialize the value to an XML string using the root processor.
:return: The serialized XML string.
See also :func:`declxml.serialize_to_file` | [
"Serialize",
"the",
"value",
"to",
"an",
"XML",
"string",
"using",
"the",
"root",
"processor",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L337-L371 | train |
gatkin/declxml | declxml.py | array | def array(
item_processor, # type: Processor
alias=None, # type: Optional[Text]
nested=None, # type: Optional[Text]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create an array processor that can be used ... | python | def array(
item_processor, # type: Processor
alias=None, # type: Optional[Text]
nested=None, # type: Optional[Text]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create an array processor that can be used ... | [
"def",
"array",
"(",
"item_processor",
",",
"alias",
"=",
"None",
",",
"nested",
"=",
"None",
",",
"omit_empty",
"=",
"False",
",",
"hooks",
"=",
"None",
")",
":",
"processor",
"=",
"_Array",
"(",
"item_processor",
",",
"alias",
",",
"nested",
",",
"om... | Create an array processor that can be used to parse and serialize array data.
XML arrays may be nested within an array element, or they may be embedded
within their parent. A nested array would look like:
.. sourcecode:: xml
<root-element>
<some-element>ABC</some-element>
... | [
"Create",
"an",
"array",
"processor",
"that",
"can",
"be",
"used",
"to",
"parse",
"and",
"serialize",
"array",
"data",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L374-L430 | train |
gatkin/declxml | declxml.py | boolean | def boolean(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=False, # type: Optional[bool]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# ty... | python | def boolean(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=False, # type: Optional[bool]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# ty... | [
"def",
"boolean",
"(",
"element_name",
",",
"attribute",
"=",
"None",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"default",
"=",
"False",
",",
"omit_empty",
"=",
"False",
",",
"hooks",
"=",
"None",
")",
":",
"return",
"_PrimitiveValue"... | Create a processor for boolean values.
:param element_name: Name of the XML element containing the value. Can also be specified
using supported XPath syntax.
:param attribute: If specified, then the value is searched for under the
attribute within the element specified by element_name. If not s... | [
"Create",
"a",
"processor",
"for",
"boolean",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L433-L473 | train |
gatkin/declxml | declxml.py | dictionary | def dictionary(
element_name, # type: Text
children, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create a processor for dictionary values.
:pa... | python | def dictionary(
element_name, # type: Text
children, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create a processor for dictionary values.
:pa... | [
"def",
"dictionary",
"(",
"element_name",
",",
"children",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"hooks",
"=",
"None",
")",
":",
"processor",
"=",
"_Dictionary",
"(",
"element_name",
",",
"children",
",",
"required",
",",
"alias",
... | Create a processor for dictionary values.
:param element_name: Name of the XML element containing the dictionary value. Can also be
specified using supported XPath syntax.
:param children: List of declxml processor objects for processing the children
contained within the dictionary.
:param ... | [
"Create",
"a",
"processor",
"for",
"dictionary",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L476-L499 | train |
gatkin/declxml | declxml.py | floating_point | def floating_point(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=0.0, # type: Optional[float]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
... | python | def floating_point(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=0.0, # type: Optional[float]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
... | [
"def",
"floating_point",
"(",
"element_name",
",",
"attribute",
"=",
"None",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"default",
"=",
"0.0",
",",
"omit_empty",
"=",
"False",
",",
"hooks",
"=",
"None",
")",
":",
"value_parser",
"=",
... | Create a processor for floating point values.
See also :func:`declxml.boolean` | [
"Create",
"a",
"processor",
"for",
"floating",
"point",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L502-L527 | train |
gatkin/declxml | declxml.py | integer | def integer(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=0, # type: Optional[int]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# type: (... | python | def integer(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default=0, # type: Optional[int]
omit_empty=False, # type: bool
hooks=None # type: Optional[Hooks]
):
# type: (... | [
"def",
"integer",
"(",
"element_name",
",",
"attribute",
"=",
"None",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"default",
"=",
"0",
",",
"omit_empty",
"=",
"False",
",",
"hooks",
"=",
"None",
")",
":",
"value_parser",
"=",
"_number... | Create a processor for integer values.
See also :func:`declxml.boolean` | [
"Create",
"a",
"processor",
"for",
"integer",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L530-L555 | train |
gatkin/declxml | declxml.py | named_tuple | def named_tuple(
element_name, # type: Text
tuple_type, # type: Type[Tuple]
child_processors, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
... | python | def named_tuple(
element_name, # type: Text
tuple_type, # type: Type[Tuple]
child_processors, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
... | [
"def",
"named_tuple",
"(",
"element_name",
",",
"tuple_type",
",",
"child_processors",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"hooks",
"=",
"None",
")",
":",
"converter",
"=",
"_named_tuple_converter",
"(",
"tuple_type",
")",
"processor"... | Create a processor for namedtuple values.
:param tuple_type: The namedtuple type.
See also :func:`declxml.dictionary` | [
"Create",
"a",
"processor",
"for",
"namedtuple",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L558-L576 | train |
gatkin/declxml | declxml.py | string | def string(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default='', # type: Optional[Text]
omit_empty=False, # type: bool
strip_whitespace=True, # type: bool
hooks=... | python | def string(
element_name, # type: Text
attribute=None, # type: Optional[Text]
required=True, # type: bool
alias=None, # type: Optional[Text]
default='', # type: Optional[Text]
omit_empty=False, # type: bool
strip_whitespace=True, # type: bool
hooks=... | [
"def",
"string",
"(",
"element_name",
",",
"attribute",
"=",
"None",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"default",
"=",
"''",
",",
"omit_empty",
"=",
"False",
",",
"strip_whitespace",
"=",
"True",
",",
"hooks",
"=",
"None",
"... | Create a processor for string values.
:param strip_whitespace: Indicates whether leading and trailing whitespace should be stripped
from parsed string values.
See also :func:`declxml.boolean` | [
"Create",
"a",
"processor",
"for",
"string",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L579-L608 | train |
gatkin/declxml | declxml.py | user_object | def user_object(
element_name, # type: Text
cls, # type: Type[Any]
child_processors, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create a ... | python | def user_object(
element_name, # type: Text
cls, # type: Type[Any]
child_processors, # type: List[Processor]
required=True, # type: bool
alias=None, # type: Optional[Text]
hooks=None # type: Optional[Hooks]
):
# type: (...) -> RootProcessor
"""
Create a ... | [
"def",
"user_object",
"(",
"element_name",
",",
"cls",
",",
"child_processors",
",",
"required",
"=",
"True",
",",
"alias",
"=",
"None",
",",
"hooks",
"=",
"None",
")",
":",
"converter",
"=",
"_user_object_converter",
"(",
"cls",
")",
"processor",
"=",
"_A... | Create a processor for user objects.
:param cls: Class object with a no-argument constructor or other callable no-argument object.
See also :func:`declxml.dictionary` | [
"Create",
"a",
"processor",
"for",
"user",
"objects",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L611-L629 | train |
gatkin/declxml | declxml.py | _element_append_path | def _element_append_path(
start_element, # type: ET.Element
element_names # type: Iterable[Text]
):
# type: (...) -> ET.Element
"""
Append the list of element names as a path to the provided start element.
:return: The final element along the path.
"""
end_element = start_elem... | python | def _element_append_path(
start_element, # type: ET.Element
element_names # type: Iterable[Text]
):
# type: (...) -> ET.Element
"""
Append the list of element names as a path to the provided start element.
:return: The final element along the path.
"""
end_element = start_elem... | [
"def",
"_element_append_path",
"(",
"start_element",
",",
"element_names",
")",
":",
"end_element",
"=",
"start_element",
"for",
"element_name",
"in",
"element_names",
":",
"new_element",
"=",
"ET",
".",
"Element",
"(",
"element_name",
")",
"end_element",
".",
"ap... | Append the list of element names as a path to the provided start element.
:return: The final element along the path. | [
"Append",
"the",
"list",
"of",
"element",
"names",
"as",
"a",
"path",
"to",
"the",
"provided",
"start",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1390-L1406 | train |
gatkin/declxml | declxml.py | _element_find_from_root | def _element_find_from_root(
root, # type: ET.Element
element_path # type: Text
):
# type: (...) -> Optional[ET.Element]
"""
Find the element specified by the given path starting from the root element of the document.
The first component of the element path is expected to be the name ... | python | def _element_find_from_root(
root, # type: ET.Element
element_path # type: Text
):
# type: (...) -> Optional[ET.Element]
"""
Find the element specified by the given path starting from the root element of the document.
The first component of the element path is expected to be the name ... | [
"def",
"_element_find_from_root",
"(",
"root",
",",
"element_path",
")",
":",
"element",
"=",
"None",
"element_names",
"=",
"element_path",
".",
"split",
"(",
"'/'",
")",
"if",
"element_names",
"[",
"0",
"]",
"==",
"root",
".",
"tag",
":",
"if",
"len",
"... | Find the element specified by the given path starting from the root element of the document.
The first component of the element path is expected to be the name of the root element. Return
None if the element is not found. | [
"Find",
"the",
"element",
"specified",
"by",
"the",
"given",
"path",
"starting",
"from",
"the",
"root",
"element",
"of",
"the",
"document",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1409-L1429 | train |
gatkin/declxml | declxml.py | _element_get_or_add_from_parent | def _element_get_or_add_from_parent(
parent, # type: ET.Element
element_path # type: Text
):
# type: (...) -> ET.Element
"""
Ensure all elements specified in the given path relative to the provided parent element exist.
Create new elements along the path only when needed, and return t... | python | def _element_get_or_add_from_parent(
parent, # type: ET.Element
element_path # type: Text
):
# type: (...) -> ET.Element
"""
Ensure all elements specified in the given path relative to the provided parent element exist.
Create new elements along the path only when needed, and return t... | [
"def",
"_element_get_or_add_from_parent",
"(",
"parent",
",",
"element_path",
")",
":",
"element_names",
"=",
"element_path",
".",
"split",
"(",
"'/'",
")",
"existing_element",
"=",
"None",
"previous_element",
"=",
"parent",
"for",
"i",
",",
"element_name",
"in",
... | Ensure all elements specified in the given path relative to the provided parent element exist.
Create new elements along the path only when needed, and return the final element specified
by the path. | [
"Ensure",
"all",
"elements",
"specified",
"in",
"the",
"given",
"path",
"relative",
"to",
"the",
"provided",
"parent",
"element",
"exist",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1432-L1460 | train |
gatkin/declxml | declxml.py | _element_path_create_new | def _element_path_create_new(element_path):
# type: (Text) -> Tuple[ET.Element, ET.Element]
"""
Create an entirely new element path.
Return a tuple where the first item is the first element in the path, and the second item is
the final element in the path.
"""
element_names = element_path.s... | python | def _element_path_create_new(element_path):
# type: (Text) -> Tuple[ET.Element, ET.Element]
"""
Create an entirely new element path.
Return a tuple where the first item is the first element in the path, and the second item is
the final element in the path.
"""
element_names = element_path.s... | [
"def",
"_element_path_create_new",
"(",
"element_path",
")",
":",
"element_names",
"=",
"element_path",
".",
"split",
"(",
"'/'",
")",
"start_element",
"=",
"ET",
".",
"Element",
"(",
"element_names",
"[",
"0",
"]",
")",
"end_element",
"=",
"_element_append_path... | Create an entirely new element path.
Return a tuple where the first item is the first element in the path, and the second item is
the final element in the path. | [
"Create",
"an",
"entirely",
"new",
"element",
"path",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1463-L1476 | train |
gatkin/declxml | declxml.py | _hooks_apply_after_parse | def _hooks_apply_after_parse(
hooks, # type: Optional[Hooks]
state, # type: _ProcessorState
value # type: Any
):
# type: (...) -> Any
"""Apply the after parse hook."""
if hooks and hooks.after_parse:
return hooks.after_parse(ProcessorStateView(state), value)
return va... | python | def _hooks_apply_after_parse(
hooks, # type: Optional[Hooks]
state, # type: _ProcessorState
value # type: Any
):
# type: (...) -> Any
"""Apply the after parse hook."""
if hooks and hooks.after_parse:
return hooks.after_parse(ProcessorStateView(state), value)
return va... | [
"def",
"_hooks_apply_after_parse",
"(",
"hooks",
",",
"state",
",",
"value",
")",
":",
"if",
"hooks",
"and",
"hooks",
".",
"after_parse",
":",
"return",
"hooks",
".",
"after_parse",
"(",
"ProcessorStateView",
"(",
"state",
")",
",",
"value",
")",
"return",
... | Apply the after parse hook. | [
"Apply",
"the",
"after",
"parse",
"hook",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1479-L1489 | train |
gatkin/declxml | declxml.py | _hooks_apply_before_serialize | def _hooks_apply_before_serialize(
hooks, # type: Optional[Hooks]
state, # type: _ProcessorState
value # type: Any
):
# type: (...) -> Any
"""Apply the before serialize hook."""
if hooks and hooks.before_serialize:
return hooks.before_serialize(ProcessorStateView(state), v... | python | def _hooks_apply_before_serialize(
hooks, # type: Optional[Hooks]
state, # type: _ProcessorState
value # type: Any
):
# type: (...) -> Any
"""Apply the before serialize hook."""
if hooks and hooks.before_serialize:
return hooks.before_serialize(ProcessorStateView(state), v... | [
"def",
"_hooks_apply_before_serialize",
"(",
"hooks",
",",
"state",
",",
"value",
")",
":",
"if",
"hooks",
"and",
"hooks",
".",
"before_serialize",
":",
"return",
"hooks",
".",
"before_serialize",
"(",
"ProcessorStateView",
"(",
"state",
")",
",",
"value",
")"... | Apply the before serialize hook. | [
"Apply",
"the",
"before",
"serialize",
"hook",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1492-L1502 | train |
gatkin/declxml | declxml.py | _named_tuple_converter | def _named_tuple_converter(tuple_type):
# type: (Type[Tuple]) -> _AggregateConverter
"""Return an _AggregateConverter for named tuples of the given type."""
def _from_dict(dict_value):
if dict_value:
return tuple_type(**dict_value)
# Cannot construct a namedtuple value from an e... | python | def _named_tuple_converter(tuple_type):
# type: (Type[Tuple]) -> _AggregateConverter
"""Return an _AggregateConverter for named tuples of the given type."""
def _from_dict(dict_value):
if dict_value:
return tuple_type(**dict_value)
# Cannot construct a namedtuple value from an e... | [
"def",
"_named_tuple_converter",
"(",
"tuple_type",
")",
":",
"def",
"_from_dict",
"(",
"dict_value",
")",
":",
"if",
"dict_value",
":",
"return",
"tuple_type",
"(",
"**",
"dict_value",
")",
"return",
"None",
"def",
"_to_dict",
"(",
"value",
")",
":",
"if",
... | Return an _AggregateConverter for named tuples of the given type. | [
"Return",
"an",
"_AggregateConverter",
"for",
"named",
"tuples",
"of",
"the",
"given",
"type",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1511-L1528 | train |
gatkin/declxml | declxml.py | _number_parser | def _number_parser(str_to_number_func):
"""Return a function to parse numbers."""
def _parse_number_value(element_text, state):
value = None
try:
value = str_to_number_func(element_text)
except (ValueError, TypeError):
state.raise_error(InvalidPrimitiveValue,
... | python | def _number_parser(str_to_number_func):
"""Return a function to parse numbers."""
def _parse_number_value(element_text, state):
value = None
try:
value = str_to_number_func(element_text)
except (ValueError, TypeError):
state.raise_error(InvalidPrimitiveValue,
... | [
"def",
"_number_parser",
"(",
"str_to_number_func",
")",
":",
"def",
"_parse_number_value",
"(",
"element_text",
",",
"state",
")",
":",
"value",
"=",
"None",
"try",
":",
"value",
"=",
"str_to_number_func",
"(",
"element_text",
")",
"except",
"(",
"ValueError",
... | Return a function to parse numbers. | [
"Return",
"a",
"function",
"to",
"parse",
"numbers",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1531-L1544 | train |
gatkin/declxml | declxml.py | _parse_boolean | def _parse_boolean(element_text, state):
"""Parse the raw XML string as a boolean value."""
value = None
lowered_text = element_text.lower()
if lowered_text == 'true':
value = True
elif lowered_text == 'false':
value = False
else:
state.raise_error(InvalidPrimitiveValue,... | python | def _parse_boolean(element_text, state):
"""Parse the raw XML string as a boolean value."""
value = None
lowered_text = element_text.lower()
if lowered_text == 'true':
value = True
elif lowered_text == 'false':
value = False
else:
state.raise_error(InvalidPrimitiveValue,... | [
"def",
"_parse_boolean",
"(",
"element_text",
",",
"state",
")",
":",
"value",
"=",
"None",
"lowered_text",
"=",
"element_text",
".",
"lower",
"(",
")",
"if",
"lowered_text",
"==",
"'true'",
":",
"value",
"=",
"True",
"elif",
"lowered_text",
"==",
"'false'",... | Parse the raw XML string as a boolean value. | [
"Parse",
"the",
"raw",
"XML",
"string",
"as",
"a",
"boolean",
"value",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1547-L1559 | train |
gatkin/declxml | declxml.py | _string_parser | def _string_parser(strip_whitespace):
"""Return a parser function for parsing string values."""
def _parse_string_value(element_text, _state):
if element_text is None:
value = ''
elif strip_whitespace:
value = element_text.strip()
else:
value = element... | python | def _string_parser(strip_whitespace):
"""Return a parser function for parsing string values."""
def _parse_string_value(element_text, _state):
if element_text is None:
value = ''
elif strip_whitespace:
value = element_text.strip()
else:
value = element... | [
"def",
"_string_parser",
"(",
"strip_whitespace",
")",
":",
"def",
"_parse_string_value",
"(",
"element_text",
",",
"_state",
")",
":",
"if",
"element_text",
"is",
"None",
":",
"value",
"=",
"''",
"elif",
"strip_whitespace",
":",
"value",
"=",
"element_text",
... | Return a parser function for parsing string values. | [
"Return",
"a",
"parser",
"function",
"for",
"parsing",
"string",
"values",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1574-L1586 | train |
gatkin/declxml | declxml.py | _user_object_converter | def _user_object_converter(cls):
# type: (Type[Any]) -> _AggregateConverter
"""Return an _AggregateConverter for a user object of the given class."""
def _from_dict(dict_value):
try:
object_value = cls(**dict_value)
except TypeError:
# Constructor does not support key... | python | def _user_object_converter(cls):
# type: (Type[Any]) -> _AggregateConverter
"""Return an _AggregateConverter for a user object of the given class."""
def _from_dict(dict_value):
try:
object_value = cls(**dict_value)
except TypeError:
# Constructor does not support key... | [
"def",
"_user_object_converter",
"(",
"cls",
")",
":",
"def",
"_from_dict",
"(",
"dict_value",
")",
":",
"try",
":",
"object_value",
"=",
"cls",
"(",
"**",
"dict_value",
")",
"except",
"TypeError",
":",
"object_value",
"=",
"cls",
"(",
")",
"for",
"field_n... | Return an _AggregateConverter for a user object of the given class. | [
"Return",
"an",
"_AggregateConverter",
"for",
"a",
"user",
"object",
"of",
"the",
"given",
"class",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1589-L1610 | train |
gatkin/declxml | declxml.py | _xml_namespace_strip | def _xml_namespace_strip(root):
# type: (ET.Element) -> None
"""Strip the XML namespace prefix from all element tags under the given root Element."""
if '}' not in root.tag:
return # Nothing to do, no namespace present
for element in root.iter():
if '}' in element.tag:
elem... | python | def _xml_namespace_strip(root):
# type: (ET.Element) -> None
"""Strip the XML namespace prefix from all element tags under the given root Element."""
if '}' not in root.tag:
return # Nothing to do, no namespace present
for element in root.iter():
if '}' in element.tag:
elem... | [
"def",
"_xml_namespace_strip",
"(",
"root",
")",
":",
"if",
"'}'",
"not",
"in",
"root",
".",
"tag",
":",
"return",
"for",
"element",
"in",
"root",
".",
"iter",
"(",
")",
":",
"if",
"'}'",
"in",
"element",
".",
"tag",
":",
"element",
".",
"tag",
"="... | Strip the XML namespace prefix from all element tags under the given root Element. | [
"Strip",
"the",
"XML",
"namespace",
"prefix",
"from",
"all",
"element",
"tags",
"under",
"the",
"given",
"root",
"Element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1613-L1625 | train |
gatkin/declxml | declxml.py | _Aggregate.parse_at_element | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as an aggregate."""
parsed_dict = self._dictionary.parse_at_element(element, state)
return self._converter... | python | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as an aggregate."""
parsed_dict = self._dictionary.parse_at_element(element, state)
return self._converter... | [
"def",
"parse_at_element",
"(",
"self",
",",
"element",
",",
"state",
")",
":",
"parsed_dict",
"=",
"self",
".",
"_dictionary",
".",
"parse_at_element",
"(",
"element",
",",
"state",
")",
"return",
"self",
".",
"_converter",
".",
"from_dict",
"(",
"parsed_di... | Parse the provided element as an aggregate. | [
"Parse",
"the",
"provided",
"element",
"as",
"an",
"aggregate",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L678-L686 | train |
gatkin/declxml | declxml.py | _Aggregate.parse_at_root | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as an aggregate."""
parsed_dict = self._dictionary.parse_at_root(root, state)
return self._converter.from_dict(p... | python | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as an aggregate."""
parsed_dict = self._dictionary.parse_at_root(root, state)
return self._converter.from_dict(p... | [
"def",
"parse_at_root",
"(",
"self",
",",
"root",
",",
"state",
")",
":",
"parsed_dict",
"=",
"self",
".",
"_dictionary",
".",
"parse_at_root",
"(",
"root",
",",
"state",
")",
"return",
"self",
".",
"_converter",
".",
"from_dict",
"(",
"parsed_dict",
")"
] | Parse the root XML element as an aggregate. | [
"Parse",
"the",
"root",
"XML",
"element",
"as",
"an",
"aggregate",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L688-L696 | train |
gatkin/declxml | declxml.py | _Aggregate.parse_from_parent | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the aggregate from the provided parent XML element."""
parsed_dict = self._dictionary.parse_from_parent(parent, state)
return s... | python | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the aggregate from the provided parent XML element."""
parsed_dict = self._dictionary.parse_from_parent(parent, state)
return s... | [
"def",
"parse_from_parent",
"(",
"self",
",",
"parent",
",",
"state",
")",
":",
"parsed_dict",
"=",
"self",
".",
"_dictionary",
".",
"parse_from_parent",
"(",
"parent",
",",
"state",
")",
"return",
"self",
".",
"_converter",
".",
"from_dict",
"(",
"parsed_di... | Parse the aggregate from the provided parent XML element. | [
"Parse",
"the",
"aggregate",
"from",
"the",
"provided",
"parent",
"XML",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L698-L706 | train |
gatkin/declxml | declxml.py | _Aggregate.serialize | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value to a new element and returns the element."""
dict_value = self._converter.to_dict(value)
return self._dictionary.serialize... | python | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value to a new element and returns the element."""
dict_value = self._converter.to_dict(value)
return self._dictionary.serialize... | [
"def",
"serialize",
"(",
"self",
",",
"value",
",",
"state",
")",
":",
"dict_value",
"=",
"self",
".",
"_converter",
".",
"to_dict",
"(",
"value",
")",
"return",
"self",
".",
"_dictionary",
".",
"serialize",
"(",
"dict_value",
",",
"state",
")"
] | Serialize the value to a new element and returns the element. | [
"Serialize",
"the",
"value",
"to",
"a",
"new",
"element",
"and",
"returns",
"the",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L708-L716 | train |
gatkin/declxml | declxml.py | _Aggregate.serialize_on_parent | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and adds it to the parent."""
dict_value = self._converter.to_dict(value)
self... | python | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and adds it to the parent."""
dict_value = self._converter.to_dict(value)
self... | [
"def",
"serialize_on_parent",
"(",
"self",
",",
"parent",
",",
"value",
",",
"state",
")",
":",
"dict_value",
"=",
"self",
".",
"_converter",
".",
"to_dict",
"(",
"value",
")",
"self",
".",
"_dictionary",
".",
"serialize_on_parent",
"(",
"parent",
",",
"di... | Serialize the value and adds it to the parent. | [
"Serialize",
"the",
"value",
"and",
"adds",
"it",
"to",
"the",
"parent",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L718-L727 | train |
gatkin/declxml | declxml.py | _Array.parse_at_element | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as an array."""
item_iter = element.findall(self._item_processor.element_path)
return self._parse(item_ite... | python | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as an array."""
item_iter = element.findall(self._item_processor.element_path)
return self._parse(item_ite... | [
"def",
"parse_at_element",
"(",
"self",
",",
"element",
",",
"state",
")",
":",
"item_iter",
"=",
"element",
".",
"findall",
"(",
"self",
".",
"_item_processor",
".",
"element_path",
")",
"return",
"self",
".",
"_parse",
"(",
"item_iter",
",",
"state",
")"... | Parse the provided element as an array. | [
"Parse",
"the",
"provided",
"element",
"as",
"an",
"array",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L784-L792 | train |
gatkin/declxml | declxml.py | _Array.parse_at_root | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as an array."""
if not self._nested:
raise InvalidRootProcessor('Non-nested array "{}" cannot be root elemen... | python | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as an array."""
if not self._nested:
raise InvalidRootProcessor('Non-nested array "{}" cannot be root elemen... | [
"def",
"parse_at_root",
"(",
"self",
",",
"root",
",",
"state",
")",
":",
"if",
"not",
"self",
".",
"_nested",
":",
"raise",
"InvalidRootProcessor",
"(",
"'Non-nested array \"{}\" cannot be root element'",
".",
"format",
"(",
"self",
".",
"alias",
")",
")",
"p... | Parse the root XML element as an array. | [
"Parse",
"the",
"root",
"XML",
"element",
"as",
"an",
"array",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L794-L813 | train |
gatkin/declxml | declxml.py | _Array.parse_from_parent | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the array data from the provided parent XML element."""
item_iter = parent.findall(self._item_path)
return self._parse(item_ite... | python | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the array data from the provided parent XML element."""
item_iter = parent.findall(self._item_path)
return self._parse(item_ite... | [
"def",
"parse_from_parent",
"(",
"self",
",",
"parent",
",",
"state",
")",
":",
"item_iter",
"=",
"parent",
".",
"findall",
"(",
"self",
".",
"_item_path",
")",
"return",
"self",
".",
"_parse",
"(",
"item_iter",
",",
"state",
")"
] | Parse the array data from the provided parent XML element. | [
"Parse",
"the",
"array",
"data",
"from",
"the",
"provided",
"parent",
"XML",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L815-L823 | train |
gatkin/declxml | declxml.py | _Array.serialize | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value into a new Element object and return it."""
if self._nested is None:
state.raise_error(InvalidRootProcessor,
... | python | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value into a new Element object and return it."""
if self._nested is None:
state.raise_error(InvalidRootProcessor,
... | [
"def",
"serialize",
"(",
"self",
",",
"value",
",",
"state",
")",
":",
"if",
"self",
".",
"_nested",
"is",
"None",
":",
"state",
".",
"raise_error",
"(",
"InvalidRootProcessor",
",",
"'Cannot directly serialize a non-nested array \"{}\"'",
".",
"format",
"(",
"s... | Serialize the value into a new Element object and return it. | [
"Serialize",
"the",
"value",
"into",
"a",
"new",
"Element",
"object",
"and",
"return",
"it",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L825-L844 | train |
gatkin/declxml | declxml.py | _Array.serialize_on_parent | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and append it to the parent element."""
if not value and self.required:
st... | python | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and append it to the parent element."""
if not value and self.required:
st... | [
"def",
"serialize_on_parent",
"(",
"self",
",",
"parent",
",",
"value",
",",
"state",
")",
":",
"if",
"not",
"value",
"and",
"self",
".",
"required",
":",
"state",
".",
"raise_error",
"(",
"MissingValue",
",",
"'Missing required array: \"{}\"'",
".",
"format",... | Serialize the value and append it to the parent element. | [
"Serialize",
"the",
"value",
"and",
"append",
"it",
"to",
"the",
"parent",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L846-L867 | train |
gatkin/declxml | declxml.py | _Array._parse | def _parse(
self,
item_iter, # type: Iterable[ET.Element]
state # type: _ProcessorState
):
# type: (...) -> List
"""Parse the array data using the provided iterator of XML elements."""
parsed_array = []
for i, item in enumerate(item_iter):
... | python | def _parse(
self,
item_iter, # type: Iterable[ET.Element]
state # type: _ProcessorState
):
# type: (...) -> List
"""Parse the array data using the provided iterator of XML elements."""
parsed_array = []
for i, item in enumerate(item_iter):
... | [
"def",
"_parse",
"(",
"self",
",",
"item_iter",
",",
"state",
")",
":",
"parsed_array",
"=",
"[",
"]",
"for",
"i",
",",
"item",
"in",
"enumerate",
"(",
"item_iter",
")",
":",
"state",
".",
"push_location",
"(",
"self",
".",
"_item_processor",
".",
"ele... | Parse the array data using the provided iterator of XML elements. | [
"Parse",
"the",
"array",
"data",
"using",
"the",
"provided",
"iterator",
"of",
"XML",
"elements",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L869-L886 | train |
gatkin/declxml | declxml.py | _Array._serialize | def _serialize(
self,
array_parent, # type: ET.Element
value, # type: List
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the array value and add it to the array parent element."""
if not value:
# Nothing to ... | python | def _serialize(
self,
array_parent, # type: ET.Element
value, # type: List
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the array value and add it to the array parent element."""
if not value:
# Nothing to ... | [
"def",
"_serialize",
"(",
"self",
",",
"array_parent",
",",
"value",
",",
"state",
")",
":",
"if",
"not",
"value",
":",
"return",
"for",
"i",
",",
"item_value",
"in",
"enumerate",
"(",
"value",
")",
":",
"state",
".",
"push_location",
"(",
"self",
".",... | Serialize the array value and add it to the array parent element. | [
"Serialize",
"the",
"array",
"value",
"and",
"add",
"it",
"to",
"the",
"array",
"parent",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L888-L905 | train |
gatkin/declxml | declxml.py | _Dictionary.parse_at_element | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as a dictionary."""
parsed_dict = {}
for child in self._child_processors:
state.push_location... | python | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the provided element as a dictionary."""
parsed_dict = {}
for child in self._child_processors:
state.push_location... | [
"def",
"parse_at_element",
"(",
"self",
",",
"element",
",",
"state",
")",
":",
"parsed_dict",
"=",
"{",
"}",
"for",
"child",
"in",
"self",
".",
"_child_processors",
":",
"state",
".",
"push_location",
"(",
"child",
".",
"element_path",
")",
"parsed_dict",
... | Parse the provided element as a dictionary. | [
"Parse",
"the",
"provided",
"element",
"as",
"a",
"dictionary",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L945-L959 | train |
gatkin/declxml | declxml.py | _Dictionary.parse_at_root | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as a dictionary."""
parsed_dict = {} # type: Dict
dict_element = _element_find_from_root(root, self.element_pa... | python | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the root XML element as a dictionary."""
parsed_dict = {} # type: Dict
dict_element = _element_find_from_root(root, self.element_pa... | [
"def",
"parse_at_root",
"(",
"self",
",",
"root",
",",
"state",
")",
":",
"parsed_dict",
"=",
"{",
"}",
"dict_element",
"=",
"_element_find_from_root",
"(",
"root",
",",
"self",
".",
"element_path",
")",
"if",
"dict_element",
"is",
"not",
"None",
":",
"par... | Parse the root XML element as a dictionary. | [
"Parse",
"the",
"root",
"XML",
"element",
"as",
"a",
"dictionary",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L961-L976 | train |
gatkin/declxml | declxml.py | _Dictionary.serialize | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value to a new element and return the element."""
if not value and self.required:
state.raise_error(
Missing... | python | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value to a new element and return the element."""
if not value and self.required:
state.raise_error(
Missing... | [
"def",
"serialize",
"(",
"self",
",",
"value",
",",
"state",
")",
":",
"if",
"not",
"value",
"and",
"self",
".",
"required",
":",
"state",
".",
"raise_error",
"(",
"MissingValue",
",",
"'Missing required aggregate \"{}\"'",
".",
"format",
"(",
"self",
".",
... | Serialize the value to a new element and return the element. | [
"Serialize",
"the",
"value",
"to",
"a",
"new",
"element",
"and",
"return",
"the",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L996-L1010 | train |
gatkin/declxml | declxml.py | _Dictionary._serialize | def _serialize(
self,
element, # type: ET.Element
value, # type: Dict
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the dictionary and append all serialized children to the element."""
for child in self._child_processor... | python | def _serialize(
self,
element, # type: ET.Element
value, # type: Dict
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the dictionary and append all serialized children to the element."""
for child in self._child_processor... | [
"def",
"_serialize",
"(",
"self",
",",
"element",
",",
"value",
",",
"state",
")",
":",
"for",
"child",
"in",
"self",
".",
"_child_processors",
":",
"state",
".",
"push_location",
"(",
"child",
".",
"element_path",
")",
"child_value",
"=",
"value",
".",
... | Serialize the dictionary and append all serialized children to the element. | [
"Serialize",
"the",
"dictionary",
"and",
"append",
"all",
"serialized",
"children",
"to",
"the",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1030-L1042 | train |
gatkin/declxml | declxml.py | _HookedAggregate.parse_at_element | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the given element."""
xml_value = self._processor.parse_at_element(element, state)
return _hooks_apply_after_parse(self._hooks,... | python | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the given element."""
xml_value = self._processor.parse_at_element(element, state)
return _hooks_apply_after_parse(self._hooks,... | [
"def",
"parse_at_element",
"(",
"self",
",",
"element",
",",
"state",
")",
":",
"xml_value",
"=",
"self",
".",
"_processor",
".",
"parse_at_element",
"(",
"element",
",",
"state",
")",
"return",
"_hooks_apply_after_parse",
"(",
"self",
".",
"_hooks",
",",
"s... | Parse the given element. | [
"Parse",
"the",
"given",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1078-L1086 | train |
gatkin/declxml | declxml.py | _HookedAggregate.parse_at_root | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the given element as the root of the document."""
xml_value = self._processor.parse_at_root(root, state)
return _hooks_apply_after_pa... | python | def parse_at_root(
self,
root, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the given element as the root of the document."""
xml_value = self._processor.parse_at_root(root, state)
return _hooks_apply_after_pa... | [
"def",
"parse_at_root",
"(",
"self",
",",
"root",
",",
"state",
")",
":",
"xml_value",
"=",
"self",
".",
"_processor",
".",
"parse_at_root",
"(",
"root",
",",
"state",
")",
"return",
"_hooks_apply_after_parse",
"(",
"self",
".",
"_hooks",
",",
"state",
","... | Parse the given element as the root of the document. | [
"Parse",
"the",
"given",
"element",
"as",
"the",
"root",
"of",
"the",
"document",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1088-L1096 | train |
gatkin/declxml | declxml.py | _HookedAggregate.parse_from_parent | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the element from the given parent element."""
xml_value = self._processor.parse_from_parent(parent, state)
return _hooks_apply_... | python | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the element from the given parent element."""
xml_value = self._processor.parse_from_parent(parent, state)
return _hooks_apply_... | [
"def",
"parse_from_parent",
"(",
"self",
",",
"parent",
",",
"state",
")",
":",
"xml_value",
"=",
"self",
".",
"_processor",
".",
"parse_from_parent",
"(",
"parent",
",",
"state",
")",
"return",
"_hooks_apply_after_parse",
"(",
"self",
".",
"_hooks",
",",
"s... | Parse the element from the given parent element. | [
"Parse",
"the",
"element",
"from",
"the",
"given",
"parent",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1098-L1106 | train |
gatkin/declxml | declxml.py | _HookedAggregate.serialize | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value and returns it."""
xml_value = _hooks_apply_before_serialize(self._hooks, state, value)
return self._processor.serialize(x... | python | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""Serialize the value and returns it."""
xml_value = _hooks_apply_before_serialize(self._hooks, state, value)
return self._processor.serialize(x... | [
"def",
"serialize",
"(",
"self",
",",
"value",
",",
"state",
")",
":",
"xml_value",
"=",
"_hooks_apply_before_serialize",
"(",
"self",
".",
"_hooks",
",",
"state",
",",
"value",
")",
"return",
"self",
".",
"_processor",
".",
"serialize",
"(",
"xml_value",
... | Serialize the value and returns it. | [
"Serialize",
"the",
"value",
"and",
"returns",
"it",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1108-L1116 | train |
gatkin/declxml | declxml.py | _HookedAggregate.serialize_on_parent | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value directory on the parent."""
xml_value = _hooks_apply_before_serialize(self._hooks, sta... | python | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value directory on the parent."""
xml_value = _hooks_apply_before_serialize(self._hooks, sta... | [
"def",
"serialize_on_parent",
"(",
"self",
",",
"parent",
",",
"value",
",",
"state",
")",
":",
"xml_value",
"=",
"_hooks_apply_before_serialize",
"(",
"self",
".",
"_hooks",
",",
"state",
",",
"value",
")",
"self",
".",
"_processor",
".",
"serialize_on_parent... | Serialize the value directory on the parent. | [
"Serialize",
"the",
"value",
"directory",
"on",
"the",
"parent",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1118-L1127 | train |
gatkin/declxml | declxml.py | _PrimitiveValue.parse_at_element | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value at the XML element."""
if self._attribute:
parsed_value = self._parse_attribute(element, self._attribut... | python | def parse_at_element(
self,
element, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value at the XML element."""
if self._attribute:
parsed_value = self._parse_attribute(element, self._attribut... | [
"def",
"parse_at_element",
"(",
"self",
",",
"element",
",",
"state",
")",
":",
"if",
"self",
".",
"_attribute",
":",
"parsed_value",
"=",
"self",
".",
"_parse_attribute",
"(",
"element",
",",
"self",
".",
"_attribute",
",",
"state",
")",
"else",
":",
"p... | Parse the primitive value at the XML element. | [
"Parse",
"the",
"primitive",
"value",
"at",
"the",
"XML",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1202-L1214 | train |
gatkin/declxml | declxml.py | _PrimitiveValue.parse_from_parent | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value under the parent XML element."""
element = parent.find(self.element_path)
if element is None and self.requ... | python | def parse_from_parent(
self,
parent, # type: ET.Element
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value under the parent XML element."""
element = parent.find(self.element_path)
if element is None and self.requ... | [
"def",
"parse_from_parent",
"(",
"self",
",",
"parent",
",",
"state",
")",
":",
"element",
"=",
"parent",
".",
"find",
"(",
"self",
".",
"element_path",
")",
"if",
"element",
"is",
"None",
"and",
"self",
".",
"required",
":",
"state",
".",
"raise_error",... | Parse the primitive value under the parent XML element. | [
"Parse",
"the",
"primitive",
"value",
"under",
"the",
"parent",
"XML",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1216-L1232 | train |
gatkin/declxml | declxml.py | _PrimitiveValue.serialize | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""
Serialize the value into a new element object and return the element.
If the omit_empty option was specified and the value is falsey, then t... | python | def serialize(
self,
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> ET.Element
"""
Serialize the value into a new element object and return the element.
If the omit_empty option was specified and the value is falsey, then t... | [
"def",
"serialize",
"(",
"self",
",",
"value",
",",
"state",
")",
":",
"start_element",
",",
"end_element",
"=",
"_element_path_create_new",
"(",
"self",
".",
"element_path",
")",
"self",
".",
"_serialize",
"(",
"end_element",
",",
"value",
",",
"state",
")"... | Serialize the value into a new element object and return the element.
If the omit_empty option was specified and the value is falsey, then this will return None. | [
"Serialize",
"the",
"value",
"into",
"a",
"new",
"element",
"object",
"and",
"return",
"the",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1234-L1249 | train |
gatkin/declxml | declxml.py | _PrimitiveValue.serialize_on_parent | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and add it to the parent element."""
# Note that falsey values are not treated as miss... | python | def serialize_on_parent(
self,
parent, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value and add it to the parent element."""
# Note that falsey values are not treated as miss... | [
"def",
"serialize_on_parent",
"(",
"self",
",",
"parent",
",",
"value",
",",
"state",
")",
":",
"if",
"value",
"is",
"None",
"and",
"self",
".",
"required",
":",
"state",
".",
"raise_error",
"(",
"MissingValue",
",",
"self",
".",
"_missing_value_message",
... | Serialize the value and add it to the parent element. | [
"Serialize",
"the",
"value",
"and",
"add",
"it",
"to",
"the",
"parent",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1251-L1267 | train |
gatkin/declxml | declxml.py | _PrimitiveValue._missing_value_message | def _missing_value_message(self, parent):
# type: (ET.Element) -> Text
"""Return the message to report that the value needed for serialization is missing."""
if self._attribute is None:
message = 'Missing required value for element "{}"'.format(self.element_path)
else:
... | python | def _missing_value_message(self, parent):
# type: (ET.Element) -> Text
"""Return the message to report that the value needed for serialization is missing."""
if self._attribute is None:
message = 'Missing required value for element "{}"'.format(self.element_path)
else:
... | [
"def",
"_missing_value_message",
"(",
"self",
",",
"parent",
")",
":",
"if",
"self",
".",
"_attribute",
"is",
"None",
":",
"message",
"=",
"'Missing required value for element \"{}\"'",
".",
"format",
"(",
"self",
".",
"element_path",
")",
"else",
":",
"if",
"... | Return the message to report that the value needed for serialization is missing. | [
"Return",
"the",
"message",
"to",
"report",
"that",
"the",
"value",
"needed",
"for",
"serialization",
"is",
"missing",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1269-L1283 | train |
gatkin/declxml | declxml.py | _PrimitiveValue._parse_attribute | def _parse_attribute(
self,
element, # type: ET.Element
attribute, # type: Text
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value within the XML element's attribute."""
parsed_value = self._default
at... | python | def _parse_attribute(
self,
element, # type: ET.Element
attribute, # type: Text
state # type: _ProcessorState
):
# type: (...) -> Any
"""Parse the primitive value within the XML element's attribute."""
parsed_value = self._default
at... | [
"def",
"_parse_attribute",
"(",
"self",
",",
"element",
",",
"attribute",
",",
"state",
")",
":",
"parsed_value",
"=",
"self",
".",
"_default",
"attribute_value",
"=",
"element",
".",
"get",
"(",
"attribute",
",",
"None",
")",
"if",
"attribute_value",
"is",
... | Parse the primitive value within the XML element's attribute. | [
"Parse",
"the",
"primitive",
"value",
"within",
"the",
"XML",
"element",
"s",
"attribute",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1285-L1305 | train |
gatkin/declxml | declxml.py | _PrimitiveValue._serialize | def _serialize(
self,
element, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value to the element."""
xml_value = _hooks_apply_before_serialize(self._hooks, state, value)
... | python | def _serialize(
self,
element, # type: ET.Element
value, # type: Any
state # type: _ProcessorState
):
# type: (...) -> None
"""Serialize the value to the element."""
xml_value = _hooks_apply_before_serialize(self._hooks, state, value)
... | [
"def",
"_serialize",
"(",
"self",
",",
"element",
",",
"value",
",",
"state",
")",
":",
"xml_value",
"=",
"_hooks_apply_before_serialize",
"(",
"self",
".",
"_hooks",
",",
"state",
",",
"value",
")",
"if",
"xml_value",
"is",
"None",
":",
"if",
"self",
".... | Serialize the value to the element. | [
"Serialize",
"the",
"value",
"to",
"the",
"element",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1307-L1331 | train |
gatkin/declxml | declxml.py | _ProcessorState.push_location | def push_location(
self,
element_path, # type: Text
array_index=None # type: Optional[int]
):
# type: (...) -> None
"""Push an item onto the state's stack of locations."""
location = ProcessorLocation(element_path=element_path, array_index=array_index)
... | python | def push_location(
self,
element_path, # type: Text
array_index=None # type: Optional[int]
):
# type: (...) -> None
"""Push an item onto the state's stack of locations."""
location = ProcessorLocation(element_path=element_path, array_index=array_index)
... | [
"def",
"push_location",
"(",
"self",
",",
"element_path",
",",
"array_index",
"=",
"None",
")",
":",
"location",
"=",
"ProcessorLocation",
"(",
"element_path",
"=",
"element_path",
",",
"array_index",
"=",
"array_index",
")",
"self",
".",
"_locations",
".",
"a... | Push an item onto the state's stack of locations. | [
"Push",
"an",
"item",
"onto",
"the",
"state",
"s",
"stack",
"of",
"locations",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1351-L1359 | train |
gatkin/declxml | declxml.py | _ProcessorState.raise_error | def raise_error(
self,
exception_type, # type: Type[Exception]
message # type: Text
):
# type: (...) -> NoReturn
"""Raise an exception with the current parser state information and error message."""
error_message = '{} at {}'.format(message, repr(self))
... | python | def raise_error(
self,
exception_type, # type: Type[Exception]
message # type: Text
):
# type: (...) -> NoReturn
"""Raise an exception with the current parser state information and error message."""
error_message = '{} at {}'.format(message, repr(self))
... | [
"def",
"raise_error",
"(",
"self",
",",
"exception_type",
",",
"message",
")",
":",
"error_message",
"=",
"'{} at {}'",
".",
"format",
"(",
"message",
",",
"repr",
"(",
"self",
")",
")",
"raise",
"exception_type",
"(",
"error_message",
")"
] | Raise an exception with the current parser state information and error message. | [
"Raise",
"an",
"exception",
"with",
"the",
"current",
"parser",
"state",
"information",
"and",
"error",
"message",
"."
] | 3a2324b43aee943e82a04587fbb68932c6f392ba | https://github.com/gatkin/declxml/blob/3a2324b43aee943e82a04587fbb68932c6f392ba/declxml.py#L1361-L1369 | train |
ponty/eagexp | eagexp/partlist.py | export_partlist_to_file | def export_partlist_to_file(input, output, timeout=20, showgui=False):
'''
call eagle and export sch or brd to partlist text file
:param input: .sch or .brd file name
:param output: text file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None
'''
... | python | def export_partlist_to_file(input, output, timeout=20, showgui=False):
'''
call eagle and export sch or brd to partlist text file
:param input: .sch or .brd file name
:param output: text file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None
'''
... | [
"def",
"export_partlist_to_file",
"(",
"input",
",",
"output",
",",
"timeout",
"=",
"20",
",",
"showgui",
"=",
"False",
")",
":",
"input",
"=",
"norm_path",
"(",
"input",
")",
"output",
"=",
"norm_path",
"(",
"output",
")",
"commands",
"=",
"export_command... | call eagle and export sch or brd to partlist text file
:param input: .sch or .brd file name
:param output: text file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None | [
"call",
"eagle",
"and",
"export",
"sch",
"or",
"brd",
"to",
"partlist",
"text",
"file"
] | 1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2 | https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/partlist.py#L16-L31 | train |
ponty/eagexp | eagexp/partlist.py | parse_partlist | def parse_partlist(str):
'''parse partlist text delivered by eagle.
header is converted to lowercase
:param str: input string
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value':'1n'}, ..])
'''
lines = str.strip().splitlines()
lines = filter(len, lines)... | python | def parse_partlist(str):
'''parse partlist text delivered by eagle.
header is converted to lowercase
:param str: input string
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value':'1n'}, ..])
'''
lines = str.strip().splitlines()
lines = filter(len, lines)... | [
"def",
"parse_partlist",
"(",
"str",
")",
":",
"lines",
"=",
"str",
".",
"strip",
"(",
")",
".",
"splitlines",
"(",
")",
"lines",
"=",
"filter",
"(",
"len",
",",
"lines",
")",
"hind",
"=",
"header_index",
"(",
"lines",
")",
"if",
"hind",
"is",
"Non... | parse partlist text delivered by eagle.
header is converted to lowercase
:param str: input string
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value':'1n'}, ..]) | [
"parse",
"partlist",
"text",
"delivered",
"by",
"eagle",
"."
] | 1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2 | https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/partlist.py#L40-L69 | train |
ponty/eagexp | eagexp/partlist.py | raw_partlist | def raw_partlist(input, timeout=20, showgui=False):
'''export partlist by eagle, then return it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: string
'''
output = tempfile.NamedTemporaryFile(
prefix='eagexp_', su... | python | def raw_partlist(input, timeout=20, showgui=False):
'''export partlist by eagle, then return it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: string
'''
output = tempfile.NamedTemporaryFile(
prefix='eagexp_', su... | [
"def",
"raw_partlist",
"(",
"input",
",",
"timeout",
"=",
"20",
",",
"showgui",
"=",
"False",
")",
":",
"output",
"=",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"prefix",
"=",
"'eagexp_'",
",",
"suffix",
"=",
"'.partlist'",
",",
"delete",
"=",
"0",
")"... | export partlist by eagle, then return it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: string | [
"export",
"partlist",
"by",
"eagle",
"then",
"return",
"it"
] | 1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2 | https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/partlist.py#L72-L87 | train |
ponty/eagexp | eagexp/partlist.py | structured_partlist | def structured_partlist(input, timeout=20, showgui=False):
'''export partlist by eagle, then parse it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value'... | python | def structured_partlist(input, timeout=20, showgui=False):
'''export partlist by eagle, then parse it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value'... | [
"def",
"structured_partlist",
"(",
"input",
",",
"timeout",
"=",
"20",
",",
"showgui",
"=",
"False",
")",
":",
"s",
"=",
"raw_partlist",
"(",
"input",
"=",
"input",
",",
"timeout",
"=",
"timeout",
",",
"showgui",
"=",
"showgui",
")",
"return",
"parse_par... | export partlist by eagle, then parse it
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: tuple of header list and dict list: (['part','value',..], [{'part':'C1', 'value':'1n'}, ..]) | [
"export",
"partlist",
"by",
"eagle",
"then",
"parse",
"it"
] | 1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2 | https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/partlist.py#L90-L100 | train |
ponty/eagexp | eagexp/partlist.py | print_partlist | def print_partlist(input, timeout=20, showgui=False):
'''print partlist text delivered by eagle
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None
'''
print raw_partlist(input=input, timeout=timeout, showgui=showgui) | python | def print_partlist(input, timeout=20, showgui=False):
'''print partlist text delivered by eagle
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None
'''
print raw_partlist(input=input, timeout=timeout, showgui=showgui) | [
"def",
"print_partlist",
"(",
"input",
",",
"timeout",
"=",
"20",
",",
"showgui",
"=",
"False",
")",
":",
"print",
"raw_partlist",
"(",
"input",
"=",
"input",
",",
"timeout",
"=",
"timeout",
",",
"showgui",
"=",
"showgui",
")"
] | print partlist text delivered by eagle
:param input: .sch or .brd file name
:param timeout: int
:param showgui: Bool, True -> do not hide eagle GUI
:rtype: None | [
"print",
"partlist",
"text",
"delivered",
"by",
"eagle"
] | 1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2 | https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/partlist.py#L104-L112 | train |
xflr6/bitsets | bitsets/visualize.py | bitset | def bitset(bs, member_label=None, filename=None, directory=None, format=None,
render=False, view=False):
"""Graphviz source for the Hasse diagram of the domains' Boolean algebra."""
if member_label is None:
member_label = MEMBER_LABEL
if filename is None:
kind = 'members' if memb... | python | def bitset(bs, member_label=None, filename=None, directory=None, format=None,
render=False, view=False):
"""Graphviz source for the Hasse diagram of the domains' Boolean algebra."""
if member_label is None:
member_label = MEMBER_LABEL
if filename is None:
kind = 'members' if memb... | [
"def",
"bitset",
"(",
"bs",
",",
"member_label",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"directory",
"=",
"None",
",",
"format",
"=",
"None",
",",
"render",
"=",
"False",
",",
"view",
"=",
"False",
")",
":",
"if",
"member_label",
"is",
"None... | Graphviz source for the Hasse diagram of the domains' Boolean algebra. | [
"Graphviz",
"source",
"for",
"the",
"Hasse",
"diagram",
"of",
"the",
"domains",
"Boolean",
"algebra",
"."
] | ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf | https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/visualize.py#L34-L68 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder._get_field_method | def _get_field_method(self, tp):
"""Returns a reference to the form element's constructor method."""
method = self.field_constructor.get(tp)
if method and hasattr(self, method.__name__):
return getattr(self, method.__name__)
return method | python | def _get_field_method(self, tp):
"""Returns a reference to the form element's constructor method."""
method = self.field_constructor.get(tp)
if method and hasattr(self, method.__name__):
return getattr(self, method.__name__)
return method | [
"def",
"_get_field_method",
"(",
"self",
",",
"tp",
")",
":",
"method",
"=",
"self",
".",
"field_constructor",
".",
"get",
"(",
"tp",
")",
"if",
"method",
"and",
"hasattr",
"(",
"self",
",",
"method",
".",
"__name__",
")",
":",
"return",
"getattr",
"("... | Returns a reference to the form element's constructor method. | [
"Returns",
"a",
"reference",
"to",
"the",
"form",
"element",
"s",
"constructor",
"method",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L66-L71 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder._create_plain_field | def _create_plain_field(self, attr, options):
"""Creates the form element."""
method = self._get_field_method(attr.py_type) or self._create_other_field
klass, options = method(attr, options)
if attr.is_unique:
options['validators'].append(validators.UniqueEntityValidator(att... | python | def _create_plain_field(self, attr, options):
"""Creates the form element."""
method = self._get_field_method(attr.py_type) or self._create_other_field
klass, options = method(attr, options)
if attr.is_unique:
options['validators'].append(validators.UniqueEntityValidator(att... | [
"def",
"_create_plain_field",
"(",
"self",
",",
"attr",
",",
"options",
")",
":",
"method",
"=",
"self",
".",
"_get_field_method",
"(",
"attr",
".",
"py_type",
")",
"or",
"self",
".",
"_create_other_field",
"klass",
",",
"options",
"=",
"method",
"(",
"att... | Creates the form element. | [
"Creates",
"the",
"form",
"element",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L77-L85 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder._create_relational_field | def _create_relational_field(self, attr, options):
"""Creates the form element for working with entity relationships."""
options['entity_class'] = attr.py_type
options['allow_empty'] = not attr.is_required
return EntityField, options | python | def _create_relational_field(self, attr, options):
"""Creates the form element for working with entity relationships."""
options['entity_class'] = attr.py_type
options['allow_empty'] = not attr.is_required
return EntityField, options | [
"def",
"_create_relational_field",
"(",
"self",
",",
"attr",
",",
"options",
")",
":",
"options",
"[",
"'entity_class'",
"]",
"=",
"attr",
".",
"py_type",
"options",
"[",
"'allow_empty'",
"]",
"=",
"not",
"attr",
".",
"is_required",
"return",
"EntityField",
... | Creates the form element for working with entity relationships. | [
"Creates",
"the",
"form",
"element",
"for",
"working",
"with",
"entity",
"relationships",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L92-L96 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder.add | def add(self, attr, field_class=None, **options):
"""Adds an element to the form based on the entity attribute."""
# print(attr.name, attr.py_type, getattr(attr, 'set', None))
# print(dir(attr))
# print(attr, attr.is_relation, attr.is_collection)
# print(attr.is_pk, attr.auto, at... | python | def add(self, attr, field_class=None, **options):
"""Adds an element to the form based on the entity attribute."""
# print(attr.name, attr.py_type, getattr(attr, 'set', None))
# print(dir(attr))
# print(attr, attr.is_relation, attr.is_collection)
# print(attr.is_pk, attr.auto, at... | [
"def",
"add",
"(",
"self",
",",
"attr",
",",
"field_class",
"=",
"None",
",",
"**",
"options",
")",
":",
"def",
"add",
"(",
"klass",
",",
"options",
")",
":",
"if",
"klass",
":",
"self",
".",
"_fields",
"[",
"attr",
".",
"name",
"]",
"=",
"field_... | Adds an element to the form based on the entity attribute. | [
"Adds",
"an",
"element",
"to",
"the",
"form",
"based",
"on",
"the",
"entity",
"attribute",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L102-L133 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder.add_button | def add_button(self, name, button_class=wtf_fields.SubmitField, **options):
"""Adds a button to the form."""
self._buttons[name] = button_class(**options) | python | def add_button(self, name, button_class=wtf_fields.SubmitField, **options):
"""Adds a button to the form."""
self._buttons[name] = button_class(**options) | [
"def",
"add_button",
"(",
"self",
",",
"name",
",",
"button_class",
"=",
"wtf_fields",
".",
"SubmitField",
",",
"**",
"options",
")",
":",
"self",
".",
"_buttons",
"[",
"name",
"]",
"=",
"button_class",
"(",
"**",
"options",
")"
] | Adds a button to the form. | [
"Adds",
"a",
"button",
"to",
"the",
"form",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L135-L137 | train |
kyzima-spb/flask-pony | flask_pony/orm.py | FormBuilder.field_uuid | def field_uuid(self, attr, options):
"""Creates a form element for the UUID type."""
options['validators'].append(validators.UUIDValidator(attr.entity))
return wtf_fields.StringField, options | python | def field_uuid(self, attr, options):
"""Creates a form element for the UUID type."""
options['validators'].append(validators.UUIDValidator(attr.entity))
return wtf_fields.StringField, options | [
"def",
"field_uuid",
"(",
"self",
",",
"attr",
",",
"options",
")",
":",
"options",
"[",
"'validators'",
"]",
".",
"append",
"(",
"validators",
".",
"UUIDValidator",
"(",
"attr",
".",
"entity",
")",
")",
"return",
"wtf_fields",
".",
"StringField",
",",
"... | Creates a form element for the UUID type. | [
"Creates",
"a",
"form",
"element",
"for",
"the",
"UUID",
"type",
"."
] | 6cf28d70b7ebf415d58fa138fcc70b8dd57432c7 | https://github.com/kyzima-spb/flask-pony/blob/6cf28d70b7ebf415d58fa138fcc70b8dd57432c7/flask_pony/orm.py#L198-L201 | train |
PaulMcMillan/tasa | tasa/cli.py | runm | def runm():
""" This is super minimal and pretty hacky, but it counts as a first pass.
"""
signal.signal(signal.SIGINT, signal_handler)
count = int(sys.argv.pop(1))
processes = [Process(target=run, args=()) for x in range(count)]
try:
for p in processes:
p.start()
except ... | python | def runm():
""" This is super minimal and pretty hacky, but it counts as a first pass.
"""
signal.signal(signal.SIGINT, signal_handler)
count = int(sys.argv.pop(1))
processes = [Process(target=run, args=()) for x in range(count)]
try:
for p in processes:
p.start()
except ... | [
"def",
"runm",
"(",
")",
":",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGINT",
",",
"signal_handler",
")",
"count",
"=",
"int",
"(",
"sys",
".",
"argv",
".",
"pop",
"(",
"1",
")",
")",
"processes",
"=",
"[",
"Process",
"(",
"target",
"=",
"... | This is super minimal and pretty hacky, but it counts as a first pass. | [
"This",
"is",
"super",
"minimal",
"and",
"pretty",
"hacky",
"but",
"it",
"counts",
"as",
"a",
"first",
"pass",
"."
] | fd548d97fd08e61c0e71296b08ffedb7d949e06a | https://github.com/PaulMcMillan/tasa/blob/fd548d97fd08e61c0e71296b08ffedb7d949e06a/tasa/cli.py#L79-L93 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.identify | def identify(self, request):
"""Establish what identity this user claims to have from request.
:param request: Request to extract identity information from.
:type request: :class:`morepath.Request`.
:returns: :class:`morepath.Identity` instance or
:attr:`morepath.NO_IDENTITY` ... | python | def identify(self, request):
"""Establish what identity this user claims to have from request.
:param request: Request to extract identity information from.
:type request: :class:`morepath.Request`.
:returns: :class:`morepath.Identity` instance or
:attr:`morepath.NO_IDENTITY` ... | [
"def",
"identify",
"(",
"self",
",",
"request",
")",
":",
"token",
"=",
"self",
".",
"get_jwt",
"(",
"request",
")",
"if",
"token",
"is",
"None",
":",
"return",
"NO_IDENTITY",
"try",
":",
"claims_set",
"=",
"self",
".",
"decode_jwt",
"(",
"token",
")",... | Establish what identity this user claims to have from request.
:param request: Request to extract identity information from.
:type request: :class:`morepath.Request`.
:returns: :class:`morepath.Identity` instance or
:attr:`morepath.NO_IDENTITY` if identity cannot
be establis... | [
"Establish",
"what",
"identity",
"this",
"user",
"claims",
"to",
"have",
"from",
"request",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L150-L173 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.remember | def remember(self, response, request, identity):
"""Remember identity on response.
Implements ``morepath.App.remember_identity``, which is called
from user login code.
Create a JWT token and return it as the Authorization field of the
response header.
:param response: ... | python | def remember(self, response, request, identity):
"""Remember identity on response.
Implements ``morepath.App.remember_identity``, which is called
from user login code.
Create a JWT token and return it as the Authorization field of the
response header.
:param response: ... | [
"def",
"remember",
"(",
"self",
",",
"response",
",",
"request",
",",
"identity",
")",
":",
"claims",
"=",
"identity",
".",
"as_dict",
"(",
")",
"userid",
"=",
"claims",
".",
"pop",
"(",
"'userid'",
")",
"claims_set",
"=",
"self",
".",
"create_claims_set... | Remember identity on response.
Implements ``morepath.App.remember_identity``, which is called
from user login code.
Create a JWT token and return it as the Authorization field of the
response header.
:param response: response object on which to store identity.
:type re... | [
"Remember",
"identity",
"on",
"response",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L175-L196 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.decode_jwt | def decode_jwt(self, token, verify_expiration=True):
"""Decode a JWTAuth token into its claims set.
This method decodes the given JWT to provide the claims set. The JWT
can fail if the token has expired (with appropriate leeway) or if the
token won't validate due to the secret (key) be... | python | def decode_jwt(self, token, verify_expiration=True):
"""Decode a JWTAuth token into its claims set.
This method decodes the given JWT to provide the claims set. The JWT
can fail if the token has expired (with appropriate leeway) or if the
token won't validate due to the secret (key) be... | [
"def",
"decode_jwt",
"(",
"self",
",",
"token",
",",
"verify_expiration",
"=",
"True",
")",
":",
"options",
"=",
"{",
"'verify_exp'",
":",
"verify_expiration",
",",
"}",
"return",
"jwt",
".",
"decode",
"(",
"token",
",",
"self",
".",
"public_key",
",",
"... | Decode a JWTAuth token into its claims set.
This method decodes the given JWT to provide the claims set. The JWT
can fail if the token has expired (with appropriate leeway) or if the
token won't validate due to the secret (key) being wrong.
If private_key/public key is set then the pu... | [
"Decode",
"a",
"JWTAuth",
"token",
"into",
"its",
"claims",
"set",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L214-L239 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.create_claims_set | def create_claims_set(self, request, userid, extra_claims=None):
"""Create the claims set based on the userid of the claimed identity,
the settings and the extra_claims dictionary.
The userid will be stored in settings.jwtauth.userid_claim
(default: "sub").
If settings.jwtauth.e... | python | def create_claims_set(self, request, userid, extra_claims=None):
"""Create the claims set based on the userid of the claimed identity,
the settings and the extra_claims dictionary.
The userid will be stored in settings.jwtauth.userid_claim
(default: "sub").
If settings.jwtauth.e... | [
"def",
"create_claims_set",
"(",
"self",
",",
"request",
",",
"userid",
",",
"extra_claims",
"=",
"None",
")",
":",
"claims_set",
"=",
"{",
"self",
".",
"userid_claim",
":",
"userid",
"}",
"now",
"=",
"timegm",
"(",
"datetime",
".",
"utcnow",
"(",
")",
... | Create the claims set based on the userid of the claimed identity,
the settings and the extra_claims dictionary.
The userid will be stored in settings.jwtauth.userid_claim
(default: "sub").
If settings.jwtauth.expiration_delta is set it will be added
to the current time and stor... | [
"Create",
"the",
"claims",
"set",
"based",
"on",
"the",
"userid",
"of",
"the",
"claimed",
"identity",
"the",
"settings",
"and",
"the",
"extra_claims",
"dictionary",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L241-L280 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.encode_jwt | def encode_jwt(self, claims_set):
"""Encode a JWT token based on the claims_set and the settings.
If available, registry.settings.jwtauth.private_key is used as key.
In this case the algorithm must be an RS* or EC* algorithm.
If registry.settings.jwtauth.private_key is not set,
... | python | def encode_jwt(self, claims_set):
"""Encode a JWT token based on the claims_set and the settings.
If available, registry.settings.jwtauth.private_key is used as key.
In this case the algorithm must be an RS* or EC* algorithm.
If registry.settings.jwtauth.private_key is not set,
... | [
"def",
"encode_jwt",
"(",
"self",
",",
"claims_set",
")",
":",
"token",
"=",
"jwt",
".",
"encode",
"(",
"claims_set",
",",
"self",
".",
"private_key",
",",
"self",
".",
"algorithm",
")",
"if",
"PY3",
":",
"token",
"=",
"token",
".",
"decode",
"(",
"e... | Encode a JWT token based on the claims_set and the settings.
If available, registry.settings.jwtauth.private_key is used as key.
In this case the algorithm must be an RS* or EC* algorithm.
If registry.settings.jwtauth.private_key is not set,
registry.settings.jwtauth.master_secret is us... | [
"Encode",
"a",
"JWT",
"token",
"based",
"on",
"the",
"claims_set",
"and",
"the",
"settings",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L282-L299 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.get_extra_claims | def get_extra_claims(self, claims_set):
"""Get claims holding extra identity info from the claims set.
Returns a dictionary of extra claims or None if there are none.
:param claims_set: set of claims, which was included in the received
token.
"""
reserved_claims = (
... | python | def get_extra_claims(self, claims_set):
"""Get claims holding extra identity info from the claims set.
Returns a dictionary of extra claims or None if there are none.
:param claims_set: set of claims, which was included in the received
token.
"""
reserved_claims = (
... | [
"def",
"get_extra_claims",
"(",
"self",
",",
"claims_set",
")",
":",
"reserved_claims",
"=",
"(",
"self",
".",
"userid_claim",
",",
"\"iss\"",
",",
"\"aud\"",
",",
"\"exp\"",
",",
"\"nbf\"",
",",
"\"iat\"",
",",
"\"jti\"",
",",
"\"refresh_until\"",
",",
"\"n... | Get claims holding extra identity info from the claims set.
Returns a dictionary of extra claims or None if there are none.
:param claims_set: set of claims, which was included in the received
token. | [
"Get",
"claims",
"holding",
"extra",
"identity",
"info",
"from",
"the",
"claims",
"set",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L314-L333 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.get_jwt | def get_jwt(self, request):
"""Extract the JWT token from the authorisation header of the request.
Returns the JWT token or None, if the token cannot be extracted.
:param request: request object.
:type request: :class:`morepath.Request`
"""
try:
authorizatio... | python | def get_jwt(self, request):
"""Extract the JWT token from the authorisation header of the request.
Returns the JWT token or None, if the token cannot be extracted.
:param request: request object.
:type request: :class:`morepath.Request`
"""
try:
authorizatio... | [
"def",
"get_jwt",
"(",
"self",
",",
"request",
")",
":",
"try",
":",
"authorization",
"=",
"request",
".",
"authorization",
"except",
"ValueError",
":",
"return",
"None",
"if",
"authorization",
"is",
"None",
":",
"return",
"None",
"authtype",
",",
"token",
... | Extract the JWT token from the authorisation header of the request.
Returns the JWT token or None, if the token cannot be extracted.
:param request: request object.
:type request: :class:`morepath.Request` | [
"Extract",
"the",
"JWT",
"token",
"from",
"the",
"authorisation",
"header",
"of",
"the",
"request",
"."
] | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L335-L352 | train |
morepath/more.jwtauth | more/jwtauth/main.py | JWTIdentityPolicy.verify_refresh | def verify_refresh(self, request):
"""
Verify if the request to refresh the token is valid.
If valid it returns the userid which can be used to create
an updated identity with ``remember_identity``.
Otherwise it raises an exception based on InvalidTokenError.
:param requ... | python | def verify_refresh(self, request):
"""
Verify if the request to refresh the token is valid.
If valid it returns the userid which can be used to create
an updated identity with ``remember_identity``.
Otherwise it raises an exception based on InvalidTokenError.
:param requ... | [
"def",
"verify_refresh",
"(",
"self",
",",
"request",
")",
":",
"if",
"not",
"self",
".",
"allow_refresh",
":",
"raise",
"InvalidTokenError",
"(",
"'Token refresh is disabled'",
")",
"token",
"=",
"self",
".",
"get_jwt",
"(",
"request",
")",
"if",
"token",
"... | Verify if the request to refresh the token is valid.
If valid it returns the userid which can be used to create
an updated identity with ``remember_identity``.
Otherwise it raises an exception based on InvalidTokenError.
:param request: current request object
:type request: :cla... | [
"Verify",
"if",
"the",
"request",
"to",
"refresh",
"the",
"token",
"is",
"valid",
".",
"If",
"valid",
"it",
"returns",
"the",
"userid",
"which",
"can",
"be",
"used",
"to",
"create",
"an",
"updated",
"identity",
"with",
"remember_identity",
".",
"Otherwise",
... | 1c3c5731612069a092e44cf612641c05edf1f083 | https://github.com/morepath/more.jwtauth/blob/1c3c5731612069a092e44cf612641c05edf1f083/more/jwtauth/main.py#L354-L404 | train |
guaix-ucm/numina | numina/array/robustfit.py | fit_theil_sen | def fit_theil_sen(x, y):
"""Compute a robust linear fit using the Theil-Sen method.
See http://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator for details.
This function "pairs up sample points by the rank of their x-coordinates
(the point with the smallest coordinate being paired with the first poin... | python | def fit_theil_sen(x, y):
"""Compute a robust linear fit using the Theil-Sen method.
See http://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator for details.
This function "pairs up sample points by the rank of their x-coordinates
(the point with the smallest coordinate being paired with the first poin... | [
"def",
"fit_theil_sen",
"(",
"x",
",",
"y",
")",
":",
"xx",
"=",
"numpy",
".",
"asarray",
"(",
"x",
")",
"y1",
"=",
"numpy",
".",
"asarray",
"(",
"y",
")",
"n",
"=",
"len",
"(",
"xx",
")",
"if",
"n",
"<",
"5",
":",
"raise",
"ValueError",
"(",... | Compute a robust linear fit using the Theil-Sen method.
See http://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator for details.
This function "pairs up sample points by the rank of their x-coordinates
(the point with the smallest coordinate being paired with the first point
above the median coordinat... | [
"Compute",
"a",
"robust",
"linear",
"fit",
"using",
"the",
"Theil",
"-",
"Sen",
"method",
"."
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/robustfit.py#L15-L80 | train |
guaix-ucm/numina | numina/user/cli.py | process_unknown_arguments | def process_unknown_arguments(unknowns):
"""Process arguments unknown to the parser"""
result = argparse.Namespace()
result.extra_control = {}
# It would be interesting to use argparse internal
# machinery for this
for unknown in unknowns:
# Check prefixes
prefix = '--parameter-... | python | def process_unknown_arguments(unknowns):
"""Process arguments unknown to the parser"""
result = argparse.Namespace()
result.extra_control = {}
# It would be interesting to use argparse internal
# machinery for this
for unknown in unknowns:
# Check prefixes
prefix = '--parameter-... | [
"def",
"process_unknown_arguments",
"(",
"unknowns",
")",
":",
"result",
"=",
"argparse",
".",
"Namespace",
"(",
")",
"result",
".",
"extra_control",
"=",
"{",
"}",
"for",
"unknown",
"in",
"unknowns",
":",
"prefix",
"=",
"'--parameter-'",
"if",
"unknown",
".... | Process arguments unknown to the parser | [
"Process",
"arguments",
"unknown",
"to",
"the",
"parser"
] | 6c829495df8937f77c2de9383c1038ffb3e713e3 | https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/user/cli.py#L152-L170 | train |
rfk/playitagainsam | playitagainsam/util.py | get_fd | def get_fd(file_or_fd, default=None):
"""Helper function for getting a file descriptor."""
fd = file_or_fd
if fd is None:
fd = default
if hasattr(fd, "fileno"):
fd = fd.fileno()
return fd | python | def get_fd(file_or_fd, default=None):
"""Helper function for getting a file descriptor."""
fd = file_or_fd
if fd is None:
fd = default
if hasattr(fd, "fileno"):
fd = fd.fileno()
return fd | [
"def",
"get_fd",
"(",
"file_or_fd",
",",
"default",
"=",
"None",
")",
":",
"fd",
"=",
"file_or_fd",
"if",
"fd",
"is",
"None",
":",
"fd",
"=",
"default",
"if",
"hasattr",
"(",
"fd",
",",
"\"fileno\"",
")",
":",
"fd",
"=",
"fd",
".",
"fileno",
"(",
... | Helper function for getting a file descriptor. | [
"Helper",
"function",
"for",
"getting",
"a",
"file",
"descriptor",
"."
] | 897cc8e8ca920a4afb8597b4a345361065a3f108 | https://github.com/rfk/playitagainsam/blob/897cc8e8ca920a4afb8597b4a345361065a3f108/playitagainsam/util.py#L65-L72 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.