repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
hydraplatform/hydra-base | hydra_base/db/model.py | ResourceAttr.get_network | def get_network(self):
"""
Get the network that this resource attribute is in.
"""
ref_key = self.ref_key
if ref_key == 'NETWORK':
return self.network
elif ref_key == 'NODE':
return self.node.network
elif ref_key == 'LINK':
ret... | python | def get_network(self):
"""
Get the network that this resource attribute is in.
"""
ref_key = self.ref_key
if ref_key == 'NETWORK':
return self.network
elif ref_key == 'NODE':
return self.node.network
elif ref_key == 'LINK':
ret... | [
"def",
"get_network",
"(",
"self",
")",
":",
"ref_key",
"=",
"self",
".",
"ref_key",
"if",
"ref_key",
"==",
"'NETWORK'",
":",
"return",
"self",
".",
"network",
"elif",
"ref_key",
"==",
"'NODE'",
":",
"return",
"self",
".",
"node",
".",
"network",
"elif",... | Get the network that this resource attribute is in. | [
"Get",
"the",
"network",
"that",
"this",
"resource",
"attribute",
"is",
"in",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L560-L574 |
hydraplatform/hydra-base | hydra_base/db/model.py | ResourceAttr.check_read_permission | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this resource attribute
"""
return self.get_resource().check_read_permission(user_id, do_raise=do_raise) | python | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this resource attribute
"""
return self.get_resource().check_read_permission(user_id, do_raise=do_raise) | [
"def",
"check_read_permission",
"(",
"self",
",",
"user_id",
",",
"do_raise",
"=",
"True",
")",
":",
"return",
"self",
".",
"get_resource",
"(",
")",
".",
"check_read_permission",
"(",
"user_id",
",",
"do_raise",
"=",
"do_raise",
")"
] | Check whether this user can read this resource attribute | [
"Check",
"whether",
"this",
"user",
"can",
"read",
"this",
"resource",
"attribute"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L602-L606 |
hydraplatform/hydra-base | hydra_base/db/model.py | ResourceAttr.check_write_permission | def check_write_permission(self, user_id, do_raise=True):
"""
Check whether this user can write this node
"""
return self.get_resource().check_write_permission(user_id, do_raise=do_raise) | python | def check_write_permission(self, user_id, do_raise=True):
"""
Check whether this user can write this node
"""
return self.get_resource().check_write_permission(user_id, do_raise=do_raise) | [
"def",
"check_write_permission",
"(",
"self",
",",
"user_id",
",",
"do_raise",
"=",
"True",
")",
":",
"return",
"self",
".",
"get_resource",
"(",
")",
".",
"check_write_permission",
"(",
"user_id",
",",
"do_raise",
"=",
"do_raise",
")"
] | Check whether this user can write this node | [
"Check",
"whether",
"this",
"user",
"can",
"write",
"this",
"node"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L608-L612 |
hydraplatform/hydra-base | hydra_base/db/model.py | Network.add_link | def add_link(self, name, desc, layout, node_1, node_2):
"""
Add a link to a network. Links are what effectively
define the network topology, by associating two already
existing nodes.
"""
existing_link = get_session().query(Link).filter(Link.name==name, Link.... | python | def add_link(self, name, desc, layout, node_1, node_2):
"""
Add a link to a network. Links are what effectively
define the network topology, by associating two already
existing nodes.
"""
existing_link = get_session().query(Link).filter(Link.name==name, Link.... | [
"def",
"add_link",
"(",
"self",
",",
"name",
",",
"desc",
",",
"layout",
",",
"node_1",
",",
"node_2",
")",
":",
"existing_link",
"=",
"get_session",
"(",
")",
".",
"query",
"(",
"Link",
")",
".",
"filter",
"(",
"Link",
".",
"name",
"==",
"name",
"... | Add a link to a network. Links are what effectively
define the network topology, by associating two already
existing nodes. | [
"Add",
"a",
"link",
"to",
"a",
"network",
".",
"Links",
"are",
"what",
"effectively",
"define",
"the",
"network",
"topology",
"by",
"associating",
"two",
"already",
"existing",
"nodes",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L860-L882 |
hydraplatform/hydra-base | hydra_base/db/model.py | Network.add_node | def add_node(self, name, desc, layout, node_x, node_y):
"""
Add a node to a network.
"""
existing_node = get_session().query(Node).filter(Node.name==name, Node.network_id==self.id).first()
if existing_node is not None:
raise HydraError("A node with name %s is alre... | python | def add_node(self, name, desc, layout, node_x, node_y):
"""
Add a node to a network.
"""
existing_node = get_session().query(Node).filter(Node.name==name, Node.network_id==self.id).first()
if existing_node is not None:
raise HydraError("A node with name %s is alre... | [
"def",
"add_node",
"(",
"self",
",",
"name",
",",
"desc",
",",
"layout",
",",
"node_x",
",",
"node_y",
")",
":",
"existing_node",
"=",
"get_session",
"(",
")",
".",
"query",
"(",
"Node",
")",
".",
"filter",
"(",
"Node",
".",
"name",
"==",
"name",
"... | Add a node to a network. | [
"Add",
"a",
"node",
"to",
"a",
"network",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L885-L907 |
hydraplatform/hydra-base | hydra_base/db/model.py | Network.add_group | def add_group(self, name, desc, status):
"""
Add a new group to a network.
"""
existing_group = get_session().query(ResourceGroup).filter(ResourceGroup.name==name, ResourceGroup.network_id==self.id).first()
if existing_group is not None:
raise HydraError("A resou... | python | def add_group(self, name, desc, status):
"""
Add a new group to a network.
"""
existing_group = get_session().query(ResourceGroup).filter(ResourceGroup.name==name, ResourceGroup.network_id==self.id).first()
if existing_group is not None:
raise HydraError("A resou... | [
"def",
"add_group",
"(",
"self",
",",
"name",
",",
"desc",
",",
"status",
")",
":",
"existing_group",
"=",
"get_session",
"(",
")",
".",
"query",
"(",
"ResourceGroup",
")",
".",
"filter",
"(",
"ResourceGroup",
".",
"name",
"==",
"name",
",",
"ResourceGro... | Add a new group to a network. | [
"Add",
"a",
"new",
"group",
"to",
"a",
"network",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L909-L928 |
hydraplatform/hydra-base | hydra_base/db/model.py | Network.check_read_permission | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this network
"""
if _is_admin(user_id):
return True
if int(self.created_by) == int(user_id):
return True
for owner in self.owners:
if in... | python | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this network
"""
if _is_admin(user_id):
return True
if int(self.created_by) == int(user_id):
return True
for owner in self.owners:
if in... | [
"def",
"check_read_permission",
"(",
"self",
",",
"user_id",
",",
"do_raise",
"=",
"True",
")",
":",
"if",
"_is_admin",
"(",
"user_id",
")",
":",
"return",
"True",
"if",
"int",
"(",
"self",
".",
"created_by",
")",
"==",
"int",
"(",
"user_id",
")",
":",... | Check whether this user can read this network | [
"Check",
"whether",
"this",
"user",
"can",
"read",
"this",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L960-L982 |
hydraplatform/hydra-base | hydra_base/db/model.py | Network.check_share_permission | def check_share_permission(self, user_id):
"""
Check whether this user can write this project
"""
if _is_admin(user_id):
return
if int(self.created_by) == int(user_id):
return
for owner in self.owners:
if owner.user_id == int(use... | python | def check_share_permission(self, user_id):
"""
Check whether this user can write this project
"""
if _is_admin(user_id):
return
if int(self.created_by) == int(user_id):
return
for owner in self.owners:
if owner.user_id == int(use... | [
"def",
"check_share_permission",
"(",
"self",
",",
"user_id",
")",
":",
"if",
"_is_admin",
"(",
"user_id",
")",
":",
"return",
"if",
"int",
"(",
"self",
".",
"created_by",
")",
"==",
"int",
"(",
"user_id",
")",
":",
"return",
"for",
"owner",
"in",
"sel... | Check whether this user can write this project | [
"Check",
"whether",
"this",
"user",
"can",
"write",
"this",
"project"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1008-L1026 |
hydraplatform/hydra-base | hydra_base/db/model.py | Link.check_read_permission | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this link
"""
return self.network.check_read_permission(user_id, do_raise=do_raise) | python | def check_read_permission(self, user_id, do_raise=True):
"""
Check whether this user can read this link
"""
return self.network.check_read_permission(user_id, do_raise=do_raise) | [
"def",
"check_read_permission",
"(",
"self",
",",
"user_id",
",",
"do_raise",
"=",
"True",
")",
":",
"return",
"self",
".",
"network",
".",
"check_read_permission",
"(",
"user_id",
",",
"do_raise",
"=",
"do_raise",
")"
] | Check whether this user can read this link | [
"Check",
"whether",
"this",
"user",
"can",
"read",
"this",
"link"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1090-L1094 |
hydraplatform/hydra-base | hydra_base/db/model.py | Link.check_write_permission | def check_write_permission(self, user_id, do_raise=True):
"""
Check whether this user can write this link
"""
return self.network.check_write_permission(user_id, do_raise=do_raise) | python | def check_write_permission(self, user_id, do_raise=True):
"""
Check whether this user can write this link
"""
return self.network.check_write_permission(user_id, do_raise=do_raise) | [
"def",
"check_write_permission",
"(",
"self",
",",
"user_id",
",",
"do_raise",
"=",
"True",
")",
":",
"return",
"self",
".",
"network",
".",
"check_write_permission",
"(",
"user_id",
",",
"do_raise",
"=",
"do_raise",
")"
] | Check whether this user can write this link | [
"Check",
"whether",
"this",
"user",
"can",
"write",
"this",
"link"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1096-L1101 |
hydraplatform/hydra-base | hydra_base/db/model.py | ResourceGroup.get_items | def get_items(self, scenario_id):
"""
Get all the items in this group, in the given scenario
"""
items = get_session().query(ResourceGroupItem)\
.filter(ResourceGroupItem.group_id==self.id).\
filter(ResourceGroupItem.scenario_id==scenario_id).all()
... | python | def get_items(self, scenario_id):
"""
Get all the items in this group, in the given scenario
"""
items = get_session().query(ResourceGroupItem)\
.filter(ResourceGroupItem.group_id==self.id).\
filter(ResourceGroupItem.scenario_id==scenario_id).all()
... | [
"def",
"get_items",
"(",
"self",
",",
"scenario_id",
")",
":",
"items",
"=",
"get_session",
"(",
")",
".",
"query",
"(",
"ResourceGroupItem",
")",
".",
"filter",
"(",
"ResourceGroupItem",
".",
"group_id",
"==",
"self",
".",
"id",
")",
".",
"filter",
"(",... | Get all the items in this group, in the given scenario | [
"Get",
"all",
"the",
"items",
"in",
"this",
"group",
"in",
"the",
"given",
"scenario"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1231-L1239 |
hydraplatform/hydra-base | hydra_base/db/model.py | Note.set_ref | def set_ref(self, ref_key, ref_id):
"""
Using a ref key and ref id set the
reference to the appropriate resource type.
"""
if ref_key == 'NETWORK':
self.network_id = ref_id
elif ref_key == 'NODE':
self.node_id = ref_id
elif ref_key ... | python | def set_ref(self, ref_key, ref_id):
"""
Using a ref key and ref id set the
reference to the appropriate resource type.
"""
if ref_key == 'NETWORK':
self.network_id = ref_id
elif ref_key == 'NODE':
self.node_id = ref_id
elif ref_key ... | [
"def",
"set_ref",
"(",
"self",
",",
"ref_key",
",",
"ref_id",
")",
":",
"if",
"ref_key",
"==",
"'NETWORK'",
":",
"self",
".",
"network_id",
"=",
"ref_id",
"elif",
"ref_key",
"==",
"'NODE'",
":",
"self",
".",
"node_id",
"=",
"ref_id",
"elif",
"ref_key",
... | Using a ref key and ref id set the
reference to the appropriate resource type. | [
"Using",
"a",
"ref",
"key",
"and",
"ref",
"id",
"set",
"the",
"reference",
"to",
"the",
"appropriate",
"resource",
"type",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1465-L1484 |
hydraplatform/hydra-base | hydra_base/db/model.py | Note.get_ref_id | def get_ref_id(self):
"""
Return the ID of the resource to which this not is attached
"""
if self.ref_key == 'NETWORK':
return self.network_id
elif self.ref_key == 'NODE':
return self.node_id
elif self.ref_key == 'LINK':
return sel... | python | def get_ref_id(self):
"""
Return the ID of the resource to which this not is attached
"""
if self.ref_key == 'NETWORK':
return self.network_id
elif self.ref_key == 'NODE':
return self.node_id
elif self.ref_key == 'LINK':
return sel... | [
"def",
"get_ref_id",
"(",
"self",
")",
":",
"if",
"self",
".",
"ref_key",
"==",
"'NETWORK'",
":",
"return",
"self",
".",
"network_id",
"elif",
"self",
".",
"ref_key",
"==",
"'NODE'",
":",
"return",
"self",
".",
"node_id",
"elif",
"self",
".",
"ref_key",
... | Return the ID of the resource to which this not is attached | [
"Return",
"the",
"ID",
"of",
"the",
"resource",
"to",
"which",
"this",
"not",
"is",
"attached"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1486-L1502 |
hydraplatform/hydra-base | hydra_base/db/model.py | Note.get_ref | def get_ref(self):
"""
Return the ID of the resource to which this not is attached
"""
if self.ref_key == 'NETWORK':
return self.network
elif self.ref_key == 'NODE':
return self.node
elif self.ref_key == 'LINK':
return self.link
... | python | def get_ref(self):
"""
Return the ID of the resource to which this not is attached
"""
if self.ref_key == 'NETWORK':
return self.network
elif self.ref_key == 'NODE':
return self.node
elif self.ref_key == 'LINK':
return self.link
... | [
"def",
"get_ref",
"(",
"self",
")",
":",
"if",
"self",
".",
"ref_key",
"==",
"'NETWORK'",
":",
"return",
"self",
".",
"network",
"elif",
"self",
".",
"ref_key",
"==",
"'NODE'",
":",
"return",
"self",
".",
"node",
"elif",
"self",
".",
"ref_key",
"==",
... | Return the ID of the resource to which this not is attached | [
"Return",
"the",
"ID",
"of",
"the",
"resource",
"to",
"which",
"this",
"not",
"is",
"attached"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1504-L1519 |
hydraplatform/hydra-base | hydra_base/db/model.py | User.permissions | def permissions(self):
"""Return a set with all permissions granted to the user."""
perms = set()
for r in self.roles:
perms = perms | set(r.permissions)
return perms | python | def permissions(self):
"""Return a set with all permissions granted to the user."""
perms = set()
for r in self.roles:
perms = perms | set(r.permissions)
return perms | [
"def",
"permissions",
"(",
"self",
")",
":",
"perms",
"=",
"set",
"(",
")",
"for",
"r",
"in",
"self",
".",
"roles",
":",
"perms",
"=",
"perms",
"|",
"set",
"(",
"r",
".",
"permissions",
")",
"return",
"perms"
] | Return a set with all permissions granted to the user. | [
"Return",
"a",
"set",
"with",
"all",
"permissions",
"granted",
"to",
"the",
"user",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1687-L1692 |
hydraplatform/hydra-base | hydra_base/db/model.py | User.roles | def roles(self):
"""Return a set with all roles granted to the user."""
roles = []
for ur in self.roleusers:
roles.append(ur.role)
return set(roles) | python | def roles(self):
"""Return a set with all roles granted to the user."""
roles = []
for ur in self.roleusers:
roles.append(ur.role)
return set(roles) | [
"def",
"roles",
"(",
"self",
")",
":",
"roles",
"=",
"[",
"]",
"for",
"ur",
"in",
"self",
".",
"roleusers",
":",
"roles",
".",
"append",
"(",
"ur",
".",
"role",
")",
"return",
"set",
"(",
"roles",
")"
] | Return a set with all roles granted to the user. | [
"Return",
"a",
"set",
"with",
"all",
"roles",
"granted",
"to",
"the",
"user",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1695-L1700 |
hydraplatform/hydra-base | hydra_base/db/model.py | User.is_admin | def is_admin(self):
"""
Check that the user has a role with the code 'admin'
"""
for ur in self.roleusers:
if ur.role.code == 'admin':
return True
return False | python | def is_admin(self):
"""
Check that the user has a role with the code 'admin'
"""
for ur in self.roleusers:
if ur.role.code == 'admin':
return True
return False | [
"def",
"is_admin",
"(",
"self",
")",
":",
"for",
"ur",
"in",
"self",
".",
"roleusers",
":",
"if",
"ur",
".",
"role",
".",
"code",
"==",
"'admin'",
":",
"return",
"True",
"return",
"False"
] | Check that the user has a role with the code 'admin' | [
"Check",
"that",
"the",
"user",
"has",
"a",
"role",
"with",
"the",
"code",
"admin"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/model.py#L1702-L1710 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _check_dimension | def _check_dimension(typeattr, unit_id=None):
"""
Check that the unit and dimension on a type attribute match.
Alternatively, pass in a unit manually to check against the dimension
of the type attribute
"""
if unit_id is None:
unit_id = typeattr.unit_id
dimension_id = _g... | python | def _check_dimension(typeattr, unit_id=None):
"""
Check that the unit and dimension on a type attribute match.
Alternatively, pass in a unit manually to check against the dimension
of the type attribute
"""
if unit_id is None:
unit_id = typeattr.unit_id
dimension_id = _g... | [
"def",
"_check_dimension",
"(",
"typeattr",
",",
"unit_id",
"=",
"None",
")",
":",
"if",
"unit_id",
"is",
"None",
":",
"unit_id",
"=",
"typeattr",
".",
"unit_id",
"dimension_id",
"=",
"_get_attr",
"(",
"typeattr",
".",
"attr_id",
")",
".",
"dimension_id",
... | Check that the unit and dimension on a type attribute match.
Alternatively, pass in a unit manually to check against the dimension
of the type attribute | [
"Check",
"that",
"the",
"unit",
"and",
"dimension",
"on",
"a",
"type",
"attribute",
"match",
".",
"Alternatively",
"pass",
"in",
"a",
"unit",
"manually",
"to",
"check",
"against",
"the",
"dimension",
"of",
"the",
"type",
"attribute"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L44-L68 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_types_by_attr | def get_types_by_attr(resource, template_id=None):
"""
Using the attributes of the resource, get all the
types that this resource matches.
@returns a dictionary, keyed on the template name, with the
value being the list of type names which match the resources
attributes.
... | python | def get_types_by_attr(resource, template_id=None):
"""
Using the attributes of the resource, get all the
types that this resource matches.
@returns a dictionary, keyed on the template name, with the
value being the list of type names which match the resources
attributes.
... | [
"def",
"get_types_by_attr",
"(",
"resource",
",",
"template_id",
"=",
"None",
")",
":",
"resource_type_templates",
"=",
"[",
"]",
"#Create a list of all of this resources attributes.",
"attr_ids",
"=",
"[",
"]",
"for",
"res_attr",
"in",
"resource",
".",
"attributes",
... | Using the attributes of the resource, get all the
types that this resource matches.
@returns a dictionary, keyed on the template name, with the
value being the list of type names which match the resources
attributes. | [
"Using",
"the",
"attributes",
"of",
"the",
"resource",
"get",
"all",
"the",
"types",
"that",
"this",
"resource",
"matches",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L71-L102 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _get_attr_by_name_and_dimension | def _get_attr_by_name_and_dimension(name, dimension_id):
"""
Search for an attribute with the given name and dimension_id.
If such an attribute does not exist, create one.
"""
attr = db.DBSession.query(Attr).filter(Attr.name==name, Attr.dimension_id==dimension_id).first()
if attr is No... | python | def _get_attr_by_name_and_dimension(name, dimension_id):
"""
Search for an attribute with the given name and dimension_id.
If such an attribute does not exist, create one.
"""
attr = db.DBSession.query(Attr).filter(Attr.name==name, Attr.dimension_id==dimension_id).first()
if attr is No... | [
"def",
"_get_attr_by_name_and_dimension",
"(",
"name",
",",
"dimension_id",
")",
":",
"attr",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Attr",
")",
".",
"filter",
"(",
"Attr",
".",
"name",
"==",
"name",
",",
"Attr",
".",
"dimension_id",
"==",
"dim... | Search for an attribute with the given name and dimension_id.
If such an attribute does not exist, create one. | [
"Search",
"for",
"an",
"attribute",
"with",
"the",
"given",
"name",
"and",
"dimension_id",
".",
"If",
"such",
"an",
"attribute",
"does",
"not",
"exist",
"create",
"one",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L104-L123 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_template_as_json | def get_template_as_json(template_id, **kwargs):
"""
Get a template (including attribute and dataset definitions) as a JSON
string. This is just a wrapper around the get_template_as_dict function.
"""
user_id = kwargs['user_id']
return json.dumps(get_template_as_dict(template_id, user_id... | python | def get_template_as_json(template_id, **kwargs):
"""
Get a template (including attribute and dataset definitions) as a JSON
string. This is just a wrapper around the get_template_as_dict function.
"""
user_id = kwargs['user_id']
return json.dumps(get_template_as_dict(template_id, user_id... | [
"def",
"get_template_as_json",
"(",
"template_id",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
"[",
"'user_id'",
"]",
"return",
"json",
".",
"dumps",
"(",
"get_template_as_dict",
"(",
"template_id",
",",
"user_id",
"=",
"user_id",
")",
")"
] | Get a template (including attribute and dataset definitions) as a JSON
string. This is just a wrapper around the get_template_as_dict function. | [
"Get",
"a",
"template",
"(",
"including",
"attribute",
"and",
"dataset",
"definitions",
")",
"as",
"a",
"JSON",
"string",
".",
"This",
"is",
"just",
"a",
"wrapper",
"around",
"the",
"get_template_as_dict",
"function",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L349-L355 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_template_as_xml | def get_template_as_xml(template_id,**kwargs):
"""
Turn a template into an xml template
"""
template_xml = etree.Element("template_definition")
template_i = db.DBSession.query(Template).filter(
Template.id==template_id).options(
#joinedload_all('templatetypes.typeatt... | python | def get_template_as_xml(template_id,**kwargs):
"""
Turn a template into an xml template
"""
template_xml = etree.Element("template_definition")
template_i = db.DBSession.query(Template).filter(
Template.id==template_id).options(
#joinedload_all('templatetypes.typeatt... | [
"def",
"get_template_as_xml",
"(",
"template_id",
",",
"*",
"*",
"kwargs",
")",
":",
"template_xml",
"=",
"etree",
".",
"Element",
"(",
"\"template_definition\"",
")",
"template_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"filte... | Turn a template into an xml template | [
"Turn",
"a",
"template",
"into",
"an",
"xml",
"template"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L412-L457 |
hydraplatform/hydra-base | hydra_base/lib/template.py | import_template_json | def import_template_json(template_json_string,allow_update=True, **kwargs):
"""
Add the template, type and typeattrs described
in a JSON file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer require... | python | def import_template_json(template_json_string,allow_update=True, **kwargs):
"""
Add the template, type and typeattrs described
in a JSON file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer require... | [
"def",
"import_template_json",
"(",
"template_json_string",
",",
"allow_update",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
"try",
":",
"template_dict",
"=",
"json",
".",
"loads",
"(",
"temp... | Add the template, type and typeattrs described
in a JSON file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer required.
The allow_update indicates whether an existing template of the same name should
... | [
"Add",
"the",
"template",
"type",
"and",
"typeattrs",
"described",
"in",
"a",
"JSON",
"file",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L459-L478 |
hydraplatform/hydra-base | hydra_base/lib/template.py | import_template_xml | def import_template_xml(template_xml, allow_update=True, **kwargs):
"""
Add the template, type and typeattrs described
in an XML file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer required.
"... | python | def import_template_xml(template_xml, allow_update=True, **kwargs):
"""
Add the template, type and typeattrs described
in an XML file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer required.
"... | [
"def",
"import_template_xml",
"(",
"template_xml",
",",
"allow_update",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"template_xsd_path",
"=",
"config",
".",
"get",
"(",
"'templates'",
",",
"'template_xsd_path'",
")",
"xmlschema_doc",
"=",
"etree",
".",
"pa... | Add the template, type and typeattrs described
in an XML file.
Delete type, typeattr entries in the DB that are not in the XML file
The assumption is that they have been deleted and are no longer required. | [
"Add",
"the",
"template",
"type",
"and",
"typeattrs",
"described",
"in",
"an",
"XML",
"file",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L647-L772 |
hydraplatform/hydra-base | hydra_base/lib/template.py | apply_template_to_network | def apply_template_to_network(template_id, network_id, **kwargs):
"""
For each node and link in a network, check whether it matches
a type in a given template. If so, assign the type to the node / link.
"""
net_i = db.DBSession.query(Network).filter(Network.id==network_id).one()
#There ... | python | def apply_template_to_network(template_id, network_id, **kwargs):
"""
For each node and link in a network, check whether it matches
a type in a given template. If so, assign the type to the node / link.
"""
net_i = db.DBSession.query(Network).filter(Network.id==network_id).one()
#There ... | [
"def",
"apply_template_to_network",
"(",
"template_id",
",",
"network_id",
",",
"*",
"*",
"kwargs",
")",
":",
"net_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")",
".",
"filter",
"(",
"Network",
".",
"id",
"==",
"network_id",
")",
".",... | For each node and link in a network, check whether it matches
a type in a given template. If so, assign the type to the node / link. | [
"For",
"each",
"node",
"and",
"link",
"in",
"a",
"network",
"check",
"whether",
"it",
"matches",
"a",
"type",
"in",
"a",
"given",
"template",
".",
"If",
"so",
"assign",
"the",
"type",
"to",
"the",
"node",
"/",
"link",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L774-L805 |
hydraplatform/hydra-base | hydra_base/lib/template.py | set_network_template | def set_network_template(template_id, network_id, **kwargs):
"""
Apply an existing template to a network. Used when a template has changed, and additional attributes
must be added to the network's elements.
"""
resource_types = []
#There should only ever be one matching type, but if ther... | python | def set_network_template(template_id, network_id, **kwargs):
"""
Apply an existing template to a network. Used when a template has changed, and additional attributes
must be added to the network's elements.
"""
resource_types = []
#There should only ever be one matching type, but if ther... | [
"def",
"set_network_template",
"(",
"template_id",
",",
"network_id",
",",
"*",
"*",
"kwargs",
")",
":",
"resource_types",
"=",
"[",
"]",
"#There should only ever be one matching type, but if there are more,",
"#all we can do is pick the first one.",
"try",
":",
"network_type... | Apply an existing template to a network. Used when a template has changed, and additional attributes
must be added to the network's elements. | [
"Apply",
"an",
"existing",
"template",
"to",
"a",
"network",
".",
"Used",
"when",
"a",
"template",
"has",
"changed",
"and",
"additional",
"attributes",
"must",
"be",
"added",
"to",
"the",
"network",
"s",
"elements",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L807-L850 |
hydraplatform/hydra-base | hydra_base/lib/template.py | remove_template_from_network | def remove_template_from_network(network_id, template_id, remove_attrs, **kwargs):
"""
Remove all resource types in a network relating to the specified
template.
remove_attrs
Flag to indicate whether the attributes associated with the template
types should be removed ... | python | def remove_template_from_network(network_id, template_id, remove_attrs, **kwargs):
"""
Remove all resource types in a network relating to the specified
template.
remove_attrs
Flag to indicate whether the attributes associated with the template
types should be removed ... | [
"def",
"remove_template_from_network",
"(",
"network_id",
",",
"template_id",
",",
"remove_attrs",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"network",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")",
".",
"filter",
"(",
"Network",
".",... | Remove all resource types in a network relating to the specified
template.
remove_attrs
Flag to indicate whether the attributes associated with the template
types should be removed from the resources in the network. These will
only be removed if they are not shared wi... | [
"Remove",
"all",
"resource",
"types",
"in",
"a",
"network",
"relating",
"to",
"the",
"specified",
"template",
".",
"remove_attrs",
"Flag",
"to",
"indicate",
"whether",
"the",
"attributes",
"associated",
"with",
"the",
"template",
"types",
"should",
"be",
"remove... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L852-L902 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _get_resources_to_remove | def _get_resources_to_remove(resource, template):
"""
Given a resource and a template being removed, identify the resource attribtes
which can be removed.
"""
type_ids = [tmpltype.id for tmpltype in template.templatetypes]
node_attr_ids = dict([(ra.attr_id, ra) for ra in resource.attrib... | python | def _get_resources_to_remove(resource, template):
"""
Given a resource and a template being removed, identify the resource attribtes
which can be removed.
"""
type_ids = [tmpltype.id for tmpltype in template.templatetypes]
node_attr_ids = dict([(ra.attr_id, ra) for ra in resource.attrib... | [
"def",
"_get_resources_to_remove",
"(",
"resource",
",",
"template",
")",
":",
"type_ids",
"=",
"[",
"tmpltype",
".",
"id",
"for",
"tmpltype",
"in",
"template",
".",
"templatetypes",
"]",
"node_attr_ids",
"=",
"dict",
"(",
"[",
"(",
"ra",
".",
"attr_id",
"... | Given a resource and a template being removed, identify the resource attribtes
which can be removed. | [
"Given",
"a",
"resource",
"and",
"a",
"template",
"being",
"removed",
"identify",
"the",
"resource",
"attribtes",
"which",
"can",
"be",
"removed",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L904-L927 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_matching_resource_types | def get_matching_resource_types(resource_type, resource_id,**kwargs):
"""
Get the possible types of a resource by checking its attributes
against all available types.
@returns A list of TypeSummary objects.
"""
resource_i = None
if resource_type == 'NETWORK':
resource_i ... | python | def get_matching_resource_types(resource_type, resource_id,**kwargs):
"""
Get the possible types of a resource by checking its attributes
against all available types.
@returns A list of TypeSummary objects.
"""
resource_i = None
if resource_type == 'NETWORK':
resource_i ... | [
"def",
"get_matching_resource_types",
"(",
"resource_type",
",",
"resource_id",
",",
"*",
"*",
"kwargs",
")",
":",
"resource_i",
"=",
"None",
"if",
"resource_type",
"==",
"'NETWORK'",
":",
"resource_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network"... | Get the possible types of a resource by checking its attributes
against all available types.
@returns A list of TypeSummary objects. | [
"Get",
"the",
"possible",
"types",
"of",
"a",
"resource",
"by",
"checking",
"its",
"attributes",
"against",
"all",
"available",
"types",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L929-L947 |
hydraplatform/hydra-base | hydra_base/lib/template.py | assign_types_to_resources | def assign_types_to_resources(resource_types,**kwargs):
"""
Assign new types to list of resources.
This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
... | python | def assign_types_to_resources(resource_types,**kwargs):
"""
Assign new types to list of resources.
This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
... | [
"def",
"assign_types_to_resources",
"(",
"resource_types",
",",
"*",
"*",
"kwargs",
")",
":",
"#Remove duplicate values from types by turning it into a set",
"type_ids",
"=",
"list",
"(",
"set",
"(",
"[",
"rt",
".",
"type_id",
"for",
"rt",
"in",
"resource_types",
"]... | Assign new types to list of resources.
This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
function can also be used to update resources, when a resource type ... | [
"Assign",
"new",
"types",
"to",
"list",
"of",
"resources",
".",
"This",
"function",
"checks",
"if",
"the",
"necessary",
"attributes",
"are",
"present",
"and",
"adds",
"them",
"if",
"needed",
".",
"Non",
"existing",
"attributes",
"are",
"also",
"added",
"when... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L949-L1034 |
hydraplatform/hydra-base | hydra_base/lib/template.py | check_type_compatibility | def check_type_compatibility(type_1_id, type_2_id):
"""
When applying a type to a resource, it may be the case that the resource already
has an attribute specified in the new type, but the template which defines this
pre-existing attribute has a different unit specification to the new templa... | python | def check_type_compatibility(type_1_id, type_2_id):
"""
When applying a type to a resource, it may be the case that the resource already
has an attribute specified in the new type, but the template which defines this
pre-existing attribute has a different unit specification to the new templa... | [
"def",
"check_type_compatibility",
"(",
"type_1_id",
",",
"type_2_id",
")",
":",
"errors",
"=",
"[",
"]",
"type_1",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"TemplateType",
")",
".",
"filter",
"(",
"TemplateType",
".",
"id",
"==",
"type_1_id",
")",
... | When applying a type to a resource, it may be the case that the resource already
has an attribute specified in the new type, but the template which defines this
pre-existing attribute has a different unit specification to the new template.
This function checks for any situations where different... | [
"When",
"applying",
"a",
"type",
"to",
"a",
"resource",
"it",
"may",
"be",
"the",
"case",
"that",
"the",
"resource",
"already",
"has",
"an",
"attribute",
"specified",
"in",
"the",
"new",
"type",
"but",
"the",
"template",
"which",
"defines",
"this",
"pre",
... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1036-L1090 |
hydraplatform/hydra-base | hydra_base/lib/template.py | assign_type_to_resource | def assign_type_to_resource(type_id, resource_type, resource_id,**kwargs):
"""Assign new type to a resource. This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
function can a... | python | def assign_type_to_resource(type_id, resource_type, resource_id,**kwargs):
"""Assign new type to a resource. This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
function can a... | [
"def",
"assign_type_to_resource",
"(",
"type_id",
",",
"resource_type",
",",
"resource_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"resource_type",
"==",
"'NETWORK'",
":",
"resource",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")",
".",
"... | Assign new type to a resource. This function checks if the necessary
attributes are present and adds them if needed. Non existing attributes
are also added when the type is already assigned. This means that this
function can also be used to update resources, when a resource type has
changed. | [
"Assign",
"new",
"type",
"to",
"a",
"resource",
".",
"This",
"function",
"checks",
"if",
"the",
"necessary",
"attributes",
"are",
"present",
"and",
"adds",
"them",
"if",
"needed",
".",
"Non",
"existing",
"attributes",
"are",
"also",
"added",
"when",
"the",
... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1190-L1228 |
hydraplatform/hydra-base | hydra_base/lib/template.py | set_resource_type | def set_resource_type(resource, type_id, types={}, **kwargs):
"""
Set this resource to be a certain type.
Type objects (a dictionary keyed on type_id) may be
passed in to save on loading.
This function does not call save. It must be done afterwards.
New resource attributes ar... | python | def set_resource_type(resource, type_id, types={}, **kwargs):
"""
Set this resource to be a certain type.
Type objects (a dictionary keyed on type_id) may be
passed in to save on loading.
This function does not call save. It must be done afterwards.
New resource attributes ar... | [
"def",
"set_resource_type",
"(",
"resource",
",",
"type_id",
",",
"types",
"=",
"{",
"}",
",",
"*",
"*",
"kwargs",
")",
":",
"ref_key",
"=",
"resource",
".",
"ref_key",
"existing_attr_ids",
"=",
"[",
"]",
"for",
"res_attr",
"in",
"resource",
".",
"attrib... | Set this resource to be a certain type.
Type objects (a dictionary keyed on type_id) may be
passed in to save on loading.
This function does not call save. It must be done afterwards.
New resource attributes are added to the resource if the template
requires them. Resource attrib... | [
"Set",
"this",
"resource",
"to",
"be",
"a",
"certain",
"type",
".",
"Type",
"objects",
"(",
"a",
"dictionary",
"keyed",
"on",
"type_id",
")",
"may",
"be",
"passed",
"in",
"to",
"save",
"on",
"loading",
".",
"This",
"function",
"does",
"not",
"call",
"s... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1230-L1327 |
hydraplatform/hydra-base | hydra_base/lib/template.py | remove_type_from_resource | def remove_type_from_resource( type_id, resource_type, resource_id,**kwargs):
"""
Remove a resource type trom a resource
"""
node_id = resource_id if resource_type == 'NODE' else None
link_id = resource_id if resource_type == 'LINK' else None
group_id = resource_id if resource_type == 'GROUP... | python | def remove_type_from_resource( type_id, resource_type, resource_id,**kwargs):
"""
Remove a resource type trom a resource
"""
node_id = resource_id if resource_type == 'NODE' else None
link_id = resource_id if resource_type == 'LINK' else None
group_id = resource_id if resource_type == 'GROUP... | [
"def",
"remove_type_from_resource",
"(",
"type_id",
",",
"resource_type",
",",
"resource_id",
",",
"*",
"*",
"kwargs",
")",
":",
"node_id",
"=",
"resource_id",
"if",
"resource_type",
"==",
"'NODE'",
"else",
"None",
"link_id",
"=",
"resource_id",
"if",
"resource_... | Remove a resource type trom a resource | [
"Remove",
"a",
"resource",
"type",
"trom",
"a",
"resource"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1329-L1347 |
hydraplatform/hydra-base | hydra_base/lib/template.py | add_template | def add_template(template, **kwargs):
"""
Add template and a type and typeattrs.
"""
tmpl = Template()
tmpl.name = template.name
if template.description:
tmpl.description = template.description
if template.layout:
tmpl.layout = get_layout_as_string(template.layout)
d... | python | def add_template(template, **kwargs):
"""
Add template and a type and typeattrs.
"""
tmpl = Template()
tmpl.name = template.name
if template.description:
tmpl.description = template.description
if template.layout:
tmpl.layout = get_layout_as_string(template.layout)
d... | [
"def",
"add_template",
"(",
"template",
",",
"*",
"*",
"kwargs",
")",
":",
"tmpl",
"=",
"Template",
"(",
")",
"tmpl",
".",
"name",
"=",
"template",
".",
"name",
"if",
"template",
".",
"description",
":",
"tmpl",
".",
"description",
"=",
"template",
"."... | Add template and a type and typeattrs. | [
"Add",
"template",
"and",
"a",
"type",
"and",
"typeattrs",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1376-L1396 |
hydraplatform/hydra-base | hydra_base/lib/template.py | update_template | def update_template(template,**kwargs):
"""
Update template and a type and typeattrs.
"""
tmpl = db.DBSession.query(Template).filter(Template.id==template.id).one()
tmpl.name = template.name
if template.description:
tmpl.description = template.description
#Lazy load the rest of ... | python | def update_template(template,**kwargs):
"""
Update template and a type and typeattrs.
"""
tmpl = db.DBSession.query(Template).filter(Template.id==template.id).one()
tmpl.name = template.name
if template.description:
tmpl.description = template.description
#Lazy load the rest of ... | [
"def",
"update_template",
"(",
"template",
",",
"*",
"*",
"kwargs",
")",
":",
"tmpl",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"filter",
"(",
"Template",
".",
"id",
"==",
"template",
".",
"id",
")",
".",
"one",
"(",
")"... | Update template and a type and typeattrs. | [
"Update",
"template",
"and",
"a",
"type",
"and",
"typeattrs",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1398-L1437 |
hydraplatform/hydra-base | hydra_base/lib/template.py | delete_template | def delete_template(template_id,**kwargs):
"""
Delete a template and its type and typeattrs.
"""
try:
tmpl = db.DBSession.query(Template).filter(Template.id==template_id).one()
except NoResultFound:
raise ResourceNotFoundError("Template %s not found"%(template_id,))
db.DBSess... | python | def delete_template(template_id,**kwargs):
"""
Delete a template and its type and typeattrs.
"""
try:
tmpl = db.DBSession.query(Template).filter(Template.id==template_id).one()
except NoResultFound:
raise ResourceNotFoundError("Template %s not found"%(template_id,))
db.DBSess... | [
"def",
"delete_template",
"(",
"template_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"tmpl",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"filter",
"(",
"Template",
".",
"id",
"==",
"template_id",
")",
".",
"one",
"("... | Delete a template and its type and typeattrs. | [
"Delete",
"a",
"template",
"and",
"its",
"type",
"and",
"typeattrs",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1439-L1449 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_templates | def get_templates(load_all=True, **kwargs):
"""
Get all templates.
Args:
load_all Boolean: Returns just the template entry or the full template structure (template types and type attrs)
Returns:
List of Template objects
"""
if load_all is False:
templa... | python | def get_templates(load_all=True, **kwargs):
"""
Get all templates.
Args:
load_all Boolean: Returns just the template entry or the full template structure (template types and type attrs)
Returns:
List of Template objects
"""
if load_all is False:
templa... | [
"def",
"get_templates",
"(",
"load_all",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"load_all",
"is",
"False",
":",
"templates",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"all",
"(",
")",
"else",
":",
"templates... | Get all templates.
Args:
load_all Boolean: Returns just the template entry or the full template structure (template types and type attrs)
Returns:
List of Template objects | [
"Get",
"all",
"templates",
".",
"Args",
":",
"load_all",
"Boolean",
":",
"Returns",
"just",
"the",
"template",
"entry",
"or",
"the",
"full",
"template",
"structure",
"(",
"template",
"types",
"and",
"type",
"attrs",
")",
"Returns",
":",
"List",
"of",
"Temp... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1451-L1464 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_template | def get_template(template_id,**kwargs):
"""
Get a specific resource template template, by ID.
"""
try:
tmpl_i = db.DBSession.query(Template).filter(Template.id==template_id).options(joinedload_all('templatetypes.typeattrs.default_dataset.metadata')).one()
#Load the attributes.
... | python | def get_template(template_id,**kwargs):
"""
Get a specific resource template template, by ID.
"""
try:
tmpl_i = db.DBSession.query(Template).filter(Template.id==template_id).options(joinedload_all('templatetypes.typeattrs.default_dataset.metadata')).one()
#Load the attributes.
... | [
"def",
"get_template",
"(",
"template_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"tmpl_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"filter",
"(",
"Template",
".",
"id",
"==",
"template_id",
")",
".",
"options",
... | Get a specific resource template template, by ID. | [
"Get",
"a",
"specific",
"resource",
"template",
"template",
"by",
"ID",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1475-L1489 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_template_by_name | def get_template_by_name(name,**kwargs):
"""
Get a specific resource template, by name.
"""
try:
tmpl_i = db.DBSession.query(Template).filter(Template.name == name).options(joinedload_all('templatetypes.typeattrs.default_dataset.metadata')).one()
return tmpl_i
except NoResultFoun... | python | def get_template_by_name(name,**kwargs):
"""
Get a specific resource template, by name.
"""
try:
tmpl_i = db.DBSession.query(Template).filter(Template.name == name).options(joinedload_all('templatetypes.typeattrs.default_dataset.metadata')).one()
return tmpl_i
except NoResultFoun... | [
"def",
"get_template_by_name",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"tmpl_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Template",
")",
".",
"filter",
"(",
"Template",
".",
"name",
"==",
"name",
")",
".",
"options",
"(",... | Get a specific resource template, by name. | [
"Get",
"a",
"specific",
"resource",
"template",
"by",
"name",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1491-L1500 |
hydraplatform/hydra-base | hydra_base/lib/template.py | add_templatetype | def add_templatetype(templatetype,**kwargs):
"""
Add a template type with typeattrs.
"""
type_i = _update_templatetype(templatetype)
db.DBSession.flush()
return type_i | python | def add_templatetype(templatetype,**kwargs):
"""
Add a template type with typeattrs.
"""
type_i = _update_templatetype(templatetype)
db.DBSession.flush()
return type_i | [
"def",
"add_templatetype",
"(",
"templatetype",
",",
"*",
"*",
"kwargs",
")",
":",
"type_i",
"=",
"_update_templatetype",
"(",
"templatetype",
")",
"db",
".",
"DBSession",
".",
"flush",
"(",
")",
"return",
"type_i"
] | Add a template type with typeattrs. | [
"Add",
"a",
"template",
"type",
"with",
"typeattrs",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1502-L1511 |
hydraplatform/hydra-base | hydra_base/lib/template.py | update_templatetype | def update_templatetype(templatetype,**kwargs):
"""
Update a resource type and its typeattrs.
New typeattrs will be added. typeattrs not sent will be ignored.
To delete typeattrs, call delete_typeattr
"""
tmpltype_i = db.DBSession.query(TemplateType).filter(TemplateType.id == templa... | python | def update_templatetype(templatetype,**kwargs):
"""
Update a resource type and its typeattrs.
New typeattrs will be added. typeattrs not sent will be ignored.
To delete typeattrs, call delete_typeattr
"""
tmpltype_i = db.DBSession.query(TemplateType).filter(TemplateType.id == templa... | [
"def",
"update_templatetype",
"(",
"templatetype",
",",
"*",
"*",
"kwargs",
")",
":",
"tmpltype_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"TemplateType",
")",
".",
"filter",
"(",
"TemplateType",
".",
"id",
"==",
"templatetype",
".",
"id",
")",
... | Update a resource type and its typeattrs.
New typeattrs will be added. typeattrs not sent will be ignored.
To delete typeattrs, call delete_typeattr | [
"Update",
"a",
"resource",
"type",
"and",
"its",
"typeattrs",
".",
"New",
"typeattrs",
"will",
"be",
"added",
".",
"typeattrs",
"not",
"sent",
"will",
"be",
"ignored",
".",
"To",
"delete",
"typeattrs",
"call",
"delete_typeattr"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1513-L1526 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _set_typeattr | def _set_typeattr(typeattr, existing_ta = None):
"""
Add or updsate a type attribute.
If an existing type attribute is provided, then update.
Checks are performed to ensure that the dimension provided on the
type attr (not updateable) is the same as that on the referring attribute.
... | python | def _set_typeattr(typeattr, existing_ta = None):
"""
Add or updsate a type attribute.
If an existing type attribute is provided, then update.
Checks are performed to ensure that the dimension provided on the
type attr (not updateable) is the same as that on the referring attribute.
... | [
"def",
"_set_typeattr",
"(",
"typeattr",
",",
"existing_ta",
"=",
"None",
")",
":",
"if",
"existing_ta",
"is",
"None",
":",
"ta",
"=",
"TypeAttr",
"(",
"attr_id",
"=",
"typeattr",
".",
"attr_id",
")",
"else",
":",
"ta",
"=",
"existing_ta",
"ta",
".",
"... | Add or updsate a type attribute.
If an existing type attribute is provided, then update.
Checks are performed to ensure that the dimension provided on the
type attr (not updateable) is the same as that on the referring attribute.
The unit provided (stored on tattr) must conform to the d... | [
"Add",
"or",
"updsate",
"a",
"type",
"attribute",
".",
"If",
"an",
"existing",
"type",
"attribute",
"is",
"provided",
"then",
"update",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1528-L1601 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _update_templatetype | def _update_templatetype(templatetype, existing_tt=None):
"""
Add or update a templatetype. If an existing template type is passed in,
update that one. Otherwise search for an existing one. If not found, add.
"""
if existing_tt is None:
if "id" in templatetype and templatetype.id is ... | python | def _update_templatetype(templatetype, existing_tt=None):
"""
Add or update a templatetype. If an existing template type is passed in,
update that one. Otherwise search for an existing one. If not found, add.
"""
if existing_tt is None:
if "id" in templatetype and templatetype.id is ... | [
"def",
"_update_templatetype",
"(",
"templatetype",
",",
"existing_tt",
"=",
"None",
")",
":",
"if",
"existing_tt",
"is",
"None",
":",
"if",
"\"id\"",
"in",
"templatetype",
"and",
"templatetype",
".",
"id",
"is",
"not",
"None",
":",
"tmpltype_i",
"=",
"db",
... | Add or update a templatetype. If an existing template type is passed in,
update that one. Otherwise search for an existing one. If not found, add. | [
"Add",
"or",
"update",
"a",
"templatetype",
".",
"If",
"an",
"existing",
"template",
"type",
"is",
"passed",
"in",
"update",
"that",
"one",
".",
"Otherwise",
"search",
"for",
"an",
"existing",
"one",
".",
"If",
"not",
"found",
"add",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1603-L1650 |
hydraplatform/hydra-base | hydra_base/lib/template.py | delete_templatetype | def delete_templatetype(type_id,template_i=None, **kwargs):
"""
Delete a template type and its typeattrs.
"""
try:
tmpltype_i = db.DBSession.query(TemplateType).filter(TemplateType.id == type_id).one()
except NoResultFound:
raise ResourceNotFoundError("Template Type %s not found"... | python | def delete_templatetype(type_id,template_i=None, **kwargs):
"""
Delete a template type and its typeattrs.
"""
try:
tmpltype_i = db.DBSession.query(TemplateType).filter(TemplateType.id == type_id).one()
except NoResultFound:
raise ResourceNotFoundError("Template Type %s not found"... | [
"def",
"delete_templatetype",
"(",
"type_id",
",",
"template_i",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"tmpltype_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"TemplateType",
")",
".",
"filter",
"(",
"TemplateType",
".",
"id",... | Delete a template type and its typeattrs. | [
"Delete",
"a",
"template",
"type",
"and",
"its",
"typeattrs",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1652-L1667 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_templatetype | def get_templatetype(type_id,**kwargs):
"""
Get a specific resource type by ID.
"""
templatetype = db.DBSession.query(TemplateType).filter(
TemplateType.id==type_id).options(
joinedload_all("typeattrs")).one()
return templatetype | python | def get_templatetype(type_id,**kwargs):
"""
Get a specific resource type by ID.
"""
templatetype = db.DBSession.query(TemplateType).filter(
TemplateType.id==type_id).options(
joinedload_all("typeattrs")).one()
return templatetype | [
"def",
"get_templatetype",
"(",
"type_id",
",",
"*",
"*",
"kwargs",
")",
":",
"templatetype",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"TemplateType",
")",
".",
"filter",
"(",
"TemplateType",
".",
"id",
"==",
"type_id",
")",
".",
"options",
"(",
... | Get a specific resource type by ID. | [
"Get",
"a",
"specific",
"resource",
"type",
"by",
"ID",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1669-L1678 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_templatetype_by_name | def get_templatetype_by_name(template_id, type_name,**kwargs):
"""
Get a specific resource type by name.
"""
try:
templatetype = db.DBSession.query(TemplateType).filter(TemplateType.id==template_id, TemplateType.name==type_name).one()
except NoResultFound:
raise HydraError("%s i... | python | def get_templatetype_by_name(template_id, type_name,**kwargs):
"""
Get a specific resource type by name.
"""
try:
templatetype = db.DBSession.query(TemplateType).filter(TemplateType.id==template_id, TemplateType.name==type_name).one()
except NoResultFound:
raise HydraError("%s i... | [
"def",
"get_templatetype_by_name",
"(",
"template_id",
",",
"type_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"templatetype",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"TemplateType",
")",
".",
"filter",
"(",
"TemplateType",
".",
"id",
"=="... | Get a specific resource type by name. | [
"Get",
"a",
"specific",
"resource",
"type",
"by",
"name",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1680-L1690 |
hydraplatform/hydra-base | hydra_base/lib/template.py | add_typeattr | def add_typeattr(typeattr,**kwargs):
"""
Add an typeattr to an existing type.
"""
tmpltype = get_templatetype(typeattr.type_id, user_id=kwargs.get('user_id'))
ta = _set_typeattr(typeattr)
tmpltype.typeattrs.append(ta)
db.DBSession.flush()
return ta | python | def add_typeattr(typeattr,**kwargs):
"""
Add an typeattr to an existing type.
"""
tmpltype = get_templatetype(typeattr.type_id, user_id=kwargs.get('user_id'))
ta = _set_typeattr(typeattr)
tmpltype.typeattrs.append(ta)
db.DBSession.flush()
return ta | [
"def",
"add_typeattr",
"(",
"typeattr",
",",
"*",
"*",
"kwargs",
")",
":",
"tmpltype",
"=",
"get_templatetype",
"(",
"typeattr",
".",
"type_id",
",",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
")",
"ta",
"=",
"_set_typeattr",
"(",
"type... | Add an typeattr to an existing type. | [
"Add",
"an",
"typeattr",
"to",
"an",
"existing",
"type",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1692-L1705 |
hydraplatform/hydra-base | hydra_base/lib/template.py | delete_typeattr | def delete_typeattr(typeattr,**kwargs):
"""
Remove an typeattr from an existing type
"""
tmpltype = get_templatetype(typeattr.type_id, user_id=kwargs.get('user_id'))
ta = db.DBSession.query(TypeAttr).filter(TypeAttr.type_id == typeattr.type_id,
TypeAtt... | python | def delete_typeattr(typeattr,**kwargs):
"""
Remove an typeattr from an existing type
"""
tmpltype = get_templatetype(typeattr.type_id, user_id=kwargs.get('user_id'))
ta = db.DBSession.query(TypeAttr).filter(TypeAttr.type_id == typeattr.type_id,
TypeAtt... | [
"def",
"delete_typeattr",
"(",
"typeattr",
",",
"*",
"*",
"kwargs",
")",
":",
"tmpltype",
"=",
"get_templatetype",
"(",
"typeattr",
".",
"type_id",
",",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
")",
"ta",
"=",
"db",
".",
"DBSession",
... | Remove an typeattr from an existing type | [
"Remove",
"an",
"typeattr",
"from",
"an",
"existing",
"type"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1708-L1722 |
hydraplatform/hydra-base | hydra_base/lib/template.py | validate_attr | def validate_attr(resource_attr_id, scenario_id, template_id=None):
"""
Check that a resource attribute satisfies the requirements of all the types of the
resource.
"""
rs = db.DBSession.query(ResourceScenario).\
filter(ResourceScenario.resource_attr_id==resource_attr... | python | def validate_attr(resource_attr_id, scenario_id, template_id=None):
"""
Check that a resource attribute satisfies the requirements of all the types of the
resource.
"""
rs = db.DBSession.query(ResourceScenario).\
filter(ResourceScenario.resource_attr_id==resource_attr... | [
"def",
"validate_attr",
"(",
"resource_attr_id",
",",
"scenario_id",
",",
"template_id",
"=",
"None",
")",
":",
"rs",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceScenario",
")",
".",
"filter",
"(",
"ResourceScenario",
".",
"resource_attr_id",
"=="... | Check that a resource attribute satisfies the requirements of all the types of the
resource. | [
"Check",
"that",
"a",
"resource",
"attribute",
"satisfies",
"the",
"requirements",
"of",
"all",
"the",
"types",
"of",
"the",
"resource",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1724-L1753 |
hydraplatform/hydra-base | hydra_base/lib/template.py | validate_attrs | def validate_attrs(resource_attr_ids, scenario_id, template_id=None):
"""
Check that multiple resource attribute satisfy the requirements of the types of resources to
which the they are attached.
"""
multi_rs = db.DBSession.query(ResourceScenario).\
filter(Resourc... | python | def validate_attrs(resource_attr_ids, scenario_id, template_id=None):
"""
Check that multiple resource attribute satisfy the requirements of the types of resources to
which the they are attached.
"""
multi_rs = db.DBSession.query(ResourceScenario).\
filter(Resourc... | [
"def",
"validate_attrs",
"(",
"resource_attr_ids",
",",
"scenario_id",
",",
"template_id",
"=",
"None",
")",
":",
"multi_rs",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceScenario",
")",
".",
"filter",
"(",
"ResourceScenario",
".",
"resource_attr_id"... | Check that multiple resource attribute satisfy the requirements of the types of resources to
which the they are attached. | [
"Check",
"that",
"multiple",
"resource",
"attribute",
"satisfy",
"the",
"requirements",
"of",
"the",
"types",
"of",
"resources",
"to",
"which",
"the",
"they",
"are",
"attached",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1755-L1786 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _do_validate_resourcescenario | def _do_validate_resourcescenario(resourcescenario, template_id=None):
"""
Perform a check to ensure a resource scenario's datasets are correct given what the
definition of that resource (its type) specifies.
"""
res = resourcescenario.resourceattr.get_resource()
types = res.types
... | python | def _do_validate_resourcescenario(resourcescenario, template_id=None):
"""
Perform a check to ensure a resource scenario's datasets are correct given what the
definition of that resource (its type) specifies.
"""
res = resourcescenario.resourceattr.get_resource()
types = res.types
... | [
"def",
"_do_validate_resourcescenario",
"(",
"resourcescenario",
",",
"template_id",
"=",
"None",
")",
":",
"res",
"=",
"resourcescenario",
".",
"resourceattr",
".",
"get_resource",
"(",
")",
"types",
"=",
"res",
".",
"types",
"dataset",
"=",
"resourcescenario",
... | Perform a check to ensure a resource scenario's datasets are correct given what the
definition of that resource (its type) specifies. | [
"Perform",
"a",
"check",
"to",
"ensure",
"a",
"resource",
"scenario",
"s",
"datasets",
"are",
"correct",
"given",
"what",
"the",
"definition",
"of",
"that",
"resource",
"(",
"its",
"type",
")",
"specifies",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1821-L1857 |
hydraplatform/hydra-base | hydra_base/lib/template.py | validate_network | def validate_network(network_id, template_id, scenario_id=None):
"""
Given a network, scenario and template, ensure that all the nodes, links & groups
in the network have the correct resource attributes as defined by the types in the template.
Also ensure valid entries in tresourcetype.
... | python | def validate_network(network_id, template_id, scenario_id=None):
"""
Given a network, scenario and template, ensure that all the nodes, links & groups
in the network have the correct resource attributes as defined by the types in the template.
Also ensure valid entries in tresourcetype.
... | [
"def",
"validate_network",
"(",
"network_id",
",",
"template_id",
",",
"scenario_id",
"=",
"None",
")",
":",
"network",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")",
".",
"filter",
"(",
"Network",
".",
"id",
"==",
"network_id",
")",
"."... | Given a network, scenario and template, ensure that all the nodes, links & groups
in the network have the correct resource attributes as defined by the types in the template.
Also ensure valid entries in tresourcetype.
This validation will not fail if a resource has more than the required type, ... | [
"Given",
"a",
"network",
"scenario",
"and",
"template",
"ensure",
"that",
"all",
"the",
"nodes",
"links",
"&",
"groups",
"in",
"the",
"network",
"have",
"the",
"correct",
"resource",
"attributes",
"as",
"defined",
"by",
"the",
"types",
"in",
"the",
"template... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1859-L1921 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_network_as_xml_template | def get_network_as_xml_template(network_id,**kwargs):
"""
Turn an existing network into an xml template
using its attributes.
If an optional scenario ID is passed in, default
values will be populated from that scenario.
"""
template_xml = etree.Element("template_definition")
... | python | def get_network_as_xml_template(network_id,**kwargs):
"""
Turn an existing network into an xml template
using its attributes.
If an optional scenario ID is passed in, default
values will be populated from that scenario.
"""
template_xml = etree.Element("template_definition")
... | [
"def",
"get_network_as_xml_template",
"(",
"network_id",
",",
"*",
"*",
"kwargs",
")",
":",
"template_xml",
"=",
"etree",
".",
"Element",
"(",
"\"template_definition\"",
")",
"net_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")",
".",
"filt... | Turn an existing network into an xml template
using its attributes.
If an optional scenario ID is passed in, default
values will be populated from that scenario. | [
"Turn",
"an",
"existing",
"network",
"into",
"an",
"xml",
"template",
"using",
"its",
"attributes",
".",
"If",
"an",
"optional",
"scenario",
"ID",
"is",
"passed",
"in",
"default",
"values",
"will",
"be",
"populated",
"from",
"that",
"scenario",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L1988-L2091 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _make_attr_element_from_typeattr | def _make_attr_element_from_typeattr(parent, type_attr_i):
"""
General function to add an attribute element to a resource element.
resource_attr_i can also e a type_attr if being called from get_tempalte_as_xml
"""
attr = _make_attr_element(parent, type_attr_i.attr)
if type_attr_i.unit... | python | def _make_attr_element_from_typeattr(parent, type_attr_i):
"""
General function to add an attribute element to a resource element.
resource_attr_i can also e a type_attr if being called from get_tempalte_as_xml
"""
attr = _make_attr_element(parent, type_attr_i.attr)
if type_attr_i.unit... | [
"def",
"_make_attr_element_from_typeattr",
"(",
"parent",
",",
"type_attr_i",
")",
":",
"attr",
"=",
"_make_attr_element",
"(",
"parent",
",",
"type_attr_i",
".",
"attr",
")",
"if",
"type_attr_i",
".",
"unit_id",
"is",
"not",
"None",
":",
"attr_unit",
"=",
"et... | General function to add an attribute element to a resource element.
resource_attr_i can also e a type_attr if being called from get_tempalte_as_xml | [
"General",
"function",
"to",
"add",
"an",
"attribute",
"element",
"to",
"a",
"resource",
"element",
".",
"resource_attr_i",
"can",
"also",
"e",
"a",
"type_attr",
"if",
"being",
"called",
"from",
"get_tempalte_as_xml"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L2093-L2116 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _make_attr_element_from_resourceattr | def _make_attr_element_from_resourceattr(parent, resource_attr_i):
"""
General function to add an attribute element to a resource element.
"""
attr = _make_attr_element(parent, resource_attr_i.attr)
attr_is_var = etree.SubElement(attr, 'is_var')
attr_is_var.text = resource_attr_i.attr_i... | python | def _make_attr_element_from_resourceattr(parent, resource_attr_i):
"""
General function to add an attribute element to a resource element.
"""
attr = _make_attr_element(parent, resource_attr_i.attr)
attr_is_var = etree.SubElement(attr, 'is_var')
attr_is_var.text = resource_attr_i.attr_i... | [
"def",
"_make_attr_element_from_resourceattr",
"(",
"parent",
",",
"resource_attr_i",
")",
":",
"attr",
"=",
"_make_attr_element",
"(",
"parent",
",",
"resource_attr_i",
".",
"attr",
")",
"attr_is_var",
"=",
"etree",
".",
"SubElement",
"(",
"attr",
",",
"'is_var'"... | General function to add an attribute element to a resource element. | [
"General",
"function",
"to",
"add",
"an",
"attribute",
"element",
"to",
"a",
"resource",
"element",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L2118-L2128 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _make_attr_element | def _make_attr_element(parent, attr_i):
"""
create an attribute element from an attribute DB object
"""
attr = etree.SubElement(parent, "attribute")
attr_name = etree.SubElement(attr, 'name')
attr_name.text = attr_i.name
attr_desc = etree.SubElement(attr, 'description')
a... | python | def _make_attr_element(parent, attr_i):
"""
create an attribute element from an attribute DB object
"""
attr = etree.SubElement(parent, "attribute")
attr_name = etree.SubElement(attr, 'name')
attr_name.text = attr_i.name
attr_desc = etree.SubElement(attr, 'description')
a... | [
"def",
"_make_attr_element",
"(",
"parent",
",",
"attr_i",
")",
":",
"attr",
"=",
"etree",
".",
"SubElement",
"(",
"parent",
",",
"\"attribute\"",
")",
"attr_name",
"=",
"etree",
".",
"SubElement",
"(",
"attr",
",",
"'name'",
")",
"attr_name",
".",
"text",... | create an attribute element from an attribute DB object | [
"create",
"an",
"attribute",
"element",
"from",
"an",
"attribute",
"DB",
"object"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L2130-L2145 |
hydraplatform/hydra-base | hydra_base/lib/template.py | get_etree_layout_as_dict | def get_etree_layout_as_dict(layout_tree):
"""
Convert something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
<item>
<name>shapefile</name>
<value>blah.shp</value>
</item>
</layout>
... | python | def get_etree_layout_as_dict(layout_tree):
"""
Convert something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
<item>
<name>shapefile</name>
<value>blah.shp</value>
</item>
</layout>
... | [
"def",
"get_etree_layout_as_dict",
"(",
"layout_tree",
")",
":",
"layout_dict",
"=",
"dict",
"(",
")",
"for",
"item",
"in",
"layout_tree",
".",
"findall",
"(",
"'item'",
")",
":",
"name",
"=",
"item",
".",
"find",
"(",
"'name'",
")",
".",
"text",
"val_el... | Convert something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
<item>
<name>shapefile</name>
<value>blah.shp</value>
</item>
</layout>
Into something that looks like this:
{
'co... | [
"Convert",
"something",
"that",
"looks",
"like",
"this",
":",
"<layout",
">",
"<item",
">",
"<name",
">",
"color<",
"/",
"name",
">",
"<value",
">",
"red<",
"/",
"value",
">",
"<",
"/",
"item",
">",
"<item",
">",
"<name",
">",
"shapefile<",
"/",
"nam... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L2147-L2176 |
hydraplatform/hydra-base | hydra_base/lib/template.py | _get_layout_as_etree | def _get_layout_as_etree(layout_dict):
"""
Convert something that looks like this:
{
'color' : ['red'],
'shapefile' : ['blah.shp']
}
Into something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
... | python | def _get_layout_as_etree(layout_dict):
"""
Convert something that looks like this:
{
'color' : ['red'],
'shapefile' : ['blah.shp']
}
Into something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
... | [
"def",
"_get_layout_as_etree",
"(",
"layout_dict",
")",
":",
"if",
"layout_dict",
"is",
"None",
":",
"return",
"None",
"layout",
"=",
"etree",
".",
"Element",
"(",
"\"layout\"",
")",
"layout_dict",
"=",
"eval",
"(",
"layout_dict",
")",
"for",
"k",
",",
"v"... | Convert something that looks like this:
{
'color' : ['red'],
'shapefile' : ['blah.shp']
}
Into something that looks like this:
<layout>
<item>
<name>color</name>
<value>red</value>
</item>
<item>
<name>shapefile</name>
... | [
"Convert",
"something",
"that",
"looks",
"like",
"this",
":",
"{",
"color",
":",
"[",
"red",
"]",
"shapefile",
":",
"[",
"blah",
".",
"shp",
"]",
"}"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/template.py#L2178-L2210 |
hydraplatform/hydra-base | hydra_base/lib/HydraTypes/Registry.py | HydraObjectFactory.valueFromDataset | def valueFromDataset(cls, datatype, value, metadata=None, tmap=None):
"""
Return the value contained by dataset argument, after casting to
correct type and performing type-specific validation
"""
if tmap is None:
tmap = typemap
obj = cls.fromDataset(dataty... | python | def valueFromDataset(cls, datatype, value, metadata=None, tmap=None):
"""
Return the value contained by dataset argument, after casting to
correct type and performing type-specific validation
"""
if tmap is None:
tmap = typemap
obj = cls.fromDataset(dataty... | [
"def",
"valueFromDataset",
"(",
"cls",
",",
"datatype",
",",
"value",
",",
"metadata",
"=",
"None",
",",
"tmap",
"=",
"None",
")",
":",
"if",
"tmap",
"is",
"None",
":",
"tmap",
"=",
"typemap",
"obj",
"=",
"cls",
".",
"fromDataset",
"(",
"datatype",
"... | Return the value contained by dataset argument, after casting to
correct type and performing type-specific validation | [
"Return",
"the",
"value",
"contained",
"by",
"dataset",
"argument",
"after",
"casting",
"to",
"correct",
"type",
"and",
"performing",
"type",
"-",
"specific",
"validation"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/HydraTypes/Registry.py#L28-L36 |
hydraplatform/hydra-base | hydra_base/lib/HydraTypes/Registry.py | HydraObjectFactory.fromDataset | def fromDataset(datatype, value, metadata=None, tmap=None):
"""
Return a representation of dataset argument as an instance
of the class corresponding to its datatype
"""
if tmap is None:
tmap = typemap
return tmap[datatype.upper()].fromDataset(value, meta... | python | def fromDataset(datatype, value, metadata=None, tmap=None):
"""
Return a representation of dataset argument as an instance
of the class corresponding to its datatype
"""
if tmap is None:
tmap = typemap
return tmap[datatype.upper()].fromDataset(value, meta... | [
"def",
"fromDataset",
"(",
"datatype",
",",
"value",
",",
"metadata",
"=",
"None",
",",
"tmap",
"=",
"None",
")",
":",
"if",
"tmap",
"is",
"None",
":",
"tmap",
"=",
"typemap",
"return",
"tmap",
"[",
"datatype",
".",
"upper",
"(",
")",
"]",
".",
"fr... | Return a representation of dataset argument as an instance
of the class corresponding to its datatype | [
"Return",
"a",
"representation",
"of",
"dataset",
"argument",
"as",
"an",
"instance"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/HydraTypes/Registry.py#L39-L47 |
hydraplatform/hydra-base | hydra_base/lib/units.py | exists_dimension | def exists_dimension(dimension_name,**kwargs):
"""
Given a dimension returns True if it exists, False otherwise
"""
try:
dimension = db.DBSession.query(Dimension).filter(Dimension.name==dimension_name).one()
# At this point the dimension exists
return True
except NoResult... | python | def exists_dimension(dimension_name,**kwargs):
"""
Given a dimension returns True if it exists, False otherwise
"""
try:
dimension = db.DBSession.query(Dimension).filter(Dimension.name==dimension_name).one()
# At this point the dimension exists
return True
except NoResult... | [
"def",
"exists_dimension",
"(",
"dimension_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"dimension",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")",
".",
"filter",
"(",
"Dimension",
".",
"name",
"==",
"dimension_name",
")",
"."... | Given a dimension returns True if it exists, False otherwise | [
"Given",
"a",
"dimension",
"returns",
"True",
"if",
"it",
"exists",
"False",
"otherwise"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L49-L59 |
hydraplatform/hydra-base | hydra_base/lib/units.py | _parse_unit | def _parse_unit(measure_or_unit_abbreviation):
"""
Helper function that extracts constant factors from unit specifications.
This allows to specify units similar to this: 10^6 m^3.
Return a couple (unit, factor)
"""
try:
float(measure_or_unit_abbreviation[0])
# The mea... | python | def _parse_unit(measure_or_unit_abbreviation):
"""
Helper function that extracts constant factors from unit specifications.
This allows to specify units similar to this: 10^6 m^3.
Return a couple (unit, factor)
"""
try:
float(measure_or_unit_abbreviation[0])
# The mea... | [
"def",
"_parse_unit",
"(",
"measure_or_unit_abbreviation",
")",
":",
"try",
":",
"float",
"(",
"measure_or_unit_abbreviation",
"[",
"0",
"]",
")",
"# The measure contains the values and the unit_abbreviation",
"factor",
",",
"unit_abbreviation",
"=",
"measure_or_unit_abbrevia... | Helper function that extracts constant factors from unit specifications.
This allows to specify units similar to this: 10^6 m^3.
Return a couple (unit, factor) | [
"Helper",
"function",
"that",
"extracts",
"constant",
"factors",
"from",
"unit",
"specifications",
".",
"This",
"allows",
"to",
"specify",
"units",
"similar",
"to",
"this",
":",
"10^6",
"m^3",
".",
"Return",
"a",
"couple",
"(",
"unit",
"factor",
")"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L75-L88 |
hydraplatform/hydra-base | hydra_base/lib/units.py | convert_units | def convert_units(values, source_measure_or_unit_abbreviation, target_measure_or_unit_abbreviation,**kwargs):
"""
Convert a value from one unit to another one.
Example::
>>> cli = PluginLib.connect()
>>> cli.service.convert_units(20.0, 'm', 'km')
0.02
Pa... | python | def convert_units(values, source_measure_or_unit_abbreviation, target_measure_or_unit_abbreviation,**kwargs):
"""
Convert a value from one unit to another one.
Example::
>>> cli = PluginLib.connect()
>>> cli.service.convert_units(20.0, 'm', 'km')
0.02
Pa... | [
"def",
"convert_units",
"(",
"values",
",",
"source_measure_or_unit_abbreviation",
",",
"target_measure_or_unit_abbreviation",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"numpy",
".",
"isscalar",
"(",
"values",
")",
":",
"# If it is a scalar, converts to an array",
"value... | Convert a value from one unit to another one.
Example::
>>> cli = PluginLib.connect()
>>> cli.service.convert_units(20.0, 'm', 'km')
0.02
Parameters:
values: single measure or an array of measures
source_measure_or_unit_abbreviation: A measur... | [
"Convert",
"a",
"value",
"from",
"one",
"unit",
"to",
"another",
"one",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L98-L121 |
hydraplatform/hydra-base | hydra_base/lib/units.py | convert | def convert(values, source_measure_or_unit_abbreviation, target_measure_or_unit_abbreviation):
"""
Convert a value or a list of values from an unit to another one.
The two units must represent the same physical dimension.
"""
source_dimension = get_dimension_by_unit_measure_or_abbreviation(... | python | def convert(values, source_measure_or_unit_abbreviation, target_measure_or_unit_abbreviation):
"""
Convert a value or a list of values from an unit to another one.
The two units must represent the same physical dimension.
"""
source_dimension = get_dimension_by_unit_measure_or_abbreviation(... | [
"def",
"convert",
"(",
"values",
",",
"source_measure_or_unit_abbreviation",
",",
"target_measure_or_unit_abbreviation",
")",
":",
"source_dimension",
"=",
"get_dimension_by_unit_measure_or_abbreviation",
"(",
"source_measure_or_unit_abbreviation",
")",
"target_dimension",
"=",
"... | Convert a value or a list of values from an unit to another one.
The two units must represent the same physical dimension. | [
"Convert",
"a",
"value",
"or",
"a",
"list",
"of",
"values",
"from",
"an",
"unit",
"to",
"another",
"one",
".",
"The",
"two",
"units",
"must",
"represent",
"the",
"same",
"physical",
"dimension",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L123-L155 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_empty_dimension | def get_empty_dimension(**kwargs):
"""
Returns a dimension object initialized with empty values
"""
dimension = JSONObject(Dimension())
dimension.id = None
dimension.name = ''
dimension.description = ''
dimension.project_id = None
dimension.units = []
return dimension | python | def get_empty_dimension(**kwargs):
"""
Returns a dimension object initialized with empty values
"""
dimension = JSONObject(Dimension())
dimension.id = None
dimension.name = ''
dimension.description = ''
dimension.project_id = None
dimension.units = []
return dimension | [
"def",
"get_empty_dimension",
"(",
"*",
"*",
"kwargs",
")",
":",
"dimension",
"=",
"JSONObject",
"(",
"Dimension",
"(",
")",
")",
"dimension",
".",
"id",
"=",
"None",
"dimension",
".",
"name",
"=",
"''",
"dimension",
".",
"description",
"=",
"''",
"dimen... | Returns a dimension object initialized with empty values | [
"Returns",
"a",
"dimension",
"object",
"initialized",
"with",
"empty",
"values"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L163-L173 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_dimension | def get_dimension(dimension_id, do_accept_dimension_id_none=False,**kwargs):
"""
Given a dimension id returns all its data
"""
if do_accept_dimension_id_none == True and dimension_id is None:
# In this special case, the method returns a dimension with id None
return get_empty_dimensi... | python | def get_dimension(dimension_id, do_accept_dimension_id_none=False,**kwargs):
"""
Given a dimension id returns all its data
"""
if do_accept_dimension_id_none == True and dimension_id is None:
# In this special case, the method returns a dimension with id None
return get_empty_dimensi... | [
"def",
"get_dimension",
"(",
"dimension_id",
",",
"do_accept_dimension_id_none",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"do_accept_dimension_id_none",
"==",
"True",
"and",
"dimension_id",
"is",
"None",
":",
"# In this special case, the method returns a d... | Given a dimension id returns all its data | [
"Given",
"a",
"dimension",
"id",
"returns",
"all",
"its",
"data"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L177-L194 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_dimensions | def get_dimensions(**kwargs):
"""
Returns a list of objects describing all the dimensions with all the units.
"""
dimensions_list = db.DBSession.query(Dimension).options(load_only("id")).all()
return_list = []
for dimension in dimensions_list:
return_list.append(get_dimension(dimensi... | python | def get_dimensions(**kwargs):
"""
Returns a list of objects describing all the dimensions with all the units.
"""
dimensions_list = db.DBSession.query(Dimension).options(load_only("id")).all()
return_list = []
for dimension in dimensions_list:
return_list.append(get_dimension(dimensi... | [
"def",
"get_dimensions",
"(",
"*",
"*",
"kwargs",
")",
":",
"dimensions_list",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")",
".",
"options",
"(",
"load_only",
"(",
"\"id\"",
")",
")",
".",
"all",
"(",
")",
"return_list",
"=",
"[",
... | Returns a list of objects describing all the dimensions with all the units. | [
"Returns",
"a",
"list",
"of",
"objects",
"describing",
"all",
"the",
"dimensions",
"with",
"all",
"the",
"units",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L197-L207 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_dimension_by_name | def get_dimension_by_name(dimension_name,**kwargs):
"""
Given a dimension name returns all its data. Used in convert functions
"""
try:
if dimension_name is None:
dimension_name = ''
dimension = db.DBSession.query(Dimension).filter(func.lower(Dimension.name)==func.lower(d... | python | def get_dimension_by_name(dimension_name,**kwargs):
"""
Given a dimension name returns all its data. Used in convert functions
"""
try:
if dimension_name is None:
dimension_name = ''
dimension = db.DBSession.query(Dimension).filter(func.lower(Dimension.name)==func.lower(d... | [
"def",
"get_dimension_by_name",
"(",
"dimension_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"if",
"dimension_name",
"is",
"None",
":",
"dimension_name",
"=",
"''",
"dimension",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")",
"."... | Given a dimension name returns all its data. Used in convert functions | [
"Given",
"a",
"dimension",
"name",
"returns",
"all",
"its",
"data",
".",
"Used",
"in",
"convert",
"functions"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L210-L223 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_unit | def get_unit(unit_id, **kwargs):
"""
Returns a single unit
"""
try:
unit = db.DBSession.query(Unit).filter(Unit.id==unit_id).one()
return JSONObject(unit)
except NoResultFound:
# The dimension does not exist
raise ResourceNotFoundError("Unit %s not found"%(unit_id... | python | def get_unit(unit_id, **kwargs):
"""
Returns a single unit
"""
try:
unit = db.DBSession.query(Unit).filter(Unit.id==unit_id).one()
return JSONObject(unit)
except NoResultFound:
# The dimension does not exist
raise ResourceNotFoundError("Unit %s not found"%(unit_id... | [
"def",
"get_unit",
"(",
"unit_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"unit",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
".",
"filter",
"(",
"Unit",
".",
"id",
"==",
"unit_id",
")",
".",
"one",
"(",
")",
"return",
... | Returns a single unit | [
"Returns",
"a",
"single",
"unit"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L233-L242 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_units | def get_units(**kwargs):
"""
Returns all the units
"""
units_list = db.DBSession.query(Unit).all()
units = []
for unit in units_list:
new_unit = JSONObject(unit)
units.append(new_unit)
return units | python | def get_units(**kwargs):
"""
Returns all the units
"""
units_list = db.DBSession.query(Unit).all()
units = []
for unit in units_list:
new_unit = JSONObject(unit)
units.append(new_unit)
return units | [
"def",
"get_units",
"(",
"*",
"*",
"kwargs",
")",
":",
"units_list",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
".",
"all",
"(",
")",
"units",
"=",
"[",
"]",
"for",
"unit",
"in",
"units_list",
":",
"new_unit",
"=",
"JSONObject",
"... | Returns all the units | [
"Returns",
"all",
"the",
"units"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L244-L254 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_dimension_by_unit_measure_or_abbreviation | def get_dimension_by_unit_measure_or_abbreviation(measure_or_unit_abbreviation,**kwargs):
"""
Return the physical dimension a given unit abbreviation of a measure, or the measure itself, refers to.
The search key is the abbreviation or the full measure
"""
unit_abbreviation, factor = _parse... | python | def get_dimension_by_unit_measure_or_abbreviation(measure_or_unit_abbreviation,**kwargs):
"""
Return the physical dimension a given unit abbreviation of a measure, or the measure itself, refers to.
The search key is the abbreviation or the full measure
"""
unit_abbreviation, factor = _parse... | [
"def",
"get_dimension_by_unit_measure_or_abbreviation",
"(",
"measure_or_unit_abbreviation",
",",
"*",
"*",
"kwargs",
")",
":",
"unit_abbreviation",
",",
"factor",
"=",
"_parse_unit",
"(",
"measure_or_unit_abbreviation",
")",
"units",
"=",
"db",
".",
"DBSession",
".",
... | Return the physical dimension a given unit abbreviation of a measure, or the measure itself, refers to.
The search key is the abbreviation or the full measure | [
"Return",
"the",
"physical",
"dimension",
"a",
"given",
"unit",
"abbreviation",
"of",
"a",
"measure",
"or",
"the",
"measure",
"itself",
"refers",
"to",
".",
"The",
"search",
"key",
"is",
"the",
"abbreviation",
"or",
"the",
"full",
"measure"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L256-L272 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_dimension_by_unit_id | def get_dimension_by_unit_id(unit_id, do_accept_unit_id_none=False, **kwargs):
"""
Return the physical dimension a given unit id refers to.
if do_accept_unit_id_none is False, it raises an exception if unit_id is not valid or None
if do_accept_unit_id_none is True, and unit_id is None, the f... | python | def get_dimension_by_unit_id(unit_id, do_accept_unit_id_none=False, **kwargs):
"""
Return the physical dimension a given unit id refers to.
if do_accept_unit_id_none is False, it raises an exception if unit_id is not valid or None
if do_accept_unit_id_none is True, and unit_id is None, the f... | [
"def",
"get_dimension_by_unit_id",
"(",
"unit_id",
",",
"do_accept_unit_id_none",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"do_accept_unit_id_none",
"==",
"True",
"and",
"unit_id",
"is",
"None",
":",
"# In this special case, the method returns a dimension ... | Return the physical dimension a given unit id refers to.
if do_accept_unit_id_none is False, it raises an exception if unit_id is not valid or None
if do_accept_unit_id_none is True, and unit_id is None, the function returns a Dimension with id None (unit_id can be none in some cases) | [
"Return",
"the",
"physical",
"dimension",
"a",
"given",
"unit",
"id",
"refers",
"to",
".",
"if",
"do_accept_unit_id_none",
"is",
"False",
"it",
"raises",
"an",
"exception",
"if",
"unit_id",
"is",
"not",
"valid",
"or",
"None",
"if",
"do_accept_unit_id_none",
"i... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L274-L289 |
hydraplatform/hydra-base | hydra_base/lib/units.py | get_unit_by_abbreviation | def get_unit_by_abbreviation(unit_abbreviation, **kwargs):
"""
Returns a single unit by abbreviation. Used as utility function to resolve string to id
"""
try:
if unit_abbreviation is None:
unit_abbreviation = ''
unit_i = db.DBSession.query(Unit).filter(Unit.abbreviation=... | python | def get_unit_by_abbreviation(unit_abbreviation, **kwargs):
"""
Returns a single unit by abbreviation. Used as utility function to resolve string to id
"""
try:
if unit_abbreviation is None:
unit_abbreviation = ''
unit_i = db.DBSession.query(Unit).filter(Unit.abbreviation=... | [
"def",
"get_unit_by_abbreviation",
"(",
"unit_abbreviation",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"if",
"unit_abbreviation",
"is",
"None",
":",
"unit_abbreviation",
"=",
"''",
"unit_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
... | Returns a single unit by abbreviation. Used as utility function to resolve string to id | [
"Returns",
"a",
"single",
"unit",
"by",
"abbreviation",
".",
"Used",
"as",
"utility",
"function",
"to",
"resolve",
"string",
"to",
"id"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L292-L303 |
hydraplatform/hydra-base | hydra_base/lib/units.py | add_dimension | def add_dimension(dimension,**kwargs):
"""
Add the dimension defined into the object "dimension" to the DB
If dimension["project_id"] is None it means that the dimension is global, otherwise is property of a project
If the dimension exists emits an exception
"""
if numpy.isscalar(dim... | python | def add_dimension(dimension,**kwargs):
"""
Add the dimension defined into the object "dimension" to the DB
If dimension["project_id"] is None it means that the dimension is global, otherwise is property of a project
If the dimension exists emits an exception
"""
if numpy.isscalar(dim... | [
"def",
"add_dimension",
"(",
"dimension",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"numpy",
".",
"isscalar",
"(",
"dimension",
")",
":",
"# If it is a scalar, converts to an Object",
"dimension",
"=",
"{",
"'name'",
":",
"dimension",
"}",
"new_dimension",
"=",
... | Add the dimension defined into the object "dimension" to the DB
If dimension["project_id"] is None it means that the dimension is global, otherwise is property of a project
If the dimension exists emits an exception | [
"Add",
"the",
"dimension",
"defined",
"into",
"the",
"object",
"dimension",
"to",
"the",
"DB",
"If",
"dimension",
"[",
"project_id",
"]",
"is",
"None",
"it",
"means",
"that",
"the",
"dimension",
"is",
"global",
"otherwise",
"is",
"property",
"of",
"a",
"pr... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L312-L337 |
hydraplatform/hydra-base | hydra_base/lib/units.py | update_dimension | def update_dimension(dimension,**kwargs):
"""
Update a dimension in the DB.
Raises and exception if the dimension does not exist.
The key is ALWAYS the name and the name itself is not modificable
"""
db_dimension = None
dimension = JSONObject(dimension)
try:
db_dimens... | python | def update_dimension(dimension,**kwargs):
"""
Update a dimension in the DB.
Raises and exception if the dimension does not exist.
The key is ALWAYS the name and the name itself is not modificable
"""
db_dimension = None
dimension = JSONObject(dimension)
try:
db_dimens... | [
"def",
"update_dimension",
"(",
"dimension",
",",
"*",
"*",
"kwargs",
")",
":",
"db_dimension",
"=",
"None",
"dimension",
"=",
"JSONObject",
"(",
"dimension",
")",
"try",
":",
"db_dimension",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")"... | Update a dimension in the DB.
Raises and exception if the dimension does not exist.
The key is ALWAYS the name and the name itself is not modificable | [
"Update",
"a",
"dimension",
"in",
"the",
"DB",
".",
"Raises",
"and",
"exception",
"if",
"the",
"dimension",
"does",
"not",
"exist",
".",
"The",
"key",
"is",
"ALWAYS",
"the",
"name",
"and",
"the",
"name",
"itself",
"is",
"not",
"modificable"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L340-L360 |
hydraplatform/hydra-base | hydra_base/lib/units.py | delete_dimension | def delete_dimension(dimension_id,**kwargs):
"""
Delete a dimension from the DB. Raises and exception if the dimension does not exist
"""
try:
dimension = db.DBSession.query(Dimension).filter(Dimension.id==dimension_id).one()
db.DBSession.query(Unit).filter(Unit.dimension_id==dimens... | python | def delete_dimension(dimension_id,**kwargs):
"""
Delete a dimension from the DB. Raises and exception if the dimension does not exist
"""
try:
dimension = db.DBSession.query(Dimension).filter(Dimension.id==dimension_id).one()
db.DBSession.query(Unit).filter(Unit.dimension_id==dimens... | [
"def",
"delete_dimension",
"(",
"dimension_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"dimension",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")",
".",
"filter",
"(",
"Dimension",
".",
"id",
"==",
"dimension_id",
")",
".",
"o... | Delete a dimension from the DB. Raises and exception if the dimension does not exist | [
"Delete",
"a",
"dimension",
"from",
"the",
"DB",
".",
"Raises",
"and",
"exception",
"if",
"the",
"dimension",
"does",
"not",
"exist"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L363-L376 |
hydraplatform/hydra-base | hydra_base/lib/units.py | bulk_add_dimensions | def bulk_add_dimensions(dimension_list, **kwargs):
"""
Save all the dimensions contained in the passed list.
"""
added_dimensions = []
for dimension in dimension_list:
added_dimensions.append(add_dimension(dimension, **kwargs))
return JSONObject({"dimensions": added_dimensions}) | python | def bulk_add_dimensions(dimension_list, **kwargs):
"""
Save all the dimensions contained in the passed list.
"""
added_dimensions = []
for dimension in dimension_list:
added_dimensions.append(add_dimension(dimension, **kwargs))
return JSONObject({"dimensions": added_dimensions}) | [
"def",
"bulk_add_dimensions",
"(",
"dimension_list",
",",
"*",
"*",
"kwargs",
")",
":",
"added_dimensions",
"=",
"[",
"]",
"for",
"dimension",
"in",
"dimension_list",
":",
"added_dimensions",
".",
"append",
"(",
"add_dimension",
"(",
"dimension",
",",
"*",
"*"... | Save all the dimensions contained in the passed list. | [
"Save",
"all",
"the",
"dimensions",
"contained",
"in",
"the",
"passed",
"list",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L380-L388 |
hydraplatform/hydra-base | hydra_base/lib/units.py | add_unit | def add_unit(unit,**kwargs):
"""
Add the unit defined into the object "unit" to the DB
If unit["project_id"] is None it means that the unit is global, otherwise is property of a project
If the unit exists emits an exception
A minimal example:
.. code-block:: python
... | python | def add_unit(unit,**kwargs):
"""
Add the unit defined into the object "unit" to the DB
If unit["project_id"] is None it means that the unit is global, otherwise is property of a project
If the unit exists emits an exception
A minimal example:
.. code-block:: python
... | [
"def",
"add_unit",
"(",
"unit",
",",
"*",
"*",
"kwargs",
")",
":",
"new_unit",
"=",
"Unit",
"(",
")",
"new_unit",
".",
"dimension_id",
"=",
"unit",
"[",
"\"dimension_id\"",
"]",
"new_unit",
".",
"name",
"=",
"unit",
"[",
"'name'",
"]",
"# Needed to unifo... | Add the unit defined into the object "unit" to the DB
If unit["project_id"] is None it means that the unit is global, otherwise is property of a project
If the unit exists emits an exception
A minimal example:
.. code-block:: python
new_unit = dict(
name ... | [
"Add",
"the",
"unit",
"defined",
"into",
"the",
"object",
"unit",
"to",
"the",
"DB",
"If",
"unit",
"[",
"project_id",
"]",
"is",
"None",
"it",
"means",
"that",
"the",
"unit",
"is",
"global",
"otherwise",
"is",
"property",
"of",
"a",
"project",
"If",
"t... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L397-L443 |
hydraplatform/hydra-base | hydra_base/lib/units.py | bulk_add_units | def bulk_add_units(unit_list, **kwargs):
"""
Save all the units contained in the passed list, with the name of their dimension.
"""
# for unit in unit_list:
# add_unit(unit, **kwargs)
added_units = []
for unit in unit_list:
added_units.append(add_unit(unit, **kwargs))
r... | python | def bulk_add_units(unit_list, **kwargs):
"""
Save all the units contained in the passed list, with the name of their dimension.
"""
# for unit in unit_list:
# add_unit(unit, **kwargs)
added_units = []
for unit in unit_list:
added_units.append(add_unit(unit, **kwargs))
r... | [
"def",
"bulk_add_units",
"(",
"unit_list",
",",
"*",
"*",
"kwargs",
")",
":",
"# for unit in unit_list:",
"# add_unit(unit, **kwargs)",
"added_units",
"=",
"[",
"]",
"for",
"unit",
"in",
"unit_list",
":",
"added_units",
".",
"append",
"(",
"add_unit",
"(",
"... | Save all the units contained in the passed list, with the name of their dimension. | [
"Save",
"all",
"the",
"units",
"contained",
"in",
"the",
"passed",
"list",
"with",
"the",
"name",
"of",
"their",
"dimension",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L446-L457 |
hydraplatform/hydra-base | hydra_base/lib/units.py | delete_unit | def delete_unit(unit_id, **kwargs):
"""
Delete a unit from the DB.
Raises and exception if the unit does not exist
"""
try:
db_unit = db.DBSession.query(Unit).filter(Unit.id==unit_id).one()
db.DBSession.delete(db_unit)
db.DBSession.flush()
return True
ex... | python | def delete_unit(unit_id, **kwargs):
"""
Delete a unit from the DB.
Raises and exception if the unit does not exist
"""
try:
db_unit = db.DBSession.query(Unit).filter(Unit.id==unit_id).one()
db.DBSession.delete(db_unit)
db.DBSession.flush()
return True
ex... | [
"def",
"delete_unit",
"(",
"unit_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"db_unit",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
".",
"filter",
"(",
"Unit",
".",
"id",
"==",
"unit_id",
")",
".",
"one",
"(",
")",
"db",
... | Delete a unit from the DB.
Raises and exception if the unit does not exist | [
"Delete",
"a",
"unit",
"from",
"the",
"DB",
".",
"Raises",
"and",
"exception",
"if",
"the",
"unit",
"does",
"not",
"exist"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L463-L476 |
hydraplatform/hydra-base | hydra_base/lib/units.py | update_unit | def update_unit(unit, **kwargs):
"""
Update a unit in the DB.
Raises and exception if the unit does not exist
"""
try:
db_unit = db.DBSession.query(Unit).join(Dimension).filter(Unit.id==unit["id"]).filter().one()
db_unit.name = unit["name"]
# Needed to uniform into... | python | def update_unit(unit, **kwargs):
"""
Update a unit in the DB.
Raises and exception if the unit does not exist
"""
try:
db_unit = db.DBSession.query(Unit).join(Dimension).filter(Unit.id==unit["id"]).filter().one()
db_unit.name = unit["name"]
# Needed to uniform into... | [
"def",
"update_unit",
"(",
"unit",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"db_unit",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
".",
"join",
"(",
"Dimension",
")",
".",
"filter",
"(",
"Unit",
".",
"id",
"==",
"unit",
"["... | Update a unit in the DB.
Raises and exception if the unit does not exist | [
"Update",
"a",
"unit",
"in",
"the",
"DB",
".",
"Raises",
"and",
"exception",
"if",
"the",
"unit",
"does",
"not",
"exist"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L480-L504 |
hydraplatform/hydra-base | hydra_base/lib/units.py | convert_dataset | def convert_dataset(dataset_id, target_unit_abbreviation,**kwargs):
"""
Convert a whole dataset (specified by 'dataset_id') to new unit ('target_unit_abbreviation').
Conversion ALWAYS creates a NEW dataset, so function returns the dataset ID of new dataset.
"""
ds_i = db.DBSession.query(Dat... | python | def convert_dataset(dataset_id, target_unit_abbreviation,**kwargs):
"""
Convert a whole dataset (specified by 'dataset_id') to new unit ('target_unit_abbreviation').
Conversion ALWAYS creates a NEW dataset, so function returns the dataset ID of new dataset.
"""
ds_i = db.DBSession.query(Dat... | [
"def",
"convert_dataset",
"(",
"dataset_id",
",",
"target_unit_abbreviation",
",",
"*",
"*",
"kwargs",
")",
":",
"ds_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dataset",
")",
".",
"filter",
"(",
"Dataset",
".",
"id",
"==",
"dataset_id",
")",
".... | Convert a whole dataset (specified by 'dataset_id') to new unit ('target_unit_abbreviation').
Conversion ALWAYS creates a NEW dataset, so function returns the dataset ID of new dataset. | [
"Convert",
"a",
"whole",
"dataset",
"(",
"specified",
"by",
"dataset_id",
")",
"to",
"new",
"unit",
"(",
"target_unit_abbreviation",
")",
".",
"Conversion",
"ALWAYS",
"creates",
"a",
"NEW",
"dataset",
"so",
"function",
"returns",
"the",
"dataset",
"ID",
"of",
... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L529-L583 |
hydraplatform/hydra-base | hydra_base/lib/units.py | validate_resource_attributes | def validate_resource_attributes(resource, attributes, template, check_unit=True, exact_match=False,**kwargs):
"""
Validate that the resource provided matches the template.
Only passes if the resource contains ONLY the attributes specified
in the template.
The template should take t... | python | def validate_resource_attributes(resource, attributes, template, check_unit=True, exact_match=False,**kwargs):
"""
Validate that the resource provided matches the template.
Only passes if the resource contains ONLY the attributes specified
in the template.
The template should take t... | [
"def",
"validate_resource_attributes",
"(",
"resource",
",",
"attributes",
",",
"template",
",",
"check_unit",
"=",
"True",
",",
"exact_match",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"errors",
"=",
"[",
"]",
"#is it a node or link?",
"res_type",
"=",... | Validate that the resource provided matches the template.
Only passes if the resource contains ONLY the attributes specified
in the template.
The template should take the form of a dictionary, as should the
resources.
*check_unit*: Makes sure that if a unit is specified in the ... | [
"Validate",
"that",
"the",
"resource",
"provided",
"matches",
"the",
"template",
".",
"Only",
"passes",
"if",
"the",
"resource",
"contains",
"ONLY",
"the",
"attributes",
"specified",
"in",
"the",
"template",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/units.py#L592-L717 |
multiformats/py-multibase | multibase/multibase.py | encode | def encode(encoding, data):
"""
Encodes the given data using the encoding that is specified
:param str encoding: encoding to use, should be one of the supported encoding
:param data: data to encode
:type data: str or bytes
:return: multibase encoded data
:rtype: bytes
:raises ValueError... | python | def encode(encoding, data):
"""
Encodes the given data using the encoding that is specified
:param str encoding: encoding to use, should be one of the supported encoding
:param data: data to encode
:type data: str or bytes
:return: multibase encoded data
:rtype: bytes
:raises ValueError... | [
"def",
"encode",
"(",
"encoding",
",",
"data",
")",
":",
"data",
"=",
"ensure_bytes",
"(",
"data",
",",
"'utf8'",
")",
"try",
":",
"return",
"ENCODINGS_LOOKUP",
"[",
"encoding",
"]",
".",
"code",
"+",
"ENCODINGS_LOOKUP",
"[",
"encoding",
"]",
".",
"conve... | Encodes the given data using the encoding that is specified
:param str encoding: encoding to use, should be one of the supported encoding
:param data: data to encode
:type data: str or bytes
:return: multibase encoded data
:rtype: bytes
:raises ValueError: if the encoding is not supported | [
"Encodes",
"the",
"given",
"data",
"using",
"the",
"encoding",
"that",
"is",
"specified"
] | train | https://github.com/multiformats/py-multibase/blob/8f435762b50a17f921c13b59eb0c7b9c52afc879/multibase/multibase.py#L32-L47 |
multiformats/py-multibase | multibase/multibase.py | get_codec | def get_codec(data):
"""
Returns the codec used to encode the given data
:param data: multibase encoded data
:type data: str or bytes
:return: the :py:obj:`multibase.Encoding` object for the data's codec
:raises ValueError: if the codec is not supported
"""
try:
key = ensure_byt... | python | def get_codec(data):
"""
Returns the codec used to encode the given data
:param data: multibase encoded data
:type data: str or bytes
:return: the :py:obj:`multibase.Encoding` object for the data's codec
:raises ValueError: if the codec is not supported
"""
try:
key = ensure_byt... | [
"def",
"get_codec",
"(",
"data",
")",
":",
"try",
":",
"key",
"=",
"ensure_bytes",
"(",
"data",
"[",
":",
"CODE_LENGTH",
"]",
",",
"'utf8'",
")",
"codec",
"=",
"ENCODINGS_LOOKUP",
"[",
"key",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
... | Returns the codec used to encode the given data
:param data: multibase encoded data
:type data: str or bytes
:return: the :py:obj:`multibase.Encoding` object for the data's codec
:raises ValueError: if the codec is not supported | [
"Returns",
"the",
"codec",
"used",
"to",
"encode",
"the",
"given",
"data"
] | train | https://github.com/multiformats/py-multibase/blob/8f435762b50a17f921c13b59eb0c7b9c52afc879/multibase/multibase.py#L50-L65 |
multiformats/py-multibase | multibase/multibase.py | decode | def decode(data):
"""
Decode the multibase decoded data
:param data: multibase encoded data
:type data: str or bytes
:return: decoded data
:rtype: str
:raises ValueError: if the data is not multibase encoded
"""
data = ensure_bytes(data, 'utf8')
codec = get_codec(data)
return... | python | def decode(data):
"""
Decode the multibase decoded data
:param data: multibase encoded data
:type data: str or bytes
:return: decoded data
:rtype: str
:raises ValueError: if the data is not multibase encoded
"""
data = ensure_bytes(data, 'utf8')
codec = get_codec(data)
return... | [
"def",
"decode",
"(",
"data",
")",
":",
"data",
"=",
"ensure_bytes",
"(",
"data",
",",
"'utf8'",
")",
"codec",
"=",
"get_codec",
"(",
"data",
")",
"return",
"codec",
".",
"converter",
".",
"decode",
"(",
"data",
"[",
"CODE_LENGTH",
":",
"]",
")"
] | Decode the multibase decoded data
:param data: multibase encoded data
:type data: str or bytes
:return: decoded data
:rtype: str
:raises ValueError: if the data is not multibase encoded | [
"Decode",
"the",
"multibase",
"decoded",
"data",
":",
"param",
"data",
":",
"multibase",
"encoded",
"data",
":",
"type",
"data",
":",
"str",
"or",
"bytes",
":",
"return",
":",
"decoded",
"data",
":",
"rtype",
":",
"str",
":",
"raises",
"ValueError",
":",... | train | https://github.com/multiformats/py-multibase/blob/8f435762b50a17f921c13b59eb0c7b9c52afc879/multibase/multibase.py#L84-L95 |
oceanprotocol/oceandb-bigchaindb-driver | oceandb_bigchaindb_driver/instance.py | ed25519_generate_key_pair_from_secret | def ed25519_generate_key_pair_from_secret(secret):
"""
Generate a new key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
A tuple of (private_key, public_key) encoded in base58.
"""
# if you want to do this correctly, use a key derivation function!
... | python | def ed25519_generate_key_pair_from_secret(secret):
"""
Generate a new key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
A tuple of (private_key, public_key) encoded in base58.
"""
# if you want to do this correctly, use a key derivation function!
... | [
"def",
"ed25519_generate_key_pair_from_secret",
"(",
"secret",
")",
":",
"# if you want to do this correctly, use a key derivation function!",
"if",
"not",
"isinstance",
"(",
"secret",
",",
"bytes",
")",
":",
"secret",
"=",
"secret",
".",
"encode",
"(",
")",
"hash_bytes... | Generate a new key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
A tuple of (private_key, public_key) encoded in base58. | [
"Generate",
"a",
"new",
"key",
"pair",
".",
"Args",
":",
"secret",
"(",
":",
"class",
":",
"string",
")",
":",
"A",
"secret",
"that",
"serves",
"as",
"a",
"seed",
"Returns",
":",
"A",
"tuple",
"of",
"(",
"private_key",
"public_key",
")",
"encoded",
"... | train | https://github.com/oceanprotocol/oceandb-bigchaindb-driver/blob/82315bcc9f7ba8b01beb08014bdeb541546c6671/oceandb_bigchaindb_driver/instance.py#L48-L69 |
oceanprotocol/oceandb-bigchaindb-driver | oceandb_bigchaindb_driver/instance.py | generate_key_pair | def generate_key_pair(secret=None):
"""Generates a cryptographic key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.cry... | python | def generate_key_pair(secret=None):
"""Generates a cryptographic key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.cry... | [
"def",
"generate_key_pair",
"(",
"secret",
"=",
"None",
")",
":",
"if",
"secret",
":",
"keypair_raw",
"=",
"ed25519_generate_key_pair_from_secret",
"(",
"secret",
")",
"return",
"CryptoKeypair",
"(",
"*",
"(",
"k",
".",
"decode",
"(",
")",
"for",
"k",
"in",
... | Generates a cryptographic key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
... | [
"Generates",
"a",
"cryptographic",
"key",
"pair",
".",
"Args",
":",
"secret",
"(",
":",
"class",
":",
"string",
")",
":",
"A",
"secret",
"that",
"serves",
"as",
"a",
"seed",
"Returns",
":",
":",
"class",
":",
"~bigchaindb",
".",
"common",
".",
"crypto"... | train | https://github.com/oceanprotocol/oceandb-bigchaindb-driver/blob/82315bcc9f7ba8b01beb08014bdeb541546c6671/oceandb_bigchaindb_driver/instance.py#L72-L87 |
monetate/ectou-metadata | ectou_metadata/service.py | _get_role_arn | def _get_role_arn():
"""
Return role arn from X-Role-ARN header,
lookup role arn from source IP,
or fall back to command line default.
"""
role_arn = bottle.request.headers.get('X-Role-ARN')
if not role_arn:
role_arn = _lookup_ip_role_arn(bottle.request.environ.get('REMOTE_ADDR'))
... | python | def _get_role_arn():
"""
Return role arn from X-Role-ARN header,
lookup role arn from source IP,
or fall back to command line default.
"""
role_arn = bottle.request.headers.get('X-Role-ARN')
if not role_arn:
role_arn = _lookup_ip_role_arn(bottle.request.environ.get('REMOTE_ADDR'))
... | [
"def",
"_get_role_arn",
"(",
")",
":",
"role_arn",
"=",
"bottle",
".",
"request",
".",
"headers",
".",
"get",
"(",
"'X-Role-ARN'",
")",
"if",
"not",
"role_arn",
":",
"role_arn",
"=",
"_lookup_ip_role_arn",
"(",
"bottle",
".",
"request",
".",
"environ",
"."... | Return role arn from X-Role-ARN header,
lookup role arn from source IP,
or fall back to command line default. | [
"Return",
"role",
"arn",
"from",
"X",
"-",
"Role",
"-",
"ARN",
"header",
"lookup",
"role",
"arn",
"from",
"source",
"IP",
"or",
"fall",
"back",
"to",
"command",
"line",
"default",
"."
] | train | https://github.com/monetate/ectou-metadata/blob/f5d57d086363321e6e4a1206f94c8f980971cb0c/ectou_metadata/service.py#L33-L44 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/mixin.py | DynamoDBMixin._on_dynamodb_exception | def _on_dynamodb_exception(self, error):
"""Dynamically handle DynamoDB exceptions, returning HTTP error
responses.
:param exceptions.DynamoDBException error:
"""
if isinstance(error, exceptions.ConditionalCheckFailedException):
raise web.HTTPError(409, reason='Cond... | python | def _on_dynamodb_exception(self, error):
"""Dynamically handle DynamoDB exceptions, returning HTTP error
responses.
:param exceptions.DynamoDBException error:
"""
if isinstance(error, exceptions.ConditionalCheckFailedException):
raise web.HTTPError(409, reason='Cond... | [
"def",
"_on_dynamodb_exception",
"(",
"self",
",",
"error",
")",
":",
"if",
"isinstance",
"(",
"error",
",",
"exceptions",
".",
"ConditionalCheckFailedException",
")",
":",
"raise",
"web",
".",
"HTTPError",
"(",
"409",
",",
"reason",
"=",
"'Condition Check Failu... | Dynamically handle DynamoDB exceptions, returning HTTP error
responses.
:param exceptions.DynamoDBException error: | [
"Dynamically",
"handle",
"DynamoDB",
"exceptions",
"returning",
"HTTP",
"error",
"responses",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/mixin.py#L39-L56 |
multiformats/py-multibase | multibase/converters.py | BaseByteStringConverter._chunk_with_padding | def _chunk_with_padding(self, iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# _chunk_with_padding('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue) | python | def _chunk_with_padding(self, iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# _chunk_with_padding('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue) | [
"def",
"_chunk_with_padding",
"(",
"self",
",",
"iterable",
",",
"n",
",",
"fillvalue",
"=",
"None",
")",
":",
"# _chunk_with_padding('ABCDEFG', 3, 'x') --> ABC DEF Gxx\"",
"args",
"=",
"[",
"iter",
"(",
"iterable",
")",
"]",
"*",
"n",
"return",
"zip_longest",
"... | Collect data into fixed-length chunks or blocks | [
"Collect",
"data",
"into",
"fixed",
"-",
"length",
"chunks",
"or",
"blocks"
] | train | https://github.com/multiformats/py-multibase/blob/8f435762b50a17f921c13b59eb0c7b9c52afc879/multibase/converters.py#L47-L51 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/utils.py | marshall | def marshall(values):
"""
Marshall a `dict` into something DynamoDB likes.
:param dict values: The values to marshall
:rtype: dict
:raises ValueError: if an unsupported type is encountered
Return the values in a nested dict structure that is required for
writing the values to DynamoDB.
... | python | def marshall(values):
"""
Marshall a `dict` into something DynamoDB likes.
:param dict values: The values to marshall
:rtype: dict
:raises ValueError: if an unsupported type is encountered
Return the values in a nested dict structure that is required for
writing the values to DynamoDB.
... | [
"def",
"marshall",
"(",
"values",
")",
":",
"serialized",
"=",
"{",
"}",
"for",
"key",
"in",
"values",
":",
"serialized",
"[",
"key",
"]",
"=",
"_marshall_value",
"(",
"values",
"[",
"key",
"]",
")",
"return",
"serialized"
] | Marshall a `dict` into something DynamoDB likes.
:param dict values: The values to marshall
:rtype: dict
:raises ValueError: if an unsupported type is encountered
Return the values in a nested dict structure that is required for
writing the values to DynamoDB. | [
"Marshall",
"a",
"dict",
"into",
"something",
"DynamoDB",
"likes",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/utils.py#L40-L55 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/utils.py | unmarshall | def unmarshall(values):
"""
Transform a response payload from DynamoDB to a native dict
:param dict values: The response payload from DynamoDB
:rtype: dict
:raises ValueError: if an unsupported type code is encountered
"""
unmarshalled = {}
for key in values:
unmarshalled[key] ... | python | def unmarshall(values):
"""
Transform a response payload from DynamoDB to a native dict
:param dict values: The response payload from DynamoDB
:rtype: dict
:raises ValueError: if an unsupported type code is encountered
"""
unmarshalled = {}
for key in values:
unmarshalled[key] ... | [
"def",
"unmarshall",
"(",
"values",
")",
":",
"unmarshalled",
"=",
"{",
"}",
"for",
"key",
"in",
"values",
":",
"unmarshalled",
"[",
"key",
"]",
"=",
"_unmarshall_dict",
"(",
"values",
"[",
"key",
"]",
")",
"return",
"unmarshalled"
] | Transform a response payload from DynamoDB to a native dict
:param dict values: The response payload from DynamoDB
:rtype: dict
:raises ValueError: if an unsupported type code is encountered | [
"Transform",
"a",
"response",
"payload",
"from",
"DynamoDB",
"to",
"a",
"native",
"dict"
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/utils.py#L58-L70 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/utils.py | _marshall_value | def _marshall_value(value):
"""
Recursively transform `value` into an AttributeValue `dict`
:param mixed value: The value to encode
:rtype: dict
:raises ValueError: for unsupported types
Return the value as dict indicating the data type and transform or
recursively process the value if req... | python | def _marshall_value(value):
"""
Recursively transform `value` into an AttributeValue `dict`
:param mixed value: The value to encode
:rtype: dict
:raises ValueError: for unsupported types
Return the value as dict indicating the data type and transform or
recursively process the value if req... | [
"def",
"_marshall_value",
"(",
"value",
")",
":",
"if",
"PYTHON3",
"and",
"isinstance",
"(",
"value",
",",
"bytes",
")",
":",
"return",
"{",
"'B'",
":",
"base64",
".",
"b64encode",
"(",
"value",
")",
".",
"decode",
"(",
"'ascii'",
")",
"}",
"elif",
"... | Recursively transform `value` into an AttributeValue `dict`
:param mixed value: The value to encode
:rtype: dict
:raises ValueError: for unsupported types
Return the value as dict indicating the data type and transform or
recursively process the value if required. | [
"Recursively",
"transform",
"value",
"into",
"an",
"AttributeValue",
"dict"
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/utils.py#L83-L134 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/utils.py | _unmarshall_dict | def _unmarshall_dict(value):
"""Unmarshall a single dict value from a row that was returned from
DynamoDB, returning the value as a normal Python dict.
:param dict value: The value to unmarshall
:rtype: mixed
:raises ValueError: if an unsupported type code is encountered
"""
key = list(val... | python | def _unmarshall_dict(value):
"""Unmarshall a single dict value from a row that was returned from
DynamoDB, returning the value as a normal Python dict.
:param dict value: The value to unmarshall
:rtype: mixed
:raises ValueError: if an unsupported type code is encountered
"""
key = list(val... | [
"def",
"_unmarshall_dict",
"(",
"value",
")",
":",
"key",
"=",
"list",
"(",
"value",
".",
"keys",
"(",
")",
")",
".",
"pop",
"(",
")",
"if",
"key",
"==",
"'B'",
":",
"return",
"base64",
".",
"b64decode",
"(",
"value",
"[",
"key",
"]",
".",
"encod... | Unmarshall a single dict value from a row that was returned from
DynamoDB, returning the value as a normal Python dict.
:param dict value: The value to unmarshall
:rtype: mixed
:raises ValueError: if an unsupported type code is encountered | [
"Unmarshall",
"a",
"single",
"dict",
"value",
"from",
"a",
"row",
"that",
"was",
"returned",
"from",
"DynamoDB",
"returning",
"the",
"value",
"as",
"a",
"normal",
"Python",
"dict",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/utils.py#L148-L179 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/client.py | _unwrap_result | def _unwrap_result(action, result):
"""Unwrap a request response and return only the response data.
:param str action: The action name
:param result: The result of the action
:type: result: list or dict
:rtype: dict | None
"""
if not result:
return
elif action in {'DeleteItem',... | python | def _unwrap_result(action, result):
"""Unwrap a request response and return only the response data.
:param str action: The action name
:param result: The result of the action
:type: result: list or dict
:rtype: dict | None
"""
if not result:
return
elif action in {'DeleteItem',... | [
"def",
"_unwrap_result",
"(",
"action",
",",
"result",
")",
":",
"if",
"not",
"result",
":",
"return",
"elif",
"action",
"in",
"{",
"'DeleteItem'",
",",
"'PutItem'",
",",
"'UpdateItem'",
"}",
":",
"return",
"_unwrap_delete_put_update_item",
"(",
"result",
")",... | Unwrap a request response and return only the response data.
:param str action: The action name
:param result: The result of the action
:type: result: list or dict
:rtype: dict | None | [
"Unwrap",
"a",
"request",
"response",
"and",
"return",
"only",
"the",
"response",
"data",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/client.py#L943-L964 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/client.py | Client.list_tables | def list_tables(self, exclusive_start_table_name=None, limit=None):
"""
Invoke the `ListTables`_ function.
Returns an array of table names associated with the current account
and endpoint. The output from *ListTables* is paginated, with each page
returning a maximum of ``100`` t... | python | def list_tables(self, exclusive_start_table_name=None, limit=None):
"""
Invoke the `ListTables`_ function.
Returns an array of table names associated with the current account
and endpoint. The output from *ListTables* is paginated, with each page
returning a maximum of ``100`` t... | [
"def",
"list_tables",
"(",
"self",
",",
"exclusive_start_table_name",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"}",
"if",
"exclusive_start_table_name",
":",
"payload",
"[",
"'ExclusiveStartTableName'",
"]",
"=",
"exclusive_start_table... | Invoke the `ListTables`_ function.
Returns an array of table names associated with the current account
and endpoint. The output from *ListTables* is paginated, with each page
returning a maximum of ``100`` table names.
:param str exclusive_start_table_name: The first table name that th... | [
"Invoke",
"the",
"ListTables",
"_",
"function",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/client.py#L176-L200 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/client.py | Client.put_item | def put_item(self, table_name, item,
condition_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
return_consumed_capacity=None,
return_item_collection_metrics=None,
return_values=None)... | python | def put_item(self, table_name, item,
condition_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
return_consumed_capacity=None,
return_item_collection_metrics=None,
return_values=None)... | [
"def",
"put_item",
"(",
"self",
",",
"table_name",
",",
"item",
",",
"condition_expression",
"=",
"None",
",",
"expression_attribute_names",
"=",
"None",
",",
"expression_attribute_values",
"=",
"None",
",",
"return_consumed_capacity",
"=",
"None",
",",
"return_item... | Invoke the `PutItem`_ function, creating a new item, or replaces an
old item with a new item. If an item that has the same primary key as
the new item already exists in the specified table, the new item
completely replaces the existing item. You can perform a conditional
put operation (a... | [
"Invoke",
"the",
"PutItem",
"_",
"function",
"creating",
"a",
"new",
"item",
"or",
"replaces",
"an",
"old",
"item",
"with",
"a",
"new",
"item",
".",
"If",
"an",
"item",
"that",
"has",
"the",
"same",
"primary",
"key",
"as",
"the",
"new",
"item",
"alread... | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/client.py#L202-L276 |
sprockets/sprockets-dynamodb | sprockets_dynamodb/client.py | Client.get_item | def get_item(self, table_name, key_dict,
consistent_read=False,
expression_attribute_names=None,
projection_expression=None,
return_consumed_capacity=None):
"""
Invoke the `GetItem`_ function.
:param str table_name: table to re... | python | def get_item(self, table_name, key_dict,
consistent_read=False,
expression_attribute_names=None,
projection_expression=None,
return_consumed_capacity=None):
"""
Invoke the `GetItem`_ function.
:param str table_name: table to re... | [
"def",
"get_item",
"(",
"self",
",",
"table_name",
",",
"key_dict",
",",
"consistent_read",
"=",
"False",
",",
"expression_attribute_names",
"=",
"None",
",",
"projection_expression",
"=",
"None",
",",
"return_consumed_capacity",
"=",
"None",
")",
":",
"payload",
... | Invoke the `GetItem`_ function.
:param str table_name: table to retrieve the item from
:param dict key_dict: key to use for retrieval. This will
be marshalled for you so a native :class:`dict` works.
:param bool consistent_read: Determines the read consistency model: If
... | [
"Invoke",
"the",
"GetItem",
"_",
"function",
"."
] | train | https://github.com/sprockets/sprockets-dynamodb/blob/2e202bcb01f23f828f91299599311007054de4aa/sprockets_dynamodb/client.py#L278-L331 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.