repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
vnmabus/dcor | dcor/_dcor.py | _u_distance_correlation_sqr_naive | def _u_distance_correlation_sqr_naive(x, y, exponent=1):
"""Bias-corrected distance correlation estimator between two matrices."""
return _distance_sqr_stats_naive_generic(
x, y,
matrix_centered=_u_distance_matrix,
product=u_product,
exponent=exponent).correlation_xy | python | def _u_distance_correlation_sqr_naive(x, y, exponent=1):
"""Bias-corrected distance correlation estimator between two matrices."""
return _distance_sqr_stats_naive_generic(
x, y,
matrix_centered=_u_distance_matrix,
product=u_product,
exponent=exponent).correlation_xy | [
"def",
"_u_distance_correlation_sqr_naive",
"(",
"x",
",",
"y",
",",
"exponent",
"=",
"1",
")",
":",
"return",
"_distance_sqr_stats_naive_generic",
"(",
"x",
",",
"y",
",",
"matrix_centered",
"=",
"_u_distance_matrix",
",",
"product",
"=",
"u_product",
",",
"exp... | Bias-corrected distance correlation estimator between two matrices. | [
"Bias",
"-",
"corrected",
"distance",
"correlation",
"estimator",
"between",
"two",
"matrices",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L95-L101 | train |
vnmabus/dcor | dcor/_dcor.py | _can_use_fast_algorithm | def _can_use_fast_algorithm(x, y, exponent=1):
"""
Check if the fast algorithm for distance stats can be used.
The fast algorithm has complexity :math:`O(NlogN)`, better than the
complexity of the naive algorithm (:math:`O(N^2)`).
The algorithm can only be used for random variables (not vectors) w... | python | def _can_use_fast_algorithm(x, y, exponent=1):
"""
Check if the fast algorithm for distance stats can be used.
The fast algorithm has complexity :math:`O(NlogN)`, better than the
complexity of the naive algorithm (:math:`O(N^2)`).
The algorithm can only be used for random variables (not vectors) w... | [
"def",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"exponent",
"=",
"1",
")",
":",
"return",
"(",
"_is_random_variable",
"(",
"x",
")",
"and",
"_is_random_variable",
"(",
"y",
")",
"and",
"x",
".",
"shape",
"[",
"0",
"]",
">",
"3",
"and",
"y"... | Check if the fast algorithm for distance stats can be used.
The fast algorithm has complexity :math:`O(NlogN)`, better than the
complexity of the naive algorithm (:math:`O(N^2)`).
The algorithm can only be used for random variables (not vectors) where
the number of instances is greater than 3. Also, t... | [
"Check",
"if",
"the",
"fast",
"algorithm",
"for",
"distance",
"stats",
"can",
"be",
"used",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L115-L127 | train |
vnmabus/dcor | dcor/_dcor.py | _dyad_update | def _dyad_update(y, c): # pylint:disable=too-many-locals
# This function has many locals so it can be compared
# with the original algorithm.
"""
Inner function of the fast distance covariance.
This function is compiled because otherwise it would become
a bottleneck.
"""
n = y.shape[0... | python | def _dyad_update(y, c): # pylint:disable=too-many-locals
# This function has many locals so it can be compared
# with the original algorithm.
"""
Inner function of the fast distance covariance.
This function is compiled because otherwise it would become
a bottleneck.
"""
n = y.shape[0... | [
"def",
"_dyad_update",
"(",
"y",
",",
"c",
")",
":",
"# pylint:disable=too-many-locals",
"# This function has many locals so it can be compared",
"# with the original algorithm.",
"n",
"=",
"y",
".",
"shape",
"[",
"0",
"]",
"gamma",
"=",
"np",
".",
"zeros",
"(",
"n"... | Inner function of the fast distance covariance.
This function is compiled because otherwise it would become
a bottleneck. | [
"Inner",
"function",
"of",
"the",
"fast",
"distance",
"covariance",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L131-L178 | train |
vnmabus/dcor | dcor/_dcor.py | _distance_covariance_sqr_fast_generic | def _distance_covariance_sqr_fast_generic(
x, y, unbiased=False): # pylint:disable=too-many-locals
# This function has many locals so it can be compared
# with the original algorithm.
"""Fast algorithm for the squared distance covariance."""
x = np.asarray(x)
y = np.asarray(y)
x = np.r... | python | def _distance_covariance_sqr_fast_generic(
x, y, unbiased=False): # pylint:disable=too-many-locals
# This function has many locals so it can be compared
# with the original algorithm.
"""Fast algorithm for the squared distance covariance."""
x = np.asarray(x)
y = np.asarray(y)
x = np.r... | [
"def",
"_distance_covariance_sqr_fast_generic",
"(",
"x",
",",
"y",
",",
"unbiased",
"=",
"False",
")",
":",
"# pylint:disable=too-many-locals",
"# This function has many locals so it can be compared",
"# with the original algorithm.",
"x",
"=",
"np",
".",
"asarray",
"(",
"... | Fast algorithm for the squared distance covariance. | [
"Fast",
"algorithm",
"for",
"the",
"squared",
"distance",
"covariance",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L229-L303 | train |
vnmabus/dcor | dcor/_dcor.py | _distance_stats_sqr_fast_generic | def _distance_stats_sqr_fast_generic(x, y, dcov_function):
"""Compute the distance stats using the fast algorithm."""
covariance_xy_sqr = dcov_function(x, y)
variance_x_sqr = dcov_function(x, x)
variance_y_sqr = dcov_function(y, y)
denominator_sqr_signed = variance_x_sqr * variance_y_sqr
denomin... | python | def _distance_stats_sqr_fast_generic(x, y, dcov_function):
"""Compute the distance stats using the fast algorithm."""
covariance_xy_sqr = dcov_function(x, y)
variance_x_sqr = dcov_function(x, x)
variance_y_sqr = dcov_function(y, y)
denominator_sqr_signed = variance_x_sqr * variance_y_sqr
denomin... | [
"def",
"_distance_stats_sqr_fast_generic",
"(",
"x",
",",
"y",
",",
"dcov_function",
")",
":",
"covariance_xy_sqr",
"=",
"dcov_function",
"(",
"x",
",",
"y",
")",
"variance_x_sqr",
"=",
"dcov_function",
"(",
"x",
",",
"x",
")",
"variance_y_sqr",
"=",
"dcov_fun... | Compute the distance stats using the fast algorithm. | [
"Compute",
"the",
"distance",
"stats",
"using",
"the",
"fast",
"algorithm",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L316-L335 | train |
vnmabus/dcor | dcor/_dcor.py | distance_covariance_sqr | def distance_covariance_sqr(x, y, **kwargs):
"""
distance_covariance_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with t... | python | def distance_covariance_sqr(x, y, **kwargs):
"""
distance_covariance_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with t... | [
"def",
"distance_covariance_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_distance_covariance_sqr_fast",
"(",
"x",
",",
"y",
")",
"else",
... | distance_covariance_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the individual random
variables while the rows are... | [
"distance_covariance_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L360-L417 | train |
vnmabus/dcor | dcor/_dcor.py | u_distance_covariance_sqr | def u_distance_covariance_sqr(x, y, **kwargs):
"""
u_distance_covariance_sqr(x, y, *, exponent=1)
Computes the unbiased estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the... | python | def u_distance_covariance_sqr(x, y, **kwargs):
"""
u_distance_covariance_sqr(x, y, *, exponent=1)
Computes the unbiased estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the... | [
"def",
"u_distance_covariance_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_u_distance_covariance_sqr_fast",
"(",
"x",
",",
"y",
")",
"else... | u_distance_covariance_sqr(x, y, *, exponent=1)
Computes the unbiased estimator for the squared distance covariance
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the individual random
variables while the rows are ind... | [
"u_distance_covariance_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L420-L477 | train |
vnmabus/dcor | dcor/_dcor.py | distance_stats_sqr | def distance_stats_sqr(x, y, **kwargs):
"""
distance_stats_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
... | python | def distance_stats_sqr(x, y, **kwargs):
"""
distance_stats_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
... | [
"def",
"distance_stats_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_distance_stats_sqr_fast",
"(",
"x",
",",
"y",
")",
"else",
":",
"r... | distance_stats_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
x: array_like
First random vector. The co... | [
"distance_stats_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L537-L609 | train |
vnmabus/dcor | dcor/_dcor.py | u_distance_stats_sqr | def u_distance_stats_sqr(x, y, **kwargs):
"""
u_distance_stats_sqr(x, y, *, exponent=1)
Computes the unbiased estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
... | python | def u_distance_stats_sqr(x, y, **kwargs):
"""
u_distance_stats_sqr(x, y, *, exponent=1)
Computes the unbiased estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
... | [
"def",
"u_distance_stats_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_u_distance_stats_sqr_fast",
"(",
"x",
",",
"y",
")",
"else",
":",
... | u_distance_stats_sqr(x, y, *, exponent=1)
Computes the unbiased estimators for the squared distance covariance
and squared distance correlation between two random vectors, and the
individual squared distance variances.
Parameters
----------
x: array_like
First random vector. The column... | [
"u_distance_stats_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L612-L687 | train |
vnmabus/dcor | dcor/_dcor.py | distance_stats | def distance_stats(x, y, **kwargs):
"""
distance_stats(x, y, *, exponent=1)
Computes the usual (biased) estimators for the distance covariance
and distance correlation between two random vectors, and the
individual distance variances.
Parameters
----------
x: array_like
First r... | python | def distance_stats(x, y, **kwargs):
"""
distance_stats(x, y, *, exponent=1)
Computes the usual (biased) estimators for the distance covariance
and distance correlation between two random vectors, and the
individual distance variances.
Parameters
----------
x: array_like
First r... | [
"def",
"distance_stats",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"Stats",
"(",
"*",
"[",
"_sqrt",
"(",
"s",
")",
"for",
"s",
"in",
"distance_stats_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
"]",
")"
] | distance_stats(x, y, *, exponent=1)
Computes the usual (biased) estimators for the distance covariance
and distance correlation between two random vectors, and the
individual distance variances.
Parameters
----------
x: array_like
First random vector. The columns correspond with the in... | [
"distance_stats",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L690-L755 | train |
vnmabus/dcor | dcor/_dcor.py | distance_correlation_sqr | def distance_correlation_sqr(x, y, **kwargs):
"""
distance_correlation_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond wit... | python | def distance_correlation_sqr(x, y, **kwargs):
"""
distance_correlation_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond wit... | [
"def",
"distance_correlation_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_distance_correlation_sqr_fast",
"(",
"x",
",",
"y",
")",
"else",... | distance_correlation_sqr(x, y, *, exponent=1)
Computes the usual (biased) estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the individual random
variables while the rows a... | [
"distance_correlation_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L758-L815 | train |
vnmabus/dcor | dcor/_dcor.py | u_distance_correlation_sqr | def u_distance_correlation_sqr(x, y, **kwargs):
"""
u_distance_correlation_sqr(x, y, *, exponent=1)
Computes the bias-corrected estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond... | python | def u_distance_correlation_sqr(x, y, **kwargs):
"""
u_distance_correlation_sqr(x, y, *, exponent=1)
Computes the bias-corrected estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond... | [
"def",
"u_distance_correlation_sqr",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"_can_use_fast_algorithm",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_u_distance_correlation_sqr_fast",
"(",
"x",
",",
"y",
")",
"el... | u_distance_correlation_sqr(x, y, *, exponent=1)
Computes the bias-corrected estimator for the squared distance correlation
between two random vectors.
Parameters
----------
x: array_like
First random vector. The columns correspond with the individual random
variables while the rows... | [
"u_distance_correlation_sqr",
"(",
"x",
"y",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L818-L877 | train |
vnmabus/dcor | dcor/_dcor.py | distance_correlation_af_inv_sqr | def distance_correlation_af_inv_sqr(x, y):
"""
Square of the affinely invariant distance correlation.
Computes the estimator for the square of the affinely invariant distance
correlation between two random vectors.
.. warning:: The return value of this function is undefined when the
... | python | def distance_correlation_af_inv_sqr(x, y):
"""
Square of the affinely invariant distance correlation.
Computes the estimator for the square of the affinely invariant distance
correlation between two random vectors.
.. warning:: The return value of this function is undefined when the
... | [
"def",
"distance_correlation_af_inv_sqr",
"(",
"x",
",",
"y",
")",
":",
"x",
"=",
"_af_inv_scaled",
"(",
"x",
")",
"y",
"=",
"_af_inv_scaled",
"(",
"y",
")",
"correlation",
"=",
"distance_correlation_sqr",
"(",
"x",
",",
"y",
")",
"return",
"0",
"if",
"n... | Square of the affinely invariant distance correlation.
Computes the estimator for the square of the affinely invariant distance
correlation between two random vectors.
.. warning:: The return value of this function is undefined when the
covariance matrix of :math:`x` or :math:`y` is singu... | [
"Square",
"of",
"the",
"affinely",
"invariant",
"distance",
"correlation",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_dcor.py#L937-L988 | train |
vnmabus/dcor | dcor/_pairwise.py | pairwise | def pairwise(function, x, y=None, **kwargs):
"""
pairwise(function, x, y=None, *, pool=None, is_symmetric=None, **kwargs)
Computes a dependency measure between each pair of elements.
Parameters
----------
function: Dependency measure function.
x: iterable of array_like
First list o... | python | def pairwise(function, x, y=None, **kwargs):
"""
pairwise(function, x, y=None, *, pool=None, is_symmetric=None, **kwargs)
Computes a dependency measure between each pair of elements.
Parameters
----------
function: Dependency measure function.
x: iterable of array_like
First list o... | [
"def",
"pairwise",
"(",
"function",
",",
"x",
",",
"y",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_pairwise_imp",
"(",
"function",
",",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")"
] | pairwise(function, x, y=None, *, pool=None, is_symmetric=None, **kwargs)
Computes a dependency measure between each pair of elements.
Parameters
----------
function: Dependency measure function.
x: iterable of array_like
First list of random vectors. The columns of each vector correspond
... | [
"pairwise",
"(",
"function",
"x",
"y",
"=",
"None",
"*",
"pool",
"=",
"None",
"is_symmetric",
"=",
"None",
"**",
"kwargs",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_pairwise.py#L10-L94 | train |
vnmabus/dcor | dcor/_pairwise.py | _pairwise_imp | def _pairwise_imp(function, x, y=None, pool=None, is_symmetric=None, **kwargs):
"""
Real implementation of :func:`pairwise`.
This function is used to make several parameters keyword-only in
Python 2.
"""
map_function = pool.map if pool else map
if is_symmetric is None:
is_symmetri... | python | def _pairwise_imp(function, x, y=None, pool=None, is_symmetric=None, **kwargs):
"""
Real implementation of :func:`pairwise`.
This function is used to make several parameters keyword-only in
Python 2.
"""
map_function = pool.map if pool else map
if is_symmetric is None:
is_symmetri... | [
"def",
"_pairwise_imp",
"(",
"function",
",",
"x",
",",
"y",
"=",
"None",
",",
"pool",
"=",
"None",
",",
"is_symmetric",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"map_function",
"=",
"pool",
".",
"map",
"if",
"pool",
"else",
"map",
"if",
"is... | Real implementation of :func:`pairwise`.
This function is used to make several parameters keyword-only in
Python 2. | [
"Real",
"implementation",
"of",
":",
"func",
":",
"pairwise",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_pairwise.py#L97-L134 | train |
vnmabus/dcor | dcor/_utils.py | _jit | def _jit(function):
"""
Compile a function using a jit compiler.
The function is always compiled to check errors, but is only used outside
tests, so that code coverage analysis can be performed in jitted functions.
The tests set sys._called_from_test in conftest.py.
"""
import sys
co... | python | def _jit(function):
"""
Compile a function using a jit compiler.
The function is always compiled to check errors, but is only used outside
tests, so that code coverage analysis can be performed in jitted functions.
The tests set sys._called_from_test in conftest.py.
"""
import sys
co... | [
"def",
"_jit",
"(",
"function",
")",
":",
"import",
"sys",
"compiled",
"=",
"numba",
".",
"jit",
"(",
"function",
")",
"if",
"hasattr",
"(",
"sys",
",",
"'_called_from_test'",
")",
":",
"return",
"function",
"else",
":",
"# pragma: no cover",
"return",
"co... | Compile a function using a jit compiler.
The function is always compiled to check errors, but is only used outside
tests, so that code coverage analysis can be performed in jitted functions.
The tests set sys._called_from_test in conftest.py. | [
"Compile",
"a",
"function",
"using",
"a",
"jit",
"compiler",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_utils.py#L10-L27 | train |
vnmabus/dcor | dcor/_utils.py | _sqrt | def _sqrt(x):
"""
Return square root of an ndarray.
This sqrt function for ndarrays tries to use the exponentiation operator
if the objects stored do not supply a sqrt method.
"""
x = np.clip(x, a_min=0, a_max=None)
try:
return np.sqrt(x)
except AttributeError:
exponen... | python | def _sqrt(x):
"""
Return square root of an ndarray.
This sqrt function for ndarrays tries to use the exponentiation operator
if the objects stored do not supply a sqrt method.
"""
x = np.clip(x, a_min=0, a_max=None)
try:
return np.sqrt(x)
except AttributeError:
exponen... | [
"def",
"_sqrt",
"(",
"x",
")",
":",
"x",
"=",
"np",
".",
"clip",
"(",
"x",
",",
"a_min",
"=",
"0",
",",
"a_max",
"=",
"None",
")",
"try",
":",
"return",
"np",
".",
"sqrt",
"(",
"x",
")",
"except",
"AttributeError",
":",
"exponent",
"=",
"0.5",
... | Return square root of an ndarray.
This sqrt function for ndarrays tries to use the exponentiation operator
if the objects stored do not supply a sqrt method. | [
"Return",
"square",
"root",
"of",
"an",
"ndarray",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_utils.py#L30-L50 | train |
vnmabus/dcor | dcor/_utils.py | _transform_to_2d | def _transform_to_2d(t):
"""Convert vectors to column matrices, to always have a 2d shape."""
t = np.asarray(t)
dim = len(t.shape)
assert dim <= 2
if dim < 2:
t = np.atleast_2d(t).T
return t | python | def _transform_to_2d(t):
"""Convert vectors to column matrices, to always have a 2d shape."""
t = np.asarray(t)
dim = len(t.shape)
assert dim <= 2
if dim < 2:
t = np.atleast_2d(t).T
return t | [
"def",
"_transform_to_2d",
"(",
"t",
")",
":",
"t",
"=",
"np",
".",
"asarray",
"(",
"t",
")",
"dim",
"=",
"len",
"(",
"t",
".",
"shape",
")",
"assert",
"dim",
"<=",
"2",
"if",
"dim",
"<",
"2",
":",
"t",
"=",
"np",
".",
"atleast_2d",
"(",
"t",... | Convert vectors to column matrices, to always have a 2d shape. | [
"Convert",
"vectors",
"to",
"column",
"matrices",
"to",
"always",
"have",
"a",
"2d",
"shape",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_utils.py#L53-L63 | train |
vnmabus/dcor | dcor/_utils.py | _can_be_double | def _can_be_double(x):
"""
Return if the array can be safely converted to double.
That happens when the dtype is a float with the same size of
a double or narrower, or when is an integer that can be safely
converted to double (if the roundtrip conversion works).
"""
return ((np.issubdtype(... | python | def _can_be_double(x):
"""
Return if the array can be safely converted to double.
That happens when the dtype is a float with the same size of
a double or narrower, or when is an integer that can be safely
converted to double (if the roundtrip conversion works).
"""
return ((np.issubdtype(... | [
"def",
"_can_be_double",
"(",
"x",
")",
":",
"return",
"(",
"(",
"np",
".",
"issubdtype",
"(",
"x",
".",
"dtype",
",",
"np",
".",
"floating",
")",
"and",
"x",
".",
"dtype",
".",
"itemsize",
"<=",
"np",
".",
"dtype",
"(",
"float",
")",
".",
"items... | Return if the array can be safely converted to double.
That happens when the dtype is a float with the same size of
a double or narrower, or when is an integer that can be safely
converted to double (if the roundtrip conversion works). | [
"Return",
"if",
"the",
"array",
"can",
"be",
"safely",
"converted",
"to",
"double",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/_utils.py#L66-L78 | train |
vnmabus/dcor | dcor/distances.py | _cdist_naive | def _cdist_naive(x, y, exponent=1):
"""Pairwise distance, custom implementation."""
squared_norms = ((x[_np.newaxis, :, :] - y[:, _np.newaxis, :]) ** 2).sum(2)
exponent = exponent / 2
try:
exponent = squared_norms.take(0).from_float(exponent)
except AttributeError:
pass
return ... | python | def _cdist_naive(x, y, exponent=1):
"""Pairwise distance, custom implementation."""
squared_norms = ((x[_np.newaxis, :, :] - y[:, _np.newaxis, :]) ** 2).sum(2)
exponent = exponent / 2
try:
exponent = squared_norms.take(0).from_float(exponent)
except AttributeError:
pass
return ... | [
"def",
"_cdist_naive",
"(",
"x",
",",
"y",
",",
"exponent",
"=",
"1",
")",
":",
"squared_norms",
"=",
"(",
"(",
"x",
"[",
"_np",
".",
"newaxis",
",",
":",
",",
":",
"]",
"-",
"y",
"[",
":",
",",
"_np",
".",
"newaxis",
",",
":",
"]",
")",
"*... | Pairwise distance, custom implementation. | [
"Pairwise",
"distance",
"custom",
"implementation",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L18-L28 | train |
vnmabus/dcor | dcor/distances.py | _pdist_scipy | def _pdist_scipy(x, exponent=1):
"""Pairwise distance between points in a set."""
metric = 'euclidean'
if exponent != 1:
metric = 'sqeuclidean'
distances = _spatial.distance.pdist(x, metric=metric)
distances = _spatial.distance.squareform(distances)
if exponent != 1:
distances... | python | def _pdist_scipy(x, exponent=1):
"""Pairwise distance between points in a set."""
metric = 'euclidean'
if exponent != 1:
metric = 'sqeuclidean'
distances = _spatial.distance.pdist(x, metric=metric)
distances = _spatial.distance.squareform(distances)
if exponent != 1:
distances... | [
"def",
"_pdist_scipy",
"(",
"x",
",",
"exponent",
"=",
"1",
")",
":",
"metric",
"=",
"'euclidean'",
"if",
"exponent",
"!=",
"1",
":",
"metric",
"=",
"'sqeuclidean'",
"distances",
"=",
"_spatial",
".",
"distance",
".",
"pdist",
"(",
"x",
",",
"metric",
... | Pairwise distance between points in a set. | [
"Pairwise",
"distance",
"between",
"points",
"in",
"a",
"set",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L31-L44 | train |
vnmabus/dcor | dcor/distances.py | _cdist_scipy | def _cdist_scipy(x, y, exponent=1):
"""Pairwise distance between the points in two sets."""
metric = 'euclidean'
if exponent != 1:
metric = 'sqeuclidean'
distances = _spatial.distance.cdist(x, y, metric=metric)
if exponent != 1:
distances **= exponent / 2
return distances | python | def _cdist_scipy(x, y, exponent=1):
"""Pairwise distance between the points in two sets."""
metric = 'euclidean'
if exponent != 1:
metric = 'sqeuclidean'
distances = _spatial.distance.cdist(x, y, metric=metric)
if exponent != 1:
distances **= exponent / 2
return distances | [
"def",
"_cdist_scipy",
"(",
"x",
",",
"y",
",",
"exponent",
"=",
"1",
")",
":",
"metric",
"=",
"'euclidean'",
"if",
"exponent",
"!=",
"1",
":",
"metric",
"=",
"'sqeuclidean'",
"distances",
"=",
"_spatial",
".",
"distance",
".",
"cdist",
"(",
"x",
",",
... | Pairwise distance between the points in two sets. | [
"Pairwise",
"distance",
"between",
"the",
"points",
"in",
"two",
"sets",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L47-L59 | train |
vnmabus/dcor | dcor/distances.py | _pdist | def _pdist(x, exponent=1):
"""
Pairwise distance between points in a set.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double.
"""
if _can_be_double(x):
return _pdist_scipy(x, exponent)
... | python | def _pdist(x, exponent=1):
"""
Pairwise distance between points in a set.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double.
"""
if _can_be_double(x):
return _pdist_scipy(x, exponent)
... | [
"def",
"_pdist",
"(",
"x",
",",
"exponent",
"=",
"1",
")",
":",
"if",
"_can_be_double",
"(",
"x",
")",
":",
"return",
"_pdist_scipy",
"(",
"x",
",",
"exponent",
")",
"else",
":",
"return",
"_cdist_naive",
"(",
"x",
",",
"x",
",",
"exponent",
")"
] | Pairwise distance between points in a set.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double. | [
"Pairwise",
"distance",
"between",
"points",
"in",
"a",
"set",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L62-L74 | train |
vnmabus/dcor | dcor/distances.py | _cdist | def _cdist(x, y, exponent=1):
"""
Pairwise distance between points in two sets.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double.
"""
if _can_be_double(x) and _can_be_double(y):
return _c... | python | def _cdist(x, y, exponent=1):
"""
Pairwise distance between points in two sets.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double.
"""
if _can_be_double(x) and _can_be_double(y):
return _c... | [
"def",
"_cdist",
"(",
"x",
",",
"y",
",",
"exponent",
"=",
"1",
")",
":",
"if",
"_can_be_double",
"(",
"x",
")",
"and",
"_can_be_double",
"(",
"y",
")",
":",
"return",
"_cdist_scipy",
"(",
"x",
",",
"y",
",",
"exponent",
")",
"else",
":",
"return",... | Pairwise distance between points in two sets.
As Scipy converts every value to double, this wrapper uses
a less efficient implementation if the original dtype
can not be converted to double. | [
"Pairwise",
"distance",
"between",
"points",
"in",
"two",
"sets",
"."
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L77-L89 | train |
vnmabus/dcor | dcor/distances.py | pairwise_distances | def pairwise_distances(x, y=None, **kwargs):
r"""
pairwise_distances(x, y=None, *, exponent=1)
Pairwise distance between points.
Return the pairwise distance between points in two sets, or
in the same set if only one set is passed.
Parameters
----------
x: array_like
An :math:... | python | def pairwise_distances(x, y=None, **kwargs):
r"""
pairwise_distances(x, y=None, *, exponent=1)
Pairwise distance between points.
Return the pairwise distance between points in two sets, or
in the same set if only one set is passed.
Parameters
----------
x: array_like
An :math:... | [
"def",
"pairwise_distances",
"(",
"x",
",",
"y",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"x",
"=",
"_transform_to_2d",
"(",
"x",
")",
"if",
"y",
"is",
"None",
"or",
"y",
"is",
"x",
":",
"return",
"_pdist",
"(",
"x",
",",
"*",
"*",
"kwar... | r"""
pairwise_distances(x, y=None, *, exponent=1)
Pairwise distance between points.
Return the pairwise distance between points in two sets, or
in the same set if only one set is passed.
Parameters
----------
x: array_like
An :math:`n \times m` array of :math:`n` observations in
... | [
"r",
"pairwise_distances",
"(",
"x",
"y",
"=",
"None",
"*",
"exponent",
"=",
"1",
")"
] | b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d | https://github.com/vnmabus/dcor/blob/b0ff1273c0a52efdabdfdadefc7ff2a49def7e8d/dcor/distances.py#L92-L149 | train |
kumar303/mohawk | mohawk/receiver.py | Receiver.respond | def respond(self,
content=EmptyValue,
content_type=EmptyValue,
always_hash_content=True,
ext=None):
"""
Respond to the request.
This generates the :attr:`mohawk.Receiver.response_header`
attribute.
:param content=E... | python | def respond(self,
content=EmptyValue,
content_type=EmptyValue,
always_hash_content=True,
ext=None):
"""
Respond to the request.
This generates the :attr:`mohawk.Receiver.response_header`
attribute.
:param content=E... | [
"def",
"respond",
"(",
"self",
",",
"content",
"=",
"EmptyValue",
",",
"content_type",
"=",
"EmptyValue",
",",
"always_hash_content",
"=",
"True",
",",
"ext",
"=",
"None",
")",
":",
"log",
".",
"debug",
"(",
"'generating response header'",
")",
"resource",
"... | Respond to the request.
This generates the :attr:`mohawk.Receiver.response_header`
attribute.
:param content=EmptyValue: Byte string of response body that will be sent.
:type content=EmptyValue: str
:param content_type=EmptyValue: content-type header value for response.
... | [
"Respond",
"to",
"the",
"request",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/receiver.py#L123-L171 | train |
kumar303/mohawk | mohawk/util.py | calculate_payload_hash | def calculate_payload_hash(payload, algorithm, content_type):
"""Calculates a hash for a given payload."""
p_hash = hashlib.new(algorithm)
parts = []
parts.append('hawk.' + str(HAWK_VER) + '.payload\n')
parts.append(parse_content_type(content_type) + '\n')
parts.append(payload or '')
parts.... | python | def calculate_payload_hash(payload, algorithm, content_type):
"""Calculates a hash for a given payload."""
p_hash = hashlib.new(algorithm)
parts = []
parts.append('hawk.' + str(HAWK_VER) + '.payload\n')
parts.append(parse_content_type(content_type) + '\n')
parts.append(payload or '')
parts.... | [
"def",
"calculate_payload_hash",
"(",
"payload",
",",
"algorithm",
",",
"content_type",
")",
":",
"p_hash",
"=",
"hashlib",
".",
"new",
"(",
"algorithm",
")",
"parts",
"=",
"[",
"]",
"parts",
".",
"append",
"(",
"'hawk.'",
"+",
"str",
"(",
"HAWK_VER",
")... | Calculates a hash for a given payload. | [
"Calculates",
"a",
"hash",
"for",
"a",
"given",
"payload",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/util.py#L49-L69 | train |
kumar303/mohawk | mohawk/util.py | calculate_mac | def calculate_mac(mac_type, resource, content_hash):
"""Calculates a message authorization code (MAC)."""
normalized = normalize_string(mac_type, resource, content_hash)
log.debug(u'normalized resource for mac calc: {norm}'
.format(norm=normalized))
digestmod = getattr(hashlib, resource.cr... | python | def calculate_mac(mac_type, resource, content_hash):
"""Calculates a message authorization code (MAC)."""
normalized = normalize_string(mac_type, resource, content_hash)
log.debug(u'normalized resource for mac calc: {norm}'
.format(norm=normalized))
digestmod = getattr(hashlib, resource.cr... | [
"def",
"calculate_mac",
"(",
"mac_type",
",",
"resource",
",",
"content_hash",
")",
":",
"normalized",
"=",
"normalize_string",
"(",
"mac_type",
",",
"resource",
",",
"content_hash",
")",
"log",
".",
"debug",
"(",
"u'normalized resource for mac calc: {norm}'",
".",
... | Calculates a message authorization code (MAC). | [
"Calculates",
"a",
"message",
"authorization",
"code",
"(",
"MAC",
")",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/util.py#L72-L88 | train |
kumar303/mohawk | mohawk/util.py | calculate_ts_mac | def calculate_ts_mac(ts, credentials):
"""Calculates a message authorization code (MAC) for a timestamp."""
normalized = ('hawk.{hawk_ver}.ts\n{ts}\n'
.format(hawk_ver=HAWK_VER, ts=ts))
log.debug(u'normalized resource for ts mac calc: {norm}'
.format(norm=normalized))
dig... | python | def calculate_ts_mac(ts, credentials):
"""Calculates a message authorization code (MAC) for a timestamp."""
normalized = ('hawk.{hawk_ver}.ts\n{ts}\n'
.format(hawk_ver=HAWK_VER, ts=ts))
log.debug(u'normalized resource for ts mac calc: {norm}'
.format(norm=normalized))
dig... | [
"def",
"calculate_ts_mac",
"(",
"ts",
",",
"credentials",
")",
":",
"normalized",
"=",
"(",
"'hawk.{hawk_ver}.ts\\n{ts}\\n'",
".",
"format",
"(",
"hawk_ver",
"=",
"HAWK_VER",
",",
"ts",
"=",
"ts",
")",
")",
"log",
".",
"debug",
"(",
"u'normalized resource for ... | Calculates a message authorization code (MAC) for a timestamp. | [
"Calculates",
"a",
"message",
"authorization",
"code",
"(",
"MAC",
")",
"for",
"a",
"timestamp",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/util.py#L91-L106 | train |
kumar303/mohawk | mohawk/util.py | normalize_string | def normalize_string(mac_type, resource, content_hash):
"""Serializes mac_type and resource into a HAWK string."""
normalized = [
'hawk.' + str(HAWK_VER) + '.' + mac_type,
normalize_header_attr(resource.timestamp),
normalize_header_attr(resource.nonce),
normalize_header_attr(res... | python | def normalize_string(mac_type, resource, content_hash):
"""Serializes mac_type and resource into a HAWK string."""
normalized = [
'hawk.' + str(HAWK_VER) + '.' + mac_type,
normalize_header_attr(resource.timestamp),
normalize_header_attr(resource.nonce),
normalize_header_attr(res... | [
"def",
"normalize_string",
"(",
"mac_type",
",",
"resource",
",",
"content_hash",
")",
":",
"normalized",
"=",
"[",
"'hawk.'",
"+",
"str",
"(",
"HAWK_VER",
")",
"+",
"'.'",
"+",
"mac_type",
",",
"normalize_header_attr",
"(",
"resource",
".",
"timestamp",
")"... | Serializes mac_type and resource into a HAWK string. | [
"Serializes",
"mac_type",
"and",
"resource",
"into",
"a",
"HAWK",
"string",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/util.py#L109-L136 | train |
kumar303/mohawk | mohawk/util.py | parse_authorization_header | def parse_authorization_header(auth_header):
"""
Example Authorization header:
'Hawk id="dh37fgj492je", ts="1367076201", nonce="NPHgnG", ext="and
welcome!", mac="CeWHy4d9kbLGhDlkyw2Nh3PJ7SDOdZDa267KH4ZaNMY="'
"""
if len(auth_header) > MAX_LENGTH:
raise BadHeaderValue('Header exc... | python | def parse_authorization_header(auth_header):
"""
Example Authorization header:
'Hawk id="dh37fgj492je", ts="1367076201", nonce="NPHgnG", ext="and
welcome!", mac="CeWHy4d9kbLGhDlkyw2Nh3PJ7SDOdZDa267KH4ZaNMY="'
"""
if len(auth_header) > MAX_LENGTH:
raise BadHeaderValue('Header exc... | [
"def",
"parse_authorization_header",
"(",
"auth_header",
")",
":",
"if",
"len",
"(",
"auth_header",
")",
">",
"MAX_LENGTH",
":",
"raise",
"BadHeaderValue",
"(",
"'Header exceeds maximum length of {max_length}'",
".",
"format",
"(",
"max_length",
"=",
"MAX_LENGTH",
")"... | Example Authorization header:
'Hawk id="dh37fgj492je", ts="1367076201", nonce="NPHgnG", ext="and
welcome!", mac="CeWHy4d9kbLGhDlkyw2Nh3PJ7SDOdZDa267KH4ZaNMY="' | [
"Example",
"Authorization",
"header",
":"
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/util.py#L147-L192 | train |
kumar303/mohawk | mohawk/bewit.py | get_bewit | def get_bewit(resource):
"""
Returns a bewit identifier for the resource as a string.
:param resource:
Resource to generate a bewit for
:type resource: `mohawk.base.Resource`
"""
if resource.method != 'GET':
raise ValueError('bewits can only be generated for GET requests')
i... | python | def get_bewit(resource):
"""
Returns a bewit identifier for the resource as a string.
:param resource:
Resource to generate a bewit for
:type resource: `mohawk.base.Resource`
"""
if resource.method != 'GET':
raise ValueError('bewits can only be generated for GET requests')
i... | [
"def",
"get_bewit",
"(",
"resource",
")",
":",
"if",
"resource",
".",
"method",
"!=",
"'GET'",
":",
"raise",
"ValueError",
"(",
"'bewits can only be generated for GET requests'",
")",
"if",
"resource",
".",
"nonce",
"!=",
"''",
":",
"raise",
"ValueError",
"(",
... | Returns a bewit identifier for the resource as a string.
:param resource:
Resource to generate a bewit for
:type resource: `mohawk.base.Resource` | [
"Returns",
"a",
"bewit",
"identifier",
"for",
"the",
"resource",
"as",
"a",
"string",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/bewit.py#L21-L61 | train |
kumar303/mohawk | mohawk/bewit.py | parse_bewit | def parse_bewit(bewit):
"""
Returns a `bewittuple` representing the parts of an encoded bewit string.
This has the following named attributes:
(id, expiration, mac, ext)
:param bewit:
A base64 encoded bewit string
:type bewit: str
"""
decoded_bewit = b64decode(bewit).decode(... | python | def parse_bewit(bewit):
"""
Returns a `bewittuple` representing the parts of an encoded bewit string.
This has the following named attributes:
(id, expiration, mac, ext)
:param bewit:
A base64 encoded bewit string
:type bewit: str
"""
decoded_bewit = b64decode(bewit).decode(... | [
"def",
"parse_bewit",
"(",
"bewit",
")",
":",
"decoded_bewit",
"=",
"b64decode",
"(",
"bewit",
")",
".",
"decode",
"(",
"'ascii'",
")",
"bewit_parts",
"=",
"decoded_bewit",
".",
"split",
"(",
"\"\\\\\"",
")",
"if",
"len",
"(",
"bewit_parts",
")",
"!=",
"... | Returns a `bewittuple` representing the parts of an encoded bewit string.
This has the following named attributes:
(id, expiration, mac, ext)
:param bewit:
A base64 encoded bewit string
:type bewit: str | [
"Returns",
"a",
"bewittuple",
"representing",
"the",
"parts",
"of",
"an",
"encoded",
"bewit",
"string",
".",
"This",
"has",
"the",
"following",
"named",
"attributes",
":",
"(",
"id",
"expiration",
"mac",
"ext",
")"
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/bewit.py#L67-L81 | train |
kumar303/mohawk | mohawk/bewit.py | strip_bewit | def strip_bewit(url):
"""
Strips the bewit parameter out of a url.
Returns (encoded_bewit, stripped_url)
Raises InvalidBewit if no bewit found.
:param url:
The url containing a bewit parameter
:type url: str
"""
m = re.search('[?&]bewit=([^&]+)', url)
if not m:
rai... | python | def strip_bewit(url):
"""
Strips the bewit parameter out of a url.
Returns (encoded_bewit, stripped_url)
Raises InvalidBewit if no bewit found.
:param url:
The url containing a bewit parameter
:type url: str
"""
m = re.search('[?&]bewit=([^&]+)', url)
if not m:
rai... | [
"def",
"strip_bewit",
"(",
"url",
")",
":",
"m",
"=",
"re",
".",
"search",
"(",
"'[?&]bewit=([^&]+)'",
",",
"url",
")",
"if",
"not",
"m",
":",
"raise",
"InvalidBewit",
"(",
"'no bewit data found'",
")",
"bewit",
"=",
"m",
".",
"group",
"(",
"1",
")",
... | Strips the bewit parameter out of a url.
Returns (encoded_bewit, stripped_url)
Raises InvalidBewit if no bewit found.
:param url:
The url containing a bewit parameter
:type url: str | [
"Strips",
"the",
"bewit",
"parameter",
"out",
"of",
"a",
"url",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/bewit.py#L84-L101 | train |
kumar303/mohawk | mohawk/bewit.py | check_bewit | def check_bewit(url, credential_lookup, now=None):
"""
Validates the given bewit.
Returns True if the resource has a valid bewit parameter attached,
or raises a subclass of HawkFail otherwise.
:param credential_lookup:
Callable to look up the credentials dict by sender ID.
The cred... | python | def check_bewit(url, credential_lookup, now=None):
"""
Validates the given bewit.
Returns True if the resource has a valid bewit parameter attached,
or raises a subclass of HawkFail otherwise.
:param credential_lookup:
Callable to look up the credentials dict by sender ID.
The cred... | [
"def",
"check_bewit",
"(",
"url",
",",
"credential_lookup",
",",
"now",
"=",
"None",
")",
":",
"raw_bewit",
",",
"stripped_url",
"=",
"strip_bewit",
"(",
"url",
")",
"bewit",
"=",
"parse_bewit",
"(",
"raw_bewit",
")",
"try",
":",
"credentials",
"=",
"crede... | Validates the given bewit.
Returns True if the resource has a valid bewit parameter attached,
or raises a subclass of HawkFail otherwise.
:param credential_lookup:
Callable to look up the credentials dict by sender ID.
The credentials dict must have the keys:
``id``, ``key``, and `... | [
"Validates",
"the",
"given",
"bewit",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/bewit.py#L104-L159 | train |
kumar303/mohawk | mohawk/sender.py | Sender.accept_response | def accept_response(self,
response_header,
content=EmptyValue,
content_type=EmptyValue,
accept_untrusted_content=False,
localtime_offset_in_seconds=0,
timestamp_skew_in_seconds... | python | def accept_response(self,
response_header,
content=EmptyValue,
content_type=EmptyValue,
accept_untrusted_content=False,
localtime_offset_in_seconds=0,
timestamp_skew_in_seconds... | [
"def",
"accept_response",
"(",
"self",
",",
"response_header",
",",
"content",
"=",
"EmptyValue",
",",
"content_type",
"=",
"EmptyValue",
",",
"accept_untrusted_content",
"=",
"False",
",",
"localtime_offset_in_seconds",
"=",
"0",
",",
"timestamp_skew_in_seconds",
"="... | Accept a response to this request.
:param response_header:
A `Hawk`_ ``Server-Authorization`` header
such as one created by :class:`mohawk.Receiver`.
:type response_header: str
:param content=EmptyValue: Byte string of the response body received.
:type content=E... | [
"Accept",
"a",
"response",
"to",
"this",
"request",
"."
] | 037be67ccf50ae704705e67add44e02737a65d21 | https://github.com/kumar303/mohawk/blob/037be67ccf50ae704705e67add44e02737a65d21/mohawk/sender.py#L106-L175 | train |
kajic/django-model-changes | django_model_changes/changes.py | ChangesMixin.current_state | def current_state(self):
"""
Returns a ``field -> value`` dict of the current state of the instance.
"""
field_names = set()
[field_names.add(f.name) for f in self._meta.local_fields]
[field_names.add(f.attname) for f in self._meta.local_fields]
return dict([(fiel... | python | def current_state(self):
"""
Returns a ``field -> value`` dict of the current state of the instance.
"""
field_names = set()
[field_names.add(f.name) for f in self._meta.local_fields]
[field_names.add(f.attname) for f in self._meta.local_fields]
return dict([(fiel... | [
"def",
"current_state",
"(",
"self",
")",
":",
"field_names",
"=",
"set",
"(",
")",
"[",
"field_names",
".",
"add",
"(",
"f",
".",
"name",
")",
"for",
"f",
"in",
"self",
".",
"_meta",
".",
"local_fields",
"]",
"[",
"field_names",
".",
"add",
"(",
"... | Returns a ``field -> value`` dict of the current state of the instance. | [
"Returns",
"a",
"field",
"-",
">",
"value",
"dict",
"of",
"the",
"current",
"state",
"of",
"the",
"instance",
"."
] | 92124ebdf29cba930eb1ced00135823b961041d3 | https://github.com/kajic/django-model-changes/blob/92124ebdf29cba930eb1ced00135823b961041d3/django_model_changes/changes.py#L98-L105 | train |
kajic/django-model-changes | django_model_changes/changes.py | ChangesMixin.was_persisted | def was_persisted(self):
"""
Returns true if the instance was persisted (saved) in its old
state.
Examples::
>>> user = User()
>>> user.save()
>>> user.was_persisted()
False
>>> user = User.objects.get(pk=1)
>>> u... | python | def was_persisted(self):
"""
Returns true if the instance was persisted (saved) in its old
state.
Examples::
>>> user = User()
>>> user.save()
>>> user.was_persisted()
False
>>> user = User.objects.get(pk=1)
>>> u... | [
"def",
"was_persisted",
"(",
"self",
")",
":",
"pk_name",
"=",
"self",
".",
"_meta",
".",
"pk",
".",
"name",
"return",
"bool",
"(",
"self",
".",
"old_state",
"(",
")",
"[",
"pk_name",
"]",
")"
] | Returns true if the instance was persisted (saved) in its old
state.
Examples::
>>> user = User()
>>> user.save()
>>> user.was_persisted()
False
>>> user = User.objects.get(pk=1)
>>> user.delete()
>>> user.was_persist... | [
"Returns",
"true",
"if",
"the",
"instance",
"was",
"persisted",
"(",
"saved",
")",
"in",
"its",
"old",
"state",
"."
] | 92124ebdf29cba930eb1ced00135823b961041d3 | https://github.com/kajic/django-model-changes/blob/92124ebdf29cba930eb1ced00135823b961041d3/django_model_changes/changes.py#L149-L167 | train |
nilp0inter/cpe | cpe/cpe.py | CPE._trim | def _trim(cls, s):
"""
Remove trailing colons from the URI back to the first non-colon.
:param string s: input URI string
:returns: URI string with trailing colons removed
:rtype: string
TEST: trailing colons necessary
>>> s = '1:2::::'
>>> CPE._trim(s)... | python | def _trim(cls, s):
"""
Remove trailing colons from the URI back to the first non-colon.
:param string s: input URI string
:returns: URI string with trailing colons removed
:rtype: string
TEST: trailing colons necessary
>>> s = '1:2::::'
>>> CPE._trim(s)... | [
"def",
"_trim",
"(",
"cls",
",",
"s",
")",
":",
"reverse",
"=",
"s",
"[",
":",
":",
"-",
"1",
"]",
"idx",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"reverse",
")",
")",
":",
"if",
"reverse",
"[",
"i",
"]",
"==",
"\":... | Remove trailing colons from the URI back to the first non-colon.
:param string s: input URI string
:returns: URI string with trailing colons removed
:rtype: string
TEST: trailing colons necessary
>>> s = '1:2::::'
>>> CPE._trim(s)
'1:2'
TEST: trailing ... | [
"Remove",
"trailing",
"colons",
"from",
"the",
"URI",
"back",
"to",
"the",
"first",
"non",
"-",
"colon",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L115-L146 | train |
nilp0inter/cpe | cpe/cpe.py | CPE._create_cpe_parts | def _create_cpe_parts(self, system, components):
"""
Create the structure to store the input type of system associated
with components of CPE Name (hardware, operating system and software).
:param string system: type of system associated with CPE Name
:param dict components: CPE... | python | def _create_cpe_parts(self, system, components):
"""
Create the structure to store the input type of system associated
with components of CPE Name (hardware, operating system and software).
:param string system: type of system associated with CPE Name
:param dict components: CPE... | [
"def",
"_create_cpe_parts",
"(",
"self",
",",
"system",
",",
"components",
")",
":",
"if",
"system",
"not",
"in",
"CPEComponent",
".",
"SYSTEM_VALUES",
":",
"errmsg",
"=",
"\"Key '{0}' is not exist\"",
".",
"format",
"(",
"system",
")",
"raise",
"ValueError",
... | Create the structure to store the input type of system associated
with components of CPE Name (hardware, operating system and software).
:param string system: type of system associated with CPE Name
:param dict components: CPE Name components to store
:returns: None
:exception: ... | [
"Create",
"the",
"structure",
"to",
"store",
"the",
"input",
"type",
"of",
"system",
"associated",
"with",
"components",
"of",
"CPE",
"Name",
"(",
"hardware",
"operating",
"system",
"and",
"software",
")",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L389-L408 | train |
nilp0inter/cpe | cpe/cpe.py | CPE._get_attribute_components | def _get_attribute_components(self, att):
"""
Returns the component list of input attribute.
:param string att: Attribute name to get
:returns: List of Component objects of the attribute in CPE Name
:rtype: list
:exception: ValueError - invalid attribute name
"""... | python | def _get_attribute_components(self, att):
"""
Returns the component list of input attribute.
:param string att: Attribute name to get
:returns: List of Component objects of the attribute in CPE Name
:rtype: list
:exception: ValueError - invalid attribute name
"""... | [
"def",
"_get_attribute_components",
"(",
"self",
",",
"att",
")",
":",
"lc",
"=",
"[",
"]",
"if",
"not",
"CPEComponent",
".",
"is_valid_attribute",
"(",
"att",
")",
":",
"errmsg",
"=",
"\"Invalid attribute name '{0}' is not exist\"",
".",
"format",
"(",
"att",
... | Returns the component list of input attribute.
:param string att: Attribute name to get
:returns: List of Component objects of the attribute in CPE Name
:rtype: list
:exception: ValueError - invalid attribute name | [
"Returns",
"the",
"component",
"list",
"of",
"input",
"attribute",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L410-L431 | train |
nilp0inter/cpe | cpe/cpe.py | CPE._pack_edition | def _pack_edition(self):
"""
Pack the values of the five arguments into the simple edition
component. If all the values are blank, just return a blank.
:returns: "edition", "sw_edition", "target_sw", "target_hw" and "other"
attributes packed in a only value
:rtype: s... | python | def _pack_edition(self):
"""
Pack the values of the five arguments into the simple edition
component. If all the values are blank, just return a blank.
:returns: "edition", "sw_edition", "target_sw", "target_hw" and "other"
attributes packed in a only value
:rtype: s... | [
"def",
"_pack_edition",
"(",
"self",
")",
":",
"COMP_KEYS",
"=",
"(",
"CPEComponent",
".",
"ATT_EDITION",
",",
"CPEComponent",
".",
"ATT_SW_EDITION",
",",
"CPEComponent",
".",
"ATT_TARGET_SW",
",",
"CPEComponent",
".",
"ATT_TARGET_HW",
",",
"CPEComponent",
".",
... | Pack the values of the five arguments into the simple edition
component. If all the values are blank, just return a blank.
:returns: "edition", "sw_edition", "target_sw", "target_hw" and "other"
attributes packed in a only value
:rtype: string
:exception: TypeError - incompa... | [
"Pack",
"the",
"values",
"of",
"the",
"five",
"arguments",
"into",
"the",
"simple",
"edition",
"component",
".",
"If",
"all",
"the",
"values",
"are",
"blank",
"just",
"return",
"a",
"blank",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L433-L505 | train |
nilp0inter/cpe | cpe/cpe.py | CPE.as_uri_2_3 | def as_uri_2_3(self):
"""
Returns the CPE Name as URI string of version 2.3.
:returns: CPE Name as URI string of version 2.3
:rtype: string
:exception: TypeError - incompatible version
"""
uri = []
uri.append("cpe:/")
ordered_comp_parts = {
... | python | def as_uri_2_3(self):
"""
Returns the CPE Name as URI string of version 2.3.
:returns: CPE Name as URI string of version 2.3
:rtype: string
:exception: TypeError - incompatible version
"""
uri = []
uri.append("cpe:/")
ordered_comp_parts = {
... | [
"def",
"as_uri_2_3",
"(",
"self",
")",
":",
"uri",
"=",
"[",
"]",
"uri",
".",
"append",
"(",
"\"cpe:/\"",
")",
"ordered_comp_parts",
"=",
"{",
"0",
":",
"CPEComponent",
".",
"ATT_PART",
",",
"1",
":",
"CPEComponent",
".",
"ATT_VENDOR",
",",
"2",
":",
... | Returns the CPE Name as URI string of version 2.3.
:returns: CPE Name as URI string of version 2.3
:rtype: string
:exception: TypeError - incompatible version | [
"Returns",
"the",
"CPE",
"Name",
"as",
"URI",
"string",
"of",
"version",
"2",
".",
"3",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L517-L602 | train |
nilp0inter/cpe | cpe/cpe.py | CPE.as_wfn | def as_wfn(self):
"""
Returns the CPE Name as Well-Formed Name string of version 2.3.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version
"""
from .cpe2_3_wfn import CPE2_3_WFN
wfn = []
wfn.append(CPE2_3_W... | python | def as_wfn(self):
"""
Returns the CPE Name as Well-Formed Name string of version 2.3.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version
"""
from .cpe2_3_wfn import CPE2_3_WFN
wfn = []
wfn.append(CPE2_3_W... | [
"def",
"as_wfn",
"(",
"self",
")",
":",
"from",
".",
"cpe2_3_wfn",
"import",
"CPE2_3_WFN",
"wfn",
"=",
"[",
"]",
"wfn",
".",
"append",
"(",
"CPE2_3_WFN",
".",
"CPE_PREFIX",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"CPEComponent",
".... | Returns the CPE Name as Well-Formed Name string of version 2.3.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version | [
"Returns",
"the",
"CPE",
"Name",
"as",
"Well",
"-",
"Formed",
"Name",
"string",
"of",
"version",
"2",
".",
"3",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L604-L666 | train |
nilp0inter/cpe | cpe/cpe.py | CPE.as_fs | def as_fs(self):
"""
Returns the CPE Name as formatted string of version 2.3.
:returns: CPE Name as formatted string
:rtype: string
:exception: TypeError - incompatible version
"""
fs = []
fs.append("cpe:2.3:")
for i in range(0, len(CPEComponent... | python | def as_fs(self):
"""
Returns the CPE Name as formatted string of version 2.3.
:returns: CPE Name as formatted string
:rtype: string
:exception: TypeError - incompatible version
"""
fs = []
fs.append("cpe:2.3:")
for i in range(0, len(CPEComponent... | [
"def",
"as_fs",
"(",
"self",
")",
":",
"fs",
"=",
"[",
"]",
"fs",
".",
"append",
"(",
"\"cpe:2.3:\"",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"CPEComponent",
".",
"ordered_comp_parts",
")",
")",
":",
"ck",
"=",
"CPEComponent",
".... | Returns the CPE Name as formatted string of version 2.3.
:returns: CPE Name as formatted string
:rtype: string
:exception: TypeError - incompatible version | [
"Returns",
"the",
"CPE",
"Name",
"as",
"formatted",
"string",
"of",
"version",
"2",
".",
"3",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe.py#L668-L714 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple._is_alphanum | def _is_alphanum(cls, c):
"""
Returns True if c is an uppercase letter, a lowercase letter,
a digit or an underscore, otherwise False.
:param string c: Character to check
:returns: True if char is alphanumeric or an underscore,
False otherwise
:rtype: boolean... | python | def _is_alphanum(cls, c):
"""
Returns True if c is an uppercase letter, a lowercase letter,
a digit or an underscore, otherwise False.
:param string c: Character to check
:returns: True if char is alphanumeric or an underscore,
False otherwise
:rtype: boolean... | [
"def",
"_is_alphanum",
"(",
"cls",
",",
"c",
")",
":",
"alphanum_rxc",
"=",
"re",
".",
"compile",
"(",
"CPEComponentSimple",
".",
"_ALPHANUM_PATTERN",
")",
"return",
"(",
"alphanum_rxc",
".",
"match",
"(",
"c",
")",
"is",
"not",
"None",
")"
] | Returns True if c is an uppercase letter, a lowercase letter,
a digit or an underscore, otherwise False.
:param string c: Character to check
:returns: True if char is alphanumeric or an underscore,
False otherwise
:rtype: boolean
TEST: a wrong character
>>> ... | [
"Returns",
"True",
"if",
"c",
"is",
"an",
"uppercase",
"letter",
"a",
"lowercase",
"letter",
"a",
"digit",
"or",
"an",
"underscore",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L98-L115 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple._pct_encode_uri | def _pct_encode_uri(cls, c):
"""
Return the appropriate percent-encoding of character c (URI string).
Certain characters are returned without encoding.
:param string c: Character to check
:returns: Encoded character as URI
:rtype: string
TEST:
>>> c = '... | python | def _pct_encode_uri(cls, c):
"""
Return the appropriate percent-encoding of character c (URI string).
Certain characters are returned without encoding.
:param string c: Character to check
:returns: Encoded character as URI
:rtype: string
TEST:
>>> c = '... | [
"def",
"_pct_encode_uri",
"(",
"cls",
",",
"c",
")",
":",
"CPEComponentSimple",
".",
"spechar_to_pce",
"[",
"'-'",
"]",
"=",
"c",
"# bound without encoding",
"CPEComponentSimple",
".",
"spechar_to_pce",
"[",
"'.'",
"]",
"=",
"c",
"# bound without encoding",
"retur... | Return the appropriate percent-encoding of character c (URI string).
Certain characters are returned without encoding.
:param string c: Character to check
:returns: Encoded character as URI
:rtype: string
TEST:
>>> c = '.'
>>> CPEComponentSimple._pct_encode_uri... | [
"Return",
"the",
"appropriate",
"percent",
"-",
"encoding",
"of",
"character",
"c",
"(",
"URI",
"string",
")",
".",
"Certain",
"characters",
"are",
"returned",
"without",
"encoding",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L118-L143 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple._is_valid_language | def _is_valid_language(self):
"""
Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value.lower()
lang_rxc = re.comp... | python | def _is_valid_language(self):
"""
Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value.lower()
lang_rxc = re.comp... | [
"def",
"_is_valid_language",
"(",
"self",
")",
":",
"comp_str",
"=",
"self",
".",
"_encoded_value",
".",
"lower",
"(",
")",
"lang_rxc",
"=",
"re",
".",
"compile",
"(",
"CPEComponentSimple",
".",
"_LANGTAG_PATTERN",
")",
"return",
"lang_rxc",
".",
"match",
"(... | Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean | [
"Return",
"True",
"if",
"the",
"value",
"of",
"component",
"in",
"attribute",
"language",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L184-L195 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple._is_valid_part | def _is_valid_part(self):
"""
Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value.lower()
part_rxc = re... | python | def _is_valid_part(self):
"""
Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value.lower()
part_rxc = re... | [
"def",
"_is_valid_part",
"(",
"self",
")",
":",
"comp_str",
"=",
"self",
".",
"_encoded_value",
".",
"lower",
"(",
")",
"part_rxc",
"=",
"re",
".",
"compile",
"(",
"CPEComponentSimple",
".",
"_PART_PATTERN",
")",
"return",
"part_rxc",
".",
"match",
"(",
"c... | Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean | [
"Return",
"True",
"if",
"the",
"value",
"of",
"component",
"in",
"attribute",
"part",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L197-L208 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple._parse | def _parse(self, comp_att):
"""
Check if the value of component is correct in the attribute "comp_att".
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component
"""
errmsg = "Invali... | python | def _parse(self, comp_att):
"""
Check if the value of component is correct in the attribute "comp_att".
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component
"""
errmsg = "Invali... | [
"def",
"_parse",
"(",
"self",
",",
"comp_att",
")",
":",
"errmsg",
"=",
"\"Invalid attribute '{0}'\"",
".",
"format",
"(",
"comp_att",
")",
"if",
"not",
"CPEComponent",
".",
"is_valid_attribute",
"(",
"comp_att",
")",
":",
"raise",
"ValueError",
"(",
"errmsg",... | Check if the value of component is correct in the attribute "comp_att".
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component | [
"Check",
"if",
"the",
"value",
"of",
"component",
"is",
"correct",
"in",
"the",
"attribute",
"comp_att",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L223-L259 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple.as_fs | def as_fs(self):
"""
Returns the value of component encoded as formatted string.
Inspect each character in value of component.
Certain nonalpha characters pass thru without escaping
into the result, but most retain escaping.
:returns: Formatted string associated with co... | python | def as_fs(self):
"""
Returns the value of component encoded as formatted string.
Inspect each character in value of component.
Certain nonalpha characters pass thru without escaping
into the result, but most retain escaping.
:returns: Formatted string associated with co... | [
"def",
"as_fs",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"_standard_value",
"result",
"=",
"[",
"]",
"idx",
"=",
"0",
"while",
"(",
"idx",
"<",
"len",
"(",
"s",
")",
")",
":",
"c",
"=",
"s",
"[",
"idx",
"]",
"# get the idx'th character of s",
... | Returns the value of component encoded as formatted string.
Inspect each character in value of component.
Certain nonalpha characters pass thru without escaping
into the result, but most retain escaping.
:returns: Formatted string associated with component
:rtype: string | [
"Returns",
"the",
"value",
"of",
"component",
"encoded",
"as",
"formatted",
"string",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L261-L298 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple.as_uri_2_3 | def as_uri_2_3(self):
"""
Returns the value of component encoded as URI string.
Scans an input string s and applies the following transformations:
- Pass alphanumeric characters thru untouched
- Percent-encode quoted non-alphanumerics as needed
- Unquoted special charac... | python | def as_uri_2_3(self):
"""
Returns the value of component encoded as URI string.
Scans an input string s and applies the following transformations:
- Pass alphanumeric characters thru untouched
- Percent-encode quoted non-alphanumerics as needed
- Unquoted special charac... | [
"def",
"as_uri_2_3",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"_standard_value",
"result",
"=",
"[",
"]",
"idx",
"=",
"0",
"while",
"(",
"idx",
"<",
"len",
"(",
"s",
")",
")",
":",
"thischar",
"=",
"s",
"[",
"idx",
"]",
"# get the idx'th chara... | Returns the value of component encoded as URI string.
Scans an input string s and applies the following transformations:
- Pass alphanumeric characters thru untouched
- Percent-encode quoted non-alphanumerics as needed
- Unquoted special characters are mapped to their special forms.
... | [
"Returns",
"the",
"value",
"of",
"component",
"encoded",
"as",
"URI",
"string",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L300-L344 | train |
nilp0inter/cpe | cpe/comp/cpecomp_simple.py | CPEComponentSimple.set_value | def set_value(self, comp_str, comp_att):
"""
Set the value of component. By default, the component has a simple
value.
:param string comp_str: new value of component
:param string comp_att: attribute associated with value of component
:returns: None
:exception: V... | python | def set_value(self, comp_str, comp_att):
"""
Set the value of component. By default, the component has a simple
value.
:param string comp_str: new value of component
:param string comp_att: attribute associated with value of component
:returns: None
:exception: V... | [
"def",
"set_value",
"(",
"self",
",",
"comp_str",
",",
"comp_att",
")",
":",
"old_value",
"=",
"self",
".",
"_encoded_value",
"self",
".",
"_encoded_value",
"=",
"comp_str",
"# Check the value of component",
"try",
":",
"self",
".",
"_parse",
"(",
"comp_att",
... | Set the value of component. By default, the component has a simple
value.
:param string comp_str: new value of component
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component | [
"Set",
"the",
"value",
"of",
"component",
".",
"By",
"default",
"the",
"component",
"has",
"a",
"simple",
"value",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp_simple.py#L367-L390 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3_fs.py | CPEComponent2_3_FS._decode | def _decode(self):
"""
Convert the characters of string s to standard value (WFN value).
Inspect each character in value of component. Copy quoted characters,
with their escaping, into the result. Look for unquoted non
alphanumerics and if not "*" or "?", add escaping.
:... | python | def _decode(self):
"""
Convert the characters of string s to standard value (WFN value).
Inspect each character in value of component. Copy quoted characters,
with their escaping, into the result. Look for unquoted non
alphanumerics and if not "*" or "?", add escaping.
:... | [
"def",
"_decode",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"idx",
"=",
"0",
"s",
"=",
"self",
".",
"_encoded_value",
"embedded",
"=",
"False",
"errmsg",
"=",
"[",
"]",
"errmsg",
".",
"append",
"(",
"\"Invalid character '\"",
")",
"while",
"(",
... | Convert the characters of string s to standard value (WFN value).
Inspect each character in value of component. Copy quoted characters,
with their escaping, into the result. Look for unquoted non
alphanumerics and if not "*" or "?", add escaping.
:exception: ValueError - invalid charact... | [
"Convert",
"the",
"characters",
"of",
"string",
"s",
"to",
"standard",
"value",
"(",
"WFN",
"value",
")",
".",
"Inspect",
"each",
"character",
"in",
"value",
"of",
"component",
".",
"Copy",
"quoted",
"characters",
"with",
"their",
"escaping",
"into",
"the",
... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3_fs.py#L93-L165 | train |
nilp0inter/cpe | cpe/cpe1_1.py | CPE1_1._parse | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self.cpe_str.find(" ") != -1):
errmsg = "Bad-formed CPE Name: it must not have whitespaces... | python | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self.cpe_str.find(" ") != -1):
errmsg = "Bad-formed CPE Name: it must not have whitespaces... | [
"def",
"_parse",
"(",
"self",
")",
":",
"# CPE Name must not have whitespaces",
"if",
"(",
"self",
".",
"cpe_str",
".",
"find",
"(",
"\" \"",
")",
"!=",
"-",
"1",
")",
":",
"errmsg",
"=",
"\"Bad-formed CPE Name: it must not have whitespaces\"",
"raise",
"ValueErro... | Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name | [
"Checks",
"if",
"the",
"CPE",
"Name",
"is",
"valid",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe1_1.py#L173-L264 | train |
nilp0inter/cpe | cpe/cpe1_1.py | CPE1_1.get_attribute_values | def get_attribute_values(self, att_name):
"""
Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - in... | python | def get_attribute_values(self, att_name):
"""
Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - in... | [
"def",
"get_attribute_values",
"(",
"self",
",",
"att_name",
")",
":",
"lc",
"=",
"[",
"]",
"if",
"not",
"CPEComponent",
".",
"is_valid_attribute",
"(",
"att_name",
")",
":",
"errmsg",
"=",
"\"Invalid attribute name: {0}\"",
".",
"format",
"(",
"att_name",
")"... | Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - invalid attribute name | [
"Returns",
"the",
"values",
"of",
"attribute",
"att_name",
"of",
"CPE",
"Name",
".",
"By",
"default",
"a",
"only",
"element",
"in",
"each",
"part",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe1_1.py#L318-L348 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3_uri_edpacked.py | CPEComponent2_3_URI_edpacked.set_value | def set_value(self, comp_str):
"""
Set the value of component.
:param string comp_str: value of component
:returns: None
:exception: ValueError - incorrect value of component
"""
self._is_negated = False
self._encoded_value = comp_str
self._stand... | python | def set_value(self, comp_str):
"""
Set the value of component.
:param string comp_str: value of component
:returns: None
:exception: ValueError - incorrect value of component
"""
self._is_negated = False
self._encoded_value = comp_str
self._stand... | [
"def",
"set_value",
"(",
"self",
",",
"comp_str",
")",
":",
"self",
".",
"_is_negated",
"=",
"False",
"self",
".",
"_encoded_value",
"=",
"comp_str",
"self",
".",
"_standard_value",
"=",
"super",
"(",
"CPEComponent2_3_URI_edpacked",
",",
"self",
")",
".",
"_... | Set the value of component.
:param string comp_str: value of component
:returns: None
:exception: ValueError - incorrect value of component | [
"Set",
"the",
"value",
"of",
"component",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3_uri_edpacked.py#L91-L103 | train |
nilp0inter/cpe | cpe/comp/cpecomp1_1.py | CPEComponent1_1._decode | def _decode(self):
"""
Convert the encoded value of component to standard value (WFN value).
"""
s = self._encoded_value
elements = s.replace('~', '').split('!')
dec_elements = []
for elem in elements:
result = []
idx = 0
whil... | python | def _decode(self):
"""
Convert the encoded value of component to standard value (WFN value).
"""
s = self._encoded_value
elements = s.replace('~', '').split('!')
dec_elements = []
for elem in elements:
result = []
idx = 0
whil... | [
"def",
"_decode",
"(",
"self",
")",
":",
"s",
"=",
"self",
".",
"_encoded_value",
"elements",
"=",
"s",
".",
"replace",
"(",
"'~'",
",",
"''",
")",
".",
"split",
"(",
"'!'",
")",
"dec_elements",
"=",
"[",
"]",
"for",
"elem",
"in",
"elements",
":",
... | Convert the encoded value of component to standard value (WFN value). | [
"Convert",
"the",
"encoded",
"value",
"of",
"component",
"to",
"standard",
"value",
"(",
"WFN",
"value",
")",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp1_1.py#L156-L183 | train |
nilp0inter/cpe | cpe/comp/cpecomp1_1.py | CPEComponent1_1._is_valid_value | def _is_valid_value(self):
"""
Return True if the value of component in generic attribute is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value
value_pattern = []
valu... | python | def _is_valid_value(self):
"""
Return True if the value of component in generic attribute is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value
value_pattern = []
valu... | [
"def",
"_is_valid_value",
"(",
"self",
")",
":",
"comp_str",
"=",
"self",
".",
"_encoded_value",
"value_pattern",
"=",
"[",
"]",
"value_pattern",
".",
"append",
"(",
"\"^((\"",
")",
"value_pattern",
".",
"append",
"(",
"\"~[\"",
")",
"value_pattern",
".",
"a... | Return True if the value of component in generic attribute is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean | [
"Return",
"True",
"if",
"the",
"value",
"of",
"component",
"in",
"generic",
"attribute",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp1_1.py#L185-L210 | train |
nilp0inter/cpe | cpe/comp/cpecomp1_1.py | CPEComponent1_1.as_wfn | def as_wfn(self):
r"""
Returns the value of compoment encoded as Well-Formed Name (WFN)
string.
:returns: WFN string
:rtype: string
TEST:
>>> val = 'xp!vista'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VERSION)
>>> comp1.as_wfn()
... | python | def as_wfn(self):
r"""
Returns the value of compoment encoded as Well-Formed Name (WFN)
string.
:returns: WFN string
:rtype: string
TEST:
>>> val = 'xp!vista'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VERSION)
>>> comp1.as_wfn()
... | [
"def",
"as_wfn",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"for",
"s",
"in",
"self",
".",
"_standard_value",
":",
"result",
".",
"append",
"(",
"s",
")",
"result",
".",
"append",
"(",
"CPEComponent1_1",
".",
"_ESCAPE_SEPARATOR",
")",
"return",
"\... | r"""
Returns the value of compoment encoded as Well-Formed Name (WFN)
string.
:returns: WFN string
:rtype: string
TEST:
>>> val = 'xp!vista'
>>> comp1 = CPEComponent1_1(val, CPEComponentSimple.ATT_VERSION)
>>> comp1.as_wfn()
'xp\\!vista' | [
"r",
"Returns",
"the",
"value",
"of",
"compoment",
"encoded",
"as",
"Well",
"-",
"Formed",
"Name",
"(",
"WFN",
")",
"string",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp1_1.py#L309-L331 | train |
nilp0inter/cpe | cpe/comp/cpecomp1_1.py | CPEComponent1_1.set_value | def set_value(self, comp_str, comp_att):
"""
Set the value of component. By default, the component has a simple
value.
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component
TEST:... | python | def set_value(self, comp_str, comp_att):
"""
Set the value of component. By default, the component has a simple
value.
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component
TEST:... | [
"def",
"set_value",
"(",
"self",
",",
"comp_str",
",",
"comp_att",
")",
":",
"super",
"(",
"CPEComponent1_1",
",",
"self",
")",
".",
"set_value",
"(",
"comp_str",
",",
"comp_att",
")",
"self",
".",
"_is_negated",
"=",
"comp_str",
".",
"startswith",
"(",
... | Set the value of component. By default, the component has a simple
value.
:param string comp_att: attribute associated with value of component
:returns: None
:exception: ValueError - incorrect value of component
TEST:
>>> val = 'xp!vista'
>>> val2 = 'sp2'
... | [
"Set",
"the",
"value",
"of",
"component",
".",
"By",
"default",
"the",
"component",
"has",
"a",
"simple",
"value",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp1_1.py#L333-L354 | train |
nilp0inter/cpe | cpe/cpe2_3_uri.py | CPE2_3_URI._create_component | def _create_component(cls, att, value):
"""
Returns a component with value "value".
:param string att: Attribute name
:param string value: Attribute value
:returns: Component object created
:rtype: CPEComponent
:exception: ValueError - invalid value of attribute
... | python | def _create_component(cls, att, value):
"""
Returns a component with value "value".
:param string att: Attribute name
:param string value: Attribute value
:returns: Component object created
:rtype: CPEComponent
:exception: ValueError - invalid value of attribute
... | [
"def",
"_create_component",
"(",
"cls",
",",
"att",
",",
"value",
")",
":",
"if",
"value",
"==",
"CPEComponent2_3_URI",
".",
"VALUE_UNDEFINED",
":",
"comp",
"=",
"CPEComponentUndefined",
"(",
")",
"elif",
"(",
"value",
"==",
"CPEComponent2_3_URI",
".",
"VALUE_... | Returns a component with value "value".
:param string att: Attribute name
:param string value: Attribute value
:returns: Component object created
:rtype: CPEComponent
:exception: ValueError - invalid value of attribute | [
"Returns",
"a",
"component",
"with",
"value",
"value",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_uri.py#L104-L131 | train |
nilp0inter/cpe | cpe/cpe2_3_uri.py | CPE2_3_URI._unpack_edition | def _unpack_edition(cls, value):
"""
Unpack its elements and set the attributes in wfn accordingly.
Parse out the five elements:
~ edition ~ software edition ~ target sw ~ target hw ~ other
:param string value: Value of edition attribute
:returns: Dictionary with parts ... | python | def _unpack_edition(cls, value):
"""
Unpack its elements and set the attributes in wfn accordingly.
Parse out the five elements:
~ edition ~ software edition ~ target sw ~ target hw ~ other
:param string value: Value of edition attribute
:returns: Dictionary with parts ... | [
"def",
"_unpack_edition",
"(",
"cls",
",",
"value",
")",
":",
"components",
"=",
"value",
".",
"split",
"(",
"CPEComponent2_3_URI",
".",
"SEPARATOR_PACKED_EDITION",
")",
"d",
"=",
"dict",
"(",
")",
"ed",
"=",
"components",
"[",
"1",
"]",
"sw_ed",
"=",
"c... | Unpack its elements and set the attributes in wfn accordingly.
Parse out the five elements:
~ edition ~ software edition ~ target sw ~ target hw ~ other
:param string value: Value of edition attribute
:returns: Dictionary with parts of edition attribute
:exception: ValueError -... | [
"Unpack",
"its",
"elements",
"and",
"set",
"the",
"attributes",
"in",
"wfn",
"accordingly",
".",
"Parse",
"out",
"the",
"five",
"elements",
":"
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_uri.py#L134-L166 | train |
nilp0inter/cpe | cpe/cpe2_3_uri.py | CPE2_3_URI._parse | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | python | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | [
"def",
"_parse",
"(",
"self",
")",
":",
"# CPE Name must not have whitespaces",
"if",
"(",
"self",
".",
"_str",
".",
"find",
"(",
"\" \"",
")",
"!=",
"-",
"1",
")",
":",
"msg",
"=",
"\"Bad-formed CPE Name: it must not have whitespaces\"",
"raise",
"ValueError",
... | Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name | [
"Checks",
"if",
"the",
"CPE",
"Name",
"is",
"valid",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_uri.py#L254-L343 | train |
nilp0inter/cpe | cpe/cpe2_3_uri.py | CPE2_3_URI.as_wfn | def as_wfn(self):
"""
Returns the CPE Name as Well-Formed Name string of version 2.3.
If edition component is not packed, only shows the first seven
components, otherwise shows all.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatib... | python | def as_wfn(self):
"""
Returns the CPE Name as Well-Formed Name string of version 2.3.
If edition component is not packed, only shows the first seven
components, otherwise shows all.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatib... | [
"def",
"as_wfn",
"(",
"self",
")",
":",
"if",
"self",
".",
"_str",
".",
"find",
"(",
"CPEComponent2_3_URI",
".",
"SEPARATOR_PACKED_EDITION",
")",
"==",
"-",
"1",
":",
"# Edition unpacked, only show the first seven components",
"wfn",
"=",
"[",
"]",
"wfn",
".",
... | Returns the CPE Name as Well-Formed Name string of version 2.3.
If edition component is not packed, only shows the first seven
components, otherwise shows all.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version | [
"Returns",
"the",
"CPE",
"Name",
"as",
"Well",
"-",
"Formed",
"Name",
"string",
"of",
"version",
"2",
".",
"3",
".",
"If",
"edition",
"component",
"is",
"not",
"packed",
"only",
"shows",
"the",
"first",
"seven",
"components",
"otherwise",
"shows",
"all",
... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_uri.py#L345-L415 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3_uri.py | CPEComponent2_3_URI._decode | def _decode(self):
"""
Convert the characters of character in value of component to standard
value (WFN value).
This function scans the value of component and returns a copy
with all percent-encoded characters decoded.
:exception: ValueError - invalid character in value ... | python | def _decode(self):
"""
Convert the characters of character in value of component to standard
value (WFN value).
This function scans the value of component and returns a copy
with all percent-encoded characters decoded.
:exception: ValueError - invalid character in value ... | [
"def",
"_decode",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"idx",
"=",
"0",
"s",
"=",
"self",
".",
"_encoded_value",
"embedded",
"=",
"False",
"errmsg",
"=",
"[",
"]",
"errmsg",
".",
"append",
"(",
"\"Invalid value: \"",
")",
"while",
"(",
"id... | Convert the characters of character in value of component to standard
value (WFN value).
This function scans the value of component and returns a copy
with all percent-encoded characters decoded.
:exception: ValueError - invalid character in value of component | [
"Convert",
"the",
"characters",
"of",
"character",
"in",
"value",
"of",
"component",
"to",
"standard",
"value",
"(",
"WFN",
"value",
")",
".",
"This",
"function",
"scans",
"the",
"value",
"of",
"component",
"and",
"returns",
"a",
"copy",
"with",
"all",
"pe... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3_uri.py#L163-L244 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3_uri.py | CPEComponent2_3_URI._is_valid_edition | def _is_valid_edition(self):
"""
Return True if the input value of attribute "edition" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._standard_value[0]
packed = []
packed.app... | python | def _is_valid_edition(self):
"""
Return True if the input value of attribute "edition" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
"""
comp_str = self._standard_value[0]
packed = []
packed.app... | [
"def",
"_is_valid_edition",
"(",
"self",
")",
":",
"comp_str",
"=",
"self",
".",
"_standard_value",
"[",
"0",
"]",
"packed",
"=",
"[",
"]",
"packed",
".",
"append",
"(",
"\"(\"",
")",
"packed",
".",
"append",
"(",
"CPEComponent2_3_URI",
".",
"SEPARATOR_PAC... | Return True if the input value of attribute "edition" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean | [
"Return",
"True",
"if",
"the",
"input",
"value",
"of",
"attribute",
"edition",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3_uri.py#L246-L271 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3.py | CPEComponent2_3._is_valid_language | def _is_valid_language(self):
"""
Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
CASE 1: Language part with/without region part
CASE 2: Language part ... | python | def _is_valid_language(self):
"""
Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
CASE 1: Language part with/without region part
CASE 2: Language part ... | [
"def",
"_is_valid_language",
"(",
"self",
")",
":",
"def",
"check_generic_language",
"(",
"self",
",",
"value",
")",
":",
"\"\"\"\n Check possible values in language part\n when region part exists or not in language value.\n\n Possible values of language ... | Return True if the value of component in attribute "language" is valid,
and otherwise False.
:returns: True if value is valid, False otherwise
:rtype: boolean
CASE 1: Language part with/without region part
CASE 2: Language part without region part
CASE 3: Region part wi... | [
"Return",
"True",
"if",
"the",
"value",
"of",
"component",
"in",
"attribute",
"language",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3.py#L58-L245 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3.py | CPEComponent2_3._is_valid_part | def _is_valid_part(self):
"""
Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value
# Check if value of ... | python | def _is_valid_part(self):
"""
Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean
"""
comp_str = self._encoded_value
# Check if value of ... | [
"def",
"_is_valid_part",
"(",
"self",
")",
":",
"comp_str",
"=",
"self",
".",
"_encoded_value",
"# Check if value of component do not have wildcard",
"if",
"(",
"(",
"comp_str",
".",
"find",
"(",
"self",
".",
"WILDCARD_ONE",
")",
"==",
"-",
"1",
")",
"and",
"(... | Return True if the value of component in attribute "part" is valid,
and otherwise False.
:returns: True if value of component is valid, False otherwise
:rtype: boolean | [
"Return",
"True",
"if",
"the",
"value",
"of",
"component",
"in",
"attribute",
"part",
"is",
"valid",
"and",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3.py#L247-L269 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3._compare | def _compare(cls, source, target):
"""
Compares two values associated with a attribute of two WFNs,
which may be logical values (ANY or NA) or string values.
:param string source: First attribute value
:param string target: Second attribute value
:returns: The attribute ... | python | def _compare(cls, source, target):
"""
Compares two values associated with a attribute of two WFNs,
which may be logical values (ANY or NA) or string values.
:param string source: First attribute value
:param string target: Second attribute value
:returns: The attribute ... | [
"def",
"_compare",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"if",
"(",
"CPESet2_3",
".",
"_is_string",
"(",
"source",
")",
")",
":",
"source",
"=",
"source",
".",
"lower",
"(",
")",
"if",
"(",
"CPESet2_3",
".",
"_is_string",
"(",
"target",... | Compares two values associated with a attribute of two WFNs,
which may be logical values (ANY or NA) or string values.
:param string source: First attribute value
:param string target: Second attribute value
:returns: The attribute comparison relation.
:rtype: int
This ... | [
"Compares",
"two",
"values",
"associated",
"with",
"a",
"attribute",
"of",
"two",
"WFNs",
"which",
"may",
"be",
"logical",
"values",
"(",
"ANY",
"or",
"NA",
")",
"or",
"string",
"values",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L74-L121 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3._compare_strings | def _compare_strings(cls, source, target):
"""
Compares a source string to a target string,
and addresses the condition in which the source string
includes unquoted special characters.
It performs a simple regular expression match,
with the assumption that (as required) ... | python | def _compare_strings(cls, source, target):
"""
Compares a source string to a target string,
and addresses the condition in which the source string
includes unquoted special characters.
It performs a simple regular expression match,
with the assumption that (as required) ... | [
"def",
"_compare_strings",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"start",
"=",
"0",
"end",
"=",
"len",
"(",
"source",
")",
"begins",
"=",
"0",
"ends",
"=",
"0",
"# Reading of initial wildcard in source",
"if",
"source",
".",
"startswith",
"("... | Compares a source string to a target string,
and addresses the condition in which the source string
includes unquoted special characters.
It performs a simple regular expression match,
with the assumption that (as required) unquoted special characters
appear only at the beginnin... | [
"Compares",
"a",
"source",
"string",
"to",
"a",
"target",
"string",
"and",
"addresses",
"the",
"condition",
"in",
"which",
"the",
"source",
"string",
"includes",
"unquoted",
"special",
"characters",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L124-L198 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3._contains_wildcards | def _contains_wildcards(cls, s):
"""
Return True if the string contains any unquoted special characters
(question-mark or asterisk), otherwise False.
Ex: _contains_wildcards("foo") => FALSE
Ex: _contains_wildcards("foo\?") => FALSE
Ex: _contains_wildcards("foo?") => TRUE... | python | def _contains_wildcards(cls, s):
"""
Return True if the string contains any unquoted special characters
(question-mark or asterisk), otherwise False.
Ex: _contains_wildcards("foo") => FALSE
Ex: _contains_wildcards("foo\?") => FALSE
Ex: _contains_wildcards("foo?") => TRUE... | [
"def",
"_contains_wildcards",
"(",
"cls",
",",
"s",
")",
":",
"idx",
"=",
"s",
".",
"find",
"(",
"\"*\"",
")",
"if",
"idx",
"!=",
"-",
"1",
":",
"if",
"idx",
"==",
"0",
":",
"return",
"True",
"else",
":",
"if",
"s",
"[",
"idx",
"-",
"1",
"]",... | Return True if the string contains any unquoted special characters
(question-mark or asterisk), otherwise False.
Ex: _contains_wildcards("foo") => FALSE
Ex: _contains_wildcards("foo\?") => FALSE
Ex: _contains_wildcards("foo?") => TRUE
Ex: _contains_wildcards("\*bar") => FALSE
... | [
"Return",
"True",
"if",
"the",
"string",
"contains",
"any",
"unquoted",
"special",
"characters",
"(",
"question",
"-",
"mark",
"or",
"asterisk",
")",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L201-L235 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3._is_even_wildcards | def _is_even_wildcards(cls, str, idx):
"""
Returns True if an even number of escape (backslash) characters
precede the character at index idx in string str.
:param string str: string to check
:returns: True if an even number of escape characters precede
the character... | python | def _is_even_wildcards(cls, str, idx):
"""
Returns True if an even number of escape (backslash) characters
precede the character at index idx in string str.
:param string str: string to check
:returns: True if an even number of escape characters precede
the character... | [
"def",
"_is_even_wildcards",
"(",
"cls",
",",
"str",
",",
"idx",
")",
":",
"result",
"=",
"0",
"while",
"(",
"(",
"idx",
">",
"0",
")",
"and",
"(",
"str",
"[",
"idx",
"-",
"1",
"]",
"==",
"\"\\\\\"",
")",
")",
":",
"idx",
"-=",
"1",
"result",
... | Returns True if an even number of escape (backslash) characters
precede the character at index idx in string str.
:param string str: string to check
:returns: True if an even number of escape characters precede
the character at index idx in string str, False otherwise.
:rtyp... | [
"Returns",
"True",
"if",
"an",
"even",
"number",
"of",
"escape",
"(",
"backslash",
")",
"characters",
"precede",
"the",
"character",
"at",
"index",
"idx",
"in",
"string",
"str",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L238-L255 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3._is_string | def _is_string(cls, arg):
"""
Return True if arg is a string value,
and False if arg is a logical value (ANY or NA).
:param string arg: string to check
:returns: True if value is a string, False if it is a logical value.
:rtype: boolean
This function is a suppor... | python | def _is_string(cls, arg):
"""
Return True if arg is a string value,
and False if arg is a logical value (ANY or NA).
:param string arg: string to check
:returns: True if value is a string, False if it is a logical value.
:rtype: boolean
This function is a suppor... | [
"def",
"_is_string",
"(",
"cls",
",",
"arg",
")",
":",
"isAny",
"=",
"arg",
"==",
"CPEComponent2_3_WFN",
".",
"VALUE_ANY",
"isNa",
"=",
"arg",
"==",
"CPEComponent2_3_WFN",
".",
"VALUE_NA",
"return",
"not",
"(",
"isAny",
"or",
"isNa",
")"
] | Return True if arg is a string value,
and False if arg is a logical value (ANY or NA).
:param string arg: string to check
:returns: True if value is a string, False if it is a logical value.
:rtype: boolean
This function is a support function for _compare(). | [
"Return",
"True",
"if",
"arg",
"is",
"a",
"string",
"value",
"and",
"False",
"if",
"arg",
"is",
"a",
"logical",
"value",
"(",
"ANY",
"or",
"NA",
")",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L258-L273 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.compare_wfns | def compare_wfns(cls, source, target):
"""
Compares two WFNs and returns a generator of pairwise attribute-value
comparison results. It provides full access to the individual
comparison results to enable use-case specific implementations
of novel name-comparison algorithms.
... | python | def compare_wfns(cls, source, target):
"""
Compares two WFNs and returns a generator of pairwise attribute-value
comparison results. It provides full access to the individual
comparison results to enable use-case specific implementations
of novel name-comparison algorithms.
... | [
"def",
"compare_wfns",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"# Compare results using the get() function in WFN",
"for",
"att",
"in",
"CPEComponent",
".",
"CPE_COMP_KEYS_EXTENDED",
":",
"value_src",
"=",
"source",
".",
"get_attribute_values",
"(",
"att",... | Compares two WFNs and returns a generator of pairwise attribute-value
comparison results. It provides full access to the individual
comparison results to enable use-case specific implementations
of novel name-comparison algorithms.
Compare each attribute of the Source WFN to the Target ... | [
"Compares",
"two",
"WFNs",
"and",
"returns",
"a",
"generator",
"of",
"pairwise",
"attribute",
"-",
"value",
"comparison",
"results",
".",
"It",
"provides",
"full",
"access",
"to",
"the",
"individual",
"comparison",
"results",
"to",
"enable",
"use",
"-",
"case"... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L276-L303 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.cpe_disjoint | def cpe_disjoint(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is DISJOINT.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation betwe... | python | def cpe_disjoint(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is DISJOINT.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation betwe... | [
"def",
"cpe_disjoint",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"# If any pairwise comparison returned DISJOINT then",
"# the overall name relationship is DISJOINT",
"for",
"att",
",",
"result",
"in",
"CPESet2_3",
".",
"compare_wfns",
"(",
"source",
",",
"ta... | Compares two WFNs and returns True if the set-theoretic relation
between the names is DISJOINT.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between source and target
is DISJOINT, otherwise Fal... | [
"Compares",
"two",
"WFNs",
"and",
"returns",
"True",
"if",
"the",
"set",
"-",
"theoretic",
"relation",
"between",
"the",
"names",
"is",
"DISJOINT",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L306-L324 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.cpe_equal | def cpe_equal(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is EQUAL.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between sou... | python | def cpe_equal(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is EQUAL.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between sou... | [
"def",
"cpe_equal",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"# If any pairwise comparison returned EQUAL then",
"# the overall name relationship is EQUAL",
"for",
"att",
",",
"result",
"in",
"CPESet2_3",
".",
"compare_wfns",
"(",
"source",
",",
"target",
"... | Compares two WFNs and returns True if the set-theoretic relation
between the names is EQUAL.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between source and target
is EQUAL, otherwise False.
... | [
"Compares",
"two",
"WFNs",
"and",
"returns",
"True",
"if",
"the",
"set",
"-",
"theoretic",
"relation",
"between",
"the",
"names",
"is",
"EQUAL",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L327-L345 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.cpe_subset | def cpe_subset(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUBSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relat... | python | def cpe_subset(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUBSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relat... | [
"def",
"cpe_subset",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"# If any pairwise comparison returned something other than SUBSET",
"# or EQUAL, then SUBSET is False.",
"for",
"att",
",",
"result",
"in",
"CPESet2_3",
".",
"compare_wfns",
"(",
"source",
",",
"t... | Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUBSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between source and target
is SUBSET, othe... | [
"Compares",
"two",
"WFNs",
"and",
"returns",
"True",
"if",
"the",
"set",
"-",
"theoretic",
"relation",
"between",
"the",
"names",
"is",
"(",
"non",
"-",
"proper",
")",
"SUBSET",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L348-L367 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.cpe_superset | def cpe_superset(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUPERSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set r... | python | def cpe_superset(cls, source, target):
"""
Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUPERSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set r... | [
"def",
"cpe_superset",
"(",
"cls",
",",
"source",
",",
"target",
")",
":",
"# If any pairwise comparison returned something other than SUPERSET",
"# or EQUAL, then SUPERSET is False.",
"for",
"att",
",",
"result",
"in",
"CPESet2_3",
".",
"compare_wfns",
"(",
"source",
","... | Compares two WFNs and returns True if the set-theoretic relation
between the names is (non-proper) SUPERSET.
:param CPE2_3_WFN source: first WFN CPE Name
:param CPE2_3_WFN target: seconds WFN CPE Name
:returns: True if the set relation between source and target
is SUPERSET, ... | [
"Compares",
"two",
"WFNs",
"and",
"returns",
"True",
"if",
"the",
"set",
"-",
"theoretic",
"relation",
"between",
"the",
"names",
"is",
"(",
"non",
"-",
"proper",
")",
"SUPERSET",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L370-L390 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.append | def append(self, cpe):
"""
Adds a CPE element to the set if not already.
Only WFN CPE Names are valid, so this function converts the input CPE
object of version 2.3 to WFN style.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - inv... | python | def append(self, cpe):
"""
Adds a CPE element to the set if not already.
Only WFN CPE Names are valid, so this function converts the input CPE
object of version 2.3 to WFN style.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - inv... | [
"def",
"append",
"(",
"self",
",",
"cpe",
")",
":",
"if",
"cpe",
".",
"VERSION",
"!=",
"CPE2_3",
".",
"VERSION",
":",
"errmsg",
"=",
"\"CPE Name version {0} not valid, version 2.3 expected\"",
".",
"format",
"(",
"cpe",
".",
"VERSION",
")",
"raise",
"ValueErro... | Adds a CPE element to the set if not already.
Only WFN CPE Names are valid, so this function converts the input CPE
object of version 2.3 to WFN style.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name | [
"Adds",
"a",
"CPE",
"element",
"to",
"the",
"set",
"if",
"not",
"already",
".",
"Only",
"WFN",
"CPE",
"Names",
"are",
"valid",
"so",
"this",
"function",
"converts",
"the",
"input",
"CPE",
"object",
"of",
"version",
"2",
".",
"3",
"to",
"WFN",
"style",
... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L396-L421 | train |
nilp0inter/cpe | cpe/cpeset2_3.py | CPESet2_3.name_match | def name_match(self, wfn):
"""
Accepts a set of CPE Names K and a candidate CPE Name X. It returns
'True' if X matches any member of K, and 'False' otherwise.
:param CPESet self: A set of m known CPE Names K = {K1, K2, …, Km}.
:param CPE cpe: A candidate CPE Name X.
:ret... | python | def name_match(self, wfn):
"""
Accepts a set of CPE Names K and a candidate CPE Name X. It returns
'True' if X matches any member of K, and 'False' otherwise.
:param CPESet self: A set of m known CPE Names K = {K1, K2, …, Km}.
:param CPE cpe: A candidate CPE Name X.
:ret... | [
"def",
"name_match",
"(",
"self",
",",
"wfn",
")",
":",
"for",
"N",
"in",
"self",
".",
"K",
":",
"if",
"CPESet2_3",
".",
"cpe_superset",
"(",
"wfn",
",",
"N",
")",
":",
"return",
"True",
"return",
"False"
] | Accepts a set of CPE Names K and a candidate CPE Name X. It returns
'True' if X matches any member of K, and 'False' otherwise.
:param CPESet self: A set of m known CPE Names K = {K1, K2, …, Km}.
:param CPE cpe: A candidate CPE Name X.
:returns: True if X matches K, otherwise False.
... | [
"Accepts",
"a",
"set",
"of",
"CPE",
"Names",
"K",
"and",
"a",
"candidate",
"CPE",
"Name",
"X",
".",
"It",
"returns",
"True",
"if",
"X",
"matches",
"any",
"member",
"of",
"K",
"and",
"False",
"otherwise",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_3.py#L423-L437 | train |
nilp0inter/cpe | cpe/cpe2_3_wfn.py | CPE2_3_WFN._parse | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# Check prefix and initial bracket of WFN
if self._str[0:5] != CPE2_3_WFN.CPE_PREFIX:
errmsg = "Bad-formed CPE Name: WFN prefix not... | python | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# Check prefix and initial bracket of WFN
if self._str[0:5] != CPE2_3_WFN.CPE_PREFIX:
errmsg = "Bad-formed CPE Name: WFN prefix not... | [
"def",
"_parse",
"(",
"self",
")",
":",
"# Check prefix and initial bracket of WFN",
"if",
"self",
".",
"_str",
"[",
"0",
":",
"5",
"]",
"!=",
"CPE2_3_WFN",
".",
"CPE_PREFIX",
":",
"errmsg",
"=",
"\"Bad-formed CPE Name: WFN prefix not found\"",
"raise",
"ValueError"... | Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name | [
"Checks",
"if",
"the",
"CPE",
"Name",
"is",
"valid",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_wfn.py#L110-L216 | train |
nilp0inter/cpe | cpe/cpelang2_2.py | CPELanguage2_2.language_match | def language_match(self, cpeset, cpel_dom=None):
"""
Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applic... | python | def language_match(self, cpeset, cpel_dom=None):
"""
Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applic... | [
"def",
"language_match",
"(",
"self",
",",
"cpeset",
",",
"cpel_dom",
"=",
"None",
")",
":",
"# Root element tag",
"TAG_ROOT",
"=",
"'#document'",
"# A container for child platform definitions",
"TAG_PLATSPEC",
"=",
"'cpe:platform-specification'",
"# Information about a platf... | Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applicability
Language, represented as the XML infoset for the ... | [
"Accepts",
"a",
"set",
"of",
"known",
"CPE",
"Names",
"and",
"an",
"expression",
"in",
"the",
"CPE",
"language",
"and",
"delivers",
"the",
"answer",
"True",
"if",
"the",
"expression",
"matches",
"with",
"the",
"set",
".",
"Otherwise",
"it",
"returns",
"Fal... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpelang2_2.py#L59-L149 | train |
nilp0inter/cpe | cpe/cpeset2_2.py | CPESet2_2.append | def append(self, cpe):
"""
Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset2_2 import CPESet2_2
>>> from .cpe2_2 import CPE2_2... | python | def append(self, cpe):
"""
Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset2_2 import CPESet2_2
>>> from .cpe2_2 import CPE2_2... | [
"def",
"append",
"(",
"self",
",",
"cpe",
")",
":",
"if",
"cpe",
".",
"VERSION",
"!=",
"CPE",
".",
"VERSION_2_2",
":",
"errmsg",
"=",
"\"CPE Name version {0} not valid, version 2.2 expected\"",
".",
"format",
"(",
"cpe",
".",
"VERSION",
")",
"raise",
"ValueErr... | Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset2_2 import CPESet2_2
>>> from .cpe2_2 import CPE2_2
>>> uri1 = 'cpe:/h:hp'
>>>... | [
"Adds",
"a",
"CPE",
"Name",
"to",
"the",
"set",
"if",
"not",
"already",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset2_2.py#L58-L86 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_3_wfn.py | CPEComponent2_3_WFN.set_value | def set_value(self, comp_str, comp_att):
"""
Set the value of component.
:param string comp_str: value of component
:param string comp_att: attribute associated with comp_str
:returns: None
:exception: ValueError - incorrect value of component
"""
# Del ... | python | def set_value(self, comp_str, comp_att):
"""
Set the value of component.
:param string comp_str: value of component
:param string comp_att: attribute associated with comp_str
:returns: None
:exception: ValueError - incorrect value of component
"""
# Del ... | [
"def",
"set_value",
"(",
"self",
",",
"comp_str",
",",
"comp_att",
")",
":",
"# Del double quotes of value",
"str",
"=",
"comp_str",
"[",
"1",
":",
"-",
"1",
"]",
"self",
".",
"_standard_value",
"=",
"str",
"# Parse the value",
"super",
"(",
"CPEComponent2_3_W... | Set the value of component.
:param string comp_str: value of component
:param string comp_att: attribute associated with comp_str
:returns: None
:exception: ValueError - incorrect value of component | [
"Set",
"the",
"value",
"of",
"component",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_3_wfn.py#L132-L147 | train |
nilp0inter/cpe | cpe/cpeset1_1.py | CPESet1_1.append | def append(self, cpe):
"""
Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset1_1 import CPESet1_1
>>> from .cpe1_1 import CPE1_1
... | python | def append(self, cpe):
"""
Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset1_1 import CPESet1_1
>>> from .cpe1_1 import CPE1_1
... | [
"def",
"append",
"(",
"self",
",",
"cpe",
")",
":",
"if",
"cpe",
".",
"VERSION",
"!=",
"CPE",
".",
"VERSION_1_1",
":",
"msg",
"=",
"\"CPE Name version {0} not valid, version 1.1 expected\"",
".",
"format",
"(",
"cpe",
".",
"VERSION",
")",
"raise",
"ValueError"... | Adds a CPE Name to the set if not already.
:param CPE cpe: CPE Name to store in set
:returns: None
:exception: ValueError - invalid version of CPE Name
TEST:
>>> from .cpeset1_1 import CPESet1_1
>>> from .cpe1_1 import CPE1_1
>>> uri1 = 'cpe://microsoft:windows... | [
"Adds",
"a",
"CPE",
"Name",
"to",
"the",
"set",
"if",
"not",
"already",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset1_1.py#L56-L83 | train |
nilp0inter/cpe | cpe/cpeset1_1.py | CPESet1_1.name_match | def name_match(self, cpe):
"""
Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set... | python | def name_match(self, cpe):
"""
Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set... | [
"def",
"name_match",
"(",
"self",
",",
"cpe",
")",
":",
"# An empty set not matching with any CPE",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"return",
"False",
"# If input CPE Name string is in set of CPE Name strings",
"# not do searching more because there is a matchi... | Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set of m known CPE Names K = {K1, K2, …, Km}.
... | [
"Accepts",
"a",
"set",
"of",
"known",
"instances",
"of",
"CPE",
"Names",
"and",
"a",
"candidate",
"CPE",
"Name",
"and",
"returns",
"True",
"if",
"the",
"candidate",
"can",
"be",
"shown",
"to",
"be",
"an",
"instance",
"based",
"on",
"the",
"content",
"of"... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset1_1.py#L85-L169 | train |
nilp0inter/cpe | cpe/cpe2_3_fs.py | CPE2_3_FS._parse | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | python | def _parse(self):
"""
Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | [
"def",
"_parse",
"(",
"self",
")",
":",
"# CPE Name must not have whitespaces",
"if",
"(",
"self",
".",
"_str",
".",
"find",
"(",
"\" \"",
")",
"!=",
"-",
"1",
")",
":",
"msg",
"=",
"\"Bad-formed CPE Name: it must not have whitespaces\"",
"raise",
"ValueError",
... | Checks if the CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name | [
"Checks",
"if",
"the",
"CPE",
"Name",
"is",
"valid",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_fs.py#L130-L199 | train |
nilp0inter/cpe | cpe/cpe2_3_fs.py | CPE2_3_FS.get_attribute_values | def get_attribute_values(self, att_name):
"""
Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - in... | python | def get_attribute_values(self, att_name):
"""
Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - in... | [
"def",
"get_attribute_values",
"(",
"self",
",",
"att_name",
")",
":",
"lc",
"=",
"[",
"]",
"if",
"not",
"CPEComponent",
".",
"is_valid_attribute",
"(",
"att_name",
")",
":",
"errmsg",
"=",
"\"Invalid attribute name: {0}\"",
".",
"format",
"(",
"att_name",
")"... | Returns the values of attribute "att_name" of CPE Name.
By default a only element in each part.
:param string att_name: Attribute name to get
:returns: List of attribute values
:rtype: list
:exception: ValueError - invalid attribute name | [
"Returns",
"the",
"values",
"of",
"attribute",
"att_name",
"of",
"CPE",
"Name",
".",
"By",
"default",
"a",
"only",
"element",
"in",
"each",
"part",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_3_fs.py#L201-L233 | train |
nilp0inter/cpe | cpe/cpe2_2.py | CPE2_2._parse | def _parse(self):
"""
Checks if CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | python | def _parse(self):
"""
Checks if CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name
"""
# CPE Name must not have whitespaces
if (self._str.find(" ") != -1):
msg = "Bad-formed CPE Name: it must not have whitespaces"
... | [
"def",
"_parse",
"(",
"self",
")",
":",
"# CPE Name must not have whitespaces",
"if",
"(",
"self",
".",
"_str",
".",
"find",
"(",
"\" \"",
")",
"!=",
"-",
"1",
")",
":",
"msg",
"=",
"\"Bad-formed CPE Name: it must not have whitespaces\"",
"raise",
"ValueError",
... | Checks if CPE Name is valid.
:returns: None
:exception: ValueError - bad-formed CPE Name | [
"Checks",
"if",
"CPE",
"Name",
"is",
"valid",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_2.py#L127-L193 | train |
nilp0inter/cpe | cpe/cpe2_2.py | CPE2_2.as_wfn | def as_wfn(self):
"""
Returns the CPE Name as WFN string of version 2.3.
Only shows the first seven components.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version
"""
wfn = []
wfn.append(CPE2_3_WFN.CPE_PRE... | python | def as_wfn(self):
"""
Returns the CPE Name as WFN string of version 2.3.
Only shows the first seven components.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version
"""
wfn = []
wfn.append(CPE2_3_WFN.CPE_PRE... | [
"def",
"as_wfn",
"(",
"self",
")",
":",
"wfn",
"=",
"[",
"]",
"wfn",
".",
"append",
"(",
"CPE2_3_WFN",
".",
"CPE_PREFIX",
")",
"for",
"ck",
"in",
"CPEComponent",
".",
"CPE_COMP_KEYS",
":",
"lc",
"=",
"self",
".",
"_get_attribute_components",
"(",
"ck",
... | Returns the CPE Name as WFN string of version 2.3.
Only shows the first seven components.
:return: CPE Name as WFN string
:rtype: string
:exception: TypeError - incompatible version | [
"Returns",
"the",
"CPE",
"Name",
"as",
"WFN",
"string",
"of",
"version",
"2",
".",
"3",
".",
"Only",
"shows",
"the",
"first",
"seven",
"components",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpe2_2.py#L195-L238 | train |
nilp0inter/cpe | cpe/cpelang2_3.py | CPELanguage2_3._fact_ref_eval | def _fact_ref_eval(cls, cpeset, wfn):
"""
Returns True if wfn is a non-proper superset (True superset
or equal to) any of the names in cpeset, otherwise False.
:param CPESet cpeset: list of CPE bound Names.
:param CPE2_3_WFN wfn: WFN CPE Name.
:returns: True if wfn is a ... | python | def _fact_ref_eval(cls, cpeset, wfn):
"""
Returns True if wfn is a non-proper superset (True superset
or equal to) any of the names in cpeset, otherwise False.
:param CPESet cpeset: list of CPE bound Names.
:param CPE2_3_WFN wfn: WFN CPE Name.
:returns: True if wfn is a ... | [
"def",
"_fact_ref_eval",
"(",
"cls",
",",
"cpeset",
",",
"wfn",
")",
":",
"for",
"n",
"in",
"cpeset",
":",
"# Need to convert each n from bound form to WFN",
"if",
"(",
"CPESet2_3",
".",
"cpe_superset",
"(",
"wfn",
",",
"n",
")",
")",
":",
"return",
"True",
... | Returns True if wfn is a non-proper superset (True superset
or equal to) any of the names in cpeset, otherwise False.
:param CPESet cpeset: list of CPE bound Names.
:param CPE2_3_WFN wfn: WFN CPE Name.
:returns: True if wfn is a non-proper superset any of the names in cpeset, otherwise ... | [
"Returns",
"True",
"if",
"wfn",
"is",
"a",
"non",
"-",
"proper",
"superset",
"(",
"True",
"superset",
"or",
"equal",
"to",
")",
"any",
"of",
"the",
"names",
"in",
"cpeset",
"otherwise",
"False",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpelang2_3.py#L62-L78 | train |
nilp0inter/cpe | cpe/cpelang2_3.py | CPELanguage2_3._check_fact_ref_eval | def _check_fact_ref_eval(cls, cpel_dom):
"""
Returns the result (True, False, Error) of performing the specified
check, unless the check isnt supported, in which case it returns
False. Error is a catch-all for all results other than True and
False.
:param string cpel_do... | python | def _check_fact_ref_eval(cls, cpel_dom):
"""
Returns the result (True, False, Error) of performing the specified
check, unless the check isnt supported, in which case it returns
False. Error is a catch-all for all results other than True and
False.
:param string cpel_do... | [
"def",
"_check_fact_ref_eval",
"(",
"cls",
",",
"cpel_dom",
")",
":",
"CHECK_SYSTEM",
"=",
"\"check-system\"",
"CHECK_LOCATION",
"=",
"\"check-location\"",
"CHECK_ID",
"=",
"\"check-id\"",
"checksystemID",
"=",
"cpel_dom",
".",
"getAttribute",
"(",
"CHECK_SYSTEM",
")"... | Returns the result (True, False, Error) of performing the specified
check, unless the check isnt supported, in which case it returns
False. Error is a catch-all for all results other than True and
False.
:param string cpel_dom: XML infoset for the check_fact_ref element.
:retur... | [
"Returns",
"the",
"result",
"(",
"True",
"False",
"Error",
")",
"of",
"performing",
"the",
"specified",
"check",
"unless",
"the",
"check",
"isnt",
"supported",
"in",
"which",
"case",
"it",
"returns",
"False",
".",
"Error",
"is",
"a",
"catch",
"-",
"all",
... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpelang2_3.py#L81-L114 | train |
nilp0inter/cpe | cpe/cpelang2_3.py | CPELanguage2_3._unbind | def _unbind(cls, boundname):
"""
Unbinds a bound form to a WFN.
:param string boundname: CPE name
:returns: WFN object associated with boundname.
:rtype: CPE2_3_WFN
"""
try:
fs = CPE2_3_FS(boundname)
except:
# CPE name is not form... | python | def _unbind(cls, boundname):
"""
Unbinds a bound form to a WFN.
:param string boundname: CPE name
:returns: WFN object associated with boundname.
:rtype: CPE2_3_WFN
"""
try:
fs = CPE2_3_FS(boundname)
except:
# CPE name is not form... | [
"def",
"_unbind",
"(",
"cls",
",",
"boundname",
")",
":",
"try",
":",
"fs",
"=",
"CPE2_3_FS",
"(",
"boundname",
")",
"except",
":",
"# CPE name is not formatted string",
"try",
":",
"uri",
"=",
"CPE2_3_URI",
"(",
"boundname",
")",
"except",
":",
"# CPE name ... | Unbinds a bound form to a WFN.
:param string boundname: CPE name
:returns: WFN object associated with boundname.
:rtype: CPE2_3_WFN | [
"Unbinds",
"a",
"bound",
"form",
"to",
"a",
"WFN",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpelang2_3.py#L145-L166 | train |
nilp0inter/cpe | cpe/cpelang2_3.py | CPELanguage2_3.language_match | def language_match(self, cpeset, cpel_dom=None):
"""
Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applic... | python | def language_match(self, cpeset, cpel_dom=None):
"""
Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applic... | [
"def",
"language_match",
"(",
"self",
",",
"cpeset",
",",
"cpel_dom",
"=",
"None",
")",
":",
"# Root element tag",
"TAG_ROOT",
"=",
"'#document'",
"# A container for child platform definitions",
"TAG_PLATSPEC",
"=",
"'cpe:platform-specification'",
"# Information about a platf... | Accepts a set of known CPE Names and an expression in the CPE language,
and delivers the answer True if the expression matches with the set.
Otherwise, it returns False.
:param CPELanguage self: An expression in the CPE Applicability
Language, represented as the XML infoset for the ... | [
"Accepts",
"a",
"set",
"of",
"known",
"CPE",
"Names",
"and",
"an",
"expression",
"in",
"the",
"CPE",
"language",
"and",
"delivers",
"the",
"answer",
"True",
"if",
"the",
"expression",
"matches",
"with",
"the",
"set",
".",
"Otherwise",
"it",
"returns",
"Fal... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpelang2_3.py#L172-L277 | train |
nilp0inter/cpe | cpe/cpeset.py | CPESet.name_match | def name_match(self, cpe):
"""
Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set... | python | def name_match(self, cpe):
"""
Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set... | [
"def",
"name_match",
"(",
"self",
",",
"cpe",
")",
":",
"# An empty set not matching with any CPE",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"return",
"False",
"# If input CPE Name string is in set of CPE Name strings",
"# not do searching more because there is a matchi... | Accepts a set of known instances of CPE Names and a candidate CPE Name,
and returns 'True' if the candidate can be shown to be
an instance based on the content of the known instances.
Otherwise, it returns 'False'.
:param CPESet self: A set of m known CPE Names K = {K1, K2, …, Km}.
... | [
"Accepts",
"a",
"set",
"of",
"known",
"instances",
"of",
"CPE",
"Names",
"and",
"a",
"candidate",
"CPE",
"Name",
"and",
"returns",
"True",
"if",
"the",
"candidate",
"can",
"be",
"shown",
"to",
"be",
"an",
"instance",
"based",
"on",
"the",
"content",
"of"... | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/cpeset.py#L121-L195 | train |
nilp0inter/cpe | cpe/comp/cpecomp2_2.py | CPEComponent2_2._decode | def _decode(self):
"""
Convert the encoded value of component to standard value (WFN value).
"""
result = []
idx = 0
s = self._encoded_value
while (idx < len(s)):
# Get the idx'th character of s
c = s[idx]
if (c in CPECompone... | python | def _decode(self):
"""
Convert the encoded value of component to standard value (WFN value).
"""
result = []
idx = 0
s = self._encoded_value
while (idx < len(s)):
# Get the idx'th character of s
c = s[idx]
if (c in CPECompone... | [
"def",
"_decode",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"idx",
"=",
"0",
"s",
"=",
"self",
".",
"_encoded_value",
"while",
"(",
"idx",
"<",
"len",
"(",
"s",
")",
")",
":",
"# Get the idx'th character of s",
"c",
"=",
"s",
"[",
"idx",
"]",... | Convert the encoded value of component to standard value (WFN value). | [
"Convert",
"the",
"encoded",
"value",
"of",
"component",
"to",
"standard",
"value",
"(",
"WFN",
"value",
")",
"."
] | 670d947472a7652af5149324977b50f9a7af9bcf | https://github.com/nilp0inter/cpe/blob/670d947472a7652af5149324977b50f9a7af9bcf/cpe/comp/cpecomp2_2.py#L90-L113 | train |
pysal/giddy | giddy/components.py | is_component | def is_component(w, ids):
"""Check if the set of ids form a single connected component
Parameters
----------
w : spatial weights boject
ids : list
identifiers of units that are tested to be a single connected
component
Returns
-------
True : if the list of ... | python | def is_component(w, ids):
"""Check if the set of ids form a single connected component
Parameters
----------
w : spatial weights boject
ids : list
identifiers of units that are tested to be a single connected
component
Returns
-------
True : if the list of ... | [
"def",
"is_component",
"(",
"w",
",",
"ids",
")",
":",
"components",
"=",
"0",
"marks",
"=",
"dict",
"(",
"[",
"(",
"node",
",",
"0",
")",
"for",
"node",
"in",
"ids",
"]",
")",
"q",
"=",
"[",
"]",
"for",
"node",
"in",
"ids",
":",
"if",
"marks... | Check if the set of ids form a single connected component
Parameters
----------
w : spatial weights boject
ids : list
identifiers of units that are tested to be a single connected
component
Returns
-------
True : if the list of ids represents a single connected... | [
"Check",
"if",
"the",
"set",
"of",
"ids",
"form",
"a",
"single",
"connected",
"component"
] | 13fae6c18933614be78e91a6b5060693bea33a04 | https://github.com/pysal/giddy/blob/13fae6c18933614be78e91a6b5060693bea33a04/giddy/components.py#L11-L50 | train |
pysal/giddy | giddy/components.py | check_contiguity | def check_contiguity(w, neighbors, leaver):
"""Check if contiguity is maintained if leaver is removed from neighbors
Parameters
----------
w : spatial weights object
simple contiguity based weights
neighbors : list
nodes that are to be checked if th... | python | def check_contiguity(w, neighbors, leaver):
"""Check if contiguity is maintained if leaver is removed from neighbors
Parameters
----------
w : spatial weights object
simple contiguity based weights
neighbors : list
nodes that are to be checked if th... | [
"def",
"check_contiguity",
"(",
"w",
",",
"neighbors",
",",
"leaver",
")",
":",
"ids",
"=",
"neighbors",
"[",
":",
"]",
"ids",
".",
"remove",
"(",
"leaver",
")",
"return",
"is_component",
"(",
"w",
",",
"ids",
")"
] | Check if contiguity is maintained if leaver is removed from neighbors
Parameters
----------
w : spatial weights object
simple contiguity based weights
neighbors : list
nodes that are to be checked if they form a single \
connec... | [
"Check",
"if",
"contiguity",
"is",
"maintained",
"if",
"leaver",
"is",
"removed",
"from",
"neighbors"
] | 13fae6c18933614be78e91a6b5060693bea33a04 | https://github.com/pysal/giddy/blob/13fae6c18933614be78e91a6b5060693bea33a04/giddy/components.py#L53-L103 | train |
pyinvoke/invocations | invocations/console.py | confirm | def confirm(question, assume_yes=True):
"""
Ask user a yes/no question and return their response as a boolean.
``question`` should be a simple, grammatically complete question such as
"Do you wish to continue?", and will have a string similar to ``" [Y/n] "``
appended automatically. This function w... | python | def confirm(question, assume_yes=True):
"""
Ask user a yes/no question and return their response as a boolean.
``question`` should be a simple, grammatically complete question such as
"Do you wish to continue?", and will have a string similar to ``" [Y/n] "``
appended automatically. This function w... | [
"def",
"confirm",
"(",
"question",
",",
"assume_yes",
"=",
"True",
")",
":",
"# Set up suffix",
"if",
"assume_yes",
":",
"suffix",
"=",
"\"Y/n\"",
"else",
":",
"suffix",
"=",
"\"y/N\"",
"# Loop till we get something we like",
"# TODO: maybe don't do this? It can be anno... | Ask user a yes/no question and return their response as a boolean.
``question`` should be a simple, grammatically complete question such as
"Do you wish to continue?", and will have a string similar to ``" [Y/n] "``
appended automatically. This function will *not* append a question mark for
you.
B... | [
"Ask",
"user",
"a",
"yes",
"/",
"no",
"question",
"and",
"return",
"their",
"response",
"as",
"a",
"boolean",
"."
] | bbf1b319bd1536817d5301ceb9eeb2f31830e5dc | https://github.com/pyinvoke/invocations/blob/bbf1b319bd1536817d5301ceb9eeb2f31830e5dc/invocations/console.py#L13-L59 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.