repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
happyleavesaoc/aoc-mgz | mgz/summary.py | find_postgame | def find_postgame(data, size):
"""Find postgame struct.
We can find postgame location by scanning the last few
thousand bytes of the rec and looking for a pattern as
follows:
[action op] [action length] [action type]
01 00 00 00 30 08 00 00 ff
The last occurance of this pa... | python | def find_postgame(data, size):
"""Find postgame struct.
We can find postgame location by scanning the last few
thousand bytes of the rec and looking for a pattern as
follows:
[action op] [action length] [action type]
01 00 00 00 30 08 00 00 ff
The last occurance of this pa... | [
"def",
"find_postgame",
"(",
"data",
",",
"size",
")",
":",
"pos",
"=",
"None",
"for",
"i",
"in",
"range",
"(",
"size",
"-",
"SEARCH_MAX_BYTES",
",",
"size",
"-",
"LOOKAHEAD",
")",
":",
"op_type",
",",
"length",
",",
"action_type",
"=",
"struct",
".",
... | Find postgame struct.
We can find postgame location by scanning the last few
thousand bytes of the rec and looking for a pattern as
follows:
[action op] [action length] [action type]
01 00 00 00 30 08 00 00 ff
The last occurance of this pattern signals the start of
the pos... | [
"Find",
"postgame",
"struct",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L54-L73 | train | Find postgame structure. |
happyleavesaoc/aoc-mgz | mgz/summary.py | parse_postgame | def parse_postgame(handle, size):
"""Parse postgame structure."""
data = handle.read()
postgame = find_postgame(data, size)
if postgame:
pos, length = postgame
try:
return mgz.body.actions.postgame.parse(data[pos:pos + length])
except construct.core.ConstructError:
... | python | def parse_postgame(handle, size):
"""Parse postgame structure."""
data = handle.read()
postgame = find_postgame(data, size)
if postgame:
pos, length = postgame
try:
return mgz.body.actions.postgame.parse(data[pos:pos + length])
except construct.core.ConstructError:
... | [
"def",
"parse_postgame",
"(",
"handle",
",",
"size",
")",
":",
"data",
"=",
"handle",
".",
"read",
"(",
")",
"postgame",
"=",
"find_postgame",
"(",
"data",
",",
"size",
")",
"if",
"postgame",
":",
"pos",
",",
"length",
"=",
"postgame",
"try",
":",
"r... | Parse postgame structure. | [
"Parse",
"postgame",
"structure",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L76-L86 | train | Parse the postgame structure. |
happyleavesaoc/aoc-mgz | mgz/summary.py | ach | def ach(structure, fields):
"""Get field from achievements structure."""
field = fields.pop(0)
if structure:
if hasattr(structure, field):
structure = getattr(structure, field)
if not fields:
return structure
return ach(structure, fields)
retur... | python | def ach(structure, fields):
"""Get field from achievements structure."""
field = fields.pop(0)
if structure:
if hasattr(structure, field):
structure = getattr(structure, field)
if not fields:
return structure
return ach(structure, fields)
retur... | [
"def",
"ach",
"(",
"structure",
",",
"fields",
")",
":",
"field",
"=",
"fields",
".",
"pop",
"(",
"0",
")",
"if",
"structure",
":",
"if",
"hasattr",
"(",
"structure",
",",
"field",
")",
":",
"structure",
"=",
"getattr",
"(",
"structure",
",",
"field"... | Get field from achievements structure. | [
"Get",
"field",
"from",
"achievements",
"structure",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L89-L98 | train | Get field from achievements structure. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_postgame | def get_postgame(self):
"""Get postgame structure."""
if self._cache['postgame'] is not None:
return self._cache['postgame']
self._handle.seek(0)
try:
self._cache['postgame'] = parse_postgame(self._handle, self.size)
return self._cache['postgame']
... | python | def get_postgame(self):
"""Get postgame structure."""
if self._cache['postgame'] is not None:
return self._cache['postgame']
self._handle.seek(0)
try:
self._cache['postgame'] = parse_postgame(self._handle, self.size)
return self._cache['postgame']
... | [
"def",
"get_postgame",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cache",
"[",
"'postgame'",
"]",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_cache",
"[",
"'postgame'",
"]",
"self",
".",
"_handle",
".",
"seek",
"(",
"0",
")",
"try",
":",
"s... | Get postgame structure. | [
"Get",
"postgame",
"structure",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L138-L150 | train | Get postgame structure. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_duration | def get_duration(self):
"""Get game duration."""
postgame = self.get_postgame()
if postgame:
return postgame.duration_int * 1000
duration = self._header.initial.restore_time
try:
while self._handle.tell() < self.size:
operation = mgz.body.o... | python | def get_duration(self):
"""Get game duration."""
postgame = self.get_postgame()
if postgame:
return postgame.duration_int * 1000
duration = self._header.initial.restore_time
try:
while self._handle.tell() < self.size:
operation = mgz.body.o... | [
"def",
"get_duration",
"(",
"self",
")",
":",
"postgame",
"=",
"self",
".",
"get_postgame",
"(",
")",
"if",
"postgame",
":",
"return",
"postgame",
".",
"duration_int",
"*",
"1000",
"duration",
"=",
"self",
".",
"_header",
".",
"initial",
".",
"restore_time... | Get game duration. | [
"Get",
"game",
"duration",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L152-L169 | train | Get game duration. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_restored | def get_restored(self):
"""Check for restored game."""
return self._header.initial.restore_time > 0, self._header.initial.restore_time | python | def get_restored(self):
"""Check for restored game."""
return self._header.initial.restore_time > 0, self._header.initial.restore_time | [
"def",
"get_restored",
"(",
"self",
")",
":",
"return",
"self",
".",
"_header",
".",
"initial",
".",
"restore_time",
">",
"0",
",",
"self",
".",
"_header",
".",
"initial",
".",
"restore_time"
] | Check for restored game. | [
"Check",
"for",
"restored",
"game",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L171-L173 | train | Check for restored game. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_version | def get_version(self):
"""Get game version."""
return mgz.const.VERSIONS[self._header.version], str(self._header.sub_version)[:5] | python | def get_version(self):
"""Get game version."""
return mgz.const.VERSIONS[self._header.version], str(self._header.sub_version)[:5] | [
"def",
"get_version",
"(",
"self",
")",
":",
"return",
"mgz",
".",
"const",
".",
"VERSIONS",
"[",
"self",
".",
"_header",
".",
"version",
"]",
",",
"str",
"(",
"self",
".",
"_header",
".",
"sub_version",
")",
"[",
":",
"5",
"]"
] | Get game version. | [
"Get",
"game",
"version",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L175-L177 | train | Get game version. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_dataset | def get_dataset(self):
"""Get dataset."""
sample = self._header.initial.players[0].attributes.player_stats
if 'mod' in sample and sample.mod['id'] > 0:
return sample.mod
elif 'trickle_food' in sample and sample.trickle_food:
return {
'id': 1,
... | python | def get_dataset(self):
"""Get dataset."""
sample = self._header.initial.players[0].attributes.player_stats
if 'mod' in sample and sample.mod['id'] > 0:
return sample.mod
elif 'trickle_food' in sample and sample.trickle_food:
return {
'id': 1,
... | [
"def",
"get_dataset",
"(",
"self",
")",
":",
"sample",
"=",
"self",
".",
"_header",
".",
"initial",
".",
"players",
"[",
"0",
"]",
".",
"attributes",
".",
"player_stats",
"if",
"'mod'",
"in",
"sample",
"and",
"sample",
".",
"mod",
"[",
"'id'",
"]",
"... | Get dataset. | [
"Get",
"dataset",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L179-L194 | train | Get dataset. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_teams | def get_teams(self):
"""Get teams."""
if self._cache['teams']:
return self._cache['teams']
teams = []
for j, player in enumerate(self._header.initial.players):
added = False
for i in range(0, len(self._header.initial.players)):
if playe... | python | def get_teams(self):
"""Get teams."""
if self._cache['teams']:
return self._cache['teams']
teams = []
for j, player in enumerate(self._header.initial.players):
added = False
for i in range(0, len(self._header.initial.players)):
if playe... | [
"def",
"get_teams",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cache",
"[",
"'teams'",
"]",
":",
"return",
"self",
".",
"_cache",
"[",
"'teams'",
"]",
"teams",
"=",
"[",
"]",
"for",
"j",
",",
"player",
"in",
"enumerate",
"(",
"self",
".",
"_header... | Get teams. | [
"Get",
"teams",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L200-L231 | train | Get teams. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_diplomacy | def get_diplomacy(self):
"""Compute diplomacy."""
if not self._cache['teams']:
self.get_teams()
player_num = 0
computer_num = 0
for player in self._header.scenario.game_settings.player_info:
if player.type == 'human':
player_num += 1
... | python | def get_diplomacy(self):
"""Compute diplomacy."""
if not self._cache['teams']:
self.get_teams()
player_num = 0
computer_num = 0
for player in self._header.scenario.game_settings.player_info:
if player.type == 'human':
player_num += 1
... | [
"def",
"get_diplomacy",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_cache",
"[",
"'teams'",
"]",
":",
"self",
".",
"get_teams",
"(",
")",
"player_num",
"=",
"0",
"computer_num",
"=",
"0",
"for",
"player",
"in",
"self",
".",
"_header",
".",
"sc... | Compute diplomacy. | [
"Compute",
"diplomacy",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L233-L263 | train | Compute diplomacy. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_achievements | def get_achievements(self, name):
"""Get achievements for a player.
Must match on name, not index, since order is not always the same.
"""
postgame = self.get_postgame()
if not postgame:
return None
for achievements in postgame.achievements:
# ach... | python | def get_achievements(self, name):
"""Get achievements for a player.
Must match on name, not index, since order is not always the same.
"""
postgame = self.get_postgame()
if not postgame:
return None
for achievements in postgame.achievements:
# ach... | [
"def",
"get_achievements",
"(",
"self",
",",
"name",
")",
":",
"postgame",
"=",
"self",
".",
"get_postgame",
"(",
")",
"if",
"not",
"postgame",
":",
"return",
"None",
"for",
"achievements",
"in",
"postgame",
".",
"achievements",
":",
"# achievements player nam... | Get achievements for a player.
Must match on name, not index, since order is not always the same. | [
"Get",
"achievements",
"for",
"a",
"player",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L265-L277 | train | Get achievements for a player. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_players | def get_players(self):
"""Get basic player info."""
ratings = self.get_ratings()
for i, player in enumerate(self._header.initial.players[1:]):
achievements = self.get_achievements(player.attributes.player_name)
if achievements:
winner = achievements.victor... | python | def get_players(self):
"""Get basic player info."""
ratings = self.get_ratings()
for i, player in enumerate(self._header.initial.players[1:]):
achievements = self.get_achievements(player.attributes.player_name)
if achievements:
winner = achievements.victor... | [
"def",
"get_players",
"(",
"self",
")",
":",
"ratings",
"=",
"self",
".",
"get_ratings",
"(",
")",
"for",
"i",
",",
"player",
"in",
"enumerate",
"(",
"self",
".",
"_header",
".",
"initial",
".",
"players",
"[",
"1",
":",
"]",
")",
":",
"achievements"... | Get basic player info. | [
"Get",
"basic",
"player",
"info",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L279-L342 | train | Get basic player info. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary._process_body | def _process_body(self):
"""Get Voobly ladder.
This is expensive if the rec is not from Voobly,
since it will search the whole file. Returns tuple,
(from_voobly, ladder_name, rated, ratings).
"""
start_time = time.time()
ratings = {}
encoding = self.get_e... | python | def _process_body(self):
"""Get Voobly ladder.
This is expensive if the rec is not from Voobly,
since it will search the whole file. Returns tuple,
(from_voobly, ladder_name, rated, ratings).
"""
start_time = time.time()
ratings = {}
encoding = self.get_e... | [
"def",
"_process_body",
"(",
"self",
")",
":",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"ratings",
"=",
"{",
"}",
"encoding",
"=",
"self",
".",
"get_encoding",
"(",
")",
"checksums",
"=",
"[",
"]",
"ladder",
"=",
"None",
"voobly",
"=",
"Fals... | Get Voobly ladder.
This is expensive if the rec is not from Voobly,
since it will search the whole file. Returns tuple,
(from_voobly, ladder_name, rated, ratings). | [
"Get",
"Voobly",
"ladder",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L353-L403 | train | Process the body of a Voobly ladder. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_settings | def get_settings(self):
"""Get settings."""
postgame = self.get_postgame()
return {
'type': (
self._header.lobby.game_type_id,
self._header.lobby.game_type
),
'difficulty': (
self._header.scenario.game_settings.d... | python | def get_settings(self):
"""Get settings."""
postgame = self.get_postgame()
return {
'type': (
self._header.lobby.game_type_id,
self._header.lobby.game_type
),
'difficulty': (
self._header.scenario.game_settings.d... | [
"def",
"get_settings",
"(",
"self",
")",
":",
"postgame",
"=",
"self",
".",
"get_postgame",
"(",
")",
"return",
"{",
"'type'",
":",
"(",
"self",
".",
"_header",
".",
"lobby",
".",
"game_type_id",
",",
"self",
".",
"_header",
".",
"lobby",
".",
"game_ty... | Get settings. | [
"Get",
"settings",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L405-L444 | train | Get settings. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_map | def get_map(self):
"""Get the map metadata."""
if self._cache['map']:
return self._cache['map']
map_id = self._header.scenario.game_settings.map_id
instructions = self._header.scenario.messages.instructions
size = mgz.const.MAP_SIZES.get(self._header.map_info.size_x)
... | python | def get_map(self):
"""Get the map metadata."""
if self._cache['map']:
return self._cache['map']
map_id = self._header.scenario.game_settings.map_id
instructions = self._header.scenario.messages.instructions
size = mgz.const.MAP_SIZES.get(self._header.map_info.size_x)
... | [
"def",
"get_map",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cache",
"[",
"'map'",
"]",
":",
"return",
"self",
".",
"_cache",
"[",
"'map'",
"]",
"map_id",
"=",
"self",
".",
"_header",
".",
"scenario",
".",
"game_settings",
".",
"map_id",
"instructions... | Get the map metadata. | [
"Get",
"the",
"map",
"metadata",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L461-L533 | train | Get the map metadata. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_completed | def get_completed(self):
"""Determine if the game was completed.
If there's a postgame, it will indicate completion.
If there is no postgame, guess based on resignation.
"""
postgame = self.get_postgame()
if postgame:
return postgame.complete
else:
... | python | def get_completed(self):
"""Determine if the game was completed.
If there's a postgame, it will indicate completion.
If there is no postgame, guess based on resignation.
"""
postgame = self.get_postgame()
if postgame:
return postgame.complete
else:
... | [
"def",
"get_completed",
"(",
"self",
")",
":",
"postgame",
"=",
"self",
".",
"get_postgame",
"(",
")",
"if",
"postgame",
":",
"return",
"postgame",
".",
"complete",
"else",
":",
"return",
"True",
"if",
"self",
".",
"_cache",
"[",
"'resigned'",
"]",
"else... | Determine if the game was completed.
If there's a postgame, it will indicate completion.
If there is no postgame, guess based on resignation. | [
"Determine",
"if",
"the",
"game",
"was",
"completed",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L535-L545 | train | Determine if the game was completed. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.get_mirror | def get_mirror(self):
"""Determine mirror match."""
mirror = False
if self.get_diplomacy()['1v1']:
civs = set()
for data in self.get_players():
civs.add(data['civilization'])
mirror = (len(civs) == 1)
return mirror | python | def get_mirror(self):
"""Determine mirror match."""
mirror = False
if self.get_diplomacy()['1v1']:
civs = set()
for data in self.get_players():
civs.add(data['civilization'])
mirror = (len(civs) == 1)
return mirror | [
"def",
"get_mirror",
"(",
"self",
")",
":",
"mirror",
"=",
"False",
"if",
"self",
".",
"get_diplomacy",
"(",
")",
"[",
"'1v1'",
"]",
":",
"civs",
"=",
"set",
"(",
")",
"for",
"data",
"in",
"self",
".",
"get_players",
"(",
")",
":",
"civs",
".",
"... | Determine mirror match. | [
"Determine",
"mirror",
"match",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L547-L555 | train | Determine mirror match. |
happyleavesaoc/aoc-mgz | mgz/summary.py | Summary.guess_winner | def guess_winner(self, i):
"""Guess if a player won.
Find what team the player was on. If anyone
on their team resigned, assume the player lost.
"""
for team in self.get_teams():
if i not in team:
continue
for p in team:
if... | python | def guess_winner(self, i):
"""Guess if a player won.
Find what team the player was on. If anyone
on their team resigned, assume the player lost.
"""
for team in self.get_teams():
if i not in team:
continue
for p in team:
if... | [
"def",
"guess_winner",
"(",
"self",
",",
"i",
")",
":",
"for",
"team",
"in",
"self",
".",
"get_teams",
"(",
")",
":",
"if",
"i",
"not",
"in",
"team",
":",
"continue",
"for",
"p",
"in",
"team",
":",
"if",
"p",
"in",
"self",
".",
"_cache",
"[",
"... | Guess if a player won.
Find what team the player was on. If anyone
on their team resigned, assume the player lost. | [
"Guess",
"if",
"a",
"player",
"won",
"."
] | 13fc379cc062d7640bfa028eed9c0d45d37a7b2b | https://github.com/happyleavesaoc/aoc-mgz/blob/13fc379cc062d7640bfa028eed9c0d45d37a7b2b/mgz/summary.py#L557-L569 | train | Guess if a player won. |
fernandojunior/python-pattern-observer | observer.py | Event.on | def on(self, handler):
"""Attach a handler (any Python callable) for the event."""
if not hasattr(handler, '__call__'):
raise TypeError('handler is not a callable object.')
self.handlers.add(handler) | python | def on(self, handler):
"""Attach a handler (any Python callable) for the event."""
if not hasattr(handler, '__call__'):
raise TypeError('handler is not a callable object.')
self.handlers.add(handler) | [
"def",
"on",
"(",
"self",
",",
"handler",
")",
":",
"if",
"not",
"hasattr",
"(",
"handler",
",",
"'__call__'",
")",
":",
"raise",
"TypeError",
"(",
"'handler is not a callable object.'",
")",
"self",
".",
"handlers",
".",
"add",
"(",
"handler",
")"
] | Attach a handler (any Python callable) for the event. | [
"Attach",
"a",
"handler",
"(",
"any",
"Python",
"callable",
")",
"for",
"the",
"event",
"."
] | 9acb029dd6c9276830ea2d7655bbb80eed8e95fa | https://github.com/fernandojunior/python-pattern-observer/blob/9acb029dd6c9276830ea2d7655bbb80eed8e95fa/observer.py#L33-L37 | train | Attach a handler for the event. |
fernandojunior/python-pattern-observer | observer.py | Event.trigger | def trigger(self, *args, **kwargs):
"""Execute the handlers with a message, if any."""
for h in self.handlers:
h(*args, **kwargs) | python | def trigger(self, *args, **kwargs):
"""Execute the handlers with a message, if any."""
for h in self.handlers:
h(*args, **kwargs) | [
"def",
"trigger",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"h",
"in",
"self",
".",
"handlers",
":",
"h",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | Execute the handlers with a message, if any. | [
"Execute",
"the",
"handlers",
"with",
"a",
"message",
"if",
"any",
"."
] | 9acb029dd6c9276830ea2d7655bbb80eed8e95fa | https://github.com/fernandojunior/python-pattern-observer/blob/9acb029dd6c9276830ea2d7655bbb80eed8e95fa/observer.py#L43-L46 | train | Execute the handlers with a message. |
fernandojunior/python-pattern-observer | observer.py | Observable.on | def on(self, event, handler=None):
"""Create, add or update an event with a handler or more attached."""
if isinstance(event, str) and ' ' in event: # event is list str-based
self.on(event.split(' '), handler)
elif isinstance(event, list): # many events contains same handler
... | python | def on(self, event, handler=None):
"""Create, add or update an event with a handler or more attached."""
if isinstance(event, str) and ' ' in event: # event is list str-based
self.on(event.split(' '), handler)
elif isinstance(event, list): # many events contains same handler
... | [
"def",
"on",
"(",
"self",
",",
"event",
",",
"handler",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"event",
",",
"str",
")",
"and",
"' '",
"in",
"event",
":",
"# event is list str-based",
"self",
".",
"on",
"(",
"event",
".",
"split",
"(",
"' '"... | Create, add or update an event with a handler or more attached. | [
"Create",
"add",
"or",
"update",
"an",
"event",
"with",
"a",
"handler",
"or",
"more",
"attached",
"."
] | 9acb029dd6c9276830ea2d7655bbb80eed8e95fa | https://github.com/fernandojunior/python-pattern-observer/blob/9acb029dd6c9276830ea2d7655bbb80eed8e95fa/observer.py#L59-L78 | train | Create or update an event with a handler or more attached. |
fernandojunior/python-pattern-observer | observer.py | Observable.off | def off(self, event, handler=None):
"""Remove an event or a handler from it."""
if handler:
self.events[event].off(handler)
else:
del self.events[event]
delattr(self, event) | python | def off(self, event, handler=None):
"""Remove an event or a handler from it."""
if handler:
self.events[event].off(handler)
else:
del self.events[event]
delattr(self, event) | [
"def",
"off",
"(",
"self",
",",
"event",
",",
"handler",
"=",
"None",
")",
":",
"if",
"handler",
":",
"self",
".",
"events",
"[",
"event",
"]",
".",
"off",
"(",
"handler",
")",
"else",
":",
"del",
"self",
".",
"events",
"[",
"event",
"]",
"delatt... | Remove an event or a handler from it. | [
"Remove",
"an",
"event",
"or",
"a",
"handler",
"from",
"it",
"."
] | 9acb029dd6c9276830ea2d7655bbb80eed8e95fa | https://github.com/fernandojunior/python-pattern-observer/blob/9acb029dd6c9276830ea2d7655bbb80eed8e95fa/observer.py#L80-L86 | train | Remove an event or a handler from it. |
fernandojunior/python-pattern-observer | observer.py | Observable.trigger | def trigger(self, *args, **kargs):
"""
Execute all event handlers with optional arguments for the observable.
"""
event = args[0]
if isinstance(event, str) and ' ' in event:
event = event.split(' ') # split event names ...
if isinstance(event, list): # eve... | python | def trigger(self, *args, **kargs):
"""
Execute all event handlers with optional arguments for the observable.
"""
event = args[0]
if isinstance(event, str) and ' ' in event:
event = event.split(' ') # split event names ...
if isinstance(event, list): # eve... | [
"def",
"trigger",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kargs",
")",
":",
"event",
"=",
"args",
"[",
"0",
"]",
"if",
"isinstance",
"(",
"event",
",",
"str",
")",
"and",
"' '",
"in",
"event",
":",
"event",
"=",
"event",
".",
"split",
"(... | Execute all event handlers with optional arguments for the observable. | [
"Execute",
"all",
"event",
"handlers",
"with",
"optional",
"arguments",
"for",
"the",
"observable",
"."
] | 9acb029dd6c9276830ea2d7655bbb80eed8e95fa | https://github.com/fernandojunior/python-pattern-observer/blob/9acb029dd6c9276830ea2d7655bbb80eed8e95fa/observer.py#L88-L101 | train | Execute all event handlers with optional arguments for the observable. |
bfarr/kombine | kombine/interruptible_pool.py | _initializer_wrapper | def _initializer_wrapper(initializer, *args):
"""
Ignore SIGINT. During typical keyboard interrupts, the parent does the
killing.
"""
signal.signal(signal.SIGINT, signal.SIG_IGN)
if initializer is not None:
initializer(*args) | python | def _initializer_wrapper(initializer, *args):
"""
Ignore SIGINT. During typical keyboard interrupts, the parent does the
killing.
"""
signal.signal(signal.SIGINT, signal.SIG_IGN)
if initializer is not None:
initializer(*args) | [
"def",
"_initializer_wrapper",
"(",
"initializer",
",",
"*",
"args",
")",
":",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGINT",
",",
"signal",
".",
"SIG_IGN",
")",
"if",
"initializer",
"is",
"not",
"None",
":",
"initializer",
"(",
"*",
"args",
")"
... | Ignore SIGINT. During typical keyboard interrupts, the parent does the
killing. | [
"Ignore",
"SIGINT",
".",
"During",
"typical",
"keyboard",
"interrupts",
"the",
"parent",
"does",
"the",
"killing",
"."
] | 50c946dee5da33e7baab71d9bd6c265ff02ffb13 | https://github.com/bfarr/kombine/blob/50c946dee5da33e7baab71d9bd6c265ff02ffb13/kombine/interruptible_pool.py#L20-L27 | train | Wrapper for the initializer function. |
networks-lab/tidyextractors | tidyextractors/base_extractor.py | BaseExtractor._col_type_set | def _col_type_set(self, col, df):
"""
Determines the set of types present in a DataFrame column.
:param str col: A column name.
:param pandas.DataFrame df: The dataset. Usually ``self._data``.
:return: A set of Types.
"""
type_set = set()
if df[col].dtype... | python | def _col_type_set(self, col, df):
"""
Determines the set of types present in a DataFrame column.
:param str col: A column name.
:param pandas.DataFrame df: The dataset. Usually ``self._data``.
:return: A set of Types.
"""
type_set = set()
if df[col].dtype... | [
"def",
"_col_type_set",
"(",
"self",
",",
"col",
",",
"df",
")",
":",
"type_set",
"=",
"set",
"(",
")",
"if",
"df",
"[",
"col",
"]",
".",
"dtype",
"==",
"np",
".",
"dtype",
"(",
"object",
")",
":",
"unindexed_col",
"=",
"list",
"(",
"df",
"[",
... | Determines the set of types present in a DataFrame column.
:param str col: A column name.
:param pandas.DataFrame df: The dataset. Usually ``self._data``.
:return: A set of Types. | [
"Determines",
"the",
"set",
"of",
"types",
"present",
"in",
"a",
"DataFrame",
"column",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/base_extractor.py#L84-L103 | train | Determines the set of types present in a DataFrame column. |
networks-lab/tidyextractors | tidyextractors/base_extractor.py | BaseExtractor._drop_collections | def _drop_collections(self, df):
"""
Drops columns containing collections (i.e. sets, dicts, lists) from a DataFrame.
:param pandas.DataFrame df: Usually self._data.
:return: pandas.DataFrame
"""
all_cols = df.columns
keep_cols = []
# Check whether each ... | python | def _drop_collections(self, df):
"""
Drops columns containing collections (i.e. sets, dicts, lists) from a DataFrame.
:param pandas.DataFrame df: Usually self._data.
:return: pandas.DataFrame
"""
all_cols = df.columns
keep_cols = []
# Check whether each ... | [
"def",
"_drop_collections",
"(",
"self",
",",
"df",
")",
":",
"all_cols",
"=",
"df",
".",
"columns",
"keep_cols",
"=",
"[",
"]",
"# Check whether each column contains collections.",
"for",
"c",
"in",
"all_cols",
":",
"if",
"len",
"(",
"self",
".",
"_col_type_s... | Drops columns containing collections (i.e. sets, dicts, lists) from a DataFrame.
:param pandas.DataFrame df: Usually self._data.
:return: pandas.DataFrame | [
"Drops",
"columns",
"containing",
"collections",
"(",
"i",
".",
"e",
".",
"sets",
"dicts",
"lists",
")",
"from",
"a",
"DataFrame",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/base_extractor.py#L105-L119 | train | Drops columns containing collections i. e. sets dicts lists |
networks-lab/tidyextractors | tidyextractors/base_extractor.py | BaseExtractor.raw | def raw(self, drop_collections = False):
"""
Produces the extractor object's data as it is stored internally.
:param bool drop_collections: Defaults to False. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame
"""
base_df = self._... | python | def raw(self, drop_collections = False):
"""
Produces the extractor object's data as it is stored internally.
:param bool drop_collections: Defaults to False. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame
"""
base_df = self._... | [
"def",
"raw",
"(",
"self",
",",
"drop_collections",
"=",
"False",
")",
":",
"base_df",
"=",
"self",
".",
"_data",
"if",
"drop_collections",
"is",
"True",
":",
"out_df",
"=",
"self",
".",
"_drop_collections",
"(",
"base_df",
")",
"else",
":",
"out_df",
"=... | Produces the extractor object's data as it is stored internally.
:param bool drop_collections: Defaults to False. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame | [
"Produces",
"the",
"extractor",
"object",
"s",
"data",
"as",
"it",
"is",
"stored",
"internally",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/base_extractor.py#L121-L134 | train | Produces the extractor object s data as it is stored internally. |
networks-lab/tidyextractors | tidyextractors/base_extractor.py | BaseExtractor.expand_on | def expand_on(self, col1, col2, rename1 = None, rename2 = None, drop = [], drop_collections = False):
"""
Returns a reshaped version of extractor's data, where unique combinations of values from col1 and col2
are given individual rows.
Example function call from ``tidymbox``:
.... | python | def expand_on(self, col1, col2, rename1 = None, rename2 = None, drop = [], drop_collections = False):
"""
Returns a reshaped version of extractor's data, where unique combinations of values from col1 and col2
are given individual rows.
Example function call from ``tidymbox``:
.... | [
"def",
"expand_on",
"(",
"self",
",",
"col1",
",",
"col2",
",",
"rename1",
"=",
"None",
",",
"rename2",
"=",
"None",
",",
"drop",
"=",
"[",
"]",
",",
"drop_collections",
"=",
"False",
")",
":",
"# Assumption 1: Expanded columns are either atomic are built in col... | Returns a reshaped version of extractor's data, where unique combinations of values from col1 and col2
are given individual rows.
Example function call from ``tidymbox``:
.. code-block:: python
self.expand_on('From', 'To', ['MessageID', 'Recipient'], rename1='From', rename2='Recip... | [
"Returns",
"a",
"reshaped",
"version",
"of",
"extractor",
"s",
"data",
"where",
"unique",
"combinations",
"of",
"values",
"from",
"col1",
"and",
"col2",
"are",
"given",
"individual",
"rows",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/base_extractor.py#L136-L317 | train | Expand the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes of the related attributes. |
TkTech/Jawa | jawa/classloader.py | _walk | def _walk(path, follow_links=False, maximum_depth=None):
"""A modified os.walk with support for maximum traversal depth."""
root_level = path.rstrip(os.path.sep).count(os.path.sep)
for root, dirs, files in os.walk(path, followlinks=follow_links):
yield root, dirs, files
if maximum_depth is N... | python | def _walk(path, follow_links=False, maximum_depth=None):
"""A modified os.walk with support for maximum traversal depth."""
root_level = path.rstrip(os.path.sep).count(os.path.sep)
for root, dirs, files in os.walk(path, followlinks=follow_links):
yield root, dirs, files
if maximum_depth is N... | [
"def",
"_walk",
"(",
"path",
",",
"follow_links",
"=",
"False",
",",
"maximum_depth",
"=",
"None",
")",
":",
"root_level",
"=",
"path",
".",
"rstrip",
"(",
"os",
".",
"path",
".",
"sep",
")",
".",
"count",
"(",
"os",
".",
"path",
".",
"sep",
")",
... | A modified os.walk with support for maximum traversal depth. | [
"A",
"modified",
"os",
".",
"walk",
"with",
"support",
"for",
"maximum",
"traversal",
"depth",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L14-L23 | train | A modified os. walk with support for maximum traversal depth. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.update | def update(self, *sources, follow_symlinks: bool=False,
maximum_depth: int=20):
"""Add one or more ClassFile sources to the class loader.
If a given source is a directory path, it is traversed up to the
maximum set depth and all files under it are added to the class loader
... | python | def update(self, *sources, follow_symlinks: bool=False,
maximum_depth: int=20):
"""Add one or more ClassFile sources to the class loader.
If a given source is a directory path, it is traversed up to the
maximum set depth and all files under it are added to the class loader
... | [
"def",
"update",
"(",
"self",
",",
"*",
"sources",
",",
"follow_symlinks",
":",
"bool",
"=",
"False",
",",
"maximum_depth",
":",
"int",
"=",
"20",
")",
":",
"for",
"source",
"in",
"sources",
":",
"if",
"isinstance",
"(",
"source",
",",
"self",
".",
"... | Add one or more ClassFile sources to the class loader.
If a given source is a directory path, it is traversed up to the
maximum set depth and all files under it are added to the class loader
lookup table.
If a given source is a .jar or .zip file it will be opened and the
file i... | [
"Add",
"one",
"or",
"more",
"ClassFile",
"sources",
"to",
"the",
"class",
"loader",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L62-L105 | train | Adds one or more ClassFile sources to the class loader lookup table. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.open | def open(self, path: str, mode: str='r') -> IO:
"""Open an IO-like object for `path`.
.. note::
Mode *must* be either 'r' or 'w', as the underlying objects
do not understand the full range of modes.
:param path: The path to open.
:param mode: The mode of the fi... | python | def open(self, path: str, mode: str='r') -> IO:
"""Open an IO-like object for `path`.
.. note::
Mode *must* be either 'r' or 'w', as the underlying objects
do not understand the full range of modes.
:param path: The path to open.
:param mode: The mode of the fi... | [
"def",
"open",
"(",
"self",
",",
"path",
":",
"str",
",",
"mode",
":",
"str",
"=",
"'r'",
")",
"->",
"IO",
":",
"entry",
"=",
"self",
".",
"path_map",
".",
"get",
"(",
"path",
")",
"if",
"entry",
"is",
"None",
":",
"raise",
"FileNotFoundError",
"... | Open an IO-like object for `path`.
.. note::
Mode *must* be either 'r' or 'w', as the underlying objects
do not understand the full range of modes.
:param path: The path to open.
:param mode: The mode of the file being opened, either 'r' or 'w'. | [
"Open",
"an",
"IO",
"-",
"like",
"object",
"for",
"path",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L108-L129 | train | Open an IO - like object for the given path. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.load | def load(self, path: str) -> ClassFile:
"""Load the class at `path` and return it.
Load will attempt to load the file at `path` and `path` + .class
before failing.
:param path: Fully-qualified path to a ClassFile.
"""
# Try to refresh the class from the cache, loading i... | python | def load(self, path: str) -> ClassFile:
"""Load the class at `path` and return it.
Load will attempt to load the file at `path` and `path` + .class
before failing.
:param path: Fully-qualified path to a ClassFile.
"""
# Try to refresh the class from the cache, loading i... | [
"def",
"load",
"(",
"self",
",",
"path",
":",
"str",
")",
"->",
"ClassFile",
":",
"# Try to refresh the class from the cache, loading it from disk",
"# if not found.",
"try",
":",
"r",
"=",
"self",
".",
"class_cache",
".",
"pop",
"(",
"path",
")",
"except",
"Key... | Load the class at `path` and return it.
Load will attempt to load the file at `path` and `path` + .class
before failing.
:param path: Fully-qualified path to a ClassFile. | [
"Load",
"the",
"class",
"at",
"path",
"and",
"return",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L131-L159 | train | Load the class at path and return it. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.dependencies | def dependencies(self, path: str) -> Set[str]:
"""Returns a set of all classes referenced by the ClassFile at
`path` without reading the entire ClassFile.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
... | python | def dependencies(self, path: str) -> Set[str]:
"""Returns a set of all classes referenced by the ClassFile at
`path` without reading the entire ClassFile.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
... | [
"def",
"dependencies",
"(",
"self",
",",
"path",
":",
"str",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"return",
"set",
"(",
"c",
".",
"name",
".",
"value",
"for",
"c",
"in",
"self",
".",
"search_constant_pool",
"(",
"path",
"=",
"path",
",",
"type_"... | Returns a set of all classes referenced by the ClassFile at
`path` without reading the entire ClassFile.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
:param path: Fully-qualified path to a ClassFile. | [
"Returns",
"a",
"set",
"of",
"all",
"classes",
"referenced",
"by",
"the",
"ClassFile",
"at",
"path",
"without",
"reading",
"the",
"entire",
"ClassFile",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L166-L178 | train | Returns a set of all classes referenced by the ClassFile at
path without reading the entire ClassFile. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.search_constant_pool | def search_constant_pool(self, *, path: str, **options):
"""Partially load the class at `path`, yield all matching constants
from the ConstantPool.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
:par... | python | def search_constant_pool(self, *, path: str, **options):
"""Partially load the class at `path`, yield all matching constants
from the ConstantPool.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
:par... | [
"def",
"search_constant_pool",
"(",
"self",
",",
"*",
",",
"path",
":",
"str",
",",
"*",
"*",
"options",
")",
":",
"with",
"self",
".",
"open",
"(",
"f'{path}.class'",
")",
"as",
"source",
":",
"# Skip over the magic, minor, and major version.",
"source",
".",... | Partially load the class at `path`, yield all matching constants
from the ConstantPool.
This is an optimization method that does not load a complete ClassFile,
nor does it add the results to the ClassLoader cache.
:param path: Fully-qualified path to a ClassFile.
:param options... | [
"Partially",
"load",
"the",
"class",
"at",
"path",
"yield",
"all",
"matching",
"constants",
"from",
"the",
"ConstantPool",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L180-L195 | train | Partially load the class at path yield all matching constants
from the ConstantPool. |
TkTech/Jawa | jawa/classloader.py | ClassLoader.classes | def classes(self) -> Iterator[str]:
"""Yield the name of all classes discovered in the path map."""
yield from (
c[:-6]
for c in self.path_map.keys() if c.endswith('.class')
) | python | def classes(self) -> Iterator[str]:
"""Yield the name of all classes discovered in the path map."""
yield from (
c[:-6]
for c in self.path_map.keys() if c.endswith('.class')
) | [
"def",
"classes",
"(",
"self",
")",
"->",
"Iterator",
"[",
"str",
"]",
":",
"yield",
"from",
"(",
"c",
"[",
":",
"-",
"6",
"]",
"for",
"c",
"in",
"self",
".",
"path_map",
".",
"keys",
"(",
")",
"if",
"c",
".",
"endswith",
"(",
"'.class'",
")",
... | Yield the name of all classes discovered in the path map. | [
"Yield",
"the",
"name",
"of",
"all",
"classes",
"discovered",
"in",
"the",
"path",
"map",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/classloader.py#L198-L203 | train | Yield the name of all classes discovered in the path map. |
thespacedoctor/polyglot | polyglot/webarchive.py | webarchive.create | def create(self, url, pathToWebarchive):
"""
*create the webarchive object*
**Key Arguments:**
- ``url`` -- the url of the webpage to generate the webarchive for
- ``pathToWebarchive`` -- tthe path to output the the webarchive file to
**Return:**
- ... | python | def create(self, url, pathToWebarchive):
"""
*create the webarchive object*
**Key Arguments:**
- ``url`` -- the url of the webpage to generate the webarchive for
- ``pathToWebarchive`` -- tthe path to output the the webarchive file to
**Return:**
- ... | [
"def",
"create",
"(",
"self",
",",
"url",
",",
"pathToWebarchive",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``create`` method'",
")",
"from",
"subprocess",
"import",
"Popen",
",",
"PIPE",
",",
"STDOUT",
"webarchiver",
"=",
"self",
".",... | *create the webarchive object*
**Key Arguments:**
- ``url`` -- the url of the webpage to generate the webarchive for
- ``pathToWebarchive`` -- tthe path to output the the webarchive file to
**Return:**
- ``webarchive`` -- the path to the webarchive (or -1 if the ge... | [
"*",
"create",
"the",
"webarchive",
"object",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/webarchive.py#L59-L91 | train | create the webarchive object for a given url and path to a webarchive file |
thespacedoctor/polyglot | polyglot/htmlCleaner.py | htmlCleaner.clean | def clean(
self):
"""*parse and clean the html document with Mercury Parser*
**Return:**
- ``filePath`` -- path to the cleaned HTML document
**Usage:**
See class usage
"""
self.log.debug('starting the ``clean`` method')
url = self.... | python | def clean(
self):
"""*parse and clean the html document with Mercury Parser*
**Return:**
- ``filePath`` -- path to the cleaned HTML document
**Usage:**
See class usage
"""
self.log.debug('starting the ``clean`` method')
url = self.... | [
"def",
"clean",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``clean`` method'",
")",
"url",
"=",
"self",
".",
"url",
"# PARSE THE CONTENT OF THE WEBPAGE AT THE URL",
"parser_response",
"=",
"self",
".",
"_request_parsed_article_from_me... | *parse and clean the html document with Mercury Parser*
**Return:**
- ``filePath`` -- path to the cleaned HTML document
**Usage:**
See class usage | [
"*",
"parse",
"and",
"clean",
"the",
"html",
"document",
"with",
"Mercury",
"Parser",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/htmlCleaner.py#L97-L225 | train | parse and clean the HTML document with Mercury Parser |
thespacedoctor/polyglot | polyglot/htmlCleaner.py | htmlCleaner._request_parsed_article_from_mercury | def _request_parsed_article_from_mercury(
self,
url):
"""* request parsed article from mercury*
**Key Arguments:**
- ``url`` -- the URL to the HTML page to parse and clean
**Return:**
- None
**Usage:**
.. todo::
... | python | def _request_parsed_article_from_mercury(
self,
url):
"""* request parsed article from mercury*
**Key Arguments:**
- ``url`` -- the URL to the HTML page to parse and clean
**Return:**
- None
**Usage:**
.. todo::
... | [
"def",
"_request_parsed_article_from_mercury",
"(",
"self",
",",
"url",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'completed the ````_request_parsed_article_from_mercury`` method'",
")",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
"=",
... | * request parsed article from mercury*
**Key Arguments:**
- ``url`` -- the URL to the HTML page to parse and clean
**Return:**
- None
**Usage:**
.. todo::
- add usage info
- create a sublime snippet for usage
... | [
"*",
"request",
"parsed",
"article",
"from",
"mercury",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/htmlCleaner.py#L227-L269 | train | request parsed article from mercury |
snowman2/pangaea | pangaea/read.py | open_mfdataset | def open_mfdataset(path_to_lsm_files,
lat_var,
lon_var,
time_var,
lat_dim,
lon_dim,
time_dim,
lon_to_180=False,
coords_projected=False,
loader=None,
... | python | def open_mfdataset(path_to_lsm_files,
lat_var,
lon_var,
time_var,
lat_dim,
lon_dim,
time_dim,
lon_to_180=False,
coords_projected=False,
loader=None,
... | [
"def",
"open_mfdataset",
"(",
"path_to_lsm_files",
",",
"lat_var",
",",
"lon_var",
",",
"time_var",
",",
"lat_dim",
",",
"lon_dim",
",",
"time_dim",
",",
"lon_to_180",
"=",
"False",
",",
"coords_projected",
"=",
"False",
",",
"loader",
"=",
"None",
",",
"eng... | Wrapper to open land surface model netcdf files
using :func:`xarray.open_mfdataset`.
.. warning:: The time dimension and variable will both be
renamed to 'time' to enable slicing.
Parameters
----------
path_to_lsm_files: :obj:`str`
Path to land surface model files with wildcard.
... | [
"Wrapper",
"to",
"open",
"land",
"surface",
"model",
"netcdf",
"files",
"using",
":",
"func",
":",
"xarray",
".",
"open_mfdataset",
"."
] | a304e9a489cfc0bc1c74e7cb50c3335a4f3d596f | https://github.com/snowman2/pangaea/blob/a304e9a489cfc0bc1c74e7cb50c3335a4f3d596f/pangaea/read.py#L18-L145 | train | Wrapper to open land surface model netcdf files using xarray. open_mfdataset. |
thespacedoctor/polyglot | polyglot/markdown/kindle_notebook.py | kindle_notebook.convert | def convert(self):
"""
*convert the kindle_notebook object*
**Return:**
- ``kindle_notebook``
**Usage:**
.. todo::
- add usage info
- create a sublime snippet for usage
- update the package tutorial if needed
.. code-blo... | python | def convert(self):
"""
*convert the kindle_notebook object*
**Return:**
- ``kindle_notebook``
**Usage:**
.. todo::
- add usage info
- create a sublime snippet for usage
- update the package tutorial if needed
.. code-blo... | [
"def",
"convert",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``convert`` method'",
")",
"import",
"codecs",
"pathToReadFile",
"=",
"self",
".",
"kindleExportPath",
"try",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"attemp... | *convert the kindle_notebook object*
**Return:**
- ``kindle_notebook``
**Usage:**
.. todo::
- add usage info
- create a sublime snippet for usage
- update the package tutorial if needed
.. code-block:: python
usage code | [
"*",
"convert",
"the",
"kindle_notebook",
"object",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/markdown/kindle_notebook.py#L82-L201 | train | convert the kindle_notebook object into a python object |
openstack/stacktach-timex | timex/lexer.py | TimexLexer.t_IDENTIFIER | def t_IDENTIFIER(self, t):
r'[a-zA-Z_][a-zA-Z0-9_]*'
t.type = self.reserved_words.get(t.value, 'IDENTIFIER')
return t | python | def t_IDENTIFIER(self, t):
r'[a-zA-Z_][a-zA-Z0-9_]*'
t.type = self.reserved_words.get(t.value, 'IDENTIFIER')
return t | [
"def",
"t_IDENTIFIER",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"type",
"=",
"self",
".",
"reserved_words",
".",
"get",
"(",
"t",
".",
"value",
",",
"'IDENTIFIER'",
")",
"return",
"t"
] | r'[a-zA-Z_][a-zA-Z0-9_]* | [
"r",
"[",
"a",
"-",
"zA",
"-",
"Z_",
"]",
"[",
"a",
"-",
"zA",
"-",
"Z0",
"-",
"9_",
"]",
"*"
] | 2c143c84cf91bc18ce9175022f4d9295e1fee18c | https://github.com/openstack/stacktach-timex/blob/2c143c84cf91bc18ce9175022f4d9295e1fee18c/timex/lexer.py#L87-L90 | train | r Identifier is a reserved word. |
openstack/stacktach-timex | timex/lexer.py | TimexLexer.t_newline | def t_newline(self, t):
r'\n+'
t.lexer.lineno += len(t.value)
self.latest_newline = t.lexpos | python | def t_newline(self, t):
r'\n+'
t.lexer.lineno += len(t.value)
self.latest_newline = t.lexpos | [
"def",
"t_newline",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"len",
"(",
"t",
".",
"value",
")",
"self",
".",
"latest_newline",
"=",
"t",
".",
"lexpos"
] | r'\n+ | [
"r",
"\\",
"n",
"+"
] | 2c143c84cf91bc18ce9175022f4d9295e1fee18c | https://github.com/openstack/stacktach-timex/blob/2c143c84cf91bc18ce9175022f4d9295e1fee18c/timex/lexer.py#L97-L100 | train | r \ n |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor._extract | def _extract(self, source, extract_tweets=True, *args, **kwargs):
"""
Extracts user data Using the twitter API. Mutates _data.
NOTE: TwitterExtractor requires a complete set of Twitter API credentials
to initialize: 'access_token', 'access_secret', 'consumer_key', and 'consumer_secret'.
... | python | def _extract(self, source, extract_tweets=True, *args, **kwargs):
"""
Extracts user data Using the twitter API. Mutates _data.
NOTE: TwitterExtractor requires a complete set of Twitter API credentials
to initialize: 'access_token', 'access_secret', 'consumer_key', and 'consumer_secret'.
... | [
"def",
"_extract",
"(",
"self",
",",
"source",
",",
"extract_tweets",
"=",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Check that the proper API keywords were provided.",
"for",
"cred",
"in",
"[",
"'access_token'",
",",
"'access_secret'",
","... | Extracts user data Using the twitter API. Mutates _data.
NOTE: TwitterExtractor requires a complete set of Twitter API credentials
to initialize: 'access_token', 'access_secret', 'consumer_key', and 'consumer_secret'.
:param list source: A list of user screen name strings.
:param args: ... | [
"Extracts",
"user",
"data",
"Using",
"the",
"twitter",
"API",
".",
"Mutates",
"_data",
".",
"NOTE",
":",
"TwitterExtractor",
"requires",
"a",
"complete",
"set",
"of",
"Twitter",
"API",
"credentials",
"to",
"initialize",
":",
"access_token",
"access_secret",
"con... | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L51-L94 | train | Extract user data using the Twitter API. |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor.users | def users(self, drop_collections = True):
"""
Returns a table of Twitter user data, with "users" as rows/observations.
:param bool drop_collections: Defaults to True. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame
"""
base_df ... | python | def users(self, drop_collections = True):
"""
Returns a table of Twitter user data, with "users" as rows/observations.
:param bool drop_collections: Defaults to True. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame
"""
base_df ... | [
"def",
"users",
"(",
"self",
",",
"drop_collections",
"=",
"True",
")",
":",
"base_df",
"=",
"self",
".",
"_data",
"if",
"drop_collections",
"is",
"True",
":",
"out_df",
"=",
"self",
".",
"_drop_collections",
"(",
"base_df",
")",
"else",
":",
"out_df",
"... | Returns a table of Twitter user data, with "users" as rows/observations.
:param bool drop_collections: Defaults to True. Indicates whether columns with lists/dicts/sets will be dropped.
:return: pandas.DataFrame | [
"Returns",
"a",
"table",
"of",
"Twitter",
"user",
"data",
"with",
"users",
"as",
"rows",
"/",
"observations",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L96-L109 | train | Returns a table of Twitter user data with users as rows and observations as rows and observations. |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor.tweets | def tweets(self):
"""
Returns a table of Twitter user data, with "tweets" as rows/observations.
.. note::
drop_collections is not available for this method, since there are no meaningful collections to keep.
:return: pandas.DataFrame
"""
# I've hard coded ... | python | def tweets(self):
"""
Returns a table of Twitter user data, with "tweets" as rows/observations.
.. note::
drop_collections is not available for this method, since there are no meaningful collections to keep.
:return: pandas.DataFrame
"""
# I've hard coded ... | [
"def",
"tweets",
"(",
"self",
")",
":",
"# I've hard coded these. Seemed like a good idea at the time...",
"# TODO: Fix this.",
"all_columns",
"=",
"[",
"'contributors_enabled'",
",",
"'created_at'",
",",
"'default_profile'",
",",
"'default_profile_image'",
",",
"'description'"... | Returns a table of Twitter user data, with "tweets" as rows/observations.
.. note::
drop_collections is not available for this method, since there are no meaningful collections to keep.
:return: pandas.DataFrame | [
"Returns",
"a",
"table",
"of",
"Twitter",
"user",
"data",
"with",
"tweets",
"as",
"rows",
"/",
"observations",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L111-L149 | train | Returns a table of Twitter user data with tweets as rows and observations. |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor._handle_object | def _handle_object(self, name, obj):
"""
Process an object using twitter_object_handlers_lookup.
Doesn't currently do anything (as of 2017-06-16).
:param str name: Object name
:param obj: An object to be processed
:return: A dictionary of attributes
"""
i... | python | def _handle_object(self, name, obj):
"""
Process an object using twitter_object_handlers_lookup.
Doesn't currently do anything (as of 2017-06-16).
:param str name: Object name
:param obj: An object to be processed
:return: A dictionary of attributes
"""
i... | [
"def",
"_handle_object",
"(",
"self",
",",
"name",
",",
"obj",
")",
":",
"if",
"type",
"(",
"obj",
")",
"in",
"twitter_object_handlers_lookup",
":",
"return",
"twitter_object_handlers_lookup",
"[",
"type",
"(",
"obj",
")",
"]",
"(",
"name",
",",
"obj",
")"... | Process an object using twitter_object_handlers_lookup.
Doesn't currently do anything (as of 2017-06-16).
:param str name: Object name
:param obj: An object to be processed
:return: A dictionary of attributes | [
"Process",
"an",
"object",
"using",
"twitter_object_handlers_lookup",
".",
"Doesn",
"t",
"currently",
"do",
"anything",
"(",
"as",
"of",
"2017",
"-",
"06",
"-",
"16",
")",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L151-L163 | train | Process an object using twitter_object_handlers_lookup. |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor._make_object_dict | def _make_object_dict(self, obj):
"""
Processes an object, exporting its data as a nested dictionary.
:param obj: An object
:return: A nested dictionary of object data
"""
data = {}
for attr in dir(obj):
if attr[0] is not '_' and attr is not 'status':... | python | def _make_object_dict(self, obj):
"""
Processes an object, exporting its data as a nested dictionary.
:param obj: An object
:return: A nested dictionary of object data
"""
data = {}
for attr in dir(obj):
if attr[0] is not '_' and attr is not 'status':... | [
"def",
"_make_object_dict",
"(",
"self",
",",
"obj",
")",
":",
"data",
"=",
"{",
"}",
"for",
"attr",
"in",
"dir",
"(",
"obj",
")",
":",
"if",
"attr",
"[",
"0",
"]",
"is",
"not",
"'_'",
"and",
"attr",
"is",
"not",
"'status'",
":",
"datum",
"=",
... | Processes an object, exporting its data as a nested dictionary.
:param obj: An object
:return: A nested dictionary of object data | [
"Processes",
"an",
"object",
"exporting",
"its",
"data",
"as",
"a",
"nested",
"dictionary",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L165-L178 | train | Processes an object and returns a nested dictionary of object data. |
networks-lab/tidyextractors | tidyextractors/tidytwitter/twitter_extractor.py | TwitterExtractor._make_user_dict | def _make_user_dict(self, username):
"""
Processes a Twitter User object, exporting as a nested dictionary.
Complex values (i.e. objects that aren't int, bool, float, str, or
a collection of such) are converted to strings (i.e. using __str__
or __repr__). To access user data only... | python | def _make_user_dict(self, username):
"""
Processes a Twitter User object, exporting as a nested dictionary.
Complex values (i.e. objects that aren't int, bool, float, str, or
a collection of such) are converted to strings (i.e. using __str__
or __repr__). To access user data only... | [
"def",
"_make_user_dict",
"(",
"self",
",",
"username",
")",
":",
"user",
"=",
"self",
".",
"_api",
".",
"get_user",
"(",
"username",
")",
"return",
"self",
".",
"_make_object_dict",
"(",
"user",
")"
] | Processes a Twitter User object, exporting as a nested dictionary.
Complex values (i.e. objects that aren't int, bool, float, str, or
a collection of such) are converted to strings (i.e. using __str__
or __repr__). To access user data only, use make_user_dict(username)['_json'].
:param ... | [
"Processes",
"a",
"Twitter",
"User",
"object",
"exporting",
"as",
"a",
"nested",
"dictionary",
".",
"Complex",
"values",
"(",
"i",
".",
"e",
".",
"objects",
"that",
"aren",
"t",
"int",
"bool",
"float",
"str",
"or",
"a",
"collection",
"of",
"such",
")",
... | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidytwitter/twitter_extractor.py#L180-L191 | train | Processes a Twitter User object and converts it to a nested dictionary. |
thespacedoctor/polyglot | polyglot/ebook.py | ebook.get | def get(self):
"""
*get the ebook object*
**Return:**
- ``ebook``
**Usage:**
See class docstring for usage
"""
self.log.debug('starting the ``get`` method')
if self.format == "epub":
if self.urlOrPath[:4] == "http" or self.u... | python | def get(self):
"""
*get the ebook object*
**Return:**
- ``ebook``
**Usage:**
See class docstring for usage
"""
self.log.debug('starting the ``get`` method')
if self.format == "epub":
if self.urlOrPath[:4] == "http" or self.u... | [
"def",
"get",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``get`` method'",
")",
"if",
"self",
".",
"format",
"==",
"\"epub\"",
":",
"if",
"self",
".",
"urlOrPath",
"[",
":",
"4",
"]",
"==",
"\"http\"",
"or",
"self",
... | *get the ebook object*
**Return:**
- ``ebook``
**Usage:**
See class docstring for usage | [
"*",
"get",
"the",
"ebook",
"object",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/ebook.py#L144-L186 | train | get the ebook object |
thespacedoctor/polyglot | polyglot/ebook.py | ebook._url_to_epub | def _url_to_epub(
self):
"""*generate the epub book from a URL*
"""
self.log.debug('starting the ``_url_to_epub`` method')
from polyglot import htmlCleaner
cleaner = htmlCleaner(
log=self.log,
settings=self.settings,
url=self.urlOr... | python | def _url_to_epub(
self):
"""*generate the epub book from a URL*
"""
self.log.debug('starting the ``_url_to_epub`` method')
from polyglot import htmlCleaner
cleaner = htmlCleaner(
log=self.log,
settings=self.settings,
url=self.urlOr... | [
"def",
"_url_to_epub",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``_url_to_epub`` method'",
")",
"from",
"polyglot",
"import",
"htmlCleaner",
"cleaner",
"=",
"htmlCleaner",
"(",
"log",
"=",
"self",
".",
"log",
",",
"settings"... | *generate the epub book from a URL* | [
"*",
"generate",
"the",
"epub",
"book",
"from",
"a",
"URL",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/ebook.py#L188-L244 | train | generate the epub book from a URL |
thespacedoctor/polyglot | polyglot/ebook.py | ebook._tmp_html_file | def _tmp_html_file(
self,
content):
"""*create a tmp html file with some content used for the header or footer of the ebook*
**Key Arguments:**
- ``content`` -- the content to include in the HTML file.
"""
self.log.debug('starting the ``_tmp_html_file... | python | def _tmp_html_file(
self,
content):
"""*create a tmp html file with some content used for the header or footer of the ebook*
**Key Arguments:**
- ``content`` -- the content to include in the HTML file.
"""
self.log.debug('starting the ``_tmp_html_file... | [
"def",
"_tmp_html_file",
"(",
"self",
",",
"content",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``_tmp_html_file`` method'",
")",
"content",
"=",
"\"\"\"\n\n<hr>\n<div style=\"text-align: center\">\n%(content)s\n</div>\n<hr>\n\n\"\"\"",
"%",
"locals",
... | *create a tmp html file with some content used for the header or footer of the ebook*
**Key Arguments:**
- ``content`` -- the content to include in the HTML file. | [
"*",
"create",
"a",
"tmp",
"html",
"file",
"with",
"some",
"content",
"used",
"for",
"the",
"header",
"or",
"footer",
"of",
"the",
"ebook",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/ebook.py#L246-L282 | train | Create a tmp html file with some content used for the header or footer of the ebook. |
thespacedoctor/polyglot | polyglot/ebook.py | ebook._epub_to_mobi | def _epub_to_mobi(
self,
epubPath,
deleteEpub=False):
"""*convert the give epub to mobi format using kindlegen*
**Key Arguments:**
- ``epubPath`` -- path to the epub book
- ``deleteEpub`` -- delete the epub when mobi is generated. Default *Fal... | python | def _epub_to_mobi(
self,
epubPath,
deleteEpub=False):
"""*convert the give epub to mobi format using kindlegen*
**Key Arguments:**
- ``epubPath`` -- path to the epub book
- ``deleteEpub`` -- delete the epub when mobi is generated. Default *Fal... | [
"def",
"_epub_to_mobi",
"(",
"self",
",",
"epubPath",
",",
"deleteEpub",
"=",
"False",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``_epub_to_mobi`` method'",
")",
"mobi",
"=",
"epubPath",
".",
"replace",
"(",
"\".epub\"",
",",
"\".mobi\"",... | *convert the give epub to mobi format using kindlegen*
**Key Arguments:**
- ``epubPath`` -- path to the epub book
- ``deleteEpub`` -- delete the epub when mobi is generated. Default *False*
**Return:**
- ``mobi`` -- the path to the generated mobi book | [
"*",
"convert",
"the",
"give",
"epub",
"to",
"mobi",
"format",
"using",
"kindlegen",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/ebook.py#L284-L321 | train | convert the give epub to mobi format using kindlegen |
thespacedoctor/polyglot | polyglot/ebook.py | ebook._docx_to_epub | def _docx_to_epub(
self):
"""*convert docx file to epub*
"""
self.log.debug('starting the ``_docx_to_epub`` method')
if self.footer:
footer = self._tmp_html_file(self.footer)
footer = '"%(footer)s"' % locals()
else:
footer = ""
... | python | def _docx_to_epub(
self):
"""*convert docx file to epub*
"""
self.log.debug('starting the ``_docx_to_epub`` method')
if self.footer:
footer = self._tmp_html_file(self.footer)
footer = '"%(footer)s"' % locals()
else:
footer = ""
... | [
"def",
"_docx_to_epub",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"'starting the ``_docx_to_epub`` method'",
")",
"if",
"self",
".",
"footer",
":",
"footer",
"=",
"self",
".",
"_tmp_html_file",
"(",
"self",
".",
"footer",
")",
"footer",
... | *convert docx file to epub* | [
"*",
"convert",
"docx",
"file",
"to",
"epub",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/ebook.py#L323-L409 | train | converts a docx file to an epub file |
TkTech/Jawa | jawa/fields.py | Field.unpack | def unpack(self, source: IO):
"""
Read the Field from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providi... | python | def unpack(self, source: IO):
"""
Read the Field from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providi... | [
"def",
"unpack",
"(",
"self",
",",
"source",
":",
"IO",
")",
":",
"self",
".",
"access_flags",
".",
"unpack",
"(",
"source",
".",
"read",
"(",
"2",
")",
")",
"self",
".",
"_name_index",
",",
"self",
".",
"_descriptor_index",
"=",
"unpack",
"(",
"'>HH... | Read the Field from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providing `read()` | [
"Read",
"the",
"Field",
"from",
"the",
"file",
"-",
"like",
"object",
"fio",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L59-L72 | train | Read the Field from the file - like object source. |
TkTech/Jawa | jawa/fields.py | Field.pack | def pack(self, out: IO):
"""
Write the Field to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `write(... | python | def pack(self, out: IO):
"""
Write the Field to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `write(... | [
"def",
"pack",
"(",
"self",
",",
"out",
":",
"IO",
")",
":",
"out",
".",
"write",
"(",
"self",
".",
"access_flags",
".",
"pack",
"(",
")",
")",
"out",
".",
"write",
"(",
"pack",
"(",
"'>HH'",
",",
"self",
".",
"_name_index",
",",
"self",
".",
"... | Write the Field to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `write()` | [
"Write",
"the",
"Field",
"to",
"the",
"file",
"-",
"like",
"object",
"out",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L74-L87 | train | Write the Field to the file - like object out. |
TkTech/Jawa | jawa/fields.py | FieldTable.find_and_remove | def find_and_remove(self, f: Callable):
"""
Removes any and all fields for which `f(field)` returns `True`.
"""
self._table = [fld for fld in self._table if not f(fld)] | python | def find_and_remove(self, f: Callable):
"""
Removes any and all fields for which `f(field)` returns `True`.
"""
self._table = [fld for fld in self._table if not f(fld)] | [
"def",
"find_and_remove",
"(",
"self",
",",
"f",
":",
"Callable",
")",
":",
"self",
".",
"_table",
"=",
"[",
"fld",
"for",
"fld",
"in",
"self",
".",
"_table",
"if",
"not",
"f",
"(",
"fld",
")",
"]"
] | Removes any and all fields for which `f(field)` returns `True`. | [
"Removes",
"any",
"and",
"all",
"fields",
"for",
"which",
"f",
"(",
"field",
")",
"returns",
"True",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L98-L102 | train | Removes any and all fields for which f returns True. |
TkTech/Jawa | jawa/fields.py | FieldTable.remove | def remove(self, field: Field):
"""
Removes a `Field` from the table by identity.
"""
self._table = [fld for fld in self._table if fld is not field] | python | def remove(self, field: Field):
"""
Removes a `Field` from the table by identity.
"""
self._table = [fld for fld in self._table if fld is not field] | [
"def",
"remove",
"(",
"self",
",",
"field",
":",
"Field",
")",
":",
"self",
".",
"_table",
"=",
"[",
"fld",
"for",
"fld",
"in",
"self",
".",
"_table",
"if",
"fld",
"is",
"not",
"field",
"]"
] | Removes a `Field` from the table by identity. | [
"Removes",
"a",
"Field",
"from",
"the",
"table",
"by",
"identity",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L104-L108 | train | Removes a Field from the table by identity. |
TkTech/Jawa | jawa/fields.py | FieldTable.create | def create(self, name: str, descriptor: str, value: Constant=None) -> Field:
"""
Creates a new field from `name` and `descriptor`. For example::
>>> from jawa.cf import ClassFile
>>> cf = ClassFile.create('BeerCounter')
>>> field = cf.fields.create('BeerCount', 'I')
... | python | def create(self, name: str, descriptor: str, value: Constant=None) -> Field:
"""
Creates a new field from `name` and `descriptor`. For example::
>>> from jawa.cf import ClassFile
>>> cf = ClassFile.create('BeerCounter')
>>> field = cf.fields.create('BeerCount', 'I')
... | [
"def",
"create",
"(",
"self",
",",
"name",
":",
"str",
",",
"descriptor",
":",
"str",
",",
"value",
":",
"Constant",
"=",
"None",
")",
"->",
"Field",
":",
"field",
"=",
"Field",
"(",
"self",
".",
"_cf",
")",
"name",
"=",
"self",
".",
"_cf",
".",
... | Creates a new field from `name` and `descriptor`. For example::
>>> from jawa.cf import ClassFile
>>> cf = ClassFile.create('BeerCounter')
>>> field = cf.fields.create('BeerCount', 'I')
To automatically create a static field, pass a value::
>>> from jawa.cf imp... | [
"Creates",
"a",
"new",
"field",
"from",
"name",
"and",
"descriptor",
".",
"For",
"example",
"::"
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L110-L144 | train | Creates a new field from name and descriptor. |
TkTech/Jawa | jawa/fields.py | FieldTable.unpack | def unpack(self, source: IO):
"""
Read the FieldTable from the file-like object `source`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object... | python | def unpack(self, source: IO):
"""
Read the FieldTable from the file-like object `source`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object... | [
"def",
"unpack",
"(",
"self",
",",
"source",
":",
"IO",
")",
":",
"field_count",
"=",
"unpack",
"(",
"'>H'",
",",
"source",
".",
"read",
"(",
"2",
")",
")",
"[",
"0",
"]",
"for",
"_",
"in",
"repeat",
"(",
"None",
",",
"field_count",
")",
":",
"... | Read the FieldTable from the file-like object `source`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providing `read()` | [
"Read",
"the",
"FieldTable",
"from",
"the",
"file",
"-",
"like",
"object",
"source",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L150-L165 | train | Read the FieldTable from the file - like object source. |
TkTech/Jawa | jawa/fields.py | FieldTable.pack | def pack(self, out: IO):
"""
Write the FieldTable to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `w... | python | def pack(self, out: IO):
"""
Write the FieldTable to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `w... | [
"def",
"pack",
"(",
"self",
",",
"out",
":",
"IO",
")",
":",
"out",
".",
"write",
"(",
"pack",
"(",
"'>H'",
",",
"len",
"(",
"self",
")",
")",
")",
"for",
"field",
"in",
"self",
".",
"_table",
":",
"field",
".",
"pack",
"(",
"out",
")"
] | Write the FieldTable to the file-like object `out`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when saving a ClassFile.
:param out: Any file-like object providing `write()` | [
"Write",
"the",
"FieldTable",
"to",
"the",
"file",
"-",
"like",
"object",
"out",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L167-L180 | train | Write the FieldTable to out. |
TkTech/Jawa | jawa/fields.py | FieldTable.find | def find(self, *, name: str=None, type_: str=None,
f: Callable=None) -> Iterator[Field]:
"""
Iterates over the fields table, yielding each matching method. Calling
without any arguments is equivalent to iterating over the table.
:param name: The name of the field(s) to find... | python | def find(self, *, name: str=None, type_: str=None,
f: Callable=None) -> Iterator[Field]:
"""
Iterates over the fields table, yielding each matching method. Calling
without any arguments is equivalent to iterating over the table.
:param name: The name of the field(s) to find... | [
"def",
"find",
"(",
"self",
",",
"*",
",",
"name",
":",
"str",
"=",
"None",
",",
"type_",
":",
"str",
"=",
"None",
",",
"f",
":",
"Callable",
"=",
"None",
")",
"->",
"Iterator",
"[",
"Field",
"]",
":",
"for",
"field",
"in",
"self",
".",
"_table... | Iterates over the fields table, yielding each matching method. Calling
without any arguments is equivalent to iterating over the table.
:param name: The name of the field(s) to find.
:param type_: The field descriptor (Ex: 'I')
:param f: Any callable which takes one argument (the field)... | [
"Iterates",
"over",
"the",
"fields",
"table",
"yielding",
"each",
"matching",
"method",
".",
"Calling",
"without",
"any",
"arguments",
"is",
"equivalent",
"to",
"iterating",
"over",
"the",
"table",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/fields.py#L185-L206 | train | Iterates over the fields table yielding each matching method. |
networks-lab/tidyextractors | tidyextractors/tidygit/git_object_handlers.py | handle_stats | def handle_stats(name, obj):
"""
Stats object handler.
:param name: Unused String
:param obj: GitPython Stats
:return: Dictionary of attributes.
"""
return {'total_deletions': obj.total['deletions'],
'total_insertions': obj.total['insertions'],
'total_lines': obj.tota... | python | def handle_stats(name, obj):
"""
Stats object handler.
:param name: Unused String
:param obj: GitPython Stats
:return: Dictionary of attributes.
"""
return {'total_deletions': obj.total['deletions'],
'total_insertions': obj.total['insertions'],
'total_lines': obj.tota... | [
"def",
"handle_stats",
"(",
"name",
",",
"obj",
")",
":",
"return",
"{",
"'total_deletions'",
":",
"obj",
".",
"total",
"[",
"'deletions'",
"]",
",",
"'total_insertions'",
":",
"obj",
".",
"total",
"[",
"'insertions'",
"]",
",",
"'total_lines'",
":",
"obj"... | Stats object handler.
:param name: Unused String
:param obj: GitPython Stats
:return: Dictionary of attributes. | [
"Stats",
"object",
"handler",
".",
":",
"param",
"name",
":",
"Unused",
"String",
":",
"param",
"obj",
":",
"GitPython",
"Stats",
":",
"return",
":",
"Dictionary",
"of",
"attributes",
"."
] | 658448ed533beecf32adcc188fc64d1068d15ca6 | https://github.com/networks-lab/tidyextractors/blob/658448ed533beecf32adcc188fc64d1068d15ca6/tidyextractors/tidygit/git_object_handlers.py#L29-L40 | train | Handles GitPython Stats object. |
mardix/pylot | setup.py | read_pkginfo | def read_pkginfo(filename):
"""
Help us read the pkginfo without accessing __init__
"""
COMMENT_CHAR = '#'
OPTION_CHAR = '='
options = {}
f = open(filename)
for line in f:
if COMMENT_CHAR in line:
line, comment = line.split(COMMENT_CHAR, 1)
if OPTION_CHAR in ... | python | def read_pkginfo(filename):
"""
Help us read the pkginfo without accessing __init__
"""
COMMENT_CHAR = '#'
OPTION_CHAR = '='
options = {}
f = open(filename)
for line in f:
if COMMENT_CHAR in line:
line, comment = line.split(COMMENT_CHAR, 1)
if OPTION_CHAR in ... | [
"def",
"read_pkginfo",
"(",
"filename",
")",
":",
"COMMENT_CHAR",
"=",
"'#'",
"OPTION_CHAR",
"=",
"'='",
"options",
"=",
"{",
"}",
"f",
"=",
"open",
"(",
"filename",
")",
"for",
"line",
"in",
"f",
":",
"if",
"COMMENT_CHAR",
"in",
"line",
":",
"line",
... | Help us read the pkginfo without accessing __init__ | [
"Help",
"us",
"read",
"the",
"pkginfo",
"without",
"accessing",
"__init__"
] | 506a33a56ebdfc0925b94015e8cf98ccb16a143c | https://github.com/mardix/pylot/blob/506a33a56ebdfc0925b94015e8cf98ccb16a143c/setup.py#L17-L34 | train | Help us read the pkginfo without accessing __init__ |
piotr-rusin/spam-lists | spam_lists/validation.py | is_valid_host | def is_valid_host(value):
"""Check if given value is a valid host string.
:param value: a value to test
:returns: True if the value is valid
"""
host_validators = validators.ipv4, validators.ipv6, validators.domain
return any(f(value) for f in host_validators) | python | def is_valid_host(value):
"""Check if given value is a valid host string.
:param value: a value to test
:returns: True if the value is valid
"""
host_validators = validators.ipv4, validators.ipv6, validators.domain
return any(f(value) for f in host_validators) | [
"def",
"is_valid_host",
"(",
"value",
")",
":",
"host_validators",
"=",
"validators",
".",
"ipv4",
",",
"validators",
".",
"ipv6",
",",
"validators",
".",
"domain",
"return",
"any",
"(",
"f",
"(",
"value",
")",
"for",
"f",
"in",
"host_validators",
")"
] | Check if given value is a valid host string.
:param value: a value to test
:returns: True if the value is valid | [
"Check",
"if",
"given",
"value",
"is",
"a",
"valid",
"host",
"string",
"."
] | fd616e8761b28f3eaa503fee5e45f7748e8f88f2 | https://github.com/piotr-rusin/spam-lists/blob/fd616e8761b28f3eaa503fee5e45f7748e8f88f2/spam_lists/validation.py#L15-L22 | train | Checks if given value is a valid host string. |
piotr-rusin/spam-lists | spam_lists/validation.py | is_valid_url | def is_valid_url(value):
"""Check if given value is a valid URL string.
:param value: a value to test
:returns: True if the value is valid
"""
match = URL_REGEX.match(value)
host_str = urlparse(value).hostname
return match and is_valid_host(host_str) | python | def is_valid_url(value):
"""Check if given value is a valid URL string.
:param value: a value to test
:returns: True if the value is valid
"""
match = URL_REGEX.match(value)
host_str = urlparse(value).hostname
return match and is_valid_host(host_str) | [
"def",
"is_valid_url",
"(",
"value",
")",
":",
"match",
"=",
"URL_REGEX",
".",
"match",
"(",
"value",
")",
"host_str",
"=",
"urlparse",
"(",
"value",
")",
".",
"hostname",
"return",
"match",
"and",
"is_valid_host",
"(",
"host_str",
")"
] | Check if given value is a valid URL string.
:param value: a value to test
:returns: True if the value is valid | [
"Check",
"if",
"given",
"value",
"is",
"a",
"valid",
"URL",
"string",
"."
] | fd616e8761b28f3eaa503fee5e45f7748e8f88f2 | https://github.com/piotr-rusin/spam-lists/blob/fd616e8761b28f3eaa503fee5e45f7748e8f88f2/spam_lists/validation.py#L33-L41 | train | Check if given value is a valid URL string. |
piotr-rusin/spam-lists | spam_lists/validation.py | accepts_valid_host | def accepts_valid_host(func):
"""Return a wrapper that runs given method only for valid hosts.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation
"""
@functools.wraps(func)
def wrapper(obj, value, *args, **kwargs):
"""Run the function and return a valu... | python | def accepts_valid_host(func):
"""Return a wrapper that runs given method only for valid hosts.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation
"""
@functools.wraps(func)
def wrapper(obj, value, *args, **kwargs):
"""Run the function and return a valu... | [
"def",
"accepts_valid_host",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"obj",
",",
"value",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Run the function and return a value for a valid host.\... | Return a wrapper that runs given method only for valid hosts.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation | [
"Return",
"a",
"wrapper",
"that",
"runs",
"given",
"method",
"only",
"for",
"valid",
"hosts",
"."
] | fd616e8761b28f3eaa503fee5e45f7748e8f88f2 | https://github.com/piotr-rusin/spam-lists/blob/fd616e8761b28f3eaa503fee5e45f7748e8f88f2/spam_lists/validation.py#L44-L62 | train | Decorator that runs given function only for valid hosts. |
piotr-rusin/spam-lists | spam_lists/validation.py | accepts_valid_urls | def accepts_valid_urls(func):
"""Return a wrapper that runs given method only for valid URLs.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation
"""
@functools.wraps(func)
def wrapper(obj, urls, *args, **kwargs):
"""Run the function and return a value ... | python | def accepts_valid_urls(func):
"""Return a wrapper that runs given method only for valid URLs.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation
"""
@functools.wraps(func)
def wrapper(obj, urls, *args, **kwargs):
"""Run the function and return a value ... | [
"def",
"accepts_valid_urls",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"obj",
",",
"urls",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Run the function and return a value for valid URLs.\n\n... | Return a wrapper that runs given method only for valid URLs.
:param func: a method to be wrapped
:returns: a wrapper that adds argument validation | [
"Return",
"a",
"wrapper",
"that",
"runs",
"given",
"method",
"only",
"for",
"valid",
"URLs",
"."
] | fd616e8761b28f3eaa503fee5e45f7748e8f88f2 | https://github.com/piotr-rusin/spam-lists/blob/fd616e8761b28f3eaa503fee5e45f7748e8f88f2/spam_lists/validation.py#L65-L86 | train | Decorator that runs given method only for valid URLs. |
TkTech/Jawa | jawa/constants.py | ConstantPool.get | def get(self, index):
"""
Returns the `Constant` at `index`, raising a KeyError if it
does not exist.
"""
constant = self._pool[index]
if not isinstance(constant, Constant):
constant = _constant_types[constant[0]](self, index, *constant[1:])
self._... | python | def get(self, index):
"""
Returns the `Constant` at `index`, raising a KeyError if it
does not exist.
"""
constant = self._pool[index]
if not isinstance(constant, Constant):
constant = _constant_types[constant[0]](self, index, *constant[1:])
self._... | [
"def",
"get",
"(",
"self",
",",
"index",
")",
":",
"constant",
"=",
"self",
".",
"_pool",
"[",
"index",
"]",
"if",
"not",
"isinstance",
"(",
"constant",
",",
"Constant",
")",
":",
"constant",
"=",
"_constant_types",
"[",
"constant",
"[",
"0",
"]",
"]... | Returns the `Constant` at `index`, raising a KeyError if it
does not exist. | [
"Returns",
"the",
"Constant",
"at",
"index",
"raising",
"a",
"KeyError",
"if",
"it",
"does",
"not",
"exist",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L352-L361 | train | Returns the Constant at the given index raising a KeyError if the index is not in the pool. |
TkTech/Jawa | jawa/constants.py | ConstantPool.find | def find(self, type_=None, f=None):
"""
Iterates over the pool, yielding each matching ``Constant``. Calling
without any arguments is equivalent to iterating over the pool.
:param type_: Any subclass of :class:`Constant` or ``None``.
:param f: Any callable which takes one argume... | python | def find(self, type_=None, f=None):
"""
Iterates over the pool, yielding each matching ``Constant``. Calling
without any arguments is equivalent to iterating over the pool.
:param type_: Any subclass of :class:`Constant` or ``None``.
:param f: Any callable which takes one argume... | [
"def",
"find",
"(",
"self",
",",
"type_",
"=",
"None",
",",
"f",
"=",
"None",
")",
":",
"for",
"constant",
"in",
"self",
":",
"if",
"type_",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"constant",
",",
"type_",
")",
":",
"continue",
"if",... | Iterates over the pool, yielding each matching ``Constant``. Calling
without any arguments is equivalent to iterating over the pool.
:param type_: Any subclass of :class:`Constant` or ``None``.
:param f: Any callable which takes one argument (the constant). | [
"Iterates",
"over",
"the",
"pool",
"yielding",
"each",
"matching",
"Constant",
".",
"Calling",
"without",
"any",
"arguments",
"is",
"equivalent",
"to",
"iterating",
"over",
"the",
"pool",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L369-L384 | train | Iterates over the pool yielding each matching Constant. |
TkTech/Jawa | jawa/constants.py | ConstantPool.find_one | def find_one(self, *args, **kwargs):
"""
Same as ``find()`` but returns only the first result, or `None` if
nothing was found.
"""
try:
return next(self.find(*args, **kwargs))
except StopIteration:
return None | python | def find_one(self, *args, **kwargs):
"""
Same as ``find()`` but returns only the first result, or `None` if
nothing was found.
"""
try:
return next(self.find(*args, **kwargs))
except StopIteration:
return None | [
"def",
"find_one",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"next",
"(",
"self",
".",
"find",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
")",
"except",
"StopIteration",
":",
"return",
"None"
] | Same as ``find()`` but returns only the first result, or `None` if
nothing was found. | [
"Same",
"as",
"find",
"()",
"but",
"returns",
"only",
"the",
"first",
"result",
"or",
"None",
"if",
"nothing",
"was",
"found",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L386-L394 | train | Same as find but returns only the first result. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_utf8 | def create_utf8(self, value):
"""
Creates a new :class:`ConstantUTF8`, adding it to the pool and
returning it.
:param value: The value of the new UTF8 string.
"""
self.append((1, value))
return self.get(self.raw_count - 1) | python | def create_utf8(self, value):
"""
Creates a new :class:`ConstantUTF8`, adding it to the pool and
returning it.
:param value: The value of the new UTF8 string.
"""
self.append((1, value))
return self.get(self.raw_count - 1) | [
"def",
"create_utf8",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"append",
"(",
"(",
"1",
",",
"value",
")",
")",
"return",
"self",
".",
"get",
"(",
"self",
".",
"raw_count",
"-",
"1",
")"
] | Creates a new :class:`ConstantUTF8`, adding it to the pool and
returning it.
:param value: The value of the new UTF8 string. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantUTF8",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L396-L404 | train | Creates a new UTF8 string and returns it. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_integer | def create_integer(self, value: int) -> Integer:
"""
Creates a new :class:`ConstantInteger`, adding it to the pool and
returning it.
:param value: The value of the new integer.
"""
self.append((3, value))
return self.get(self.raw_count - 1) | python | def create_integer(self, value: int) -> Integer:
"""
Creates a new :class:`ConstantInteger`, adding it to the pool and
returning it.
:param value: The value of the new integer.
"""
self.append((3, value))
return self.get(self.raw_count - 1) | [
"def",
"create_integer",
"(",
"self",
",",
"value",
":",
"int",
")",
"->",
"Integer",
":",
"self",
".",
"append",
"(",
"(",
"3",
",",
"value",
")",
")",
"return",
"self",
".",
"get",
"(",
"self",
".",
"raw_count",
"-",
"1",
")"
] | Creates a new :class:`ConstantInteger`, adding it to the pool and
returning it.
:param value: The value of the new integer. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantInteger",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L406-L414 | train | Creates a new integer in the pool and returns it. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_float | def create_float(self, value: float) -> Float:
"""
Creates a new :class:`ConstantFloat`, adding it to the pool and
returning it.
:param value: The value of the new float.
"""
self.append((4, value))
return self.get(self.raw_count - 1) | python | def create_float(self, value: float) -> Float:
"""
Creates a new :class:`ConstantFloat`, adding it to the pool and
returning it.
:param value: The value of the new float.
"""
self.append((4, value))
return self.get(self.raw_count - 1) | [
"def",
"create_float",
"(",
"self",
",",
"value",
":",
"float",
")",
"->",
"Float",
":",
"self",
".",
"append",
"(",
"(",
"4",
",",
"value",
")",
")",
"return",
"self",
".",
"get",
"(",
"self",
".",
"raw_count",
"-",
"1",
")"
] | Creates a new :class:`ConstantFloat`, adding it to the pool and
returning it.
:param value: The value of the new float. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantFloat",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L416-L424 | train | Creates a new float in the pool and returns it. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_long | def create_long(self, value: int) -> Long:
"""
Creates a new :class:`ConstantLong`, adding it to the pool and
returning it.
:param value: The value of the new long.
"""
self.append((5, value))
self.append(None)
return self.get(self.raw_count - 2) | python | def create_long(self, value: int) -> Long:
"""
Creates a new :class:`ConstantLong`, adding it to the pool and
returning it.
:param value: The value of the new long.
"""
self.append((5, value))
self.append(None)
return self.get(self.raw_count - 2) | [
"def",
"create_long",
"(",
"self",
",",
"value",
":",
"int",
")",
"->",
"Long",
":",
"self",
".",
"append",
"(",
"(",
"5",
",",
"value",
")",
")",
"self",
".",
"append",
"(",
"None",
")",
"return",
"self",
".",
"get",
"(",
"self",
".",
"raw_count... | Creates a new :class:`ConstantLong`, adding it to the pool and
returning it.
:param value: The value of the new long. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantLong",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L426-L435 | train | Creates a new long in the pool and returns it. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_double | def create_double(self, value: float) -> Double:
"""
Creates a new :class:`ConstantDouble`, adding it to the pool and
returning it.
:param value: The value of the new Double.
"""
self.append((6, value))
self.append(None)
return self.get(self.raw_count - 2... | python | def create_double(self, value: float) -> Double:
"""
Creates a new :class:`ConstantDouble`, adding it to the pool and
returning it.
:param value: The value of the new Double.
"""
self.append((6, value))
self.append(None)
return self.get(self.raw_count - 2... | [
"def",
"create_double",
"(",
"self",
",",
"value",
":",
"float",
")",
"->",
"Double",
":",
"self",
".",
"append",
"(",
"(",
"6",
",",
"value",
")",
")",
"self",
".",
"append",
"(",
"None",
")",
"return",
"self",
".",
"get",
"(",
"self",
".",
"raw... | Creates a new :class:`ConstantDouble`, adding it to the pool and
returning it.
:param value: The value of the new Double. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantDouble",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L437-L446 | train | Creates a new Double. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_class | def create_class(self, name: str) -> ConstantClass:
"""
Creates a new :class:`ConstantClass`, adding it to the pool and
returning it.
:param name: The name of the new class.
"""
self.append((
7,
self.create_utf8(name).index
))
retu... | python | def create_class(self, name: str) -> ConstantClass:
"""
Creates a new :class:`ConstantClass`, adding it to the pool and
returning it.
:param name: The name of the new class.
"""
self.append((
7,
self.create_utf8(name).index
))
retu... | [
"def",
"create_class",
"(",
"self",
",",
"name",
":",
"str",
")",
"->",
"ConstantClass",
":",
"self",
".",
"append",
"(",
"(",
"7",
",",
"self",
".",
"create_utf8",
"(",
"name",
")",
".",
"index",
")",
")",
"return",
"self",
".",
"get",
"(",
"self"... | Creates a new :class:`ConstantClass`, adding it to the pool and
returning it.
:param name: The name of the new class. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantClass",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L448-L459 | train | Creates a new ConstantClass from the given name. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_string | def create_string(self, value: str) -> String:
"""
Creates a new :class:`ConstantString`, adding it to the pool and
returning it.
:param value: The value of the new string as a UTF8 string.
"""
self.append((
8,
self.create_utf8(value).index
... | python | def create_string(self, value: str) -> String:
"""
Creates a new :class:`ConstantString`, adding it to the pool and
returning it.
:param value: The value of the new string as a UTF8 string.
"""
self.append((
8,
self.create_utf8(value).index
... | [
"def",
"create_string",
"(",
"self",
",",
"value",
":",
"str",
")",
"->",
"String",
":",
"self",
".",
"append",
"(",
"(",
"8",
",",
"self",
".",
"create_utf8",
"(",
"value",
")",
".",
"index",
")",
")",
"return",
"self",
".",
"get",
"(",
"self",
... | Creates a new :class:`ConstantString`, adding it to the pool and
returning it.
:param value: The value of the new string as a UTF8 string. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantString",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L461-L472 | train | Creates a new string from the given value. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_name_and_type | def create_name_and_type(self, name: str, descriptor: str) -> NameAndType:
"""
Creates a new :class:`ConstantNameAndType`, adding it to the pool and
returning it.
:param name: The name of the class.
:param descriptor: The descriptor for `name`.
"""
self.append((
... | python | def create_name_and_type(self, name: str, descriptor: str) -> NameAndType:
"""
Creates a new :class:`ConstantNameAndType`, adding it to the pool and
returning it.
:param name: The name of the class.
:param descriptor: The descriptor for `name`.
"""
self.append((
... | [
"def",
"create_name_and_type",
"(",
"self",
",",
"name",
":",
"str",
",",
"descriptor",
":",
"str",
")",
"->",
"NameAndType",
":",
"self",
".",
"append",
"(",
"(",
"12",
",",
"self",
".",
"create_utf8",
"(",
"name",
")",
".",
"index",
",",
"self",
".... | Creates a new :class:`ConstantNameAndType`, adding it to the pool and
returning it.
:param name: The name of the class.
:param descriptor: The descriptor for `name`. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantNameAndType",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L474-L487 | train | Creates a new name and type. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_field_ref | def create_field_ref(self, class_: str, field: str, descriptor: str) \
-> FieldReference:
"""
Creates a new :class:`ConstantFieldRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `field` belongs.
:param field: The name of the... | python | def create_field_ref(self, class_: str, field: str, descriptor: str) \
-> FieldReference:
"""
Creates a new :class:`ConstantFieldRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `field` belongs.
:param field: The name of the... | [
"def",
"create_field_ref",
"(",
"self",
",",
"class_",
":",
"str",
",",
"field",
":",
"str",
",",
"descriptor",
":",
"str",
")",
"->",
"FieldReference",
":",
"self",
".",
"append",
"(",
"(",
"9",
",",
"self",
".",
"create_class",
"(",
"class_",
")",
... | Creates a new :class:`ConstantFieldRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `field` belongs.
:param field: The name of the field.
:param descriptor: The descriptor for `field`. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantFieldRef",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L489-L504 | train | Creates a new ConstantFieldRef. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_method_ref | def create_method_ref(self, class_: str, method: str, descriptor: str) \
-> MethodReference:
"""
Creates a new :class:`ConstantMethodRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `method` belongs.
:param method: The name ... | python | def create_method_ref(self, class_: str, method: str, descriptor: str) \
-> MethodReference:
"""
Creates a new :class:`ConstantMethodRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `method` belongs.
:param method: The name ... | [
"def",
"create_method_ref",
"(",
"self",
",",
"class_",
":",
"str",
",",
"method",
":",
"str",
",",
"descriptor",
":",
"str",
")",
"->",
"MethodReference",
":",
"self",
".",
"append",
"(",
"(",
"10",
",",
"self",
".",
"create_class",
"(",
"class_",
")"... | Creates a new :class:`ConstantMethodRef`, adding it to the pool and
returning it.
:param class_: The name of the class to which `method` belongs.
:param method: The name of the method.
:param descriptor: The descriptor for `method`. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantMethodRef",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L506-L521 | train | Creates a new ConstantMethodRef. |
TkTech/Jawa | jawa/constants.py | ConstantPool.create_interface_method_ref | def create_interface_method_ref(self, class_: str, if_method: str,
descriptor: str) -> InterfaceMethodRef:
"""
Creates a new :class:`ConstantInterfaceMethodRef`, adding it to the
pool and returning it.
:param class_: The name of the class to which `if... | python | def create_interface_method_ref(self, class_: str, if_method: str,
descriptor: str) -> InterfaceMethodRef:
"""
Creates a new :class:`ConstantInterfaceMethodRef`, adding it to the
pool and returning it.
:param class_: The name of the class to which `if... | [
"def",
"create_interface_method_ref",
"(",
"self",
",",
"class_",
":",
"str",
",",
"if_method",
":",
"str",
",",
"descriptor",
":",
"str",
")",
"->",
"InterfaceMethodRef",
":",
"self",
".",
"append",
"(",
"(",
"11",
",",
"self",
".",
"create_class",
"(",
... | Creates a new :class:`ConstantInterfaceMethodRef`, adding it to the
pool and returning it.
:param class_: The name of the class to which `if_method` belongs.
:param if_method: The name of the interface method.
:param descriptor: The descriptor for `if_method`. | [
"Creates",
"a",
"new",
":",
"class",
":",
"ConstantInterfaceMethodRef",
"adding",
"it",
"to",
"the",
"pool",
"and",
"returning",
"it",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L523-L538 | train | Creates a new ConstantInterfaceMethodRef. |
TkTech/Jawa | jawa/constants.py | ConstantPool.unpack | def unpack(self, fio):
"""
Read the ConstantPool from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param fio: Any file-like object providing ... | python | def unpack(self, fio):
"""
Read the ConstantPool from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param fio: Any file-like object providing ... | [
"def",
"unpack",
"(",
"self",
",",
"fio",
")",
":",
"# Reads in the ConstantPool (constant_pool in the JVM Spec)",
"constant_pool_count",
"=",
"unpack",
"(",
"'>H'",
",",
"fio",
".",
"read",
"(",
"2",
")",
")",
"[",
"0",
"]",
"# Pull this locally so CPython doesn't ... | Read the ConstantPool from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param fio: Any file-like object providing `read()` | [
"Read",
"the",
"ConstantPool",
"from",
"the",
"file",
"-",
"like",
"object",
"fio",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L540-L581 | train | Reads in the ConstantPool from the file - like object fio and appends the contents of the ConstantPool to self. |
TkTech/Jawa | jawa/constants.py | ConstantPool.pack | def pack(self, fout):
"""
Write the ConstantPool to the file-like object `fout`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be calle=d for you when saving a ClassFile.
:param fout: Any file-like object providing ... | python | def pack(self, fout):
"""
Write the ConstantPool to the file-like object `fout`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be calle=d for you when saving a ClassFile.
:param fout: Any file-like object providing ... | [
"def",
"pack",
"(",
"self",
",",
"fout",
")",
":",
"write",
"=",
"fout",
".",
"write",
"write",
"(",
"pack",
"(",
"'>H'",
",",
"self",
".",
"raw_count",
")",
")",
"for",
"constant",
"in",
"self",
":",
"write",
"(",
"constant",
".",
"pack",
"(",
"... | Write the ConstantPool to the file-like object `fout`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be calle=d for you when saving a ClassFile.
:param fout: Any file-like object providing `write()` | [
"Write",
"the",
"ConstantPool",
"to",
"the",
"file",
"-",
"like",
"object",
"fout",
"."
] | 94c8424e699029ac33fbc0e866fff0ecb2742289 | https://github.com/TkTech/Jawa/blob/94c8424e699029ac33fbc0e866fff0ecb2742289/jawa/constants.py#L583-L598 | train | Write the ConstantPool to the file - like object fout. |
mardix/pylot | pylot/cmd.py | create_project | def create_project(project_name, template="default"):
"""
Create the project
"""
project_dir = get_project_dir_path(project_name)
run_tpl = pkg_resources.resource_string(__name__, '%s/run.py' % (SKELETON_DIR))
init_py_tpl = pkg_resources.resource_string(__name__, '%s/init.py' % (SKELETON_DIR))... | python | def create_project(project_name, template="default"):
"""
Create the project
"""
project_dir = get_project_dir_path(project_name)
run_tpl = pkg_resources.resource_string(__name__, '%s/run.py' % (SKELETON_DIR))
init_py_tpl = pkg_resources.resource_string(__name__, '%s/init.py' % (SKELETON_DIR))... | [
"def",
"create_project",
"(",
"project_name",
",",
"template",
"=",
"\"default\"",
")",
":",
"project_dir",
"=",
"get_project_dir_path",
"(",
"project_name",
")",
"run_tpl",
"=",
"pkg_resources",
".",
"resource_string",
"(",
"__name__",
",",
"'%s/run.py'",
"%",
"(... | Create the project | [
"Create",
"the",
"project"
] | 506a33a56ebdfc0925b94015e8cf98ccb16a143c | https://github.com/mardix/pylot/blob/506a33a56ebdfc0925b94015e8cf98ccb16a143c/pylot/cmd.py#L39-L100 | train | Create a new project |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | checkout_and_create_branch | def checkout_and_create_branch(repo, name):
"""Checkout branch. Create it if necessary"""
local_branch = repo.branches[name] if name in repo.branches else None
if not local_branch:
if name in repo.remotes.origin.refs:
# If origin branch exists but not local, git.checkout is the fatest wa... | python | def checkout_and_create_branch(repo, name):
"""Checkout branch. Create it if necessary"""
local_branch = repo.branches[name] if name in repo.branches else None
if not local_branch:
if name in repo.remotes.origin.refs:
# If origin branch exists but not local, git.checkout is the fatest wa... | [
"def",
"checkout_and_create_branch",
"(",
"repo",
",",
"name",
")",
":",
"local_branch",
"=",
"repo",
".",
"branches",
"[",
"name",
"]",
"if",
"name",
"in",
"repo",
".",
"branches",
"else",
"None",
"if",
"not",
"local_branch",
":",
"if",
"name",
"in",
"r... | Checkout branch. Create it if necessary | [
"Checkout",
"branch",
".",
"Create",
"it",
"if",
"necessary"
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L9-L21 | train | Checkout branch. Create it if necessary. |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | checkout_create_push_branch | def checkout_create_push_branch(repo, name):
"""Checkout this branch. Create it if necessary, and push it to origin.
"""
try:
repo.git.checkout(name)
_LOGGER.info("Checkout %s success", name)
except GitCommandError:
_LOGGER.info("Checkout %s was impossible (branch does not exist)... | python | def checkout_create_push_branch(repo, name):
"""Checkout this branch. Create it if necessary, and push it to origin.
"""
try:
repo.git.checkout(name)
_LOGGER.info("Checkout %s success", name)
except GitCommandError:
_LOGGER.info("Checkout %s was impossible (branch does not exist)... | [
"def",
"checkout_create_push_branch",
"(",
"repo",
",",
"name",
")",
":",
"try",
":",
"repo",
".",
"git",
".",
"checkout",
"(",
"name",
")",
"_LOGGER",
".",
"info",
"(",
"\"Checkout %s success\"",
",",
"name",
")",
"except",
"GitCommandError",
":",
"_LOGGER"... | Checkout this branch. Create it if necessary, and push it to origin. | [
"Checkout",
"this",
"branch",
".",
"Create",
"it",
"if",
"necessary",
"and",
"push",
"it",
"to",
"origin",
"."
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L23-L32 | train | Checkout this branch. Create it if necessary and push it to origin. |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | do_commit | def do_commit(repo, message_template, branch_name, hexsha):
"Do a commit if modified/untracked files"
repo.git.add(repo.working_tree_dir)
if not repo.git.diff(staged=True):
_LOGGER.warning('No modified files in this Autorest run')
return False
checkout_and_create_branch(repo, branch_na... | python | def do_commit(repo, message_template, branch_name, hexsha):
"Do a commit if modified/untracked files"
repo.git.add(repo.working_tree_dir)
if not repo.git.diff(staged=True):
_LOGGER.warning('No modified files in this Autorest run')
return False
checkout_and_create_branch(repo, branch_na... | [
"def",
"do_commit",
"(",
"repo",
",",
"message_template",
",",
"branch_name",
",",
"hexsha",
")",
":",
"repo",
".",
"git",
".",
"add",
"(",
"repo",
".",
"working_tree_dir",
")",
"if",
"not",
"repo",
".",
"git",
".",
"diff",
"(",
"staged",
"=",
"True",
... | Do a commit if modified/untracked files | [
"Do",
"a",
"commit",
"if",
"modified",
"/",
"untracked",
"files"
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L35-L47 | train | Do a commit if modified or untracked files |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | get_repo_hexsha | def get_repo_hexsha(git_folder):
"""Get the SHA1 of the current repo"""
repo = Repo(str(git_folder))
if repo.bare:
not_git_hexsha = "notgitrepo"
_LOGGER.warning("Not a git repo, SHA1 used will be: %s", not_git_hexsha)
return not_git_hexsha
hexsha = repo.head.commit.hexsha
_LO... | python | def get_repo_hexsha(git_folder):
"""Get the SHA1 of the current repo"""
repo = Repo(str(git_folder))
if repo.bare:
not_git_hexsha = "notgitrepo"
_LOGGER.warning("Not a git repo, SHA1 used will be: %s", not_git_hexsha)
return not_git_hexsha
hexsha = repo.head.commit.hexsha
_LO... | [
"def",
"get_repo_hexsha",
"(",
"git_folder",
")",
":",
"repo",
"=",
"Repo",
"(",
"str",
"(",
"git_folder",
")",
")",
"if",
"repo",
".",
"bare",
":",
"not_git_hexsha",
"=",
"\"notgitrepo\"",
"_LOGGER",
".",
"warning",
"(",
"\"Not a git repo, SHA1 used will be: %s... | Get the SHA1 of the current repo | [
"Get",
"the",
"SHA1",
"of",
"the",
"current",
"repo"
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L49-L58 | train | Get the SHA1 of the current repo |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | checkout_with_fetch | def checkout_with_fetch(git_folder, refspec, repository="origin"):
"""Fetch the refspec, and checkout FETCH_HEAD.
Beware that you will ne in detached head mode.
"""
_LOGGER.info("Trying to fetch and checkout %s", refspec)
repo = Repo(str(git_folder))
repo.git.fetch(repository, refspec) # FETCH_... | python | def checkout_with_fetch(git_folder, refspec, repository="origin"):
"""Fetch the refspec, and checkout FETCH_HEAD.
Beware that you will ne in detached head mode.
"""
_LOGGER.info("Trying to fetch and checkout %s", refspec)
repo = Repo(str(git_folder))
repo.git.fetch(repository, refspec) # FETCH_... | [
"def",
"checkout_with_fetch",
"(",
"git_folder",
",",
"refspec",
",",
"repository",
"=",
"\"origin\"",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Trying to fetch and checkout %s\"",
",",
"refspec",
")",
"repo",
"=",
"Repo",
"(",
"str",
"(",
"git_folder",
")",
"... | Fetch the refspec, and checkout FETCH_HEAD.
Beware that you will ne in detached head mode. | [
"Fetch",
"the",
"refspec",
"and",
"checkout",
"FETCH_HEAD",
".",
"Beware",
"that",
"you",
"will",
"ne",
"in",
"detached",
"head",
"mode",
"."
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L60-L68 | train | Fetch the refspec and checkout FETCH_HEAD. |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | clone_to_path | def clone_to_path(https_authenticated_url, folder, branch_or_commit=None):
"""Clone the given URL to the folder.
:param str branch_or_commit: If specified, switch to this branch. Branch must exist.
"""
_LOGGER.info("Cloning repo")
repo = Repo.clone_from(https_authenticated_url, str(folder))
# D... | python | def clone_to_path(https_authenticated_url, folder, branch_or_commit=None):
"""Clone the given URL to the folder.
:param str branch_or_commit: If specified, switch to this branch. Branch must exist.
"""
_LOGGER.info("Cloning repo")
repo = Repo.clone_from(https_authenticated_url, str(folder))
# D... | [
"def",
"clone_to_path",
"(",
"https_authenticated_url",
",",
"folder",
",",
"branch_or_commit",
"=",
"None",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Cloning repo\"",
")",
"repo",
"=",
"Repo",
".",
"clone_from",
"(",
"https_authenticated_url",
",",
"str",
"(",
... | Clone the given URL to the folder.
:param str branch_or_commit: If specified, switch to this branch. Branch must exist. | [
"Clone",
"the",
"given",
"URL",
"to",
"the",
"folder",
"."
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L70-L83 | train | Clone the given URL to the given folder. |
Azure/azure-python-devtools | src/azure_devtools/ci_tools/git_tools.py | get_files_in_commit | def get_files_in_commit(git_folder, commit_id="HEAD"):
"""List of files in HEAD commit.
"""
repo = Repo(str(git_folder))
output = repo.git.diff("--name-only", commit_id+"^", commit_id)
return output.splitlines() | python | def get_files_in_commit(git_folder, commit_id="HEAD"):
"""List of files in HEAD commit.
"""
repo = Repo(str(git_folder))
output = repo.git.diff("--name-only", commit_id+"^", commit_id)
return output.splitlines() | [
"def",
"get_files_in_commit",
"(",
"git_folder",
",",
"commit_id",
"=",
"\"HEAD\"",
")",
":",
"repo",
"=",
"Repo",
"(",
"str",
"(",
"git_folder",
")",
")",
"output",
"=",
"repo",
".",
"git",
".",
"diff",
"(",
"\"--name-only\"",
",",
"commit_id",
"+",
"\"... | List of files in HEAD commit. | [
"List",
"of",
"files",
"in",
"HEAD",
"commit",
"."
] | 2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936 | https://github.com/Azure/azure-python-devtools/blob/2bf87b1f3cedd2b26fb2e4fd47a9baf435dcf936/src/azure_devtools/ci_tools/git_tools.py#L85-L90 | train | Get a list of files in HEAD commit. |
qwiglydee/drf-mongo-filters | drf_mongo_filters/filtersets.py | BaseFilterset.parse_values | def parse_values(self, query):
"""
extract values from query
"""
values = {}
for name, filt in self.filters.items():
val = filt.parse_value(query)
if val is None:
continue
values[name] = val
return values | python | def parse_values(self, query):
"""
extract values from query
"""
values = {}
for name, filt in self.filters.items():
val = filt.parse_value(query)
if val is None:
continue
values[name] = val
return values | [
"def",
"parse_values",
"(",
"self",
",",
"query",
")",
":",
"values",
"=",
"{",
"}",
"for",
"name",
",",
"filt",
"in",
"self",
".",
"filters",
".",
"items",
"(",
")",
":",
"val",
"=",
"filt",
".",
"parse_value",
"(",
"query",
")",
"if",
"val",
"i... | extract values from query | [
"extract",
"values",
"from",
"query"
] | f7e397c329bac6d7b8cbb1df70d96eccdcfbc1ec | https://github.com/qwiglydee/drf-mongo-filters/blob/f7e397c329bac6d7b8cbb1df70d96eccdcfbc1ec/drf_mongo_filters/filtersets.py#L49-L59 | train | extract values from query |
qwiglydee/drf-mongo-filters | drf_mongo_filters/filtersets.py | BaseFilterset.filter_queryset | def filter_queryset(self, queryset):
"""
convert values to filtering params and apply to queryset
"""
for name, filt in self.filters.items():
val = self.values.get(name, None)
if name is None:
continue
params = filt.filter_params(val)
... | python | def filter_queryset(self, queryset):
"""
convert values to filtering params and apply to queryset
"""
for name, filt in self.filters.items():
val = self.values.get(name, None)
if name is None:
continue
params = filt.filter_params(val)
... | [
"def",
"filter_queryset",
"(",
"self",
",",
"queryset",
")",
":",
"for",
"name",
",",
"filt",
"in",
"self",
".",
"filters",
".",
"items",
"(",
")",
":",
"val",
"=",
"self",
".",
"values",
".",
"get",
"(",
"name",
",",
"None",
")",
"if",
"name",
"... | convert values to filtering params and apply to queryset | [
"convert",
"values",
"to",
"filtering",
"params",
"and",
"apply",
"to",
"queryset"
] | f7e397c329bac6d7b8cbb1df70d96eccdcfbc1ec | https://github.com/qwiglydee/drf-mongo-filters/blob/f7e397c329bac6d7b8cbb1df70d96eccdcfbc1ec/drf_mongo_filters/filtersets.py#L61-L76 | train | convert values to filtering params and apply to queryset |
mezz64/pyEmby | pyemby/device.py | EmbyDevice.media_artist | def media_artist(self):
"""Artist of current playing media (Music track only)."""
try:
artists = self.session['NowPlayingItem']['Artists']
if len(artists) > 1:
return artists[0]
else:
return artists
except KeyError:
... | python | def media_artist(self):
"""Artist of current playing media (Music track only)."""
try:
artists = self.session['NowPlayingItem']['Artists']
if len(artists) > 1:
return artists[0]
else:
return artists
except KeyError:
... | [
"def",
"media_artist",
"(",
"self",
")",
":",
"try",
":",
"artists",
"=",
"self",
".",
"session",
"[",
"'NowPlayingItem'",
"]",
"[",
"'Artists'",
"]",
"if",
"len",
"(",
"artists",
")",
">",
"1",
":",
"return",
"artists",
"[",
"0",
"]",
"else",
":",
... | Artist of current playing media (Music track only). | [
"Artist",
"of",
"current",
"playing",
"media",
"(",
"Music",
"track",
"only",
")",
"."
] | 6bb621e4e25bf1b9b0aba2c38b588e68f8816226 | https://github.com/mezz64/pyEmby/blob/6bb621e4e25bf1b9b0aba2c38b588e68f8816226/pyemby/device.py#L121-L130 | train | Return the artist of the currently playing media. |
mezz64/pyEmby | pyemby/device.py | EmbyDevice.media_image_url | def media_image_url(self):
"""Image url of current playing media."""
if self.is_nowplaying:
base = self.server.construct_url(API_URL)
try:
image_id = self.session['NowPlayingItem']['ImageTags']['Thumb']
image_type = 'Thumb'
except KeyEr... | python | def media_image_url(self):
"""Image url of current playing media."""
if self.is_nowplaying:
base = self.server.construct_url(API_URL)
try:
image_id = self.session['NowPlayingItem']['ImageTags']['Thumb']
image_type = 'Thumb'
except KeyEr... | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_nowplaying",
":",
"base",
"=",
"self",
".",
"server",
".",
"construct_url",
"(",
"API_URL",
")",
"try",
":",
"image_id",
"=",
"self",
".",
"session",
"[",
"'NowPlayingItem'",
"]",
"[... | Image url of current playing media. | [
"Image",
"url",
"of",
"current",
"playing",
"media",
"."
] | 6bb621e4e25bf1b9b0aba2c38b588e68f8816226 | https://github.com/mezz64/pyEmby/blob/6bb621e4e25bf1b9b0aba2c38b588e68f8816226/pyemby/device.py#L178-L196 | train | Image url of current playing media. |
mezz64/pyEmby | pyemby/device.py | EmbyDevice.state | def state(self):
""" Return current playstate of the device. """
if self.is_active:
if 'NowPlayingItem' in self.session:
if self.session['PlayState']['IsPaused']:
return STATE_PAUSED
else:
return STATE_PLAYING
... | python | def state(self):
""" Return current playstate of the device. """
if self.is_active:
if 'NowPlayingItem' in self.session:
if self.session['PlayState']['IsPaused']:
return STATE_PAUSED
else:
return STATE_PLAYING
... | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_active",
":",
"if",
"'NowPlayingItem'",
"in",
"self",
".",
"session",
":",
"if",
"self",
".",
"session",
"[",
"'PlayState'",
"]",
"[",
"'IsPaused'",
"]",
":",
"return",
"STATE_PAUSED",
"else",... | Return current playstate of the device. | [
"Return",
"current",
"playstate",
"of",
"the",
"device",
"."
] | 6bb621e4e25bf1b9b0aba2c38b588e68f8816226 | https://github.com/mezz64/pyEmby/blob/6bb621e4e25bf1b9b0aba2c38b588e68f8816226/pyemby/device.py#L224-L235 | train | Return the current playstate of the device. |
mezz64/pyEmby | pyemby/device.py | EmbyDevice.set_playstate | async def set_playstate(self, state, pos=0):
""" Send media commands to server. """
url = '{}/Sessions/{}/Playing/{}'.format(
self.server.construct_url(API_URL), self.session_id, state)
params = {'api_key': self.server.api_key}
if state == 'seek':
params['SeekPos... | python | async def set_playstate(self, state, pos=0):
""" Send media commands to server. """
url = '{}/Sessions/{}/Playing/{}'.format(
self.server.construct_url(API_URL), self.session_id, state)
params = {'api_key': self.server.api_key}
if state == 'seek':
params['SeekPos... | [
"async",
"def",
"set_playstate",
"(",
"self",
",",
"state",
",",
"pos",
"=",
"0",
")",
":",
"url",
"=",
"'{}/Sessions/{}/Playing/{}'",
".",
"format",
"(",
"self",
".",
"server",
".",
"construct_url",
"(",
"API_URL",
")",
",",
"self",
".",
"session_id",
"... | Send media commands to server. | [
"Send",
"media",
"commands",
"to",
"server",
"."
] | 6bb621e4e25bf1b9b0aba2c38b588e68f8816226 | https://github.com/mezz64/pyEmby/blob/6bb621e4e25bf1b9b0aba2c38b588e68f8816226/pyemby/device.py#L250-L266 | train | Send media commands to server. |
thespacedoctor/polyglot | polyglot/markdown/translate.py | translate.footnote | def footnote(
self,
text):
"""*convert plain-text to MMD footnote*
**Key Arguments:**
- ``text`` -- the text to convert to MMD footnote
**Return:**
- ``text`` -- the footnote text
**Usage:**
To convert a text block to footno... | python | def footnote(
self,
text):
"""*convert plain-text to MMD footnote*
**Key Arguments:**
- ``text`` -- the text to convert to MMD footnote
**Return:**
- ``text`` -- the footnote text
**Usage:**
To convert a text block to footno... | [
"def",
"footnote",
"(",
"self",
",",
"text",
")",
":",
"rand",
"=",
"str",
"(",
"randint",
"(",
"0",
",",
"99",
")",
")",
"now",
"=",
"datetime",
".",
"now",
"(",
")",
"now",
"=",
"now",
".",
"strftime",
"(",
"\"%Y%m%dT%H:%M:%S-\"",
")",
"+",
"ra... | *convert plain-text to MMD footnote*
**Key Arguments:**
- ``text`` -- the text to convert to MMD footnote
**Return:**
- ``text`` -- the footnote text
**Usage:**
To convert a text block to footnote text:
.. code-block:: python
... | [
"*",
"convert",
"plain",
"-",
"text",
"to",
"MMD",
"footnote",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/markdown/translate.py#L227-L259 | train | convert plain - text to MMD footnote |
thespacedoctor/polyglot | polyglot/markdown/translate.py | translate.glossary | def glossary(
self,
term,
definition):
"""*genarate a MMD glossary*
**Key Arguments:**
- ``term`` -- the term to add as a glossary item
- ``definition`` -- the definition of the glossary term
**Return:**
- ``glossary`` -- ... | python | def glossary(
self,
term,
definition):
"""*genarate a MMD glossary*
**Key Arguments:**
- ``term`` -- the term to add as a glossary item
- ``definition`` -- the definition of the glossary term
**Return:**
- ``glossary`` -- ... | [
"def",
"glossary",
"(",
"self",
",",
"term",
",",
"definition",
")",
":",
"term",
"=",
"term",
".",
"strip",
"(",
")",
"term",
"=",
"term",
".",
"lower",
"(",
")",
"title",
"=",
"term",
".",
"title",
"(",
")",
"definition",
"=",
"definition",
".",
... | *genarate a MMD glossary*
**Key Arguments:**
- ``term`` -- the term to add as a glossary item
- ``definition`` -- the definition of the glossary term
**Return:**
- ``glossary`` -- the glossary text
**Usage:**
To genarate a glossary item:
... | [
"*",
"genarate",
"a",
"MMD",
"glossary",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/markdown/translate.py#L261-L300 | train | This function returns a MMD glossary that can be used to add a single item to a MMD. |
thespacedoctor/polyglot | polyglot/markdown/translate.py | translate.cite | def cite(
self,
title,
author=False,
year=False,
url=False,
publisher=False,
mediaKind=False,
linkedText=False,
nocite=False):
"""*generate a MMD citation*
**Key Arguments:**
- ``titl... | python | def cite(
self,
title,
author=False,
year=False,
url=False,
publisher=False,
mediaKind=False,
linkedText=False,
nocite=False):
"""*generate a MMD citation*
**Key Arguments:**
- ``titl... | [
"def",
"cite",
"(",
"self",
",",
"title",
",",
"author",
"=",
"False",
",",
"year",
"=",
"False",
",",
"url",
"=",
"False",
",",
"publisher",
"=",
"False",
",",
"mediaKind",
"=",
"False",
",",
"linkedText",
"=",
"False",
",",
"nocite",
"=",
"False",
... | *generate a MMD citation*
**Key Arguments:**
- ``title`` -- the citation title
- ``author`` -- the author. Default *False*
- ``year`` -- year published. Default *False*
- ``url`` -- url to the media. Default *False*
- ``publisher`` -- the publisher of... | [
"*",
"generate",
"a",
"MMD",
"citation",
"*"
] | 98038d746aa67e343b73b3ccee1e02d31dab81ec | https://github.com/thespacedoctor/polyglot/blob/98038d746aa67e343b73b3ccee1e02d31dab81ec/polyglot/markdown/translate.py#L302-L387 | train | Generate a MMD citation for a specific object. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.