repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
SpockBotMC/SpockBot | spockbot/vector.py | CartesianVector.dist_sq | def dist_sq(self, other=None):
""" For fast length comparison """
v = self - other if other else self
return sum(map(lambda a: a * a, v)) | python | def dist_sq(self, other=None):
""" For fast length comparison """
v = self - other if other else self
return sum(map(lambda a: a * a, v)) | [
"def",
"dist_sq",
"(",
"self",
",",
"other",
"=",
"None",
")",
":",
"v",
"=",
"self",
"-",
"other",
"if",
"other",
"else",
"self",
"return",
"sum",
"(",
"map",
"(",
"lambda",
"a",
":",
"a",
"*",
"a",
",",
"v",
")",
")"
] | For fast length comparison | [
"For",
"fast",
"length",
"comparison"
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/vector.py#L119-L122 | train | 59,400 |
SpockBotMC/SpockBot | spockbot/vector.py | Vector3.yaw_pitch | def yaw_pitch(self):
"""
Calculate the yaw and pitch of this vector
"""
if not self:
return YawPitch(0, 0)
ground_distance = math.sqrt(self.x ** 2 + self.z ** 2)
if ground_distance:
alpha1 = -math.asin(self.x / ground_distance) / math.pi * 180
... | python | def yaw_pitch(self):
"""
Calculate the yaw and pitch of this vector
"""
if not self:
return YawPitch(0, 0)
ground_distance = math.sqrt(self.x ** 2 + self.z ** 2)
if ground_distance:
alpha1 = -math.asin(self.x / ground_distance) / math.pi * 180
... | [
"def",
"yaw_pitch",
"(",
"self",
")",
":",
"if",
"not",
"self",
":",
"return",
"YawPitch",
"(",
"0",
",",
"0",
")",
"ground_distance",
"=",
"math",
".",
"sqrt",
"(",
"self",
".",
"x",
"**",
"2",
"+",
"self",
".",
"z",
"**",
"2",
")",
"if",
"gro... | Calculate the yaw and pitch of this vector | [
"Calculate",
"the",
"yaw",
"and",
"pitch",
"of",
"this",
"vector"
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/vector.py#L204-L228 | train | 59,401 |
SpockBotMC/SpockBot | spockbot/mcdata/windows.py | make_slot_check | def make_slot_check(wanted):
"""
Creates and returns a function that takes a slot
and checks if it matches the wanted item.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
"""
if isinstance(wanted, types.FunctionType):
return wanted # just forward the slot ... | python | def make_slot_check(wanted):
"""
Creates and returns a function that takes a slot
and checks if it matches the wanted item.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
"""
if isinstance(wanted, types.FunctionType):
return wanted # just forward the slot ... | [
"def",
"make_slot_check",
"(",
"wanted",
")",
":",
"if",
"isinstance",
"(",
"wanted",
",",
"types",
".",
"FunctionType",
")",
":",
"return",
"wanted",
"# just forward the slot check function",
"if",
"isinstance",
"(",
"wanted",
",",
"int",
")",
":",
"item",
",... | Creates and returns a function that takes a slot
and checks if it matches the wanted item.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata) | [
"Creates",
"and",
"returns",
"a",
"function",
"that",
"takes",
"a",
"slot",
"and",
"checks",
"if",
"it",
"matches",
"the",
"wanted",
"item",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcdata/windows.py#L13-L39 | train | 59,402 |
SpockBotMC/SpockBot | spockbot/mcdata/windows.py | _make_window | def _make_window(window_dict):
"""
Creates a new class for that window and registers it at this module.
"""
cls_name = '%sWindow' % camel_case(str(window_dict['name']))
bases = (Window,)
attrs = {
'__module__': sys.modules[__name__],
'name': str(window_dict['name']),
'inv... | python | def _make_window(window_dict):
"""
Creates a new class for that window and registers it at this module.
"""
cls_name = '%sWindow' % camel_case(str(window_dict['name']))
bases = (Window,)
attrs = {
'__module__': sys.modules[__name__],
'name': str(window_dict['name']),
'inv... | [
"def",
"_make_window",
"(",
"window_dict",
")",
":",
"cls_name",
"=",
"'%sWindow'",
"%",
"camel_case",
"(",
"str",
"(",
"window_dict",
"[",
"'name'",
"]",
")",
")",
"bases",
"=",
"(",
"Window",
",",
")",
"attrs",
"=",
"{",
"'__module__'",
":",
"sys",
"... | Creates a new class for that window and registers it at this module. | [
"Creates",
"a",
"new",
"class",
"for",
"that",
"window",
"and",
"registers",
"it",
"at",
"this",
"module",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcdata/windows.py#L330-L371 | train | 59,403 |
SpockBotMC/SpockBot | spockbot/mcdata/windows.py | Slot.get_dict | def get_dict(self):
""" Formats the slot for network packing. """
data = {'id': self.item_id}
if self.item_id != constants.INV_ITEMID_EMPTY:
data['damage'] = self.damage
data['amount'] = self.amount
if self.nbt is not None:
data['enchants'] = s... | python | def get_dict(self):
""" Formats the slot for network packing. """
data = {'id': self.item_id}
if self.item_id != constants.INV_ITEMID_EMPTY:
data['damage'] = self.damage
data['amount'] = self.amount
if self.nbt is not None:
data['enchants'] = s... | [
"def",
"get_dict",
"(",
"self",
")",
":",
"data",
"=",
"{",
"'id'",
":",
"self",
".",
"item_id",
"}",
"if",
"self",
".",
"item_id",
"!=",
"constants",
".",
"INV_ITEMID_EMPTY",
":",
"data",
"[",
"'damage'",
"]",
"=",
"self",
".",
"damage",
"data",
"["... | Formats the slot for network packing. | [
"Formats",
"the",
"slot",
"for",
"network",
"packing",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcdata/windows.py#L75-L83 | train | 59,404 |
SpockBotMC/SpockBot | spockbot/mcdata/windows.py | BaseClick.on_success | def on_success(self, inv_plugin, emit_set_slot):
"""
Called when the click was successful
and should be applied to the inventory.
Args:
inv_plugin (InventoryPlugin): inventory plugin instance
emit_set_slot (func): function to signal a slot change,
... | python | def on_success(self, inv_plugin, emit_set_slot):
"""
Called when the click was successful
and should be applied to the inventory.
Args:
inv_plugin (InventoryPlugin): inventory plugin instance
emit_set_slot (func): function to signal a slot change,
... | [
"def",
"on_success",
"(",
"self",
",",
"inv_plugin",
",",
"emit_set_slot",
")",
":",
"self",
".",
"dirty",
"=",
"set",
"(",
")",
"self",
".",
"apply",
"(",
"inv_plugin",
")",
"for",
"changed_slot",
"in",
"self",
".",
"dirty",
":",
"emit_set_slot",
"(",
... | Called when the click was successful
and should be applied to the inventory.
Args:
inv_plugin (InventoryPlugin): inventory plugin instance
emit_set_slot (func): function to signal a slot change,
should be InventoryPlugin().emit_set_slot | [
"Called",
"when",
"the",
"click",
"was",
"successful",
"and",
"should",
"be",
"applied",
"to",
"the",
"inventory",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcdata/windows.py#L141-L154 | train | 59,405 |
SpockBotMC/SpockBot | spockbot/mcp/yggdrasil.py | YggdrasilCore.authenticate | def authenticate(self):
"""
Generate an access token using an username and password. Any existing
client token is invalidated if not provided.
Returns:
dict: Response or error dict
"""
endpoint = '/authenticate'
payload = {
'agent': {
... | python | def authenticate(self):
"""
Generate an access token using an username and password. Any existing
client token is invalidated if not provided.
Returns:
dict: Response or error dict
"""
endpoint = '/authenticate'
payload = {
'agent': {
... | [
"def",
"authenticate",
"(",
"self",
")",
":",
"endpoint",
"=",
"'/authenticate'",
"payload",
"=",
"{",
"'agent'",
":",
"{",
"'name'",
":",
"'Minecraft'",
",",
"'version'",
":",
"self",
".",
"ygg_version",
",",
"}",
",",
"'username'",
":",
"self",
".",
"u... | Generate an access token using an username and password. Any existing
client token is invalidated if not provided.
Returns:
dict: Response or error dict | [
"Generate",
"an",
"access",
"token",
"using",
"an",
"username",
"and",
"password",
".",
"Any",
"existing",
"client",
"token",
"is",
"invalidated",
"if",
"not",
"provided",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcp/yggdrasil.py#L50-L76 | train | 59,406 |
SpockBotMC/SpockBot | spockbot/mcp/yggdrasil.py | YggdrasilCore.validate | def validate(self):
"""
Check if an access token is valid
Returns:
dict: Empty or error dict
"""
endpoint = '/validate'
payload = dict(accessToken=self.access_token)
rep = self._ygg_req(endpoint, payload)
return not bool(rep) | python | def validate(self):
"""
Check if an access token is valid
Returns:
dict: Empty or error dict
"""
endpoint = '/validate'
payload = dict(accessToken=self.access_token)
rep = self._ygg_req(endpoint, payload)
return not bool(rep) | [
"def",
"validate",
"(",
"self",
")",
":",
"endpoint",
"=",
"'/validate'",
"payload",
"=",
"dict",
"(",
"accessToken",
"=",
"self",
".",
"access_token",
")",
"rep",
"=",
"self",
".",
"_ygg_req",
"(",
"endpoint",
",",
"payload",
")",
"return",
"not",
"bool... | Check if an access token is valid
Returns:
dict: Empty or error dict | [
"Check",
"if",
"an",
"access",
"token",
"is",
"valid"
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcp/yggdrasil.py#L143-L154 | train | 59,407 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.total_stored | def total_stored(self, wanted, slots=None):
"""
Calculates the total number of items of that type
in the current window or given slot range.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
"""
if slots is None:
slots = self.wi... | python | def total_stored(self, wanted, slots=None):
"""
Calculates the total number of items of that type
in the current window or given slot range.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
"""
if slots is None:
slots = self.wi... | [
"def",
"total_stored",
"(",
"self",
",",
"wanted",
",",
"slots",
"=",
"None",
")",
":",
"if",
"slots",
"is",
"None",
":",
"slots",
"=",
"self",
".",
"window",
".",
"slots",
"wanted",
"=",
"make_slot_check",
"(",
"wanted",
")",
"return",
"sum",
"(",
"... | Calculates the total number of items of that type
in the current window or given slot range.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata) | [
"Calculates",
"the",
"total",
"number",
"of",
"items",
"of",
"that",
"type",
"in",
"the",
"current",
"window",
"or",
"given",
"slot",
"range",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L24-L35 | train | 59,408 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.find_slot | def find_slot(self, wanted, slots=None):
"""
Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
Returns:
Optional[Slot]: The fi... | python | def find_slot(self, wanted, slots=None):
"""
Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
Returns:
Optional[Slot]: The fi... | [
"def",
"find_slot",
"(",
"self",
",",
"wanted",
",",
"slots",
"=",
"None",
")",
":",
"for",
"slot",
"in",
"self",
".",
"find_slots",
"(",
"wanted",
",",
"slots",
")",
":",
"return",
"slot",
"return",
"None"
] | Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
Returns:
Optional[Slot]: The first slot containing the item
or N... | [
"Searches",
"the",
"given",
"slots",
"or",
"if",
"not",
"given",
"active",
"hotbar",
"slot",
"hotbar",
"inventory",
"open",
"window",
"in",
"this",
"order",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L37-L51 | train | 59,409 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.find_slots | def find_slots(self, wanted, slots=None):
"""
Yields all slots containing the item.
Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
... | python | def find_slots(self, wanted, slots=None):
"""
Yields all slots containing the item.
Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)
... | [
"def",
"find_slots",
"(",
"self",
",",
"wanted",
",",
"slots",
"=",
"None",
")",
":",
"if",
"slots",
"is",
"None",
":",
"slots",
"=",
"self",
".",
"inv_slots_preferred",
"+",
"self",
".",
"window",
".",
"window_slots",
"wanted",
"=",
"make_slot_check",
"... | Yields all slots containing the item.
Searches the given slots or, if not given,
active hotbar slot, hotbar, inventory, open window in this order.
Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata) | [
"Yields",
"all",
"slots",
"containing",
"the",
"item",
".",
"Searches",
"the",
"given",
"slots",
"or",
"if",
"not",
"given",
"active",
"hotbar",
"slot",
"hotbar",
"inventory",
"open",
"window",
"in",
"this",
"order",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L53-L68 | train | 59,410 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.click_slot | def click_slot(self, slot, right=False):
"""
Left-click or right-click the slot.
Args:
slot (Slot): The clicked slot. Can be ``Slot`` instance or integer.
Set to ``inventory.cursor_slot``
for clicking outside the window.
"""
... | python | def click_slot(self, slot, right=False):
"""
Left-click or right-click the slot.
Args:
slot (Slot): The clicked slot. Can be ``Slot`` instance or integer.
Set to ``inventory.cursor_slot``
for clicking outside the window.
"""
... | [
"def",
"click_slot",
"(",
"self",
",",
"slot",
",",
"right",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"slot",
",",
"int",
")",
":",
"slot",
"=",
"self",
".",
"window",
".",
"slots",
"[",
"slot",
"]",
"button",
"=",
"constants",
".",
"INV_BU... | Left-click or right-click the slot.
Args:
slot (Slot): The clicked slot. Can be ``Slot`` instance or integer.
Set to ``inventory.cursor_slot``
for clicking outside the window. | [
"Left",
"-",
"click",
"or",
"right",
"-",
"click",
"the",
"slot",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L83-L96 | train | 59,411 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.drop_slot | def drop_slot(self, slot=None, drop_stack=False):
"""
Drop one or all items of the slot.
Does not wait for confirmation from the server. If you want that,
use a ``Task`` and ``yield inventory.async.drop_slot()`` instead.
If ``slot`` is None, drops the ``cursor_slot`` or, if tha... | python | def drop_slot(self, slot=None, drop_stack=False):
"""
Drop one or all items of the slot.
Does not wait for confirmation from the server. If you want that,
use a ``Task`` and ``yield inventory.async.drop_slot()`` instead.
If ``slot`` is None, drops the ``cursor_slot`` or, if tha... | [
"def",
"drop_slot",
"(",
"self",
",",
"slot",
"=",
"None",
",",
"drop_stack",
"=",
"False",
")",
":",
"if",
"slot",
"is",
"None",
":",
"if",
"self",
".",
"cursor_slot",
".",
"is_empty",
":",
"slot",
"=",
"self",
".",
"active_slot",
"else",
":",
"slot... | Drop one or all items of the slot.
Does not wait for confirmation from the server. If you want that,
use a ``Task`` and ``yield inventory.async.drop_slot()`` instead.
If ``slot`` is None, drops the ``cursor_slot`` or, if that's empty,
the currently held item (``active_slot``).
... | [
"Drop",
"one",
"or",
"all",
"items",
"of",
"the",
"slot",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L98-L125 | train | 59,412 |
SpockBotMC/SpockBot | spockbot/plugins/helpers/inventory.py | InventoryCore.inv_slots_preferred | def inv_slots_preferred(self):
"""
List of all available inventory slots in the preferred search order.
Does not include the additional slots from the open window.
1. active slot
2. remainder of the hotbar
3. remainder of the persistent inventory
"""
slot... | python | def inv_slots_preferred(self):
"""
List of all available inventory slots in the preferred search order.
Does not include the additional slots from the open window.
1. active slot
2. remainder of the hotbar
3. remainder of the persistent inventory
"""
slot... | [
"def",
"inv_slots_preferred",
"(",
"self",
")",
":",
"slots",
"=",
"[",
"self",
".",
"active_slot",
"]",
"slots",
".",
"extend",
"(",
"slot",
"for",
"slot",
"in",
"self",
".",
"window",
".",
"hotbar_slots",
"if",
"slot",
"!=",
"self",
".",
"active_slot",... | List of all available inventory slots in the preferred search order.
Does not include the additional slots from the open window.
1. active slot
2. remainder of the hotbar
3. remainder of the persistent inventory | [
"List",
"of",
"all",
"available",
"inventory",
"slots",
"in",
"the",
"preferred",
"search",
"order",
".",
"Does",
"not",
"include",
"the",
"additional",
"slots",
"from",
"the",
"open",
"window",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/helpers/inventory.py#L145-L158 | train | 59,413 |
SpockBotMC/SpockBot | spockbot/plugins/tools/smpmap.py | Dimension.get_block_entity_data | def get_block_entity_data(self, pos_or_x, y=None, z=None):
"""
Access block entity data.
Returns:
BlockEntityData subclass instance or
None if no block entity data is stored for that location.
"""
if None not in (y, z): # x y z supplied
pos_o... | python | def get_block_entity_data(self, pos_or_x, y=None, z=None):
"""
Access block entity data.
Returns:
BlockEntityData subclass instance or
None if no block entity data is stored for that location.
"""
if None not in (y, z): # x y z supplied
pos_o... | [
"def",
"get_block_entity_data",
"(",
"self",
",",
"pos_or_x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
")",
":",
"if",
"None",
"not",
"in",
"(",
"y",
",",
"z",
")",
":",
"# x y z supplied",
"pos_or_x",
"=",
"pos_or_x",
",",
"y",
",",
"z",
"coo... | Access block entity data.
Returns:
BlockEntityData subclass instance or
None if no block entity data is stored for that location. | [
"Access",
"block",
"entity",
"data",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/tools/smpmap.py#L302-L313 | train | 59,414 |
SpockBotMC/SpockBot | spockbot/plugins/tools/smpmap.py | Dimension.set_block_entity_data | def set_block_entity_data(self, pos_or_x, y=None, z=None, data=None):
"""
Update block entity data.
Returns:
Old data if block entity data was already stored for that location,
None otherwise.
"""
if None not in (y, z): # x y z supplied
pos_o... | python | def set_block_entity_data(self, pos_or_x, y=None, z=None, data=None):
"""
Update block entity data.
Returns:
Old data if block entity data was already stored for that location,
None otherwise.
"""
if None not in (y, z): # x y z supplied
pos_o... | [
"def",
"set_block_entity_data",
"(",
"self",
",",
"pos_or_x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
",",
"data",
"=",
"None",
")",
":",
"if",
"None",
"not",
"in",
"(",
"y",
",",
"z",
")",
":",
"# x y z supplied",
"pos_or_x",
"=",
"pos_or_x",
... | Update block entity data.
Returns:
Old data if block entity data was already stored for that location,
None otherwise. | [
"Update",
"block",
"entity",
"data",
"."
] | f89911551f18357720034fbaa52837a0d09f66ea | https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/tools/smpmap.py#L315-L328 | train | 59,415 |
mattrobenolt/python-sourcemap | sourcemap/decoder.py | SourceMapDecoder.parse_vlq | def parse_vlq(self, segment):
"""
Parse a string of VLQ-encoded data.
Returns:
a list of integers.
"""
values = []
cur, shift = 0, 0
for c in segment:
val = B64[ord(c)]
# Each character is 6 bits:
# 5 of value and t... | python | def parse_vlq(self, segment):
"""
Parse a string of VLQ-encoded data.
Returns:
a list of integers.
"""
values = []
cur, shift = 0, 0
for c in segment:
val = B64[ord(c)]
# Each character is 6 bits:
# 5 of value and t... | [
"def",
"parse_vlq",
"(",
"self",
",",
"segment",
")",
":",
"values",
"=",
"[",
"]",
"cur",
",",
"shift",
"=",
"0",
",",
"0",
"for",
"c",
"in",
"segment",
":",
"val",
"=",
"B64",
"[",
"ord",
"(",
"c",
")",
"]",
"# Each character is 6 bits:",
"# 5 of... | Parse a string of VLQ-encoded data.
Returns:
a list of integers. | [
"Parse",
"a",
"string",
"of",
"VLQ",
"-",
"encoded",
"data",
"."
] | 8d6969a3ce2c6b139c6e81927beed58ae67e840b | https://github.com/mattrobenolt/python-sourcemap/blob/8d6969a3ce2c6b139c6e81927beed58ae67e840b/sourcemap/decoder.py#L33-L63 | train | 59,416 |
mattrobenolt/python-sourcemap | sourcemap/decoder.py | SourceMapDecoder.decode | def decode(self, source):
"""Decode a source map object into a SourceMapIndex.
The index is keyed on (dst_line, dst_column) for lookups,
and a per row index is kept to help calculate which Token to retrieve.
For example:
A minified source file has two rows and two tokens pe... | python | def decode(self, source):
"""Decode a source map object into a SourceMapIndex.
The index is keyed on (dst_line, dst_column) for lookups,
and a per row index is kept to help calculate which Token to retrieve.
For example:
A minified source file has two rows and two tokens pe... | [
"def",
"decode",
"(",
"self",
",",
"source",
")",
":",
"# According to spec (https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.h7yy76c5il9v)",
"# A SouceMap may be prepended with \")]}'\" to cause a Javascript error.",
"# If the file starts with that ... | Decode a source map object into a SourceMapIndex.
The index is keyed on (dst_line, dst_column) for lookups,
and a per row index is kept to help calculate which Token to retrieve.
For example:
A minified source file has two rows and two tokens per row.
# All parsed toke... | [
"Decode",
"a",
"source",
"map",
"object",
"into",
"a",
"SourceMapIndex",
"."
] | 8d6969a3ce2c6b139c6e81927beed58ae67e840b | https://github.com/mattrobenolt/python-sourcemap/blob/8d6969a3ce2c6b139c6e81927beed58ae67e840b/sourcemap/decoder.py#L65-L195 | train | 59,417 |
mattrobenolt/python-sourcemap | sourcemap/__init__.py | discover | def discover(source):
"Given a JavaScript file, find the sourceMappingURL line"
source = source.splitlines()
# Source maps are only going to exist at either the top or bottom of the document.
# Technically, there isn't anything indicating *where* it should exist, so we
# are generous and assume it's... | python | def discover(source):
"Given a JavaScript file, find the sourceMappingURL line"
source = source.splitlines()
# Source maps are only going to exist at either the top or bottom of the document.
# Technically, there isn't anything indicating *where* it should exist, so we
# are generous and assume it's... | [
"def",
"discover",
"(",
"source",
")",
":",
"source",
"=",
"source",
".",
"splitlines",
"(",
")",
"# Source maps are only going to exist at either the top or bottom of the document.",
"# Technically, there isn't anything indicating *where* it should exist, so we",
"# are generous and a... | Given a JavaScript file, find the sourceMappingURL line | [
"Given",
"a",
"JavaScript",
"file",
"find",
"the",
"sourceMappingURL",
"line"
] | 8d6969a3ce2c6b139c6e81927beed58ae67e840b | https://github.com/mattrobenolt/python-sourcemap/blob/8d6969a3ce2c6b139c6e81927beed58ae67e840b/sourcemap/__init__.py#L25-L43 | train | 59,418 |
cournape/audiolab | pavement.py | clean | def clean():
"""Remove build, dist, egg-info garbage."""
d = ['build', 'dist', 'scikits.audiolab.egg-info', HTML_DESTDIR,
PDF_DESTDIR]
for i in d:
paver.path.path(i).rmtree()
(paver.path.path('docs') / options.sphinx.builddir).rmtree() | python | def clean():
"""Remove build, dist, egg-info garbage."""
d = ['build', 'dist', 'scikits.audiolab.egg-info', HTML_DESTDIR,
PDF_DESTDIR]
for i in d:
paver.path.path(i).rmtree()
(paver.path.path('docs') / options.sphinx.builddir).rmtree() | [
"def",
"clean",
"(",
")",
":",
"d",
"=",
"[",
"'build'",
",",
"'dist'",
",",
"'scikits.audiolab.egg-info'",
",",
"HTML_DESTDIR",
",",
"PDF_DESTDIR",
"]",
"for",
"i",
"in",
"d",
":",
"paver",
".",
"path",
".",
"path",
"(",
"i",
")",
".",
"rmtree",
"("... | Remove build, dist, egg-info garbage. | [
"Remove",
"build",
"dist",
"egg",
"-",
"info",
"garbage",
"."
] | e4918832c1e52b56428c5f3535ddeb9d9daff9ac | https://github.com/cournape/audiolab/blob/e4918832c1e52b56428c5f3535ddeb9d9daff9ac/pavement.py#L96-L103 | train | 59,419 |
linkedin/pyexchange | pyexchange/base/calendar.py | BaseExchangeCalendarEvent.add_attendees | def add_attendees(self, attendees, required=True):
"""
Adds new attendees to the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
new_attendees = self._build_resource_dictionary(attendees, required=required)
for email in new_attendees:
s... | python | def add_attendees(self, attendees, required=True):
"""
Adds new attendees to the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
new_attendees = self._build_resource_dictionary(attendees, required=required)
for email in new_attendees:
s... | [
"def",
"add_attendees",
"(",
"self",
",",
"attendees",
",",
"required",
"=",
"True",
")",
":",
"new_attendees",
"=",
"self",
".",
"_build_resource_dictionary",
"(",
"attendees",
",",
"required",
"=",
"required",
")",
"for",
"email",
"in",
"new_attendees",
":",... | Adds new attendees to the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects. | [
"Adds",
"new",
"attendees",
"to",
"the",
"event",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/base/calendar.py#L230-L242 | train | 59,420 |
linkedin/pyexchange | pyexchange/base/calendar.py | BaseExchangeCalendarEvent.remove_attendees | def remove_attendees(self, attendees):
"""
Removes attendees from the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
attendees_to_delete = self._build_resource_dictionary(attendees)
for email in attendees_to_delete.keys():
if email in s... | python | def remove_attendees(self, attendees):
"""
Removes attendees from the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
attendees_to_delete = self._build_resource_dictionary(attendees)
for email in attendees_to_delete.keys():
if email in s... | [
"def",
"remove_attendees",
"(",
"self",
",",
"attendees",
")",
":",
"attendees_to_delete",
"=",
"self",
".",
"_build_resource_dictionary",
"(",
"attendees",
")",
"for",
"email",
"in",
"attendees_to_delete",
".",
"keys",
"(",
")",
":",
"if",
"email",
"in",
"sel... | Removes attendees from the event.
*attendees* can be a list of email addresses or :class:`ExchangeEventAttendee` objects. | [
"Removes",
"attendees",
"from",
"the",
"event",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/base/calendar.py#L244-L256 | train | 59,421 |
linkedin/pyexchange | pyexchange/base/calendar.py | BaseExchangeCalendarEvent.add_resources | def add_resources(self, resources):
"""
Adds new resources to the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
new_resources = self._build_resource_dictionary(resources)
for key in new_resources:
self._resources[key] = new_resources[k... | python | def add_resources(self, resources):
"""
Adds new resources to the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
new_resources = self._build_resource_dictionary(resources)
for key in new_resources:
self._resources[key] = new_resources[k... | [
"def",
"add_resources",
"(",
"self",
",",
"resources",
")",
":",
"new_resources",
"=",
"self",
".",
"_build_resource_dictionary",
"(",
"resources",
")",
"for",
"key",
"in",
"new_resources",
":",
"self",
".",
"_resources",
"[",
"key",
"]",
"=",
"new_resources",... | Adds new resources to the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects. | [
"Adds",
"new",
"resources",
"to",
"the",
"event",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/base/calendar.py#L273-L283 | train | 59,422 |
linkedin/pyexchange | pyexchange/base/calendar.py | BaseExchangeCalendarEvent.remove_resources | def remove_resources(self, resources):
"""
Removes resources from the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
resources_to_delete = self._build_resource_dictionary(resources)
for email in resources_to_delete.keys():
if email in s... | python | def remove_resources(self, resources):
"""
Removes resources from the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects.
"""
resources_to_delete = self._build_resource_dictionary(resources)
for email in resources_to_delete.keys():
if email in s... | [
"def",
"remove_resources",
"(",
"self",
",",
"resources",
")",
":",
"resources_to_delete",
"=",
"self",
".",
"_build_resource_dictionary",
"(",
"resources",
")",
"for",
"email",
"in",
"resources_to_delete",
".",
"keys",
"(",
")",
":",
"if",
"email",
"in",
"sel... | Removes resources from the event.
*resources* can be a list of email addresses or :class:`ExchangeEventAttendee` objects. | [
"Removes",
"resources",
"from",
"the",
"event",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/base/calendar.py#L285-L297 | train | 59,423 |
linkedin/pyexchange | pyexchange/base/calendar.py | BaseExchangeCalendarEvent.validate | def validate(self):
""" Validates that all required fields are present """
if not self.start:
raise ValueError("Event has no start date")
if not self.end:
raise ValueError("Event has no end date")
if self.end < self.start:
raise ValueError("Start date is after end date")
if self... | python | def validate(self):
""" Validates that all required fields are present """
if not self.start:
raise ValueError("Event has no start date")
if not self.end:
raise ValueError("Event has no end date")
if self.end < self.start:
raise ValueError("Start date is after end date")
if self... | [
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"start",
":",
"raise",
"ValueError",
"(",
"\"Event has no start date\"",
")",
"if",
"not",
"self",
".",
"end",
":",
"raise",
"ValueError",
"(",
"\"Event has no end date\"",
")",
"if",
"self"... | Validates that all required fields are present | [
"Validates",
"that",
"all",
"required",
"fields",
"are",
"present"
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/base/calendar.py#L305-L320 | train | 59,424 |
cournape/audiolab | audiolab/soundio/setuphelp.py | info_factory | def info_factory(name, libnames, headers, frameworks=None,
section=None, classname=None):
"""Create a system_info class.
Parameters
----------
name : str
name of the library
libnames : seq
list of libraries to look for
headers : seq
... | python | def info_factory(name, libnames, headers, frameworks=None,
section=None, classname=None):
"""Create a system_info class.
Parameters
----------
name : str
name of the library
libnames : seq
list of libraries to look for
headers : seq
... | [
"def",
"info_factory",
"(",
"name",
",",
"libnames",
",",
"headers",
",",
"frameworks",
"=",
"None",
",",
"section",
"=",
"None",
",",
"classname",
"=",
"None",
")",
":",
"if",
"not",
"classname",
":",
"classname",
"=",
"'%s_info'",
"%",
"name",
"if",
... | Create a system_info class.
Parameters
----------
name : str
name of the library
libnames : seq
list of libraries to look for
headers : seq
list of headers to look for
classname : str
name of the returned class
section : st... | [
"Create",
"a",
"system_info",
"class",
"."
] | e4918832c1e52b56428c5f3535ddeb9d9daff9ac | https://github.com/cournape/audiolab/blob/e4918832c1e52b56428c5f3535ddeb9d9daff9ac/audiolab/soundio/setuphelp.py#L6-L88 | train | 59,425 |
linkedin/pyexchange | pyexchange/exchange2010/__init__.py | Exchange2010CalendarEventList.load_all_details | def load_all_details(self):
"""
This function will execute all the event lookups for known events.
This is intended for use when you want to have a completely populated event entry, including
Organizer & Attendee details.
"""
log.debug(u"Loading all details")
if self.count > 0:
# Now,... | python | def load_all_details(self):
"""
This function will execute all the event lookups for known events.
This is intended for use when you want to have a completely populated event entry, including
Organizer & Attendee details.
"""
log.debug(u"Loading all details")
if self.count > 0:
# Now,... | [
"def",
"load_all_details",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"u\"Loading all details\"",
")",
"if",
"self",
".",
"count",
">",
"0",
":",
"# Now, empty out the events to prevent duplicates!",
"del",
"(",
"self",
".",
"events",
"[",
":",
"]",
")",... | This function will execute all the event lookups for known events.
This is intended for use when you want to have a completely populated event entry, including
Organizer & Attendee details. | [
"This",
"function",
"will",
"execute",
"all",
"the",
"event",
"lookups",
"for",
"known",
"events",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/__init__.py#L154-L174 | train | 59,426 |
cournape/audiolab | audiolab/pysndfile/compat.py | sndfile.seek | def seek(self, offset, whence=0, mode='rw'):
"""similar to python seek function, taking only in account audio data.
:Parameters:
offset : int
the number of frames (eg two samples for stereo files) to move
relatively to position set by whence.
when... | python | def seek(self, offset, whence=0, mode='rw'):
"""similar to python seek function, taking only in account audio data.
:Parameters:
offset : int
the number of frames (eg two samples for stereo files) to move
relatively to position set by whence.
when... | [
"def",
"seek",
"(",
"self",
",",
"offset",
",",
"whence",
"=",
"0",
",",
"mode",
"=",
"'rw'",
")",
":",
"try",
":",
"st",
"=",
"self",
".",
"_sndfile",
".",
"seek",
"(",
"offset",
",",
"whence",
",",
"mode",
")",
"except",
"IOError",
",",
"e",
... | similar to python seek function, taking only in account audio data.
:Parameters:
offset : int
the number of frames (eg two samples for stereo files) to move
relatively to position set by whence.
whence : int
only 0 (beginning), 1 (current)... | [
"similar",
"to",
"python",
"seek",
"function",
"taking",
"only",
"in",
"account",
"audio",
"data",
"."
] | e4918832c1e52b56428c5f3535ddeb9d9daff9ac | https://github.com/cournape/audiolab/blob/e4918832c1e52b56428c5f3535ddeb9d9daff9ac/audiolab/pysndfile/compat.py#L125-L151 | train | 59,427 |
cournape/audiolab | audiolab/pysndfile/compat.py | sndfile.read_frames | def read_frames(self, nframes, dtype=np.float64):
"""Read nframes frames of the file.
:Parameters:
nframes : int
number of frames to read.
dtype : numpy dtype
dtype of the returned array containing read data (see note).
Notes
----... | python | def read_frames(self, nframes, dtype=np.float64):
"""Read nframes frames of the file.
:Parameters:
nframes : int
number of frames to read.
dtype : numpy dtype
dtype of the returned array containing read data (see note).
Notes
----... | [
"def",
"read_frames",
"(",
"self",
",",
"nframes",
",",
"dtype",
"=",
"np",
".",
"float64",
")",
":",
"return",
"self",
".",
"_sndfile",
".",
"read_frames",
"(",
"nframes",
",",
"dtype",
")"
] | Read nframes frames of the file.
:Parameters:
nframes : int
number of frames to read.
dtype : numpy dtype
dtype of the returned array containing read data (see note).
Notes
-----
- read_frames updates the read pointer.
- ... | [
"Read",
"nframes",
"frames",
"of",
"the",
"file",
"."
] | e4918832c1e52b56428c5f3535ddeb9d9daff9ac | https://github.com/cournape/audiolab/blob/e4918832c1e52b56428c5f3535ddeb9d9daff9ac/audiolab/pysndfile/compat.py#L181-L203 | train | 59,428 |
cournape/audiolab | audiolab/pysndfile/compat.py | sndfile.write_frames | def write_frames(self, input, nframes = -1):
"""write data to file.
:Parameters:
input : ndarray
array containing data to write.
nframes : int
number of frames to write.
Notes
-----
- One column is one channel (one row pe... | python | def write_frames(self, input, nframes = -1):
"""write data to file.
:Parameters:
input : ndarray
array containing data to write.
nframes : int
number of frames to write.
Notes
-----
- One column is one channel (one row pe... | [
"def",
"write_frames",
"(",
"self",
",",
"input",
",",
"nframes",
"=",
"-",
"1",
")",
":",
"if",
"nframes",
"==",
"-",
"1",
":",
"if",
"input",
".",
"ndim",
"==",
"1",
":",
"nframes",
"=",
"input",
".",
"size",
"elif",
"input",
".",
"ndim",
"==",... | write data to file.
:Parameters:
input : ndarray
array containing data to write.
nframes : int
number of frames to write.
Notes
-----
- One column is one channel (one row per channel after 0.9)
- updates the write pointer... | [
"write",
"data",
"to",
"file",
"."
] | e4918832c1e52b56428c5f3535ddeb9d9daff9ac | https://github.com/cournape/audiolab/blob/e4918832c1e52b56428c5f3535ddeb9d9daff9ac/audiolab/pysndfile/compat.py#L209-L234 | train | 59,429 |
linkedin/pyexchange | pyexchange/exchange2010/soap_request.py | delete_field | def delete_field(field_uri):
"""
Helper function to request deletion of a field. This is necessary when you want to overwrite values instead of
appending.
<t:DeleteItemField>
<t:FieldURI FieldURI="calendar:Resources"/>
</t:DeleteItemField>
"""
root = T.DeleteItemField(
T.Fiel... | python | def delete_field(field_uri):
"""
Helper function to request deletion of a field. This is necessary when you want to overwrite values instead of
appending.
<t:DeleteItemField>
<t:FieldURI FieldURI="calendar:Resources"/>
</t:DeleteItemField>
"""
root = T.DeleteItemField(
T.Fiel... | [
"def",
"delete_field",
"(",
"field_uri",
")",
":",
"root",
"=",
"T",
".",
"DeleteItemField",
"(",
"T",
".",
"FieldURI",
"(",
"FieldURI",
"=",
"field_uri",
")",
")",
"return",
"root"
] | Helper function to request deletion of a field. This is necessary when you want to overwrite values instead of
appending.
<t:DeleteItemField>
<t:FieldURI FieldURI="calendar:Resources"/>
</t:DeleteItemField> | [
"Helper",
"function",
"to",
"request",
"deletion",
"of",
"a",
"field",
".",
"This",
"is",
"necessary",
"when",
"you",
"want",
"to",
"overwrite",
"values",
"instead",
"of",
"appending",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/soap_request.py#L62-L76 | train | 59,430 |
linkedin/pyexchange | pyexchange/exchange2010/soap_request.py | get_occurrence | def get_occurrence(exchange_id, instance_index, format=u"Default"):
"""
Requests one or more calendar items from the store matching the master & index.
exchange_id is the id for the master event in the Exchange store.
format controls how much data you get back from Exchange. Full docs are here, but acce... | python | def get_occurrence(exchange_id, instance_index, format=u"Default"):
"""
Requests one or more calendar items from the store matching the master & index.
exchange_id is the id for the master event in the Exchange store.
format controls how much data you get back from Exchange. Full docs are here, but acce... | [
"def",
"get_occurrence",
"(",
"exchange_id",
",",
"instance_index",
",",
"format",
"=",
"u\"Default\"",
")",
":",
"root",
"=",
"M",
".",
"GetItem",
"(",
"M",
".",
"ItemShape",
"(",
"T",
".",
"BaseShape",
"(",
"format",
")",
")",
",",
"M",
".",
"ItemIds... | Requests one or more calendar items from the store matching the master & index.
exchange_id is the id for the master event in the Exchange store.
format controls how much data you get back from Exchange. Full docs are here, but acceptible values
are IdOnly, Default, and AllProperties.
GetItem Doc:
... | [
"Requests",
"one",
"or",
"more",
"calendar",
"items",
"from",
"the",
"store",
"matching",
"the",
"master",
"&",
"index",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/soap_request.py#L186-L223 | train | 59,431 |
linkedin/pyexchange | pyexchange/exchange2010/soap_request.py | new_event | def new_event(event):
"""
Requests a new event be created in the store.
http://msdn.microsoft.com/en-us/library/aa564690(v=exchg.140).aspx
<m:CreateItem SendMeetingInvitations="SendToAllAndSaveCopy"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="htt... | python | def new_event(event):
"""
Requests a new event be created in the store.
http://msdn.microsoft.com/en-us/library/aa564690(v=exchg.140).aspx
<m:CreateItem SendMeetingInvitations="SendToAllAndSaveCopy"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="htt... | [
"def",
"new_event",
"(",
"event",
")",
":",
"id",
"=",
"T",
".",
"DistinguishedFolderId",
"(",
"Id",
"=",
"event",
".",
"calendar_id",
")",
"if",
"event",
".",
"calendar_id",
"in",
"DISTINGUISHED_IDS",
"else",
"T",
".",
"FolderId",
"(",
"Id",
"=",
"event... | Requests a new event be created in the store.
http://msdn.microsoft.com/en-us/library/aa564690(v=exchg.140).aspx
<m:CreateItem SendMeetingInvitations="SendToAllAndSaveCopy"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exch... | [
"Requests",
"a",
"new",
"event",
"be",
"created",
"in",
"the",
"store",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/soap_request.py#L280-L406 | train | 59,432 |
linkedin/pyexchange | pyexchange/exchange2010/soap_request.py | update_property_node | def update_property_node(node_to_insert, field_uri):
""" Helper function - generates a SetItemField which tells Exchange you want to overwrite the contents of a field."""
root = T.SetItemField(
T.FieldURI(FieldURI=field_uri),
T.CalendarItem(node_to_insert)
)
return root | python | def update_property_node(node_to_insert, field_uri):
""" Helper function - generates a SetItemField which tells Exchange you want to overwrite the contents of a field."""
root = T.SetItemField(
T.FieldURI(FieldURI=field_uri),
T.CalendarItem(node_to_insert)
)
return root | [
"def",
"update_property_node",
"(",
"node_to_insert",
",",
"field_uri",
")",
":",
"root",
"=",
"T",
".",
"SetItemField",
"(",
"T",
".",
"FieldURI",
"(",
"FieldURI",
"=",
"field_uri",
")",
",",
"T",
".",
"CalendarItem",
"(",
"node_to_insert",
")",
")",
"ret... | Helper function - generates a SetItemField which tells Exchange you want to overwrite the contents of a field. | [
"Helper",
"function",
"-",
"generates",
"a",
"SetItemField",
"which",
"tells",
"Exchange",
"you",
"want",
"to",
"overwrite",
"the",
"contents",
"of",
"a",
"field",
"."
] | d568f4edd326adb451b915ddf66cf1a37820e3ca | https://github.com/linkedin/pyexchange/blob/d568f4edd326adb451b915ddf66cf1a37820e3ca/pyexchange/exchange2010/soap_request.py#L465-L471 | train | 59,433 |
hfaran/Tornado-JSON | tornado_json/api_doc_gen.py | _validate_example | def _validate_example(rh, method, example_type):
"""Validates example against schema
:returns: Formatted example if example exists and validates, otherwise None
:raises ValidationError: If example does not validate against the schema
"""
example = getattr(method, example_type + "_example")
sche... | python | def _validate_example(rh, method, example_type):
"""Validates example against schema
:returns: Formatted example if example exists and validates, otherwise None
:raises ValidationError: If example does not validate against the schema
"""
example = getattr(method, example_type + "_example")
sche... | [
"def",
"_validate_example",
"(",
"rh",
",",
"method",
",",
"example_type",
")",
":",
"example",
"=",
"getattr",
"(",
"method",
",",
"example_type",
"+",
"\"_example\"",
")",
"schema",
"=",
"getattr",
"(",
"method",
",",
"example_type",
"+",
"\"_schema\"",
")... | Validates example against schema
:returns: Formatted example if example exists and validates, otherwise None
:raises ValidationError: If example does not validate against the schema | [
"Validates",
"example",
"against",
"schema"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/api_doc_gen.py#L18-L39 | train | 59,434 |
hfaran/Tornado-JSON | tornado_json/api_doc_gen.py | _get_rh_methods | def _get_rh_methods(rh):
"""Yield all HTTP methods in ``rh`` that are decorated
with schema.validate"""
for k, v in vars(rh).items():
if all([
k in HTTP_METHODS,
is_method(v),
hasattr(v, "input_schema")
]):
yield (k, v) | python | def _get_rh_methods(rh):
"""Yield all HTTP methods in ``rh`` that are decorated
with schema.validate"""
for k, v in vars(rh).items():
if all([
k in HTTP_METHODS,
is_method(v),
hasattr(v, "input_schema")
]):
yield (k, v) | [
"def",
"_get_rh_methods",
"(",
"rh",
")",
":",
"for",
"k",
",",
"v",
"in",
"vars",
"(",
"rh",
")",
".",
"items",
"(",
")",
":",
"if",
"all",
"(",
"[",
"k",
"in",
"HTTP_METHODS",
",",
"is_method",
"(",
"v",
")",
",",
"hasattr",
"(",
"v",
",",
... | Yield all HTTP methods in ``rh`` that are decorated
with schema.validate | [
"Yield",
"all",
"HTTP",
"methods",
"in",
"rh",
"that",
"are",
"decorated",
"with",
"schema",
".",
"validate"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/api_doc_gen.py#L42-L51 | train | 59,435 |
hfaran/Tornado-JSON | tornado_json/api_doc_gen.py | _escape_markdown_literals | def _escape_markdown_literals(string):
"""Escape any markdown literals in ``string`` by prepending with \\
:type string: str
:rtype: str
"""
literals = list("\\`*_{}[]()<>#+-.!:|")
escape = lambda c: '\\' + c if c in literals else c
return "".join(map(escape, string)) | python | def _escape_markdown_literals(string):
"""Escape any markdown literals in ``string`` by prepending with \\
:type string: str
:rtype: str
"""
literals = list("\\`*_{}[]()<>#+-.!:|")
escape = lambda c: '\\' + c if c in literals else c
return "".join(map(escape, string)) | [
"def",
"_escape_markdown_literals",
"(",
"string",
")",
":",
"literals",
"=",
"list",
"(",
"\"\\\\`*_{}[]()<>#+-.!:|\"",
")",
"escape",
"=",
"lambda",
"c",
":",
"'\\\\'",
"+",
"c",
"if",
"c",
"in",
"literals",
"else",
"c",
"return",
"\"\"",
".",
"join",
"(... | Escape any markdown literals in ``string`` by prepending with \\
:type string: str
:rtype: str | [
"Escape",
"any",
"markdown",
"literals",
"in",
"string",
"by",
"prepending",
"with",
"\\\\"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/api_doc_gen.py#L86-L94 | train | 59,436 |
hfaran/Tornado-JSON | tornado_json/api_doc_gen.py | _cleandoc | def _cleandoc(doc):
"""Remove uniform indents from ``doc`` lines that are not empty
:returns: Cleaned ``doc``
"""
indent_length = lambda s: len(s) - len(s.lstrip(" "))
not_empty = lambda s: s != ""
lines = doc.split("\n")
indent = min(map(indent_length, filter(not_empty, lines)))
retu... | python | def _cleandoc(doc):
"""Remove uniform indents from ``doc`` lines that are not empty
:returns: Cleaned ``doc``
"""
indent_length = lambda s: len(s) - len(s.lstrip(" "))
not_empty = lambda s: s != ""
lines = doc.split("\n")
indent = min(map(indent_length, filter(not_empty, lines)))
retu... | [
"def",
"_cleandoc",
"(",
"doc",
")",
":",
"indent_length",
"=",
"lambda",
"s",
":",
"len",
"(",
"s",
")",
"-",
"len",
"(",
"s",
".",
"lstrip",
"(",
"\" \"",
")",
")",
"not_empty",
"=",
"lambda",
"s",
":",
"s",
"!=",
"\"\"",
"lines",
"=",
"doc",
... | Remove uniform indents from ``doc`` lines that are not empty
:returns: Cleaned ``doc`` | [
"Remove",
"uniform",
"indents",
"from",
"doc",
"lines",
"that",
"are",
"not",
"empty"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/api_doc_gen.py#L97-L108 | train | 59,437 |
hfaran/Tornado-JSON | tornado_json/api_doc_gen.py | get_api_docs | def get_api_docs(routes):
"""
Generates GitHub Markdown formatted API documentation using
provided schemas in RequestHandler methods and their docstrings.
:type routes: [(url, RequestHandler), ...]
:param routes: List of routes (this is ideally all possible routes of the
app)
:rtype: s... | python | def get_api_docs(routes):
"""
Generates GitHub Markdown formatted API documentation using
provided schemas in RequestHandler methods and their docstrings.
:type routes: [(url, RequestHandler), ...]
:param routes: List of routes (this is ideally all possible routes of the
app)
:rtype: s... | [
"def",
"get_api_docs",
"(",
"routes",
")",
":",
"routes",
"=",
"map",
"(",
"_get_tuple_from_route",
",",
"routes",
")",
"documentation",
"=",
"[",
"]",
"for",
"url",
",",
"rh",
",",
"methods",
"in",
"sorted",
"(",
"routes",
",",
"key",
"=",
"lambda",
"... | Generates GitHub Markdown formatted API documentation using
provided schemas in RequestHandler methods and their docstrings.
:type routes: [(url, RequestHandler), ...]
:param routes: List of routes (this is ideally all possible routes of the
app)
:rtype: str
:returns: generated GFM-formatt... | [
"Generates",
"GitHub",
"Markdown",
"formatted",
"API",
"documentation",
"using",
"provided",
"schemas",
"in",
"RequestHandler",
"methods",
"and",
"their",
"docstrings",
"."
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/api_doc_gen.py#L237-L260 | train | 59,438 |
hfaran/Tornado-JSON | tornado_json/jsend.py | JSendMixin.error | def error(self, message, data=None, code=None):
"""An error occurred in processing the request, i.e. an exception was
thrown.
:type data: A JSON-serializable object
:param data: A generic container for any other information about the
error, i.e. the conditions that caused t... | python | def error(self, message, data=None, code=None):
"""An error occurred in processing the request, i.e. an exception was
thrown.
:type data: A JSON-serializable object
:param data: A generic container for any other information about the
error, i.e. the conditions that caused t... | [
"def",
"error",
"(",
"self",
",",
"message",
",",
"data",
"=",
"None",
",",
"code",
"=",
"None",
")",
":",
"result",
"=",
"{",
"'status'",
":",
"'error'",
",",
"'message'",
":",
"message",
"}",
"if",
"data",
":",
"result",
"[",
"'data'",
"]",
"=",
... | An error occurred in processing the request, i.e. an exception was
thrown.
:type data: A JSON-serializable object
:param data: A generic container for any other information about the
error, i.e. the conditions that caused the error,
stack traces, etc.
:type mes... | [
"An",
"error",
"occurred",
"in",
"processing",
"the",
"request",
"i",
".",
"e",
".",
"an",
"exception",
"was",
"thrown",
"."
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/jsend.py#L35-L55 | train | 59,439 |
hfaran/Tornado-JSON | tornado_json/schema.py | input_schema_clean | def input_schema_clean(input_, input_schema):
"""
Updates schema default values with input data.
:param input_: Input data
:type input_: dict
:param input_schema: Input schema
:type input_schema: dict
:returns: Nested dict with data (defaul values updated with input data)
:rtype: dict... | python | def input_schema_clean(input_, input_schema):
"""
Updates schema default values with input data.
:param input_: Input data
:type input_: dict
:param input_schema: Input schema
:type input_schema: dict
:returns: Nested dict with data (defaul values updated with input data)
:rtype: dict... | [
"def",
"input_schema_clean",
"(",
"input_",
",",
"input_schema",
")",
":",
"if",
"input_schema",
".",
"get",
"(",
"'type'",
")",
"==",
"'object'",
":",
"try",
":",
"defaults",
"=",
"get_object_defaults",
"(",
"input_schema",
")",
"except",
"NoObjectDefaults",
... | Updates schema default values with input data.
:param input_: Input data
:type input_: dict
:param input_schema: Input schema
:type input_schema: dict
:returns: Nested dict with data (defaul values updated with input data)
:rtype: dict | [
"Updates",
"schema",
"default",
"values",
"with",
"input",
"data",
"."
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/schema.py#L61-L79 | train | 59,440 |
hfaran/Tornado-JSON | tornado_json/schema.py | validate | def validate(input_schema=None, output_schema=None,
input_example=None, output_example=None,
validator_cls=None,
format_checker=None, on_empty_404=False,
use_defaults=False):
"""Parameterized decorator for schema validation
:type validator_cls: IValidator cla... | python | def validate(input_schema=None, output_schema=None,
input_example=None, output_example=None,
validator_cls=None,
format_checker=None, on_empty_404=False,
use_defaults=False):
"""Parameterized decorator for schema validation
:type validator_cls: IValidator cla... | [
"def",
"validate",
"(",
"input_schema",
"=",
"None",
",",
"output_schema",
"=",
"None",
",",
"input_example",
"=",
"None",
",",
"output_example",
"=",
"None",
",",
"validator_cls",
"=",
"None",
",",
"format_checker",
"=",
"None",
",",
"on_empty_404",
"=",
"F... | Parameterized decorator for schema validation
:type validator_cls: IValidator class
:type format_checker: jsonschema.FormatChecker or None
:type on_empty_404: bool
:param on_empty_404: If this is set, and the result from the
decorated method is a falsy value, a 404 will be raised.
:type use... | [
"Parameterized",
"decorator",
"for",
"schema",
"validation"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/schema.py#L82-L201 | train | 59,441 |
hfaran/Tornado-JSON | setup.py | read | def read(filename):
"""Read and return `filename` in root dir of project and return string"""
return codecs.open(os.path.join(__DIR__, filename), 'r').read() | python | def read(filename):
"""Read and return `filename` in root dir of project and return string"""
return codecs.open(os.path.join(__DIR__, filename), 'r').read() | [
"def",
"read",
"(",
"filename",
")",
":",
"return",
"codecs",
".",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"__DIR__",
",",
"filename",
")",
",",
"'r'",
")",
".",
"read",
"(",
")"
] | Read and return `filename` in root dir of project and return string | [
"Read",
"and",
"return",
"filename",
"in",
"root",
"dir",
"of",
"project",
"and",
"return",
"string"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/setup.py#L10-L12 | train | 59,442 |
hfaran/Tornado-JSON | tornado_json/utils.py | deep_update | def deep_update(source, overrides):
"""Update a nested dictionary or similar mapping.
Modify ``source`` in place.
:type source: collections.Mapping
:type overrides: collections.Mapping
:rtype: collections.Mapping
"""
for key, value in overrides.items():
if isinstance(value, collect... | python | def deep_update(source, overrides):
"""Update a nested dictionary or similar mapping.
Modify ``source`` in place.
:type source: collections.Mapping
:type overrides: collections.Mapping
:rtype: collections.Mapping
"""
for key, value in overrides.items():
if isinstance(value, collect... | [
"def",
"deep_update",
"(",
"source",
",",
"overrides",
")",
":",
"for",
"key",
",",
"value",
"in",
"overrides",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"collections",
".",
"Mapping",
")",
"and",
"value",
":",
"returned",
"="... | Update a nested dictionary or similar mapping.
Modify ``source`` in place.
:type source: collections.Mapping
:type overrides: collections.Mapping
:rtype: collections.Mapping | [
"Update",
"a",
"nested",
"dictionary",
"or",
"similar",
"mapping",
"."
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/utils.py#L7-L22 | train | 59,443 |
hfaran/Tornado-JSON | tornado_json/utils.py | is_handler_subclass | def is_handler_subclass(cls, classnames=("ViewHandler", "APIHandler")):
"""Determines if ``cls`` is indeed a subclass of ``classnames``"""
if isinstance(cls, list):
return any(is_handler_subclass(c) for c in cls)
elif isinstance(cls, type):
return any(c.__name__ in classnames for c in inspec... | python | def is_handler_subclass(cls, classnames=("ViewHandler", "APIHandler")):
"""Determines if ``cls`` is indeed a subclass of ``classnames``"""
if isinstance(cls, list):
return any(is_handler_subclass(c) for c in cls)
elif isinstance(cls, type):
return any(c.__name__ in classnames for c in inspec... | [
"def",
"is_handler_subclass",
"(",
"cls",
",",
"classnames",
"=",
"(",
"\"ViewHandler\"",
",",
"\"APIHandler\"",
")",
")",
":",
"if",
"isinstance",
"(",
"cls",
",",
"list",
")",
":",
"return",
"any",
"(",
"is_handler_subclass",
"(",
"c",
")",
"for",
"c",
... | Determines if ``cls`` is indeed a subclass of ``classnames`` | [
"Determines",
"if",
"cls",
"is",
"indeed",
"a",
"subclass",
"of",
"classnames"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/utils.py#L60-L72 | train | 59,444 |
hfaran/Tornado-JSON | tornado_json/requesthandlers.py | APIHandler.write_error | def write_error(self, status_code, **kwargs):
"""Override of RequestHandler.write_error
Calls ``error()`` or ``fail()`` from JSendMixin depending on which
exception was raised with provided reason and status code.
:type status_code: int
:param status_code: HTTP status code
... | python | def write_error(self, status_code, **kwargs):
"""Override of RequestHandler.write_error
Calls ``error()`` or ``fail()`` from JSendMixin depending on which
exception was raised with provided reason and status code.
:type status_code: int
:param status_code: HTTP status code
... | [
"def",
"write_error",
"(",
"self",
",",
"status_code",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"get_exc_message",
"(",
"exception",
")",
":",
"return",
"exception",
".",
"log_message",
"if",
"hasattr",
"(",
"exception",
",",
"\"log_message\"",
")",
"else",... | Override of RequestHandler.write_error
Calls ``error()`` or ``fail()`` from JSendMixin depending on which
exception was raised with provided reason and status code.
:type status_code: int
:param status_code: HTTP status code | [
"Override",
"of",
"RequestHandler",
".",
"write_error"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/requesthandlers.py#L50-L85 | train | 59,445 |
hfaran/Tornado-JSON | tornado_json/routes.py | gen_submodule_names | def gen_submodule_names(package):
"""Walk package and yield names of all submodules
:type package: package
:param package: The package to get submodule names of
:returns: Iterator that yields names of all submodules of ``package``
:rtype: Iterator that yields ``str``
"""
for importer, modn... | python | def gen_submodule_names(package):
"""Walk package and yield names of all submodules
:type package: package
:param package: The package to get submodule names of
:returns: Iterator that yields names of all submodules of ``package``
:rtype: Iterator that yields ``str``
"""
for importer, modn... | [
"def",
"gen_submodule_names",
"(",
"package",
")",
":",
"for",
"importer",
",",
"modname",
",",
"ispkg",
"in",
"pkgutil",
".",
"walk_packages",
"(",
"path",
"=",
"package",
".",
"__path__",
",",
"prefix",
"=",
"package",
".",
"__name__",
"+",
"'.'",
",",
... | Walk package and yield names of all submodules
:type package: package
:param package: The package to get submodule names of
:returns: Iterator that yields names of all submodules of ``package``
:rtype: Iterator that yields ``str`` | [
"Walk",
"package",
"and",
"yield",
"names",
"of",
"all",
"submodules"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/routes.py#L28-L40 | train | 59,446 |
hfaran/Tornado-JSON | tornado_json/routes.py | get_module_routes | def get_module_routes(module_name, custom_routes=None, exclusions=None,
arg_pattern=r'(?P<{}>[a-zA-Z0-9_\-]+)'):
"""Create and return routes for module_name
Routes are (url, RequestHandler) tuples
:returns: list of routes for ``module_name`` with respect to ``exclusions``
and... | python | def get_module_routes(module_name, custom_routes=None, exclusions=None,
arg_pattern=r'(?P<{}>[a-zA-Z0-9_\-]+)'):
"""Create and return routes for module_name
Routes are (url, RequestHandler) tuples
:returns: list of routes for ``module_name`` with respect to ``exclusions``
and... | [
"def",
"get_module_routes",
"(",
"module_name",
",",
"custom_routes",
"=",
"None",
",",
"exclusions",
"=",
"None",
",",
"arg_pattern",
"=",
"r'(?P<{}>[a-zA-Z0-9_\\-]+)'",
")",
":",
"def",
"has_method",
"(",
"module",
",",
"cls_name",
",",
"method_name",
")",
":"... | Create and return routes for module_name
Routes are (url, RequestHandler) tuples
:returns: list of routes for ``module_name`` with respect to ``exclusions``
and ``custom_routes``. Returned routes are with URLs formatted such
that they are forward-slash-separated by module/class level
a... | [
"Create",
"and",
"return",
"routes",
"for",
"module_name"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/routes.py#L43-L197 | train | 59,447 |
hfaran/Tornado-JSON | tornado_json/gen.py | coroutine | def coroutine(func, replace_callback=True):
"""Tornado-JSON compatible wrapper for ``tornado.gen.coroutine``
Annotates original argspec.args of ``func`` as attribute ``__argspec_args``
"""
# gen.coroutine in tornado 3.x.x and 5.x.x have a different signature than 4.x.x
if TORNADO_MAJOR != 4:
... | python | def coroutine(func, replace_callback=True):
"""Tornado-JSON compatible wrapper for ``tornado.gen.coroutine``
Annotates original argspec.args of ``func`` as attribute ``__argspec_args``
"""
# gen.coroutine in tornado 3.x.x and 5.x.x have a different signature than 4.x.x
if TORNADO_MAJOR != 4:
... | [
"def",
"coroutine",
"(",
"func",
",",
"replace_callback",
"=",
"True",
")",
":",
"# gen.coroutine in tornado 3.x.x and 5.x.x have a different signature than 4.x.x",
"if",
"TORNADO_MAJOR",
"!=",
"4",
":",
"wrapper",
"=",
"gen",
".",
"coroutine",
"(",
"func",
")",
"else... | Tornado-JSON compatible wrapper for ``tornado.gen.coroutine``
Annotates original argspec.args of ``func`` as attribute ``__argspec_args`` | [
"Tornado",
"-",
"JSON",
"compatible",
"wrapper",
"for",
"tornado",
".",
"gen",
".",
"coroutine"
] | 8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f | https://github.com/hfaran/Tornado-JSON/blob/8d8b35ff77f13cb3ab1a606bd2083b26cc69c54f/tornado_json/gen.py#L8-L19 | train | 59,448 |
dlintott/gns3-converter | gns3converter/main.py | main | def main():
"""
Entry point for gns3-converter
"""
arg_parse = setup_argparse()
args = arg_parse.parse_args()
if not args.quiet:
print('GNS3 Topology Converter')
if args.debug:
logging_level = logging.DEBUG
else:
logging_level = logging.WARNING
logging.basi... | python | def main():
"""
Entry point for gns3-converter
"""
arg_parse = setup_argparse()
args = arg_parse.parse_args()
if not args.quiet:
print('GNS3 Topology Converter')
if args.debug:
logging_level = logging.DEBUG
else:
logging_level = logging.WARNING
logging.basi... | [
"def",
"main",
"(",
")",
":",
"arg_parse",
"=",
"setup_argparse",
"(",
")",
"args",
"=",
"arg_parse",
".",
"parse_args",
"(",
")",
"if",
"not",
"args",
".",
"quiet",
":",
"print",
"(",
"'GNS3 Topology Converter'",
")",
"if",
"args",
".",
"debug",
":",
... | Entry point for gns3-converter | [
"Entry",
"point",
"for",
"gns3",
"-",
"converter"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L32-L66 | train | 59,449 |
dlintott/gns3-converter | gns3converter/main.py | setup_argparse | def setup_argparse():
"""
Setup the argparse argument parser
:return: instance of argparse
:rtype: ArgumentParser
"""
parser = argparse.ArgumentParser(
description='Convert old ini-style GNS3 topologies (<=0.8.7) to '
'the newer version 1+ JSON format')
parser.ad... | python | def setup_argparse():
"""
Setup the argparse argument parser
:return: instance of argparse
:rtype: ArgumentParser
"""
parser = argparse.ArgumentParser(
description='Convert old ini-style GNS3 topologies (<=0.8.7) to '
'the newer version 1+ JSON format')
parser.ad... | [
"def",
"setup_argparse",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Convert old ini-style GNS3 topologies (<=0.8.7) to '",
"'the newer version 1+ JSON format'",
")",
"parser",
".",
"add_argument",
"(",
"'--version'",
",",
"... | Setup the argparse argument parser
:return: instance of argparse
:rtype: ArgumentParser | [
"Setup",
"the",
"argparse",
"argument",
"parser"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L69-L94 | train | 59,450 |
dlintott/gns3-converter | gns3converter/main.py | do_conversion | def do_conversion(topology_def, topology_name, output_dir=None, debug=False,
quiet=False):
"""
Convert the topology
:param dict topology_def: Dict containing topology file and snapshot bool.
For example:
``{'file': filename, 'sna... | python | def do_conversion(topology_def, topology_name, output_dir=None, debug=False,
quiet=False):
"""
Convert the topology
:param dict topology_def: Dict containing topology file and snapshot bool.
For example:
``{'file': filename, 'sna... | [
"def",
"do_conversion",
"(",
"topology_def",
",",
"topology_name",
",",
"output_dir",
"=",
"None",
",",
"debug",
"=",
"False",
",",
"quiet",
"=",
"False",
")",
":",
"# Create a new instance of the the Converter",
"gns3_conv",
"=",
"Converter",
"(",
"topology_def",
... | Convert the topology
:param dict topology_def: Dict containing topology file and snapshot bool.
For example:
``{'file': filename, 'snapshot': False}``
:param str topology_name: The name of the topology
:param str output_dir: The directory in which... | [
"Convert",
"the",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L97-L132 | train | 59,451 |
dlintott/gns3-converter | gns3converter/main.py | get_snapshots | def get_snapshots(topology):
"""
Return the paths of any snapshot topologies
:param str topology: topology file
:return: list of dicts containing snapshot topologies
:rtype: list
"""
snapshots = []
snap_dir = os.path.join(topology_dirname(topology), 'snapshots')
if os.path.exists(sn... | python | def get_snapshots(topology):
"""
Return the paths of any snapshot topologies
:param str topology: topology file
:return: list of dicts containing snapshot topologies
:rtype: list
"""
snapshots = []
snap_dir = os.path.join(topology_dirname(topology), 'snapshots')
if os.path.exists(sn... | [
"def",
"get_snapshots",
"(",
"topology",
")",
":",
"snapshots",
"=",
"[",
"]",
"snap_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"topology_dirname",
"(",
"topology",
")",
",",
"'snapshots'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"snap_d... | Return the paths of any snapshot topologies
:param str topology: topology file
:return: list of dicts containing snapshot topologies
:rtype: list | [
"Return",
"the",
"paths",
"of",
"any",
"snapshot",
"topologies"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L157-L174 | train | 59,452 |
dlintott/gns3-converter | gns3converter/main.py | name | def name(topology_file, topology_name=None):
"""
Calculate the name to save the converted topology as using either either
a specified name or the directory name of the current project
:param str topology_file: Topology filename
:param topology_name: Optional topology name (Default: None)
:type ... | python | def name(topology_file, topology_name=None):
"""
Calculate the name to save the converted topology as using either either
a specified name or the directory name of the current project
:param str topology_file: Topology filename
:param topology_name: Optional topology name (Default: None)
:type ... | [
"def",
"name",
"(",
"topology_file",
",",
"topology_name",
"=",
"None",
")",
":",
"if",
"topology_name",
"is",
"not",
"None",
":",
"logging",
".",
"debug",
"(",
"'topology name supplied'",
")",
"topo_name",
"=",
"topology_name",
"else",
":",
"logging",
".",
... | Calculate the name to save the converted topology as using either either
a specified name or the directory name of the current project
:param str topology_file: Topology filename
:param topology_name: Optional topology name (Default: None)
:type topology_name: str or None
:return: new topology name... | [
"Calculate",
"the",
"name",
"to",
"save",
"the",
"converted",
"topology",
"as",
"using",
"either",
"either",
"a",
"specified",
"name",
"or",
"the",
"directory",
"name",
"of",
"the",
"current",
"project"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L177-L194 | train | 59,453 |
dlintott/gns3-converter | gns3converter/main.py | snapshot_name | def snapshot_name(topo_name):
"""
Get the snapshot name
:param str topo_name: topology file location. The name is taken from the
directory containing the topology file using the
following format: topology_NAME_snapshot_DATE_TIME
:return: snapshot name... | python | def snapshot_name(topo_name):
"""
Get the snapshot name
:param str topo_name: topology file location. The name is taken from the
directory containing the topology file using the
following format: topology_NAME_snapshot_DATE_TIME
:return: snapshot name... | [
"def",
"snapshot_name",
"(",
"topo_name",
")",
":",
"topo_name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"topology_dirname",
"(",
"topo_name",
")",
")",
"snap_re",
"=",
"re",
".",
"compile",
"(",
"'^topology_(.+)(_snapshot_)(\\d{6}_\\d{6})$'",
")",
"result... | Get the snapshot name
:param str topo_name: topology file location. The name is taken from the
directory containing the topology file using the
following format: topology_NAME_snapshot_DATE_TIME
:return: snapshot name
:raises ConvertError: when unable to ... | [
"Get",
"the",
"snapshot",
"name"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L197-L216 | train | 59,454 |
dlintott/gns3-converter | gns3converter/main.py | save | def save(output_dir, converter, json_topology, snapshot, quiet):
"""
Save the converted topology
:param str output_dir: Output Directory
:param Converter converter: Converter instance
:param JSONTopology json_topology: JSON topology layout
:param bool snapshot: Is this a snapshot?
:param bo... | python | def save(output_dir, converter, json_topology, snapshot, quiet):
"""
Save the converted topology
:param str output_dir: Output Directory
:param Converter converter: Converter instance
:param JSONTopology json_topology: JSON topology layout
:param bool snapshot: Is this a snapshot?
:param bo... | [
"def",
"save",
"(",
"output_dir",
",",
"converter",
",",
"json_topology",
",",
"snapshot",
",",
"quiet",
")",
":",
"try",
":",
"old_topology_dir",
"=",
"topology_dirname",
"(",
"converter",
".",
"topology",
")",
"if",
"output_dir",
":",
"output_dir",
"=",
"o... | Save the converted topology
:param str output_dir: Output Directory
:param Converter converter: Converter instance
:param JSONTopology json_topology: JSON topology layout
:param bool snapshot: Is this a snapshot?
:param bool quiet: No console printing | [
"Save",
"the",
"converted",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L219-L292 | train | 59,455 |
dlintott/gns3-converter | gns3converter/main.py | copy_configs | def copy_configs(configs, source, target):
"""
Copy dynamips configs to converted topology
:param configs: Configs to copy
:param str source: Source topology directory
:param str target: Target topology files directory
:return: True when a config cannot be found, otherwise false
:rtype: boo... | python | def copy_configs(configs, source, target):
"""
Copy dynamips configs to converted topology
:param configs: Configs to copy
:param str source: Source topology directory
:param str target: Target topology files directory
:return: True when a config cannot be found, otherwise false
:rtype: boo... | [
"def",
"copy_configs",
"(",
"configs",
",",
"source",
",",
"target",
")",
":",
"config_err",
"=",
"False",
"if",
"len",
"(",
"configs",
")",
">",
"0",
":",
"config_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"target",
",",
"'dynamips'",
",",
"'co... | Copy dynamips configs to converted topology
:param configs: Configs to copy
:param str source: Source topology directory
:param str target: Target topology files directory
:return: True when a config cannot be found, otherwise false
:rtype: bool | [
"Copy",
"dynamips",
"configs",
"to",
"converted",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L295-L319 | train | 59,456 |
dlintott/gns3-converter | gns3converter/main.py | copy_vpcs_configs | def copy_vpcs_configs(source, target):
"""
Copy any VPCS configs to the converted topology
:param str source: Source topology directory
:param str target: Target topology files directory
"""
# Prepare a list of files to copy
vpcs_files = glob.glob(os.path.join(source, 'configs', '*.vpc'))
... | python | def copy_vpcs_configs(source, target):
"""
Copy any VPCS configs to the converted topology
:param str source: Source topology directory
:param str target: Target topology files directory
"""
# Prepare a list of files to copy
vpcs_files = glob.glob(os.path.join(source, 'configs', '*.vpc'))
... | [
"def",
"copy_vpcs_configs",
"(",
"source",
",",
"target",
")",
":",
"# Prepare a list of files to copy",
"vpcs_files",
"=",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
"(",
"source",
",",
"'configs'",
",",
"'*.vpc'",
")",
")",
"vpcs_hist",
"=",... | Copy any VPCS configs to the converted topology
:param str source: Source topology directory
:param str target: Target topology files directory | [
"Copy",
"any",
"VPCS",
"configs",
"to",
"the",
"converted",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L322-L341 | train | 59,457 |
dlintott/gns3-converter | gns3converter/main.py | copy_topology_image | def copy_topology_image(source, target):
"""
Copy any images of the topology to the converted topology
:param str source: Source topology directory
:param str target: Target Directory
"""
files = glob.glob(os.path.join(source, '*.png'))
for file in files:
shutil.copy(file, target) | python | def copy_topology_image(source, target):
"""
Copy any images of the topology to the converted topology
:param str source: Source topology directory
:param str target: Target Directory
"""
files = glob.glob(os.path.join(source, '*.png'))
for file in files:
shutil.copy(file, target) | [
"def",
"copy_topology_image",
"(",
"source",
",",
"target",
")",
":",
"files",
"=",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
"(",
"source",
",",
"'*.png'",
")",
")",
"for",
"file",
"in",
"files",
":",
"shutil",
".",
"copy",
"(",
"f... | Copy any images of the topology to the converted topology
:param str source: Source topology directory
:param str target: Target Directory | [
"Copy",
"any",
"images",
"of",
"the",
"topology",
"to",
"the",
"converted",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L344-L354 | train | 59,458 |
dlintott/gns3-converter | gns3converter/main.py | copy_images | def copy_images(images, source, target):
"""
Copy images to converted topology
:param images: Images to copy
:param source: Old Topology Directory
:param target: Target topology files directory
:return: True when an image cannot be found, otherwise false
:rtype: bool
"""
image_err =... | python | def copy_images(images, source, target):
"""
Copy images to converted topology
:param images: Images to copy
:param source: Old Topology Directory
:param target: Target topology files directory
:return: True when an image cannot be found, otherwise false
:rtype: bool
"""
image_err =... | [
"def",
"copy_images",
"(",
"images",
",",
"source",
",",
"target",
")",
":",
"image_err",
"=",
"False",
"if",
"len",
"(",
"images",
")",
">",
"0",
":",
"images_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"target",
",",
"'images'",
")",
"os",
".... | Copy images to converted topology
:param images: Images to copy
:param source: Old Topology Directory
:param target: Target topology files directory
:return: True when an image cannot be found, otherwise false
:rtype: bool | [
"Copy",
"images",
"to",
"converted",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L357-L384 | train | 59,459 |
dlintott/gns3-converter | gns3converter/main.py | make_vbox_dirs | def make_vbox_dirs(max_vbox_id, output_dir, topology_name):
"""
Create VirtualBox working directories if required
:param int max_vbox_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name
"""
if max_vbox_id is not None:
f... | python | def make_vbox_dirs(max_vbox_id, output_dir, topology_name):
"""
Create VirtualBox working directories if required
:param int max_vbox_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name
"""
if max_vbox_id is not None:
f... | [
"def",
"make_vbox_dirs",
"(",
"max_vbox_id",
",",
"output_dir",
",",
"topology_name",
")",
":",
"if",
"max_vbox_id",
"is",
"not",
"None",
":",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"max_vbox_id",
"+",
"1",
")",
":",
"vbox_dir",
"=",
"os",
".",
"pat... | Create VirtualBox working directories if required
:param int max_vbox_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name | [
"Create",
"VirtualBox",
"working",
"directories",
"if",
"required"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L398-L410 | train | 59,460 |
dlintott/gns3-converter | gns3converter/main.py | make_qemu_dirs | def make_qemu_dirs(max_qemu_id, output_dir, topology_name):
"""
Create Qemu VM working directories if required
:param int max_qemu_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name
"""
if max_qemu_id is not None:
for ... | python | def make_qemu_dirs(max_qemu_id, output_dir, topology_name):
"""
Create Qemu VM working directories if required
:param int max_qemu_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name
"""
if max_qemu_id is not None:
for ... | [
"def",
"make_qemu_dirs",
"(",
"max_qemu_id",
",",
"output_dir",
",",
"topology_name",
")",
":",
"if",
"max_qemu_id",
"is",
"not",
"None",
":",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"max_qemu_id",
"+",
"1",
")",
":",
"qemu_dir",
"=",
"os",
".",
"pat... | Create Qemu VM working directories if required
:param int max_qemu_id: Number of directories to create
:param str output_dir: Output directory
:param str topology_name: Topology name | [
"Create",
"Qemu",
"VM",
"working",
"directories",
"if",
"required"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/main.py#L413-L425 | train | 59,461 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_wic | def add_wic(self, old_wic, wic):
"""
Convert the old style WIC slot to a new style WIC slot and add the WIC
to the node properties
:param str old_wic: Old WIC slot
:param str wic: WIC name
"""
new_wic = 'wic' + old_wic[-1]
self.node['properties'][new_wic]... | python | def add_wic(self, old_wic, wic):
"""
Convert the old style WIC slot to a new style WIC slot and add the WIC
to the node properties
:param str old_wic: Old WIC slot
:param str wic: WIC name
"""
new_wic = 'wic' + old_wic[-1]
self.node['properties'][new_wic]... | [
"def",
"add_wic",
"(",
"self",
",",
"old_wic",
",",
"wic",
")",
":",
"new_wic",
"=",
"'wic'",
"+",
"old_wic",
"[",
"-",
"1",
"]",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"new_wic",
"]",
"=",
"wic"
] | Convert the old style WIC slot to a new style WIC slot and add the WIC
to the node properties
:param str old_wic: Old WIC slot
:param str wic: WIC name | [
"Convert",
"the",
"old",
"style",
"WIC",
"slot",
"to",
"a",
"new",
"style",
"WIC",
"slot",
"and",
"add",
"the",
"WIC",
"to",
"the",
"node",
"properties"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L49-L58 | train | 59,462 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_slot_ports | def add_slot_ports(self, slot):
"""
Add the ports to be added for a adapter card
:param str slot: Slot name
"""
slot_nb = int(slot[4])
# slot_adapter = None
# if slot in self.node['properties']:
# slot_adapter = self.node['properties'][slot]
#... | python | def add_slot_ports(self, slot):
"""
Add the ports to be added for a adapter card
:param str slot: Slot name
"""
slot_nb = int(slot[4])
# slot_adapter = None
# if slot in self.node['properties']:
# slot_adapter = self.node['properties'][slot]
#... | [
"def",
"add_slot_ports",
"(",
"self",
",",
"slot",
")",
":",
"slot_nb",
"=",
"int",
"(",
"slot",
"[",
"4",
"]",
")",
"# slot_adapter = None",
"# if slot in self.node['properties']:",
"# slot_adapter = self.node['properties'][slot]",
"# elif self.device_info['model'] == 'c... | Add the ports to be added for a adapter card
:param str slot: Slot name | [
"Add",
"the",
"ports",
"to",
"be",
"added",
"for",
"a",
"adapter",
"card"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L91-L121 | train | 59,463 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_info_from_hv | def add_info_from_hv(self):
"""
Add the information we need from the old hypervisor section
"""
# Router Image
if 'image' in self.hypervisor:
self.node['properties']['image'] = \
os.path.basename(self.hypervisor['image'])
# IDLE-PC
if '... | python | def add_info_from_hv(self):
"""
Add the information we need from the old hypervisor section
"""
# Router Image
if 'image' in self.hypervisor:
self.node['properties']['image'] = \
os.path.basename(self.hypervisor['image'])
# IDLE-PC
if '... | [
"def",
"add_info_from_hv",
"(",
"self",
")",
":",
"# Router Image",
"if",
"'image'",
"in",
"self",
".",
"hypervisor",
":",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"'image'",
"]",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"h... | Add the information we need from the old hypervisor section | [
"Add",
"the",
"information",
"we",
"need",
"from",
"the",
"old",
"hypervisor",
"section"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L123-L145 | train | 59,464 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_device_items | def add_device_items(self, item, device):
"""
Add the various items from the device to the node
:param str item: item key
:param dict device: dictionary containing items
"""
if item in ('aux', 'console'):
self.node['properties'][item] = device[item]
e... | python | def add_device_items(self, item, device):
"""
Add the various items from the device to the node
:param str item: item key
:param dict device: dictionary containing items
"""
if item in ('aux', 'console'):
self.node['properties'][item] = device[item]
e... | [
"def",
"add_device_items",
"(",
"self",
",",
"item",
",",
"device",
")",
":",
"if",
"item",
"in",
"(",
"'aux'",
",",
"'console'",
")",
":",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"item",
"]",
"=",
"device",
"[",
"item",
"]",
"elif",
"i... | Add the various items from the device to the node
:param str item: item key
:param dict device: dictionary containing items | [
"Add",
"the",
"various",
"items",
"from",
"the",
"device",
"to",
"the",
"node"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L147-L190 | train | 59,465 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_to_virtualbox | def add_to_virtualbox(self):
"""
Add additional parameters that were in the VBoxDevice section or not
present
"""
# VirtualBox Image
if 'vmname' not in self.node['properties']:
self.node['properties']['vmname'] = \
self.hypervisor['VBoxDevice']... | python | def add_to_virtualbox(self):
"""
Add additional parameters that were in the VBoxDevice section or not
present
"""
# VirtualBox Image
if 'vmname' not in self.node['properties']:
self.node['properties']['vmname'] = \
self.hypervisor['VBoxDevice']... | [
"def",
"add_to_virtualbox",
"(",
"self",
")",
":",
"# VirtualBox Image",
"if",
"'vmname'",
"not",
"in",
"self",
".",
"node",
"[",
"'properties'",
"]",
":",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"'vmname'",
"]",
"=",
"self",
".",
"hypervisor",... | Add additional parameters that were in the VBoxDevice section or not
present | [
"Add",
"additional",
"parameters",
"that",
"were",
"in",
"the",
"VBoxDevice",
"section",
"or",
"not",
"present"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L192-L208 | train | 59,466 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_to_qemu | def add_to_qemu(self):
"""
Add additional parameters to a QemuVM Device that were present in its
global conf section
"""
device = self.device_info['ext_conf']
node_prop = self.node['properties']
hv_device = self.hypervisor[device]
# QEMU HDD Images
... | python | def add_to_qemu(self):
"""
Add additional parameters to a QemuVM Device that were present in its
global conf section
"""
device = self.device_info['ext_conf']
node_prop = self.node['properties']
hv_device = self.hypervisor[device]
# QEMU HDD Images
... | [
"def",
"add_to_qemu",
"(",
"self",
")",
":",
"device",
"=",
"self",
".",
"device_info",
"[",
"'ext_conf'",
"]",
"node_prop",
"=",
"self",
".",
"node",
"[",
"'properties'",
"]",
"hv_device",
"=",
"self",
".",
"hypervisor",
"[",
"device",
"]",
"# QEMU HDD Im... | Add additional parameters to a QemuVM Device that were present in its
global conf section | [
"Add",
"additional",
"parameters",
"to",
"a",
"QemuVM",
"Device",
"that",
"were",
"present",
"in",
"its",
"global",
"conf",
"section"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L210-L264 | train | 59,467 |
dlintott/gns3-converter | gns3converter/node.py | Node.add_vm_ethernet_ports | def add_vm_ethernet_ports(self):
"""
Add ethernet ports to Virtualbox and Qemu nodes
"""
for i in range(self.node['properties']['adapters']):
port = {'id': self.port_id,
'name': 'Ethernet%s' % i,
'port_number': i}
self.node[... | python | def add_vm_ethernet_ports(self):
"""
Add ethernet ports to Virtualbox and Qemu nodes
"""
for i in range(self.node['properties']['adapters']):
port = {'id': self.port_id,
'name': 'Ethernet%s' % i,
'port_number': i}
self.node[... | [
"def",
"add_vm_ethernet_ports",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"'adapters'",
"]",
")",
":",
"port",
"=",
"{",
"'id'",
":",
"self",
".",
"port_id",
",",
"'name'",
":",
"'Ether... | Add ethernet ports to Virtualbox and Qemu nodes | [
"Add",
"ethernet",
"ports",
"to",
"Virtualbox",
"and",
"Qemu",
"nodes"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L266-L275 | train | 59,468 |
dlintott/gns3-converter | gns3converter/node.py | Node.set_qemu_symbol | def set_qemu_symbol(self):
"""
Set the appropriate symbol for QEMU Devices
"""
valid_devices = {'ASA': 'asa', 'PIX': 'PIX_firewall',
'JUNOS': 'router', 'IDS': 'ids'}
if self.device_info['from'] in valid_devices \
and 'default_symbol' not i... | python | def set_qemu_symbol(self):
"""
Set the appropriate symbol for QEMU Devices
"""
valid_devices = {'ASA': 'asa', 'PIX': 'PIX_firewall',
'JUNOS': 'router', 'IDS': 'ids'}
if self.device_info['from'] in valid_devices \
and 'default_symbol' not i... | [
"def",
"set_qemu_symbol",
"(",
"self",
")",
":",
"valid_devices",
"=",
"{",
"'ASA'",
":",
"'asa'",
",",
"'PIX'",
":",
"'PIX_firewall'",
",",
"'JUNOS'",
":",
"'router'",
",",
"'IDS'",
":",
"'ids'",
"}",
"if",
"self",
".",
"device_info",
"[",
"'from'",
"]"... | Set the appropriate symbol for QEMU Devices | [
"Set",
"the",
"appropriate",
"symbol",
"for",
"QEMU",
"Devices"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L277-L286 | train | 59,469 |
dlintott/gns3-converter | gns3converter/node.py | Node.set_symbol | def set_symbol(self, symbol):
"""
Set a symbol for a device
:param str symbol: Symbol to use
"""
if symbol == 'EtherSwitch router':
symbol = 'multilayer_switch'
elif symbol == 'Host':
symbol = 'computer'
normal = ':/symbols/%s.normal.svg'... | python | def set_symbol(self, symbol):
"""
Set a symbol for a device
:param str symbol: Symbol to use
"""
if symbol == 'EtherSwitch router':
symbol = 'multilayer_switch'
elif symbol == 'Host':
symbol = 'computer'
normal = ':/symbols/%s.normal.svg'... | [
"def",
"set_symbol",
"(",
"self",
",",
"symbol",
")",
":",
"if",
"symbol",
"==",
"'EtherSwitch router'",
":",
"symbol",
"=",
"'multilayer_switch'",
"elif",
"symbol",
"==",
"'Host'",
":",
"symbol",
"=",
"'computer'",
"normal",
"=",
"':/symbols/%s.normal.svg'",
"%... | Set a symbol for a device
:param str symbol: Symbol to use | [
"Set",
"a",
"symbol",
"for",
"a",
"device"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L288-L303 | train | 59,470 |
dlintott/gns3-converter | gns3converter/node.py | Node.calc_ethsw_port | def calc_ethsw_port(self, port_num, port_def):
"""
Split and create the port entry for an Ethernet Switch
:param port_num: port number
:type port_num: str or int
:param str port_def: port definition
"""
# Port String - access 1 SW2 1
# 0: type 1: vlan 2: ... | python | def calc_ethsw_port(self, port_num, port_def):
"""
Split and create the port entry for an Ethernet Switch
:param port_num: port number
:type port_num: str or int
:param str port_def: port definition
"""
# Port String - access 1 SW2 1
# 0: type 1: vlan 2: ... | [
"def",
"calc_ethsw_port",
"(",
"self",
",",
"port_num",
",",
"port_def",
")",
":",
"# Port String - access 1 SW2 1",
"# 0: type 1: vlan 2: destination device 3: destination port",
"port_def",
"=",
"port_def",
".",
"split",
"(",
"' '",
")",
"if",
"len",
"(",
"port_def",
... | Split and create the port entry for an Ethernet Switch
:param port_num: port number
:type port_num: str or int
:param str port_def: port definition | [
"Split",
"and",
"create",
"the",
"port",
"entry",
"for",
"an",
"Ethernet",
"Switch"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L305-L331 | train | 59,471 |
dlintott/gns3-converter | gns3converter/node.py | Node.calc_mb_ports | def calc_mb_ports(self):
"""
Add the default ports to add to a router
"""
model = self.device_info['model']
chassis = self.device_info['chassis']
num_ports = MODEL_MATRIX[model][chassis]['ports']
ports = []
if num_ports > 0:
port_type = MODEL_... | python | def calc_mb_ports(self):
"""
Add the default ports to add to a router
"""
model = self.device_info['model']
chassis = self.device_info['chassis']
num_ports = MODEL_MATRIX[model][chassis]['ports']
ports = []
if num_ports > 0:
port_type = MODEL_... | [
"def",
"calc_mb_ports",
"(",
"self",
")",
":",
"model",
"=",
"self",
".",
"device_info",
"[",
"'model'",
"]",
"chassis",
"=",
"self",
".",
"device_info",
"[",
"'chassis'",
"]",
"num_ports",
"=",
"MODEL_MATRIX",
"[",
"model",
"]",
"[",
"chassis",
"]",
"["... | Add the default ports to add to a router | [
"Add",
"the",
"default",
"ports",
"to",
"add",
"to",
"a",
"router"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L354-L374 | train | 59,472 |
dlintott/gns3-converter | gns3converter/node.py | Node.calc_link | def calc_link(self, src_id, src_port, src_port_name, destination):
"""
Add a link item for processing later
:param int src_id: Source node ID
:param int src_port: Source port ID
:param str src_port_name: Source port name
:param dict destination: Destination
"""
... | python | def calc_link(self, src_id, src_port, src_port_name, destination):
"""
Add a link item for processing later
:param int src_id: Source node ID
:param int src_port: Source port ID
:param str src_port_name: Source port name
:param dict destination: Destination
"""
... | [
"def",
"calc_link",
"(",
"self",
",",
"src_id",
",",
"src_port",
",",
"src_port_name",
",",
"destination",
")",
":",
"if",
"destination",
"[",
"'device'",
"]",
"==",
"'NIO'",
":",
"destination",
"[",
"'port'",
"]",
"=",
"destination",
"[",
"'port'",
"]",
... | Add a link item for processing later
:param int src_id: Source node ID
:param int src_port: Source port ID
:param str src_port_name: Source port name
:param dict destination: Destination | [
"Add",
"a",
"link",
"item",
"for",
"processing",
"later"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L376-L395 | train | 59,473 |
dlintott/gns3-converter | gns3converter/node.py | Node.set_description | def set_description(self):
"""
Set the node description
"""
if self.device_info['type'] == 'Router':
self.node['description'] = '%s %s' % (self.device_info['type'],
self.device_info['model'])
else:
self.nod... | python | def set_description(self):
"""
Set the node description
"""
if self.device_info['type'] == 'Router':
self.node['description'] = '%s %s' % (self.device_info['type'],
self.device_info['model'])
else:
self.nod... | [
"def",
"set_description",
"(",
"self",
")",
":",
"if",
"self",
".",
"device_info",
"[",
"'type'",
"]",
"==",
"'Router'",
":",
"self",
".",
"node",
"[",
"'description'",
"]",
"=",
"'%s %s'",
"%",
"(",
"self",
".",
"device_info",
"[",
"'type'",
"]",
",",... | Set the node description | [
"Set",
"the",
"node",
"description"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L402-L410 | train | 59,474 |
dlintott/gns3-converter | gns3converter/node.py | Node.set_type | def set_type(self):
"""
Set the node type
"""
if self.device_info['type'] == 'Router':
self.node['type'] = self.device_info['model'].upper()
else:
self.node['type'] = self.device_info['type'] | python | def set_type(self):
"""
Set the node type
"""
if self.device_info['type'] == 'Router':
self.node['type'] = self.device_info['model'].upper()
else:
self.node['type'] = self.device_info['type'] | [
"def",
"set_type",
"(",
"self",
")",
":",
"if",
"self",
".",
"device_info",
"[",
"'type'",
"]",
"==",
"'Router'",
":",
"self",
".",
"node",
"[",
"'type'",
"]",
"=",
"self",
".",
"device_info",
"[",
"'model'",
"]",
".",
"upper",
"(",
")",
"else",
":... | Set the node type | [
"Set",
"the",
"node",
"type"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L412-L419 | train | 59,475 |
dlintott/gns3-converter | gns3converter/node.py | Node.calc_device_links | def calc_device_links(self):
"""
Calculate a router or VirtualBox link
"""
for connection in self.interfaces:
int_type = connection['from'][0]
int_name = connection['from'].replace(int_type,
PORT_TYPES[int_type.upp... | python | def calc_device_links(self):
"""
Calculate a router or VirtualBox link
"""
for connection in self.interfaces:
int_type = connection['from'][0]
int_name = connection['from'].replace(int_type,
PORT_TYPES[int_type.upp... | [
"def",
"calc_device_links",
"(",
"self",
")",
":",
"for",
"connection",
"in",
"self",
".",
"interfaces",
":",
"int_type",
"=",
"connection",
"[",
"'from'",
"]",
"[",
"0",
"]",
"int_name",
"=",
"connection",
"[",
"'from'",
"]",
".",
"replace",
"(",
"int_t... | Calculate a router or VirtualBox link | [
"Calculate",
"a",
"router",
"or",
"VirtualBox",
"link"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L431-L454 | train | 59,476 |
dlintott/gns3-converter | gns3converter/node.py | Node.calc_cloud_connection | def calc_cloud_connection(self):
"""
Add the ports and nios for a cloud connection
:return: None on success or RuntimeError on error
"""
# Connection String - SW1:1:nio_gen_eth:eth0
# 0: Destination device 1: Destination port
# 2: NIO 3: NIO Destination
s... | python | def calc_cloud_connection(self):
"""
Add the ports and nios for a cloud connection
:return: None on success or RuntimeError on error
"""
# Connection String - SW1:1:nio_gen_eth:eth0
# 0: Destination device 1: Destination port
# 2: NIO 3: NIO Destination
s... | [
"def",
"calc_cloud_connection",
"(",
"self",
")",
":",
"# Connection String - SW1:1:nio_gen_eth:eth0",
"# 0: Destination device 1: Destination port",
"# 2: NIO 3: NIO Destination",
"self",
".",
"node",
"[",
"'properties'",
"]",
"[",
"'nios'",
"]",
"=",
"[",
"]",
"if",
"se... | Add the ports and nios for a cloud connection
:return: None on success or RuntimeError on error | [
"Add",
"the",
"ports",
"and",
"nios",
"for",
"a",
"cloud",
"connection"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L456-L488 | train | 59,477 |
dlintott/gns3-converter | gns3converter/node.py | Node.process_mappings | def process_mappings(self):
"""
Process the mappings for a Frame Relay switch. Removes duplicates and
adds the mappings to the node properties
"""
for mapping_a in self.mappings:
for mapping_b in self.mappings:
if mapping_a['source'] == mapping_b['dest... | python | def process_mappings(self):
"""
Process the mappings for a Frame Relay switch. Removes duplicates and
adds the mappings to the node properties
"""
for mapping_a in self.mappings:
for mapping_b in self.mappings:
if mapping_a['source'] == mapping_b['dest... | [
"def",
"process_mappings",
"(",
"self",
")",
":",
"for",
"mapping_a",
"in",
"self",
".",
"mappings",
":",
"for",
"mapping_b",
"in",
"self",
".",
"mappings",
":",
"if",
"mapping_a",
"[",
"'source'",
"]",
"==",
"mapping_b",
"[",
"'dest'",
"]",
":",
"self",... | Process the mappings for a Frame Relay switch. Removes duplicates and
adds the mappings to the node properties | [
"Process",
"the",
"mappings",
"for",
"a",
"Frame",
"Relay",
"switch",
".",
"Removes",
"duplicates",
"and",
"adds",
"the",
"mappings",
"to",
"the",
"node",
"properties"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/node.py#L490-L504 | train | 59,478 |
dlintott/gns3-converter | gns3converter/utils.py | fix_path | def fix_path(path):
"""
Fix windows path's. Linux path's will remain unaltered
:param str path: The path to be fixed
:return: The fixed path
:rtype: str
"""
if '\\' in path:
path = path.replace('\\', '/')
path = os.path.normpath(path)
return path | python | def fix_path(path):
"""
Fix windows path's. Linux path's will remain unaltered
:param str path: The path to be fixed
:return: The fixed path
:rtype: str
"""
if '\\' in path:
path = path.replace('\\', '/')
path = os.path.normpath(path)
return path | [
"def",
"fix_path",
"(",
"path",
")",
":",
"if",
"'\\\\'",
"in",
"path",
":",
"path",
"=",
"path",
".",
"replace",
"(",
"'\\\\'",
",",
"'/'",
")",
"path",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"path",
")",
"return",
"path"
] | Fix windows path's. Linux path's will remain unaltered
:param str path: The path to be fixed
:return: The fixed path
:rtype: str | [
"Fix",
"windows",
"path",
"s",
".",
"Linux",
"path",
"s",
"will",
"remain",
"unaltered"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/utils.py#L18-L31 | train | 59,479 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.read_topology | def read_topology(self):
"""
Read the ini-style topology file using ConfigObj
:return config: Topology parsed by :py:mod:`ConfigObj`
:rtype: ConfigObj
"""
configspec = resource_stream(__name__, 'configspec')
try:
handle = open(self._topology)
... | python | def read_topology(self):
"""
Read the ini-style topology file using ConfigObj
:return config: Topology parsed by :py:mod:`ConfigObj`
:rtype: ConfigObj
"""
configspec = resource_stream(__name__, 'configspec')
try:
handle = open(self._topology)
... | [
"def",
"read_topology",
"(",
"self",
")",
":",
"configspec",
"=",
"resource_stream",
"(",
"__name__",
",",
"'configspec'",
")",
"try",
":",
"handle",
"=",
"open",
"(",
"self",
".",
"_topology",
")",
"handle",
".",
"close",
"(",
")",
"try",
":",
"config",... | Read the ini-style topology file using ConfigObj
:return config: Topology parsed by :py:mod:`ConfigObj`
:rtype: ConfigObj | [
"Read",
"the",
"ini",
"-",
"style",
"topology",
"file",
"using",
"ConfigObj"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L61-L106 | train | 59,480 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.process_topology | def process_topology(self, old_top):
"""
Processes the sections returned by get_instances
:param ConfigObj old_top: old topology as processed by
:py:meth:`read_topology`
:returns: tuple of dicts containing hypervisors, devices and artwork
:rtype... | python | def process_topology(self, old_top):
"""
Processes the sections returned by get_instances
:param ConfigObj old_top: old topology as processed by
:py:meth:`read_topology`
:returns: tuple of dicts containing hypervisors, devices and artwork
:rtype... | [
"def",
"process_topology",
"(",
"self",
",",
"old_top",
")",
":",
"sections",
"=",
"self",
".",
"get_sections",
"(",
"old_top",
")",
"topo",
"=",
"LegacyTopology",
"(",
"sections",
",",
"old_top",
")",
"for",
"instance",
"in",
"sorted",
"(",
"sections",
")... | Processes the sections returned by get_instances
:param ConfigObj old_top: old topology as processed by
:py:meth:`read_topology`
:returns: tuple of dicts containing hypervisors, devices and artwork
:rtype: tuple | [
"Processes",
"the",
"sections",
"returned",
"by",
"get_instances"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L108-L150 | train | 59,481 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.generate_links | def generate_links(self, nodes):
"""
Generate a list of links
:param list nodes: A list of nodes from :py:meth:`generate_nodes`
:return: list of links
:rtype: list
"""
new_links = []
for link in self.links:
# Expand port name if required
... | python | def generate_links(self, nodes):
"""
Generate a list of links
:param list nodes: A list of nodes from :py:meth:`generate_nodes`
:return: list of links
:rtype: list
"""
new_links = []
for link in self.links:
# Expand port name if required
... | [
"def",
"generate_links",
"(",
"self",
",",
"nodes",
")",
":",
"new_links",
"=",
"[",
"]",
"for",
"link",
"in",
"self",
".",
"links",
":",
"# Expand port name if required",
"if",
"INTERFACE_RE",
".",
"search",
"(",
"link",
"[",
"'dest_port'",
"]",
")",
"or"... | Generate a list of links
:param list nodes: A list of nodes from :py:meth:`generate_nodes`
:return: list of links
:rtype: list | [
"Generate",
"a",
"list",
"of",
"links"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L265-L315 | train | 59,482 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.device_id_from_name | def device_id_from_name(device_name, nodes):
"""
Get the device ID when given a device name
:param str device_name: device name
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: device ID
:rtype: int
"""
device_id = None
for... | python | def device_id_from_name(device_name, nodes):
"""
Get the device ID when given a device name
:param str device_name: device name
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: device ID
:rtype: int
"""
device_id = None
for... | [
"def",
"device_id_from_name",
"(",
"device_name",
",",
"nodes",
")",
":",
"device_id",
"=",
"None",
"for",
"node",
"in",
"nodes",
":",
"if",
"device_name",
"==",
"node",
"[",
"'properties'",
"]",
"[",
"'name'",
"]",
":",
"device_id",
"=",
"node",
"[",
"'... | Get the device ID when given a device name
:param str device_name: device name
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: device ID
:rtype: int | [
"Get",
"the",
"device",
"ID",
"when",
"given",
"a",
"device",
"name"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L318-L332 | train | 59,483 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.port_id_from_name | def port_id_from_name(port_name, device_id, nodes):
"""
Get the port ID when given a port name
:param str port_name: port name
:param str device_id: device ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port ID
:rtype: int
"""... | python | def port_id_from_name(port_name, device_id, nodes):
"""
Get the port ID when given a port name
:param str port_name: port name
:param str device_id: device ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port ID
:rtype: int
"""... | [
"def",
"port_id_from_name",
"(",
"port_name",
",",
"device_id",
",",
"nodes",
")",
":",
"port_id",
"=",
"None",
"for",
"node",
"in",
"nodes",
":",
"if",
"device_id",
"==",
"node",
"[",
"'id'",
"]",
":",
"for",
"port",
"in",
"node",
"[",
"'ports'",
"]",... | Get the port ID when given a port name
:param str port_name: port name
:param str device_id: device ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port ID
:rtype: int | [
"Get",
"the",
"port",
"ID",
"when",
"given",
"a",
"port",
"name"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L335-L353 | train | 59,484 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.convert_destination_to_id | def convert_destination_to_id(destination_node, destination_port, nodes):
"""
Convert a destination to device and port ID
:param str destination_node: Destination node name
:param str destination_port: Destination port name
:param list nodes: list of nodes from :py:meth:`generat... | python | def convert_destination_to_id(destination_node, destination_port, nodes):
"""
Convert a destination to device and port ID
:param str destination_node: Destination node name
:param str destination_port: Destination port name
:param list nodes: list of nodes from :py:meth:`generat... | [
"def",
"convert_destination_to_id",
"(",
"destination_node",
",",
"destination_port",
",",
"nodes",
")",
":",
"device_id",
"=",
"None",
"device_name",
"=",
"None",
"port_id",
"=",
"None",
"if",
"destination_node",
"!=",
"'NIO'",
":",
"for",
"node",
"in",
"nodes"... | Convert a destination to device and port ID
:param str destination_node: Destination node name
:param str destination_port: Destination port name
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: dict containing device ID, device name and port ID
:rtype: d... | [
"Convert",
"a",
"destination",
"to",
"device",
"and",
"port",
"ID"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L356-L392 | train | 59,485 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.get_node_name_from_id | def get_node_name_from_id(node_id, nodes):
"""
Get the name of a node when given the node_id
:param int node_id: The ID of a node
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: node name
:rtype: str
"""
node_name = ''
for... | python | def get_node_name_from_id(node_id, nodes):
"""
Get the name of a node when given the node_id
:param int node_id: The ID of a node
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: node name
:rtype: str
"""
node_name = ''
for... | [
"def",
"get_node_name_from_id",
"(",
"node_id",
",",
"nodes",
")",
":",
"node_name",
"=",
"''",
"for",
"node",
"in",
"nodes",
":",
"if",
"node",
"[",
"'id'",
"]",
"==",
"node_id",
":",
"node_name",
"=",
"node",
"[",
"'properties'",
"]",
"[",
"'name'",
... | Get the name of a node when given the node_id
:param int node_id: The ID of a node
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: node name
:rtype: str | [
"Get",
"the",
"name",
"of",
"a",
"node",
"when",
"given",
"the",
"node_id"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L395-L409 | train | 59,486 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.get_port_name_from_id | def get_port_name_from_id(node_id, port_id, nodes):
"""
Get the name of a port for a given node and port ID
:param int node_id: node ID
:param int port_id: port ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port name
:rtype: str
... | python | def get_port_name_from_id(node_id, port_id, nodes):
"""
Get the name of a port for a given node and port ID
:param int node_id: node ID
:param int port_id: port ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port name
:rtype: str
... | [
"def",
"get_port_name_from_id",
"(",
"node_id",
",",
"port_id",
",",
"nodes",
")",
":",
"port_name",
"=",
"''",
"for",
"node",
"in",
"nodes",
":",
"if",
"node",
"[",
"'id'",
"]",
"==",
"node_id",
":",
"for",
"port",
"in",
"node",
"[",
"'ports'",
"]",
... | Get the name of a port for a given node and port ID
:param int node_id: node ID
:param int port_id: port ID
:param list nodes: list of nodes from :py:meth:`generate_nodes`
:return: port name
:rtype: str | [
"Get",
"the",
"name",
"of",
"a",
"port",
"for",
"a",
"given",
"node",
"and",
"port",
"ID"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L412-L429 | train | 59,487 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.add_node_connection | def add_node_connection(self, link, nodes):
"""
Add a connection to a node
:param dict link: link definition
:param list nodes: list of nodes from :py:meth:`generate_nodes`
"""
# Description
src_desc = 'connected to %s on port %s' % \
(self.get... | python | def add_node_connection(self, link, nodes):
"""
Add a connection to a node
:param dict link: link definition
:param list nodes: list of nodes from :py:meth:`generate_nodes`
"""
# Description
src_desc = 'connected to %s on port %s' % \
(self.get... | [
"def",
"add_node_connection",
"(",
"self",
",",
"link",
",",
"nodes",
")",
":",
"# Description",
"src_desc",
"=",
"'connected to %s on port %s'",
"%",
"(",
"self",
".",
"get_node_name_from_id",
"(",
"link",
"[",
"'destination_node_id'",
"]",
",",
"nodes",
")",
"... | Add a connection to a node
:param dict link: link definition
:param list nodes: list of nodes from :py:meth:`generate_nodes` | [
"Add",
"a",
"connection",
"to",
"a",
"node"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L431-L464 | train | 59,488 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.generate_shapes | def generate_shapes(shapes):
"""
Generate the shapes for the topology
:param dict shapes: A dict of converted shapes from the old topology
:return: dict containing two lists (ellipse, rectangle)
:rtype: dict
"""
new_shapes = {'ellipse': [], 'rectangle': []}
... | python | def generate_shapes(shapes):
"""
Generate the shapes for the topology
:param dict shapes: A dict of converted shapes from the old topology
:return: dict containing two lists (ellipse, rectangle)
:rtype: dict
"""
new_shapes = {'ellipse': [], 'rectangle': []}
... | [
"def",
"generate_shapes",
"(",
"shapes",
")",
":",
"new_shapes",
"=",
"{",
"'ellipse'",
":",
"[",
"]",
",",
"'rectangle'",
":",
"[",
"]",
"}",
"for",
"shape",
"in",
"shapes",
":",
"tmp_shape",
"=",
"{",
"}",
"for",
"shape_item",
"in",
"shapes",
"[",
... | Generate the shapes for the topology
:param dict shapes: A dict of converted shapes from the old topology
:return: dict containing two lists (ellipse, rectangle)
:rtype: dict | [
"Generate",
"the",
"shapes",
"for",
"the",
"topology"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L467-L485 | train | 59,489 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.generate_notes | def generate_notes(notes):
"""
Generate the notes list
:param dict notes: A dict of converted notes from the old topology
:return: List of notes for the the topology
:rtype: list
"""
new_notes = []
for note in notes:
tmp_note = {}
... | python | def generate_notes(notes):
"""
Generate the notes list
:param dict notes: A dict of converted notes from the old topology
:return: List of notes for the the topology
:rtype: list
"""
new_notes = []
for note in notes:
tmp_note = {}
... | [
"def",
"generate_notes",
"(",
"notes",
")",
":",
"new_notes",
"=",
"[",
"]",
"for",
"note",
"in",
"notes",
":",
"tmp_note",
"=",
"{",
"}",
"for",
"note_item",
"in",
"notes",
"[",
"note",
"]",
":",
"tmp_note",
"[",
"note_item",
"]",
"=",
"notes",
"[",... | Generate the notes list
:param dict notes: A dict of converted notes from the old topology
:return: List of notes for the the topology
:rtype: list | [
"Generate",
"the",
"notes",
"list"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L488-L505 | train | 59,490 |
dlintott/gns3-converter | gns3converter/converter.py | Converter.generate_images | def generate_images(self, pixmaps):
"""
Generate the images list and store the images to copy
:param dict pixmaps: A dict of converted pixmaps from the old topology
:return: A list of images
:rtype: list
"""
new_images = []
for image in pixmaps:
... | python | def generate_images(self, pixmaps):
"""
Generate the images list and store the images to copy
:param dict pixmaps: A dict of converted pixmaps from the old topology
:return: A list of images
:rtype: list
"""
new_images = []
for image in pixmaps:
... | [
"def",
"generate_images",
"(",
"self",
",",
"pixmaps",
")",
":",
"new_images",
"=",
"[",
"]",
"for",
"image",
"in",
"pixmaps",
":",
"tmp_image",
"=",
"{",
"}",
"for",
"img_item",
"in",
"pixmaps",
"[",
"image",
"]",
":",
"if",
"img_item",
"==",
"'path'"... | Generate the images list and store the images to copy
:param dict pixmaps: A dict of converted pixmaps from the old topology
:return: A list of images
:rtype: list | [
"Generate",
"the",
"images",
"list",
"and",
"store",
"the",
"images",
"to",
"copy"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/converter.py#L507-L531 | train | 59,491 |
dlintott/gns3-converter | gns3converter/topology.py | LegacyTopology.add_qemu_path | def add_qemu_path(self, instance):
"""
Add the qemu path to the hypervisor conf data
:param instance: Hypervisor instance
"""
tmp_conf = {'qemu_path': self.old_top[instance]['qemupath']}
if len(self.topology['conf']) == 0:
self.topology['conf'].append(tmp_con... | python | def add_qemu_path(self, instance):
"""
Add the qemu path to the hypervisor conf data
:param instance: Hypervisor instance
"""
tmp_conf = {'qemu_path': self.old_top[instance]['qemupath']}
if len(self.topology['conf']) == 0:
self.topology['conf'].append(tmp_con... | [
"def",
"add_qemu_path",
"(",
"self",
",",
"instance",
")",
":",
"tmp_conf",
"=",
"{",
"'qemu_path'",
":",
"self",
".",
"old_top",
"[",
"instance",
"]",
"[",
"'qemupath'",
"]",
"}",
"if",
"len",
"(",
"self",
".",
"topology",
"[",
"'conf'",
"]",
")",
"... | Add the qemu path to the hypervisor conf data
:param instance: Hypervisor instance | [
"Add",
"the",
"qemu",
"path",
"to",
"the",
"hypervisor",
"conf",
"data"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L162-L172 | train | 59,492 |
dlintott/gns3-converter | gns3converter/topology.py | LegacyTopology.add_conf_item | def add_conf_item(self, instance, item):
"""
Add a hypervisor configuration item
:param instance: Hypervisor instance
:param item: Item to add
"""
tmp_conf = {}
if item not in EXTRA_CONF:
tmp_conf['model'] = MODEL_TRANSFORM[item]
for s_item ... | python | def add_conf_item(self, instance, item):
"""
Add a hypervisor configuration item
:param instance: Hypervisor instance
:param item: Item to add
"""
tmp_conf = {}
if item not in EXTRA_CONF:
tmp_conf['model'] = MODEL_TRANSFORM[item]
for s_item ... | [
"def",
"add_conf_item",
"(",
"self",
",",
"instance",
",",
"item",
")",
":",
"tmp_conf",
"=",
"{",
"}",
"if",
"item",
"not",
"in",
"EXTRA_CONF",
":",
"tmp_conf",
"[",
"'model'",
"]",
"=",
"MODEL_TRANSFORM",
"[",
"item",
"]",
"for",
"s_item",
"in",
"sor... | Add a hypervisor configuration item
:param instance: Hypervisor instance
:param item: Item to add | [
"Add",
"a",
"hypervisor",
"configuration",
"item"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L174-L198 | train | 59,493 |
dlintott/gns3-converter | gns3converter/topology.py | LegacyTopology.device_typename | def device_typename(item):
"""
Convert the old names to new-style names and types
:param str item: A device in the form of 'TYPE NAME'
:return: tuple containing device name and type details
"""
dev_type = {'ROUTER': {'from': 'ROUTER',
'des... | python | def device_typename(item):
"""
Convert the old names to new-style names and types
:param str item: A device in the form of 'TYPE NAME'
:return: tuple containing device name and type details
"""
dev_type = {'ROUTER': {'from': 'ROUTER',
'des... | [
"def",
"device_typename",
"(",
"item",
")",
":",
"dev_type",
"=",
"{",
"'ROUTER'",
":",
"{",
"'from'",
":",
"'ROUTER'",
",",
"'desc'",
":",
"'Router'",
",",
"'type'",
":",
"'Router'",
",",
"'label_x'",
":",
"19.5",
"}",
",",
"'QEMU'",
":",
"{",
"'from'... | Convert the old names to new-style names and types
:param str item: A device in the form of 'TYPE NAME'
:return: tuple containing device name and type details | [
"Convert",
"the",
"old",
"names",
"to",
"new",
"-",
"style",
"names",
"and",
"types"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L246-L314 | train | 59,494 |
dlintott/gns3-converter | gns3converter/topology.py | JSONTopology.get_topology | def get_topology(self):
"""
Get the converted topology ready for JSON encoding
:return: converted topology assembled into a single dict
:rtype: dict
"""
topology = {'name': self._name,
'resources_type': 'local',
'topology': {},
... | python | def get_topology(self):
"""
Get the converted topology ready for JSON encoding
:return: converted topology assembled into a single dict
:rtype: dict
"""
topology = {'name': self._name,
'resources_type': 'local',
'topology': {},
... | [
"def",
"get_topology",
"(",
"self",
")",
":",
"topology",
"=",
"{",
"'name'",
":",
"self",
".",
"_name",
",",
"'resources_type'",
":",
"'local'",
",",
"'topology'",
":",
"{",
"}",
",",
"'type'",
":",
"'topology'",
",",
"'version'",
":",
"'1.0'",
"}",
"... | Get the converted topology ready for JSON encoding
:return: converted topology assembled into a single dict
:rtype: dict | [
"Get",
"the",
"converted",
"topology",
"ready",
"for",
"JSON",
"encoding"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L469-L498 | train | 59,495 |
dlintott/gns3-converter | gns3converter/topology.py | JSONTopology.get_vboxes | def get_vboxes(self):
"""
Get the maximum ID of the VBoxes
:return: Maximum VBox ID
:rtype: int
"""
vbox_list = []
vbox_max = None
for node in self.nodes:
if node['type'] == 'VirtualBoxVM':
vbox_list.append(node['vbox_id'])
... | python | def get_vboxes(self):
"""
Get the maximum ID of the VBoxes
:return: Maximum VBox ID
:rtype: int
"""
vbox_list = []
vbox_max = None
for node in self.nodes:
if node['type'] == 'VirtualBoxVM':
vbox_list.append(node['vbox_id'])
... | [
"def",
"get_vboxes",
"(",
"self",
")",
":",
"vbox_list",
"=",
"[",
"]",
"vbox_max",
"=",
"None",
"for",
"node",
"in",
"self",
".",
"nodes",
":",
"if",
"node",
"[",
"'type'",
"]",
"==",
"'VirtualBoxVM'",
":",
"vbox_list",
".",
"append",
"(",
"node",
"... | Get the maximum ID of the VBoxes
:return: Maximum VBox ID
:rtype: int | [
"Get",
"the",
"maximum",
"ID",
"of",
"the",
"VBoxes"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L500-L515 | train | 59,496 |
dlintott/gns3-converter | gns3converter/topology.py | JSONTopology.get_qemus | def get_qemus(self):
"""
Get the maximum ID of the Qemu VMs
:return: Maximum Qemu VM ID
:rtype: int
"""
qemu_vm_list = []
qemu_vm_max = None
for node in self.nodes:
if node['type'] == 'QemuVM':
qemu_vm_list.append(node['qemu_id... | python | def get_qemus(self):
"""
Get the maximum ID of the Qemu VMs
:return: Maximum Qemu VM ID
:rtype: int
"""
qemu_vm_list = []
qemu_vm_max = None
for node in self.nodes:
if node['type'] == 'QemuVM':
qemu_vm_list.append(node['qemu_id... | [
"def",
"get_qemus",
"(",
"self",
")",
":",
"qemu_vm_list",
"=",
"[",
"]",
"qemu_vm_max",
"=",
"None",
"for",
"node",
"in",
"self",
".",
"nodes",
":",
"if",
"node",
"[",
"'type'",
"]",
"==",
"'QemuVM'",
":",
"qemu_vm_list",
".",
"append",
"(",
"node",
... | Get the maximum ID of the Qemu VMs
:return: Maximum Qemu VM ID
:rtype: int | [
"Get",
"the",
"maximum",
"ID",
"of",
"the",
"Qemu",
"VMs"
] | acbc55da51de86388dc5b5f6da55809b3c86b7ca | https://github.com/dlintott/gns3-converter/blob/acbc55da51de86388dc5b5f6da55809b3c86b7ca/gns3converter/topology.py#L517-L532 | train | 59,497 |
aeguana/PyFileMaker | PyFileMaker/xml2obj.py | Element.getElements | def getElements(self,name=''):
'Get a list of child elements'
#If no tag name is specified, return the all children
if not name:
return self.children
else:
# else return only those children with a matching tag name
elements = []
for element in self.children:
if element.name == name:
element... | python | def getElements(self,name=''):
'Get a list of child elements'
#If no tag name is specified, return the all children
if not name:
return self.children
else:
# else return only those children with a matching tag name
elements = []
for element in self.children:
if element.name == name:
element... | [
"def",
"getElements",
"(",
"self",
",",
"name",
"=",
"''",
")",
":",
"#If no tag name is specified, return the all children",
"if",
"not",
"name",
":",
"return",
"self",
".",
"children",
"else",
":",
"# else return only those children with a matching tag name",
"elements"... | Get a list of child elements | [
"Get",
"a",
"list",
"of",
"child",
"elements"
] | ef269b52a97e329d91da3c4851ddac800d7fd7e6 | https://github.com/aeguana/PyFileMaker/blob/ef269b52a97e329d91da3c4851ddac800d7fd7e6/PyFileMaker/xml2obj.py#L35-L46 | train | 59,498 |
aeguana/PyFileMaker | PyFileMaker/xml2obj.py | Xml2Obj.StartElement | def StartElement(self,name,attributes):
'SAX start element even handler'
# Instantiate an Element object
element = Element(name.encode(),attributes)
# Push element onto the stack and make it a child of parent
if len(self.nodeStack) > 0:
parent = self.nodeStack[-1]
parent.AddChild(element)
else:
... | python | def StartElement(self,name,attributes):
'SAX start element even handler'
# Instantiate an Element object
element = Element(name.encode(),attributes)
# Push element onto the stack and make it a child of parent
if len(self.nodeStack) > 0:
parent = self.nodeStack[-1]
parent.AddChild(element)
else:
... | [
"def",
"StartElement",
"(",
"self",
",",
"name",
",",
"attributes",
")",
":",
"# Instantiate an Element object",
"element",
"=",
"Element",
"(",
"name",
".",
"encode",
"(",
")",
",",
"attributes",
")",
"# Push element onto the stack and make it a child of parent",
"if... | SAX start element even handler | [
"SAX",
"start",
"element",
"even",
"handler"
] | ef269b52a97e329d91da3c4851ddac800d7fd7e6 | https://github.com/aeguana/PyFileMaker/blob/ef269b52a97e329d91da3c4851ddac800d7fd7e6/PyFileMaker/xml2obj.py#L54-L65 | train | 59,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.