repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.list_instances | def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
memory=None, hostname=None, domain=None,
local_disk=None, datacenter=None, nic_speed=None,
public_ip=None, private_ip=None, **kwargs):
"""Retrieve a list of all virtual ... | python | def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
memory=None, hostname=None, domain=None,
local_disk=None, datacenter=None, nic_speed=None,
public_ip=None, private_ip=None, **kwargs):
"""Retrieve a list of all virtual ... | [
"def",
"list_instances",
"(",
"self",
",",
"hourly",
"=",
"True",
",",
"monthly",
"=",
"True",
",",
"tags",
"=",
"None",
",",
"cpus",
"=",
"None",
",",
"memory",
"=",
"None",
",",
"hostname",
"=",
"None",
",",
"domain",
"=",
"None",
",",
"local_disk"... | Retrieve a list of all virtual servers on the account.
Example::
# Print out a list of hourly instances in the DAL05 data center.
for vsi in mgr.list_instances(hourly=True, datacenter='dal05'):
print vsi['fullyQualifiedDomainName'], vsi['primaryIpAddress']
... | [
"Retrieve",
"a",
"list",
"of",
"all",
"virtual",
"servers",
"on",
"the",
"account",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L61-L162 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.get_instance | def get_instance(self, instance_id, **kwargs):
"""Get details about a virtual server instance.
:param integer instance_id: the instance ID
:returns: A dictionary containing a large amount of information about
the specified instance.
Example::
# Print out ... | python | def get_instance(self, instance_id, **kwargs):
"""Get details about a virtual server instance.
:param integer instance_id: the instance ID
:returns: A dictionary containing a large amount of information about
the specified instance.
Example::
# Print out ... | [
"def",
"get_instance",
"(",
"self",
",",
"instance_id",
",",
"**",
"kwargs",
")",
":",
"if",
"'mask'",
"not",
"in",
"kwargs",
":",
"kwargs",
"[",
"'mask'",
"]",
"=",
"(",
"'id,'",
"'globalIdentifier,'",
"'fullyQualifiedDomainName,'",
"'hostname,'",
"'domain,'",
... | Get details about a virtual server instance.
:param integer instance_id: the instance ID
:returns: A dictionary containing a large amount of information about
the specified instance.
Example::
# Print out instance ID 12345.
vsi = mgr.get_instance(1234... | [
"Get",
"details",
"about",
"a",
"virtual",
"server",
"instance",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L165-L240 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.reload_instance | def reload_instance(self, instance_id,
post_uri=None,
ssh_keys=None,
image_id=None):
"""Perform an OS reload of an instance.
:param integer instance_id: the instance ID to reload
:param string post_url: The URI of the post-... | python | def reload_instance(self, instance_id,
post_uri=None,
ssh_keys=None,
image_id=None):
"""Perform an OS reload of an instance.
:param integer instance_id: the instance ID to reload
:param string post_url: The URI of the post-... | [
"def",
"reload_instance",
"(",
"self",
",",
"instance_id",
",",
"post_uri",
"=",
"None",
",",
"ssh_keys",
"=",
"None",
",",
"image_id",
"=",
"None",
")",
":",
"config",
"=",
"{",
"}",
"if",
"post_uri",
":",
"config",
"[",
"'customProvisionScriptUri'",
"]",... | Perform an OS reload of an instance.
:param integer instance_id: the instance ID to reload
:param string post_url: The URI of the post-install script to run
after reload
:param list ssh_keys: The SSH keys to add to the root user
:param int image_id: The G... | [
"Perform",
"an",
"OS",
"reload",
"of",
"an",
"instance",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L269-L305 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.wait_for_transaction | def wait_for_transaction(self, instance_id, limit, delay=10):
"""Waits on a VS transaction for the specified amount of time.
This is really just a wrapper for wait_for_ready(pending=True).
Provided for backwards compatibility.
:param int instance_id: The instance ID with the pending tr... | python | def wait_for_transaction(self, instance_id, limit, delay=10):
"""Waits on a VS transaction for the specified amount of time.
This is really just a wrapper for wait_for_ready(pending=True).
Provided for backwards compatibility.
:param int instance_id: The instance ID with the pending tr... | [
"def",
"wait_for_transaction",
"(",
"self",
",",
"instance_id",
",",
"limit",
",",
"delay",
"=",
"10",
")",
":",
"return",
"self",
".",
"wait_for_ready",
"(",
"instance_id",
",",
"limit",
",",
"delay",
"=",
"delay",
",",
"pending",
"=",
"True",
")"
] | Waits on a VS transaction for the specified amount of time.
This is really just a wrapper for wait_for_ready(pending=True).
Provided for backwards compatibility.
:param int instance_id: The instance ID with the pending transaction
:param int limit: The maximum amount of time to wait.
... | [
"Waits",
"on",
"a",
"VS",
"transaction",
"for",
"the",
"specified",
"amount",
"of",
"time",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L442-L453 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.verify_create_instance | def verify_create_instance(self, **kwargs):
"""Verifies an instance creation command.
Without actually placing an order.
See :func:`create_instance` for a list of available options.
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'... | python | def verify_create_instance(self, **kwargs):
"""Verifies an instance creation command.
Without actually placing an order.
See :func:`create_instance` for a list of available options.
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'... | [
"def",
"verify_create_instance",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"kwargs",
".",
"pop",
"(",
"'tags'",
",",
"None",
")",
"create_options",
"=",
"self",
".",
"_generate_create_dict",
"(",
"**",
"kwargs",
")",
"return",
"self",
".",
"guest",
".",
... | Verifies an instance creation command.
Without actually placing an order.
See :func:`create_instance` for a list of available options.
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'hostname': u'minion05',
'datacenter': u... | [
"Verifies",
"an",
"instance",
"creation",
"command",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L493-L524 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.create_instance | def create_instance(self, **kwargs):
"""Creates a new virtual server instance.
.. warning::
This will add charges to your account
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'hostname': u'minion05',
'datace... | python | def create_instance(self, **kwargs):
"""Creates a new virtual server instance.
.. warning::
This will add charges to your account
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'hostname': u'minion05',
'datace... | [
"def",
"create_instance",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"tags",
"=",
"kwargs",
".",
"pop",
"(",
"'tags'",
",",
"None",
")",
"inst",
"=",
"self",
".",
"guest",
".",
"createObject",
"(",
"self",
".",
"_generate_create_dict",
"(",
"**",
"kwa... | Creates a new virtual server instance.
.. warning::
This will add charges to your account
Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'hostname': u'minion05',
'datacenter': u'hkg02',
'flavor': 'BL1_... | [
"Creates",
"a",
"new",
"virtual",
"server",
"instance",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L526-L584 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.set_tags | def set_tags(self, tags, guest_id):
"""Sets tags on a guest with a retry decorator
Just calls guest.setTags, but if it fails from an APIError will retry
"""
self.guest.setTags(tags, id=guest_id) | python | def set_tags(self, tags, guest_id):
"""Sets tags on a guest with a retry decorator
Just calls guest.setTags, but if it fails from an APIError will retry
"""
self.guest.setTags(tags, id=guest_id) | [
"def",
"set_tags",
"(",
"self",
",",
"tags",
",",
"guest_id",
")",
":",
"self",
".",
"guest",
".",
"setTags",
"(",
"tags",
",",
"id",
"=",
"guest_id",
")"
] | Sets tags on a guest with a retry decorator
Just calls guest.setTags, but if it fails from an APIError will retry | [
"Sets",
"tags",
"on",
"a",
"guest",
"with",
"a",
"retry",
"decorator"
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L587-L592 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.create_instances | def create_instances(self, config_list):
"""Creates multiple virtual server instances.
This takes a list of dictionaries using the same arguments as
create_instance().
.. warning::
This will add charges to your account
Example::
# Define the instance ... | python | def create_instances(self, config_list):
"""Creates multiple virtual server instances.
This takes a list of dictionaries using the same arguments as
create_instance().
.. warning::
This will add charges to your account
Example::
# Define the instance ... | [
"def",
"create_instances",
"(",
"self",
",",
"config_list",
")",
":",
"tags",
"=",
"[",
"conf",
".",
"pop",
"(",
"'tags'",
",",
"None",
")",
"for",
"conf",
"in",
"config_list",
"]",
"resp",
"=",
"self",
".",
"guest",
".",
"createObjects",
"(",
"[",
"... | Creates multiple virtual server instances.
This takes a list of dictionaries using the same arguments as
create_instance().
.. warning::
This will add charges to your account
Example::
# Define the instance we want to create.
new_vsi = {
... | [
"Creates",
"multiple",
"virtual",
"server",
"instances",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L594-L644 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.change_port_speed | def change_port_speed(self, instance_id, public, speed):
"""Allows you to change the port speed of a virtual server's NICs.
Example::
#change the Public interface to 10Mbps on instance 12345
result = mgr.change_port_speed(instance_id=12345,
... | python | def change_port_speed(self, instance_id, public, speed):
"""Allows you to change the port speed of a virtual server's NICs.
Example::
#change the Public interface to 10Mbps on instance 12345
result = mgr.change_port_speed(instance_id=12345,
... | [
"def",
"change_port_speed",
"(",
"self",
",",
"instance_id",
",",
"public",
",",
"speed",
")",
":",
"if",
"public",
":",
"return",
"self",
".",
"client",
".",
"call",
"(",
"'Virtual_Guest'",
",",
"'setPublicNetworkInterfaceSpeed'",
",",
"speed",
",",
"id",
"... | Allows you to change the port speed of a virtual server's NICs.
Example::
#change the Public interface to 10Mbps on instance 12345
result = mgr.change_port_speed(instance_id=12345,
public=True, speed=10)
# result will be True or an Ex... | [
"Allows",
"you",
"to",
"change",
"the",
"port",
"speed",
"of",
"a",
"virtual",
"server",
"s",
"NICs",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L646-L670 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_ids_from_hostname | def _get_ids_from_hostname(self, hostname):
"""List VS ids which match the given hostname."""
results = self.list_instances(hostname=hostname, mask="id")
return [result['id'] for result in results] | python | def _get_ids_from_hostname(self, hostname):
"""List VS ids which match the given hostname."""
results = self.list_instances(hostname=hostname, mask="id")
return [result['id'] for result in results] | [
"def",
"_get_ids_from_hostname",
"(",
"self",
",",
"hostname",
")",
":",
"results",
"=",
"self",
".",
"list_instances",
"(",
"hostname",
"=",
"hostname",
",",
"mask",
"=",
"\"id\"",
")",
"return",
"[",
"result",
"[",
"'id'",
"]",
"for",
"result",
"in",
"... | List VS ids which match the given hostname. | [
"List",
"VS",
"ids",
"which",
"match",
"the",
"given",
"hostname",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L672-L675 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_ids_from_ip | def _get_ids_from_ip(self, ip_address): # pylint: disable=inconsistent-return-statements
"""List VS ids which match the given ip address."""
try:
# Does it look like an ip address?
socket.inet_aton(ip_address)
except socket.error:
return []
# Find th... | python | def _get_ids_from_ip(self, ip_address): # pylint: disable=inconsistent-return-statements
"""List VS ids which match the given ip address."""
try:
# Does it look like an ip address?
socket.inet_aton(ip_address)
except socket.error:
return []
# Find th... | [
"def",
"_get_ids_from_ip",
"(",
"self",
",",
"ip_address",
")",
":",
"try",
":",
"socket",
".",
"inet_aton",
"(",
"ip_address",
")",
"except",
"socket",
".",
"error",
":",
"return",
"[",
"]",
"results",
"=",
"self",
".",
"list_instances",
"(",
"public_ip",... | List VS ids which match the given ip address. | [
"List",
"VS",
"ids",
"which",
"match",
"the",
"given",
"ip",
"address",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L677-L692 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager.upgrade | def upgrade(self, instance_id, cpus=None, memory=None, nic_speed=None, public=True, preset=None):
"""Upgrades a VS instance.
Example::
# Upgrade instance 12345 to 4 CPUs and 4 GB of memory
import SoftLayer
client = SoftLayer.create_client_from_env()
mgr = So... | python | def upgrade(self, instance_id, cpus=None, memory=None, nic_speed=None, public=True, preset=None):
"""Upgrades a VS instance.
Example::
# Upgrade instance 12345 to 4 CPUs and 4 GB of memory
import SoftLayer
client = SoftLayer.create_client_from_env()
mgr = So... | [
"def",
"upgrade",
"(",
"self",
",",
"instance_id",
",",
"cpus",
"=",
"None",
",",
"memory",
"=",
"None",
",",
"nic_speed",
"=",
"None",
",",
"public",
"=",
"True",
",",
"preset",
"=",
"None",
")",
":",
"upgrade_prices",
"=",
"self",
".",
"_get_upgrade_... | Upgrades a VS instance.
Example::
# Upgrade instance 12345 to 4 CPUs and 4 GB of memory
import SoftLayer
client = SoftLayer.create_client_from_env()
mgr = SoftLayer.VSManager(client)
mgr.upgrade(12345, cpus=4, memory=4)
:param int instance_id: In... | [
"Upgrades",
"a",
"VS",
"instance",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L801-L867 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_package_items | def _get_package_items(self):
"""Following Method gets all the item ids related to VS.
Deprecated in favor of _get_upgrade_prices()
"""
warnings.warn("use _get_upgrade_prices() instead",
DeprecationWarning)
mask = [
'description',
'c... | python | def _get_package_items(self):
"""Following Method gets all the item ids related to VS.
Deprecated in favor of _get_upgrade_prices()
"""
warnings.warn("use _get_upgrade_prices() instead",
DeprecationWarning)
mask = [
'description',
'c... | [
"def",
"_get_package_items",
"(",
"self",
")",
":",
"warnings",
".",
"warn",
"(",
"\"use _get_upgrade_prices() instead\"",
",",
"DeprecationWarning",
")",
"mask",
"=",
"[",
"'description'",
",",
"'capacity'",
",",
"'units'",
",",
"'prices[id,locationGroupId,categories[n... | Following Method gets all the item ids related to VS.
Deprecated in favor of _get_upgrade_prices() | [
"Following",
"Method",
"gets",
"all",
"the",
"item",
"ids",
"related",
"to",
"VS",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L927-L946 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_upgrade_prices | def _get_upgrade_prices(self, instance_id, include_downgrade_options=True):
"""Following Method gets all the price ids related to upgrading a VS.
:param int instance_id: Instance id of the VS to be upgraded
:returns: list
"""
mask = [
'id',
'locationGrou... | python | def _get_upgrade_prices(self, instance_id, include_downgrade_options=True):
"""Following Method gets all the price ids related to upgrading a VS.
:param int instance_id: Instance id of the VS to be upgraded
:returns: list
"""
mask = [
'id',
'locationGrou... | [
"def",
"_get_upgrade_prices",
"(",
"self",
",",
"instance_id",
",",
"include_downgrade_options",
"=",
"True",
")",
":",
"mask",
"=",
"[",
"'id'",
",",
"'locationGroupId'",
",",
"'categories[name,id,categoryCode]'",
",",
"'item[description,capacity,units]'",
"]",
"mask",... | Following Method gets all the price ids related to upgrading a VS.
:param int instance_id: Instance id of the VS to be upgraded
:returns: list | [
"Following",
"Method",
"gets",
"all",
"the",
"price",
"ids",
"related",
"to",
"upgrading",
"a",
"VS",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L948-L962 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_price_id_for_upgrade_option | def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, public=True):
"""Find the price id for the option and value to upgrade. This
:param list upgrade_prices: Contains all the prices related to a VS upgrade
:param string option: Describes type of parameter to be upgraded
... | python | def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, public=True):
"""Find the price id for the option and value to upgrade. This
:param list upgrade_prices: Contains all the prices related to a VS upgrade
:param string option: Describes type of parameter to be upgraded
... | [
"def",
"_get_price_id_for_upgrade_option",
"(",
"self",
",",
"upgrade_prices",
",",
"option",
",",
"value",
",",
"public",
"=",
"True",
")",
":",
"option_category",
"=",
"{",
"'memory'",
":",
"'ram'",
",",
"'cpus'",
":",
"'guest_core'",
",",
"'nic_speed'",
":"... | Find the price id for the option and value to upgrade. This
:param list upgrade_prices: Contains all the prices related to a VS upgrade
:param string option: Describes type of parameter to be upgraded
:param int value: The value of the parameter to be upgraded
:param bool public: CPU wi... | [
"Find",
"the",
"price",
"id",
"for",
"the",
"option",
"and",
"value",
"to",
"upgrade",
".",
"This"
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L965-L1003 | train |
softlayer/softlayer-python | SoftLayer/managers/vs.py | VSManager._get_price_id_for_upgrade | def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
"""Find the price id for the option and value to upgrade.
Deprecated in favor of _get_price_id_for_upgrade_option()
:param list package_items: Contains all the items related to an VS
:param string option: D... | python | def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
"""Find the price id for the option and value to upgrade.
Deprecated in favor of _get_price_id_for_upgrade_option()
:param list package_items: Contains all the items related to an VS
:param string option: D... | [
"def",
"_get_price_id_for_upgrade",
"(",
"self",
",",
"package_items",
",",
"option",
",",
"value",
",",
"public",
"=",
"True",
")",
":",
"warnings",
".",
"warn",
"(",
"\"use _get_price_id_for_upgrade_option() instead\"",
",",
"DeprecationWarning",
")",
"option_catego... | Find the price id for the option and value to upgrade.
Deprecated in favor of _get_price_id_for_upgrade_option()
:param list package_items: Contains all the items related to an VS
:param string option: Describes type of parameter to be upgraded
:param int value: The value of the parame... | [
"Find",
"the",
"price",
"id",
"for",
"the",
"option",
"and",
"value",
"to",
"upgrade",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs.py#L1006-L1048 | train |
softlayer/softlayer-python | SoftLayer/CLI/securitygroup/interface.py | interface_list | def interface_list(env, securitygroup_id, sortby):
"""List interfaces associated with security groups."""
mgr = SoftLayer.NetworkManager(env.client)
table = formatting.Table(COLUMNS)
table.sortby = sortby
mask = (
'''networkComponentBindings[
networkComponentId,
net... | python | def interface_list(env, securitygroup_id, sortby):
"""List interfaces associated with security groups."""
mgr = SoftLayer.NetworkManager(env.client)
table = formatting.Table(COLUMNS)
table.sortby = sortby
mask = (
'''networkComponentBindings[
networkComponentId,
net... | [
"def",
"interface_list",
"(",
"env",
",",
"securitygroup_id",
",",
"sortby",
")",
":",
"mgr",
"=",
"SoftLayer",
".",
"NetworkManager",
"(",
"env",
".",
"client",
")",
"table",
"=",
"formatting",
".",
"Table",
"(",
"COLUMNS",
")",
"table",
".",
"sortby",
... | List interfaces associated with security groups. | [
"List",
"interfaces",
"associated",
"with",
"security",
"groups",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/securitygroup/interface.py#L26-L75 | train |
softlayer/softlayer-python | SoftLayer/CLI/securitygroup/interface.py | add | def add(env, securitygroup_id, network_component, server, interface):
"""Attach an interface to a security group."""
_validate_args(network_component, server, interface)
mgr = SoftLayer.NetworkManager(env.client)
component_id = _get_component_id(env, network_component, server, interface)
ret = mgr... | python | def add(env, securitygroup_id, network_component, server, interface):
"""Attach an interface to a security group."""
_validate_args(network_component, server, interface)
mgr = SoftLayer.NetworkManager(env.client)
component_id = _get_component_id(env, network_component, server, interface)
ret = mgr... | [
"def",
"add",
"(",
"env",
",",
"securitygroup_id",
",",
"network_component",
",",
"server",
",",
"interface",
")",
":",
"_validate_args",
"(",
"network_component",
",",
"server",
",",
"interface",
")",
"mgr",
"=",
"SoftLayer",
".",
"NetworkManager",
"(",
"env"... | Attach an interface to a security group. | [
"Attach",
"an",
"interface",
"to",
"a",
"security",
"group",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/securitygroup/interface.py#L88-L103 | train |
edx/XBlock | xblock/plugin.py | default_select | def default_select(identifier, all_entry_points): # pylint: disable=inconsistent-return-statements
"""
Raise an exception when we have ambiguous entry points.
"""
if len(all_entry_points) == 0:
raise PluginMissingError(identifier)
elif len(all_entry_points) == 1:
return all_entry_... | python | def default_select(identifier, all_entry_points): # pylint: disable=inconsistent-return-statements
"""
Raise an exception when we have ambiguous entry points.
"""
if len(all_entry_points) == 0:
raise PluginMissingError(identifier)
elif len(all_entry_points) == 1:
return all_entry_... | [
"def",
"default_select",
"(",
"identifier",
",",
"all_entry_points",
")",
":",
"if",
"len",
"(",
"all_entry_points",
")",
"==",
"0",
":",
"raise",
"PluginMissingError",
"(",
"identifier",
")",
"elif",
"len",
"(",
"all_entry_points",
")",
"==",
"1",
":",
"ret... | Raise an exception when we have ambiguous entry points. | [
"Raise",
"an",
"exception",
"when",
"we",
"have",
"ambiguous",
"entry",
"points",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/plugin.py#L34-L46 | train |
edx/XBlock | xblock/plugin.py | Plugin._load_class_entry_point | def _load_class_entry_point(cls, entry_point):
"""
Load `entry_point`, and set the `entry_point.name` as the
attribute `plugin_name` on the loaded object
"""
class_ = entry_point.load()
setattr(class_, 'plugin_name', entry_point.name)
return class_ | python | def _load_class_entry_point(cls, entry_point):
"""
Load `entry_point`, and set the `entry_point.name` as the
attribute `plugin_name` on the loaded object
"""
class_ = entry_point.load()
setattr(class_, 'plugin_name', entry_point.name)
return class_ | [
"def",
"_load_class_entry_point",
"(",
"cls",
",",
"entry_point",
")",
":",
"class_",
"=",
"entry_point",
".",
"load",
"(",
")",
"setattr",
"(",
"class_",
",",
"'plugin_name'",
",",
"entry_point",
".",
"name",
")",
"return",
"class_"
] | Load `entry_point`, and set the `entry_point.name` as the
attribute `plugin_name` on the loaded object | [
"Load",
"entry_point",
"and",
"set",
"the",
"entry_point",
".",
"name",
"as",
"the",
"attribute",
"plugin_name",
"on",
"the",
"loaded",
"object"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/plugin.py#L70-L77 | train |
edx/XBlock | xblock/plugin.py | Plugin.load_class | def load_class(cls, identifier, default=None, select=None):
"""Load a single class specified by identifier.
If `identifier` specifies more than a single class, and `select` is not None,
then call `select` on the list of entry_points. Otherwise, choose
the first one and log a warning.
... | python | def load_class(cls, identifier, default=None, select=None):
"""Load a single class specified by identifier.
If `identifier` specifies more than a single class, and `select` is not None,
then call `select` on the list of entry_points. Otherwise, choose
the first one and log a warning.
... | [
"def",
"load_class",
"(",
"cls",
",",
"identifier",
",",
"default",
"=",
"None",
",",
"select",
"=",
"None",
")",
":",
"identifier",
"=",
"identifier",
".",
"lower",
"(",
")",
"key",
"=",
"(",
"cls",
".",
"entry_point",
",",
"identifier",
")",
"if",
... | Load a single class specified by identifier.
If `identifier` specifies more than a single class, and `select` is not None,
then call `select` on the list of entry_points. Otherwise, choose
the first one and log a warning.
If `default` is provided, return it if no entry_point matching
... | [
"Load",
"a",
"single",
"class",
"specified",
"by",
"identifier",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/plugin.py#L80-L122 | train |
edx/XBlock | xblock/plugin.py | Plugin.load_classes | def load_classes(cls, fail_silently=True):
"""Load all the classes for a plugin.
Produces a sequence containing the identifiers and their corresponding
classes for all of the available instances of this plugin.
fail_silently causes the code to simply log warnings if a
plugin ca... | python | def load_classes(cls, fail_silently=True):
"""Load all the classes for a plugin.
Produces a sequence containing the identifiers and their corresponding
classes for all of the available instances of this plugin.
fail_silently causes the code to simply log warnings if a
plugin ca... | [
"def",
"load_classes",
"(",
"cls",
",",
"fail_silently",
"=",
"True",
")",
":",
"all_classes",
"=",
"itertools",
".",
"chain",
"(",
"pkg_resources",
".",
"iter_entry_points",
"(",
"cls",
".",
"entry_point",
")",
",",
"(",
"entry_point",
"for",
"identifier",
... | Load all the classes for a plugin.
Produces a sequence containing the identifiers and their corresponding
classes for all of the available instances of this plugin.
fail_silently causes the code to simply log warnings if a
plugin cannot import. The goal is to be able to use part of
... | [
"Load",
"all",
"the",
"classes",
"for",
"a",
"plugin",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/plugin.py#L125-L151 | train |
edx/XBlock | xblock/plugin.py | Plugin.register_temp_plugin | def register_temp_plugin(cls, class_, identifier=None, dist='xblock'):
"""Decorate a function to run with a temporary plugin available.
Use it like this in tests::
@register_temp_plugin(MyXBlockClass):
def test_the_thing():
# Here I can load MyXBlockClass by nam... | python | def register_temp_plugin(cls, class_, identifier=None, dist='xblock'):
"""Decorate a function to run with a temporary plugin available.
Use it like this in tests::
@register_temp_plugin(MyXBlockClass):
def test_the_thing():
# Here I can load MyXBlockClass by nam... | [
"def",
"register_temp_plugin",
"(",
"cls",
",",
"class_",
",",
"identifier",
"=",
"None",
",",
"dist",
"=",
"'xblock'",
")",
":",
"from",
"mock",
"import",
"Mock",
"if",
"identifier",
"is",
"None",
":",
"identifier",
"=",
"class_",
".",
"__name__",
".",
... | Decorate a function to run with a temporary plugin available.
Use it like this in tests::
@register_temp_plugin(MyXBlockClass):
def test_the_thing():
# Here I can load MyXBlockClass by name. | [
"Decorate",
"a",
"function",
"to",
"run",
"with",
"a",
"temporary",
"plugin",
"available",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/plugin.py#L154-L192 | train |
edx/XBlock | xblock/django/request.py | webob_to_django_response | def webob_to_django_response(webob_response):
"""Returns a django response to the `webob_response`"""
from django.http import HttpResponse
django_response = HttpResponse(
webob_response.app_iter,
content_type=webob_response.content_type,
status=webob_response.status_code,
)
f... | python | def webob_to_django_response(webob_response):
"""Returns a django response to the `webob_response`"""
from django.http import HttpResponse
django_response = HttpResponse(
webob_response.app_iter,
content_type=webob_response.content_type,
status=webob_response.status_code,
)
f... | [
"def",
"webob_to_django_response",
"(",
"webob_response",
")",
":",
"from",
"django",
".",
"http",
"import",
"HttpResponse",
"django_response",
"=",
"HttpResponse",
"(",
"webob_response",
".",
"app_iter",
",",
"content_type",
"=",
"webob_response",
".",
"content_type"... | Returns a django response to the `webob_response` | [
"Returns",
"a",
"django",
"response",
"to",
"the",
"webob_response"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/django/request.py#L14-L24 | train |
edx/XBlock | xblock/django/request.py | querydict_to_multidict | def querydict_to_multidict(query_dict, wrap=None):
"""
Returns a new `webob.MultiDict` from a `django.http.QueryDict`.
If `wrap` is provided, it's used to wrap the values.
"""
wrap = wrap or (lambda val: val)
return MultiDict(chain.from_iterable(
six.moves.zip(repeat(key), (wrap(v) for... | python | def querydict_to_multidict(query_dict, wrap=None):
"""
Returns a new `webob.MultiDict` from a `django.http.QueryDict`.
If `wrap` is provided, it's used to wrap the values.
"""
wrap = wrap or (lambda val: val)
return MultiDict(chain.from_iterable(
six.moves.zip(repeat(key), (wrap(v) for... | [
"def",
"querydict_to_multidict",
"(",
"query_dict",
",",
"wrap",
"=",
"None",
")",
":",
"wrap",
"=",
"wrap",
"or",
"(",
"lambda",
"val",
":",
"val",
")",
"return",
"MultiDict",
"(",
"chain",
".",
"from_iterable",
"(",
"six",
".",
"moves",
".",
"zip",
"... | Returns a new `webob.MultiDict` from a `django.http.QueryDict`.
If `wrap` is provided, it's used to wrap the values. | [
"Returns",
"a",
"new",
"webob",
".",
"MultiDict",
"from",
"a",
"django",
".",
"http",
".",
"QueryDict",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/django/request.py#L76-L87 | train |
edx/XBlock | xblock/django/request.py | HeaderDict._meta_name | def _meta_name(self, name):
"""
Translate HTTP header names to the format used by Django request objects.
See https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest.META
"""
name = name.upper().replace('-', '_')
if name not in self.UNPREFIXED... | python | def _meta_name(self, name):
"""
Translate HTTP header names to the format used by Django request objects.
See https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest.META
"""
name = name.upper().replace('-', '_')
if name not in self.UNPREFIXED... | [
"def",
"_meta_name",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"name",
".",
"upper",
"(",
")",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
"if",
"name",
"not",
"in",
"self",
".",
"UNPREFIXED_HEADERS",
":",
"name",
"=",
"'HTTP_'",
"+",
"name... | Translate HTTP header names to the format used by Django request objects.
See https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest.META | [
"Translate",
"HTTP",
"header",
"names",
"to",
"the",
"format",
"used",
"by",
"Django",
"request",
"objects",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/django/request.py#L39-L48 | train |
edx/XBlock | xblock/django/request.py | HeaderDict._un_meta_name | def _un_meta_name(self, name):
"""
Reverse of _meta_name
"""
if name.startswith('HTTP_'):
name = name[5:]
return name.replace('_', '-').title() | python | def _un_meta_name(self, name):
"""
Reverse of _meta_name
"""
if name.startswith('HTTP_'):
name = name[5:]
return name.replace('_', '-').title() | [
"def",
"_un_meta_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
".",
"startswith",
"(",
"'HTTP_'",
")",
":",
"name",
"=",
"name",
"[",
"5",
":",
"]",
"return",
"name",
".",
"replace",
"(",
"'_'",
",",
"'-'",
")",
".",
"title",
"(",
")"
... | Reverse of _meta_name | [
"Reverse",
"of",
"_meta_name"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/django/request.py#L50-L56 | train |
edx/XBlock | xblock/django/request.py | DjangoWebobRequest.environ | def environ(self):
"""
Add path_info to the request's META dictionary.
"""
environ = dict(self._request.META)
environ['PATH_INFO'] = self._request.path_info
return environ | python | def environ(self):
"""
Add path_info to the request's META dictionary.
"""
environ = dict(self._request.META)
environ['PATH_INFO'] = self._request.path_info
return environ | [
"def",
"environ",
"(",
"self",
")",
":",
"environ",
"=",
"dict",
"(",
"self",
".",
"_request",
".",
"META",
")",
"environ",
"[",
"'PATH_INFO'",
"]",
"=",
"self",
".",
"_request",
".",
"path_info",
"return",
"environ"
] | Add path_info to the request's META dictionary. | [
"Add",
"path_info",
"to",
"the",
"request",
"s",
"META",
"dictionary",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/django/request.py#L119-L127 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData._getfield | def _getfield(self, block, name):
"""
Return the field with the given `name` from `block`.
If no field with `name` exists in any namespace, raises a KeyError.
:param block: xblock to retrieve the field from
:type block: :class:`~xblock.core.XBlock`
:param name: name of t... | python | def _getfield(self, block, name):
"""
Return the field with the given `name` from `block`.
If no field with `name` exists in any namespace, raises a KeyError.
:param block: xblock to retrieve the field from
:type block: :class:`~xblock.core.XBlock`
:param name: name of t... | [
"def",
"_getfield",
"(",
"self",
",",
"block",
",",
"name",
")",
":",
"block_field",
"=",
"getattr",
"(",
"block",
".",
"__class__",
",",
"name",
",",
"None",
")",
"if",
"block_field",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"block_field",
",",
... | Return the field with the given `name` from `block`.
If no field with `name` exists in any namespace, raises a KeyError.
:param block: xblock to retrieve the field from
:type block: :class:`~xblock.core.XBlock`
:param name: name of the field to retrieve
:type name: str
:... | [
"Return",
"the",
"field",
"with",
"the",
"given",
"name",
"from",
"block",
".",
"If",
"no",
"field",
"with",
"name",
"exists",
"in",
"any",
"namespace",
"raises",
"a",
"KeyError",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L130-L149 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData.get | def get(self, block, name):
"""
Retrieve the value for the field named `name`.
If a value is provided for `default`, then it will be
returned if no value is set
"""
return self._kvs.get(self._key(block, name)) | python | def get(self, block, name):
"""
Retrieve the value for the field named `name`.
If a value is provided for `default`, then it will be
returned if no value is set
"""
return self._kvs.get(self._key(block, name)) | [
"def",
"get",
"(",
"self",
",",
"block",
",",
"name",
")",
":",
"return",
"self",
".",
"_kvs",
".",
"get",
"(",
"self",
".",
"_key",
"(",
"block",
",",
"name",
")",
")"
] | Retrieve the value for the field named `name`.
If a value is provided for `default`, then it will be
returned if no value is set | [
"Retrieve",
"the",
"value",
"for",
"the",
"field",
"named",
"name",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L193-L200 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData.set | def set(self, block, name, value):
"""
Set the value of the field named `name`
"""
self._kvs.set(self._key(block, name), value) | python | def set(self, block, name, value):
"""
Set the value of the field named `name`
"""
self._kvs.set(self._key(block, name), value) | [
"def",
"set",
"(",
"self",
",",
"block",
",",
"name",
",",
"value",
")",
":",
"self",
".",
"_kvs",
".",
"set",
"(",
"self",
".",
"_key",
"(",
"block",
",",
"name",
")",
",",
"value",
")"
] | Set the value of the field named `name` | [
"Set",
"the",
"value",
"of",
"the",
"field",
"named",
"name"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L202-L206 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData.delete | def delete(self, block, name):
"""
Reset the value of the field named `name` to the default
"""
self._kvs.delete(self._key(block, name)) | python | def delete(self, block, name):
"""
Reset the value of the field named `name` to the default
"""
self._kvs.delete(self._key(block, name)) | [
"def",
"delete",
"(",
"self",
",",
"block",
",",
"name",
")",
":",
"self",
".",
"_kvs",
".",
"delete",
"(",
"self",
".",
"_key",
"(",
"block",
",",
"name",
")",
")"
] | Reset the value of the field named `name` to the default | [
"Reset",
"the",
"value",
"of",
"the",
"field",
"named",
"name",
"to",
"the",
"default"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L208-L212 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData.has | def has(self, block, name):
"""
Return whether or not the field named `name` has a non-default value
"""
try:
return self._kvs.has(self._key(block, name))
except KeyError:
return False | python | def has(self, block, name):
"""
Return whether or not the field named `name` has a non-default value
"""
try:
return self._kvs.has(self._key(block, name))
except KeyError:
return False | [
"def",
"has",
"(",
"self",
",",
"block",
",",
"name",
")",
":",
"try",
":",
"return",
"self",
".",
"_kvs",
".",
"has",
"(",
"self",
".",
"_key",
"(",
"block",
",",
"name",
")",
")",
"except",
"KeyError",
":",
"return",
"False"
] | Return whether or not the field named `name` has a non-default value | [
"Return",
"whether",
"or",
"not",
"the",
"field",
"named",
"name",
"has",
"a",
"non",
"-",
"default",
"value"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L214-L221 | train |
edx/XBlock | xblock/runtime.py | KvsFieldData.set_many | def set_many(self, block, update_dict):
"""Update the underlying model with the correct values."""
updated_dict = {}
# Generate a new dict with the correct mappings.
for (key, value) in six.iteritems(update_dict):
updated_dict[self._key(block, key)] = value
self._kv... | python | def set_many(self, block, update_dict):
"""Update the underlying model with the correct values."""
updated_dict = {}
# Generate a new dict with the correct mappings.
for (key, value) in six.iteritems(update_dict):
updated_dict[self._key(block, key)] = value
self._kv... | [
"def",
"set_many",
"(",
"self",
",",
"block",
",",
"update_dict",
")",
":",
"updated_dict",
"=",
"{",
"}",
"for",
"(",
"key",
",",
"value",
")",
"in",
"six",
".",
"iteritems",
"(",
"update_dict",
")",
":",
"updated_dict",
"[",
"self",
".",
"_key",
"(... | Update the underlying model with the correct values. | [
"Update",
"the",
"underlying",
"model",
"with",
"the",
"correct",
"values",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L223-L231 | train |
edx/XBlock | xblock/runtime.py | MemoryIdManager.create_aside | def create_aside(self, definition_id, usage_id, aside_type):
"""Create the aside."""
return (
self.ASIDE_DEFINITION_ID(definition_id, aside_type),
self.ASIDE_USAGE_ID(usage_id, aside_type),
) | python | def create_aside(self, definition_id, usage_id, aside_type):
"""Create the aside."""
return (
self.ASIDE_DEFINITION_ID(definition_id, aside_type),
self.ASIDE_USAGE_ID(usage_id, aside_type),
) | [
"def",
"create_aside",
"(",
"self",
",",
"definition_id",
",",
"usage_id",
",",
"aside_type",
")",
":",
"return",
"(",
"self",
".",
"ASIDE_DEFINITION_ID",
"(",
"definition_id",
",",
"aside_type",
")",
",",
"self",
".",
"ASIDE_USAGE_ID",
"(",
"usage_id",
",",
... | Create the aside. | [
"Create",
"the",
"aside",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L385-L390 | train |
edx/XBlock | xblock/runtime.py | MemoryIdManager.create_usage | def create_usage(self, def_id):
"""Make a usage, storing its definition id."""
usage_id = self._next_id("u")
self._usages[usage_id] = def_id
return usage_id | python | def create_usage(self, def_id):
"""Make a usage, storing its definition id."""
usage_id = self._next_id("u")
self._usages[usage_id] = def_id
return usage_id | [
"def",
"create_usage",
"(",
"self",
",",
"def_id",
")",
":",
"usage_id",
"=",
"self",
".",
"_next_id",
"(",
"\"u\"",
")",
"self",
".",
"_usages",
"[",
"usage_id",
"]",
"=",
"def_id",
"return",
"usage_id"
] | Make a usage, storing its definition id. | [
"Make",
"a",
"usage",
"storing",
"its",
"definition",
"id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L400-L404 | train |
edx/XBlock | xblock/runtime.py | MemoryIdManager.get_definition_id | def get_definition_id(self, usage_id):
"""Get a definition_id by its usage id."""
try:
return self._usages[usage_id]
except KeyError:
raise NoSuchUsage(repr(usage_id)) | python | def get_definition_id(self, usage_id):
"""Get a definition_id by its usage id."""
try:
return self._usages[usage_id]
except KeyError:
raise NoSuchUsage(repr(usage_id)) | [
"def",
"get_definition_id",
"(",
"self",
",",
"usage_id",
")",
":",
"try",
":",
"return",
"self",
".",
"_usages",
"[",
"usage_id",
"]",
"except",
"KeyError",
":",
"raise",
"NoSuchUsage",
"(",
"repr",
"(",
"usage_id",
")",
")"
] | Get a definition_id by its usage id. | [
"Get",
"a",
"definition_id",
"by",
"its",
"usage",
"id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L406-L411 | train |
edx/XBlock | xblock/runtime.py | MemoryIdManager.create_definition | def create_definition(self, block_type, slug=None):
"""Make a definition, storing its block type."""
prefix = "d"
if slug:
prefix += "_" + slug
def_id = self._next_id(prefix)
self._definitions[def_id] = block_type
return def_id | python | def create_definition(self, block_type, slug=None):
"""Make a definition, storing its block type."""
prefix = "d"
if slug:
prefix += "_" + slug
def_id = self._next_id(prefix)
self._definitions[def_id] = block_type
return def_id | [
"def",
"create_definition",
"(",
"self",
",",
"block_type",
",",
"slug",
"=",
"None",
")",
":",
"prefix",
"=",
"\"d\"",
"if",
"slug",
":",
"prefix",
"+=",
"\"_\"",
"+",
"slug",
"def_id",
"=",
"self",
".",
"_next_id",
"(",
"prefix",
")",
"self",
".",
... | Make a definition, storing its block type. | [
"Make",
"a",
"definition",
"storing",
"its",
"block",
"type",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L413-L420 | train |
edx/XBlock | xblock/runtime.py | MemoryIdManager.get_block_type | def get_block_type(self, def_id):
"""Get a block_type by its definition id."""
try:
return self._definitions[def_id]
except KeyError:
try:
return def_id.aside_type
except AttributeError:
raise NoSuchDefinition(repr(def_id)) | python | def get_block_type(self, def_id):
"""Get a block_type by its definition id."""
try:
return self._definitions[def_id]
except KeyError:
try:
return def_id.aside_type
except AttributeError:
raise NoSuchDefinition(repr(def_id)) | [
"def",
"get_block_type",
"(",
"self",
",",
"def_id",
")",
":",
"try",
":",
"return",
"self",
".",
"_definitions",
"[",
"def_id",
"]",
"except",
"KeyError",
":",
"try",
":",
"return",
"def_id",
".",
"aside_type",
"except",
"AttributeError",
":",
"raise",
"N... | Get a block_type by its definition id. | [
"Get",
"a",
"block_type",
"by",
"its",
"definition",
"id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L422-L430 | train |
edx/XBlock | xblock/runtime.py | Runtime.field_data | def field_data(self, field_data):
"""
Set field_data.
Deprecated in favor of a 'field-data' service.
"""
warnings.warn("Runtime.field_data is deprecated", FieldDataDeprecationWarning, stacklevel=2)
self._deprecated_per_instance_field_data = field_data | python | def field_data(self, field_data):
"""
Set field_data.
Deprecated in favor of a 'field-data' service.
"""
warnings.warn("Runtime.field_data is deprecated", FieldDataDeprecationWarning, stacklevel=2)
self._deprecated_per_instance_field_data = field_data | [
"def",
"field_data",
"(",
"self",
",",
"field_data",
")",
":",
"warnings",
".",
"warn",
"(",
"\"Runtime.field_data is deprecated\"",
",",
"FieldDataDeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"self",
".",
"_deprecated_per_instance_field_data",
"=",
"field_d... | Set field_data.
Deprecated in favor of a 'field-data' service. | [
"Set",
"field_data",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L593-L600 | train |
edx/XBlock | xblock/runtime.py | Runtime.construct_xblock_from_class | def construct_xblock_from_class(self, cls, scope_ids, field_data=None, *args, **kwargs):
"""
Construct a new xblock of type cls, mixing in the mixins
defined for this application.
"""
return self.mixologist.mix(cls)(
runtime=self,
field_data=field_data,
... | python | def construct_xblock_from_class(self, cls, scope_ids, field_data=None, *args, **kwargs):
"""
Construct a new xblock of type cls, mixing in the mixins
defined for this application.
"""
return self.mixologist.mix(cls)(
runtime=self,
field_data=field_data,
... | [
"def",
"construct_xblock_from_class",
"(",
"self",
",",
"cls",
",",
"scope_ids",
",",
"field_data",
"=",
"None",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"self",
".",
"mixologist",
".",
"mix",
"(",
"cls",
")",
"(",
"runtime",
"=",
"se... | Construct a new xblock of type cls, mixing in the mixins
defined for this application. | [
"Construct",
"a",
"new",
"xblock",
"of",
"type",
"cls",
"mixing",
"in",
"the",
"mixins",
"defined",
"for",
"this",
"application",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L626-L636 | train |
edx/XBlock | xblock/runtime.py | Runtime.get_block | def get_block(self, usage_id, for_parent=None):
"""
Create an XBlock instance in this runtime.
The `usage_id` is used to find the XBlock class and data.
"""
def_id = self.id_reader.get_definition_id(usage_id)
try:
block_type = self.id_reader.get_block_type(de... | python | def get_block(self, usage_id, for_parent=None):
"""
Create an XBlock instance in this runtime.
The `usage_id` is used to find the XBlock class and data.
"""
def_id = self.id_reader.get_definition_id(usage_id)
try:
block_type = self.id_reader.get_block_type(de... | [
"def",
"get_block",
"(",
"self",
",",
"usage_id",
",",
"for_parent",
"=",
"None",
")",
":",
"def_id",
"=",
"self",
".",
"id_reader",
".",
"get_definition_id",
"(",
"usage_id",
")",
"try",
":",
"block_type",
"=",
"self",
".",
"id_reader",
".",
"get_block_ty... | Create an XBlock instance in this runtime.
The `usage_id` is used to find the XBlock class and data. | [
"Create",
"an",
"XBlock",
"instance",
"in",
"this",
"runtime",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L638-L651 | train |
edx/XBlock | xblock/runtime.py | Runtime.get_aside | def get_aside(self, aside_usage_id):
"""
Create an XBlockAside in this runtime.
The `aside_usage_id` is used to find the Aside class and data.
"""
aside_type = self.id_reader.get_aside_type_from_usage(aside_usage_id)
xblock_usage = self.id_reader.get_usage_id_from_aside(... | python | def get_aside(self, aside_usage_id):
"""
Create an XBlockAside in this runtime.
The `aside_usage_id` is used to find the Aside class and data.
"""
aside_type = self.id_reader.get_aside_type_from_usage(aside_usage_id)
xblock_usage = self.id_reader.get_usage_id_from_aside(... | [
"def",
"get_aside",
"(",
"self",
",",
"aside_usage_id",
")",
":",
"aside_type",
"=",
"self",
".",
"id_reader",
".",
"get_aside_type_from_usage",
"(",
"aside_usage_id",
")",
"xblock_usage",
"=",
"self",
".",
"id_reader",
".",
"get_usage_id_from_aside",
"(",
"aside_... | Create an XBlockAside in this runtime.
The `aside_usage_id` is used to find the Aside class and data. | [
"Create",
"an",
"XBlockAside",
"in",
"this",
"runtime",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L653-L666 | train |
edx/XBlock | xblock/runtime.py | Runtime.parse_xml_string | def parse_xml_string(self, xml, id_generator=None):
"""Parse a string of XML, returning a usage id."""
if id_generator is not None:
warnings.warn(
"Passing an id_generator directly is deprecated "
"in favor of constructing the Runtime with the id_generator",
... | python | def parse_xml_string(self, xml, id_generator=None):
"""Parse a string of XML, returning a usage id."""
if id_generator is not None:
warnings.warn(
"Passing an id_generator directly is deprecated "
"in favor of constructing the Runtime with the id_generator",
... | [
"def",
"parse_xml_string",
"(",
"self",
",",
"xml",
",",
"id_generator",
"=",
"None",
")",
":",
"if",
"id_generator",
"is",
"not",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Passing an id_generator directly is deprecated \"",
"\"in favor of constructing the Runtime w... | Parse a string of XML, returning a usage id. | [
"Parse",
"a",
"string",
"of",
"XML",
"returning",
"a",
"usage",
"id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L670-L685 | train |
edx/XBlock | xblock/runtime.py | Runtime.parse_xml_file | def parse_xml_file(self, fileobj, id_generator=None):
"""Parse an open XML file, returning a usage id."""
root = etree.parse(fileobj).getroot()
usage_id = self._usage_id_from_node(root, None, id_generator)
return usage_id | python | def parse_xml_file(self, fileobj, id_generator=None):
"""Parse an open XML file, returning a usage id."""
root = etree.parse(fileobj).getroot()
usage_id = self._usage_id_from_node(root, None, id_generator)
return usage_id | [
"def",
"parse_xml_file",
"(",
"self",
",",
"fileobj",
",",
"id_generator",
"=",
"None",
")",
":",
"root",
"=",
"etree",
".",
"parse",
"(",
"fileobj",
")",
".",
"getroot",
"(",
")",
"usage_id",
"=",
"self",
".",
"_usage_id_from_node",
"(",
"root",
",",
... | Parse an open XML file, returning a usage id. | [
"Parse",
"an",
"open",
"XML",
"file",
"returning",
"a",
"usage",
"id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L687-L691 | train |
edx/XBlock | xblock/runtime.py | Runtime._usage_id_from_node | def _usage_id_from_node(self, node, parent_id, id_generator=None):
"""Create a new usage id from an XML dom node.
Args:
node (lxml.etree.Element): The DOM node to interpret.
parent_id: The usage ID of the parent block
id_generator (IdGenerator): The :class:`.IdGenera... | python | def _usage_id_from_node(self, node, parent_id, id_generator=None):
"""Create a new usage id from an XML dom node.
Args:
node (lxml.etree.Element): The DOM node to interpret.
parent_id: The usage ID of the parent block
id_generator (IdGenerator): The :class:`.IdGenera... | [
"def",
"_usage_id_from_node",
"(",
"self",
",",
"node",
",",
"parent_id",
",",
"id_generator",
"=",
"None",
")",
":",
"if",
"id_generator",
"is",
"not",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Passing an id_generator directly is deprecated \"",
"\"in favor of ... | Create a new usage id from an XML dom node.
Args:
node (lxml.etree.Element): The DOM node to interpret.
parent_id: The usage ID of the parent block
id_generator (IdGenerator): The :class:`.IdGenerator` to use
for creating ids | [
"Create",
"a",
"new",
"usage",
"id",
"from",
"an",
"XML",
"dom",
"node",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L693-L736 | train |
edx/XBlock | xblock/runtime.py | Runtime._aside_from_xml | def _aside_from_xml(self, node, block_def_id, block_usage_id, id_generator):
"""
Create an aside from the xml and attach it to the given block
"""
id_generator = id_generator or self.id_generator
aside_type = node.tag
aside_class = self.load_aside_type(aside_type)
... | python | def _aside_from_xml(self, node, block_def_id, block_usage_id, id_generator):
"""
Create an aside from the xml and attach it to the given block
"""
id_generator = id_generator or self.id_generator
aside_type = node.tag
aside_class = self.load_aside_type(aside_type)
... | [
"def",
"_aside_from_xml",
"(",
"self",
",",
"node",
",",
"block_def_id",
",",
"block_usage_id",
",",
"id_generator",
")",
":",
"id_generator",
"=",
"id_generator",
"or",
"self",
".",
"id_generator",
"aside_type",
"=",
"node",
".",
"tag",
"aside_class",
"=",
"s... | Create an aside from the xml and attach it to the given block | [
"Create",
"an",
"aside",
"from",
"the",
"xml",
"and",
"attach",
"it",
"to",
"the",
"given",
"block"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L738-L749 | train |
edx/XBlock | xblock/runtime.py | Runtime.add_node_as_child | def add_node_as_child(self, block, node, id_generator=None):
"""
Called by XBlock.parse_xml to treat a child node as a child block.
"""
usage_id = self._usage_id_from_node(node, block.scope_ids.usage_id, id_generator)
block.children.append(usage_id) | python | def add_node_as_child(self, block, node, id_generator=None):
"""
Called by XBlock.parse_xml to treat a child node as a child block.
"""
usage_id = self._usage_id_from_node(node, block.scope_ids.usage_id, id_generator)
block.children.append(usage_id) | [
"def",
"add_node_as_child",
"(",
"self",
",",
"block",
",",
"node",
",",
"id_generator",
"=",
"None",
")",
":",
"usage_id",
"=",
"self",
".",
"_usage_id_from_node",
"(",
"node",
",",
"block",
".",
"scope_ids",
".",
"usage_id",
",",
"id_generator",
")",
"bl... | Called by XBlock.parse_xml to treat a child node as a child block. | [
"Called",
"by",
"XBlock",
".",
"parse_xml",
"to",
"treat",
"a",
"child",
"node",
"as",
"a",
"child",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L751-L756 | train |
edx/XBlock | xblock/runtime.py | Runtime.export_to_xml | def export_to_xml(self, block, xmlfile):
"""
Export the block to XML, writing the XML to `xmlfile`.
"""
root = etree.Element("unknown_root", nsmap=XML_NAMESPACES)
tree = etree.ElementTree(root)
block.add_xml_to_node(root)
# write asides as children
for asi... | python | def export_to_xml(self, block, xmlfile):
"""
Export the block to XML, writing the XML to `xmlfile`.
"""
root = etree.Element("unknown_root", nsmap=XML_NAMESPACES)
tree = etree.ElementTree(root)
block.add_xml_to_node(root)
# write asides as children
for asi... | [
"def",
"export_to_xml",
"(",
"self",
",",
"block",
",",
"xmlfile",
")",
":",
"root",
"=",
"etree",
".",
"Element",
"(",
"\"unknown_root\"",
",",
"nsmap",
"=",
"XML_NAMESPACES",
")",
"tree",
"=",
"etree",
".",
"ElementTree",
"(",
"root",
")",
"block",
"."... | Export the block to XML, writing the XML to `xmlfile`. | [
"Export",
"the",
"block",
"to",
"XML",
"writing",
"the",
"XML",
"to",
"xmlfile",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L760-L773 | train |
edx/XBlock | xblock/runtime.py | Runtime.add_block_as_child_node | def add_block_as_child_node(self, block, node):
"""
Export `block` as a child node of `node`.
"""
child = etree.SubElement(node, "unknown")
block.add_xml_to_node(child) | python | def add_block_as_child_node(self, block, node):
"""
Export `block` as a child node of `node`.
"""
child = etree.SubElement(node, "unknown")
block.add_xml_to_node(child) | [
"def",
"add_block_as_child_node",
"(",
"self",
",",
"block",
",",
"node",
")",
":",
"child",
"=",
"etree",
".",
"SubElement",
"(",
"node",
",",
"\"unknown\"",
")",
"block",
".",
"add_xml_to_node",
"(",
"child",
")"
] | Export `block` as a child node of `node`. | [
"Export",
"block",
"as",
"a",
"child",
"node",
"of",
"node",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L775-L780 | train |
edx/XBlock | xblock/runtime.py | Runtime.render | def render(self, block, view_name, context=None):
"""
Render a block by invoking its view.
Finds the view named `view_name` on `block`. The default view will be
used if a specific view hasn't be registered. If there is no default
view, an exception will be raised.
The... | python | def render(self, block, view_name, context=None):
"""
Render a block by invoking its view.
Finds the view named `view_name` on `block`. The default view will be
used if a specific view hasn't be registered. If there is no default
view, an exception will be raised.
The... | [
"def",
"render",
"(",
"self",
",",
"block",
",",
"view_name",
",",
"context",
"=",
"None",
")",
":",
"old_view_name",
"=",
"self",
".",
"_view_name",
"self",
".",
"_view_name",
"=",
"view_name",
"try",
":",
"view_fn",
"=",
"getattr",
"(",
"block",
",",
... | Render a block by invoking its view.
Finds the view named `view_name` on `block`. The default view will be
used if a specific view hasn't be registered. If there is no default
view, an exception will be raised.
The view is invoked, passing it `context`. The value returned by the
... | [
"Render",
"a",
"block",
"by",
"invoking",
"its",
"view",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L784-L818 | train |
edx/XBlock | xblock/runtime.py | Runtime.render_child | def render_child(self, child, view_name=None, context=None):
"""A shortcut to render a child block.
Use this method to render your children from your own view function.
If `view_name` is not provided, it will default to the view name you're
being rendered with.
Returns the sam... | python | def render_child(self, child, view_name=None, context=None):
"""A shortcut to render a child block.
Use this method to render your children from your own view function.
If `view_name` is not provided, it will default to the view name you're
being rendered with.
Returns the sam... | [
"def",
"render_child",
"(",
"self",
",",
"child",
",",
"view_name",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"return",
"child",
".",
"render",
"(",
"view_name",
"or",
"self",
".",
"_view_name",
",",
"context",
")"
] | A shortcut to render a child block.
Use this method to render your children from your own view function.
If `view_name` is not provided, it will default to the view name you're
being rendered with.
Returns the same value as :func:`render`. | [
"A",
"shortcut",
"to",
"render",
"a",
"child",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L820-L831 | train |
edx/XBlock | xblock/runtime.py | Runtime.render_children | def render_children(self, block, view_name=None, context=None):
"""Render a block's children, returning a list of results.
Each child of `block` will be rendered, just as :func:`render_child` does.
Returns a list of values, each as provided by :func:`render`.
"""
results = []
... | python | def render_children(self, block, view_name=None, context=None):
"""Render a block's children, returning a list of results.
Each child of `block` will be rendered, just as :func:`render_child` does.
Returns a list of values, each as provided by :func:`render`.
"""
results = []
... | [
"def",
"render_children",
"(",
"self",
",",
"block",
",",
"view_name",
"=",
"None",
",",
"context",
"=",
"None",
")",
":",
"results",
"=",
"[",
"]",
"for",
"child_id",
"in",
"block",
".",
"children",
":",
"child",
"=",
"self",
".",
"get_block",
"(",
... | Render a block's children, returning a list of results.
Each child of `block` will be rendered, just as :func:`render_child` does.
Returns a list of values, each as provided by :func:`render`. | [
"Render",
"a",
"block",
"s",
"children",
"returning",
"a",
"list",
"of",
"results",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L833-L846 | train |
edx/XBlock | xblock/runtime.py | Runtime.wrap_xblock | def wrap_xblock(self, block, view, frag, context): # pylint: disable=W0613
"""
Creates a div which identifies the xblock and writes out the json_init_args into a script tag.
If there's a `wrap_child` method, it calls that with a deprecation warning.
The default implementation creates ... | python | def wrap_xblock(self, block, view, frag, context): # pylint: disable=W0613
"""
Creates a div which identifies the xblock and writes out the json_init_args into a script tag.
If there's a `wrap_child` method, it calls that with a deprecation warning.
The default implementation creates ... | [
"def",
"wrap_xblock",
"(",
"self",
",",
"block",
",",
"view",
",",
"frag",
",",
"context",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'wrap_child'",
")",
":",
"log",
".",
"warning",
"(",
"\"wrap_child is deprecated in favor of wrap_xblock and wrap_aside %s\"",
... | Creates a div which identifies the xblock and writes out the json_init_args into a script tag.
If there's a `wrap_child` method, it calls that with a deprecation warning.
The default implementation creates a frag to wraps frag w/ a div identifying the xblock. If you have
javascript, you'll nee... | [
"Creates",
"a",
"div",
"which",
"identifies",
"the",
"xblock",
"and",
"writes",
"out",
"the",
"json_init_args",
"into",
"a",
"script",
"tag",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L848-L862 | train |
edx/XBlock | xblock/runtime.py | Runtime.wrap_aside | def wrap_aside(self, block, aside, view, frag, context): # pylint: disable=unused-argument
"""
Creates a div which identifies the aside, points to the original block,
and writes out the json_init_args into a script tag.
The default implementation creates a frag to wraps frag w/ a div i... | python | def wrap_aside(self, block, aside, view, frag, context): # pylint: disable=unused-argument
"""
Creates a div which identifies the aside, points to the original block,
and writes out the json_init_args into a script tag.
The default implementation creates a frag to wraps frag w/ a div i... | [
"def",
"wrap_aside",
"(",
"self",
",",
"block",
",",
"aside",
",",
"view",
",",
"frag",
",",
"context",
")",
":",
"return",
"self",
".",
"_wrap_ele",
"(",
"aside",
",",
"view",
",",
"frag",
",",
"{",
"'block_id'",
":",
"block",
".",
"scope_ids",
".",... | Creates a div which identifies the aside, points to the original block,
and writes out the json_init_args into a script tag.
The default implementation creates a frag to wraps frag w/ a div identifying the xblock. If you have
javascript, you'll need to override this impl | [
"Creates",
"a",
"div",
"which",
"identifies",
"the",
"aside",
"points",
"to",
"the",
"original",
"block",
"and",
"writes",
"out",
"the",
"json_init_args",
"into",
"a",
"script",
"tag",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L864-L876 | train |
edx/XBlock | xblock/runtime.py | Runtime._wrap_ele | def _wrap_ele(self, block, view, frag, extra_data=None):
"""
Does the guts of the wrapping the same way for both xblocks and asides. Their
wrappers provide other info in extra_data which gets put into the dom data- attrs.
"""
wrapped = Fragment()
data = {
'usa... | python | def _wrap_ele(self, block, view, frag, extra_data=None):
"""
Does the guts of the wrapping the same way for both xblocks and asides. Their
wrappers provide other info in extra_data which gets put into the dom data- attrs.
"""
wrapped = Fragment()
data = {
'usa... | [
"def",
"_wrap_ele",
"(",
"self",
",",
"block",
",",
"view",
",",
"frag",
",",
"extra_data",
"=",
"None",
")",
":",
"wrapped",
"=",
"Fragment",
"(",
")",
"data",
"=",
"{",
"'usage'",
":",
"block",
".",
"scope_ids",
".",
"usage_id",
",",
"'block-type'",
... | Does the guts of the wrapping the same way for both xblocks and asides. Their
wrappers provide other info in extra_data which gets put into the dom data- attrs. | [
"Does",
"the",
"guts",
"of",
"the",
"wrapping",
"the",
"same",
"way",
"for",
"both",
"xblocks",
"and",
"asides",
".",
"Their",
"wrappers",
"provide",
"other",
"info",
"in",
"extra_data",
"which",
"gets",
"put",
"into",
"the",
"dom",
"data",
"-",
"attrs",
... | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L878-L919 | train |
edx/XBlock | xblock/runtime.py | Runtime.get_asides | def get_asides(self, block):
"""
Return instances for all of the asides that will decorate this `block`.
Arguments:
block (:class:`.XBlock`): The block to render retrieve asides for.
Returns:
List of XBlockAside instances
"""
aside_instances = [
... | python | def get_asides(self, block):
"""
Return instances for all of the asides that will decorate this `block`.
Arguments:
block (:class:`.XBlock`): The block to render retrieve asides for.
Returns:
List of XBlockAside instances
"""
aside_instances = [
... | [
"def",
"get_asides",
"(",
"self",
",",
"block",
")",
":",
"aside_instances",
"=",
"[",
"self",
".",
"get_aside_of_type",
"(",
"block",
",",
"aside_type",
")",
"for",
"aside_type",
"in",
"self",
".",
"applicable_aside_types",
"(",
"block",
")",
"]",
"return",... | Return instances for all of the asides that will decorate this `block`.
Arguments:
block (:class:`.XBlock`): The block to render retrieve asides for.
Returns:
List of XBlockAside instances | [
"Return",
"instances",
"for",
"all",
"of",
"the",
"asides",
"that",
"will",
"decorate",
"this",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L930-L947 | train |
edx/XBlock | xblock/runtime.py | Runtime.get_aside_of_type | def get_aside_of_type(self, block, aside_type):
"""
Return the aside of the given aside_type which might be decorating this `block`.
Arguments:
block (:class:`.XBlock`): The block to retrieve asides for.
aside_type (`str`): the type of the aside
"""
# TOD... | python | def get_aside_of_type(self, block, aside_type):
"""
Return the aside of the given aside_type which might be decorating this `block`.
Arguments:
block (:class:`.XBlock`): The block to retrieve asides for.
aside_type (`str`): the type of the aside
"""
# TOD... | [
"def",
"get_aside_of_type",
"(",
"self",
",",
"block",
",",
"aside_type",
")",
":",
"if",
"self",
".",
"id_generator",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Runtimes must be supplied with an IdGenerator to load XBlockAsides.\"",
")",
"usage_id",
"=",
"block... | Return the aside of the given aside_type which might be decorating this `block`.
Arguments:
block (:class:`.XBlock`): The block to retrieve asides for.
aside_type (`str`): the type of the aside | [
"Return",
"the",
"aside",
"of",
"the",
"given",
"aside_type",
"which",
"might",
"be",
"decorating",
"this",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L958-L980 | train |
edx/XBlock | xblock/runtime.py | Runtime.render_asides | def render_asides(self, block, view_name, frag, context):
"""
Collect all of the asides' add ons and format them into the frag. The frag already
has the given block's rendering.
"""
aside_frag_fns = []
for aside in self.get_asides(block):
aside_view_fn = aside... | python | def render_asides(self, block, view_name, frag, context):
"""
Collect all of the asides' add ons and format them into the frag. The frag already
has the given block's rendering.
"""
aside_frag_fns = []
for aside in self.get_asides(block):
aside_view_fn = aside... | [
"def",
"render_asides",
"(",
"self",
",",
"block",
",",
"view_name",
",",
"frag",
",",
"context",
")",
":",
"aside_frag_fns",
"=",
"[",
"]",
"for",
"aside",
"in",
"self",
".",
"get_asides",
"(",
"block",
")",
":",
"aside_view_fn",
"=",
"aside",
".",
"a... | Collect all of the asides' add ons and format them into the frag. The frag already
has the given block's rendering. | [
"Collect",
"all",
"of",
"the",
"asides",
"add",
"ons",
"and",
"format",
"them",
"into",
"the",
"frag",
".",
"The",
"frag",
"already",
"has",
"the",
"given",
"block",
"s",
"rendering",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L982-L995 | train |
edx/XBlock | xblock/runtime.py | Runtime.layout_asides | def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
"""
Execute and layout the aside_frags wrt the block's frag. Runtimes should feel free to override this
method to control execution, place, and style the asides appropriately for their application
This default met... | python | def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
"""
Execute and layout the aside_frags wrt the block's frag. Runtimes should feel free to override this
method to control execution, place, and style the asides appropriately for their application
This default met... | [
"def",
"layout_asides",
"(",
"self",
",",
"block",
",",
"context",
",",
"frag",
",",
"view_name",
",",
"aside_frag_fns",
")",
":",
"result",
"=",
"Fragment",
"(",
"frag",
".",
"content",
")",
"result",
".",
"add_fragment_resources",
"(",
"frag",
")",
"for"... | Execute and layout the aside_frags wrt the block's frag. Runtimes should feel free to override this
method to control execution, place, and style the asides appropriately for their application
This default method appends the aside_frags after frag. If you override this, you must
call wrap_aside... | [
"Execute",
"and",
"layout",
"the",
"aside_frags",
"wrt",
"the",
"block",
"s",
"frag",
".",
"Runtimes",
"should",
"feel",
"free",
"to",
"override",
"this",
"method",
"to",
"control",
"execution",
"place",
"and",
"style",
"the",
"asides",
"appropriately",
"for",... | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L997-L1019 | train |
edx/XBlock | xblock/runtime.py | Runtime.handle | def handle(self, block, handler_name, request, suffix=''):
"""
Handles any calls to the specified `handler_name`.
Provides a fallback handler if the specified handler isn't found.
:param handler_name: The name of the handler to call
:param request: The request to handle
... | python | def handle(self, block, handler_name, request, suffix=''):
"""
Handles any calls to the specified `handler_name`.
Provides a fallback handler if the specified handler isn't found.
:param handler_name: The name of the handler to call
:param request: The request to handle
... | [
"def",
"handle",
"(",
"self",
",",
"block",
",",
"handler_name",
",",
"request",
",",
"suffix",
"=",
"''",
")",
":",
"handler",
"=",
"getattr",
"(",
"block",
",",
"handler_name",
",",
"None",
")",
"if",
"handler",
"and",
"getattr",
"(",
"handler",
",",... | Handles any calls to the specified `handler_name`.
Provides a fallback handler if the specified handler isn't found.
:param handler_name: The name of the handler to call
:param request: The request to handle
:type request: webob.Request
:param suffix: The remainder of the url, ... | [
"Handles",
"any",
"calls",
"to",
"the",
"specified",
"handler_name",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1023-L1048 | train |
edx/XBlock | xblock/runtime.py | Runtime.service | def service(self, block, service_name):
"""Return a service, or None.
Services are objects implementing arbitrary other interfaces. They are
requested by agreed-upon names, see [XXX TODO] for a list of possible
services. The object returned depends on the service requested.
X... | python | def service(self, block, service_name):
"""Return a service, or None.
Services are objects implementing arbitrary other interfaces. They are
requested by agreed-upon names, see [XXX TODO] for a list of possible
services. The object returned depends on the service requested.
X... | [
"def",
"service",
"(",
"self",
",",
"block",
",",
"service_name",
")",
":",
"declaration",
"=",
"block",
".",
"service_declaration",
"(",
"service_name",
")",
"if",
"declaration",
"is",
"None",
":",
"raise",
"NoSuchServiceError",
"(",
"\"Service {!r} was not reque... | Return a service, or None.
Services are objects implementing arbitrary other interfaces. They are
requested by agreed-upon names, see [XXX TODO] for a list of possible
services. The object returned depends on the service requested.
XBlocks must announce their intention to request ser... | [
"Return",
"a",
"service",
"or",
"None",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1052-L1082 | train |
edx/XBlock | xblock/runtime.py | Runtime.querypath | def querypath(self, block, path):
"""An XPath-like interface to `query`."""
class BadPath(Exception):
"""Bad path exception thrown when path cannot be found."""
pass
results = self.query(block)
ROOT, SEP, WORD, FINAL = six.moves.range(4) # pylint: di... | python | def querypath(self, block, path):
"""An XPath-like interface to `query`."""
class BadPath(Exception):
"""Bad path exception thrown when path cannot be found."""
pass
results = self.query(block)
ROOT, SEP, WORD, FINAL = six.moves.range(4) # pylint: di... | [
"def",
"querypath",
"(",
"self",
",",
"block",
",",
"path",
")",
":",
"class",
"BadPath",
"(",
"Exception",
")",
":",
"pass",
"results",
"=",
"self",
".",
"query",
"(",
"block",
")",
"ROOT",
",",
"SEP",
",",
"WORD",
",",
"FINAL",
"=",
"six",
".",
... | An XPath-like interface to `query`. | [
"An",
"XPath",
"-",
"like",
"interface",
"to",
"query",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1095-L1156 | train |
edx/XBlock | xblock/runtime.py | ObjectAggregator._object_with_attr | def _object_with_attr(self, name):
"""
Returns the first object that has the attribute `name`
:param name: the attribute to filter by
:type name: `str`
:raises AttributeError: when no object has the named attribute
"""
for obj in self._objects:
if has... | python | def _object_with_attr(self, name):
"""
Returns the first object that has the attribute `name`
:param name: the attribute to filter by
:type name: `str`
:raises AttributeError: when no object has the named attribute
"""
for obj in self._objects:
if has... | [
"def",
"_object_with_attr",
"(",
"self",
",",
"name",
")",
":",
"for",
"obj",
"in",
"self",
".",
"_objects",
":",
"if",
"hasattr",
"(",
"obj",
",",
"name",
")",
":",
"return",
"obj",
"raise",
"AttributeError",
"(",
"\"No object has attribute {!r}\"",
".",
... | Returns the first object that has the attribute `name`
:param name: the attribute to filter by
:type name: `str`
:raises AttributeError: when no object has the named attribute | [
"Returns",
"the",
"first",
"object",
"that",
"has",
"the",
"attribute",
"name"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1179-L1191 | train |
edx/XBlock | xblock/runtime.py | Mixologist.mix | def mix(self, cls):
"""
Returns a subclass of `cls` mixed with `self.mixins`.
:param cls: The base class to mix into
:type cls: `class`
"""
if hasattr(cls, 'unmixed_class'):
base_class = cls.unmixed_class
old_mixins = cls.__bases__[1:] # Skip th... | python | def mix(self, cls):
"""
Returns a subclass of `cls` mixed with `self.mixins`.
:param cls: The base class to mix into
:type cls: `class`
"""
if hasattr(cls, 'unmixed_class'):
base_class = cls.unmixed_class
old_mixins = cls.__bases__[1:] # Skip th... | [
"def",
"mix",
"(",
"self",
",",
"cls",
")",
":",
"if",
"hasattr",
"(",
"cls",
",",
"'unmixed_class'",
")",
":",
"base_class",
"=",
"cls",
".",
"unmixed_class",
"old_mixins",
"=",
"cls",
".",
"__bases__",
"[",
"1",
":",
"]",
"mixins",
"=",
"old_mixins",... | Returns a subclass of `cls` mixed with `self.mixins`.
:param cls: The base class to mix into
:type cls: `class` | [
"Returns",
"a",
"subclass",
"of",
"cls",
"mixed",
"with",
"self",
".",
"mixins",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1219-L1253 | train |
edx/XBlock | xblock/runtime.py | RegexLexer.lex | def lex(self, text):
"""Iterator that tokenizes `text` and yields up tokens as they are found"""
for match in self.regex.finditer(text):
name = match.lastgroup
yield (name, match.group(name)) | python | def lex(self, text):
"""Iterator that tokenizes `text` and yields up tokens as they are found"""
for match in self.regex.finditer(text):
name = match.lastgroup
yield (name, match.group(name)) | [
"def",
"lex",
"(",
"self",
",",
"text",
")",
":",
"for",
"match",
"in",
"self",
".",
"regex",
".",
"finditer",
"(",
"text",
")",
":",
"name",
"=",
"match",
".",
"lastgroup",
"yield",
"(",
"name",
",",
"match",
".",
"group",
"(",
"name",
")",
")"
... | Iterator that tokenizes `text` and yields up tokens as they are found | [
"Iterator",
"that",
"tokenizes",
"text",
"and",
"yields",
"up",
"tokens",
"as",
"they",
"are",
"found"
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1264-L1268 | train |
edx/XBlock | xblock/runtime.py | NullI18nService.strftime | def strftime(self, dtime, format): # pylint: disable=redefined-builtin
"""
Locale-aware strftime, with format short-cuts.
"""
format = self.STRFTIME_FORMATS.get(format + "_FORMAT", format)
if six.PY2 and isinstance(format, six.text_type):
format = format.encode("... | python | def strftime(self, dtime, format): # pylint: disable=redefined-builtin
"""
Locale-aware strftime, with format short-cuts.
"""
format = self.STRFTIME_FORMATS.get(format + "_FORMAT", format)
if six.PY2 and isinstance(format, six.text_type):
format = format.encode("... | [
"def",
"strftime",
"(",
"self",
",",
"dtime",
",",
"format",
")",
":",
"format",
"=",
"self",
".",
"STRFTIME_FORMATS",
".",
"get",
"(",
"format",
"+",
"\"_FORMAT\"",
",",
"format",
")",
"if",
"six",
".",
"PY2",
"and",
"isinstance",
"(",
"format",
",",
... | Locale-aware strftime, with format short-cuts. | [
"Locale",
"-",
"aware",
"strftime",
"with",
"format",
"short",
"-",
"cuts",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1288-L1298 | train |
edx/XBlock | xblock/runtime.py | NullI18nService.ugettext | def ugettext(self):
"""
Dispatch to the appropriate gettext method to handle text objects.
Note that under python 3, this uses `gettext()`, while under python 2,
it uses `ugettext()`. This should not be used with bytestrings.
"""
# pylint: disable=no-member
if s... | python | def ugettext(self):
"""
Dispatch to the appropriate gettext method to handle text objects.
Note that under python 3, this uses `gettext()`, while under python 2,
it uses `ugettext()`. This should not be used with bytestrings.
"""
# pylint: disable=no-member
if s... | [
"def",
"ugettext",
"(",
"self",
")",
":",
"if",
"six",
".",
"PY2",
":",
"return",
"self",
".",
"_translations",
".",
"ugettext",
"else",
":",
"return",
"self",
".",
"_translations",
".",
"gettext"
] | Dispatch to the appropriate gettext method to handle text objects.
Note that under python 3, this uses `gettext()`, while under python 2,
it uses `ugettext()`. This should not be used with bytestrings. | [
"Dispatch",
"to",
"the",
"appropriate",
"gettext",
"method",
"to",
"handle",
"text",
"objects",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1301-L1312 | train |
edx/XBlock | xblock/runtime.py | NullI18nService.ungettext | def ungettext(self):
"""
Dispatch to the appropriate ngettext method to handle text objects.
Note that under python 3, this uses `ngettext()`, while under python 2,
it uses `ungettext()`. This should not be used with bytestrings.
"""
# pylint: disable=no-member
... | python | def ungettext(self):
"""
Dispatch to the appropriate ngettext method to handle text objects.
Note that under python 3, this uses `ngettext()`, while under python 2,
it uses `ungettext()`. This should not be used with bytestrings.
"""
# pylint: disable=no-member
... | [
"def",
"ungettext",
"(",
"self",
")",
":",
"if",
"six",
".",
"PY2",
":",
"return",
"self",
".",
"_translations",
".",
"ungettext",
"else",
":",
"return",
"self",
".",
"_translations",
".",
"ngettext"
] | Dispatch to the appropriate ngettext method to handle text objects.
Note that under python 3, this uses `ngettext()`, while under python 2,
it uses `ungettext()`. This should not be used with bytestrings. | [
"Dispatch",
"to",
"the",
"appropriate",
"ngettext",
"method",
"to",
"handle",
"text",
"objects",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/runtime.py#L1315-L1326 | train |
edx/XBlock | xblock/reference/plugins.py | FSService.load | def load(self, instance, xblock):
"""
Get the filesystem for the field specified in 'instance' and the
xblock in 'xblock' It is locally scoped.
"""
# TODO: Get xblock from context, once the plumbing is piped through
if djpyfs:
return djpyfs.get_filesystem(sco... | python | def load(self, instance, xblock):
"""
Get the filesystem for the field specified in 'instance' and the
xblock in 'xblock' It is locally scoped.
"""
# TODO: Get xblock from context, once the plumbing is piped through
if djpyfs:
return djpyfs.get_filesystem(sco... | [
"def",
"load",
"(",
"self",
",",
"instance",
",",
"xblock",
")",
":",
"if",
"djpyfs",
":",
"return",
"djpyfs",
".",
"get_filesystem",
"(",
"scope_key",
"(",
"instance",
",",
"xblock",
")",
")",
"else",
":",
"raise",
"NotImplementedError",
"(",
"\"djpyfs no... | Get the filesystem for the field specified in 'instance' and the
xblock in 'xblock' It is locally scoped. | [
"Get",
"the",
"filesystem",
"for",
"the",
"field",
"specified",
"in",
"instance",
"and",
"the",
"xblock",
"in",
"xblock",
"It",
"is",
"locally",
"scoped",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/reference/plugins.py#L190-L205 | train |
edx/XBlock | xblock/completable.py | CompletableXBlockMixin.emit_completion | def emit_completion(self, completion_percent):
"""
Emits completion event through Completion API.
Unlike grading API, calling this method allows completion to go down - i.e. emitting a value of 0.0 on
a previously completed block indicates that it is no longer considered complete.
... | python | def emit_completion(self, completion_percent):
"""
Emits completion event through Completion API.
Unlike grading API, calling this method allows completion to go down - i.e. emitting a value of 0.0 on
a previously completed block indicates that it is no longer considered complete.
... | [
"def",
"emit_completion",
"(",
"self",
",",
"completion_percent",
")",
":",
"completion_mode",
"=",
"XBlockCompletionMode",
".",
"get_mode",
"(",
"self",
")",
"if",
"not",
"self",
".",
"has_custom_completion",
"or",
"completion_mode",
"!=",
"XBlockCompletionMode",
"... | Emits completion event through Completion API.
Unlike grading API, calling this method allows completion to go down - i.e. emitting a value of 0.0 on
a previously completed block indicates that it is no longer considered complete.
Arguments:
completion_percent (float): Completion i... | [
"Emits",
"completion",
"event",
"through",
"Completion",
"API",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/completable.py#L35-L65 | train |
edx/XBlock | xblock/field_data.py | FieldData.has | def has(self, block, name):
"""
Return whether or not the field named `name` has a non-default value for the XBlock `block`.
:param block: block to check
:type block: :class:`~xblock.core.XBlock`
:param name: field name
:type name: str
"""
try:
... | python | def has(self, block, name):
"""
Return whether or not the field named `name` has a non-default value for the XBlock `block`.
:param block: block to check
:type block: :class:`~xblock.core.XBlock`
:param name: field name
:type name: str
"""
try:
... | [
"def",
"has",
"(",
"self",
",",
"block",
",",
"name",
")",
":",
"try",
":",
"self",
".",
"get",
"(",
"block",
",",
"name",
")",
"return",
"True",
"except",
"KeyError",
":",
"return",
"False"
] | Return whether or not the field named `name` has a non-default value for the XBlock `block`.
:param block: block to check
:type block: :class:`~xblock.core.XBlock`
:param name: field name
:type name: str | [
"Return",
"whether",
"or",
"not",
"the",
"field",
"named",
"name",
"has",
"a",
"non",
"-",
"default",
"value",
"for",
"the",
"XBlock",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/field_data.py#L69-L82 | train |
edx/XBlock | xblock/field_data.py | FieldData.set_many | def set_many(self, block, update_dict):
"""
Update many fields on an XBlock simultaneously.
:param block: the block to update
:type block: :class:`~xblock.core.XBlock`
:param update_dict: A map of field names to their new values
:type update_dict: dict
"""
... | python | def set_many(self, block, update_dict):
"""
Update many fields on an XBlock simultaneously.
:param block: the block to update
:type block: :class:`~xblock.core.XBlock`
:param update_dict: A map of field names to their new values
:type update_dict: dict
"""
... | [
"def",
"set_many",
"(",
"self",
",",
"block",
",",
"update_dict",
")",
":",
"for",
"key",
",",
"value",
"in",
"six",
".",
"iteritems",
"(",
"update_dict",
")",
":",
"self",
".",
"set",
"(",
"block",
",",
"key",
",",
"value",
")"
] | Update many fields on an XBlock simultaneously.
:param block: the block to update
:type block: :class:`~xblock.core.XBlock`
:param update_dict: A map of field names to their new values
:type update_dict: dict | [
"Update",
"many",
"fields",
"on",
"an",
"XBlock",
"simultaneously",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/field_data.py#L84-L94 | train |
edx/XBlock | xblock/exceptions.py | JsonHandlerError.get_response | def get_response(self, **kwargs):
"""
Returns a Response object containing this object's status code and a
JSON object containing the key "error" with the value of this object's
error message in the body. Keyword args are passed through to
the Response.
"""
return... | python | def get_response(self, **kwargs):
"""
Returns a Response object containing this object's status code and a
JSON object containing the key "error" with the value of this object's
error message in the body. Keyword args are passed through to
the Response.
"""
return... | [
"def",
"get_response",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"return",
"Response",
"(",
"json",
".",
"dumps",
"(",
"{",
"\"error\"",
":",
"self",
".",
"message",
"}",
")",
",",
"status_code",
"=",
"self",
".",
"status_code",
",",
"content_type",
... | Returns a Response object containing this object's status code and a
JSON object containing the key "error" with the value of this object's
error message in the body. Keyword args are passed through to
the Response. | [
"Returns",
"a",
"Response",
"object",
"containing",
"this",
"object",
"s",
"status",
"code",
"and",
"a",
"JSON",
"object",
"containing",
"the",
"key",
"error",
"with",
"the",
"value",
"of",
"this",
"object",
"s",
"error",
"message",
"in",
"the",
"body",
".... | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/exceptions.py#L126-L139 | train |
edx/XBlock | xblock/mixins.py | HandlersMixin.json_handler | def json_handler(cls, func):
"""
Wrap a handler to consume and produce JSON.
Rather than a Request object, the method will now be passed the
JSON-decoded body of the request. The request should be a POST request
in order to use this method. Any data returned by the function
... | python | def json_handler(cls, func):
"""
Wrap a handler to consume and produce JSON.
Rather than a Request object, the method will now be passed the
JSON-decoded body of the request. The request should be a POST request
in order to use this method. Any data returned by the function
... | [
"def",
"json_handler",
"(",
"cls",
",",
"func",
")",
":",
"@",
"cls",
".",
"handler",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"request",
",",
"suffix",
"=",
"''",
")",
":",
"if",
"request",
".",
"method... | Wrap a handler to consume and produce JSON.
Rather than a Request object, the method will now be passed the
JSON-decoded body of the request. The request should be a POST request
in order to use this method. Any data returned by the function
will be JSON-encoded and returned as the resp... | [
"Wrap",
"a",
"handler",
"to",
"consume",
"and",
"produce",
"JSON",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L40-L75 | train |
edx/XBlock | xblock/mixins.py | HandlersMixin.handle | def handle(self, handler_name, request, suffix=''):
"""Handle `request` with this block's runtime."""
return self.runtime.handle(self, handler_name, request, suffix) | python | def handle(self, handler_name, request, suffix=''):
"""Handle `request` with this block's runtime."""
return self.runtime.handle(self, handler_name, request, suffix) | [
"def",
"handle",
"(",
"self",
",",
"handler_name",
",",
"request",
",",
"suffix",
"=",
"''",
")",
":",
"return",
"self",
".",
"runtime",
".",
"handle",
"(",
"self",
",",
"handler_name",
",",
"request",
",",
"suffix",
")"
] | Handle `request` with this block's runtime. | [
"Handle",
"request",
"with",
"this",
"block",
"s",
"runtime",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L87-L89 | train |
edx/XBlock | xblock/mixins.py | RuntimeServicesMixin._combined_services | def _combined_services(cls): # pylint: disable=no-self-argument
"""
A dictionary that collects all _services_requested by all ancestors of this XBlock class.
"""
# The class declares what services it desires. To deal with subclasses,
# especially mixins, properly, we have to wal... | python | def _combined_services(cls): # pylint: disable=no-self-argument
"""
A dictionary that collects all _services_requested by all ancestors of this XBlock class.
"""
# The class declares what services it desires. To deal with subclasses,
# especially mixins, properly, we have to wal... | [
"def",
"_combined_services",
"(",
"cls",
")",
":",
"combined",
"=",
"{",
"}",
"for",
"parent",
"in",
"reversed",
"(",
"cls",
".",
"mro",
"(",
")",
")",
":",
"combined",
".",
"update",
"(",
"getattr",
"(",
"parent",
",",
"\"_services_requested\"",
",",
... | A dictionary that collects all _services_requested by all ancestors of this XBlock class. | [
"A",
"dictionary",
"that",
"collects",
"all",
"_services_requested",
"by",
"all",
"ancestors",
"of",
"this",
"XBlock",
"class",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L104-L114 | train |
edx/XBlock | xblock/mixins.py | RuntimeServicesMixin.needs | def needs(cls, *service_names):
"""A class decorator to indicate that an XBlock class needs particular services."""
def _decorator(cls_): # pylint: disable=missing-docstring
for service_name in service_names:
cls_._services_requested[service_nam... | python | def needs(cls, *service_names):
"""A class decorator to indicate that an XBlock class needs particular services."""
def _decorator(cls_): # pylint: disable=missing-docstring
for service_name in service_names:
cls_._services_requested[service_nam... | [
"def",
"needs",
"(",
"cls",
",",
"*",
"service_names",
")",
":",
"def",
"_decorator",
"(",
"cls_",
")",
":",
"for",
"service_name",
"in",
"service_names",
":",
"cls_",
".",
"_services_requested",
"[",
"service_name",
"]",
"=",
"\"need\"",
"return",
"cls_",
... | A class decorator to indicate that an XBlock class needs particular services. | [
"A",
"class",
"decorator",
"to",
"indicate",
"that",
"an",
"XBlock",
"class",
"needs",
"particular",
"services",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L127-L133 | train |
edx/XBlock | xblock/mixins.py | RuntimeServicesMixin.wants | def wants(cls, *service_names):
"""A class decorator to indicate that an XBlock class wants particular services."""
def _decorator(cls_): # pylint: disable=missing-docstring
for service_name in service_names:
cls_._services_requested[service_nam... | python | def wants(cls, *service_names):
"""A class decorator to indicate that an XBlock class wants particular services."""
def _decorator(cls_): # pylint: disable=missing-docstring
for service_name in service_names:
cls_._services_requested[service_nam... | [
"def",
"wants",
"(",
"cls",
",",
"*",
"service_names",
")",
":",
"def",
"_decorator",
"(",
"cls_",
")",
":",
"for",
"service_name",
"in",
"service_names",
":",
"cls_",
".",
"_services_requested",
"[",
"service_name",
"]",
"=",
"\"want\"",
"return",
"cls_",
... | A class decorator to indicate that an XBlock class wants particular services. | [
"A",
"class",
"decorator",
"to",
"indicate",
"that",
"an",
"XBlock",
"class",
"wants",
"particular",
"services",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L136-L142 | train |
edx/XBlock | xblock/mixins.py | HierarchyMixin.get_parent | def get_parent(self):
"""Return the parent block of this block, or None if there isn't one."""
if not self.has_cached_parent:
if self.parent is not None:
self._parent_block = self.runtime.get_block(self.parent)
else:
self._parent_block = None
... | python | def get_parent(self):
"""Return the parent block of this block, or None if there isn't one."""
if not self.has_cached_parent:
if self.parent is not None:
self._parent_block = self.runtime.get_block(self.parent)
else:
self._parent_block = None
... | [
"def",
"get_parent",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"has_cached_parent",
":",
"if",
"self",
".",
"parent",
"is",
"not",
"None",
":",
"self",
".",
"_parent_block",
"=",
"self",
".",
"runtime",
".",
"get_block",
"(",
"self",
".",
"paren... | Return the parent block of this block, or None if there isn't one. | [
"Return",
"the",
"parent",
"block",
"of",
"this",
"block",
"or",
"None",
"if",
"there",
"isn",
"t",
"one",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L373-L381 | train |
edx/XBlock | xblock/mixins.py | HierarchyMixin.get_child | def get_child(self, usage_id):
"""Return the child identified by ``usage_id``."""
if usage_id in self._child_cache:
return self._child_cache[usage_id]
child_block = self.runtime.get_block(usage_id, for_parent=self)
self._child_cache[usage_id] = child_block
return chi... | python | def get_child(self, usage_id):
"""Return the child identified by ``usage_id``."""
if usage_id in self._child_cache:
return self._child_cache[usage_id]
child_block = self.runtime.get_block(usage_id, for_parent=self)
self._child_cache[usage_id] = child_block
return chi... | [
"def",
"get_child",
"(",
"self",
",",
"usage_id",
")",
":",
"if",
"usage_id",
"in",
"self",
".",
"_child_cache",
":",
"return",
"self",
".",
"_child_cache",
"[",
"usage_id",
"]",
"child_block",
"=",
"self",
".",
"runtime",
".",
"get_block",
"(",
"usage_id"... | Return the child identified by ``usage_id``. | [
"Return",
"the",
"child",
"identified",
"by",
"usage_id",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L388-L395 | train |
edx/XBlock | xblock/mixins.py | HierarchyMixin.get_children | def get_children(self, usage_id_filter=None):
"""
Return instantiated XBlocks for each of this blocks ``children``.
"""
if not self.has_children:
return []
return [
self.get_child(usage_id)
for usage_id in self.children
if usage_id... | python | def get_children(self, usage_id_filter=None):
"""
Return instantiated XBlocks for each of this blocks ``children``.
"""
if not self.has_children:
return []
return [
self.get_child(usage_id)
for usage_id in self.children
if usage_id... | [
"def",
"get_children",
"(",
"self",
",",
"usage_id_filter",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"has_children",
":",
"return",
"[",
"]",
"return",
"[",
"self",
".",
"get_child",
"(",
"usage_id",
")",
"for",
"usage_id",
"in",
"self",
".",
"... | Return instantiated XBlocks for each of this blocks ``children``. | [
"Return",
"instantiated",
"XBlocks",
"for",
"each",
"of",
"this",
"blocks",
"children",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L397-L408 | train |
edx/XBlock | xblock/mixins.py | HierarchyMixin.add_children_to_node | def add_children_to_node(self, node):
"""
Add children to etree.Element `node`.
"""
if self.has_children:
for child_id in self.children:
child = self.runtime.get_block(child_id)
self.runtime.add_block_as_child_node(child, node) | python | def add_children_to_node(self, node):
"""
Add children to etree.Element `node`.
"""
if self.has_children:
for child_id in self.children:
child = self.runtime.get_block(child_id)
self.runtime.add_block_as_child_node(child, node) | [
"def",
"add_children_to_node",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"has_children",
":",
"for",
"child_id",
"in",
"self",
".",
"children",
":",
"child",
"=",
"self",
".",
"runtime",
".",
"get_block",
"(",
"child_id",
")",
"self",
".",
... | Add children to etree.Element `node`. | [
"Add",
"children",
"to",
"etree",
".",
"Element",
"node",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L416-L423 | train |
edx/XBlock | xblock/mixins.py | XmlSerializationMixin.parse_xml | def parse_xml(cls, node, runtime, keys, id_generator):
"""
Use `node` to construct a new block.
Arguments:
node (:class:`~xml.etree.ElementTree.Element`): The xml node to parse into an xblock.
runtime (:class:`.Runtime`): The runtime to use while parsing.
k... | python | def parse_xml(cls, node, runtime, keys, id_generator):
"""
Use `node` to construct a new block.
Arguments:
node (:class:`~xml.etree.ElementTree.Element`): The xml node to parse into an xblock.
runtime (:class:`.Runtime`): The runtime to use while parsing.
k... | [
"def",
"parse_xml",
"(",
"cls",
",",
"node",
",",
"runtime",
",",
"keys",
",",
"id_generator",
")",
":",
"block",
"=",
"runtime",
".",
"construct_xblock_from_class",
"(",
"cls",
",",
"keys",
")",
"for",
"child",
"in",
"node",
":",
"if",
"child",
".",
"... | Use `node` to construct a new block.
Arguments:
node (:class:`~xml.etree.ElementTree.Element`): The xml node to parse into an xblock.
runtime (:class:`.Runtime`): The runtime to use while parsing.
keys (:class:`.ScopeIds`): The keys identifying where this block
... | [
"Use",
"node",
"to",
"construct",
"a",
"new",
"block",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L432-L477 | train |
edx/XBlock | xblock/mixins.py | XmlSerializationMixin.add_xml_to_node | def add_xml_to_node(self, node):
"""
For exporting, set data on `node` from ourselves.
"""
# pylint: disable=E1101
# Set node.tag based on our class name.
node.tag = self.xml_element_name()
node.set('xblock-family', self.entry_point)
# Set node attributes... | python | def add_xml_to_node(self, node):
"""
For exporting, set data on `node` from ourselves.
"""
# pylint: disable=E1101
# Set node.tag based on our class name.
node.tag = self.xml_element_name()
node.set('xblock-family', self.entry_point)
# Set node attributes... | [
"def",
"add_xml_to_node",
"(",
"self",
",",
"node",
")",
":",
"node",
".",
"tag",
"=",
"self",
".",
"xml_element_name",
"(",
")",
"node",
".",
"set",
"(",
"'xblock-family'",
",",
"self",
".",
"entry_point",
")",
"for",
"field_name",
",",
"field",
"in",
... | For exporting, set data on `node` from ourselves. | [
"For",
"exporting",
"set",
"data",
"on",
"node",
"from",
"ourselves",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L479-L498 | train |
edx/XBlock | xblock/mixins.py | XmlSerializationMixin._set_field_if_present | def _set_field_if_present(cls, block, name, value, attrs):
"""Sets the field block.name, if block have such a field."""
if name in block.fields:
value = (block.fields[name]).from_string(value)
if "none" in attrs and attrs["none"] == "true":
setattr(block, name, No... | python | def _set_field_if_present(cls, block, name, value, attrs):
"""Sets the field block.name, if block have such a field."""
if name in block.fields:
value = (block.fields[name]).from_string(value)
if "none" in attrs and attrs["none"] == "true":
setattr(block, name, No... | [
"def",
"_set_field_if_present",
"(",
"cls",
",",
"block",
",",
"name",
",",
"value",
",",
"attrs",
")",
":",
"if",
"name",
"in",
"block",
".",
"fields",
":",
"value",
"=",
"(",
"block",
".",
"fields",
"[",
"name",
"]",
")",
".",
"from_string",
"(",
... | Sets the field block.name, if block have such a field. | [
"Sets",
"the",
"field",
"block",
".",
"name",
"if",
"block",
"have",
"such",
"a",
"field",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L513-L522 | train |
edx/XBlock | xblock/mixins.py | XmlSerializationMixin._add_field | def _add_field(self, node, field_name, field):
"""
Add xml representation of field to node.
Depending on settings, it either stores the value of field
as an xml attribute or creates a separate child node.
"""
value = field.to_string(field.read_from(self))
text_va... | python | def _add_field(self, node, field_name, field):
"""
Add xml representation of field to node.
Depending on settings, it either stores the value of field
as an xml attribute or creates a separate child node.
"""
value = field.to_string(field.read_from(self))
text_va... | [
"def",
"_add_field",
"(",
"self",
",",
"node",
",",
"field_name",
",",
"field",
")",
":",
"value",
"=",
"field",
".",
"to_string",
"(",
"field",
".",
"read_from",
"(",
"self",
")",
")",
"text_value",
"=",
"\"\"",
"if",
"value",
"is",
"None",
"else",
... | Add xml representation of field to node.
Depending on settings, it either stores the value of field
as an xml attribute or creates a separate child node. | [
"Add",
"xml",
"representation",
"of",
"field",
"to",
"node",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L524-L549 | train |
edx/XBlock | xblock/mixins.py | ViewsMixin.supports | def supports(cls, *functionalities):
"""
A view decorator to indicate that an xBlock view has support for the
given functionalities.
Arguments:
functionalities: String identifiers for the functionalities of the view.
For example: "multi_device".
"""
... | python | def supports(cls, *functionalities):
"""
A view decorator to indicate that an xBlock view has support for the
given functionalities.
Arguments:
functionalities: String identifiers for the functionalities of the view.
For example: "multi_device".
"""
... | [
"def",
"supports",
"(",
"cls",
",",
"*",
"functionalities",
")",
":",
"def",
"_decorator",
"(",
"view",
")",
":",
"if",
"not",
"hasattr",
"(",
"view",
",",
"\"_supports\"",
")",
":",
"view",
".",
"_supports",
"=",
"set",
"(",
")",
"for",
"functionality... | A view decorator to indicate that an xBlock view has support for the
given functionalities.
Arguments:
functionalities: String identifiers for the functionalities of the view.
For example: "multi_device". | [
"A",
"view",
"decorator",
"to",
"indicate",
"that",
"an",
"xBlock",
"view",
"has",
"support",
"for",
"the",
"given",
"functionalities",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/mixins.py#L572-L592 | train |
edx/XBlock | xblock/scorable.py | ScorableXBlockMixin.rescore | def rescore(self, only_if_higher):
"""
Calculate a new raw score and save it to the block. If only_if_higher
is True and the score didn't improve, keep the existing score.
Raises a TypeError if the block cannot be scored.
Raises a ValueError if the user has not yet completed th... | python | def rescore(self, only_if_higher):
"""
Calculate a new raw score and save it to the block. If only_if_higher
is True and the score didn't improve, keep the existing score.
Raises a TypeError if the block cannot be scored.
Raises a ValueError if the user has not yet completed th... | [
"def",
"rescore",
"(",
"self",
",",
"only_if_higher",
")",
":",
"_",
"=",
"self",
".",
"runtime",
".",
"service",
"(",
"self",
",",
"'i18n'",
")",
".",
"ugettext",
"if",
"not",
"self",
".",
"allows_rescore",
"(",
")",
":",
"raise",
"TypeError",
"(",
... | Calculate a new raw score and save it to the block. If only_if_higher
is True and the score didn't improve, keep the existing score.
Raises a TypeError if the block cannot be scored.
Raises a ValueError if the user has not yet completed the problem.
May also raise other errors in self... | [
"Calculate",
"a",
"new",
"raw",
"score",
"and",
"save",
"it",
"to",
"the",
"block",
".",
"If",
"only_if_higher",
"is",
"True",
"and",
"the",
"score",
"didn",
"t",
"improve",
"keep",
"the",
"existing",
"score",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/scorable.py#L34-L55 | train |
edx/XBlock | xblock/scorable.py | ScorableXBlockMixin._publish_grade | def _publish_grade(self, score, only_if_higher=None):
"""
Publish a grade to the runtime.
"""
grade_dict = {
'value': score.raw_earned,
'max_value': score.raw_possible,
'only_if_higher': only_if_higher,
}
self.runtime.publish(self, 'gra... | python | def _publish_grade(self, score, only_if_higher=None):
"""
Publish a grade to the runtime.
"""
grade_dict = {
'value': score.raw_earned,
'max_value': score.raw_possible,
'only_if_higher': only_if_higher,
}
self.runtime.publish(self, 'gra... | [
"def",
"_publish_grade",
"(",
"self",
",",
"score",
",",
"only_if_higher",
"=",
"None",
")",
":",
"grade_dict",
"=",
"{",
"'value'",
":",
"score",
".",
"raw_earned",
",",
"'max_value'",
":",
"score",
".",
"raw_possible",
",",
"'only_if_higher'",
":",
"only_i... | Publish a grade to the runtime. | [
"Publish",
"a",
"grade",
"to",
"the",
"runtime",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/scorable.py#L108-L117 | train |
edx/XBlock | xblock/fields.py | scope_key | def scope_key(instance, xblock):
"""Generate a unique key for a scope that can be used as a
filename, in a URL, or in a KVS.
Our goal is to have a pretty, human-readable 1:1 encoding.
This encoding is as good as we can do. It's reversible, but not
trivial to reverse.
Encoding scheme:
Posi... | python | def scope_key(instance, xblock):
"""Generate a unique key for a scope that can be used as a
filename, in a URL, or in a KVS.
Our goal is to have a pretty, human-readable 1:1 encoding.
This encoding is as good as we can do. It's reversible, but not
trivial to reverse.
Encoding scheme:
Posi... | [
"def",
"scope_key",
"(",
"instance",
",",
"xblock",
")",
":",
"scope_key_dict",
"=",
"{",
"}",
"scope_key_dict",
"[",
"'name'",
"]",
"=",
"instance",
".",
"name",
"if",
"instance",
".",
"scope",
".",
"user",
"==",
"UserScope",
".",
"NONE",
"or",
"instanc... | Generate a unique key for a scope that can be used as a
filename, in a URL, or in a KVS.
Our goal is to have a pretty, human-readable 1:1 encoding.
This encoding is as good as we can do. It's reversible, but not
trivial to reverse.
Encoding scheme:
Posix allows [A-Z][a-z][0-9]._-
We'd lik... | [
"Generate",
"a",
"unique",
"key",
"for",
"a",
"scope",
"that",
"can",
"be",
"used",
"as",
"a",
"filename",
"in",
"a",
"URL",
"or",
"in",
"a",
"KVS",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L1045-L1138 | train |
edx/XBlock | xblock/fields.py | Field.default | def default(self):
"""Returns the static value that this defaults to."""
if self.MUTABLE:
return copy.deepcopy(self._default)
else:
return self._default | python | def default(self):
"""Returns the static value that this defaults to."""
if self.MUTABLE:
return copy.deepcopy(self._default)
else:
return self._default | [
"def",
"default",
"(",
"self",
")",
":",
"if",
"self",
".",
"MUTABLE",
":",
"return",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"_default",
")",
"else",
":",
"return",
"self",
".",
"_default"
] | Returns the static value that this defaults to. | [
"Returns",
"the",
"static",
"value",
"that",
"this",
"defaults",
"to",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L342-L347 | train |
edx/XBlock | xblock/fields.py | Field._set_cached_value | def _set_cached_value(self, xblock, value):
"""Store a value in the xblock's cache, creating the cache if necessary."""
# pylint: disable=protected-access
if not hasattr(xblock, '_field_data_cache'):
xblock._field_data_cache = {}
xblock._field_data_cache[self.name] = value | python | def _set_cached_value(self, xblock, value):
"""Store a value in the xblock's cache, creating the cache if necessary."""
# pylint: disable=protected-access
if not hasattr(xblock, '_field_data_cache'):
xblock._field_data_cache = {}
xblock._field_data_cache[self.name] = value | [
"def",
"_set_cached_value",
"(",
"self",
",",
"xblock",
",",
"value",
")",
":",
"if",
"not",
"hasattr",
"(",
"xblock",
",",
"'_field_data_cache'",
")",
":",
"xblock",
".",
"_field_data_cache",
"=",
"{",
"}",
"xblock",
".",
"_field_data_cache",
"[",
"self",
... | Store a value in the xblock's cache, creating the cache if necessary. | [
"Store",
"a",
"value",
"in",
"the",
"xblock",
"s",
"cache",
"creating",
"the",
"cache",
"if",
"necessary",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L404-L409 | train |
edx/XBlock | xblock/fields.py | Field._del_cached_value | def _del_cached_value(self, xblock):
"""Remove a value from the xblock's cache, if the cache exists."""
# pylint: disable=protected-access
if hasattr(xblock, '_field_data_cache') and self.name in xblock._field_data_cache:
del xblock._field_data_cache[self.name] | python | def _del_cached_value(self, xblock):
"""Remove a value from the xblock's cache, if the cache exists."""
# pylint: disable=protected-access
if hasattr(xblock, '_field_data_cache') and self.name in xblock._field_data_cache:
del xblock._field_data_cache[self.name] | [
"def",
"_del_cached_value",
"(",
"self",
",",
"xblock",
")",
":",
"if",
"hasattr",
"(",
"xblock",
",",
"'_field_data_cache'",
")",
"and",
"self",
".",
"name",
"in",
"xblock",
".",
"_field_data_cache",
":",
"del",
"xblock",
".",
"_field_data_cache",
"[",
"sel... | Remove a value from the xblock's cache, if the cache exists. | [
"Remove",
"a",
"value",
"from",
"the",
"xblock",
"s",
"cache",
"if",
"the",
"cache",
"exists",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L411-L415 | train |
edx/XBlock | xblock/fields.py | Field._mark_dirty | def _mark_dirty(self, xblock, value):
"""Set this field to dirty on the xblock."""
# pylint: disable=protected-access
# Deep copy the value being marked as dirty, so that there
# is a baseline to check against when saving later
if self not in xblock._dirty_fields:
xb... | python | def _mark_dirty(self, xblock, value):
"""Set this field to dirty on the xblock."""
# pylint: disable=protected-access
# Deep copy the value being marked as dirty, so that there
# is a baseline to check against when saving later
if self not in xblock._dirty_fields:
xb... | [
"def",
"_mark_dirty",
"(",
"self",
",",
"xblock",
",",
"value",
")",
":",
"if",
"self",
"not",
"in",
"xblock",
".",
"_dirty_fields",
":",
"xblock",
".",
"_dirty_fields",
"[",
"self",
"]",
"=",
"copy",
".",
"deepcopy",
"(",
"value",
")"
] | Set this field to dirty on the xblock. | [
"Set",
"this",
"field",
"to",
"dirty",
"on",
"the",
"xblock",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L417-L424 | train |
edx/XBlock | xblock/fields.py | Field._check_or_enforce_type | def _check_or_enforce_type(self, value):
"""
Depending on whether enforce_type is enabled call self.enforce_type and
return the result or call it and trigger a silent warning if the result
is different or a Traceback
To aid with migration, enable the warnings with:
w... | python | def _check_or_enforce_type(self, value):
"""
Depending on whether enforce_type is enabled call self.enforce_type and
return the result or call it and trigger a silent warning if the result
is different or a Traceback
To aid with migration, enable the warnings with:
w... | [
"def",
"_check_or_enforce_type",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"_enable_enforce_type",
":",
"return",
"self",
".",
"enforce_type",
"(",
"value",
")",
"try",
":",
"new_value",
"=",
"self",
".",
"enforce_type",
"(",
"value",
")",
"e... | Depending on whether enforce_type is enabled call self.enforce_type and
return the result or call it and trigger a silent warning if the result
is different or a Traceback
To aid with migration, enable the warnings with:
warnings.simplefilter("always", FailingEnforceTypeWarning)
... | [
"Depending",
"on",
"whether",
"enforce_type",
"is",
"enabled",
"call",
"self",
".",
"enforce_type",
"and",
"return",
"the",
"result",
"or",
"call",
"it",
"and",
"trigger",
"a",
"silent",
"warning",
"if",
"the",
"result",
"is",
"different",
"or",
"a",
"Traceb... | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L443-L472 | train |
edx/XBlock | xblock/fields.py | Field._calculate_unique_id | def _calculate_unique_id(self, xblock):
"""
Provide a default value for fields with `default=UNIQUE_ID`.
Returned string is a SHA1 hex digest that is deterministically calculated
for the field in its given scope.
"""
key = scope_key(self, xblock)
return hashlib.s... | python | def _calculate_unique_id(self, xblock):
"""
Provide a default value for fields with `default=UNIQUE_ID`.
Returned string is a SHA1 hex digest that is deterministically calculated
for the field in its given scope.
"""
key = scope_key(self, xblock)
return hashlib.s... | [
"def",
"_calculate_unique_id",
"(",
"self",
",",
"xblock",
")",
":",
"key",
"=",
"scope_key",
"(",
"self",
",",
"xblock",
")",
"return",
"hashlib",
".",
"sha1",
"(",
"key",
".",
"encode",
"(",
"'utf-8'",
")",
")",
".",
"hexdigest",
"(",
")"
] | Provide a default value for fields with `default=UNIQUE_ID`.
Returned string is a SHA1 hex digest that is deterministically calculated
for the field in its given scope. | [
"Provide",
"a",
"default",
"value",
"for",
"fields",
"with",
"default",
"=",
"UNIQUE_ID",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L474-L482 | train |
edx/XBlock | xblock/fields.py | Field._get_default_value_to_cache | def _get_default_value_to_cache(self, xblock):
"""
Perform special logic to provide a field's default value for caching.
"""
try:
# pylint: disable=protected-access
return self.from_json(xblock._field_data.default(xblock, self.name))
except KeyError:
... | python | def _get_default_value_to_cache(self, xblock):
"""
Perform special logic to provide a field's default value for caching.
"""
try:
# pylint: disable=protected-access
return self.from_json(xblock._field_data.default(xblock, self.name))
except KeyError:
... | [
"def",
"_get_default_value_to_cache",
"(",
"self",
",",
"xblock",
")",
":",
"try",
":",
"return",
"self",
".",
"from_json",
"(",
"xblock",
".",
"_field_data",
".",
"default",
"(",
"xblock",
",",
"self",
".",
"name",
")",
")",
"except",
"KeyError",
":",
"... | Perform special logic to provide a field's default value for caching. | [
"Perform",
"special",
"logic",
"to",
"provide",
"a",
"field",
"s",
"default",
"value",
"for",
"caching",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L484-L495 | train |
edx/XBlock | xblock/fields.py | Field._warn_deprecated_outside_JSONField | def _warn_deprecated_outside_JSONField(self): # pylint: disable=invalid-name
"""Certain methods will be moved to JSONField.
This warning marks calls when the object is not
derived from that class.
"""
if not isinstance(self, JSONField) and not self.warned:
warnings.... | python | def _warn_deprecated_outside_JSONField(self): # pylint: disable=invalid-name
"""Certain methods will be moved to JSONField.
This warning marks calls when the object is not
derived from that class.
"""
if not isinstance(self, JSONField) and not self.warned:
warnings.... | [
"def",
"_warn_deprecated_outside_JSONField",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
",",
"JSONField",
")",
"and",
"not",
"self",
".",
"warned",
":",
"warnings",
".",
"warn",
"(",
"\"Deprecated. JSONifiable fields should derive from JSONField ({... | Certain methods will be moved to JSONField.
This warning marks calls when the object is not
derived from that class. | [
"Certain",
"methods",
"will",
"be",
"moved",
"to",
"JSONField",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L589-L601 | train |
edx/XBlock | xblock/fields.py | Field.to_string | def to_string(self, value):
"""
Return a JSON serialized string representation of the value.
"""
self._warn_deprecated_outside_JSONField()
value = json.dumps(
self.to_json(value),
indent=2,
sort_keys=True,
separators=(',', ': '),
... | python | def to_string(self, value):
"""
Return a JSON serialized string representation of the value.
"""
self._warn_deprecated_outside_JSONField()
value = json.dumps(
self.to_json(value),
indent=2,
sort_keys=True,
separators=(',', ': '),
... | [
"def",
"to_string",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_warn_deprecated_outside_JSONField",
"(",
")",
"value",
"=",
"json",
".",
"dumps",
"(",
"self",
".",
"to_json",
"(",
"value",
")",
",",
"indent",
"=",
"2",
",",
"sort_keys",
"=",
"T... | Return a JSON serialized string representation of the value. | [
"Return",
"a",
"JSON",
"serialized",
"string",
"representation",
"of",
"the",
"value",
"."
] | 368bf46e2c0ee69bbb21817f428c4684936e18ee | https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/fields.py#L624-L635 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.