repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
azavea/python-omgeo | omgeo/services/google.py | Google._get_component_from_result | def _get_component_from_result(self, result, lookup):
"""
Helper function to get a particular address component from a Google result.
Since the address components in results are an array of objects containing a types array,
we have to search for a particular component rather than being ... | python | def _get_component_from_result(self, result, lookup):
"""
Helper function to get a particular address component from a Google result.
Since the address components in results are an array of objects containing a types array,
we have to search for a particular component rather than being ... | [
"def",
"_get_component_from_result",
"(",
"self",
",",
"result",
",",
"lookup",
")",
":",
"for",
"component",
"in",
"result",
"[",
"'address_components'",
"]",
":",
"if",
"lookup",
"[",
"'type'",
"]",
"in",
"component",
"[",
"'types'",
"]",
":",
"return",
... | Helper function to get a particular address component from a Google result.
Since the address components in results are an array of objects containing a types array,
we have to search for a particular component rather than being able to look it up directly.
Returns the first match, so this sho... | [
"Helper",
"function",
"to",
"get",
"a",
"particular",
"address",
"component",
"from",
"a",
"Google",
"result",
"."
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/services/google.py#L76-L95 |
raonyguimaraes/pynnotator | pynnotator/install.py | Installer.install_requirements | def install_requirements(self):
"""Install Ubuntu Requirements"""
print('Installing Requirements')
print(platform.dist())
if platform.dist()[0] in ['Ubuntu', 'LinuxMint']:
command = 'sudo apt-get install -y gcc git python3-dev zlib1g-dev make zip libssl-dev libbz2-dev liblzma... | python | def install_requirements(self):
"""Install Ubuntu Requirements"""
print('Installing Requirements')
print(platform.dist())
if platform.dist()[0] in ['Ubuntu', 'LinuxMint']:
command = 'sudo apt-get install -y gcc git python3-dev zlib1g-dev make zip libssl-dev libbz2-dev liblzma... | [
"def",
"install_requirements",
"(",
"self",
")",
":",
"print",
"(",
"'Installing Requirements'",
")",
"print",
"(",
"platform",
".",
"dist",
"(",
")",
")",
"if",
"platform",
".",
"dist",
"(",
")",
"[",
"0",
"]",
"in",
"[",
"'Ubuntu'",
",",
"'LinuxMint'",... | Install Ubuntu Requirements | [
"Install",
"Ubuntu",
"Requirements"
] | train | https://github.com/raonyguimaraes/pynnotator/blob/84ba8c3cdefde4c1894b853ba8370d3b4ff1d62a/pynnotator/install.py#L33-L79 |
morpframework/morpfw | morpfw/interfaces.py | IStorageBase.search | def search(self, query: Optional[dict] = None, offset: Optional[int] = None,
limit: Optional[int] = None,
order_by: Union[None, list, tuple] = None) -> Sequence['IModel']:
"""return search result based on specified rulez query"""
raise NotImplementedError | python | def search(self, query: Optional[dict] = None, offset: Optional[int] = None,
limit: Optional[int] = None,
order_by: Union[None, list, tuple] = None) -> Sequence['IModel']:
"""return search result based on specified rulez query"""
raise NotImplementedError | [
"def",
"search",
"(",
"self",
",",
"query",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"offset",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"limit",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"order_by",
":",
"Union",
... | return search result based on specified rulez query | [
"return",
"search",
"result",
"based",
"on",
"specified",
"rulez",
"query"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L137-L141 |
morpframework/morpfw | morpfw/interfaces.py | IStorage.aggregate | def aggregate(self, query: Optional[dict] = None,
group: Optional[dict] = None,
order_by: Union[None, list, tuple] = None) -> list:
"""return aggregation result based on specified rulez query and group"""
raise NotImplementedError | python | def aggregate(self, query: Optional[dict] = None,
group: Optional[dict] = None,
order_by: Union[None, list, tuple] = None) -> list:
"""return aggregation result based on specified rulez query and group"""
raise NotImplementedError | [
"def",
"aggregate",
"(",
"self",
",",
"query",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"group",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"order_by",
":",
"Union",
"[",
"None",
",",
"list",
",",
"tuple",
"]",
"=",
"None",
... | return aggregation result based on specified rulez query and group | [
"return",
"aggregation",
"result",
"based",
"on",
"specified",
"rulez",
"query",
"and",
"group"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L168-L172 |
morpframework/morpfw | morpfw/interfaces.py | IModel.put_blob | def put_blob(self, field: str, fileobj: BinaryIO,
filename: str,
mimetype: Optional[str] = None,
size: Optional[int] = None,
encoding: Optional[str] = None) -> IBlob:
"""Receive and store blob object"""
raise NotImplementedError | python | def put_blob(self, field: str, fileobj: BinaryIO,
filename: str,
mimetype: Optional[str] = None,
size: Optional[int] = None,
encoding: Optional[str] = None) -> IBlob:
"""Receive and store blob object"""
raise NotImplementedError | [
"def",
"put_blob",
"(",
"self",
",",
"field",
":",
"str",
",",
"fileobj",
":",
"BinaryIO",
",",
"filename",
":",
"str",
",",
"mimetype",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"size",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",... | Receive and store blob object | [
"Receive",
"and",
"store",
"blob",
"object"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L289-L295 |
morpframework/morpfw | morpfw/interfaces.py | IModel.before_blobput | def before_blobput(self, field: str, fileobj: BinaryIO,
filename: str,
mimetype: Optional[str] = None,
size: Optional[int] = None,
encoding: Optional[str] = None) -> None:
"""Triggered before BLOB is stored""" | python | def before_blobput(self, field: str, fileobj: BinaryIO,
filename: str,
mimetype: Optional[str] = None,
size: Optional[int] = None,
encoding: Optional[str] = None) -> None:
"""Triggered before BLOB is stored""" | [
"def",
"before_blobput",
"(",
"self",
",",
"field",
":",
"str",
",",
"fileobj",
":",
"BinaryIO",
",",
"filename",
":",
"str",
",",
"mimetype",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"size",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
... | Triggered before BLOB is stored | [
"Triggered",
"before",
"BLOB",
"is",
"stored"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L321-L326 |
morpframework/morpfw | morpfw/interfaces.py | ICollection.search | def search(self, query: Optional[dict] = None,
offset: int = 0,
limit: Optional[int] = None,
order_by: Optional[tuple] = None,
secure: bool = False) -> List[IModel]:
"""Search for models
Filtering is done through ``rulez`` based JSON/dict quer... | python | def search(self, query: Optional[dict] = None,
offset: int = 0,
limit: Optional[int] = None,
order_by: Optional[tuple] = None,
secure: bool = False) -> List[IModel]:
"""Search for models
Filtering is done through ``rulez`` based JSON/dict quer... | [
"def",
"search",
"(",
"self",
",",
"query",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"offset",
":",
"int",
"=",
"0",
",",
"limit",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"order_by",
":",
"Optional",
"[",
"tuple",
"]",
"="... | Search for models
Filtering is done through ``rulez`` based JSON/dict query, which
defines boolean statements in JSON/dict structure.
: param query: Rulez based query
: param offset: Result offset
: param limit: Maximum number of result
: param order_by: Tuple of ``(fie... | [
"Search",
"for",
"models"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L339-L359 |
morpframework/morpfw | morpfw/interfaces.py | ICollection.aggregate | def aggregate(self, query: Optional[dict] = None,
group: Optional[dict] = None,
order_by: Optional[tuple] = None) -> List[IModel]:
"""Get aggregated results
: param query: Rulez based query
: param group: Grouping structure
: param order_by: Tuple of ... | python | def aggregate(self, query: Optional[dict] = None,
group: Optional[dict] = None,
order_by: Optional[tuple] = None) -> List[IModel]:
"""Get aggregated results
: param query: Rulez based query
: param group: Grouping structure
: param order_by: Tuple of ... | [
"def",
"aggregate",
"(",
"self",
",",
"query",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"group",
":",
"Optional",
"[",
"dict",
"]",
"=",
"None",
",",
"order_by",
":",
"Optional",
"[",
"tuple",
"]",
"=",
"None",
")",
"->",
"List",
"[",
... | Get aggregated results
: param query: Rulez based query
: param group: Grouping structure
: param order_by: Tuple of ``(field, order)`` where ``order`` is
``'asc'`` or ``'desc'``
: todo: Grouping structure need to be documented | [
"Get",
"aggregated",
"results"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/interfaces.py#L362-L375 |
Ajedi32/echovr-api | echovr_api/api.py | API.fetch_state_data | def fetch_state_data(self):
"""Fetch the raw JSON game state data from EchoVR's ``/session`` API
This method could be useful if you want to retrieve some API data not
directly exposed by this Python wrapper. Otherwise, you should probably
use :meth:`fetch_state` instead.
:retur... | python | def fetch_state_data(self):
"""Fetch the raw JSON game state data from EchoVR's ``/session`` API
This method could be useful if you want to retrieve some API data not
directly exposed by this Python wrapper. Otherwise, you should probably
use :meth:`fetch_state` instead.
:retur... | [
"def",
"fetch_state_data",
"(",
"self",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"self",
".",
"_gamestate_url",
")",
"response_text",
"=",
"response",
".",
"text",
".",
"rstrip",
"(",
"'\\0'",
")",
"return",
"json",
".",
"loads",
"(",
"res... | Fetch the raw JSON game state data from EchoVR's ``/session`` API
This method could be useful if you want to retrieve some API data not
directly exposed by this Python wrapper. Otherwise, you should probably
use :meth:`fetch_state` instead.
:returns:
An object (probably a :... | [
"Fetch",
"the",
"raw",
"JSON",
"game",
"state",
"data",
"from",
"EchoVR",
"s",
"/",
"session",
"API"
] | train | https://github.com/Ajedi32/echovr-api/blob/e135f25fb5b188e2931133d04c47c5e66e83a6c5/echovr_api/api.py#L18-L40 |
azavea/python-omgeo | omgeo/places.py | Viewbox.to_bing_str | def to_bing_str(self):
"""
Convert Viewbox object to a string that can be used by Bing
as a query parameter.
"""
vb = self.convert_srs(4326)
return '%s,%s,%s,%s' % (vb.bottom, vb.left, vb.top, vb.right) | python | def to_bing_str(self):
"""
Convert Viewbox object to a string that can be used by Bing
as a query parameter.
"""
vb = self.convert_srs(4326)
return '%s,%s,%s,%s' % (vb.bottom, vb.left, vb.top, vb.right) | [
"def",
"to_bing_str",
"(",
"self",
")",
":",
"vb",
"=",
"self",
".",
"convert_srs",
"(",
"4326",
")",
"return",
"'%s,%s,%s,%s'",
"%",
"(",
"vb",
".",
"bottom",
",",
"vb",
".",
"left",
",",
"vb",
".",
"top",
",",
"vb",
".",
"right",
")"
] | Convert Viewbox object to a string that can be used by Bing
as a query parameter. | [
"Convert",
"Viewbox",
"object",
"to",
"a",
"string",
"that",
"can",
"be",
"used",
"by",
"Bing",
"as",
"a",
"query",
"parameter",
"."
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/places.py#L29-L35 |
azavea/python-omgeo | omgeo/places.py | Viewbox.to_pelias_dict | def to_pelias_dict(self):
"""
Convert Viewbox object to a string that can be used by Pelias
as a query parameter.
"""
vb = self.convert_srs(4326)
return {
'boundary.rect.min_lat': vb.bottom,
'boundary.rect.min_lon': vb.left,
'boundary.r... | python | def to_pelias_dict(self):
"""
Convert Viewbox object to a string that can be used by Pelias
as a query parameter.
"""
vb = self.convert_srs(4326)
return {
'boundary.rect.min_lat': vb.bottom,
'boundary.rect.min_lon': vb.left,
'boundary.r... | [
"def",
"to_pelias_dict",
"(",
"self",
")",
":",
"vb",
"=",
"self",
".",
"convert_srs",
"(",
"4326",
")",
"return",
"{",
"'boundary.rect.min_lat'",
":",
"vb",
".",
"bottom",
",",
"'boundary.rect.min_lon'",
":",
"vb",
".",
"left",
",",
"'boundary.rect.max_lat'",... | Convert Viewbox object to a string that can be used by Pelias
as a query parameter. | [
"Convert",
"Viewbox",
"object",
"to",
"a",
"string",
"that",
"can",
"be",
"used",
"by",
"Pelias",
"as",
"a",
"query",
"parameter",
"."
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/places.py#L37-L48 |
azavea/python-omgeo | omgeo/places.py | Viewbox.to_google_str | def to_google_str(self):
""" Convert to Google's bounds format: 'latMin,lonMin|latMax,lonMax' """
vb = self.convert_srs(4326)
return '%s,%s|%s,%s' % (vb.bottom, vb.left, vb.top, vb.right) | python | def to_google_str(self):
""" Convert to Google's bounds format: 'latMin,lonMin|latMax,lonMax' """
vb = self.convert_srs(4326)
return '%s,%s|%s,%s' % (vb.bottom, vb.left, vb.top, vb.right) | [
"def",
"to_google_str",
"(",
"self",
")",
":",
"vb",
"=",
"self",
".",
"convert_srs",
"(",
"4326",
")",
"return",
"'%s,%s|%s,%s'",
"%",
"(",
"vb",
".",
"bottom",
",",
"vb",
".",
"left",
",",
"vb",
".",
"top",
",",
"vb",
".",
"right",
")"
] | Convert to Google's bounds format: 'latMin,lonMin|latMax,lonMax' | [
"Convert",
"to",
"Google",
"s",
"bounds",
"format",
":",
"latMin",
"lonMin|latMax",
"lonMax"
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/places.py#L50-L53 |
azavea/python-omgeo | omgeo/places.py | Viewbox.to_mapquest_str | def to_mapquest_str(self):
"""
Convert Viewbox object to a string that can be used by
`MapQuest <http://www.mapquestapi.com/geocoding/#options>`_
as a query parameter.
"""
vb = self.convert_srs(4326)
return '%s,%s,%s,%s' % (vb.left, vb.top, vb.right, vb.bottom) | python | def to_mapquest_str(self):
"""
Convert Viewbox object to a string that can be used by
`MapQuest <http://www.mapquestapi.com/geocoding/#options>`_
as a query parameter.
"""
vb = self.convert_srs(4326)
return '%s,%s,%s,%s' % (vb.left, vb.top, vb.right, vb.bottom) | [
"def",
"to_mapquest_str",
"(",
"self",
")",
":",
"vb",
"=",
"self",
".",
"convert_srs",
"(",
"4326",
")",
"return",
"'%s,%s,%s,%s'",
"%",
"(",
"vb",
".",
"left",
",",
"vb",
".",
"top",
",",
"vb",
".",
"right",
",",
"vb",
".",
"bottom",
")"
] | Convert Viewbox object to a string that can be used by
`MapQuest <http://www.mapquestapi.com/geocoding/#options>`_
as a query parameter. | [
"Convert",
"Viewbox",
"object",
"to",
"a",
"string",
"that",
"can",
"be",
"used",
"by",
"MapQuest",
"<http",
":",
"//",
"www",
".",
"mapquestapi",
".",
"com",
"/",
"geocoding",
"/",
"#options",
">",
"_",
"as",
"a",
"query",
"parameter",
"."
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/places.py#L55-L62 |
azavea/python-omgeo | omgeo/places.py | Viewbox.to_esri_wgs_json | def to_esri_wgs_json(self):
"""
Convert Viewbox object to a JSON string that can be used
by the ESRI World Geocoding Service as a parameter.
"""
try:
return ('{ "xmin" : %s, '
'"ymin" : %s, '
'"xmax" : %s, '
... | python | def to_esri_wgs_json(self):
"""
Convert Viewbox object to a JSON string that can be used
by the ESRI World Geocoding Service as a parameter.
"""
try:
return ('{ "xmin" : %s, '
'"ymin" : %s, '
'"xmax" : %s, '
... | [
"def",
"to_esri_wgs_json",
"(",
"self",
")",
":",
"try",
":",
"return",
"(",
"'{ \"xmin\" : %s, '",
"'\"ymin\" : %s, '",
"'\"xmax\" : %s, '",
"'\"ymax\" : %s, '",
"'\"spatialReference\" : {\"wkid\" : %d} }'",
"%",
"(",
"self",
".",
"left",
",",
"self",
".",
"bottom",
... | Convert Viewbox object to a JSON string that can be used
by the ESRI World Geocoding Service as a parameter. | [
"Convert",
"Viewbox",
"object",
"to",
"a",
"JSON",
"string",
"that",
"can",
"be",
"used",
"by",
"the",
"ESRI",
"World",
"Geocoding",
"Service",
"as",
"a",
"parameter",
"."
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/places.py#L64-L83 |
morpframework/morpfw | morpfw/authn/pas/user/view.py | register | def register(context, request, load):
"""Validate the username and password and create the user."""
data = request.json
res = validate(data, dataclass_to_jsl(
RegistrationSchema).get_schema())
if res:
@request.after
def set_error(response):
response.status = 422
... | python | def register(context, request, load):
"""Validate the username and password and create the user."""
data = request.json
res = validate(data, dataclass_to_jsl(
RegistrationSchema).get_schema())
if res:
@request.after
def set_error(response):
response.status = 422
... | [
"def",
"register",
"(",
"context",
",",
"request",
",",
"load",
")",
":",
"data",
"=",
"request",
".",
"json",
"res",
"=",
"validate",
"(",
"data",
",",
"dataclass_to_jsl",
"(",
"RegistrationSchema",
")",
".",
"get_schema",
"(",
")",
")",
"if",
"res",
... | Validate the username and password and create the user. | [
"Validate",
"the",
"username",
"and",
"password",
"and",
"create",
"the",
"user",
"."
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/user/view.py#L22-L48 |
morpframework/morpfw | morpfw/authn/pas/user/view.py | process_login | def process_login(context, request):
"""Authenticate username and password and log in user"""
username = request.json['username']
password = request.json['password']
# Do the password validation.
user = context.authenticate(username, password)
if not user:
@request.after
def adj... | python | def process_login(context, request):
"""Authenticate username and password and log in user"""
username = request.json['username']
password = request.json['password']
# Do the password validation.
user = context.authenticate(username, password)
if not user:
@request.after
def adj... | [
"def",
"process_login",
"(",
"context",
",",
"request",
")",
":",
"username",
"=",
"request",
".",
"json",
"[",
"'username'",
"]",
"password",
"=",
"request",
".",
"json",
"[",
"'password'",
"]",
"# Do the password validation.",
"user",
"=",
"context",
".",
... | Authenticate username and password and log in user | [
"Authenticate",
"username",
"and",
"password",
"and",
"log",
"in",
"user"
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/user/view.py#L60-L89 |
morpframework/morpfw | morpfw/authn/pas/user/view.py | logout | def logout(context, request):
"""Log out the user."""
@request.after
def forget(response):
request.app.forget_identity(response, request)
return {
'status': 'success'
} | python | def logout(context, request):
"""Log out the user."""
@request.after
def forget(response):
request.app.forget_identity(response, request)
return {
'status': 'success'
} | [
"def",
"logout",
"(",
"context",
",",
"request",
")",
":",
"@",
"request",
".",
"after",
"def",
"forget",
"(",
"response",
")",
":",
"request",
".",
"app",
".",
"forget_identity",
"(",
"response",
",",
"request",
")",
"return",
"{",
"'status'",
":",
"'... | Log out the user. | [
"Log",
"out",
"the",
"user",
"."
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/user/view.py#L131-L140 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.request | def request(self, url, method, data=None):
"""
The requester shortcut to submit a http request to CloutFlare
:param url:
:param method:
:param data:
:return:
"""
method = getattr(requests, method)
response = method(
url,
hea... | python | def request(self, url, method, data=None):
"""
The requester shortcut to submit a http request to CloutFlare
:param url:
:param method:
:param data:
:return:
"""
method = getattr(requests, method)
response = method(
url,
hea... | [
"def",
"request",
"(",
"self",
",",
"url",
",",
"method",
",",
"data",
"=",
"None",
")",
":",
"method",
"=",
"getattr",
"(",
"requests",
",",
"method",
")",
"response",
"=",
"method",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"headers",
",",
"d... | The requester shortcut to submit a http request to CloutFlare
:param url:
:param method:
:param data:
:return: | [
"The",
"requester",
"shortcut",
"to",
"submit",
"a",
"http",
"request",
"to",
"CloutFlare",
":",
"param",
"url",
":",
":",
"param",
"method",
":",
":",
"param",
"data",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L70-L88 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.setup_zone | def setup_zone(self):
"""
Setup zone for current domain.
It will also setup the dns records of the zone
:return:
"""
# Initialize current zone
zones_content = self.request(self.api_url, 'get')
try:
if len(self.domain.split('.')) == 3:
... | python | def setup_zone(self):
"""
Setup zone for current domain.
It will also setup the dns records of the zone
:return:
"""
# Initialize current zone
zones_content = self.request(self.api_url, 'get')
try:
if len(self.domain.split('.')) == 3:
... | [
"def",
"setup_zone",
"(",
"self",
")",
":",
"# Initialize current zone",
"zones_content",
"=",
"self",
".",
"request",
"(",
"self",
".",
"api_url",
",",
"'get'",
")",
"try",
":",
"if",
"len",
"(",
"self",
".",
"domain",
".",
"split",
"(",
"'.'",
")",
"... | Setup zone for current domain.
It will also setup the dns records of the zone
:return: | [
"Setup",
"zone",
"for",
"current",
"domain",
".",
"It",
"will",
"also",
"setup",
"the",
"dns",
"records",
"of",
"the",
"zone",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L90-L111 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.get_record | def get_record(self, dns_type, name):
"""
Get a dns record
:param dns_type:
:param name:
:return:
"""
try:
record = [record for record in self.dns_records
if record['type'] == dns_type and record['name'] == name][0]
except... | python | def get_record(self, dns_type, name):
"""
Get a dns record
:param dns_type:
:param name:
:return:
"""
try:
record = [record for record in self.dns_records
if record['type'] == dns_type and record['name'] == name][0]
except... | [
"def",
"get_record",
"(",
"self",
",",
"dns_type",
",",
"name",
")",
":",
"try",
":",
"record",
"=",
"[",
"record",
"for",
"record",
"in",
"self",
".",
"dns_records",
"if",
"record",
"[",
"'type'",
"]",
"==",
"dns_type",
"and",
"record",
"[",
"'name'",... | Get a dns record
:param dns_type:
:param name:
:return: | [
"Get",
"a",
"dns",
"record",
":",
"param",
"dns_type",
":",
":",
"param",
"name",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L120-L134 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.create_record | def create_record(self, dns_type, name, content, **kwargs):
"""
Create a dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
data = {
'type': dns_type,
'name': name,
'content': co... | python | def create_record(self, dns_type, name, content, **kwargs):
"""
Create a dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
data = {
'type': dns_type,
'name': name,
'content': co... | [
"def",
"create_record",
"(",
"self",
",",
"dns_type",
",",
"name",
",",
"content",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'type'",
":",
"dns_type",
",",
"'name'",
":",
"name",
",",
"'content'",
":",
"content",
"}",
"if",
"kwargs",
".",... | Create a dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return: | [
"Create",
"a",
"dns",
"record",
":",
"param",
"dns_type",
":",
":",
"param",
"name",
":",
":",
"param",
"content",
":",
":",
"param",
"kwargs",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L136-L162 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.update_record | def update_record(self, dns_type, name, content, **kwargs):
"""
Update dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
record = self.get_record(dns_type, name)
data = {
'type': dns_type,
... | python | def update_record(self, dns_type, name, content, **kwargs):
"""
Update dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
record = self.get_record(dns_type, name)
data = {
'type': dns_type,
... | [
"def",
"update_record",
"(",
"self",
",",
"dns_type",
",",
"name",
",",
"content",
",",
"*",
"*",
"kwargs",
")",
":",
"record",
"=",
"self",
".",
"get_record",
"(",
"dns_type",
",",
"name",
")",
"data",
"=",
"{",
"'type'",
":",
"dns_type",
",",
"'nam... | Update dns record
:param dns_type:
:param name:
:param content:
:param kwargs:
:return: | [
"Update",
"dns",
"record",
":",
"param",
"dns_type",
":",
":",
"param",
"name",
":",
":",
"param",
"content",
":",
":",
"param",
"kwargs",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L164-L191 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.create_or_update_record | def create_or_update_record(self, dns_type, name, content, **kwargs):
"""
Create a dns record. Update it if the record already exists.
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
try:
return self.update_rec... | python | def create_or_update_record(self, dns_type, name, content, **kwargs):
"""
Create a dns record. Update it if the record already exists.
:param dns_type:
:param name:
:param content:
:param kwargs:
:return:
"""
try:
return self.update_rec... | [
"def",
"create_or_update_record",
"(",
"self",
",",
"dns_type",
",",
"name",
",",
"content",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"self",
".",
"update_record",
"(",
"dns_type",
",",
"name",
",",
"content",
",",
"*",
"*",
"kwargs",
"... | Create a dns record. Update it if the record already exists.
:param dns_type:
:param name:
:param content:
:param kwargs:
:return: | [
"Create",
"a",
"dns",
"record",
".",
"Update",
"it",
"if",
"the",
"record",
"already",
"exists",
".",
":",
"param",
"dns_type",
":",
":",
"param",
"name",
":",
":",
"param",
"content",
":",
":",
"param",
"kwargs",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L193-L205 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.delete_record | def delete_record(self, dns_type, name):
"""
Delete a dns record
:param dns_type:
:param name:
:return:
"""
record = self.get_record(dns_type, name)
content = self.request(
urllib.parse.urljoin(self.api_url, self.zone['id'] + '/dns_records/' + ... | python | def delete_record(self, dns_type, name):
"""
Delete a dns record
:param dns_type:
:param name:
:return:
"""
record = self.get_record(dns_type, name)
content = self.request(
urllib.parse.urljoin(self.api_url, self.zone['id'] + '/dns_records/' + ... | [
"def",
"delete_record",
"(",
"self",
",",
"dns_type",
",",
"name",
")",
":",
"record",
"=",
"self",
".",
"get_record",
"(",
"dns_type",
",",
"name",
")",
"content",
"=",
"self",
".",
"request",
"(",
"urllib",
".",
"parse",
".",
"urljoin",
"(",
"self",
... | Delete a dns record
:param dns_type:
:param name:
:return: | [
"Delete",
"a",
"dns",
"record",
":",
"param",
"dns_type",
":",
":",
"param",
"name",
":",
":",
"return",
":"
] | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L207-L219 |
ailionx/cloudflare-ddns | cloudflare_ddns/cloudflare.py | CloudFlare.sync_dns_from_my_ip | def sync_dns_from_my_ip(self, dns_type='A'):
"""
Sync dns from my public ip address.
It will not do update if ip address in dns record is already same as
current public ip address.
:param dns_type:
:return:
"""
ip_address = ''
for finder in self.pu... | python | def sync_dns_from_my_ip(self, dns_type='A'):
"""
Sync dns from my public ip address.
It will not do update if ip address in dns record is already same as
current public ip address.
:param dns_type:
:return:
"""
ip_address = ''
for finder in self.pu... | [
"def",
"sync_dns_from_my_ip",
"(",
"self",
",",
"dns_type",
"=",
"'A'",
")",
":",
"ip_address",
"=",
"''",
"for",
"finder",
"in",
"self",
".",
"public_ip_finder",
":",
"try",
":",
"result",
"=",
"requests",
".",
"get",
"(",
"finder",
")",
"except",
"requ... | Sync dns from my public ip address.
It will not do update if ip address in dns record is already same as
current public ip address.
:param dns_type:
:return: | [
"Sync",
"dns",
"from",
"my",
"public",
"ip",
"address",
".",
"It",
"will",
"not",
"do",
"update",
"if",
"ip",
"address",
"in",
"dns",
"record",
"is",
"already",
"same",
"as",
"current",
"public",
"ip",
"address",
".",
":",
"param",
"dns_type",
":",
":"... | train | https://github.com/ailionx/cloudflare-ddns/blob/e4808b8314e447f69fab77b5bd3880846e59adbe/cloudflare_ddns/cloudflare.py#L221-L272 |
azavea/python-omgeo | omgeo/processor.py | _Processor._init_helper | def _init_helper(self, vars_):
"""Overwrite defaults (if they exist) with arguments passed to constructor"""
for k in vars_:
if k == 'kwargs':
for kwarg in vars_[k]:
setattr(self, kwarg, vars_[k][kwarg])
elif k != 'self':
setatt... | python | def _init_helper(self, vars_):
"""Overwrite defaults (if they exist) with arguments passed to constructor"""
for k in vars_:
if k == 'kwargs':
for kwarg in vars_[k]:
setattr(self, kwarg, vars_[k][kwarg])
elif k != 'self':
setatt... | [
"def",
"_init_helper",
"(",
"self",
",",
"vars_",
")",
":",
"for",
"k",
"in",
"vars_",
":",
"if",
"k",
"==",
"'kwargs'",
":",
"for",
"kwarg",
"in",
"vars_",
"[",
"k",
"]",
":",
"setattr",
"(",
"self",
",",
"kwarg",
",",
"vars_",
"[",
"k",
"]",
... | Overwrite defaults (if they exist) with arguments passed to constructor | [
"Overwrite",
"defaults",
"(",
"if",
"they",
"exist",
")",
"with",
"arguments",
"passed",
"to",
"constructor"
] | train | https://github.com/azavea/python-omgeo/blob/40f4e006f087dbc795a5d954ffa2c0eab433f8c9/omgeo/processor.py#L2-L9 |
morpframework/morpfw | morpfw/authn/pas/group/view.py | list_members | def list_members(context, request):
"""Return the list of users in the group."""
members = context.members()
return {
'users': [{
'username': m.identifier,
'userid': m.userid,
'roles': context.get_member_roles(m.userid),
'links': [rellink(m, request)]
... | python | def list_members(context, request):
"""Return the list of users in the group."""
members = context.members()
return {
'users': [{
'username': m.identifier,
'userid': m.userid,
'roles': context.get_member_roles(m.userid),
'links': [rellink(m, request)]
... | [
"def",
"list_members",
"(",
"context",
",",
"request",
")",
":",
"members",
"=",
"context",
".",
"members",
"(",
")",
"return",
"{",
"'users'",
":",
"[",
"{",
"'username'",
":",
"m",
".",
"identifier",
",",
"'userid'",
":",
"m",
".",
"userid",
",",
"... | Return the list of users in the group. | [
"Return",
"the",
"list",
"of",
"users",
"in",
"the",
"group",
"."
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/group/view.py#L16-L26 |
morpframework/morpfw | morpfw/authn/pas/group/view.py | grant_member | def grant_member(context, request):
"""Grant member roles in the group."""
mapping = request.json['mapping']
for entry in mapping:
user = entry['user']
roles = entry['roles']
username = user.get('username', None)
userid = user.get('userid', None)
if userid:
... | python | def grant_member(context, request):
"""Grant member roles in the group."""
mapping = request.json['mapping']
for entry in mapping:
user = entry['user']
roles = entry['roles']
username = user.get('username', None)
userid = user.get('userid', None)
if userid:
... | [
"def",
"grant_member",
"(",
"context",
",",
"request",
")",
":",
"mapping",
"=",
"request",
".",
"json",
"[",
"'mapping'",
"]",
"for",
"entry",
"in",
"mapping",
":",
"user",
"=",
"entry",
"[",
"'user'",
"]",
"roles",
"=",
"entry",
"[",
"'roles'",
"]",
... | Grant member roles in the group. | [
"Grant",
"member",
"roles",
"in",
"the",
"group",
"."
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/group/view.py#L31-L50 |
morpframework/morpfw | morpfw/authn/pas/group/view.py | revoke_member | def revoke_member(context, request):
"""Revoke member roles in the group."""
mapping = request.json['mapping']
for entry in mapping:
user = entry['user']
roles = entry['roles']
username = user.get('username', None)
userid = user.get('userid', None)
if userid:
... | python | def revoke_member(context, request):
"""Revoke member roles in the group."""
mapping = request.json['mapping']
for entry in mapping:
user = entry['user']
roles = entry['roles']
username = user.get('username', None)
userid = user.get('userid', None)
if userid:
... | [
"def",
"revoke_member",
"(",
"context",
",",
"request",
")",
":",
"mapping",
"=",
"request",
".",
"json",
"[",
"'mapping'",
"]",
"for",
"entry",
"in",
"mapping",
":",
"user",
"=",
"entry",
"[",
"'user'",
"]",
"roles",
"=",
"entry",
"[",
"'roles'",
"]",... | Revoke member roles in the group. | [
"Revoke",
"member",
"roles",
"in",
"the",
"group",
"."
] | train | https://github.com/morpframework/morpfw/blob/803fbf29714e6f29456482f1cfbdbd4922b020b0/morpfw/authn/pas/group/view.py#L55-L75 |
bbayles/vod_metadata | vod_metadata/media_info.py | call_MediaInfo | def call_MediaInfo(file_name, mediainfo_path=None):
"""Returns a dictionary of dictionaries with the output of
MediaInfo -f file_name"""
if mediainfo_path is None:
mediainfo_path = find_MediaInfo()
result = subprocess.check_output(
[mediainfo_path, "-f", file_name], universal_newline... | python | def call_MediaInfo(file_name, mediainfo_path=None):
"""Returns a dictionary of dictionaries with the output of
MediaInfo -f file_name"""
if mediainfo_path is None:
mediainfo_path = find_MediaInfo()
result = subprocess.check_output(
[mediainfo_path, "-f", file_name], universal_newline... | [
"def",
"call_MediaInfo",
"(",
"file_name",
",",
"mediainfo_path",
"=",
"None",
")",
":",
"if",
"mediainfo_path",
"is",
"None",
":",
"mediainfo_path",
"=",
"find_MediaInfo",
"(",
")",
"result",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"mediainfo_path",
... | Returns a dictionary of dictionaries with the output of
MediaInfo -f file_name | [
"Returns",
"a",
"dictionary",
"of",
"dictionaries",
"with",
"the",
"output",
"of",
"MediaInfo",
"-",
"f",
"file_name"
] | train | https://github.com/bbayles/vod_metadata/blob/d91c5766864e0c4f274b0e887c57a026d25a5ac5/vod_metadata/media_info.py#L25-L50 |
bbayles/vod_metadata | vod_metadata/media_info.py | check_video | def check_video(file_name, mediainfo_path=None):
"""
Scans the given file with MediaInfo and returns the video and audio codec
information if all the required parameters were found.
"""
D = call_MediaInfo(file_name, mediainfo_path)
err_msg = "Could not determine all video paramters"
if ("Ge... | python | def check_video(file_name, mediainfo_path=None):
"""
Scans the given file with MediaInfo and returns the video and audio codec
information if all the required parameters were found.
"""
D = call_MediaInfo(file_name, mediainfo_path)
err_msg = "Could not determine all video paramters"
if ("Ge... | [
"def",
"check_video",
"(",
"file_name",
",",
"mediainfo_path",
"=",
"None",
")",
":",
"D",
"=",
"call_MediaInfo",
"(",
"file_name",
",",
"mediainfo_path",
")",
"err_msg",
"=",
"\"Could not determine all video paramters\"",
"if",
"(",
"\"General\"",
"not",
"in",
"D... | Scans the given file with MediaInfo and returns the video and audio codec
information if all the required parameters were found. | [
"Scans",
"the",
"given",
"file",
"with",
"MediaInfo",
"and",
"returns",
"the",
"video",
"and",
"audio",
"codec",
"information",
"if",
"all",
"the",
"required",
"parameters",
"were",
"found",
"."
] | train | https://github.com/bbayles/vod_metadata/blob/d91c5766864e0c4f274b0e887c57a026d25a5ac5/vod_metadata/media_info.py#L53-L78 |
bbayles/vod_metadata | vod_metadata/media_info.py | check_picture | def check_picture(file_name, mediainfo_path=None):
"""
Scans the given file with MediaInfo and returns the picture
information if all the required parameters were found.
"""
D = call_MediaInfo(file_name, mediainfo_path)
# Check that the file analyzed was a valid movie
if (
("Image" n... | python | def check_picture(file_name, mediainfo_path=None):
"""
Scans the given file with MediaInfo and returns the picture
information if all the required parameters were found.
"""
D = call_MediaInfo(file_name, mediainfo_path)
# Check that the file analyzed was a valid movie
if (
("Image" n... | [
"def",
"check_picture",
"(",
"file_name",
",",
"mediainfo_path",
"=",
"None",
")",
":",
"D",
"=",
"call_MediaInfo",
"(",
"file_name",
",",
"mediainfo_path",
")",
"# Check that the file analyzed was a valid movie",
"if",
"(",
"(",
"\"Image\"",
"not",
"in",
"D",
")"... | Scans the given file with MediaInfo and returns the picture
information if all the required parameters were found. | [
"Scans",
"the",
"given",
"file",
"with",
"MediaInfo",
"and",
"returns",
"the",
"picture",
"information",
"if",
"all",
"the",
"required",
"parameters",
"were",
"found",
"."
] | train | https://github.com/bbayles/vod_metadata/blob/d91c5766864e0c4f274b0e887c57a026d25a5ac5/vod_metadata/media_info.py#L81-L95 |
bbayles/vod_metadata | vod_metadata/md5_calc.py | md5_checksum | def md5_checksum(file_path, chunk_bytes=4194304):
"""Return the MD5 checksum (hex digest) of the file"""
with open(file_path, "rb") as infile:
checksum = hashlib.md5()
while 1:
data = infile.read(chunk_bytes)
if not data:
break
checksum.update... | python | def md5_checksum(file_path, chunk_bytes=4194304):
"""Return the MD5 checksum (hex digest) of the file"""
with open(file_path, "rb") as infile:
checksum = hashlib.md5()
while 1:
data = infile.read(chunk_bytes)
if not data:
break
checksum.update... | [
"def",
"md5_checksum",
"(",
"file_path",
",",
"chunk_bytes",
"=",
"4194304",
")",
":",
"with",
"open",
"(",
"file_path",
",",
"\"rb\"",
")",
"as",
"infile",
":",
"checksum",
"=",
"hashlib",
".",
"md5",
"(",
")",
"while",
"1",
":",
"data",
"=",
"infile"... | Return the MD5 checksum (hex digest) of the file | [
"Return",
"the",
"MD5",
"checksum",
"(",
"hex",
"digest",
")",
"of",
"the",
"file"
] | train | https://github.com/bbayles/vod_metadata/blob/d91c5766864e0c4f274b0e887c57a026d25a5ac5/vod_metadata/md5_calc.py#L7-L18 |
Cornices/cornice.ext.sphinx | cornice_sphinx/__init__.py | trim | def trim(docstring):
"""
Remove the tabs to spaces, and remove the extra spaces / tabs that are in
front of the text in docstrings.
Implementation taken from http://www.python.org/dev/peps/pep-0257/
"""
if not docstring:
return ''
# Convert tabs to spaces (following the normal Pytho... | python | def trim(docstring):
"""
Remove the tabs to spaces, and remove the extra spaces / tabs that are in
front of the text in docstrings.
Implementation taken from http://www.python.org/dev/peps/pep-0257/
"""
if not docstring:
return ''
# Convert tabs to spaces (following the normal Pytho... | [
"def",
"trim",
"(",
"docstring",
")",
":",
"if",
"not",
"docstring",
":",
"return",
"''",
"# Convert tabs to spaces (following the normal Python rules)",
"# and split into a list of lines:",
"lines",
"=",
"docstring",
".",
"expandtabs",
"(",
")",
".",
"splitlines",
"(",... | Remove the tabs to spaces, and remove the extra spaces / tabs that are in
front of the text in docstrings.
Implementation taken from http://www.python.org/dev/peps/pep-0257/ | [
"Remove",
"the",
"tabs",
"to",
"spaces",
"and",
"remove",
"the",
"extra",
"spaces",
"/",
"tabs",
"that",
"are",
"in",
"front",
"of",
"the",
"text",
"in",
"docstrings",
"."
] | train | https://github.com/Cornices/cornice.ext.sphinx/blob/f73fdcc94d78fb5c94262adb9adc187c96378a53/cornice_sphinx/__init__.py#L240-L272 |
Cornices/cornice.ext.sphinx | cornice_sphinx/__init__.py | ServiceDirective._get_attributes | def _get_attributes(schema, location):
"""Return the schema's children, filtered by location."""
schema = DottedNameResolver(__name__).maybe_resolve(schema)
def _filter(attr):
if not hasattr(attr, "location"):
valid_location = 'body' in location
else:
... | python | def _get_attributes(schema, location):
"""Return the schema's children, filtered by location."""
schema = DottedNameResolver(__name__).maybe_resolve(schema)
def _filter(attr):
if not hasattr(attr, "location"):
valid_location = 'body' in location
else:
... | [
"def",
"_get_attributes",
"(",
"schema",
",",
"location",
")",
":",
"schema",
"=",
"DottedNameResolver",
"(",
"__name__",
")",
".",
"maybe_resolve",
"(",
"schema",
")",
"def",
"_filter",
"(",
"attr",
")",
":",
"if",
"not",
"hasattr",
"(",
"attr",
",",
"\... | Return the schema's children, filtered by location. | [
"Return",
"the",
"schema",
"s",
"children",
"filtered",
"by",
"location",
"."
] | train | https://github.com/Cornices/cornice.ext.sphinx/blob/f73fdcc94d78fb5c94262adb9adc187c96378a53/cornice_sphinx/__init__.py#L117-L128 |
achimnol/aiotools | src/aiotools/server.py | _main_ctxmgr | def _main_ctxmgr(func):
'''
A decorator wrapper for :class:`ServerMainContextManager`
Usage example:
.. code:: python
@aiotools.main
def mymain():
server_args = do_init()
stop_sig = yield server_args
if stop_sig == signal.SIGINT:
do_gracef... | python | def _main_ctxmgr(func):
'''
A decorator wrapper for :class:`ServerMainContextManager`
Usage example:
.. code:: python
@aiotools.main
def mymain():
server_args = do_init()
stop_sig = yield server_args
if stop_sig == signal.SIGINT:
do_gracef... | [
"def",
"_main_ctxmgr",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"helper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"ServerMainContextManager",
"(",
"func",
",",
"args",
",",
"kwargs",
")",
... | A decorator wrapper for :class:`ServerMainContextManager`
Usage example:
.. code:: python
@aiotools.main
def mymain():
server_args = do_init()
stop_sig = yield server_args
if stop_sig == signal.SIGINT:
do_graceful_shutdown()
else:
... | [
"A",
"decorator",
"wrapper",
"for",
":",
"class",
":",
"ServerMainContextManager"
] | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/server.py#L198-L220 |
achimnol/aiotools | src/aiotools/server.py | start_server | def start_server(worker_actxmgr: AsyncServerContextManager,
main_ctxmgr: Optional[ServerMainContextManager] = None,
extra_procs: Iterable[Callable] = tuple(),
stop_signals: Iterable[signal.Signals] = (
signal.SIGINT,
signal.SIG... | python | def start_server(worker_actxmgr: AsyncServerContextManager,
main_ctxmgr: Optional[ServerMainContextManager] = None,
extra_procs: Iterable[Callable] = tuple(),
stop_signals: Iterable[signal.Signals] = (
signal.SIGINT,
signal.SIG... | [
"def",
"start_server",
"(",
"worker_actxmgr",
":",
"AsyncServerContextManager",
",",
"main_ctxmgr",
":",
"Optional",
"[",
"ServerMainContextManager",
"]",
"=",
"None",
",",
"extra_procs",
":",
"Iterable",
"[",
"Callable",
"]",
"=",
"tuple",
"(",
")",
",",
"stop_... | Starts a multi-process server where each process has their own individual
asyncio event loop. Their lifecycles are automantically managed -- if the
main program receives one of the signals specified in ``stop_signals`` it
will initiate the shutdown routines on each worker that stops the event
loop grac... | [
"Starts",
"a",
"multi",
"-",
"process",
"server",
"where",
"each",
"process",
"has",
"their",
"own",
"individual",
"asyncio",
"event",
"loop",
".",
"Their",
"lifecycles",
"are",
"automantically",
"managed",
"--",
"if",
"the",
"main",
"program",
"receives",
"on... | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/server.py#L314-L543 |
dims/etcd3-gateway | etcd3gw/lock.py | Lock.acquire | def acquire(self):
"""Acquire the lock."""
self.lease = self.client.lease(self.ttl)
base64_key = _encode(self.key)
base64_value = _encode(self._uuid)
txn = {
'compare': [{
'key': base64_key,
'result': 'EQUAL',
'target':... | python | def acquire(self):
"""Acquire the lock."""
self.lease = self.client.lease(self.ttl)
base64_key = _encode(self.key)
base64_value = _encode(self._uuid)
txn = {
'compare': [{
'key': base64_key,
'result': 'EQUAL',
'target':... | [
"def",
"acquire",
"(",
"self",
")",
":",
"self",
".",
"lease",
"=",
"self",
".",
"client",
".",
"lease",
"(",
"self",
".",
"ttl",
")",
"base64_key",
"=",
"_encode",
"(",
"self",
".",
"key",
")",
"base64_value",
"=",
"_encode",
"(",
"self",
".",
"_u... | Acquire the lock. | [
"Acquire",
"the",
"lock",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lock.py#L41-L70 |
dims/etcd3-gateway | etcd3gw/lock.py | Lock.release | def release(self):
"""Release the lock"""
base64_key = _encode(self.key)
base64_value = _encode(self._uuid)
txn = {
'compare': [{
'key': base64_key,
'result': 'EQUAL',
'target': 'VALUE',
'value': base64_value
... | python | def release(self):
"""Release the lock"""
base64_key = _encode(self.key)
base64_value = _encode(self._uuid)
txn = {
'compare': [{
'key': base64_key,
'result': 'EQUAL',
'target': 'VALUE',
'value': base64_value
... | [
"def",
"release",
"(",
"self",
")",
":",
"base64_key",
"=",
"_encode",
"(",
"self",
".",
"key",
")",
"base64_value",
"=",
"_encode",
"(",
"self",
".",
"_uuid",
")",
"txn",
"=",
"{",
"'compare'",
":",
"[",
"{",
"'key'",
":",
"base64_key",
",",
"'resul... | Release the lock | [
"Release",
"the",
"lock"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lock.py#L72-L94 |
dims/etcd3-gateway | etcd3gw/lock.py | Lock.is_acquired | def is_acquired(self):
"""Check if the lock is acquired"""
values = self.client.get(self.key)
return six.b(self._uuid) in values | python | def is_acquired(self):
"""Check if the lock is acquired"""
values = self.client.get(self.key)
return six.b(self._uuid) in values | [
"def",
"is_acquired",
"(",
"self",
")",
":",
"values",
"=",
"self",
".",
"client",
".",
"get",
"(",
"self",
".",
"key",
")",
"return",
"six",
".",
"b",
"(",
"self",
".",
"_uuid",
")",
"in",
"values"
] | Check if the lock is acquired | [
"Check",
"if",
"the",
"lock",
"is",
"acquired"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lock.py#L103-L106 |
achimnol/aiotools | src/aiotools/iter.py | aiter | async def aiter(obj, sentinel=_sentinel):
'''
Analogous to the builtin :func:`iter()`.
'''
if sentinel is _sentinel:
# Since we cannot directly return the return value of obj.__aiter__()
# as being an async-generator, we do the async-iteration here.
async for item in obj:
... | python | async def aiter(obj, sentinel=_sentinel):
'''
Analogous to the builtin :func:`iter()`.
'''
if sentinel is _sentinel:
# Since we cannot directly return the return value of obj.__aiter__()
# as being an async-generator, we do the async-iteration here.
async for item in obj:
... | [
"async",
"def",
"aiter",
"(",
"obj",
",",
"sentinel",
"=",
"_sentinel",
")",
":",
"if",
"sentinel",
"is",
"_sentinel",
":",
"# Since we cannot directly return the return value of obj.__aiter__()",
"# as being an async-generator, we do the async-iteration here.",
"async",
"for",... | Analogous to the builtin :func:`iter()`. | [
"Analogous",
"to",
"the",
"builtin",
":",
"func",
":",
"iter",
"()",
"."
] | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/iter.py#L9-L24 |
dims/etcd3-gateway | etcd3gw/client.py | client | def client(host='localhost', port=2379,
ca_cert=None, cert_key=None, cert_cert=None,
timeout=None, protocol="http"):
"""Return an instance of an Etcd3Client."""
return Etcd3Client(host=host,
port=port,
ca_cert=ca_cert,
ce... | python | def client(host='localhost', port=2379,
ca_cert=None, cert_key=None, cert_cert=None,
timeout=None, protocol="http"):
"""Return an instance of an Etcd3Client."""
return Etcd3Client(host=host,
port=port,
ca_cert=ca_cert,
ce... | [
"def",
"client",
"(",
"host",
"=",
"'localhost'",
",",
"port",
"=",
"2379",
",",
"ca_cert",
"=",
"None",
",",
"cert_key",
"=",
"None",
",",
"cert_cert",
"=",
"None",
",",
"timeout",
"=",
"None",
",",
"protocol",
"=",
"\"http\"",
")",
":",
"return",
"... | Return an instance of an Etcd3Client. | [
"Return",
"an",
"instance",
"of",
"an",
"Etcd3Client",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L402-L412 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.get_url | def get_url(self, path):
"""Construct a full url to the v3alpha API given a specific path
:param path:
:return: url
"""
host = ('[' + self.host + ']' if (self.host.find(':') != -1)
else self.host)
base_url = self.protocol + '://' + host + ':' + str(self.p... | python | def get_url(self, path):
"""Construct a full url to the v3alpha API given a specific path
:param path:
:return: url
"""
host = ('[' + self.host + ']' if (self.host.find(':') != -1)
else self.host)
base_url = self.protocol + '://' + host + ':' + str(self.p... | [
"def",
"get_url",
"(",
"self",
",",
"path",
")",
":",
"host",
"=",
"(",
"'['",
"+",
"self",
".",
"host",
"+",
"']'",
"if",
"(",
"self",
".",
"host",
".",
"find",
"(",
"':'",
")",
"!=",
"-",
"1",
")",
"else",
"self",
".",
"host",
")",
"base_ur... | Construct a full url to the v3alpha API given a specific path
:param path:
:return: url | [
"Construct",
"a",
"full",
"url",
"to",
"the",
"v3alpha",
"API",
"given",
"a",
"specific",
"path"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L63-L72 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.post | def post(self, *args, **kwargs):
"""helper method for HTTP POST
:param args:
:param kwargs:
:return: json response
"""
try:
resp = self.session.post(*args, **kwargs)
if resp.status_code in _EXCEPTIONS_BY_CODE:
raise _EXCEPTIONS_BY_... | python | def post(self, *args, **kwargs):
"""helper method for HTTP POST
:param args:
:param kwargs:
:return: json response
"""
try:
resp = self.session.post(*args, **kwargs)
if resp.status_code in _EXCEPTIONS_BY_CODE:
raise _EXCEPTIONS_BY_... | [
"def",
"post",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"resp",
"=",
"self",
".",
"session",
".",
"post",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"resp",
".",
"status_code",
"in",
"_EXCEPTIONS_BY... | helper method for HTTP POST
:param args:
:param kwargs:
:return: json response | [
"helper",
"method",
"for",
"HTTP",
"POST"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L74-L91 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.lease | def lease(self, ttl=DEFAULT_TIMEOUT):
"""Create a Lease object given a timeout
:param ttl: timeout
:return: Lease object
"""
result = self.post(self.get_url("/lease/grant"),
json={"TTL": ttl, "ID": 0})
return Lease(int(result['ID']), client=sel... | python | def lease(self, ttl=DEFAULT_TIMEOUT):
"""Create a Lease object given a timeout
:param ttl: timeout
:return: Lease object
"""
result = self.post(self.get_url("/lease/grant"),
json={"TTL": ttl, "ID": 0})
return Lease(int(result['ID']), client=sel... | [
"def",
"lease",
"(",
"self",
",",
"ttl",
"=",
"DEFAULT_TIMEOUT",
")",
":",
"result",
"=",
"self",
".",
"post",
"(",
"self",
".",
"get_url",
"(",
"\"/lease/grant\"",
")",
",",
"json",
"=",
"{",
"\"TTL\"",
":",
"ttl",
",",
"\"ID\"",
":",
"0",
"}",
")... | Create a Lease object given a timeout
:param ttl: timeout
:return: Lease object | [
"Create",
"a",
"Lease",
"object",
"given",
"a",
"timeout"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L110-L118 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.lock | def lock(self, id=str(uuid.uuid4()), ttl=DEFAULT_TIMEOUT):
"""Create a Lock object given an ID and timeout
:param id: ID for the lock, creates a new uuid if not provided
:param ttl: timeout
:return: Lock object
"""
return Lock(id, ttl=ttl, client=self) | python | def lock(self, id=str(uuid.uuid4()), ttl=DEFAULT_TIMEOUT):
"""Create a Lock object given an ID and timeout
:param id: ID for the lock, creates a new uuid if not provided
:param ttl: timeout
:return: Lock object
"""
return Lock(id, ttl=ttl, client=self) | [
"def",
"lock",
"(",
"self",
",",
"id",
"=",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
",",
"ttl",
"=",
"DEFAULT_TIMEOUT",
")",
":",
"return",
"Lock",
"(",
"id",
",",
"ttl",
"=",
"ttl",
",",
"client",
"=",
"self",
")"
] | Create a Lock object given an ID and timeout
:param id: ID for the lock, creates a new uuid if not provided
:param ttl: timeout
:return: Lock object | [
"Create",
"a",
"Lock",
"object",
"given",
"an",
"ID",
"and",
"timeout"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L120-L127 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.create | def create(self, key, value):
"""Atomically create the given key only if the key doesn't exist.
This verifies that the create_revision of a key equales to 0, then
creates the key with the value.
This operation takes place in a transaction.
:param key: key in etcd to create
... | python | def create(self, key, value):
"""Atomically create the given key only if the key doesn't exist.
This verifies that the create_revision of a key equales to 0, then
creates the key with the value.
This operation takes place in a transaction.
:param key: key in etcd to create
... | [
"def",
"create",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"base64_key",
"=",
"_encode",
"(",
"key",
")",
"base64_value",
"=",
"_encode",
"(",
"value",
")",
"txn",
"=",
"{",
"'compare'",
":",
"[",
"{",
"'key'",
":",
"base64_key",
",",
"'result... | Atomically create the given key only if the key doesn't exist.
This verifies that the create_revision of a key equales to 0, then
creates the key with the value.
This operation takes place in a transaction.
:param key: key in etcd to create
:param value: value of the key
... | [
"Atomically",
"create",
"the",
"given",
"key",
"only",
"if",
"the",
"key",
"doesn",
"t",
"exist",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L129-L163 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.put | def put(self, key, value, lease=None):
"""Put puts the given key into the key-value store.
A put request increments the revision of the key-value store
and generates one event in the event history.
:param key:
:param value:
:param lease:
:return: boolean
... | python | def put(self, key, value, lease=None):
"""Put puts the given key into the key-value store.
A put request increments the revision of the key-value store
and generates one event in the event history.
:param key:
:param value:
:param lease:
:return: boolean
... | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
",",
"lease",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"\"key\"",
":",
"_encode",
"(",
"key",
")",
",",
"\"value\"",
":",
"_encode",
"(",
"value",
")",
"}",
"if",
"lease",
":",
"payload",
"[... | Put puts the given key into the key-value store.
A put request increments the revision of the key-value store
and generates one event in the event history.
:param key:
:param value:
:param lease:
:return: boolean | [
"Put",
"puts",
"the",
"given",
"key",
"into",
"the",
"key",
"-",
"value",
"store",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L165-L183 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.get | def get(self, key, metadata=False, sort_order=None,
sort_target=None, **kwargs):
"""Range gets the keys in the range from the key-value store.
:param key:
:param metadata:
:param sort_order: 'ascend' or 'descend' or None
:param sort_target: 'key' or 'version' or 'cre... | python | def get(self, key, metadata=False, sort_order=None,
sort_target=None, **kwargs):
"""Range gets the keys in the range from the key-value store.
:param key:
:param metadata:
:param sort_order: 'ascend' or 'descend' or None
:param sort_target: 'key' or 'version' or 'cre... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"metadata",
"=",
"False",
",",
"sort_order",
"=",
"None",
",",
"sort_target",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"order",
"=",
"0",
"if",
"sort_order",
":",
"order",
"=",
"_SORT_O... | Range gets the keys in the range from the key-value store.
:param key:
:param metadata:
:param sort_order: 'ascend' or 'descend' or None
:param sort_target: 'key' or 'version' or 'create' or 'mod' or 'value'
:param kwargs:
:return: | [
"Range",
"gets",
"the",
"keys",
"in",
"the",
"range",
"from",
"the",
"key",
"-",
"value",
"store",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L185-L230 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.get_all | def get_all(self, sort_order=None, sort_target='key'):
"""Get all keys currently stored in etcd.
:returns: sequence of (value, metadata) tuples
"""
return self.get(
key=_encode(b'\0'),
metadata=True,
sort_order=sort_order,
sort_target=sort... | python | def get_all(self, sort_order=None, sort_target='key'):
"""Get all keys currently stored in etcd.
:returns: sequence of (value, metadata) tuples
"""
return self.get(
key=_encode(b'\0'),
metadata=True,
sort_order=sort_order,
sort_target=sort... | [
"def",
"get_all",
"(",
"self",
",",
"sort_order",
"=",
"None",
",",
"sort_target",
"=",
"'key'",
")",
":",
"return",
"self",
".",
"get",
"(",
"key",
"=",
"_encode",
"(",
"b'\\0'",
")",
",",
"metadata",
"=",
"True",
",",
"sort_order",
"=",
"sort_order",... | Get all keys currently stored in etcd.
:returns: sequence of (value, metadata) tuples | [
"Get",
"all",
"keys",
"currently",
"stored",
"in",
"etcd",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L232-L243 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.get_prefix | def get_prefix(self, key_prefix, sort_order=None, sort_target=None):
"""Get a range of keys with a prefix.
:param sort_order: 'ascend' or 'descend' or None
:param key_prefix: first key in range
:returns: sequence of (value, metadata) tuples
"""
return self.get(key_prefi... | python | def get_prefix(self, key_prefix, sort_order=None, sort_target=None):
"""Get a range of keys with a prefix.
:param sort_order: 'ascend' or 'descend' or None
:param key_prefix: first key in range
:returns: sequence of (value, metadata) tuples
"""
return self.get(key_prefi... | [
"def",
"get_prefix",
"(",
"self",
",",
"key_prefix",
",",
"sort_order",
"=",
"None",
",",
"sort_target",
"=",
"None",
")",
":",
"return",
"self",
".",
"get",
"(",
"key_prefix",
",",
"metadata",
"=",
"True",
",",
"range_end",
"=",
"_encode",
"(",
"_increm... | Get a range of keys with a prefix.
:param sort_order: 'ascend' or 'descend' or None
:param key_prefix: first key in range
:returns: sequence of (value, metadata) tuples | [
"Get",
"a",
"range",
"of",
"keys",
"with",
"a",
"prefix",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L245-L257 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.replace | def replace(self, key, initial_value, new_value):
"""Atomically replace the value of a key with a new value.
This compares the current value of a key, then replaces it with a new
value if it is equal to a specified value. This operation takes place
in a transaction.
:param key:... | python | def replace(self, key, initial_value, new_value):
"""Atomically replace the value of a key with a new value.
This compares the current value of a key, then replaces it with a new
value if it is equal to a specified value. This operation takes place
in a transaction.
:param key:... | [
"def",
"replace",
"(",
"self",
",",
"key",
",",
"initial_value",
",",
"new_value",
")",
":",
"base64_key",
"=",
"_encode",
"(",
"key",
")",
"base64_initial_value",
"=",
"_encode",
"(",
"initial_value",
")",
"base64_new_value",
"=",
"_encode",
"(",
"new_value",... | Atomically replace the value of a key with a new value.
This compares the current value of a key, then replaces it with a new
value if it is equal to a specified value. This operation takes place
in a transaction.
:param key: key in etcd to replace
:param initial_value: old val... | [
"Atomically",
"replace",
"the",
"value",
"of",
"a",
"key",
"with",
"a",
"new",
"value",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L259-L296 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.delete | def delete(self, key, **kwargs):
"""DeleteRange deletes the given range from the key-value store.
A delete request increments the revision of the key-value store and
generates a delete event in the event history for every deleted key.
:param key:
:param kwargs:
:return:... | python | def delete(self, key, **kwargs):
"""DeleteRange deletes the given range from the key-value store.
A delete request increments the revision of the key-value store and
generates a delete event in the event history for every deleted key.
:param key:
:param kwargs:
:return:... | [
"def",
"delete",
"(",
"self",
",",
"key",
",",
"*",
"*",
"kwargs",
")",
":",
"payload",
"=",
"{",
"\"key\"",
":",
"_encode",
"(",
"key",
")",
",",
"}",
"payload",
".",
"update",
"(",
"kwargs",
")",
"result",
"=",
"self",
".",
"post",
"(",
"self",... | DeleteRange deletes the given range from the key-value store.
A delete request increments the revision of the key-value store and
generates a delete event in the event history for every deleted key.
:param key:
:param kwargs:
:return: | [
"DeleteRange",
"deletes",
"the",
"given",
"range",
"from",
"the",
"key",
"-",
"value",
"store",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L298-L317 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.delete_prefix | def delete_prefix(self, key_prefix):
"""Delete a range of keys with a prefix in etcd."""
return self.delete(
key_prefix, range_end=_encode(_increment_last_byte(key_prefix))) | python | def delete_prefix(self, key_prefix):
"""Delete a range of keys with a prefix in etcd."""
return self.delete(
key_prefix, range_end=_encode(_increment_last_byte(key_prefix))) | [
"def",
"delete_prefix",
"(",
"self",
",",
"key_prefix",
")",
":",
"return",
"self",
".",
"delete",
"(",
"key_prefix",
",",
"range_end",
"=",
"_encode",
"(",
"_increment_last_byte",
"(",
"key_prefix",
")",
")",
")"
] | Delete a range of keys with a prefix in etcd. | [
"Delete",
"a",
"range",
"of",
"keys",
"with",
"a",
"prefix",
"in",
"etcd",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L319-L322 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.transaction | def transaction(self, txn):
"""Txn processes multiple requests in a single transaction.
A txn request increments the revision of the key-value store and
generates events with the same revision for every completed request.
It is not allowed to modify the same key several times within one... | python | def transaction(self, txn):
"""Txn processes multiple requests in a single transaction.
A txn request increments the revision of the key-value store and
generates events with the same revision for every completed request.
It is not allowed to modify the same key several times within one... | [
"def",
"transaction",
"(",
"self",
",",
"txn",
")",
":",
"return",
"self",
".",
"post",
"(",
"self",
".",
"get_url",
"(",
"\"/kv/txn\"",
")",
",",
"data",
"=",
"json",
".",
"dumps",
"(",
"txn",
")",
")"
] | Txn processes multiple requests in a single transaction.
A txn request increments the revision of the key-value store and
generates events with the same revision for every completed request.
It is not allowed to modify the same key several times within one txn.
:param txn:
:ret... | [
"Txn",
"processes",
"multiple",
"requests",
"in",
"a",
"single",
"transaction",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L324-L335 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.watch | def watch(self, key, **kwargs):
"""Watch a key.
:param key: key to watch
:returns: tuple of ``events_iterator`` and ``cancel``.
Use ``events_iterator`` to get the events of key changes
and ``cancel`` to cancel the watch request
"""
event_queu... | python | def watch(self, key, **kwargs):
"""Watch a key.
:param key: key to watch
:returns: tuple of ``events_iterator`` and ``cancel``.
Use ``events_iterator`` to get the events of key changes
and ``cancel`` to cancel the watch request
"""
event_queu... | [
"def",
"watch",
"(",
"self",
",",
"key",
",",
"*",
"*",
"kwargs",
")",
":",
"event_queue",
"=",
"queue",
".",
"Queue",
"(",
")",
"def",
"callback",
"(",
"event",
")",
":",
"event_queue",
".",
"put",
"(",
"event",
")",
"w",
"=",
"watch",
".",
"Wat... | Watch a key.
:param key: key to watch
:returns: tuple of ``events_iterator`` and ``cancel``.
Use ``events_iterator`` to get the events of key changes
and ``cancel`` to cancel the watch request | [
"Watch",
"a",
"key",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L337-L367 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.watch_prefix | def watch_prefix(self, key_prefix, **kwargs):
"""The same as ``watch``, but watches a range of keys with a prefix."""
kwargs['range_end'] = \
_increment_last_byte(key_prefix)
return self.watch(key_prefix, **kwargs) | python | def watch_prefix(self, key_prefix, **kwargs):
"""The same as ``watch``, but watches a range of keys with a prefix."""
kwargs['range_end'] = \
_increment_last_byte(key_prefix)
return self.watch(key_prefix, **kwargs) | [
"def",
"watch_prefix",
"(",
"self",
",",
"key_prefix",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"'range_end'",
"]",
"=",
"_increment_last_byte",
"(",
"key_prefix",
")",
"return",
"self",
".",
"watch",
"(",
"key_prefix",
",",
"*",
"*",
"kwargs",
... | The same as ``watch``, but watches a range of keys with a prefix. | [
"The",
"same",
"as",
"watch",
"but",
"watches",
"a",
"range",
"of",
"keys",
"with",
"a",
"prefix",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L369-L373 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.watch_once | def watch_once(self, key, timeout=None, **kwargs):
"""Watch a key and stops after the first event.
:param key: key to watch
:param timeout: (optional) timeout in seconds.
:returns: event
"""
event_queue = queue.Queue()
def callback(event):
event_queu... | python | def watch_once(self, key, timeout=None, **kwargs):
"""Watch a key and stops after the first event.
:param key: key to watch
:param timeout: (optional) timeout in seconds.
:returns: event
"""
event_queue = queue.Queue()
def callback(event):
event_queu... | [
"def",
"watch_once",
"(",
"self",
",",
"key",
",",
"timeout",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"event_queue",
"=",
"queue",
".",
"Queue",
"(",
")",
"def",
"callback",
"(",
"event",
")",
":",
"event_queue",
".",
"put",
"(",
"event",
"... | Watch a key and stops after the first event.
:param key: key to watch
:param timeout: (optional) timeout in seconds.
:returns: event | [
"Watch",
"a",
"key",
"and",
"stops",
"after",
"the",
"first",
"event",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L375-L393 |
dims/etcd3-gateway | etcd3gw/client.py | Etcd3Client.watch_prefix_once | def watch_prefix_once(self, key_prefix, timeout=None, **kwargs):
"""Watches a range of keys with a prefix, similar to watch_once"""
kwargs['range_end'] = \
_increment_last_byte(key_prefix)
return self.watch_once(key_prefix, timeout=timeout, **kwargs) | python | def watch_prefix_once(self, key_prefix, timeout=None, **kwargs):
"""Watches a range of keys with a prefix, similar to watch_once"""
kwargs['range_end'] = \
_increment_last_byte(key_prefix)
return self.watch_once(key_prefix, timeout=timeout, **kwargs) | [
"def",
"watch_prefix_once",
"(",
"self",
",",
"key_prefix",
",",
"timeout",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"'range_end'",
"]",
"=",
"_increment_last_byte",
"(",
"key_prefix",
")",
"return",
"self",
".",
"watch_once",
"(",
"k... | Watches a range of keys with a prefix, similar to watch_once | [
"Watches",
"a",
"range",
"of",
"keys",
"with",
"a",
"prefix",
"similar",
"to",
"watch_once"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/client.py#L395-L399 |
achimnol/aiotools | src/aiotools/timer.py | create_timer | def create_timer(cb: Callable[[float], None], interval: float,
delay_policy: TimerDelayPolicy = TimerDelayPolicy.DEFAULT,
loop: Optional[asyncio.BaseEventLoop] = None) -> asyncio.Task:
'''
Schedule a timer with the given callable and the interval in seconds.
The interval va... | python | def create_timer(cb: Callable[[float], None], interval: float,
delay_policy: TimerDelayPolicy = TimerDelayPolicy.DEFAULT,
loop: Optional[asyncio.BaseEventLoop] = None) -> asyncio.Task:
'''
Schedule a timer with the given callable and the interval in seconds.
The interval va... | [
"def",
"create_timer",
"(",
"cb",
":",
"Callable",
"[",
"[",
"float",
"]",
",",
"None",
"]",
",",
"interval",
":",
"float",
",",
"delay_policy",
":",
"TimerDelayPolicy",
"=",
"TimerDelayPolicy",
".",
"DEFAULT",
",",
"loop",
":",
"Optional",
"[",
"asyncio",... | Schedule a timer with the given callable and the interval in seconds.
The interval value is also passed to the callable.
If the callable takes longer than the timer interval, all accumulated
callable's tasks will be cancelled when the timer is cancelled.
Args:
cb: TODO - fill argument descripti... | [
"Schedule",
"a",
"timer",
"with",
"the",
"given",
"callable",
"and",
"the",
"interval",
"in",
"seconds",
".",
"The",
"interval",
"value",
"is",
"also",
"passed",
"to",
"the",
"callable",
".",
"If",
"the",
"callable",
"takes",
"longer",
"than",
"the",
"time... | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/timer.py#L21-L59 |
dims/etcd3-gateway | etcd3gw/lease.py | Lease.revoke | def revoke(self):
"""LeaseRevoke revokes a lease.
All keys attached to the lease will expire and be deleted.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the respon... | python | def revoke(self):
"""LeaseRevoke revokes a lease.
All keys attached to the lease will expire and be deleted.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the respon... | [
"def",
"revoke",
"(",
"self",
")",
":",
"self",
".",
"client",
".",
"post",
"(",
"self",
".",
"client",
".",
"get_url",
"(",
"\"/kv/lease/revoke\"",
")",
",",
"json",
"=",
"{",
"\"ID\"",
":",
"self",
".",
"id",
"}",
")",
"return",
"True"
] | LeaseRevoke revokes a lease.
All keys attached to the lease will expire and be deleted.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
:return: | [
"LeaseRevoke",
"revokes",
"a",
"lease",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lease.py#L26-L38 |
dims/etcd3-gateway | etcd3gw/lease.py | Lease.ttl | def ttl(self):
"""LeaseTimeToLive retrieves lease information.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
:return:
"""
result = sel... | python | def ttl(self):
"""LeaseTimeToLive retrieves lease information.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
:return:
"""
result = sel... | [
"def",
"ttl",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"client",
".",
"post",
"(",
"self",
".",
"client",
".",
"get_url",
"(",
"\"/kv/lease/timetolive\"",
")",
",",
"json",
"=",
"{",
"\"ID\"",
":",
"self",
".",
"id",
"}",
")",
"return",
"... | LeaseTimeToLive retrieves lease information.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
:return: | [
"LeaseTimeToLive",
"retrieves",
"lease",
"information",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lease.py#L40-L51 |
dims/etcd3-gateway | etcd3gw/lease.py | Lease.keys | def keys(self):
"""Get the keys associated with this lease.
:return:
"""
result = self.client.post(self.client.get_url("/kv/lease/timetolive"),
json={"ID": self.id,
"keys": True})
keys = result['keys'] if ... | python | def keys(self):
"""Get the keys associated with this lease.
:return:
"""
result = self.client.post(self.client.get_url("/kv/lease/timetolive"),
json={"ID": self.id,
"keys": True})
keys = result['keys'] if ... | [
"def",
"keys",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"client",
".",
"post",
"(",
"self",
".",
"client",
".",
"get_url",
"(",
"\"/kv/lease/timetolive\"",
")",
",",
"json",
"=",
"{",
"\"ID\"",
":",
"self",
".",
"id",
",",
"\"keys\"",
":",
... | Get the keys associated with this lease.
:return: | [
"Get",
"the",
"keys",
"associated",
"with",
"this",
"lease",
"."
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/lease.py#L66-L75 |
achimnol/aiotools | src/aiotools/func.py | apartial | def apartial(coro, *args, **kwargs):
'''
Wraps a coroutine function with pre-defined arguments (including keyword
arguments). It is an asynchronous version of :func:`functools.partial`.
'''
@functools.wraps(coro)
async def wrapped(*cargs, **ckwargs):
return await coro(*args, *cargs, **... | python | def apartial(coro, *args, **kwargs):
'''
Wraps a coroutine function with pre-defined arguments (including keyword
arguments). It is an asynchronous version of :func:`functools.partial`.
'''
@functools.wraps(coro)
async def wrapped(*cargs, **ckwargs):
return await coro(*args, *cargs, **... | [
"def",
"apartial",
"(",
"coro",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"coro",
")",
"async",
"def",
"wrapped",
"(",
"*",
"cargs",
",",
"*",
"*",
"ckwargs",
")",
":",
"return",
"await",
"coro",
"(... | Wraps a coroutine function with pre-defined arguments (including keyword
arguments). It is an asynchronous version of :func:`functools.partial`. | [
"Wraps",
"a",
"coroutine",
"function",
"with",
"pre",
"-",
"defined",
"arguments",
"(",
"including",
"keyword",
"arguments",
")",
".",
"It",
"is",
"an",
"asynchronous",
"version",
"of",
":",
"func",
":",
"functools",
".",
"partial",
"."
] | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/func.py#L14-L24 |
achimnol/aiotools | src/aiotools/func.py | lru_cache | def lru_cache(maxsize: int = 128,
typed: bool = False,
expire_after: float = None):
'''
A simple LRU cache just like :func:`functools.lru_cache`, but it works for
coroutines. This is not as heavily optimized as :func:`functools.lru_cache`
which uses an internal C implementat... | python | def lru_cache(maxsize: int = 128,
typed: bool = False,
expire_after: float = None):
'''
A simple LRU cache just like :func:`functools.lru_cache`, but it works for
coroutines. This is not as heavily optimized as :func:`functools.lru_cache`
which uses an internal C implementat... | [
"def",
"lru_cache",
"(",
"maxsize",
":",
"int",
"=",
"128",
",",
"typed",
":",
"bool",
"=",
"False",
",",
"expire_after",
":",
"float",
"=",
"None",
")",
":",
"if",
"maxsize",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"maxsize",
",",
"int... | A simple LRU cache just like :func:`functools.lru_cache`, but it works for
coroutines. This is not as heavily optimized as :func:`functools.lru_cache`
which uses an internal C implementation, as it targets async operations
that take a long time.
It follows the same API that the standard functools prov... | [
"A",
"simple",
"LRU",
"cache",
"just",
"like",
":",
"func",
":",
"functools",
".",
"lru_cache",
"but",
"it",
"works",
"for",
"coroutines",
".",
"This",
"is",
"not",
"as",
"heavily",
"optimized",
"as",
":",
"func",
":",
"functools",
".",
"lru_cache",
"whi... | train | https://github.com/achimnol/aiotools/blob/9efc66a01fbd287f70ee3a937203d466aac4a765/src/aiotools/func.py#L27-L107 |
embedly/embedly-python | embedly/client.py | Embedly.get_services | def get_services(self):
"""
get_services makes call to services end point of api.embed.ly to fetch
the list of supported providers and their regexes
"""
if self.services:
return self.services
url = 'http://api.embed.ly/1/services/python'
http = http... | python | def get_services(self):
"""
get_services makes call to services end point of api.embed.ly to fetch
the list of supported providers and their regexes
"""
if self.services:
return self.services
url = 'http://api.embed.ly/1/services/python'
http = http... | [
"def",
"get_services",
"(",
"self",
")",
":",
"if",
"self",
".",
"services",
":",
"return",
"self",
".",
"services",
"url",
"=",
"'http://api.embed.ly/1/services/python'",
"http",
"=",
"httplib2",
".",
"Http",
"(",
"timeout",
"=",
"self",
".",
"timeout",
")"... | get_services makes call to services end point of api.embed.ly to fetch
the list of supported providers and their regexes | [
"get_services",
"makes",
"call",
"to",
"services",
"end",
"point",
"of",
"api",
".",
"embed",
".",
"ly",
"to",
"fetch",
"the",
"list",
"of",
"supported",
"providers",
"and",
"their",
"regexes"
] | train | https://github.com/embedly/embedly-python/blob/314d74989411c1dd690cd004377f9108d0d1feb1/embedly/client.py#L46-L73 |
embedly/embedly-python | embedly/client.py | Embedly._get | def _get(self, version, method, url_or_urls, **kwargs):
"""
_get makes the actual call to api.embed.ly
"""
if not url_or_urls:
raise ValueError('%s requires a url or a list of urls given: %s' %
(method.title(), url_or_urls))
# a flag we c... | python | def _get(self, version, method, url_or_urls, **kwargs):
"""
_get makes the actual call to api.embed.ly
"""
if not url_or_urls:
raise ValueError('%s requires a url or a list of urls given: %s' %
(method.title(), url_or_urls))
# a flag we c... | [
"def",
"_get",
"(",
"self",
",",
"version",
",",
"method",
",",
"url_or_urls",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"url_or_urls",
":",
"raise",
"ValueError",
"(",
"'%s requires a url or a list of urls given: %s'",
"%",
"(",
"method",
".",
"title",
... | _get makes the actual call to api.embed.ly | [
"_get",
"makes",
"the",
"actual",
"call",
"to",
"api",
".",
"embed",
".",
"ly"
] | train | https://github.com/embedly/embedly-python/blob/314d74989411c1dd690cd004377f9108d0d1feb1/embedly/client.py#L92-L148 |
embedly/embedly-python | embedly/py3_utils.py | python_2_unicode_compatible | def python_2_unicode_compatible(klass):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
From django.utils.encoding.py in 1.4.2+, minus the dependency on Six.
To support Python 2 and 3 with a single code base, define a __str__ method
... | python | def python_2_unicode_compatible(klass):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
From django.utils.encoding.py in 1.4.2+, minus the dependency on Six.
To support Python 2 and 3 with a single code base, define a __str__ method
... | [
"def",
"python_2_unicode_compatible",
"(",
"klass",
")",
":",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"==",
"2",
":",
"if",
"'__str__'",
"not",
"in",
"klass",
".",
"__dict__",
":",
"raise",
"ValueError",
"(",
"\"@python_2_unicode_compatible cannot be ap... | A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
From django.utils.encoding.py in 1.4.2+, minus the dependency on Six.
To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class... | [
"A",
"decorator",
"that",
"defines",
"__unicode__",
"and",
"__str__",
"methods",
"under",
"Python",
"2",
".",
"Under",
"Python",
"3",
"it",
"does",
"nothing",
"."
] | train | https://github.com/embedly/embedly-python/blob/314d74989411c1dd690cd004377f9108d0d1feb1/embedly/py3_utils.py#L11-L28 |
dims/etcd3-gateway | etcd3gw/utils.py | _encode | def _encode(data):
"""Encode the given data using base-64
:param data:
:return: base-64 encoded string
"""
if not isinstance(data, bytes_types):
data = six.b(str(data))
return base64.b64encode(data).decode("utf-8") | python | def _encode(data):
"""Encode the given data using base-64
:param data:
:return: base-64 encoded string
"""
if not isinstance(data, bytes_types):
data = six.b(str(data))
return base64.b64encode(data).decode("utf-8") | [
"def",
"_encode",
"(",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"bytes_types",
")",
":",
"data",
"=",
"six",
".",
"b",
"(",
"str",
"(",
"data",
")",
")",
"return",
"base64",
".",
"b64encode",
"(",
"data",
")",
".",
"decode",
... | Encode the given data using base-64
:param data:
:return: base-64 encoded string | [
"Encode",
"the",
"given",
"data",
"using",
"base",
"-",
"64"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/utils.py#L22-L30 |
dims/etcd3-gateway | etcd3gw/utils.py | _decode | def _decode(data):
"""Decode the base-64 encoded string
:param data:
:return: decoded data
"""
if not isinstance(data, bytes_types):
data = six.b(str(data))
return base64.b64decode(data.decode("utf-8")) | python | def _decode(data):
"""Decode the base-64 encoded string
:param data:
:return: decoded data
"""
if not isinstance(data, bytes_types):
data = six.b(str(data))
return base64.b64decode(data.decode("utf-8")) | [
"def",
"_decode",
"(",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"bytes_types",
")",
":",
"data",
"=",
"six",
".",
"b",
"(",
"str",
"(",
"data",
")",
")",
"return",
"base64",
".",
"b64decode",
"(",
"data",
".",
"decode",
"(",
... | Decode the base-64 encoded string
:param data:
:return: decoded data | [
"Decode",
"the",
"base",
"-",
"64",
"encoded",
"string"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/utils.py#L33-L41 |
dims/etcd3-gateway | etcd3gw/utils.py | _increment_last_byte | def _increment_last_byte(data):
"""Get the last byte in the array and increment it
:param bytes_string:
:return:
"""
if not isinstance(data, bytes_types):
if isinstance(data, six.string_types):
data = data.encode('utf-8')
else:
data = six.b(str(data))
s =... | python | def _increment_last_byte(data):
"""Get the last byte in the array and increment it
:param bytes_string:
:return:
"""
if not isinstance(data, bytes_types):
if isinstance(data, six.string_types):
data = data.encode('utf-8')
else:
data = six.b(str(data))
s =... | [
"def",
"_increment_last_byte",
"(",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"bytes_types",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"six",
".",
"string_types",
")",
":",
"data",
"=",
"data",
".",
"encode",
"(",
"'utf-8'",
... | Get the last byte in the array and increment it
:param bytes_string:
:return: | [
"Get",
"the",
"last",
"byte",
"in",
"the",
"array",
"and",
"increment",
"it"
] | train | https://github.com/dims/etcd3-gateway/blob/ad566c29cbde135aee20cfd32e0a4815ca3b5ee6/etcd3gw/utils.py#L44-L57 |
rackerlabs/fastfood | fastfood/book.py | CookBook.metadata | def metadata(self):
"""Return dict representation of this cookbook's metadata.rb ."""
self.metadata_path = os.path.join(self.path, 'metadata.rb')
if not os.path.isfile(self.metadata_path):
raise ValueError("Cookbook needs metadata.rb, %s"
% self.metadata_... | python | def metadata(self):
"""Return dict representation of this cookbook's metadata.rb ."""
self.metadata_path = os.path.join(self.path, 'metadata.rb')
if not os.path.isfile(self.metadata_path):
raise ValueError("Cookbook needs metadata.rb, %s"
% self.metadata_... | [
"def",
"metadata",
"(",
"self",
")",
":",
"self",
".",
"metadata_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'metadata.rb'",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"self",
".",
"metadata_path",
")",
... | Return dict representation of this cookbook's metadata.rb . | [
"Return",
"dict",
"representation",
"of",
"this",
"cookbook",
"s",
"metadata",
".",
"rb",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L49-L59 |
rackerlabs/fastfood | fastfood/book.py | CookBook.berksfile | def berksfile(self):
"""Return this cookbook's Berksfile instance."""
self.berks_path = os.path.join(self.path, 'Berksfile')
if not self._berksfile:
if not os.path.isfile(self.berks_path):
raise ValueError("No Berksfile found at %s"
% ... | python | def berksfile(self):
"""Return this cookbook's Berksfile instance."""
self.berks_path = os.path.join(self.path, 'Berksfile')
if not self._berksfile:
if not os.path.isfile(self.berks_path):
raise ValueError("No Berksfile found at %s"
% ... | [
"def",
"berksfile",
"(",
"self",
")",
":",
"self",
".",
"berks_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"path",
",",
"'Berksfile'",
")",
"if",
"not",
"self",
".",
"_berksfile",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile"... | Return this cookbook's Berksfile instance. | [
"Return",
"this",
"cookbook",
"s",
"Berksfile",
"instance",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L62-L70 |
rackerlabs/fastfood | fastfood/book.py | MetadataRb.from_dict | def from_dict(cls, dictionary):
"""Create a MetadataRb instance from a dict."""
cookbooks = set()
# put these in order
groups = [cookbooks]
for key, val in dictionary.items():
if key == 'depends':
cookbooks.update({cls.depends_statement(cbn, meta)
... | python | def from_dict(cls, dictionary):
"""Create a MetadataRb instance from a dict."""
cookbooks = set()
# put these in order
groups = [cookbooks]
for key, val in dictionary.items():
if key == 'depends':
cookbooks.update({cls.depends_statement(cbn, meta)
... | [
"def",
"from_dict",
"(",
"cls",
",",
"dictionary",
")",
":",
"cookbooks",
"=",
"set",
"(",
")",
"# put these in order",
"groups",
"=",
"[",
"cookbooks",
"]",
"for",
"key",
",",
"val",
"in",
"dictionary",
".",
"items",
"(",
")",
":",
"if",
"key",
"==",
... | Create a MetadataRb instance from a dict. | [
"Create",
"a",
"MetadataRb",
"instance",
"from",
"a",
"dict",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L78-L94 |
rackerlabs/fastfood | fastfood/book.py | MetadataRb.depends_statement | def depends_statement(cookbook_name, metadata=None):
"""Return a valid Ruby 'depends' statement for the metadata.rb file."""
line = "depends '%s'" % cookbook_name
if metadata:
if not isinstance(metadata, dict):
raise TypeError("Stencil dependency options for %s "
... | python | def depends_statement(cookbook_name, metadata=None):
"""Return a valid Ruby 'depends' statement for the metadata.rb file."""
line = "depends '%s'" % cookbook_name
if metadata:
if not isinstance(metadata, dict):
raise TypeError("Stencil dependency options for %s "
... | [
"def",
"depends_statement",
"(",
"cookbook_name",
",",
"metadata",
"=",
"None",
")",
":",
"line",
"=",
"\"depends '%s'\"",
"%",
"cookbook_name",
"if",
"metadata",
":",
"if",
"not",
"isinstance",
"(",
"metadata",
",",
"dict",
")",
":",
"raise",
"TypeError",
"... | Return a valid Ruby 'depends' statement for the metadata.rb file. | [
"Return",
"a",
"valid",
"Ruby",
"depends",
"statement",
"for",
"the",
"metadata",
".",
"rb",
"file",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L97-L107 |
rackerlabs/fastfood | fastfood/book.py | MetadataRb.parse | def parse(self):
"""Parse the metadata.rb into a dict."""
data = utils.ruby_lines(self.readlines())
data = [tuple(j.strip() for j in line.split(None, 1))
for line in data]
depends = {}
for line in data:
if not len(line) == 2:
continue
... | python | def parse(self):
"""Parse the metadata.rb into a dict."""
data = utils.ruby_lines(self.readlines())
data = [tuple(j.strip() for j in line.split(None, 1))
for line in data]
depends = {}
for line in data:
if not len(line) == 2:
continue
... | [
"def",
"parse",
"(",
"self",
")",
":",
"data",
"=",
"utils",
".",
"ruby_lines",
"(",
"self",
".",
"readlines",
"(",
")",
")",
"data",
"=",
"[",
"tuple",
"(",
"j",
".",
"strip",
"(",
")",
"for",
"j",
"in",
"line",
".",
"split",
"(",
"None",
",",... | Parse the metadata.rb into a dict. | [
"Parse",
"the",
"metadata",
".",
"rb",
"into",
"a",
"dict",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L113-L132 |
rackerlabs/fastfood | fastfood/book.py | MetadataRb.merge | def merge(self, other):
"""Add requirements from 'other' metadata.rb into this one."""
if not isinstance(other, MetadataRb):
raise TypeError("MetadataRb to merge should be a 'MetadataRb' "
"instance, not %s.", type(other))
current = self.to_dict()
... | python | def merge(self, other):
"""Add requirements from 'other' metadata.rb into this one."""
if not isinstance(other, MetadataRb):
raise TypeError("MetadataRb to merge should be a 'MetadataRb' "
"instance, not %s.", type(other))
current = self.to_dict()
... | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"isinstance",
"(",
"other",
",",
"MetadataRb",
")",
":",
"raise",
"TypeError",
"(",
"\"MetadataRb to merge should be a 'MetadataRb' \"",
"\"instance, not %s.\"",
",",
"type",
"(",
"other",
")",
")... | Add requirements from 'other' metadata.rb into this one. | [
"Add",
"requirements",
"from",
"other",
"metadata",
".",
"rb",
"into",
"this",
"one",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L134-L148 |
rackerlabs/fastfood | fastfood/book.py | Berksfile.parse | def parse(self):
"""Parse this Berksfile into a dict."""
self.flush()
self.seek(0)
data = utils.ruby_lines(self.readlines())
data = [tuple(j.strip() for j in line.split(None, 1))
for line in data]
datamap = {}
for line in data:
if len(l... | python | def parse(self):
"""Parse this Berksfile into a dict."""
self.flush()
self.seek(0)
data = utils.ruby_lines(self.readlines())
data = [tuple(j.strip() for j in line.split(None, 1))
for line in data]
datamap = {}
for line in data:
if len(l... | [
"def",
"parse",
"(",
"self",
")",
":",
"self",
".",
"flush",
"(",
")",
"self",
".",
"seek",
"(",
"0",
")",
"data",
"=",
"utils",
".",
"ruby_lines",
"(",
"self",
".",
"readlines",
"(",
")",
")",
"data",
"=",
"[",
"tuple",
"(",
"j",
".",
"strip",... | Parse this Berksfile into a dict. | [
"Parse",
"this",
"Berksfile",
"into",
"a",
"dict",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L168-L211 |
rackerlabs/fastfood | fastfood/book.py | Berksfile.from_dict | def from_dict(cls, dictionary):
"""Create a Berksfile instance from a dict."""
cookbooks = set()
sources = set()
other = set()
# put these in order
groups = [sources, cookbooks, other]
for key, val in dictionary.items():
if key == 'cookbook':
... | python | def from_dict(cls, dictionary):
"""Create a Berksfile instance from a dict."""
cookbooks = set()
sources = set()
other = set()
# put these in order
groups = [sources, cookbooks, other]
for key, val in dictionary.items():
if key == 'cookbook':
... | [
"def",
"from_dict",
"(",
"cls",
",",
"dictionary",
")",
":",
"cookbooks",
"=",
"set",
"(",
")",
"sources",
"=",
"set",
"(",
")",
"other",
"=",
"set",
"(",
")",
"# put these in order",
"groups",
"=",
"[",
"sources",
",",
"cookbooks",
",",
"other",
"]",
... | Create a Berksfile instance from a dict. | [
"Create",
"a",
"Berksfile",
"instance",
"from",
"a",
"dict",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L214-L236 |
rackerlabs/fastfood | fastfood/book.py | Berksfile.cookbook_statement | def cookbook_statement(cookbook_name, metadata=None):
"""Return a valid Ruby 'cookbook' statement for the Berksfile."""
line = "cookbook '%s'" % cookbook_name
if metadata:
if not isinstance(metadata, dict):
raise TypeError("Berksfile dependency hash for %s "
... | python | def cookbook_statement(cookbook_name, metadata=None):
"""Return a valid Ruby 'cookbook' statement for the Berksfile."""
line = "cookbook '%s'" % cookbook_name
if metadata:
if not isinstance(metadata, dict):
raise TypeError("Berksfile dependency hash for %s "
... | [
"def",
"cookbook_statement",
"(",
"cookbook_name",
",",
"metadata",
"=",
"None",
")",
":",
"line",
"=",
"\"cookbook '%s'\"",
"%",
"cookbook_name",
"if",
"metadata",
":",
"if",
"not",
"isinstance",
"(",
"metadata",
",",
"dict",
")",
":",
"raise",
"TypeError",
... | Return a valid Ruby 'cookbook' statement for the Berksfile. | [
"Return",
"a",
"valid",
"Ruby",
"cookbook",
"statement",
"for",
"the",
"Berksfile",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L239-L252 |
rackerlabs/fastfood | fastfood/book.py | Berksfile.merge | def merge(self, other):
"""Add requirements from 'other' Berksfile into this one."""
if not isinstance(other, Berksfile):
raise TypeError("Berksfile to merge should be a 'Berksfile' "
"instance, not %s.", type(other))
current = self.to_dict()
new =... | python | def merge(self, other):
"""Add requirements from 'other' Berksfile into this one."""
if not isinstance(other, Berksfile):
raise TypeError("Berksfile to merge should be a 'Berksfile' "
"instance, not %s.", type(other))
current = self.to_dict()
new =... | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"isinstance",
"(",
"other",
",",
"Berksfile",
")",
":",
"raise",
"TypeError",
"(",
"\"Berksfile to merge should be a 'Berksfile' \"",
"\"instance, not %s.\"",
",",
"type",
"(",
"other",
")",
")",
... | Add requirements from 'other' Berksfile into this one. | [
"Add",
"requirements",
"from",
"other",
"Berksfile",
"into",
"this",
"one",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/book.py#L254-L273 |
rackerlabs/fastfood | fastfood/stencil.py | StencilSet.manifest | def manifest(self):
"""The manifest definition of the stencilset as a dict."""
if not self._manifest:
with open(self.manifest_path) as man:
self._manifest = json.load(man)
return self._manifest | python | def manifest(self):
"""The manifest definition of the stencilset as a dict."""
if not self._manifest:
with open(self.manifest_path) as man:
self._manifest = json.load(man)
return self._manifest | [
"def",
"manifest",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_manifest",
":",
"with",
"open",
"(",
"self",
".",
"manifest_path",
")",
"as",
"man",
":",
"self",
".",
"_manifest",
"=",
"json",
".",
"load",
"(",
"man",
")",
"return",
"self",
"... | The manifest definition of the stencilset as a dict. | [
"The",
"manifest",
"definition",
"of",
"the",
"stencilset",
"as",
"a",
"dict",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/stencil.py#L69-L74 |
rackerlabs/fastfood | fastfood/stencil.py | StencilSet.stencils | def stencils(self):
"""List of stencils."""
if not self._stencils:
self._stencils = self.manifest['stencils']
return self._stencils | python | def stencils(self):
"""List of stencils."""
if not self._stencils:
self._stencils = self.manifest['stencils']
return self._stencils | [
"def",
"stencils",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_stencils",
":",
"self",
".",
"_stencils",
"=",
"self",
".",
"manifest",
"[",
"'stencils'",
"]",
"return",
"self",
".",
"_stencils"
] | List of stencils. | [
"List",
"of",
"stencils",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/stencil.py#L77-L81 |
rackerlabs/fastfood | fastfood/stencil.py | StencilSet.get_stencil | def get_stencil(self, stencil_name, **options):
"""Return a Stencil instance given a stencil name."""
if stencil_name not in self.manifest.get('stencils', {}):
raise ValueError("Stencil '%s' not declared in StencilSet "
"manifest." % stencil_name)
stencil... | python | def get_stencil(self, stencil_name, **options):
"""Return a Stencil instance given a stencil name."""
if stencil_name not in self.manifest.get('stencils', {}):
raise ValueError("Stencil '%s' not declared in StencilSet "
"manifest." % stencil_name)
stencil... | [
"def",
"get_stencil",
"(",
"self",
",",
"stencil_name",
",",
"*",
"*",
"options",
")",
":",
"if",
"stencil_name",
"not",
"in",
"self",
".",
"manifest",
".",
"get",
"(",
"'stencils'",
",",
"{",
"}",
")",
":",
"raise",
"ValueError",
"(",
"\"Stencil '%s' no... | Return a Stencil instance given a stencil name. | [
"Return",
"a",
"Stencil",
"instance",
"given",
"a",
"stencil",
"name",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/stencil.py#L83-L113 |
rackerlabs/fastfood | fastfood/food.py | _determine_selected_stencil | def _determine_selected_stencil(stencil_set, stencil_definition):
"""Determine appropriate stencil name for stencil definition.
Given a fastfood.json stencil definition with a stencil set, figure out
what the name of the stencil within the set should be, or use the default
"""
if 'stencil' not in s... | python | def _determine_selected_stencil(stencil_set, stencil_definition):
"""Determine appropriate stencil name for stencil definition.
Given a fastfood.json stencil definition with a stencil set, figure out
what the name of the stencil within the set should be, or use the default
"""
if 'stencil' not in s... | [
"def",
"_determine_selected_stencil",
"(",
"stencil_set",
",",
"stencil_definition",
")",
":",
"if",
"'stencil'",
"not",
"in",
"stencil_definition",
":",
"selected_stencil_name",
"=",
"stencil_set",
".",
"manifest",
".",
"get",
"(",
"'default_stencil'",
")",
"else",
... | Determine appropriate stencil name for stencil definition.
Given a fastfood.json stencil definition with a stencil set, figure out
what the name of the stencil within the set should be, or use the default | [
"Determine",
"appropriate",
"stencil",
"name",
"for",
"stencil",
"definition",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L35-L50 |
rackerlabs/fastfood | fastfood/food.py | _build_template_map | def _build_template_map(cookbook, cookbook_name, stencil):
"""Build a map of variables for this generated cookbook and stencil.
Get template variables from stencil option values, adding the default ones
like cookbook and cookbook year.
"""
template_map = {
'cookbook': {"name": cookbook_name... | python | def _build_template_map(cookbook, cookbook_name, stencil):
"""Build a map of variables for this generated cookbook and stencil.
Get template variables from stencil option values, adding the default ones
like cookbook and cookbook year.
"""
template_map = {
'cookbook': {"name": cookbook_name... | [
"def",
"_build_template_map",
"(",
"cookbook",
",",
"cookbook_name",
",",
"stencil",
")",
":",
"template_map",
"=",
"{",
"'cookbook'",
":",
"{",
"\"name\"",
":",
"cookbook_name",
"}",
",",
"'options'",
":",
"stencil",
"[",
"'options'",
"]",
"}",
"# Cookbooks m... | Build a map of variables for this generated cookbook and stencil.
Get template variables from stencil option values, adding the default ones
like cookbook and cookbook year. | [
"Build",
"a",
"map",
"of",
"variables",
"for",
"this",
"generated",
"cookbook",
"and",
"stencil",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L53-L75 |
rackerlabs/fastfood | fastfood/food.py | _render_binaries | def _render_binaries(files, written_files):
"""Write binary contents from filetable into files.
Using filetable for the input files, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and using the given open mode for the file.
"... | python | def _render_binaries(files, written_files):
"""Write binary contents from filetable into files.
Using filetable for the input files, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and using the given open mode for the file.
"... | [
"def",
"_render_binaries",
"(",
"files",
",",
"written_files",
")",
":",
"for",
"source_path",
",",
"target_path",
"in",
"files",
".",
"items",
"(",
")",
":",
"needdir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"target_path",
")",
"assert",
"needdir",
... | Write binary contents from filetable into files.
Using filetable for the input files, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and using the given open mode for the file. | [
"Write",
"binary",
"contents",
"from",
"filetable",
"into",
"files",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L78-L108 |
rackerlabs/fastfood | fastfood/food.py | _render_templates | def _render_templates(files, filetable, written_files, force, open_mode='w'):
"""Write template contents from filetable into files.
Using filetable for the rendered templates, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and us... | python | def _render_templates(files, filetable, written_files, force, open_mode='w'):
"""Write template contents from filetable into files.
Using filetable for the rendered templates, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and us... | [
"def",
"_render_templates",
"(",
"files",
",",
"filetable",
",",
"written_files",
",",
"force",
",",
"open_mode",
"=",
"'w'",
")",
":",
"for",
"tpl_path",
",",
"content",
"in",
"filetable",
":",
"target_path",
"=",
"files",
"[",
"tpl_path",
"]",
"needdir",
... | Write template contents from filetable into files.
Using filetable for the rendered templates, and the list of files, render
all the templates into actual files on disk, forcing to overwrite the file
as appropriate, and using the given open mode for the file. | [
"Write",
"template",
"contents",
"from",
"filetable",
"into",
"files",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L111-L144 |
rackerlabs/fastfood | fastfood/food.py | build_cookbook | def build_cookbook(build_config, templatepack_path,
cookbooks_home, force=False):
"""Build a cookbook from a fastfood.json file.
Can build on an existing cookbook, otherwise this will
create a new cookbook for you based on your templatepack.
"""
with open(build_config) as cfg:
... | python | def build_cookbook(build_config, templatepack_path,
cookbooks_home, force=False):
"""Build a cookbook from a fastfood.json file.
Can build on an existing cookbook, otherwise this will
create a new cookbook for you based on your templatepack.
"""
with open(build_config) as cfg:
... | [
"def",
"build_cookbook",
"(",
"build_config",
",",
"templatepack_path",
",",
"cookbooks_home",
",",
"force",
"=",
"False",
")",
":",
"with",
"open",
"(",
"build_config",
")",
"as",
"cfg",
":",
"cfg",
"=",
"json",
".",
"load",
"(",
"cfg",
")",
"cookbook_nam... | Build a cookbook from a fastfood.json file.
Can build on an existing cookbook, otherwise this will
create a new cookbook for you based on your templatepack. | [
"Build",
"a",
"cookbook",
"from",
"a",
"fastfood",
".",
"json",
"file",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L147-L186 |
rackerlabs/fastfood | fastfood/food.py | process_stencil | def process_stencil(cookbook, cookbook_name, template_pack,
force_argument, stencil_set, stencil, written_files):
"""Process the stencil requested, writing any missing files as needed.
The stencil named 'stencilset_name' should be one of
templatepack's stencils.
"""
# force can ... | python | def process_stencil(cookbook, cookbook_name, template_pack,
force_argument, stencil_set, stencil, written_files):
"""Process the stencil requested, writing any missing files as needed.
The stencil named 'stencilset_name' should be one of
templatepack's stencils.
"""
# force can ... | [
"def",
"process_stencil",
"(",
"cookbook",
",",
"cookbook_name",
",",
"template_pack",
",",
"force_argument",
",",
"stencil_set",
",",
"stencil",
",",
"written_files",
")",
":",
"# force can be passed on the command line or forced in a stencil's options",
"force",
"=",
"for... | Process the stencil requested, writing any missing files as needed.
The stencil named 'stencilset_name' should be one of
templatepack's stencils. | [
"Process",
"the",
"stencil",
"requested",
"writing",
"any",
"missing",
"files",
"as",
"needed",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L189-L244 |
rackerlabs/fastfood | fastfood/food.py | create_new_cookbook | def create_new_cookbook(cookbook_name, cookbooks_home):
"""Create a new cookbook.
:param cookbook_name: Name of the new cookbook.
:param cookbooks_home: Target dir for new cookbook.
"""
cookbooks_home = utils.normalize_path(cookbooks_home)
if not os.path.exists(cookbooks_home):
raise V... | python | def create_new_cookbook(cookbook_name, cookbooks_home):
"""Create a new cookbook.
:param cookbook_name: Name of the new cookbook.
:param cookbooks_home: Target dir for new cookbook.
"""
cookbooks_home = utils.normalize_path(cookbooks_home)
if not os.path.exists(cookbooks_home):
raise V... | [
"def",
"create_new_cookbook",
"(",
"cookbook_name",
",",
"cookbooks_home",
")",
":",
"cookbooks_home",
"=",
"utils",
".",
"normalize_path",
"(",
"cookbooks_home",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"cookbooks_home",
")",
":",
"raise",
"Va... | Create a new cookbook.
:param cookbook_name: Name of the new cookbook.
:param cookbooks_home: Target dir for new cookbook. | [
"Create",
"a",
"new",
"cookbook",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/food.py#L247-L272 |
rackerlabs/fastfood | fastfood/utils.py | ruby_lines | def ruby_lines(text):
"""Tidy up lines from a file, honor # comments.
Does not honor ruby block comments (yet).
"""
if isinstance(text, basestring):
text = text.splitlines()
elif not isinstance(text, list):
raise TypeError("text should be a list or a string, not %s"
... | python | def ruby_lines(text):
"""Tidy up lines from a file, honor # comments.
Does not honor ruby block comments (yet).
"""
if isinstance(text, basestring):
text = text.splitlines()
elif not isinstance(text, list):
raise TypeError("text should be a list or a string, not %s"
... | [
"def",
"ruby_lines",
"(",
"text",
")",
":",
"if",
"isinstance",
"(",
"text",
",",
"basestring",
")",
":",
"text",
"=",
"text",
".",
"splitlines",
"(",
")",
"elif",
"not",
"isinstance",
"(",
"text",
",",
"list",
")",
":",
"raise",
"TypeError",
"(",
"\... | Tidy up lines from a file, honor # comments.
Does not honor ruby block comments (yet). | [
"Tidy",
"up",
"lines",
"from",
"a",
"file",
"honor",
"#",
"comments",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/utils.py#L49-L60 |
rackerlabs/fastfood | fastfood/utils.py | deepupdate | def deepupdate(original, update, levels=5):
"""Update, like dict.update, but deeper.
Update 'original' from dict/iterable 'update'.
I.e., it recurses on dicts 'levels' times if necessary.
A standard dict.update is levels=0
"""
if not isinstance(update, dict):
update = dict(update)
... | python | def deepupdate(original, update, levels=5):
"""Update, like dict.update, but deeper.
Update 'original' from dict/iterable 'update'.
I.e., it recurses on dicts 'levels' times if necessary.
A standard dict.update is levels=0
"""
if not isinstance(update, dict):
update = dict(update)
... | [
"def",
"deepupdate",
"(",
"original",
",",
"update",
",",
"levels",
"=",
"5",
")",
":",
"if",
"not",
"isinstance",
"(",
"update",
",",
"dict",
")",
":",
"update",
"=",
"dict",
"(",
"update",
")",
"if",
"not",
"levels",
">",
"0",
":",
"original",
".... | Update, like dict.update, but deeper.
Update 'original' from dict/iterable 'update'.
I.e., it recurses on dicts 'levels' times if necessary.
A standard dict.update is levels=0 | [
"Update",
"like",
"dict",
".",
"update",
"but",
"deeper",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/utils.py#L63-L85 |
rackerlabs/fastfood | fastfood/utils.py | FileWrapper.write_statements | def write_statements(self, statements):
"""Insert the statements into the file neatly.
Ex:
statements = ["good 'dog'", "good 'cat'", "bad 'rat'", "fat 'emu'"]
# stream.txt ... animals = FileWrapper(open('stream.txt'))
good 'cow'
nice 'man'
bad 'news'
... | python | def write_statements(self, statements):
"""Insert the statements into the file neatly.
Ex:
statements = ["good 'dog'", "good 'cat'", "bad 'rat'", "fat 'emu'"]
# stream.txt ... animals = FileWrapper(open('stream.txt'))
good 'cow'
nice 'man'
bad 'news'
... | [
"def",
"write_statements",
"(",
"self",
",",
"statements",
")",
":",
"self",
".",
"seek",
"(",
"0",
")",
"original_content_lines",
"=",
"self",
".",
"readlines",
"(",
")",
"new_content_lines",
"=",
"copy",
".",
"copy",
"(",
"original_content_lines",
")",
"# ... | Insert the statements into the file neatly.
Ex:
statements = ["good 'dog'", "good 'cat'", "bad 'rat'", "fat 'emu'"]
# stream.txt ... animals = FileWrapper(open('stream.txt'))
good 'cow'
nice 'man'
bad 'news'
animals.write_statements(statements)
# st... | [
"Insert",
"the",
"statements",
"into",
"the",
"file",
"neatly",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/utils.py#L123-L177 |
rackerlabs/fastfood | fastfood/shell.py | _fastfood_build | def _fastfood_build(args):
"""Run on `fastfood build`."""
written_files, cookbook = food.build_cookbook(
args.config_file, args.template_pack,
args.cookbooks, args.force)
if len(written_files) > 0:
print("%s: %s files written" % (cookbook,
len... | python | def _fastfood_build(args):
"""Run on `fastfood build`."""
written_files, cookbook = food.build_cookbook(
args.config_file, args.template_pack,
args.cookbooks, args.force)
if len(written_files) > 0:
print("%s: %s files written" % (cookbook,
len... | [
"def",
"_fastfood_build",
"(",
"args",
")",
":",
"written_files",
",",
"cookbook",
"=",
"food",
".",
"build_cookbook",
"(",
"args",
".",
"config_file",
",",
"args",
".",
"template_pack",
",",
"args",
".",
"cookbooks",
",",
"args",
".",
"force",
")",
"if",
... | Run on `fastfood build`. | [
"Run",
"on",
"fastfood",
"build",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L49-L61 |
rackerlabs/fastfood | fastfood/shell.py | _fastfood_list | def _fastfood_list(args):
"""Run on `fastfood list`."""
template_pack = pack.TemplatePack(args.template_pack)
if args.stencil_set:
stencil_set = template_pack.load_stencil_set(args.stencil_set)
print("Available Stencils for %s:" % args.stencil_set)
for stencil in stencil_set.stencils... | python | def _fastfood_list(args):
"""Run on `fastfood list`."""
template_pack = pack.TemplatePack(args.template_pack)
if args.stencil_set:
stencil_set = template_pack.load_stencil_set(args.stencil_set)
print("Available Stencils for %s:" % args.stencil_set)
for stencil in stencil_set.stencils... | [
"def",
"_fastfood_list",
"(",
"args",
")",
":",
"template_pack",
"=",
"pack",
".",
"TemplatePack",
"(",
"args",
".",
"template_pack",
")",
"if",
"args",
".",
"stencil_set",
":",
"stencil_set",
"=",
"template_pack",
".",
"load_stencil_set",
"(",
"args",
".",
... | Run on `fastfood list`. | [
"Run",
"on",
"fastfood",
"list",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L64-L75 |
rackerlabs/fastfood | fastfood/shell.py | _fastfood_show | def _fastfood_show(args):
"""Run on `fastfood show`."""
template_pack = pack.TemplatePack(args.template_pack)
if args.stencil_set:
stencil_set = template_pack.load_stencil_set(args.stencil_set)
print("Stencil Set %s:" % args.stencil_set)
print(' Stencils:')
for stencil in st... | python | def _fastfood_show(args):
"""Run on `fastfood show`."""
template_pack = pack.TemplatePack(args.template_pack)
if args.stencil_set:
stencil_set = template_pack.load_stencil_set(args.stencil_set)
print("Stencil Set %s:" % args.stencil_set)
print(' Stencils:')
for stencil in st... | [
"def",
"_fastfood_show",
"(",
"args",
")",
":",
"template_pack",
"=",
"pack",
".",
"TemplatePack",
"(",
"args",
".",
"template_pack",
")",
"if",
"args",
".",
"stencil_set",
":",
"stencil_set",
"=",
"template_pack",
".",
"load_stencil_set",
"(",
"args",
".",
... | Run on `fastfood show`. | [
"Run",
"on",
"fastfood",
"show",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L78-L89 |
rackerlabs/fastfood | fastfood/shell.py | _release_info | def _release_info():
"""Check latest fastfood release info from PyPI."""
pypi_url = 'http://pypi.python.org/pypi/fastfood/json'
headers = {
'Accept': 'application/json',
}
request = urllib.Request(pypi_url, headers=headers)
response = urllib.urlopen(request).read().decode('utf_8')
da... | python | def _release_info():
"""Check latest fastfood release info from PyPI."""
pypi_url = 'http://pypi.python.org/pypi/fastfood/json'
headers = {
'Accept': 'application/json',
}
request = urllib.Request(pypi_url, headers=headers)
response = urllib.urlopen(request).read().decode('utf_8')
da... | [
"def",
"_release_info",
"(",
")",
":",
"pypi_url",
"=",
"'http://pypi.python.org/pypi/fastfood/json'",
"headers",
"=",
"{",
"'Accept'",
":",
"'application/json'",
",",
"}",
"request",
"=",
"urllib",
".",
"Request",
"(",
"pypi_url",
",",
"headers",
"=",
"headers",
... | Check latest fastfood release info from PyPI. | [
"Check",
"latest",
"fastfood",
"release",
"info",
"from",
"PyPI",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L92-L101 |
rackerlabs/fastfood | fastfood/shell.py | getenv | def getenv(option_name, default=None):
"""Return the option from the environment in the FASTFOOD namespace."""
env = "%s_%s" % (NAMESPACE.upper(), option_name.upper())
return os.environ.get(env, default) | python | def getenv(option_name, default=None):
"""Return the option from the environment in the FASTFOOD namespace."""
env = "%s_%s" % (NAMESPACE.upper(), option_name.upper())
return os.environ.get(env, default) | [
"def",
"getenv",
"(",
"option_name",
",",
"default",
"=",
"None",
")",
":",
"env",
"=",
"\"%s_%s\"",
"%",
"(",
"NAMESPACE",
".",
"upper",
"(",
")",
",",
"option_name",
".",
"upper",
"(",
")",
")",
"return",
"os",
".",
"environ",
".",
"get",
"(",
"e... | Return the option from the environment in the FASTFOOD namespace. | [
"Return",
"the",
"option",
"from",
"the",
"environment",
"in",
"the",
"FASTFOOD",
"namespace",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L111-L114 |
rackerlabs/fastfood | fastfood/shell.py | main | def main(argv=None):
"""fastfood command line interface."""
# pylint: disable=missing-docstring
import argparse
import traceback
class HelpfulParser(argparse.ArgumentParser):
def error(self, message, print_help=False):
if 'too few arguments' in message:
sys.argv.... | python | def main(argv=None):
"""fastfood command line interface."""
# pylint: disable=missing-docstring
import argparse
import traceback
class HelpfulParser(argparse.ArgumentParser):
def error(self, message, print_help=False):
if 'too few arguments' in message:
sys.argv.... | [
"def",
"main",
"(",
"argv",
"=",
"None",
")",
":",
"# pylint: disable=missing-docstring",
"import",
"argparse",
"import",
"traceback",
"class",
"HelpfulParser",
"(",
"argparse",
".",
"ArgumentParser",
")",
":",
"def",
"error",
"(",
"self",
",",
"message",
",",
... | fastfood command line interface. | [
"fastfood",
"command",
"line",
"interface",
"."
] | train | https://github.com/rackerlabs/fastfood/blob/543970c4cedbb3956e84a7986469fdd7e4ee8fc8/fastfood/shell.py#L117-L252 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.