repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
jstitch/MambuPy | MambuPy/rest/mambuloan.py | MambuLoan.setUser | def setUser(self, *args, **kwargs):
"""Adds the user for this loan to a 'user' field.
User is a MambuUser object.
Returns the number of requests done to Mambu.
"""
try:
user = self.mambuuserclass(entid=self['assignedUserKey'], *args, **kwargs)
except KeyErro... | python | def setUser(self, *args, **kwargs):
"""Adds the user for this loan to a 'user' field.
User is a MambuUser object.
Returns the number of requests done to Mambu.
"""
try:
user = self.mambuuserclass(entid=self['assignedUserKey'], *args, **kwargs)
except KeyErro... | [
"def",
"setUser",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"user",
"=",
"self",
".",
"mambuuserclass",
"(",
"entid",
"=",
"self",
"[",
"'assignedUserKey'",
"]",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
... | Adds the user for this loan to a 'user' field.
User is a MambuUser object.
Returns the number of requests done to Mambu. | [
"Adds",
"the",
"user",
"for",
"this",
"loan",
"to",
"a",
"user",
"field",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuloan.py#L183-L208 | train |
jstitch/MambuPy | MambuPy/rest/mambuloan.py | MambuLoan.setProduct | def setProduct(self, cache=False, *args, **kwargs):
"""Adds the product for this loan to a 'product' field.
Product is a MambuProduct object.
cache argument allows to use AllMambuProducts singleton to
retrieve the products. See mambuproduct.AllMambuProducts code
and pydoc for f... | python | def setProduct(self, cache=False, *args, **kwargs):
"""Adds the product for this loan to a 'product' field.
Product is a MambuProduct object.
cache argument allows to use AllMambuProducts singleton to
retrieve the products. See mambuproduct.AllMambuProducts code
and pydoc for f... | [
"def",
"setProduct",
"(",
"self",
",",
"cache",
"=",
"False",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"cache",
":",
"try",
":",
"prods",
"=",
"self",
".",
"allmambuproductsclass",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
... | Adds the product for this loan to a 'product' field.
Product is a MambuProduct object.
cache argument allows to use AllMambuProducts singleton to
retrieve the products. See mambuproduct.AllMambuProducts code
and pydoc for further information.
Returns the number of requests don... | [
"Adds",
"the",
"product",
"for",
"this",
"loan",
"to",
"a",
"product",
"field",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuloan.py#L211-L247 | train |
jstitch/MambuPy | MambuPy/rest/mambuloan.py | MambuLoan.getClientDetails | def getClientDetails(self, *args, **kwargs):
"""Gets the loan details for every client holder of the account.
As default, assigns the whole loan amount to each client. This
works fine for Client holders of the loan account. When Group
holders, this is perhaps not ideal, but I cannot tel... | python | def getClientDetails(self, *args, **kwargs):
"""Gets the loan details for every client holder of the account.
As default, assigns the whole loan amount to each client. This
works fine for Client holders of the loan account. When Group
holders, this is perhaps not ideal, but I cannot tel... | [
"def",
"getClientDetails",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"loannames",
"=",
"[",
"]",
"holder",
"=",
"kwargs",
"[",
"'holder'",
"]",
"for",
"client",
"in",
"holder",
"[",
"'clients'",
"]",
":",
"loannames",
".",
"append",... | Gets the loan details for every client holder of the account.
As default, assigns the whole loan amount to each client. This
works fine for Client holders of the loan account. When Group
holders, this is perhaps not ideal, but I cannot tell.
If you inherit MambuLoan you should override... | [
"Gets",
"the",
"loan",
"details",
"for",
"every",
"client",
"holder",
"of",
"the",
"account",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuloan.py#L412-L444 | train |
inveniosoftware/invenio-query-parser | invenio_query_parser/contrib/elasticsearch/walkers/dsl.py | ElasticSearchDSL.get_fields_for_keyword | def get_fields_for_keyword(self, keyword, mode='a'):
"""Convert keyword to fields."""
field = self.keyword_to_fields.get(keyword, keyword)
if isinstance(field, dict):
return field[mode]
elif isinstance(field, (list, tuple)):
return field
return [field] | python | def get_fields_for_keyword(self, keyword, mode='a'):
"""Convert keyword to fields."""
field = self.keyword_to_fields.get(keyword, keyword)
if isinstance(field, dict):
return field[mode]
elif isinstance(field, (list, tuple)):
return field
return [field] | [
"def",
"get_fields_for_keyword",
"(",
"self",
",",
"keyword",
",",
"mode",
"=",
"'a'",
")",
":",
"field",
"=",
"self",
".",
"keyword_to_fields",
".",
"get",
"(",
"keyword",
",",
"keyword",
")",
"if",
"isinstance",
"(",
"field",
",",
"dict",
")",
":",
"... | Convert keyword to fields. | [
"Convert",
"keyword",
"to",
"fields",
"."
] | 21a2c36318003ff52d2e18e7196bb420db8ecb4b | https://github.com/inveniosoftware/invenio-query-parser/blob/21a2c36318003ff52d2e18e7196bb420db8ecb4b/invenio_query_parser/contrib/elasticsearch/walkers/dsl.py#L46-L53 | train |
pyslackers/sir-bot-a-lot | sirbot/utils/__init__.py | merge_dict | def merge_dict(a, b, path=None):
"""
Merge dict b into a
"""
if not path:
path = []
for key in b:
if key in a:
if isinstance(a[key], dict) and isinstance(b[key], dict):
merge_dict(a[key], b[key], path + [str(key)])
else:
continu... | python | def merge_dict(a, b, path=None):
"""
Merge dict b into a
"""
if not path:
path = []
for key in b:
if key in a:
if isinstance(a[key], dict) and isinstance(b[key], dict):
merge_dict(a[key], b[key], path + [str(key)])
else:
continu... | [
"def",
"merge_dict",
"(",
"a",
",",
"b",
",",
"path",
"=",
"None",
")",
":",
"if",
"not",
"path",
":",
"path",
"=",
"[",
"]",
"for",
"key",
"in",
"b",
":",
"if",
"key",
"in",
"a",
":",
"if",
"isinstance",
"(",
"a",
"[",
"key",
"]",
",",
"di... | Merge dict b into a | [
"Merge",
"dict",
"b",
"into",
"a"
] | 22dfdd6a14d61dbe29423fd131b7a23e618b68d7 | https://github.com/pyslackers/sir-bot-a-lot/blob/22dfdd6a14d61dbe29423fd131b7a23e618b68d7/sirbot/utils/__init__.py#L8-L22 | train |
BernardFW/bernard | src/bernard/i18n/_formatter.py | make_date | def make_date(obj: Union[date, datetime, Text], timezone: tzinfo=None):
"""
A flexible method to get a date object.
It accepts either an ISO 8601 date/time string, either a Python `datetime`,
either a Python `date`.
If the input is a date/time and a timezone is specified, the resulting
date ob... | python | def make_date(obj: Union[date, datetime, Text], timezone: tzinfo=None):
"""
A flexible method to get a date object.
It accepts either an ISO 8601 date/time string, either a Python `datetime`,
either a Python `date`.
If the input is a date/time and a timezone is specified, the resulting
date ob... | [
"def",
"make_date",
"(",
"obj",
":",
"Union",
"[",
"date",
",",
"datetime",
",",
"Text",
"]",
",",
"timezone",
":",
"tzinfo",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"datetime",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'asti... | A flexible method to get a date object.
It accepts either an ISO 8601 date/time string, either a Python `datetime`,
either a Python `date`.
If the input is a date/time and a timezone is specified, the resulting
date object will be in the specified time zone. | [
"A",
"flexible",
"method",
"to",
"get",
"a",
"date",
"object",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/i18n/_formatter.py#L22-L40 | train |
BernardFW/bernard | src/bernard/i18n/_formatter.py | I18nFormatter.format_date | def format_date(self, value, format_):
"""
Format the date using Babel
"""
date_ = make_date(value)
return dates.format_date(date_, format_, locale=self.lang) | python | def format_date(self, value, format_):
"""
Format the date using Babel
"""
date_ = make_date(value)
return dates.format_date(date_, format_, locale=self.lang) | [
"def",
"format_date",
"(",
"self",
",",
"value",
",",
"format_",
")",
":",
"date_",
"=",
"make_date",
"(",
"value",
")",
"return",
"dates",
".",
"format_date",
"(",
"date_",
",",
"format_",
",",
"locale",
"=",
"self",
".",
"lang",
")"
] | Format the date using Babel | [
"Format",
"the",
"date",
"using",
"Babel"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/i18n/_formatter.py#L80-L85 | train |
BernardFW/bernard | src/bernard/i18n/_formatter.py | I18nFormatter.format_datetime | def format_datetime(self, value, format_):
"""
Format the datetime using Babel
"""
date_ = make_datetime(value)
return dates.format_datetime(date_, format_, locale=self.lang) | python | def format_datetime(self, value, format_):
"""
Format the datetime using Babel
"""
date_ = make_datetime(value)
return dates.format_datetime(date_, format_, locale=self.lang) | [
"def",
"format_datetime",
"(",
"self",
",",
"value",
",",
"format_",
")",
":",
"date_",
"=",
"make_datetime",
"(",
"value",
")",
"return",
"dates",
".",
"format_datetime",
"(",
"date_",
",",
"format_",
",",
"locale",
"=",
"self",
".",
"lang",
")"
] | Format the datetime using Babel | [
"Format",
"the",
"datetime",
"using",
"Babel"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/i18n/_formatter.py#L87-L92 | train |
BernardFW/bernard | src/bernard/i18n/_formatter.py | I18nFormatter.format_field | def format_field(self, value, spec):
"""
Provide the additional formatters for localization.
"""
if spec.startswith('date:'):
_, format_ = spec.split(':', 1)
return self.format_date(value, format_)
elif spec.startswith('datetime:'):
_, format_... | python | def format_field(self, value, spec):
"""
Provide the additional formatters for localization.
"""
if spec.startswith('date:'):
_, format_ = spec.split(':', 1)
return self.format_date(value, format_)
elif spec.startswith('datetime:'):
_, format_... | [
"def",
"format_field",
"(",
"self",
",",
"value",
",",
"spec",
")",
":",
"if",
"spec",
".",
"startswith",
"(",
"'date:'",
")",
":",
"_",
",",
"format_",
"=",
"spec",
".",
"split",
"(",
"':'",
",",
"1",
")",
"return",
"self",
".",
"format_date",
"("... | Provide the additional formatters for localization. | [
"Provide",
"the",
"additional",
"formatters",
"for",
"localization",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/i18n/_formatter.py#L100-L114 | train |
klmitch/turnstile | turnstile/limits.py | BucketKey._decode | def _decode(cls, value):
"""Decode the given value, reverting '%'-encoded groups."""
value = cls._DEC_RE.sub(lambda x: '%c' % int(x.group(1), 16), value)
return json.loads(value) | python | def _decode(cls, value):
"""Decode the given value, reverting '%'-encoded groups."""
value = cls._DEC_RE.sub(lambda x: '%c' % int(x.group(1), 16), value)
return json.loads(value) | [
"def",
"_decode",
"(",
"cls",
",",
"value",
")",
":",
"value",
"=",
"cls",
".",
"_DEC_RE",
".",
"sub",
"(",
"lambda",
"x",
":",
"'%c'",
"%",
"int",
"(",
"x",
".",
"group",
"(",
"1",
")",
",",
"16",
")",
",",
"value",
")",
"return",
"json",
".... | Decode the given value, reverting '%'-encoded groups. | [
"Decode",
"the",
"given",
"value",
"reverting",
"%",
"-",
"encoded",
"groups",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L153-L157 | train |
klmitch/turnstile | turnstile/limits.py | BucketKey.decode | def decode(cls, key):
"""
Decode a bucket key into a BucketKey instance.
:param key: The string form of a bucket key.
:returns: A suitable instance of BucketKey corresponding to
the passed-in key.
"""
# Determine bucket key version
prefix, sep... | python | def decode(cls, key):
"""
Decode a bucket key into a BucketKey instance.
:param key: The string form of a bucket key.
:returns: A suitable instance of BucketKey corresponding to
the passed-in key.
"""
# Determine bucket key version
prefix, sep... | [
"def",
"decode",
"(",
"cls",
",",
"key",
")",
":",
"prefix",
",",
"sep",
",",
"param_str",
"=",
"key",
".",
"partition",
"(",
"':'",
")",
"if",
"sep",
"!=",
"':'",
"or",
"prefix",
"not",
"in",
"cls",
".",
"_prefix_to_version",
":",
"raise",
"ValueErr... | Decode a bucket key into a BucketKey instance.
:param key: The string form of a bucket key.
:returns: A suitable instance of BucketKey corresponding to
the passed-in key. | [
"Decode",
"a",
"bucket",
"key",
"into",
"a",
"BucketKey",
"instance",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L198-L229 | train |
klmitch/turnstile | turnstile/limits.py | BucketLoader.need_summary | def need_summary(self, now, max_updates, max_age):
"""
Helper method to determine if a "summarize" record should be
added.
:param now: The current time.
:param max_updates: Maximum number of updates before a
summarize is required.
:param max_a... | python | def need_summary(self, now, max_updates, max_age):
"""
Helper method to determine if a "summarize" record should be
added.
:param now: The current time.
:param max_updates: Maximum number of updates before a
summarize is required.
:param max_a... | [
"def",
"need_summary",
"(",
"self",
",",
"now",
",",
"max_updates",
",",
"max_age",
")",
":",
"if",
"self",
".",
"summarized",
"is",
"True",
"and",
"self",
".",
"last_summarize_ts",
"+",
"max_age",
"<=",
"now",
":",
"return",
"True",
"return",
"self",
".... | Helper method to determine if a "summarize" record should be
added.
:param now: The current time.
:param max_updates: Maximum number of updates before a
summarize is required.
:param max_age: Maximum age of the last summarize record.
T... | [
"Helper",
"method",
"to",
"determine",
"if",
"a",
"summarize",
"record",
"should",
"be",
"added",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L403-L423 | train |
klmitch/turnstile | turnstile/limits.py | Bucket.dehydrate | def dehydrate(self):
"""Return a dict representing this bucket."""
# Only concerned about very specific attributes
result = {}
for attr in self.attrs:
result[attr] = getattr(self, attr)
return result | python | def dehydrate(self):
"""Return a dict representing this bucket."""
# Only concerned about very specific attributes
result = {}
for attr in self.attrs:
result[attr] = getattr(self, attr)
return result | [
"def",
"dehydrate",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"for",
"attr",
"in",
"self",
".",
"attrs",
":",
"result",
"[",
"attr",
"]",
"=",
"getattr",
"(",
"self",
",",
"attr",
")",
"return",
"result"
] | Return a dict representing this bucket. | [
"Return",
"a",
"dict",
"representing",
"this",
"bucket",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L464-L472 | train |
klmitch/turnstile | turnstile/limits.py | Bucket.delay | def delay(self, params, now=None):
"""Determine delay until next request."""
if now is None:
now = time.time()
# Initialize last...
if not self.last:
self.last = now
elif now < self.last:
now = self.last
# How much has leaked out?
... | python | def delay(self, params, now=None):
"""Determine delay until next request."""
if now is None:
now = time.time()
# Initialize last...
if not self.last:
self.last = now
elif now < self.last:
now = self.last
# How much has leaked out?
... | [
"def",
"delay",
"(",
"self",
",",
"params",
",",
"now",
"=",
"None",
")",
":",
"if",
"now",
"is",
"None",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"not",
"self",
".",
"last",
":",
"self",
".",
"last",
"=",
"now",
"elif",
"now",
"... | Determine delay until next request. | [
"Determine",
"delay",
"until",
"next",
"request",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L474-L506 | train |
klmitch/turnstile | turnstile/limits.py | Bucket.messages | def messages(self):
"""Return remaining messages before limiting."""
return int(math.floor(((self.limit.unit_value - self.level) /
self.limit.unit_value) * self.limit.value)) | python | def messages(self):
"""Return remaining messages before limiting."""
return int(math.floor(((self.limit.unit_value - self.level) /
self.limit.unit_value) * self.limit.value)) | [
"def",
"messages",
"(",
"self",
")",
":",
"return",
"int",
"(",
"math",
".",
"floor",
"(",
"(",
"(",
"self",
".",
"limit",
".",
"unit_value",
"-",
"self",
".",
"level",
")",
"/",
"self",
".",
"limit",
".",
"unit_value",
")",
"*",
"self",
".",
"li... | Return remaining messages before limiting. | [
"Return",
"remaining",
"messages",
"before",
"limiting",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L509-L513 | train |
klmitch/turnstile | turnstile/limits.py | Limit.dehydrate | def dehydrate(self):
"""Return a dict representing this limit."""
# Only concerned about very specific attributes
result = dict(limit_class=self._limit_full_name)
for attr in self.attrs:
# Using getattr allows the properties to come into play
result[attr] = getat... | python | def dehydrate(self):
"""Return a dict representing this limit."""
# Only concerned about very specific attributes
result = dict(limit_class=self._limit_full_name)
for attr in self.attrs:
# Using getattr allows the properties to come into play
result[attr] = getat... | [
"def",
"dehydrate",
"(",
"self",
")",
":",
"result",
"=",
"dict",
"(",
"limit_class",
"=",
"self",
".",
"_limit_full_name",
")",
"for",
"attr",
"in",
"self",
".",
"attrs",
":",
"result",
"[",
"attr",
"]",
"=",
"getattr",
"(",
"self",
",",
"attr",
")"... | Return a dict representing this limit. | [
"Return",
"a",
"dict",
"representing",
"this",
"limit",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L729-L738 | train |
klmitch/turnstile | turnstile/limits.py | Limit.load | def load(self, key):
"""
Given a bucket key, load the corresponding bucket.
:param key: The bucket key. This may be either a string or a
BucketKey object.
:returns: A Bucket object.
"""
# Turn the key into a BucketKey
if isinstance(key, bas... | python | def load(self, key):
"""
Given a bucket key, load the corresponding bucket.
:param key: The bucket key. This may be either a string or a
BucketKey object.
:returns: A Bucket object.
"""
# Turn the key into a BucketKey
if isinstance(key, bas... | [
"def",
"load",
"(",
"self",
",",
"key",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"basestring",
")",
":",
"key",
"=",
"BucketKey",
".",
"decode",
"(",
"key",
")",
"if",
"key",
".",
"uuid",
"!=",
"self",
".",
"uuid",
":",
"raise",
"ValueError",... | Given a bucket key, load the corresponding bucket.
:param key: The bucket key. This may be either a string or a
BucketKey object.
:returns: A Bucket object. | [
"Given",
"a",
"bucket",
"key",
"load",
"the",
"corresponding",
"bucket",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L780-L813 | train |
klmitch/turnstile | turnstile/limits.py | Limit.decode | def decode(self, key):
"""
Given a bucket key, compute the parameters used to compute
that key.
Note: Deprecated. Use BucketKey.decode() instead.
:param key: The bucket key. Note that the UUID must match the
UUID of this limit; a ValueError will be raised ... | python | def decode(self, key):
"""
Given a bucket key, compute the parameters used to compute
that key.
Note: Deprecated. Use BucketKey.decode() instead.
:param key: The bucket key. Note that the UUID must match the
UUID of this limit; a ValueError will be raised ... | [
"def",
"decode",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"BucketKey",
".",
"decode",
"(",
"key",
")",
"if",
"key",
".",
"uuid",
"!=",
"self",
".",
"uuid",
":",
"raise",
"ValueError",
"(",
"\"%s is not a bucket corresponding to this limit\"",
"%",
"k... | Given a bucket key, compute the parameters used to compute
that key.
Note: Deprecated. Use BucketKey.decode() instead.
:param key: The bucket key. Note that the UUID must match the
UUID of this limit; a ValueError will be raised if
this is not the case... | [
"Given",
"a",
"bucket",
"key",
"compute",
"the",
"parameters",
"used",
"to",
"compute",
"that",
"key",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L815-L835 | train |
klmitch/turnstile | turnstile/limits.py | Limit._filter | def _filter(self, environ, params):
"""
Performs final filtering of the request to determine if this
limit applies. Returns False if the limit does not apply or
if the call should not be limited, or True to apply the limit.
"""
# Search for required query arguments
... | python | def _filter(self, environ, params):
"""
Performs final filtering of the request to determine if this
limit applies. Returns False if the limit does not apply or
if the call should not be limited, or True to apply the limit.
"""
# Search for required query arguments
... | [
"def",
"_filter",
"(",
"self",
",",
"environ",
",",
"params",
")",
":",
"if",
"self",
".",
"queries",
":",
"if",
"'QUERY_STRING'",
"not",
"in",
"environ",
":",
"return",
"False",
"available",
"=",
"set",
"(",
"qstr",
".",
"partition",
"(",
"'='",
")",
... | Performs final filtering of the request to determine if this
limit applies. Returns False if the limit does not apply or
if the call should not be limited, or True to apply the limit. | [
"Performs",
"final",
"filtering",
"of",
"the",
"request",
"to",
"determine",
"if",
"this",
"limit",
"applies",
".",
"Returns",
"False",
"if",
"the",
"limit",
"does",
"not",
"apply",
"or",
"if",
"the",
"call",
"should",
"not",
"be",
"limited",
"or",
"True",... | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L849-L972 | train |
klmitch/turnstile | turnstile/limits.py | Limit.format | def format(self, status, headers, environ, bucket, delay):
"""
Formats a response entity. Returns a tuple of the desired
status code and the formatted entity. The default status code
is passed in, as is a dictionary of headers.
:param status: The default status code. Should b... | python | def format(self, status, headers, environ, bucket, delay):
"""
Formats a response entity. Returns a tuple of the desired
status code and the formatted entity. The default status code
is passed in, as is a dictionary of headers.
:param status: The default status code. Should b... | [
"def",
"format",
"(",
"self",
",",
"status",
",",
"headers",
",",
"environ",
",",
"bucket",
",",
"delay",
")",
":",
"entity",
"=",
"(",
"\"This request was rate-limited. \"",
"\"Please retry your request after %s.\"",
"%",
"time",
".",
"strftime",
"(",
"\"%Y-%m-%... | Formats a response entity. Returns a tuple of the desired
status code and the formatted entity. The default status code
is passed in, as is a dictionary of headers.
:param status: The default status code. Should be returned to
the caller, or an alternate selected. The... | [
"Formats",
"a",
"response",
"entity",
".",
"Returns",
"a",
"tuple",
"of",
"the",
"desired",
"status",
"code",
"and",
"the",
"formatted",
"entity",
".",
"The",
"default",
"status",
"code",
"is",
"passed",
"in",
"as",
"is",
"a",
"dictionary",
"of",
"headers"... | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/limits.py#L993-L1023 | train |
openvax/varlens | varlens/util.py | drop_prefix | def drop_prefix(strings):
"""
Removes common prefix from a collection of strings
"""
strings_without_extensions = [
s.split(".", 2)[0] for s in strings
]
if len(strings_without_extensions) == 1:
return [os.path.basename(strings_without_extensions[0])]
prefix_len = len(os.pat... | python | def drop_prefix(strings):
"""
Removes common prefix from a collection of strings
"""
strings_without_extensions = [
s.split(".", 2)[0] for s in strings
]
if len(strings_without_extensions) == 1:
return [os.path.basename(strings_without_extensions[0])]
prefix_len = len(os.pat... | [
"def",
"drop_prefix",
"(",
"strings",
")",
":",
"strings_without_extensions",
"=",
"[",
"s",
".",
"split",
"(",
"\".\"",
",",
"2",
")",
"[",
"0",
"]",
"for",
"s",
"in",
"strings",
"]",
"if",
"len",
"(",
"strings_without_extensions",
")",
"==",
"1",
":"... | Removes common prefix from a collection of strings | [
"Removes",
"common",
"prefix",
"from",
"a",
"collection",
"of",
"strings"
] | 715d3ede5893757b2fcba4117515621bca7b1e5d | https://github.com/openvax/varlens/blob/715d3ede5893757b2fcba4117515621bca7b1e5d/varlens/util.py#L52-L68 | train |
ossobv/dutree | dutree/dutree.py | DuNode.count | def count(self):
"Return how many nodes this contains, including self."
if self._nodes is None:
return 1
return sum(i.count() for i in self._nodes) | python | def count(self):
"Return how many nodes this contains, including self."
if self._nodes is None:
return 1
return sum(i.count() for i in self._nodes) | [
"def",
"count",
"(",
"self",
")",
":",
"\"Return how many nodes this contains, including self.\"",
"if",
"self",
".",
"_nodes",
"is",
"None",
":",
"return",
"1",
"return",
"sum",
"(",
"i",
".",
"count",
"(",
")",
"for",
"i",
"in",
"self",
".",
"_nodes",
")... | Return how many nodes this contains, including self. | [
"Return",
"how",
"many",
"nodes",
"this",
"contains",
"including",
"self",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L107-L111 | train |
ossobv/dutree | dutree/dutree.py | DuNode.app_size | def app_size(self):
"Return the total apparent size, including children."
if self._nodes is None:
return self._app_size
return sum(i.app_size() for i in self._nodes) | python | def app_size(self):
"Return the total apparent size, including children."
if self._nodes is None:
return self._app_size
return sum(i.app_size() for i in self._nodes) | [
"def",
"app_size",
"(",
"self",
")",
":",
"\"Return the total apparent size, including children.\"",
"if",
"self",
".",
"_nodes",
"is",
"None",
":",
"return",
"self",
".",
"_app_size",
"return",
"sum",
"(",
"i",
".",
"app_size",
"(",
")",
"for",
"i",
"in",
"... | Return the total apparent size, including children. | [
"Return",
"the",
"total",
"apparent",
"size",
"including",
"children",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L120-L124 | train |
ossobv/dutree | dutree/dutree.py | DuNode.use_size | def use_size(self):
"Return the total used size, including children."
if self._nodes is None:
return self._use_size
return sum(i.use_size() for i in self._nodes) | python | def use_size(self):
"Return the total used size, including children."
if self._nodes is None:
return self._use_size
return sum(i.use_size() for i in self._nodes) | [
"def",
"use_size",
"(",
"self",
")",
":",
"\"Return the total used size, including children.\"",
"if",
"self",
".",
"_nodes",
"is",
"None",
":",
"return",
"self",
".",
"_use_size",
"return",
"sum",
"(",
"i",
".",
"use_size",
"(",
")",
"for",
"i",
"in",
"self... | Return the total used size, including children. | [
"Return",
"the",
"total",
"used",
"size",
"including",
"children",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L127-L131 | train |
ossobv/dutree | dutree/dutree.py | DuNode._prune_all_if_small | def _prune_all_if_small(self, small_size, a_or_u):
"Return True and delete children if small enough."
if self._nodes is None:
return True
total_size = (self.app_size() if a_or_u else self.use_size())
if total_size < small_size:
if a_or_u:
self._se... | python | def _prune_all_if_small(self, small_size, a_or_u):
"Return True and delete children if small enough."
if self._nodes is None:
return True
total_size = (self.app_size() if a_or_u else self.use_size())
if total_size < small_size:
if a_or_u:
self._se... | [
"def",
"_prune_all_if_small",
"(",
"self",
",",
"small_size",
",",
"a_or_u",
")",
":",
"\"Return True and delete children if small enough.\"",
"if",
"self",
".",
"_nodes",
"is",
"None",
":",
"return",
"True",
"total_size",
"=",
"(",
"self",
".",
"app_size",
"(",
... | Return True and delete children if small enough. | [
"Return",
"True",
"and",
"delete",
"children",
"if",
"small",
"enough",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L153-L166 | train |
ossobv/dutree | dutree/dutree.py | DuNode._prune_some_if_small | def _prune_some_if_small(self, small_size, a_or_u):
"Merge some nodes in the directory, whilst keeping others."
# Assert that we're not messing things up.
prev_app_size = self.app_size()
prev_use_size = self.use_size()
keep_nodes = []
prune_app_size = 0
prune_use... | python | def _prune_some_if_small(self, small_size, a_or_u):
"Merge some nodes in the directory, whilst keeping others."
# Assert that we're not messing things up.
prev_app_size = self.app_size()
prev_use_size = self.use_size()
keep_nodes = []
prune_app_size = 0
prune_use... | [
"def",
"_prune_some_if_small",
"(",
"self",
",",
"small_size",
",",
"a_or_u",
")",
":",
"\"Merge some nodes in the directory, whilst keeping others.\"",
"prev_app_size",
"=",
"self",
".",
"app_size",
"(",
")",
"prev_use_size",
"=",
"self",
".",
"use_size",
"(",
")",
... | Merge some nodes in the directory, whilst keeping others. | [
"Merge",
"some",
"nodes",
"in",
"the",
"directory",
"whilst",
"keeping",
"others",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L168-L215 | train |
ossobv/dutree | dutree/dutree.py | DuNode.merge_upwards_if_smaller_than | def merge_upwards_if_smaller_than(self, small_size, a_or_u):
"""After prune_if_smaller_than is run, we may still have excess
nodes.
For example, with a small_size of 609710690:
7 /*
28815419 /data/*
32 /data/srv/*
925746... | python | def merge_upwards_if_smaller_than(self, small_size, a_or_u):
"""After prune_if_smaller_than is run, we may still have excess
nodes.
For example, with a small_size of 609710690:
7 /*
28815419 /data/*
32 /data/srv/*
925746... | [
"def",
"merge_upwards_if_smaller_than",
"(",
"self",
",",
"small_size",
",",
"a_or_u",
")",
":",
"prev_app_size",
"=",
"self",
".",
"app_size",
"(",
")",
"prev_use_size",
"=",
"self",
".",
"use_size",
"(",
")",
"small_nodes",
"=",
"self",
".",
"_find_small_nod... | After prune_if_smaller_than is run, we may still have excess
nodes.
For example, with a small_size of 609710690:
7 /*
28815419 /data/*
32 /data/srv/*
925746 /data/srv/docker.bak/*
12 /data/srv/docker.bak/sh... | [
"After",
"prune_if_smaller_than",
"is",
"run",
"we",
"may",
"still",
"have",
"excess",
"nodes",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L217-L258 | train |
ossobv/dutree | dutree/dutree.py | DuNode.as_tree | def as_tree(self):
"Return the nodes as a list of lists."
if self._nodes is None:
return [self]
ret = [self]
for node in self._nodes:
ret.append(node.as_tree())
return ret | python | def as_tree(self):
"Return the nodes as a list of lists."
if self._nodes is None:
return [self]
ret = [self]
for node in self._nodes:
ret.append(node.as_tree())
return ret | [
"def",
"as_tree",
"(",
"self",
")",
":",
"\"Return the nodes as a list of lists.\"",
"if",
"self",
".",
"_nodes",
"is",
"None",
":",
"return",
"[",
"self",
"]",
"ret",
"=",
"[",
"self",
"]",
"for",
"node",
"in",
"self",
".",
"_nodes",
":",
"ret",
".",
... | Return the nodes as a list of lists. | [
"Return",
"the",
"nodes",
"as",
"a",
"list",
"of",
"lists",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L272-L279 | train |
ossobv/dutree | dutree/dutree.py | DuScan._check_path | def _check_path(self):
"Immediately check if we can access path. Otherwise bail."
if not path.isdir(self._path or '/'):
raise OSError('Path {!r} is not a directory'.format(self._path)) | python | def _check_path(self):
"Immediately check if we can access path. Otherwise bail."
if not path.isdir(self._path or '/'):
raise OSError('Path {!r} is not a directory'.format(self._path)) | [
"def",
"_check_path",
"(",
"self",
")",
":",
"\"Immediately check if we can access path. Otherwise bail.\"",
"if",
"not",
"path",
".",
"isdir",
"(",
"self",
".",
"_path",
"or",
"'/'",
")",
":",
"raise",
"OSError",
"(",
"'Path {!r} is not a directory'",
".",
"format"... | Immediately check if we can access path. Otherwise bail. | [
"Immediately",
"check",
"if",
"we",
"can",
"access",
"path",
".",
"Otherwise",
"bail",
"."
] | adceeeb17f9fd70a7ed9c674850d7015d820eb2a | https://github.com/ossobv/dutree/blob/adceeeb17f9fd70a7ed9c674850d7015d820eb2a/dutree/dutree.py#L320-L323 | train |
allonhadaya/dmenu-python | dmenu/dmenu.py | version | def version(command='dmenu'):
'''The dmenu command's version message.
Raises:
DmenuCommandError
Example:
>>> import dmenu
>>> dmenu.version()
'dmenu-4.5, \xc2\xa9 2006-2012 dmenu engineers, see LICENSE for details'
'''
args = [command, '-v']
try:
# st... | python | def version(command='dmenu'):
'''The dmenu command's version message.
Raises:
DmenuCommandError
Example:
>>> import dmenu
>>> dmenu.version()
'dmenu-4.5, \xc2\xa9 2006-2012 dmenu engineers, see LICENSE for details'
'''
args = [command, '-v']
try:
# st... | [
"def",
"version",
"(",
"command",
"=",
"'dmenu'",
")",
":",
"args",
"=",
"[",
"command",
",",
"'-v'",
"]",
"try",
":",
"proc",
"=",
"subprocess",
".",
"Popen",
"(",
"args",
",",
"universal_newlines",
"=",
"True",
",",
"stdout",
"=",
"subprocess",
".",
... | The dmenu command's version message.
Raises:
DmenuCommandError
Example:
>>> import dmenu
>>> dmenu.version()
'dmenu-4.5, \xc2\xa9 2006-2012 dmenu engineers, see LICENSE for details' | [
"The",
"dmenu",
"command",
"s",
"version",
"message",
"."
] | 30eca49a9368c61e13e87f530cc3785a369536c4 | https://github.com/allonhadaya/dmenu-python/blob/30eca49a9368c61e13e87f530cc3785a369536c4/dmenu/dmenu.py#L28-L59 | train |
allonhadaya/dmenu-python | dmenu/dmenu.py | show | def show(
items,
command='dmenu',
bottom=None,
fast=None,
case_insensitive=None,
lines=None,
monitor=None,
prompt=None,
font=None,
background=None,
foreground=None,
background_selected=None,
foreground_selected=None)... | python | def show(
items,
command='dmenu',
bottom=None,
fast=None,
case_insensitive=None,
lines=None,
monitor=None,
prompt=None,
font=None,
background=None,
foreground=None,
background_selected=None,
foreground_selected=None)... | [
"def",
"show",
"(",
"items",
",",
"command",
"=",
"'dmenu'",
",",
"bottom",
"=",
"None",
",",
"fast",
"=",
"None",
",",
"case_insensitive",
"=",
"None",
",",
"lines",
"=",
"None",
",",
"monitor",
"=",
"None",
",",
"prompt",
"=",
"None",
",",
"font",
... | Present a dmenu to the user.
Args:
items (Iterable[str]): defines the menu items being presented to the user. items should not contain the newline character.
command (Optional[str]): defines the path to the dmenu executable. Defaults to 'dmenu'.
bottom (Optional[bool]): dmenu appears at the... | [
"Present",
"a",
"dmenu",
"to",
"the",
"user",
"."
] | 30eca49a9368c61e13e87f530cc3785a369536c4 | https://github.com/allonhadaya/dmenu-python/blob/30eca49a9368c61e13e87f530cc3785a369536c4/dmenu/dmenu.py#L62-L206 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/filtered_network.py | FilteredNetwork.get_upregulated_genes_network | def get_upregulated_genes_network(self) -> Graph:
"""Get the graph of up-regulated genes.
:return Graph: Graph of up-regulated genes.
"""
logger.info("In get_upregulated_genes_network()")
deg_graph = self.graph.copy() # deep copy graph
not_diff_expr = self.graph.vs(up_... | python | def get_upregulated_genes_network(self) -> Graph:
"""Get the graph of up-regulated genes.
:return Graph: Graph of up-regulated genes.
"""
logger.info("In get_upregulated_genes_network()")
deg_graph = self.graph.copy() # deep copy graph
not_diff_expr = self.graph.vs(up_... | [
"def",
"get_upregulated_genes_network",
"(",
"self",
")",
"->",
"Graph",
":",
"logger",
".",
"info",
"(",
"\"In get_upregulated_genes_network()\"",
")",
"deg_graph",
"=",
"self",
".",
"graph",
".",
"copy",
"(",
")",
"not_diff_expr",
"=",
"self",
".",
"graph",
... | Get the graph of up-regulated genes.
:return Graph: Graph of up-regulated genes. | [
"Get",
"the",
"graph",
"of",
"up",
"-",
"regulated",
"genes",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/filtered_network.py#L27-L41 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/filtered_network.py | FilteredNetwork.get_downregulated_genes_network | def get_downregulated_genes_network(self) -> Graph:
"""Get the graph of down-regulated genes.
:return Graph: Graph of down-regulated genes.
"""
logger.info("In get_downregulated_genes_network()")
deg_graph = self.graph.copy() # deep copy graph
not_diff_expr = self.grap... | python | def get_downregulated_genes_network(self) -> Graph:
"""Get the graph of down-regulated genes.
:return Graph: Graph of down-regulated genes.
"""
logger.info("In get_downregulated_genes_network()")
deg_graph = self.graph.copy() # deep copy graph
not_diff_expr = self.grap... | [
"def",
"get_downregulated_genes_network",
"(",
"self",
")",
"->",
"Graph",
":",
"logger",
".",
"info",
"(",
"\"In get_downregulated_genes_network()\"",
")",
"deg_graph",
"=",
"self",
".",
"graph",
".",
"copy",
"(",
")",
"not_diff_expr",
"=",
"self",
".",
"graph"... | Get the graph of down-regulated genes.
:return Graph: Graph of down-regulated genes. | [
"Get",
"the",
"graph",
"of",
"down",
"-",
"regulated",
"genes",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/filtered_network.py#L43-L57 | train |
BernardFW/bernard | src/bernard/misc/main/_base.py | make_parser | def make_parser():
"""
Generate the parser for all sub-commands
"""
parser = argparse.ArgumentParser(description='BERNARD CLI utility')
sp = parser.add_subparsers(help='Sub-command')
parser_run = sp.add_parser('run', help='Run the BERNARD server')
parser_run.set_defaults(action='run')
... | python | def make_parser():
"""
Generate the parser for all sub-commands
"""
parser = argparse.ArgumentParser(description='BERNARD CLI utility')
sp = parser.add_subparsers(help='Sub-command')
parser_run = sp.add_parser('run', help='Run the BERNARD server')
parser_run.set_defaults(action='run')
... | [
"def",
"make_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'BERNARD CLI utility'",
")",
"sp",
"=",
"parser",
".",
"add_subparsers",
"(",
"help",
"=",
"'Sub-command'",
")",
"parser_run",
"=",
"sp",
".",
"a... | Generate the parser for all sub-commands | [
"Generate",
"the",
"parser",
"for",
"all",
"sub",
"-",
"commands"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/main/_base.py#L5-L55 | train |
BernardFW/bernard | src/bernard/misc/main/_base.py | main | def main():
"""
Run the appropriate main function according to the output of the parser.
"""
parser = make_parser()
args = parser.parse_args()
if not hasattr(args, 'action'):
parser.print_help()
exit(1)
if args.action == 'sheet':
from bernard.misc.sheet_sync import... | python | def main():
"""
Run the appropriate main function according to the output of the parser.
"""
parser = make_parser()
args = parser.parse_args()
if not hasattr(args, 'action'):
parser.print_help()
exit(1)
if args.action == 'sheet':
from bernard.misc.sheet_sync import... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"make_parser",
"(",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"if",
"not",
"hasattr",
"(",
"args",
",",
"'action'",
")",
":",
"parser",
".",
"print_help",
"(",
")",
"exit",
"(",
"1",
")",
... | Run the appropriate main function according to the output of the parser. | [
"Run",
"the",
"appropriate",
"main",
"function",
"according",
"to",
"the",
"output",
"of",
"the",
"parser",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/main/_base.py#L58-L78 | train |
sthysel/knobs | src/environment.py | load_dotenv | def load_dotenv(dotenv_path, verbose=False):
"""
Read a .env file and load into os.environ.
:param dotenv_path:
:type dotenv_path: str
:param verbose: verbosity flag, raise warning if path does not exist
:return: success flag
"""
if not os.path.exists(dotenv_path):
if verbose:
... | python | def load_dotenv(dotenv_path, verbose=False):
"""
Read a .env file and load into os.environ.
:param dotenv_path:
:type dotenv_path: str
:param verbose: verbosity flag, raise warning if path does not exist
:return: success flag
"""
if not os.path.exists(dotenv_path):
if verbose:
... | [
"def",
"load_dotenv",
"(",
"dotenv_path",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dotenv_path",
")",
":",
"if",
"verbose",
":",
"warnings",
".",
"warn",
"(",
"f\"Not loading {dotenv_path}, it doesn't exist.\... | Read a .env file and load into os.environ.
:param dotenv_path:
:type dotenv_path: str
:param verbose: verbosity flag, raise warning if path does not exist
:return: success flag | [
"Read",
"a",
".",
"env",
"file",
"and",
"load",
"into",
"os",
".",
"environ",
"."
] | 1d01f50f643068076e38118a93fed9375ea3ac81 | https://github.com/sthysel/knobs/blob/1d01f50f643068076e38118a93fed9375ea3ac81/src/environment.py#L20-L35 | train |
sthysel/knobs | src/environment.py | get_key | def get_key(dotenv_path, key_to_get, verbose=False):
"""
Gets the value of a given key from the given .env
If the .env path given doesn't exist, fails
:param dotenv_path: path
:param key_to_get: key
:param verbose: verbosity flag, raise warning if path does not exist
:return: value of varia... | python | def get_key(dotenv_path, key_to_get, verbose=False):
"""
Gets the value of a given key from the given .env
If the .env path given doesn't exist, fails
:param dotenv_path: path
:param key_to_get: key
:param verbose: verbosity flag, raise warning if path does not exist
:return: value of varia... | [
"def",
"get_key",
"(",
"dotenv_path",
",",
"key_to_get",
",",
"verbose",
"=",
"False",
")",
":",
"key_to_get",
"=",
"str",
"(",
"key_to_get",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dotenv_path",
")",
":",
"if",
"verbose",
":",
"warni... | Gets the value of a given key from the given .env
If the .env path given doesn't exist, fails
:param dotenv_path: path
:param key_to_get: key
:param verbose: verbosity flag, raise warning if path does not exist
:return: value of variable from environment file or None | [
"Gets",
"the",
"value",
"of",
"a",
"given",
"key",
"from",
"the",
"given",
".",
"env"
] | 1d01f50f643068076e38118a93fed9375ea3ac81 | https://github.com/sthysel/knobs/blob/1d01f50f643068076e38118a93fed9375ea3ac81/src/environment.py#L38-L59 | train |
sthysel/knobs | src/environment.py | _get_format | def _get_format(value, quote_mode='always'):
"""
Returns the quote format depending on the quote_mode.
This determines if the key value will be quoted when written to
the env file.
:param value:
:param quote_mode:
:return: str
:raises: KeyError if the quote_mode is unknown
"""
... | python | def _get_format(value, quote_mode='always'):
"""
Returns the quote format depending on the quote_mode.
This determines if the key value will be quoted when written to
the env file.
:param value:
:param quote_mode:
:return: str
:raises: KeyError if the quote_mode is unknown
"""
... | [
"def",
"_get_format",
"(",
"value",
",",
"quote_mode",
"=",
"'always'",
")",
":",
"formats",
"=",
"{",
"'always'",
":",
"'{key}=\"{value}\"\\n'",
",",
"'auto'",
":",
"'{key}={value}\\n'",
"}",
"if",
"quote_mode",
"not",
"in",
"formats",
".",
"keys",
"(",
")"... | Returns the quote format depending on the quote_mode.
This determines if the key value will be quoted when written to
the env file.
:param value:
:param quote_mode:
:return: str
:raises: KeyError if the quote_mode is unknown | [
"Returns",
"the",
"quote",
"format",
"depending",
"on",
"the",
"quote_mode",
".",
"This",
"determines",
"if",
"the",
"key",
"value",
"will",
"be",
"quoted",
"when",
"written",
"to",
"the",
"env",
"file",
"."
] | 1d01f50f643068076e38118a93fed9375ea3ac81 | https://github.com/sthysel/knobs/blob/1d01f50f643068076e38118a93fed9375ea3ac81/src/environment.py#L181-L201 | train |
sthysel/knobs | src/environment.py | find_dotenv | def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
"""
Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise
"""
if usecwd or '__file__' not in globals():
# should work without __file__, e.g. in ... | python | def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
"""
Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise
"""
if usecwd or '__file__' not in globals():
# should work without __file__, e.g. in ... | [
"def",
"find_dotenv",
"(",
"filename",
"=",
"'.env'",
",",
"raise_error_if_not_found",
"=",
"False",
",",
"usecwd",
"=",
"False",
")",
":",
"if",
"usecwd",
"or",
"'__file__'",
"not",
"in",
"globals",
"(",
")",
":",
"path",
"=",
"os",
".",
"getcwd",
"(",
... | Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise | [
"Search",
"in",
"increasingly",
"higher",
"folders",
"for",
"the",
"given",
"file"
] | 1d01f50f643068076e38118a93fed9375ea3ac81 | https://github.com/sthysel/knobs/blob/1d01f50f643068076e38118a93fed9375ea3ac81/src/environment.py#L237-L259 | train |
garenchan/policy | policy/_parser.py | reducer | def reducer(*tokens):
"""Decorator for reduction methods.
Arguments are a sequence of tokens, which should trigger running
this reduction method.
"""
def wrapper(func):
# Make sure that we have a list of reducer sequences
if not hasattr(func, 'reducers'):
func.reducers ... | python | def reducer(*tokens):
"""Decorator for reduction methods.
Arguments are a sequence of tokens, which should trigger running
this reduction method.
"""
def wrapper(func):
# Make sure that we have a list of reducer sequences
if not hasattr(func, 'reducers'):
func.reducers ... | [
"def",
"reducer",
"(",
"*",
"tokens",
")",
":",
"def",
"wrapper",
"(",
"func",
")",
":",
"if",
"not",
"hasattr",
"(",
"func",
",",
"'reducers'",
")",
":",
"func",
".",
"reducers",
"=",
"[",
"]",
"func",
".",
"reducers",
".",
"append",
"(",
"list",
... | Decorator for reduction methods.
Arguments are a sequence of tokens, which should trigger running
this reduction method. | [
"Decorator",
"for",
"reduction",
"methods",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L19-L36 | train |
garenchan/policy | policy/_parser.py | parse_rule | def parse_rule(rule: str, raise_error=False):
"""Parses policy to a tree of Check objects."""
parser = Parser(raise_error)
return parser.parse(rule) | python | def parse_rule(rule: str, raise_error=False):
"""Parses policy to a tree of Check objects."""
parser = Parser(raise_error)
return parser.parse(rule) | [
"def",
"parse_rule",
"(",
"rule",
":",
"str",
",",
"raise_error",
"=",
"False",
")",
":",
"parser",
"=",
"Parser",
"(",
"raise_error",
")",
"return",
"parser",
".",
"parse",
"(",
"rule",
")"
] | Parses policy to a tree of Check objects. | [
"Parses",
"policy",
"to",
"a",
"tree",
"of",
"Check",
"objects",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L269-L273 | train |
garenchan/policy | policy/_parser.py | Parser._reduce | def _reduce(self):
"""Perform a greedy reduction of token stream.
If a reducer method matches, it will be executed, then the
:meth:`reduce` method will be called recursively to search
for any more possible reductions.
"""
for reduction, methname in self.reducers:
... | python | def _reduce(self):
"""Perform a greedy reduction of token stream.
If a reducer method matches, it will be executed, then the
:meth:`reduce` method will be called recursively to search
for any more possible reductions.
"""
for reduction, methname in self.reducers:
... | [
"def",
"_reduce",
"(",
"self",
")",
":",
"for",
"reduction",
",",
"methname",
"in",
"self",
".",
"reducers",
":",
"token_num",
"=",
"len",
"(",
"reduction",
")",
"if",
"(",
"len",
"(",
"self",
".",
"tokens",
")",
">=",
"token_num",
"and",
"self",
"."... | Perform a greedy reduction of token stream.
If a reducer method matches, it will be executed, then the
:meth:`reduce` method will be called recursively to search
for any more possible reductions. | [
"Perform",
"a",
"greedy",
"reduction",
"of",
"token",
"stream",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L75-L97 | train |
garenchan/policy | policy/_parser.py | Parser._parse_check | def _parse_check(self, rule):
"""Parse a single base check rule into an appropriate Check object."""
# Handle the special constant-type checks
for check_cls in (checks.FalseCheck, checks.TrueCheck):
check = check_cls()
if rule == str(check):
return check
... | python | def _parse_check(self, rule):
"""Parse a single base check rule into an appropriate Check object."""
# Handle the special constant-type checks
for check_cls in (checks.FalseCheck, checks.TrueCheck):
check = check_cls()
if rule == str(check):
return check
... | [
"def",
"_parse_check",
"(",
"self",
",",
"rule",
")",
":",
"for",
"check_cls",
"in",
"(",
"checks",
".",
"FalseCheck",
",",
"checks",
".",
"TrueCheck",
")",
":",
"check",
"=",
"check_cls",
"(",
")",
"if",
"rule",
"==",
"str",
"(",
"check",
")",
":",
... | Parse a single base check rule into an appropriate Check object. | [
"Parse",
"a",
"single",
"base",
"check",
"rule",
"into",
"an",
"appropriate",
"Check",
"object",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L117-L145 | train |
garenchan/policy | policy/_parser.py | Parser._parse_tokenize | def _parse_tokenize(self, rule):
"""Tokenizer for the policy language."""
for token in self._TOKENIZE_RE.split(rule):
# Skip empty tokens
if not token or token.isspace():
continue
# Handle leading parens on the token
clean = token.lstrip(... | python | def _parse_tokenize(self, rule):
"""Tokenizer for the policy language."""
for token in self._TOKENIZE_RE.split(rule):
# Skip empty tokens
if not token or token.isspace():
continue
# Handle leading parens on the token
clean = token.lstrip(... | [
"def",
"_parse_tokenize",
"(",
"self",
",",
"rule",
")",
":",
"for",
"token",
"in",
"self",
".",
"_TOKENIZE_RE",
".",
"split",
"(",
"rule",
")",
":",
"if",
"not",
"token",
"or",
"token",
".",
"isspace",
"(",
")",
":",
"continue",
"clean",
"=",
"token... | Tokenizer for the policy language. | [
"Tokenizer",
"for",
"the",
"policy",
"language",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L147-L186 | train |
garenchan/policy | policy/_parser.py | Parser.parse | def parse(self, rule: str):
"""Parses policy to tree.
Translate a policy written in the policy language into a tree of
Check objects.
"""
# Empty rule means always accept
if not rule:
return checks.TrueCheck()
for token, value in self._parse_tokeniz... | python | def parse(self, rule: str):
"""Parses policy to tree.
Translate a policy written in the policy language into a tree of
Check objects.
"""
# Empty rule means always accept
if not rule:
return checks.TrueCheck()
for token, value in self._parse_tokeniz... | [
"def",
"parse",
"(",
"self",
",",
"rule",
":",
"str",
")",
":",
"if",
"not",
"rule",
":",
"return",
"checks",
".",
"TrueCheck",
"(",
")",
"for",
"token",
",",
"value",
"in",
"self",
".",
"_parse_tokenize",
"(",
"rule",
")",
":",
"self",
".",
"_shif... | Parses policy to tree.
Translate a policy written in the policy language into a tree of
Check objects. | [
"Parses",
"policy",
"to",
"tree",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L188-L207 | train |
garenchan/policy | policy/_parser.py | Parser._mix_or_and_expr | def _mix_or_and_expr(self, or_expr, _and, check):
"""Modify the case 'A or B and C'
AND operator's priority is higher than OR operator.
"""
or_expr, check1 = or_expr.pop_check()
if isinstance(check1, checks.AndCheck):
and_expr = check1
and_expr.add_check... | python | def _mix_or_and_expr(self, or_expr, _and, check):
"""Modify the case 'A or B and C'
AND operator's priority is higher than OR operator.
"""
or_expr, check1 = or_expr.pop_check()
if isinstance(check1, checks.AndCheck):
and_expr = check1
and_expr.add_check... | [
"def",
"_mix_or_and_expr",
"(",
"self",
",",
"or_expr",
",",
"_and",
",",
"check",
")",
":",
"or_expr",
",",
"check1",
"=",
"or_expr",
".",
"pop_check",
"(",
")",
"if",
"isinstance",
"(",
"check1",
",",
"checks",
".",
"AndCheck",
")",
":",
"and_expr",
... | Modify the case 'A or B and C'
AND operator's priority is higher than OR operator. | [
"Modify",
"the",
"case",
"A",
"or",
"B",
"and",
"C"
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_parser.py#L226-L238 | train |
inveniosoftware/invenio-query-parser | invenio_query_parser/utils.py | build_valid_keywords_grammar | def build_valid_keywords_grammar(keywords=None):
"""Update parser grammar to add a list of allowed keywords."""
from invenio_query_parser.parser import KeywordQuery, KeywordRule, \
NotKeywordValue, SimpleQuery, ValueQuery
if keywords:
KeywordRule.grammar = attr('value', re.compile(
... | python | def build_valid_keywords_grammar(keywords=None):
"""Update parser grammar to add a list of allowed keywords."""
from invenio_query_parser.parser import KeywordQuery, KeywordRule, \
NotKeywordValue, SimpleQuery, ValueQuery
if keywords:
KeywordRule.grammar = attr('value', re.compile(
... | [
"def",
"build_valid_keywords_grammar",
"(",
"keywords",
"=",
"None",
")",
":",
"from",
"invenio_query_parser",
".",
"parser",
"import",
"KeywordQuery",
",",
"KeywordRule",
",",
"NotKeywordValue",
",",
"SimpleQuery",
",",
"ValueQuery",
"if",
"keywords",
":",
"Keyword... | Update parser grammar to add a list of allowed keywords. | [
"Update",
"parser",
"grammar",
"to",
"add",
"a",
"list",
"of",
"allowed",
"keywords",
"."
] | 21a2c36318003ff52d2e18e7196bb420db8ecb4b | https://github.com/inveniosoftware/invenio-query-parser/blob/21a2c36318003ff52d2e18e7196bb420db8ecb4b/invenio_query_parser/utils.py#L34-L51 | train |
frostming/marko | marko/renderer.py | Renderer.render | def render(self, element):
"""Renders the given element to string.
:param element: a element to be rendered.
:returns: the output string or any values.
"""
# Store the root node to provide some context to render functions
if not self.root_node:
self.root_node... | python | def render(self, element):
"""Renders the given element to string.
:param element: a element to be rendered.
:returns: the output string or any values.
"""
# Store the root node to provide some context to render functions
if not self.root_node:
self.root_node... | [
"def",
"render",
"(",
"self",
",",
"element",
")",
":",
"if",
"not",
"self",
".",
"root_node",
":",
"self",
".",
"root_node",
"=",
"element",
"render_func",
"=",
"getattr",
"(",
"self",
",",
"self",
".",
"_cls_to_func_name",
"(",
"element",
".",
"__class... | Renders the given element to string.
:param element: a element to be rendered.
:returns: the output string or any values. | [
"Renders",
"the",
"given",
"element",
"to",
"string",
"."
] | 1cd030b665fa37bad1f8b3a25a89ce1a7c491dde | https://github.com/frostming/marko/blob/1cd030b665fa37bad1f8b3a25a89ce1a7c491dde/marko/renderer.py#L37-L50 | train |
frostming/marko | marko/renderer.py | Renderer.render_children | def render_children(self, element):
"""
Recursively renders child elements. Joins the rendered
strings with no space in between.
If newlines / spaces are needed between elements, add them
in their respective templates, or override this function
in the renderer subclass, ... | python | def render_children(self, element):
"""
Recursively renders child elements. Joins the rendered
strings with no space in between.
If newlines / spaces are needed between elements, add them
in their respective templates, or override this function
in the renderer subclass, ... | [
"def",
"render_children",
"(",
"self",
",",
"element",
")",
":",
"rendered",
"=",
"[",
"self",
".",
"render",
"(",
"child",
")",
"for",
"child",
"in",
"element",
".",
"children",
"]",
"return",
"''",
".",
"join",
"(",
"rendered",
")"
] | Recursively renders child elements. Joins the rendered
strings with no space in between.
If newlines / spaces are needed between elements, add them
in their respective templates, or override this function
in the renderer subclass, so that whitespace won't seem to
appear magicall... | [
"Recursively",
"renders",
"child",
"elements",
".",
"Joins",
"the",
"rendered",
"strings",
"with",
"no",
"space",
"in",
"between",
"."
] | 1cd030b665fa37bad1f8b3a25a89ce1a7c491dde | https://github.com/frostming/marko/blob/1cd030b665fa37bad1f8b3a25a89ce1a7c491dde/marko/renderer.py#L52-L65 | train |
jstitch/MambuPy | MambuPy/rest/mambuuser.py | MambuUser.setGroups | def setGroups(self, *args, **kwargs):
"""Adds the groups assigned to this user to a 'groups' field.
Returns the number of requests done to Mambu.
"""
try:
groups = self.mambugroupsclass(creditOfficerUsername=self['username'], *args, **kwargs)
except AttributeError as... | python | def setGroups(self, *args, **kwargs):
"""Adds the groups assigned to this user to a 'groups' field.
Returns the number of requests done to Mambu.
"""
try:
groups = self.mambugroupsclass(creditOfficerUsername=self['username'], *args, **kwargs)
except AttributeError as... | [
"def",
"setGroups",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"groups",
"=",
"self",
".",
"mambugroupsclass",
"(",
"creditOfficerUsername",
"=",
"self",
"[",
"'username'",
"]",
",",
"*",
"args",
",",
"**",
"kwargs",
")",... | Adds the groups assigned to this user to a 'groups' field.
Returns the number of requests done to Mambu. | [
"Adds",
"the",
"groups",
"assigned",
"to",
"this",
"user",
"to",
"a",
"groups",
"field",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuuser.py#L60-L73 | train |
jstitch/MambuPy | MambuPy/rest/mambuuser.py | MambuUser.setRoles | def setRoles(self, *args, **kwargs):
"""Adds the role assigned to this user to a 'role' field.
Depends on the 'role' field that comes with a fullDetails=True
build of the MambuUser.
Returns the number of requests done to Mambu.
"""
try:
role = self.mamburole... | python | def setRoles(self, *args, **kwargs):
"""Adds the role assigned to this user to a 'role' field.
Depends on the 'role' field that comes with a fullDetails=True
build of the MambuUser.
Returns the number of requests done to Mambu.
"""
try:
role = self.mamburole... | [
"def",
"setRoles",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"role",
"=",
"self",
".",
"mamburoleclass",
"(",
"entid",
"=",
"self",
"[",
"'role'",
"]",
"[",
"'encodedKey'",
"]",
",",
"*",
"args",
",",
"**",
"kwargs",... | Adds the role assigned to this user to a 'role' field.
Depends on the 'role' field that comes with a fullDetails=True
build of the MambuUser.
Returns the number of requests done to Mambu. | [
"Adds",
"the",
"role",
"assigned",
"to",
"this",
"user",
"to",
"a",
"role",
"field",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuuser.py#L76-L97 | train |
jstitch/MambuPy | MambuPy/rest/mambuuser.py | MambuUser.create | def create(self, data, *args, **kwargs):
"""Creates an user in Mambu
Parameters
-data dictionary with data to send
"""
super(MambuUser, self).create(data)
self['user'][self.customFieldName] = self['customInformation']
self.init(attrs=self['user']) | python | def create(self, data, *args, **kwargs):
"""Creates an user in Mambu
Parameters
-data dictionary with data to send
"""
super(MambuUser, self).create(data)
self['user'][self.customFieldName] = self['customInformation']
self.init(attrs=self['user']) | [
"def",
"create",
"(",
"self",
",",
"data",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"super",
"(",
"MambuUser",
",",
"self",
")",
".",
"create",
"(",
"data",
")",
"self",
"[",
"'user'",
"]",
"[",
"self",
".",
"customFieldName",
"]",
"=",
"... | Creates an user in Mambu
Parameters
-data dictionary with data to send | [
"Creates",
"an",
"user",
"in",
"Mambu"
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/rest/mambuuser.py#L100-L109 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork.write_attribute_adj_list | def write_attribute_adj_list(self, path):
"""Write the bipartite attribute graph to a file.
:param str path: Path to the output file.
"""
att_mappings = self.get_attribute_mappings()
with open(path, mode="w") as file:
for k, v in att_mappings.items():
... | python | def write_attribute_adj_list(self, path):
"""Write the bipartite attribute graph to a file.
:param str path: Path to the output file.
"""
att_mappings = self.get_attribute_mappings()
with open(path, mode="w") as file:
for k, v in att_mappings.items():
... | [
"def",
"write_attribute_adj_list",
"(",
"self",
",",
"path",
")",
":",
"att_mappings",
"=",
"self",
".",
"get_attribute_mappings",
"(",
")",
"with",
"open",
"(",
"path",
",",
"mode",
"=",
"\"w\"",
")",
"as",
"file",
":",
"for",
"k",
",",
"v",
"in",
"at... | Write the bipartite attribute graph to a file.
:param str path: Path to the output file. | [
"Write",
"the",
"bipartite",
"attribute",
"graph",
"to",
"a",
"file",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L25-L34 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork.get_attribute_mappings | def get_attribute_mappings(self):
"""Get a dictionary of mappings between vertices and enumerated attributes.
:return: Dictionary of mappings between vertices and enumerated attributes.
"""
att_ind_start = len(self.graph.vs)
att_mappings = defaultdict(list)
att_ind_end =... | python | def get_attribute_mappings(self):
"""Get a dictionary of mappings between vertices and enumerated attributes.
:return: Dictionary of mappings between vertices and enumerated attributes.
"""
att_ind_start = len(self.graph.vs)
att_mappings = defaultdict(list)
att_ind_end =... | [
"def",
"get_attribute_mappings",
"(",
"self",
")",
":",
"att_ind_start",
"=",
"len",
"(",
"self",
".",
"graph",
".",
"vs",
")",
"att_mappings",
"=",
"defaultdict",
"(",
"list",
")",
"att_ind_end",
"=",
"self",
".",
"_add_differential_expression_attributes",
"(",... | Get a dictionary of mappings between vertices and enumerated attributes.
:return: Dictionary of mappings between vertices and enumerated attributes. | [
"Get",
"a",
"dictionary",
"of",
"mappings",
"between",
"vertices",
"and",
"enumerated",
"attributes",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L36-L46 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork._add_differential_expression_attributes | def _add_differential_expression_attributes(self, att_ind_start, att_mappings):
"""Add differential expression information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices... | python | def _add_differential_expression_attributes(self, att_ind_start, att_mappings):
"""Add differential expression information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices... | [
"def",
"_add_differential_expression_attributes",
"(",
"self",
",",
"att_ind_start",
",",
"att_mappings",
")",
":",
"up_regulated_ind",
"=",
"self",
".",
"graph",
".",
"vs",
".",
"select",
"(",
"up_regulated_eq",
"=",
"True",
")",
".",
"indices",
"down_regulated_i... | Add differential expression information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices and enumerated attributes.
:return: End index for attribute enumeration. | [
"Add",
"differential",
"expression",
"information",
"to",
"the",
"attribute",
"mapping",
"dictionary",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L48-L62 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork._add_attribute_values | def _add_attribute_values(self, value, att_mappings, indices):
"""Add an attribute value to the given vertices.
:param int value: Attribute value.
:param dict att_mappings: Dictionary of mappings between vertices and enumerated attributes.
:param list indices: Indices of the vertices.
... | python | def _add_attribute_values(self, value, att_mappings, indices):
"""Add an attribute value to the given vertices.
:param int value: Attribute value.
:param dict att_mappings: Dictionary of mappings between vertices and enumerated attributes.
:param list indices: Indices of the vertices.
... | [
"def",
"_add_attribute_values",
"(",
"self",
",",
"value",
",",
"att_mappings",
",",
"indices",
")",
":",
"for",
"i",
"in",
"indices",
":",
"att_mappings",
"[",
"i",
"]",
".",
"append",
"(",
"value",
")"
] | Add an attribute value to the given vertices.
:param int value: Attribute value.
:param dict att_mappings: Dictionary of mappings between vertices and enumerated attributes.
:param list indices: Indices of the vertices. | [
"Add",
"an",
"attribute",
"value",
"to",
"the",
"given",
"vertices",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L64-L72 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork._add_disease_association_attributes | def _add_disease_association_attributes(self, att_ind_start, att_mappings):
"""Add disease association information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices and enu... | python | def _add_disease_association_attributes(self, att_ind_start, att_mappings):
"""Add disease association information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices and enu... | [
"def",
"_add_disease_association_attributes",
"(",
"self",
",",
"att_ind_start",
",",
"att_mappings",
")",
":",
"disease_mappings",
"=",
"self",
".",
"get_disease_mappings",
"(",
"att_ind_start",
")",
"for",
"vertex",
"in",
"self",
".",
"graph",
".",
"vs",
":",
... | Add disease association information to the attribute mapping dictionary.
:param int att_ind_start: Start index for enumerating the attributes.
:param dict att_mappings: Dictionary of mappings between vertices and enumerated attributes. | [
"Add",
"disease",
"association",
"information",
"to",
"the",
"attribute",
"mapping",
"dictionary",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L74-L85 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork.get_disease_mappings | def get_disease_mappings(self, att_ind_start):
"""Get a dictionary of enumerations for diseases.
:param int att_ind_start: Starting index for enumeration.
:return: Dictionary of disease, number pairs.
"""
all_disease_ids = self.get_all_unique_diseases()
disease_enum = en... | python | def get_disease_mappings(self, att_ind_start):
"""Get a dictionary of enumerations for diseases.
:param int att_ind_start: Starting index for enumeration.
:return: Dictionary of disease, number pairs.
"""
all_disease_ids = self.get_all_unique_diseases()
disease_enum = en... | [
"def",
"get_disease_mappings",
"(",
"self",
",",
"att_ind_start",
")",
":",
"all_disease_ids",
"=",
"self",
".",
"get_all_unique_diseases",
"(",
")",
"disease_enum",
"=",
"enumerate",
"(",
"all_disease_ids",
",",
"start",
"=",
"att_ind_start",
")",
"disease_mappings... | Get a dictionary of enumerations for diseases.
:param int att_ind_start: Starting index for enumeration.
:return: Dictionary of disease, number pairs. | [
"Get",
"a",
"dictionary",
"of",
"enumerations",
"for",
"diseases",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L87-L98 | train |
GuiltyTargets/ppi-network-annotation | src/ppi_network_annotation/model/attribute_network.py | AttributeNetwork.get_all_unique_diseases | def get_all_unique_diseases(self):
"""Get all unique diseases that are known to the network.
:return: All unique disease identifiers.
"""
all_disease_ids = self.graph.vs["associated_diseases"]
# remove None values from list
all_disease_ids = [lst for lst in all_disease_i... | python | def get_all_unique_diseases(self):
"""Get all unique diseases that are known to the network.
:return: All unique disease identifiers.
"""
all_disease_ids = self.graph.vs["associated_diseases"]
# remove None values from list
all_disease_ids = [lst for lst in all_disease_i... | [
"def",
"get_all_unique_diseases",
"(",
"self",
")",
":",
"all_disease_ids",
"=",
"self",
".",
"graph",
".",
"vs",
"[",
"\"associated_diseases\"",
"]",
"all_disease_ids",
"=",
"[",
"lst",
"for",
"lst",
"in",
"all_disease_ids",
"if",
"lst",
"is",
"not",
"None",
... | Get all unique diseases that are known to the network.
:return: All unique disease identifiers. | [
"Get",
"all",
"unique",
"diseases",
"that",
"are",
"known",
"to",
"the",
"network",
"."
] | 4d7b6713485f2d0a0957e6457edc1b1b5a237460 | https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/model/attribute_network.py#L100-L110 | train |
BernardFW/bernard | src/bernard/analytics/_helpers.py | page_view | def page_view(url):
"""
Page view decorator.
Put that around a state handler function in order to log a page view each
time the handler gets called.
:param url: simili-URL that you want to give to the state
"""
def decorator(func):
@wraps(func)
async def wrapper(self: Base... | python | def page_view(url):
"""
Page view decorator.
Put that around a state handler function in order to log a page view each
time the handler gets called.
:param url: simili-URL that you want to give to the state
"""
def decorator(func):
@wraps(func)
async def wrapper(self: Base... | [
"def",
"page_view",
"(",
"url",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"async",
"def",
"wrapper",
"(",
"self",
":",
"BaseState",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"user_id",
"=",
"self",
... | Page view decorator.
Put that around a state handler function in order to log a page view each
time the handler gets called.
:param url: simili-URL that you want to give to the state | [
"Page",
"view",
"decorator",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/analytics/_helpers.py#L14-L42 | train |
pyQode/pyqode.cobol | pyqode/cobol/api/parsers/pic.py | parse_cobol | def parse_cobol(lines):
"""
Parses the COBOL
- converts the COBOL line into a dictionary containing the information
- parses the pic information into type, length, precision
- ~~handles redefines~~ -> our implementation does not do that anymore
because we want to display item that was rede... | python | def parse_cobol(lines):
"""
Parses the COBOL
- converts the COBOL line into a dictionary containing the information
- parses the pic information into type, length, precision
- ~~handles redefines~~ -> our implementation does not do that anymore
because we want to display item that was rede... | [
"def",
"parse_cobol",
"(",
"lines",
")",
":",
"output",
"=",
"[",
"]",
"intify",
"=",
"[",
"\"level\"",
",",
"\"occurs\"",
"]",
"for",
"row",
"in",
"lines",
":",
"match",
"=",
"CobolPatterns",
".",
"row_pattern",
".",
"match",
"(",
"row",
".",
"strip",... | Parses the COBOL
- converts the COBOL line into a dictionary containing the information
- parses the pic information into type, length, precision
- ~~handles redefines~~ -> our implementation does not do that anymore
because we want to display item that was redefined. | [
"Parses",
"the",
"COBOL",
"-",
"converts",
"the",
"COBOL",
"line",
"into",
"a",
"dictionary",
"containing",
"the",
"information",
"-",
"parses",
"the",
"pic",
"information",
"into",
"type",
"length",
"precision",
"-",
"~~handles",
"redefines~~",
"-",
">",
"our... | eedae4e320a4b2d0c44abb2c3061091321648fb7 | https://github.com/pyQode/pyqode.cobol/blob/eedae4e320a4b2d0c44abb2c3061091321648fb7/pyqode/cobol/api/parsers/pic.py#L114-L143 | train |
pyQode/pyqode.cobol | pyqode/cobol/api/parsers/pic.py | clean_names | def clean_names(lines, ensure_unique_names=False, strip_prefix=False,
make_database_safe=False):
"""
Clean the names.
Options to:
- strip prefixes on names
- enforce unique names
- make database safe names by converting - to _
"""
names = {}
for row in lines:
... | python | def clean_names(lines, ensure_unique_names=False, strip_prefix=False,
make_database_safe=False):
"""
Clean the names.
Options to:
- strip prefixes on names
- enforce unique names
- make database safe names by converting - to _
"""
names = {}
for row in lines:
... | [
"def",
"clean_names",
"(",
"lines",
",",
"ensure_unique_names",
"=",
"False",
",",
"strip_prefix",
"=",
"False",
",",
"make_database_safe",
"=",
"False",
")",
":",
"names",
"=",
"{",
"}",
"for",
"row",
"in",
"lines",
":",
"if",
"strip_prefix",
":",
"row",
... | Clean the names.
Options to:
- strip prefixes on names
- enforce unique names
- make database safe names by converting - to _ | [
"Clean",
"the",
"names",
"."
] | eedae4e320a4b2d0c44abb2c3061091321648fb7 | https://github.com/pyQode/pyqode.cobol/blob/eedae4e320a4b2d0c44abb2c3061091321648fb7/pyqode/cobol/api/parsers/pic.py#L230-L263 | train |
ikalnytskyi/holocron | src/holocron/__main__.py | create_app_from_yml | def create_app_from_yml(path):
"""Return an application instance created from YAML."""
try:
with open(path, "rt", encoding="UTF-8") as f:
try:
# Substitute ALL occurrences of '%(here)s' with a path to a
# directory with '.holocron.yml'. Please note, we also w... | python | def create_app_from_yml(path):
"""Return an application instance created from YAML."""
try:
with open(path, "rt", encoding="UTF-8") as f:
try:
# Substitute ALL occurrences of '%(here)s' with a path to a
# directory with '.holocron.yml'. Please note, we also w... | [
"def",
"create_app_from_yml",
"(",
"path",
")",
":",
"try",
":",
"with",
"open",
"(",
"path",
",",
"\"rt\"",
",",
"encoding",
"=",
"\"UTF-8\"",
")",
"as",
"f",
":",
"try",
":",
"interpolated",
"=",
"io",
".",
"StringIO",
"(",
"f",
".",
"read",
"(",
... | Return an application instance created from YAML. | [
"Return",
"an",
"application",
"instance",
"created",
"from",
"YAML",
"."
] | d202f6bccfeca64162857c6d0ee5bb53e773d2f2 | https://github.com/ikalnytskyi/holocron/blob/d202f6bccfeca64162857c6d0ee5bb53e773d2f2/src/holocron/__main__.py#L18-L40 | train |
ikalnytskyi/holocron | src/holocron/__main__.py | configure_logger | def configure_logger(level):
"""
Configure a root logger to print records in pretty format.
The format is more readable for end users, since it's not necessary at
all to know a record's dateime and a source of the record.
Examples::
[INFO] message
[WARN] message
[ERRO] mes... | python | def configure_logger(level):
"""
Configure a root logger to print records in pretty format.
The format is more readable for end users, since it's not necessary at
all to know a record's dateime and a source of the record.
Examples::
[INFO] message
[WARN] message
[ERRO] mes... | [
"def",
"configure_logger",
"(",
"level",
")",
":",
"class",
"_Formatter",
"(",
"logging",
".",
"Formatter",
")",
":",
"def",
"format",
"(",
"self",
",",
"record",
")",
":",
"record",
".",
"levelname",
"=",
"record",
".",
"levelname",
"[",
":",
"4",
"]"... | Configure a root logger to print records in pretty format.
The format is more readable for end users, since it's not necessary at
all to know a record's dateime and a source of the record.
Examples::
[INFO] message
[WARN] message
[ERRO] message
:param level: a minimum logging... | [
"Configure",
"a",
"root",
"logger",
"to",
"print",
"records",
"in",
"pretty",
"format",
"."
] | d202f6bccfeca64162857c6d0ee5bb53e773d2f2 | https://github.com/ikalnytskyi/holocron/blob/d202f6bccfeca64162857c6d0ee5bb53e773d2f2/src/holocron/__main__.py#L43-L73 | train |
ikalnytskyi/holocron | src/holocron/__main__.py | parse_command_line | def parse_command_line(args):
"""
Builds a command line interface, and parses its arguments. Returns
an object with attributes, that are represent CLI arguments.
:param args: a list of command line arguments
:returns: a parsed object with cli options
"""
parser = argparse.ArgumentParser(
... | python | def parse_command_line(args):
"""
Builds a command line interface, and parses its arguments. Returns
an object with attributes, that are represent CLI arguments.
:param args: a list of command line arguments
:returns: a parsed object with cli options
"""
parser = argparse.ArgumentParser(
... | [
"def",
"parse_command_line",
"(",
"args",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Holocron is an easy and lightweight static blog generator, \"",
"\"based on markup text and Jinja2 templates.\"",
")",
",",
"epilog",
"=",
... | Builds a command line interface, and parses its arguments. Returns
an object with attributes, that are represent CLI arguments.
:param args: a list of command line arguments
:returns: a parsed object with cli options | [
"Builds",
"a",
"command",
"line",
"interface",
"and",
"parses",
"its",
"arguments",
".",
"Returns",
"an",
"object",
"with",
"attributes",
"that",
"are",
"represent",
"CLI",
"arguments",
"."
] | d202f6bccfeca64162857c6d0ee5bb53e773d2f2 | https://github.com/ikalnytskyi/holocron/blob/d202f6bccfeca64162857c6d0ee5bb53e773d2f2/src/holocron/__main__.py#L76-L127 | train |
BernardFW/bernard | src/bernard/cli/_live_reload.py | _list_syntax_error | def _list_syntax_error():
"""
If we're going through a syntax error, add the directory of the error to
the watchlist.
"""
_, e, _ = sys.exc_info()
if isinstance(e, SyntaxError) and hasattr(e, 'filename'):
yield path.dirname(e.filename) | python | def _list_syntax_error():
"""
If we're going through a syntax error, add the directory of the error to
the watchlist.
"""
_, e, _ = sys.exc_info()
if isinstance(e, SyntaxError) and hasattr(e, 'filename'):
yield path.dirname(e.filename) | [
"def",
"_list_syntax_error",
"(",
")",
":",
"_",
",",
"e",
",",
"_",
"=",
"sys",
".",
"exc_info",
"(",
")",
"if",
"isinstance",
"(",
"e",
",",
"SyntaxError",
")",
"and",
"hasattr",
"(",
"e",
",",
"'filename'",
")",
":",
"yield",
"path",
".",
"dirna... | If we're going through a syntax error, add the directory of the error to
the watchlist. | [
"If",
"we",
"re",
"going",
"through",
"a",
"syntax",
"error",
"add",
"the",
"directory",
"of",
"the",
"error",
"to",
"the",
"watchlist",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/cli/_live_reload.py#L51-L59 | train |
BernardFW/bernard | src/bernard/cli/_live_reload.py | list_dirs | def list_dirs():
"""
List all directories known to hold project code.
"""
out = set()
out.update(_list_config_dirs())
out.update(_list_module_dirs())
out.update(_list_syntax_error())
return out | python | def list_dirs():
"""
List all directories known to hold project code.
"""
out = set()
out.update(_list_config_dirs())
out.update(_list_module_dirs())
out.update(_list_syntax_error())
return out | [
"def",
"list_dirs",
"(",
")",
":",
"out",
"=",
"set",
"(",
")",
"out",
".",
"update",
"(",
"_list_config_dirs",
"(",
")",
")",
"out",
".",
"update",
"(",
"_list_module_dirs",
"(",
")",
")",
"out",
".",
"update",
"(",
"_list_syntax_error",
"(",
")",
"... | List all directories known to hold project code. | [
"List",
"all",
"directories",
"known",
"to",
"hold",
"project",
"code",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/cli/_live_reload.py#L62-L71 | train |
BernardFW/bernard | src/bernard/cli/_live_reload.py | start_child | async def start_child():
"""
Start the child process that will look for changes in modules.
"""
logger.info('Started to watch for code changes')
loop = asyncio.get_event_loop()
watcher = aionotify.Watcher()
flags = (
aionotify.Flags.MODIFY |
aionotify.Flags.DELETE |
... | python | async def start_child():
"""
Start the child process that will look for changes in modules.
"""
logger.info('Started to watch for code changes')
loop = asyncio.get_event_loop()
watcher = aionotify.Watcher()
flags = (
aionotify.Flags.MODIFY |
aionotify.Flags.DELETE |
... | [
"async",
"def",
"start_child",
"(",
")",
":",
"logger",
".",
"info",
"(",
"'Started to watch for code changes'",
")",
"loop",
"=",
"asyncio",
".",
"get_event_loop",
"(",
")",
"watcher",
"=",
"aionotify",
".",
"Watcher",
"(",
")",
"flags",
"=",
"(",
"aionotif... | Start the child process that will look for changes in modules. | [
"Start",
"the",
"child",
"process",
"that",
"will",
"look",
"for",
"changes",
"in",
"modules",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/cli/_live_reload.py#L83-L120 | train |
BernardFW/bernard | src/bernard/cli/_live_reload.py | start_parent | def start_parent():
"""
Start the parent that will simply run the child forever until stopped.
"""
while True:
args = [sys.executable] + sys.argv
new_environ = environ.copy()
new_environ["_IN_CHILD"] = 'yes'
ret = subprocess.call(args, env=new_environ)
if ret !=... | python | def start_parent():
"""
Start the parent that will simply run the child forever until stopped.
"""
while True:
args = [sys.executable] + sys.argv
new_environ = environ.copy()
new_environ["_IN_CHILD"] = 'yes'
ret = subprocess.call(args, env=new_environ)
if ret !=... | [
"def",
"start_parent",
"(",
")",
":",
"while",
"True",
":",
"args",
"=",
"[",
"sys",
".",
"executable",
"]",
"+",
"sys",
".",
"argv",
"new_environ",
"=",
"environ",
".",
"copy",
"(",
")",
"new_environ",
"[",
"\"_IN_CHILD\"",
"]",
"=",
"'yes'",
"ret",
... | Start the parent that will simply run the child forever until stopped. | [
"Start",
"the",
"parent",
"that",
"will",
"simply",
"run",
"the",
"child",
"forever",
"until",
"stopped",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/cli/_live_reload.py#L123-L135 | train |
jpscaletti/authcode | authcode/wsgi/werkzeug.py | get_from_params | def get_from_params(request, key):
"""Try to read a value named ``key`` from the GET parameters.
"""
data = getattr(request, 'json', None) or request.values
value = data.get(key)
return to_native(value) | python | def get_from_params(request, key):
"""Try to read a value named ``key`` from the GET parameters.
"""
data = getattr(request, 'json', None) or request.values
value = data.get(key)
return to_native(value) | [
"def",
"get_from_params",
"(",
"request",
",",
"key",
")",
":",
"data",
"=",
"getattr",
"(",
"request",
",",
"'json'",
",",
"None",
")",
"or",
"request",
".",
"values",
"value",
"=",
"data",
".",
"get",
"(",
"key",
")",
"return",
"to_native",
"(",
"v... | Try to read a value named ``key`` from the GET parameters. | [
"Try",
"to",
"read",
"a",
"value",
"named",
"key",
"from",
"the",
"GET",
"parameters",
"."
] | 91529b6d0caec07d1452758d937e1e0745826139 | https://github.com/jpscaletti/authcode/blob/91529b6d0caec07d1452758d937e1e0745826139/authcode/wsgi/werkzeug.py#L55-L60 | train |
jpscaletti/authcode | authcode/wsgi/werkzeug.py | get_from_headers | def get_from_headers(request, key):
"""Try to read a value named ``key`` from the headers.
"""
value = request.headers.get(key)
return to_native(value) | python | def get_from_headers(request, key):
"""Try to read a value named ``key`` from the headers.
"""
value = request.headers.get(key)
return to_native(value) | [
"def",
"get_from_headers",
"(",
"request",
",",
"key",
")",
":",
"value",
"=",
"request",
".",
"headers",
".",
"get",
"(",
"key",
")",
"return",
"to_native",
"(",
"value",
")"
] | Try to read a value named ``key`` from the headers. | [
"Try",
"to",
"read",
"a",
"value",
"named",
"key",
"from",
"the",
"headers",
"."
] | 91529b6d0caec07d1452758d937e1e0745826139 | https://github.com/jpscaletti/authcode/blob/91529b6d0caec07d1452758d937e1e0745826139/authcode/wsgi/werkzeug.py#L63-L67 | train |
BernardFW/bernard | src/bernard/storage/redis.py | BaseRedisStore.async_init | async def async_init(self):
"""
Handle here the asynchronous part of the init.
"""
self.pool = await aioredis.create_pool(
(self.host, self.port),
db=self.db_id,
minsize=self.min_pool_size,
maxsize=self.max_pool_size,
loop=asyn... | python | async def async_init(self):
"""
Handle here the asynchronous part of the init.
"""
self.pool = await aioredis.create_pool(
(self.host, self.port),
db=self.db_id,
minsize=self.min_pool_size,
maxsize=self.max_pool_size,
loop=asyn... | [
"async",
"def",
"async_init",
"(",
"self",
")",
":",
"self",
".",
"pool",
"=",
"await",
"aioredis",
".",
"create_pool",
"(",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
")",
",",
"db",
"=",
"self",
".",
"db_id",
",",
"minsize",
"=",
"self",... | Handle here the asynchronous part of the init. | [
"Handle",
"here",
"the",
"asynchronous",
"part",
"of",
"the",
"init",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/storage/redis.py#L41-L52 | train |
rsgalloway/grit | grit/util/util.py | serialize | def serialize(d):
"""
Attempts to serialize values from a dictionary,
skipping private attrs.
:param d: A dictionary of params to serialize,
typically cls.__dict__
"""
ret = {}
for k,v in d.items():
if not k.startswith('_'):
ret[k] = str(d[k])
#ret['__c... | python | def serialize(d):
"""
Attempts to serialize values from a dictionary,
skipping private attrs.
:param d: A dictionary of params to serialize,
typically cls.__dict__
"""
ret = {}
for k,v in d.items():
if not k.startswith('_'):
ret[k] = str(d[k])
#ret['__c... | [
"def",
"serialize",
"(",
"d",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"d",
".",
"items",
"(",
")",
":",
"if",
"not",
"k",
".",
"startswith",
"(",
"'_'",
")",
":",
"ret",
"[",
"k",
"]",
"=",
"str",
"(",
"d",
"[",
"k",
... | Attempts to serialize values from a dictionary,
skipping private attrs.
:param d: A dictionary of params to serialize,
typically cls.__dict__ | [
"Attempts",
"to",
"serialize",
"values",
"from",
"a",
"dictionary",
"skipping",
"private",
"attrs",
"."
] | e6434ad8a1f4ac5d0903ebad630c81f8a5164d78 | https://github.com/rsgalloway/grit/blob/e6434ad8a1f4ac5d0903ebad630c81f8a5164d78/grit/util/util.py#L31-L44 | train |
rsgalloway/grit | grit/util/util.py | user_config | def user_config(**kwargs):
"""
Initialize Git user config file.
:param kwargs: key/value pairs are stored in the git user config file.
"""
for kw in kwargs:
git('config --global user.%s "%s"' %(kw, kwargs.get(kw))).wait() | python | def user_config(**kwargs):
"""
Initialize Git user config file.
:param kwargs: key/value pairs are stored in the git user config file.
"""
for kw in kwargs:
git('config --global user.%s "%s"' %(kw, kwargs.get(kw))).wait() | [
"def",
"user_config",
"(",
"**",
"kwargs",
")",
":",
"for",
"kw",
"in",
"kwargs",
":",
"git",
"(",
"'config --global user.%s \"%s\"'",
"%",
"(",
"kw",
",",
"kwargs",
".",
"get",
"(",
"kw",
")",
")",
")",
".",
"wait",
"(",
")"
] | Initialize Git user config file.
:param kwargs: key/value pairs are stored in the git user config file. | [
"Initialize",
"Git",
"user",
"config",
"file",
"."
] | e6434ad8a1f4ac5d0903ebad630c81f8a5164d78 | https://github.com/rsgalloway/grit/blob/e6434ad8a1f4ac5d0903ebad630c81f8a5164d78/grit/util/util.py#L51-L58 | train |
blockstack-packages/jsontokens-py | jsontokens/token_signer.py | TokenSigner._make_header | def _make_header(self, token_type=None, signing_algorithm=None):
"""
Make a JWT header
"""
if not token_type:
token_type = self.token_type
if not signing_algorithm:
signing_algorithm = self.signing_algorithm
header = {'typ': token_type, 'alg': si... | python | def _make_header(self, token_type=None, signing_algorithm=None):
"""
Make a JWT header
"""
if not token_type:
token_type = self.token_type
if not signing_algorithm:
signing_algorithm = self.signing_algorithm
header = {'typ': token_type, 'alg': si... | [
"def",
"_make_header",
"(",
"self",
",",
"token_type",
"=",
"None",
",",
"signing_algorithm",
"=",
"None",
")",
":",
"if",
"not",
"token_type",
":",
"token_type",
"=",
"self",
".",
"token_type",
"if",
"not",
"signing_algorithm",
":",
"signing_algorithm",
"=",
... | Make a JWT header | [
"Make",
"a",
"JWT",
"header"
] | 1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3 | https://github.com/blockstack-packages/jsontokens-py/blob/1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3/jsontokens/token_signer.py#L38-L49 | train |
blockstack-packages/jsontokens-py | jsontokens/token_signer.py | TokenSigner._make_signature | def _make_signature(self, header_b64, payload_b64, signing_key):
"""
Sign a serialized header and payload.
Return the urlsafe-base64-encoded signature.
"""
token_segments = [header_b64, payload_b64]
signing_input = b'.'.join(token_segments)
signer = self._get_sig... | python | def _make_signature(self, header_b64, payload_b64, signing_key):
"""
Sign a serialized header and payload.
Return the urlsafe-base64-encoded signature.
"""
token_segments = [header_b64, payload_b64]
signing_input = b'.'.join(token_segments)
signer = self._get_sig... | [
"def",
"_make_signature",
"(",
"self",
",",
"header_b64",
",",
"payload_b64",
",",
"signing_key",
")",
":",
"token_segments",
"=",
"[",
"header_b64",
",",
"payload_b64",
"]",
"signing_input",
"=",
"b'.'",
".",
"join",
"(",
"token_segments",
")",
"signer",
"=",... | Sign a serialized header and payload.
Return the urlsafe-base64-encoded signature. | [
"Sign",
"a",
"serialized",
"header",
"and",
"payload",
".",
"Return",
"the",
"urlsafe",
"-",
"base64",
"-",
"encoded",
"signature",
"."
] | 1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3 | https://github.com/blockstack-packages/jsontokens-py/blob/1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3/jsontokens/token_signer.py#L52-L65 | train |
blockstack-packages/jsontokens-py | jsontokens/token_signer.py | TokenSigner._sign_multi | def _sign_multi(self, payload, signing_keys):
"""
Make a multi-signature JWT.
Returns a JSON-structured JWT.
TODO: support multiple types of signatures
"""
if not isinstance(payload, Mapping):
raise TypeError('Expecting a mapping object, as only '
... | python | def _sign_multi(self, payload, signing_keys):
"""
Make a multi-signature JWT.
Returns a JSON-structured JWT.
TODO: support multiple types of signatures
"""
if not isinstance(payload, Mapping):
raise TypeError('Expecting a mapping object, as only '
... | [
"def",
"_sign_multi",
"(",
"self",
",",
"payload",
",",
"signing_keys",
")",
":",
"if",
"not",
"isinstance",
"(",
"payload",
",",
"Mapping",
")",
":",
"raise",
"TypeError",
"(",
"'Expecting a mapping object, as only '",
"'JSON objects can be used as payloads.'",
")",
... | Make a multi-signature JWT.
Returns a JSON-structured JWT.
TODO: support multiple types of signatures | [
"Make",
"a",
"multi",
"-",
"signature",
"JWT",
".",
"Returns",
"a",
"JSON",
"-",
"structured",
"JWT",
"."
] | 1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3 | https://github.com/blockstack-packages/jsontokens-py/blob/1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3/jsontokens/token_signer.py#L93-L127 | train |
blockstack-packages/jsontokens-py | jsontokens/token_signer.py | TokenSigner.sign | def sign(self, payload, signing_key_or_keys):
"""
Create a JWT with one or more keys.
Returns a compact-form serialized JWT if there is only one key to sign with
Returns a JSON-structured serialized JWT if there are multiple keys to sign with
"""
if isinstance(signing_key... | python | def sign(self, payload, signing_key_or_keys):
"""
Create a JWT with one or more keys.
Returns a compact-form serialized JWT if there is only one key to sign with
Returns a JSON-structured serialized JWT if there are multiple keys to sign with
"""
if isinstance(signing_key... | [
"def",
"sign",
"(",
"self",
",",
"payload",
",",
"signing_key_or_keys",
")",
":",
"if",
"isinstance",
"(",
"signing_key_or_keys",
",",
"list",
")",
":",
"return",
"self",
".",
"_sign_multi",
"(",
"payload",
",",
"signing_key_or_keys",
")",
"else",
":",
"retu... | Create a JWT with one or more keys.
Returns a compact-form serialized JWT if there is only one key to sign with
Returns a JSON-structured serialized JWT if there are multiple keys to sign with | [
"Create",
"a",
"JWT",
"with",
"one",
"or",
"more",
"keys",
".",
"Returns",
"a",
"compact",
"-",
"form",
"serialized",
"JWT",
"if",
"there",
"is",
"only",
"one",
"key",
"to",
"sign",
"with",
"Returns",
"a",
"JSON",
"-",
"structured",
"serialized",
"JWT",
... | 1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3 | https://github.com/blockstack-packages/jsontokens-py/blob/1a4e71ed63456e8381b7d3fd566ce38e6ebfa7d3/jsontokens/token_signer.py#L130-L140 | train |
pyslackers/sir-bot-a-lot | setup.py | parse_reqs | def parse_reqs(req_path='./requirements/requirements.txt'):
"""Recursively parse requirements from nested pip files."""
install_requires = []
with codecs.open(req_path, 'r') as handle:
# remove comments and empty lines
lines = (line.strip() for line in handle
if line.strip()... | python | def parse_reqs(req_path='./requirements/requirements.txt'):
"""Recursively parse requirements from nested pip files."""
install_requires = []
with codecs.open(req_path, 'r') as handle:
# remove comments and empty lines
lines = (line.strip() for line in handle
if line.strip()... | [
"def",
"parse_reqs",
"(",
"req_path",
"=",
"'./requirements/requirements.txt'",
")",
":",
"install_requires",
"=",
"[",
"]",
"with",
"codecs",
".",
"open",
"(",
"req_path",
",",
"'r'",
")",
"as",
"handle",
":",
"lines",
"=",
"(",
"line",
".",
"strip",
"(",... | Recursively parse requirements from nested pip files. | [
"Recursively",
"parse",
"requirements",
"from",
"nested",
"pip",
"files",
"."
] | 22dfdd6a14d61dbe29423fd131b7a23e618b68d7 | https://github.com/pyslackers/sir-bot-a-lot/blob/22dfdd6a14d61dbe29423fd131b7a23e618b68d7/setup.py#L25-L42 | train |
BernardFW/bernard | src/bernard/reporter/_raven.py | RavenReporter.report | def report(self, request: 'Request'=None, state: Text=None):
"""
Report current exception to Sentry.
"""
self._make_context(request, state)
self.client.captureException()
self._clear_context() | python | def report(self, request: 'Request'=None, state: Text=None):
"""
Report current exception to Sentry.
"""
self._make_context(request, state)
self.client.captureException()
self._clear_context() | [
"def",
"report",
"(",
"self",
",",
"request",
":",
"'Request'",
"=",
"None",
",",
"state",
":",
"Text",
"=",
"None",
")",
":",
"self",
".",
"_make_context",
"(",
"request",
",",
"state",
")",
"self",
".",
"client",
".",
"captureException",
"(",
")",
... | Report current exception to Sentry. | [
"Report",
"current",
"exception",
"to",
"Sentry",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/reporter/_raven.py#L68-L74 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | vary_name | def vary_name(name: Text):
"""
Validates the name and creates variations
"""
snake = re.match(r'^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$', name)
if not snake:
fail('The project name is not a valid snake-case Python variable name')
camel = [x[0].upper() + x[1:] for x in name.split('_')]
re... | python | def vary_name(name: Text):
"""
Validates the name and creates variations
"""
snake = re.match(r'^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$', name)
if not snake:
fail('The project name is not a valid snake-case Python variable name')
camel = [x[0].upper() + x[1:] for x in name.split('_')]
re... | [
"def",
"vary_name",
"(",
"name",
":",
"Text",
")",
":",
"snake",
"=",
"re",
".",
"match",
"(",
"r'^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$'",
",",
"name",
")",
"if",
"not",
"snake",
":",
"fail",
"(",
"'The project name is not a valid snake-case Python variable name'",
")",
... | Validates the name and creates variations | [
"Validates",
"the",
"name",
"and",
"creates",
"variations"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L30-L46 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | make_random_key | def make_random_key() -> Text:
"""
Generates a secure random string
"""
r = SystemRandom()
allowed = \
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+/[]'
return ''.join([r.choice(allowed) for _ in range(0, 50)]) | python | def make_random_key() -> Text:
"""
Generates a secure random string
"""
r = SystemRandom()
allowed = \
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+/[]'
return ''.join([r.choice(allowed) for _ in range(0, 50)]) | [
"def",
"make_random_key",
"(",
")",
"->",
"Text",
":",
"r",
"=",
"SystemRandom",
"(",
")",
"allowed",
"=",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+/[]'",
"return",
"''",
".",
"join",
"(",
"[",
"r",
".",
"choice",
"(",
"allowed",
")",
"f... | Generates a secure random string | [
"Generates",
"a",
"secure",
"random",
"string"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L49-L58 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | make_dir_path | def make_dir_path(project_dir, root, project_name):
"""
Generates the target path for a directory
"""
root = root.replace('__project_name_snake__', project_name)
real_dir = path.realpath(project_dir)
return path.join(real_dir, root) | python | def make_dir_path(project_dir, root, project_name):
"""
Generates the target path for a directory
"""
root = root.replace('__project_name_snake__', project_name)
real_dir = path.realpath(project_dir)
return path.join(real_dir, root) | [
"def",
"make_dir_path",
"(",
"project_dir",
",",
"root",
",",
"project_name",
")",
":",
"root",
"=",
"root",
".",
"replace",
"(",
"'__project_name_snake__'",
",",
"project_name",
")",
"real_dir",
"=",
"path",
".",
"realpath",
"(",
"project_dir",
")",
"return",... | Generates the target path for a directory | [
"Generates",
"the",
"target",
"path",
"for",
"a",
"directory"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L61-L68 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | make_file_path | def make_file_path(project_dir, project_name, root, name):
"""
Generates the target path for a file
"""
return path.join(make_dir_path(project_dir, root, project_name), name) | python | def make_file_path(project_dir, project_name, root, name):
"""
Generates the target path for a file
"""
return path.join(make_dir_path(project_dir, root, project_name), name) | [
"def",
"make_file_path",
"(",
"project_dir",
",",
"project_name",
",",
"root",
",",
"name",
")",
":",
"return",
"path",
".",
"join",
"(",
"make_dir_path",
"(",
"project_dir",
",",
"root",
",",
"project_name",
")",
",",
"name",
")"
] | Generates the target path for a file | [
"Generates",
"the",
"target",
"path",
"for",
"a",
"file"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L71-L76 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | generate_vars | def generate_vars(project_name, project_dir):
"""
Generates the variables to replace in files
"""
out = vary_name(project_name)
out['random_key'] = make_random_key()
out['settings_file'] = make_file_path(
project_dir,
project_name,
path.join('src', project_name),
... | python | def generate_vars(project_name, project_dir):
"""
Generates the variables to replace in files
"""
out = vary_name(project_name)
out['random_key'] = make_random_key()
out['settings_file'] = make_file_path(
project_dir,
project_name,
path.join('src', project_name),
... | [
"def",
"generate_vars",
"(",
"project_name",
",",
"project_dir",
")",
":",
"out",
"=",
"vary_name",
"(",
"project_name",
")",
"out",
"[",
"'random_key'",
"]",
"=",
"make_random_key",
"(",
")",
"out",
"[",
"'settings_file'",
"]",
"=",
"make_file_path",
"(",
"... | Generates the variables to replace in files | [
"Generates",
"the",
"variables",
"to",
"replace",
"in",
"files"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L79-L93 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | get_files | def get_files():
"""
Read all the template's files
"""
files_root = path.join(path.dirname(__file__), 'files')
for root, dirs, files in walk(files_root):
rel_root = path.relpath(root, files_root)
for file_name in files:
try:
f = open(path.join(root, fil... | python | def get_files():
"""
Read all the template's files
"""
files_root = path.join(path.dirname(__file__), 'files')
for root, dirs, files in walk(files_root):
rel_root = path.relpath(root, files_root)
for file_name in files:
try:
f = open(path.join(root, fil... | [
"def",
"get_files",
"(",
")",
":",
"files_root",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"'files'",
")",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"walk",
"(",
"files_root",
")",
":",
"rel_root",
"=",
... | Read all the template's files | [
"Read",
"all",
"the",
"template",
"s",
"files"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L96-L114 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | check_target | def check_target(target_path):
"""
Checks that the target path is not empty
"""
if not path.exists(target_path):
return
with scandir(target_path) as d:
for entry in d:
if not entry.name.startswith('.'):
fail(f'Target directory "{target_path}" is not empt... | python | def check_target(target_path):
"""
Checks that the target path is not empty
"""
if not path.exists(target_path):
return
with scandir(target_path) as d:
for entry in d:
if not entry.name.startswith('.'):
fail(f'Target directory "{target_path}" is not empt... | [
"def",
"check_target",
"(",
"target_path",
")",
":",
"if",
"not",
"path",
".",
"exists",
"(",
"target_path",
")",
":",
"return",
"with",
"scandir",
"(",
"target_path",
")",
"as",
"d",
":",
"for",
"entry",
"in",
"d",
":",
"if",
"not",
"entry",
".",
"n... | Checks that the target path is not empty | [
"Checks",
"that",
"the",
"target",
"path",
"is",
"not",
"empty"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L117-L128 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | replace_content | def replace_content(content, project_vars):
"""
Replaces variables inside the content.
"""
for k, v in project_vars.items():
content = content.replace(f'__{k}__', v)
return content | python | def replace_content(content, project_vars):
"""
Replaces variables inside the content.
"""
for k, v in project_vars.items():
content = content.replace(f'__{k}__', v)
return content | [
"def",
"replace_content",
"(",
"content",
",",
"project_vars",
")",
":",
"for",
"k",
",",
"v",
"in",
"project_vars",
".",
"items",
"(",
")",
":",
"content",
"=",
"content",
".",
"replace",
"(",
"f'__{k}__'",
",",
"v",
")",
"return",
"content"
] | Replaces variables inside the content. | [
"Replaces",
"variables",
"inside",
"the",
"content",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L131-L139 | train |
BernardFW/bernard | src/bernard/misc/start_project/_base.py | copy_files | def copy_files(project_vars, project_dir, files):
"""
Copies files from the template into their target location. Unicode files
get their variables replaced here and files with a shebang are set to be
executable.
"""
for root, name, content, is_unicode in files:
project_name = project_va... | python | def copy_files(project_vars, project_dir, files):
"""
Copies files from the template into their target location. Unicode files
get their variables replaced here and files with a shebang are set to be
executable.
"""
for root, name, content, is_unicode in files:
project_name = project_va... | [
"def",
"copy_files",
"(",
"project_vars",
",",
"project_dir",
",",
"files",
")",
":",
"for",
"root",
",",
"name",
",",
"content",
",",
"is_unicode",
"in",
"files",
":",
"project_name",
"=",
"project_vars",
"[",
"'project_name_snake'",
"]",
"if",
"is_unicode",
... | Copies files from the template into their target location. Unicode files
get their variables replaced here and files with a shebang are set to be
executable. | [
"Copies",
"files",
"from",
"the",
"template",
"into",
"their",
"target",
"location",
".",
"Unicode",
"files",
"get",
"their",
"variables",
"replaced",
"here",
"and",
"files",
"with",
"a",
"shebang",
"are",
"set",
"to",
"be",
"executable",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/misc/start_project/_base.py#L142-L166 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.connect | def connect(self):
"""Connect to the chatroom's server, sets up handlers, invites members as needed."""
for m in self.params['MEMBERS']:
m['ONLINE'] = 0
m.setdefault('STATUS', 'INVITED')
self.client = xmpp.Client(self.jid.getDomain(), debug=[])
conn = self.client... | python | def connect(self):
"""Connect to the chatroom's server, sets up handlers, invites members as needed."""
for m in self.params['MEMBERS']:
m['ONLINE'] = 0
m.setdefault('STATUS', 'INVITED')
self.client = xmpp.Client(self.jid.getDomain(), debug=[])
conn = self.client... | [
"def",
"connect",
"(",
"self",
")",
":",
"for",
"m",
"in",
"self",
".",
"params",
"[",
"'MEMBERS'",
"]",
":",
"m",
"[",
"'ONLINE'",
"]",
"=",
"0",
"m",
".",
"setdefault",
"(",
"'STATUS'",
",",
"'INVITED'",
")",
"self",
".",
"client",
"=",
"xmpp",
... | Connect to the chatroom's server, sets up handlers, invites members as needed. | [
"Connect",
"to",
"the",
"chatroom",
"s",
"server",
"sets",
"up",
"handlers",
"invites",
"members",
"as",
"needed",
"."
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L31-L53 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.get_member | def get_member(self, jid, default=None):
"""Get a chatroom member by JID"""
member = filter(lambda m: m['JID'] == jid, self.params['MEMBERS'])
if len(member) == 1:
return member[0]
elif len(member) == 0:
return default
else:
raise Exception('Mu... | python | def get_member(self, jid, default=None):
"""Get a chatroom member by JID"""
member = filter(lambda m: m['JID'] == jid, self.params['MEMBERS'])
if len(member) == 1:
return member[0]
elif len(member) == 0:
return default
else:
raise Exception('Mu... | [
"def",
"get_member",
"(",
"self",
",",
"jid",
",",
"default",
"=",
"None",
")",
":",
"member",
"=",
"filter",
"(",
"lambda",
"m",
":",
"m",
"[",
"'JID'",
"]",
"==",
"jid",
",",
"self",
".",
"params",
"[",
"'MEMBERS'",
"]",
")",
"if",
"len",
"(",
... | Get a chatroom member by JID | [
"Get",
"a",
"chatroom",
"member",
"by",
"JID"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L55-L63 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.is_member | def is_member(self, m):
"""Check if a user is a member of the chatroom"""
if not m:
return False
elif isinstance(m, basestring):
jid = m
else:
jid = m['JID']
is_member = len(filter(lambda m: m['JID'] == jid and m.get('STATUS') in ('ACTIVE', 'I... | python | def is_member(self, m):
"""Check if a user is a member of the chatroom"""
if not m:
return False
elif isinstance(m, basestring):
jid = m
else:
jid = m['JID']
is_member = len(filter(lambda m: m['JID'] == jid and m.get('STATUS') in ('ACTIVE', 'I... | [
"def",
"is_member",
"(",
"self",
",",
"m",
")",
":",
"if",
"not",
"m",
":",
"return",
"False",
"elif",
"isinstance",
"(",
"m",
",",
"basestring",
")",
":",
"jid",
"=",
"m",
"else",
":",
"jid",
"=",
"m",
"[",
"'JID'",
"]",
"is_member",
"=",
"len",... | Check if a user is a member of the chatroom | [
"Check",
"if",
"a",
"user",
"is",
"a",
"member",
"of",
"the",
"chatroom"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L65-L76 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.invite_user | def invite_user(self, new_member, inviter=None, roster=None):
"""Invites a new member to the chatroom"""
roster = roster or self.client.getRoster()
jid = new_member['JID']
logger.info('roster %s %s' % (jid, roster.getSubscription(jid)))
if jid in roster.keys() and roster.getSubs... | python | def invite_user(self, new_member, inviter=None, roster=None):
"""Invites a new member to the chatroom"""
roster = roster or self.client.getRoster()
jid = new_member['JID']
logger.info('roster %s %s' % (jid, roster.getSubscription(jid)))
if jid in roster.keys() and roster.getSubs... | [
"def",
"invite_user",
"(",
"self",
",",
"new_member",
",",
"inviter",
"=",
"None",
",",
"roster",
"=",
"None",
")",
":",
"roster",
"=",
"roster",
"or",
"self",
".",
"client",
".",
"getRoster",
"(",
")",
"jid",
"=",
"new_member",
"[",
"'JID'",
"]",
"l... | Invites a new member to the chatroom | [
"Invites",
"a",
"new",
"member",
"to",
"the",
"chatroom"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L78-L100 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.kick_user | def kick_user(self, jid):
"""Kicks a member from the chatroom. Kicked user will receive no more messages."""
for member in filter(lambda m: m['JID'] == jid, self.params['MEMBERS']):
member['STATUS'] = 'KICKED'
self.send_message('You have been kicked from %s' % (self.name,), membe... | python | def kick_user(self, jid):
"""Kicks a member from the chatroom. Kicked user will receive no more messages."""
for member in filter(lambda m: m['JID'] == jid, self.params['MEMBERS']):
member['STATUS'] = 'KICKED'
self.send_message('You have been kicked from %s' % (self.name,), membe... | [
"def",
"kick_user",
"(",
"self",
",",
"jid",
")",
":",
"for",
"member",
"in",
"filter",
"(",
"lambda",
"m",
":",
"m",
"[",
"'JID'",
"]",
"==",
"jid",
",",
"self",
".",
"params",
"[",
"'MEMBERS'",
"]",
")",
":",
"member",
"[",
"'STATUS'",
"]",
"="... | Kicks a member from the chatroom. Kicked user will receive no more messages. | [
"Kicks",
"a",
"member",
"from",
"the",
"chatroom",
".",
"Kicked",
"user",
"will",
"receive",
"no",
"more",
"messages",
"."
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L102-L110 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.send_message | def send_message(self, body, to, quiet=False, html_body=None):
"""Send a message to a single member"""
if to.get('MUTED'):
to['QUEUED_MESSAGES'].append(body)
else:
if not quiet:
logger.info('message on %s to %s: %s' % (self.name, to['JID'], body))
... | python | def send_message(self, body, to, quiet=False, html_body=None):
"""Send a message to a single member"""
if to.get('MUTED'):
to['QUEUED_MESSAGES'].append(body)
else:
if not quiet:
logger.info('message on %s to %s: %s' % (self.name, to['JID'], body))
... | [
"def",
"send_message",
"(",
"self",
",",
"body",
",",
"to",
",",
"quiet",
"=",
"False",
",",
"html_body",
"=",
"None",
")",
":",
"if",
"to",
".",
"get",
"(",
"'MUTED'",
")",
":",
"to",
"[",
"'QUEUED_MESSAGES'",
"]",
".",
"append",
"(",
"body",
")",... | Send a message to a single member | [
"Send",
"a",
"message",
"to",
"a",
"single",
"member"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L112-L126 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.broadcast | def broadcast(self, body, html_body=None, exclude=()):
"""Broadcast a message to users in the chatroom"""
logger.info('broadcast on %s: %s' % (self.name, body,))
for member in filter(lambda m: m.get('STATUS') == 'ACTIVE' and m not in exclude, self.params['MEMBERS']):
logger.debug(mem... | python | def broadcast(self, body, html_body=None, exclude=()):
"""Broadcast a message to users in the chatroom"""
logger.info('broadcast on %s: %s' % (self.name, body,))
for member in filter(lambda m: m.get('STATUS') == 'ACTIVE' and m not in exclude, self.params['MEMBERS']):
logger.debug(mem... | [
"def",
"broadcast",
"(",
"self",
",",
"body",
",",
"html_body",
"=",
"None",
",",
"exclude",
"=",
"(",
")",
")",
":",
"logger",
".",
"info",
"(",
"'broadcast on %s: %s'",
"%",
"(",
"self",
".",
"name",
",",
"body",
",",
")",
")",
"for",
"member",
"... | Broadcast a message to users in the chatroom | [
"Broadcast",
"a",
"message",
"to",
"users",
"in",
"the",
"chatroom"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L128-L133 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.do_invite | def do_invite(self, sender, body, args):
"""Invite members to the chatroom on a user's behalf"""
for invitee in args:
new_member = { 'JID': invitee }
self.invite_user(new_member, inviter=sender) | python | def do_invite(self, sender, body, args):
"""Invite members to the chatroom on a user's behalf"""
for invitee in args:
new_member = { 'JID': invitee }
self.invite_user(new_member, inviter=sender) | [
"def",
"do_invite",
"(",
"self",
",",
"sender",
",",
"body",
",",
"args",
")",
":",
"for",
"invitee",
"in",
"args",
":",
"new_member",
"=",
"{",
"'JID'",
":",
"invitee",
"}",
"self",
".",
"invite_user",
"(",
"new_member",
",",
"inviter",
"=",
"sender",... | Invite members to the chatroom on a user's behalf | [
"Invite",
"members",
"to",
"the",
"chatroom",
"on",
"a",
"user",
"s",
"behalf"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L141-L145 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.do_kick | def do_kick(self, sender, body, args):
"""Kick a member from the chatroom. Must be Admin to kick users"""
if sender.get('ADMIN') != True: return
for user in args:
self.kick_user(user) | python | def do_kick(self, sender, body, args):
"""Kick a member from the chatroom. Must be Admin to kick users"""
if sender.get('ADMIN') != True: return
for user in args:
self.kick_user(user) | [
"def",
"do_kick",
"(",
"self",
",",
"sender",
",",
"body",
",",
"args",
")",
":",
"if",
"sender",
".",
"get",
"(",
"'ADMIN'",
")",
"!=",
"True",
":",
"return",
"for",
"user",
"in",
"args",
":",
"self",
".",
"kick_user",
"(",
"user",
")"
] | Kick a member from the chatroom. Must be Admin to kick users | [
"Kick",
"a",
"member",
"from",
"the",
"chatroom",
".",
"Must",
"be",
"Admin",
"to",
"kick",
"users"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L147-L151 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.do_mute | def do_mute(self, sender, body, args):
"""Temporarily mutes chatroom for a user"""
if sender.get('MUTED'):
self.send_message('you are already muted', sender)
else:
self.broadcast('%s has muted this chatroom' % (sender['NICK'],))
sender['QUEUED_MESSAGES'] = []
... | python | def do_mute(self, sender, body, args):
"""Temporarily mutes chatroom for a user"""
if sender.get('MUTED'):
self.send_message('you are already muted', sender)
else:
self.broadcast('%s has muted this chatroom' % (sender['NICK'],))
sender['QUEUED_MESSAGES'] = []
... | [
"def",
"do_mute",
"(",
"self",
",",
"sender",
",",
"body",
",",
"args",
")",
":",
"if",
"sender",
".",
"get",
"(",
"'MUTED'",
")",
":",
"self",
".",
"send_message",
"(",
"'you are already muted'",
",",
"sender",
")",
"else",
":",
"self",
".",
"broadcas... | Temporarily mutes chatroom for a user | [
"Temporarily",
"mutes",
"chatroom",
"for",
"a",
"user"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L153-L160 | train |
mattlong/hermes | hermes/chatroom.py | Chatroom.do_unmute | def do_unmute(self, sender, body, args):
"""Unmutes the chatroom for a user"""
if sender.get('MUTED'):
sender['MUTED'] = False
self.broadcast('%s has unmuted this chatroom' % (sender['NICK'],))
for msg in sender.get('QUEUED_MESSAGES', []):
self.send_me... | python | def do_unmute(self, sender, body, args):
"""Unmutes the chatroom for a user"""
if sender.get('MUTED'):
sender['MUTED'] = False
self.broadcast('%s has unmuted this chatroom' % (sender['NICK'],))
for msg in sender.get('QUEUED_MESSAGES', []):
self.send_me... | [
"def",
"do_unmute",
"(",
"self",
",",
"sender",
",",
"body",
",",
"args",
")",
":",
"if",
"sender",
".",
"get",
"(",
"'MUTED'",
")",
":",
"sender",
"[",
"'MUTED'",
"]",
"=",
"False",
"self",
".",
"broadcast",
"(",
"'%s has unmuted this chatroom'",
"%",
... | Unmutes the chatroom for a user | [
"Unmutes",
"the",
"chatroom",
"for",
"a",
"user"
] | 63a5afcafe90ca99aeb44edeee9ed6f90baae431 | https://github.com/mattlong/hermes/blob/63a5afcafe90ca99aeb44edeee9ed6f90baae431/hermes/chatroom.py#L162-L171 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.