partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | Reader.needs_distribute_ready | Determine whether or not we need to redistribute the ready state | nsq/reader.py | def needs_distribute_ready(self):
'''Determine whether or not we need to redistribute the ready state'''
# Try to pre-empty starvation by comparing current RDY against
# the last value sent.
alive = [c for c in self.connections() if c.alive()]
if any(c.ready <= (c.last_ready_sent... | def needs_distribute_ready(self):
'''Determine whether or not we need to redistribute the ready state'''
# Try to pre-empty starvation by comparing current RDY against
# the last value sent.
alive = [c for c in self.connections() if c.alive()]
if any(c.ready <= (c.last_ready_sent... | [
"Determine",
"whether",
"or",
"not",
"we",
"need",
"to",
"redistribute",
"the",
"ready",
"state"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/nsq/reader.py#L44-L50 | [
"def",
"needs_distribute_ready",
"(",
"self",
")",
":",
"# Try to pre-empty starvation by comparing current RDY against",
"# the last value sent.",
"alive",
"=",
"[",
"c",
"for",
"c",
"in",
"self",
".",
"connections",
"(",
")",
"if",
"c",
".",
"alive",
"(",
")",
"... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | Reader.read | Read some number of messages | nsq/reader.py | def read(self):
'''Read some number of messages'''
found = Client.read(self)
# Redistribute our ready state if necessary
if self.needs_distribute_ready():
self.distribute_ready()
# Finally, return all the results we've read
return found | def read(self):
'''Read some number of messages'''
found = Client.read(self)
# Redistribute our ready state if necessary
if self.needs_distribute_ready():
self.distribute_ready()
# Finally, return all the results we've read
return found | [
"Read",
"some",
"number",
"of",
"messages"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/nsq/reader.py#L57-L66 | [
"def",
"read",
"(",
"self",
")",
":",
"found",
"=",
"Client",
".",
"read",
"(",
"self",
")",
"# Redistribute our ready state if necessary",
"if",
"self",
".",
"needs_distribute_ready",
"(",
")",
":",
"self",
".",
"distribute_ready",
"(",
")",
"# Finally, return ... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | profiler | Profile the block | shovel/profile.py | def profiler():
'''Profile the block'''
import cProfile
import pstats
pr = cProfile.Profile()
pr.enable()
yield
pr.disable()
ps = pstats.Stats(pr).sort_stats('tottime')
ps.print_stats() | def profiler():
'''Profile the block'''
import cProfile
import pstats
pr = cProfile.Profile()
pr.enable()
yield
pr.disable()
ps = pstats.Stats(pr).sort_stats('tottime')
ps.print_stats() | [
"Profile",
"the",
"block"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/shovel/profile.py#L9-L18 | [
"def",
"profiler",
"(",
")",
":",
"import",
"cProfile",
"import",
"pstats",
"pr",
"=",
"cProfile",
".",
"Profile",
"(",
")",
"pr",
".",
"enable",
"(",
")",
"yield",
"pr",
".",
"disable",
"(",
")",
"ps",
"=",
"pstats",
".",
"Stats",
"(",
"pr",
")",
... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | messages | Generator for count messages of the provided size | shovel/profile.py | def messages(count, size):
'''Generator for count messages of the provided size'''
import string
# Make sure we have at least 'size' letters
letters = islice(cycle(chain(string.lowercase, string.uppercase)), size)
return islice(cycle(''.join(l) for l in permutations(letters, size)), count) | def messages(count, size):
'''Generator for count messages of the provided size'''
import string
# Make sure we have at least 'size' letters
letters = islice(cycle(chain(string.lowercase, string.uppercase)), size)
return islice(cycle(''.join(l) for l in permutations(letters, size)), count) | [
"Generator",
"for",
"count",
"messages",
"of",
"the",
"provided",
"size"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/shovel/profile.py#L21-L26 | [
"def",
"messages",
"(",
"count",
",",
"size",
")",
":",
"import",
"string",
"# Make sure we have at least 'size' letters",
"letters",
"=",
"islice",
"(",
"cycle",
"(",
"chain",
"(",
"string",
".",
"lowercase",
",",
"string",
".",
"uppercase",
")",
")",
",",
... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | grouper | Collect data into fixed-length chunks or blocks | shovel/profile.py | def grouper(iterable, n):
'''Collect data into fixed-length chunks or blocks'''
args = [iter(iterable)] * n
for group in izip_longest(fillvalue=None, *args):
group = [g for g in group if g != None]
yield group | def grouper(iterable, n):
'''Collect data into fixed-length chunks or blocks'''
args = [iter(iterable)] * n
for group in izip_longest(fillvalue=None, *args):
group = [g for g in group if g != None]
yield group | [
"Collect",
"data",
"into",
"fixed",
"-",
"length",
"chunks",
"or",
"blocks"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/shovel/profile.py#L29-L34 | [
"def",
"grouper",
"(",
"iterable",
",",
"n",
")",
":",
"args",
"=",
"[",
"iter",
"(",
"iterable",
")",
"]",
"*",
"n",
"for",
"group",
"in",
"izip_longest",
"(",
"fillvalue",
"=",
"None",
",",
"*",
"args",
")",
":",
"group",
"=",
"[",
"g",
"for",
... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | basic | Basic benchmark | shovel/profile.py | def basic(topic='topic', channel='channel', count=1e6, size=10, gevent=False,
max_in_flight=2500, profile=False):
'''Basic benchmark'''
if gevent:
from gevent import monkey
monkey.patch_all()
# Check the types of the arguments
count = int(count)
size = int(size)
max_in_fligh... | def basic(topic='topic', channel='channel', count=1e6, size=10, gevent=False,
max_in_flight=2500, profile=False):
'''Basic benchmark'''
if gevent:
from gevent import monkey
monkey.patch_all()
# Check the types of the arguments
count = int(count)
size = int(size)
max_in_fligh... | [
"Basic",
"benchmark"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/shovel/profile.py#L38-L71 | [
"def",
"basic",
"(",
"topic",
"=",
"'topic'",
",",
"channel",
"=",
"'channel'",
",",
"count",
"=",
"1e6",
",",
"size",
"=",
"10",
",",
"gevent",
"=",
"False",
",",
"max_in_flight",
"=",
"2500",
",",
"profile",
"=",
"False",
")",
":",
"if",
"gevent",
... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | stats | Read a stream of floats and give summary statistics | shovel/profile.py | def stats():
'''Read a stream of floats and give summary statistics'''
import re
import sys
import math
values = []
for line in sys.stdin:
values.extend(map(float, re.findall(r'\d+\.?\d+', line)))
mean = sum(values) / len(values)
variance = sum((val - mean) ** 2 for val in value... | def stats():
'''Read a stream of floats and give summary statistics'''
import re
import sys
import math
values = []
for line in sys.stdin:
values.extend(map(float, re.findall(r'\d+\.?\d+', line)))
mean = sum(values) / len(values)
variance = sum((val - mean) ** 2 for val in value... | [
"Read",
"a",
"stream",
"of",
"floats",
"and",
"give",
"summary",
"statistics"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/shovel/profile.py#L75-L87 | [
"def",
"stats",
"(",
")",
":",
"import",
"re",
"import",
"sys",
"import",
"math",
"values",
"=",
"[",
"]",
"for",
"line",
"in",
"sys",
".",
"stdin",
":",
"values",
".",
"extend",
"(",
"map",
"(",
"float",
",",
"re",
".",
"findall",
"(",
"r'\\d+\\.?... | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | AttemptCounter.ready | Whether or not enough time has passed since the last failure | nsq/backoff.py | def ready(self):
'''Whether or not enough time has passed since the last failure'''
if self._last_failed:
delta = time.time() - self._last_failed
return delta >= self.backoff()
return True | def ready(self):
'''Whether or not enough time has passed since the last failure'''
if self._last_failed:
delta = time.time() - self._last_failed
return delta >= self.backoff()
return True | [
"Whether",
"or",
"not",
"enough",
"time",
"has",
"passed",
"since",
"the",
"last",
"failure"
] | dlecocq/nsq-py | python | https://github.com/dlecocq/nsq-py/blob/3ecacf6ab7719d38031179277113d875554a0c16/nsq/backoff.py#L83-L88 | [
"def",
"ready",
"(",
"self",
")",
":",
"if",
"self",
".",
"_last_failed",
":",
"delta",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"_last_failed",
"return",
"delta",
">=",
"self",
".",
"backoff",
"(",
")",
"return",
"True"
] | 3ecacf6ab7719d38031179277113d875554a0c16 |
train | execute_status | Print the status of the daemon.
This function displays the current status of the daemon as well
as the whole queue and all available information about every entry
in the queue.
`terminaltables` is used to format and display the queue contents.
`colorclass` is used to color format the various items ... | pueue/client/displaying.py | def execute_status(args, root_dir=None):
"""Print the status of the daemon.
This function displays the current status of the daemon as well
as the whole queue and all available information about every entry
in the queue.
`terminaltables` is used to format and display the queue contents.
`colorc... | def execute_status(args, root_dir=None):
"""Print the status of the daemon.
This function displays the current status of the daemon as well
as the whole queue and all available information about every entry
in the queue.
`terminaltables` is used to format and display the queue contents.
`colorc... | [
"Print",
"the",
"status",
"of",
"the",
"daemon",
"."
] | Nukesor/pueue | python | https://github.com/Nukesor/pueue/blob/f1d276360454d4dd2738658a13df1e20caa4b926/pueue/client/displaying.py#L19-L105 | [
"def",
"execute_status",
"(",
"args",
",",
"root_dir",
"=",
"None",
")",
":",
"status",
"=",
"command_factory",
"(",
"'status'",
")",
"(",
"{",
"}",
",",
"root_dir",
"=",
"root_dir",
")",
"# First rows, showing daemon status",
"if",
"status",
"[",
"'status'",
... | f1d276360454d4dd2738658a13df1e20caa4b926 |
train | execute_log | Print the current log file.
Args:
args['keys'] (int): If given, we only look at the specified processes.
root_dir (string): The path to the root directory the daemon is running in. | pueue/client/displaying.py | def execute_log(args, root_dir):
"""Print the current log file.
Args:
args['keys'] (int): If given, we only look at the specified processes.
root_dir (string): The path to the root directory the daemon is running in.
"""
# Print the logs of all specified processes
if args.get('keys... | def execute_log(args, root_dir):
"""Print the current log file.
Args:
args['keys'] (int): If given, we only look at the specified processes.
root_dir (string): The path to the root directory the daemon is running in.
"""
# Print the logs of all specified processes
if args.get('keys... | [
"Print",
"the",
"current",
"log",
"file",
"."
] | Nukesor/pueue | python | https://github.com/Nukesor/pueue/blob/f1d276360454d4dd2738658a13df1e20caa4b926/pueue/client/displaying.py#L108-L156 | [
"def",
"execute_log",
"(",
"args",
",",
"root_dir",
")",
":",
"# Print the logs of all specified processes",
"if",
"args",
".",
"get",
"(",
"'keys'",
")",
":",
"config_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root_dir",
",",
"'.config/pueue'",
")",
"... | f1d276360454d4dd2738658a13df1e20caa4b926 |
train | execute_show | Print stderr and stdout of the current running process.
Args:
args['watch'] (bool): If True, we open a curses session and tail
the output live in the console.
root_dir (string): The path to the root directory the daemon is running in. | pueue/client/displaying.py | def execute_show(args, root_dir):
"""Print stderr and stdout of the current running process.
Args:
args['watch'] (bool): If True, we open a curses session and tail
the output live in the console.
root_dir (string): The path to the root directory the daemon is runni... | def execute_show(args, root_dir):
"""Print stderr and stdout of the current running process.
Args:
args['watch'] (bool): If True, we open a curses session and tail
the output live in the console.
root_dir (string): The path to the root directory the daemon is runni... | [
"Print",
"stderr",
"and",
"stdout",
"of",
"the",
"current",
"running",
"process",
"."
] | Nukesor/pueue | python | https://github.com/Nukesor/pueue/blob/f1d276360454d4dd2738658a13df1e20caa4b926/pueue/client/displaying.py#L159-L228 | [
"def",
"execute_show",
"(",
"args",
",",
"root_dir",
")",
":",
"key",
"=",
"None",
"if",
"args",
".",
"get",
"(",
"'key'",
")",
":",
"key",
"=",
"args",
"[",
"'key'",
"]",
"status",
"=",
"command_factory",
"(",
"'status'",
")",
"(",
"{",
"}",
",",
... | f1d276360454d4dd2738658a13df1e20caa4b926 |
train | KKBOXTrackFetcher.fetch_track | Fetches a song track by given ID.
:param track_id: the track ID.
:type track_id: str
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.1/reference#tracks-track_id`. | kkbox_developer_sdk/track_fetcher.py | def fetch_track(self, track_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches a song track by given ID.
:param track_id: the track ID.
:type track_id: str
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.1/reference#tracks-track_id`.
''... | def fetch_track(self, track_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches a song track by given ID.
:param track_id: the track ID.
:type track_id: str
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.1/reference#tracks-track_id`.
''... | [
"Fetches",
"a",
"song",
"track",
"by",
"given",
"ID",
"."
] | KKBOX/OpenAPI-Python | python | https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/track_fetcher.py#L13-L26 | [
"def",
"fetch_track",
"(",
"self",
",",
"track_id",
",",
"terr",
"=",
"KKBOXTerritory",
".",
"TAIWAN",
")",
":",
"url",
"=",
"'https://api.kkbox.com/v1.1/tracks/%s'",
"%",
"track_id",
"url",
"+=",
"'?'",
"+",
"url_parse",
".",
"urlencode",
"(",
"{",
"'territor... | 77aa22fd300ed987d5507a5b66b149edcd28047d |
train | Indicator.show | Show a specific indicator by id
:param user: feed username
:param feed: feed name
:param id: indicator endpoint id [INT]
:return: dict
Example:
ret = Indicator.show('csirtgadgets','port-scanners', '1234') | csirtgsdk/indicator.py | def show(self, user, feed, id):
"""
Show a specific indicator by id
:param user: feed username
:param feed: feed name
:param id: indicator endpoint id [INT]
:return: dict
Example:
ret = Indicator.show('csirtgadgets','port-scanners', '1234')
"... | def show(self, user, feed, id):
"""
Show a specific indicator by id
:param user: feed username
:param feed: feed name
:param id: indicator endpoint id [INT]
:return: dict
Example:
ret = Indicator.show('csirtgadgets','port-scanners', '1234')
"... | [
"Show",
"a",
"specific",
"indicator",
"by",
"id"
] | csirtgadgets/csirtgsdk-py | python | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/indicator.py#L50-L63 | [
"def",
"show",
"(",
"self",
",",
"user",
",",
"feed",
",",
"id",
")",
":",
"uri",
"=",
"'/users/{}/feeds/{}/indicators/{}'",
".",
"format",
"(",
"user",
",",
"feed",
",",
"id",
")",
"return",
"self",
".",
"client",
".",
"get",
"(",
"uri",
")"
] | 5a7ed9c5e6fa27170366ecbdef710dc80d537dc2 |
train | Indicator.create | Submit action on the Indicator object
:return: Indicator Object | csirtgsdk/indicator.py | def create(self):
"""
Submit action on the Indicator object
:return: Indicator Object
"""
uri = '/users/{0}/feeds/{1}/indicators'\
.format(self.user, self.feed)
data = {
"indicator": json.loads(str(self.indicator)),
"comment": self.co... | def create(self):
"""
Submit action on the Indicator object
:return: Indicator Object
"""
uri = '/users/{0}/feeds/{1}/indicators'\
.format(self.user, self.feed)
data = {
"indicator": json.loads(str(self.indicator)),
"comment": self.co... | [
"Submit",
"action",
"on",
"the",
"Indicator",
"object"
] | csirtgadgets/csirtgsdk-py | python | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/indicator.py#L116-L146 | [
"def",
"create",
"(",
"self",
")",
":",
"uri",
"=",
"'/users/{0}/feeds/{1}/indicators'",
".",
"format",
"(",
"self",
".",
"user",
",",
"self",
".",
"feed",
")",
"data",
"=",
"{",
"\"indicator\"",
":",
"json",
".",
"loads",
"(",
"str",
"(",
"self",
".",... | 5a7ed9c5e6fa27170366ecbdef710dc80d537dc2 |
train | Indicator.create_bulk | Submit action against the IndicatorBulk endpoint
:param indicators: list of Indicator Objects
:param user: feed username
:param feed: feed name
:return: list of Indicator Objects submitted
from csirtgsdk.client import Client
from csirtgsdk.indicator import Indicator
... | csirtgsdk/indicator.py | def create_bulk(self, indicators, user, feed):
from .constants import API_VERSION
if API_VERSION == '1':
print("create_bulk currently un-avail with APIv1")
raise SystemExit
"""
Submit action against the IndicatorBulk endpoint
:param indicators: list of I... | def create_bulk(self, indicators, user, feed):
from .constants import API_VERSION
if API_VERSION == '1':
print("create_bulk currently un-avail with APIv1")
raise SystemExit
"""
Submit action against the IndicatorBulk endpoint
:param indicators: list of I... | [
"Submit",
"action",
"against",
"the",
"IndicatorBulk",
"endpoint"
] | csirtgadgets/csirtgsdk-py | python | https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/indicator.py#L148-L212 | [
"def",
"create_bulk",
"(",
"self",
",",
"indicators",
",",
"user",
",",
"feed",
")",
":",
"from",
".",
"constants",
"import",
"API_VERSION",
"if",
"API_VERSION",
"==",
"'1'",
":",
"print",
"(",
"\"create_bulk currently un-avail with APIv1\"",
")",
"raise",
"Syst... | 5a7ed9c5e6fa27170366ecbdef710dc80d537dc2 |
train | bind_global_key | An alias for ``bind_key(event_type, ROOT_WINDOW, key_string, cb)``.
:param event_type: Either 'KeyPress' or 'KeyRelease'.
:type event_type: str
:param key_string: A string of the form 'Mod1-Control-a'.
Namely, a list of zero or more modifiers separated by
'-', f... | pyqtkeybind/x11/keybindutil.py | def bind_global_key(conn, event_type, key_string, cb):
"""
An alias for ``bind_key(event_type, ROOT_WINDOW, key_string, cb)``.
:param event_type: Either 'KeyPress' or 'KeyRelease'.
:type event_type: str
:param key_string: A string of the form 'Mod1-Control-a'.
Namely, a list o... | def bind_global_key(conn, event_type, key_string, cb):
"""
An alias for ``bind_key(event_type, ROOT_WINDOW, key_string, cb)``.
:param event_type: Either 'KeyPress' or 'KeyRelease'.
:type event_type: str
:param key_string: A string of the form 'Mod1-Control-a'.
Namely, a list o... | [
"An",
"alias",
"for",
"bind_key",
"(",
"event_type",
"ROOT_WINDOW",
"key_string",
"cb",
")",
".",
":",
"param",
"event_type",
":",
"Either",
"KeyPress",
"or",
"KeyRelease",
".",
":",
"type",
"event_type",
":",
"str",
":",
"param",
"key_string",
":",
"A",
"... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L27-L42 | [
"def",
"bind_global_key",
"(",
"conn",
",",
"event_type",
",",
"key_string",
",",
"cb",
")",
":",
"root",
"=",
"conn",
".",
"get_setup",
"(",
")",
".",
"roots",
"[",
"0",
"]",
".",
"root",
"return",
"bind_key",
"(",
"conn",
",",
"event_type",
",",
"r... | fbfedc654c4f77778d565b52ac76470631036255 |
train | bind_key | Binds a function ``cb`` to a particular key press ``key_string`` on a
window ``wid``. Whether it's a key release or key press binding is
determined by ``event_type``.
``bind_key`` will automatically hook into the ``event`` module's dispatcher,
so that if you're using ``event.main()`` for your main loop,... | pyqtkeybind/x11/keybindutil.py | def bind_key(conn, event_type, wid, key_string, cb):
"""
Binds a function ``cb`` to a particular key press ``key_string`` on a
window ``wid``. Whether it's a key release or key press binding is
determined by ``event_type``.
``bind_key`` will automatically hook into the ``event`` module's dispatcher,... | def bind_key(conn, event_type, wid, key_string, cb):
"""
Binds a function ``cb`` to a particular key press ``key_string`` on a
window ``wid``. Whether it's a key release or key press binding is
determined by ``event_type``.
``bind_key`` will automatically hook into the ``event`` module's dispatcher,... | [
"Binds",
"a",
"function",
"cb",
"to",
"a",
"particular",
"key",
"press",
"key_string",
"on",
"a",
"window",
"wid",
".",
"Whether",
"it",
"s",
"a",
"key",
"release",
"or",
"key",
"press",
"binding",
"is",
"determined",
"by",
"event_type",
".",
"bind_key",
... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L44-L80 | [
"def",
"bind_key",
"(",
"conn",
",",
"event_type",
",",
"wid",
",",
"key_string",
",",
"cb",
")",
":",
"assert",
"event_type",
"in",
"(",
"'KeyPress'",
",",
"'KeyRelease'",
")",
"mods",
",",
"kc",
"=",
"parse_keystring",
"(",
"conn",
",",
"key_string",
"... | fbfedc654c4f77778d565b52ac76470631036255 |
train | parse_keystring | A utility function to turn strings like 'Mod1+Mod4+a' into a pair
corresponding to its modifiers and keycode.
:param key_string: String starting with zero or more modifiers followed
by exactly one key press.
Available modifiers: Control, Mod1, Mod2, Mod3, Mod4,
... | pyqtkeybind/x11/keybindutil.py | def parse_keystring(conn, key_string):
"""
A utility function to turn strings like 'Mod1+Mod4+a' into a pair
corresponding to its modifiers and keycode.
:param key_string: String starting with zero or more modifiers followed
by exactly one key press.
Avail... | def parse_keystring(conn, key_string):
"""
A utility function to turn strings like 'Mod1+Mod4+a' into a pair
corresponding to its modifiers and keycode.
:param key_string: String starting with zero or more modifiers followed
by exactly one key press.
Avail... | [
"A",
"utility",
"function",
"to",
"turn",
"strings",
"like",
"Mod1",
"+",
"Mod4",
"+",
"a",
"into",
"a",
"pair",
"corresponding",
"to",
"its",
"modifiers",
"and",
"keycode",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L82-L140 | [
"def",
"parse_keystring",
"(",
"conn",
",",
"key_string",
")",
":",
"# FIXME this code is temporary hack, requires better abstraction",
"from",
"PyQt5",
".",
"QtGui",
"import",
"QKeySequence",
"from",
"PyQt5",
".",
"QtCore",
"import",
"Qt",
"from",
".",
"qt_keycodes",
... | fbfedc654c4f77778d565b52ac76470631036255 |
train | lookup_string | Finds the keycode associated with a string representation of a keysym.
:param kstr: English representation of a keysym.
:return: Keycode, if one exists.
:rtype: int | pyqtkeybind/x11/keybindutil.py | def lookup_string(conn, kstr):
"""
Finds the keycode associated with a string representation of a keysym.
:param kstr: English representation of a keysym.
:return: Keycode, if one exists.
:rtype: int
"""
if kstr in keysyms:
return get_keycode(conn, keysyms[kstr])
elif len(kstr) ... | def lookup_string(conn, kstr):
"""
Finds the keycode associated with a string representation of a keysym.
:param kstr: English representation of a keysym.
:return: Keycode, if one exists.
:rtype: int
"""
if kstr in keysyms:
return get_keycode(conn, keysyms[kstr])
elif len(kstr) ... | [
"Finds",
"the",
"keycode",
"associated",
"with",
"a",
"string",
"representation",
"of",
"a",
"keysym",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L142-L155 | [
"def",
"lookup_string",
"(",
"conn",
",",
"kstr",
")",
":",
"if",
"kstr",
"in",
"keysyms",
":",
"return",
"get_keycode",
"(",
"conn",
",",
"keysyms",
"[",
"kstr",
"]",
")",
"elif",
"len",
"(",
"kstr",
")",
">",
"1",
"and",
"kstr",
".",
"capitalize",
... | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_keyboard_mapping | Return a keyboard mapping cookie that can be used to fetch the table of
keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie | pyqtkeybind/x11/keybindutil.py | def get_keyboard_mapping(conn):
"""
Return a keyboard mapping cookie that can be used to fetch the table of
keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie
"""
mn, mx = get_min_max_keycode(conn)
return conn.core.GetKeyboardMapping(mn, mx - mn + 1) | def get_keyboard_mapping(conn):
"""
Return a keyboard mapping cookie that can be used to fetch the table of
keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie
"""
mn, mx = get_min_max_keycode(conn)
return conn.core.GetKeyboardMapping(mn, mx - mn + 1) | [
"Return",
"a",
"keyboard",
"mapping",
"cookie",
"that",
"can",
"be",
"used",
"to",
"fetch",
"the",
"table",
"of",
"keysyms",
"in",
"the",
"current",
"X",
"environment",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L166-L175 | [
"def",
"get_keyboard_mapping",
"(",
"conn",
")",
":",
"mn",
",",
"mx",
"=",
"get_min_max_keycode",
"(",
"conn",
")",
"return",
"conn",
".",
"core",
".",
"GetKeyboardMapping",
"(",
"mn",
",",
"mx",
"-",
"mn",
"+",
"1",
")"
] | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_keyboard_mapping_unchecked | Return an unchecked keyboard mapping cookie that can be used to fetch the
table of keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie | pyqtkeybind/x11/keybindutil.py | def get_keyboard_mapping_unchecked(conn):
"""
Return an unchecked keyboard mapping cookie that can be used to fetch the
table of keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie
"""
mn, mx = get_min_max_keycode()
return conn.core.GetKeyboardMappingUnchecked... | def get_keyboard_mapping_unchecked(conn):
"""
Return an unchecked keyboard mapping cookie that can be used to fetch the
table of keysyms in the current X environment.
:rtype: xcb.xproto.GetKeyboardMappingCookie
"""
mn, mx = get_min_max_keycode()
return conn.core.GetKeyboardMappingUnchecked... | [
"Return",
"an",
"unchecked",
"keyboard",
"mapping",
"cookie",
"that",
"can",
"be",
"used",
"to",
"fetch",
"the",
"table",
"of",
"keysyms",
"in",
"the",
"current",
"X",
"environment",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L177-L186 | [
"def",
"get_keyboard_mapping_unchecked",
"(",
"conn",
")",
":",
"mn",
",",
"mx",
"=",
"get_min_max_keycode",
"(",
")",
"return",
"conn",
".",
"core",
".",
"GetKeyboardMappingUnchecked",
"(",
"mn",
",",
"mx",
"-",
"mn",
"+",
"1",
")"
] | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_keysym | Get the keysym associated with a particular keycode in the current X
environment. Although we get a list of keysyms from X in
'get_keyboard_mapping', this list is really a table with
'keysys_per_keycode' columns and ``mx - mn`` rows (where ``mx`` is the
maximum keycode and ``mn`` is the minimum keycode)... | pyqtkeybind/x11/keybindutil.py | def get_keysym(conn, keycode, col=0, kbmap=None):
"""
Get the keysym associated with a particular keycode in the current X
environment. Although we get a list of keysyms from X in
'get_keyboard_mapping', this list is really a table with
'keysys_per_keycode' columns and ``mx - mn`` rows (where ``mx``... | def get_keysym(conn, keycode, col=0, kbmap=None):
"""
Get the keysym associated with a particular keycode in the current X
environment. Although we get a list of keysyms from X in
'get_keyboard_mapping', this list is really a table with
'keysys_per_keycode' columns and ``mx - mn`` rows (where ``mx``... | [
"Get",
"the",
"keysym",
"associated",
"with",
"a",
"particular",
"keycode",
"in",
"the",
"current",
"X",
"environment",
".",
"Although",
"we",
"get",
"a",
"list",
"of",
"keysyms",
"from",
"X",
"in",
"get_keyboard_mapping",
"this",
"list",
"is",
"really",
"a"... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L188-L223 | [
"def",
"get_keysym",
"(",
"conn",
",",
"keycode",
",",
"col",
"=",
"0",
",",
"kbmap",
"=",
"None",
")",
":",
"if",
"kbmap",
"is",
"None",
":",
"kbmap",
"=",
"__kbmap",
"mn",
",",
"mx",
"=",
"get_min_max_keycode",
"(",
"conn",
")",
"per",
"=",
"kbma... | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_keycode | Given a keysym, find the keycode mapped to it in the current X environment.
It is necessary to search the keysym table in order to do this, including
all columns.
:param keysym: An X keysym.
:return: A keycode or None if one could not be found.
:rtype: int | pyqtkeybind/x11/keybindutil.py | def get_keycode(conn, keysym):
"""
Given a keysym, find the keycode mapped to it in the current X environment.
It is necessary to search the keysym table in order to do this, including
all columns.
:param keysym: An X keysym.
:return: A keycode or None if one could not be found.
:rtype: int... | def get_keycode(conn, keysym):
"""
Given a keysym, find the keycode mapped to it in the current X environment.
It is necessary to search the keysym table in order to do this, including
all columns.
:param keysym: An X keysym.
:return: A keycode or None if one could not be found.
:rtype: int... | [
"Given",
"a",
"keysym",
"find",
"the",
"keycode",
"mapped",
"to",
"it",
"in",
"the",
"current",
"X",
"environment",
".",
"It",
"is",
"necessary",
"to",
"search",
"the",
"keysym",
"table",
"in",
"order",
"to",
"do",
"this",
"including",
"all",
"columns",
... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L235-L253 | [
"def",
"get_keycode",
"(",
"conn",
",",
"keysym",
")",
":",
"mn",
",",
"mx",
"=",
"get_min_max_keycode",
"(",
"conn",
")",
"cols",
"=",
"__kbmap",
".",
"keysyms_per_keycode",
"for",
"i",
"in",
"range",
"(",
"mn",
",",
"mx",
"+",
"1",
")",
":",
"for",... | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_keys_to_mods | Fetches and creates the keycode -> modifier mask mapping. Typically, you
shouldn't have to use this---xpybutil will keep this up to date if it
changes.
This function may be useful in that it should closely replicate the output
of the ``xmodmap`` command. For example:
::
keymods = get_key... | pyqtkeybind/x11/keybindutil.py | def get_keys_to_mods(conn):
"""
Fetches and creates the keycode -> modifier mask mapping. Typically, you
shouldn't have to use this---xpybutil will keep this up to date if it
changes.
This function may be useful in that it should closely replicate the output
of the ``xmodmap`` command. For exam... | def get_keys_to_mods(conn):
"""
Fetches and creates the keycode -> modifier mask mapping. Typically, you
shouldn't have to use this---xpybutil will keep this up to date if it
changes.
This function may be useful in that it should closely replicate the output
of the ``xmodmap`` command. For exam... | [
"Fetches",
"and",
"creates",
"the",
"keycode",
"-",
">",
"modifier",
"mask",
"mapping",
".",
"Typically",
"you",
"shouldn",
"t",
"have",
"to",
"use",
"this",
"---",
"xpybutil",
"will",
"keep",
"this",
"up",
"to",
"date",
"if",
"it",
"changes",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L255-L291 | [
"def",
"get_keys_to_mods",
"(",
"conn",
")",
":",
"mm",
"=",
"xproto",
".",
"ModMask",
"modmasks",
"=",
"[",
"mm",
".",
"Shift",
",",
"mm",
".",
"Lock",
",",
"mm",
".",
"Control",
",",
"mm",
".",
"_1",
",",
"mm",
".",
"_2",
",",
"mm",
".",
"_3"... | fbfedc654c4f77778d565b52ac76470631036255 |
train | get_modifiers | Takes a ``state`` (typically found in key press or button press events)
and returns a string list representation of the modifiers that were pressed
when generating the event.
:param state: Typically from ``some_event.state``.
:return: List of modifier string representations.
:rtype: [str] | pyqtkeybind/x11/keybindutil.py | def get_modifiers(state):
"""
Takes a ``state`` (typically found in key press or button press events)
and returns a string list representation of the modifiers that were pressed
when generating the event.
:param state: Typically from ``some_event.state``.
:return: List of modifier string repres... | def get_modifiers(state):
"""
Takes a ``state`` (typically found in key press or button press events)
and returns a string list representation of the modifiers that were pressed
when generating the event.
:param state: Typically from ``some_event.state``.
:return: List of modifier string repres... | [
"Takes",
"a",
"state",
"(",
"typically",
"found",
"in",
"key",
"press",
"or",
"button",
"press",
"events",
")",
"and",
"returns",
"a",
"string",
"list",
"representation",
"of",
"the",
"modifiers",
"that",
"were",
"pressed",
"when",
"generating",
"the",
"even... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L293-L332 | [
"def",
"get_modifiers",
"(",
"state",
")",
":",
"ret",
"=",
"[",
"]",
"if",
"state",
"&",
"xproto",
".",
"ModMask",
".",
"Shift",
":",
"ret",
".",
"append",
"(",
"'Shift'",
")",
"if",
"state",
"&",
"xproto",
".",
"ModMask",
".",
"Lock",
":",
"ret",... | fbfedc654c4f77778d565b52ac76470631036255 |
train | grab_key | Grabs a key for a particular window and a modifiers/key value.
If the grab was successful, return True. Otherwise, return False.
If your client is grabbing keys, it is useful to notify the user if a
key wasn't grabbed. Keyboard shortcuts not responding is disorienting!
Also, this function will grab sev... | pyqtkeybind/x11/keybindutil.py | def grab_key(conn, wid, modifiers, key):
"""
Grabs a key for a particular window and a modifiers/key value.
If the grab was successful, return True. Otherwise, return False.
If your client is grabbing keys, it is useful to notify the user if a
key wasn't grabbed. Keyboard shortcuts not responding is... | def grab_key(conn, wid, modifiers, key):
"""
Grabs a key for a particular window and a modifiers/key value.
If the grab was successful, return True. Otherwise, return False.
If your client is grabbing keys, it is useful to notify the user if a
key wasn't grabbed. Keyboard shortcuts not responding is... | [
"Grabs",
"a",
"key",
"for",
"a",
"particular",
"window",
"and",
"a",
"modifiers",
"/",
"key",
"value",
".",
"If",
"the",
"grab",
"was",
"successful",
"return",
"True",
".",
"Otherwise",
"return",
"False",
".",
"If",
"your",
"client",
"is",
"grabbing",
"k... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L334-L363 | [
"def",
"grab_key",
"(",
"conn",
",",
"wid",
",",
"modifiers",
",",
"key",
")",
":",
"try",
":",
"for",
"mod",
"in",
"TRIVIAL_MODS",
":",
"conn",
".",
"core",
".",
"GrabKeyChecked",
"(",
"True",
",",
"wid",
",",
"modifiers",
"|",
"mod",
",",
"key",
... | fbfedc654c4f77778d565b52ac76470631036255 |
train | ungrab_key | Ungrabs a key that was grabbed by ``grab_key``. Similarly, it will return
True on success and False on failure.
When ungrabbing a key, the parameters to this function should be
*precisely* the same as the parameters to ``grab_key``.
:param wid: A window identifier.
:type wid: int
:param modifi... | pyqtkeybind/x11/keybindutil.py | def ungrab_key(conn, wid, modifiers, key):
"""
Ungrabs a key that was grabbed by ``grab_key``. Similarly, it will return
True on success and False on failure.
When ungrabbing a key, the parameters to this function should be
*precisely* the same as the parameters to ``grab_key``.
:param wid: A ... | def ungrab_key(conn, wid, modifiers, key):
"""
Ungrabs a key that was grabbed by ``grab_key``. Similarly, it will return
True on success and False on failure.
When ungrabbing a key, the parameters to this function should be
*precisely* the same as the parameters to ``grab_key``.
:param wid: A ... | [
"Ungrabs",
"a",
"key",
"that",
"was",
"grabbed",
"by",
"grab_key",
".",
"Similarly",
"it",
"will",
"return",
"True",
"on",
"success",
"and",
"False",
"on",
"failure",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L365-L387 | [
"def",
"ungrab_key",
"(",
"conn",
",",
"wid",
",",
"modifiers",
",",
"key",
")",
":",
"try",
":",
"for",
"mod",
"in",
"TRIVIAL_MODS",
":",
"conn",
".",
"core",
".",
"UngrabKeyChecked",
"(",
"key",
",",
"wid",
",",
"modifiers",
"|",
"mod",
")",
".",
... | fbfedc654c4f77778d565b52ac76470631036255 |
train | update_keyboard_mapping | Whenever the keyboard mapping is changed, this function needs to be called
to update xpybutil's internal representing of the current keysym table.
Indeed, xpybutil will do this for you automatically.
Moreover, if something is changed that affects the current keygrabs,
xpybutil will initiate a regrab wi... | pyqtkeybind/x11/keybindutil.py | def update_keyboard_mapping(conn, e):
"""
Whenever the keyboard mapping is changed, this function needs to be called
to update xpybutil's internal representing of the current keysym table.
Indeed, xpybutil will do this for you automatically.
Moreover, if something is changed that affects the curren... | def update_keyboard_mapping(conn, e):
"""
Whenever the keyboard mapping is changed, this function needs to be called
to update xpybutil's internal representing of the current keysym table.
Indeed, xpybutil will do this for you automatically.
Moreover, if something is changed that affects the curren... | [
"Whenever",
"the",
"keyboard",
"mapping",
"is",
"changed",
"this",
"function",
"needs",
"to",
"be",
"called",
"to",
"update",
"xpybutil",
"s",
"internal",
"representing",
"of",
"the",
"current",
"keysym",
"table",
".",
"Indeed",
"xpybutil",
"will",
"do",
"this... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L389-L422 | [
"def",
"update_keyboard_mapping",
"(",
"conn",
",",
"e",
")",
":",
"global",
"__kbmap",
",",
"__keysmods",
"newmap",
"=",
"get_keyboard_mapping",
"(",
"conn",
")",
".",
"reply",
"(",
")",
"if",
"e",
"is",
"None",
":",
"__kbmap",
"=",
"newmap",
"__keysmods"... | fbfedc654c4f77778d565b52ac76470631036255 |
train | run_keybind_callbacks | A function that intercepts all key press/release events, and runs
their corresponding callback functions. Nothing much to see here, except
that we must mask out the trivial modifiers from the state in order to
find the right callback.
Callbacks are called in the order that they have been added. (FIFO.)
... | pyqtkeybind/x11/keybindutil.py | def run_keybind_callbacks(e):
"""
A function that intercepts all key press/release events, and runs
their corresponding callback functions. Nothing much to see here, except
that we must mask out the trivial modifiers from the state in order to
find the right callback.
Callbacks are called in the... | def run_keybind_callbacks(e):
"""
A function that intercepts all key press/release events, and runs
their corresponding callback functions. Nothing much to see here, except
that we must mask out the trivial modifiers from the state in order to
find the right callback.
Callbacks are called in the... | [
"A",
"function",
"that",
"intercepts",
"all",
"key",
"press",
"/",
"release",
"events",
"and",
"runs",
"their",
"corresponding",
"callback",
"functions",
".",
"Nothing",
"much",
"to",
"see",
"here",
"except",
"that",
"we",
"must",
"mask",
"out",
"the",
"triv... | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L424-L447 | [
"def",
"run_keybind_callbacks",
"(",
"e",
")",
":",
"kc",
",",
"mods",
"=",
"e",
".",
"detail",
",",
"e",
".",
"state",
"for",
"mod",
"in",
"TRIVIAL_MODS",
":",
"mods",
"&=",
"~",
"mod",
"key",
"=",
"(",
"e",
".",
"event",
",",
"mods",
",",
"kc",... | fbfedc654c4f77778d565b52ac76470631036255 |
train | __regrab | Takes a dictionary of changes (mapping old keycode to new keycode) and
regrabs any keys that have been changed with the updated keycode.
:param changes: Mapping of changes from old keycode to new keycode.
:type changes: dict
:rtype: void | pyqtkeybind/x11/keybindutil.py | def __regrab(changes):
"""
Takes a dictionary of changes (mapping old keycode to new keycode) and
regrabs any keys that have been changed with the updated keycode.
:param changes: Mapping of changes from old keycode to new keycode.
:type changes: dict
:rtype: void
"""
for wid, mods, kc ... | def __regrab(changes):
"""
Takes a dictionary of changes (mapping old keycode to new keycode) and
regrabs any keys that have been changed with the updated keycode.
:param changes: Mapping of changes from old keycode to new keycode.
:type changes: dict
:rtype: void
"""
for wid, mods, kc ... | [
"Takes",
"a",
"dictionary",
"of",
"changes",
"(",
"mapping",
"old",
"keycode",
"to",
"new",
"keycode",
")",
"and",
"regrabs",
"any",
"keys",
"that",
"have",
"been",
"changed",
"with",
"the",
"updated",
"keycode",
"."
] | codito/pyqtkeybind | python | https://github.com/codito/pyqtkeybind/blob/fbfedc654c4f77778d565b52ac76470631036255/pyqtkeybind/x11/keybindutil.py#L449-L466 | [
"def",
"__regrab",
"(",
"changes",
")",
":",
"for",
"wid",
",",
"mods",
",",
"kc",
"in",
"__keybinds",
".",
"keys",
"(",
")",
":",
"if",
"kc",
"in",
"changes",
":",
"ungrab_key",
"(",
"wid",
",",
"mods",
",",
"kc",
")",
"grab_key",
"(",
"wid",
",... | fbfedc654c4f77778d565b52ac76470631036255 |
train | StorageManager.get_storages | Return a list of Storage objects from the API.
Storage types: public, private, normal, backup, cdrom, template, favorite | upcloud_api/cloud_manager/storage_mixin.py | def get_storages(self, storage_type='normal'):
"""
Return a list of Storage objects from the API.
Storage types: public, private, normal, backup, cdrom, template, favorite
"""
res = self.get_request('/storage/' + storage_type)
return Storage._create_storage_objs(res['sto... | def get_storages(self, storage_type='normal'):
"""
Return a list of Storage objects from the API.
Storage types: public, private, normal, backup, cdrom, template, favorite
"""
res = self.get_request('/storage/' + storage_type)
return Storage._create_storage_objs(res['sto... | [
"Return",
"a",
"list",
"of",
"Storage",
"objects",
"from",
"the",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L14-L21 | [
"def",
"get_storages",
"(",
"self",
",",
"storage_type",
"=",
"'normal'",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/storage/'",
"+",
"storage_type",
")",
"return",
"Storage",
".",
"_create_storage_objs",
"(",
"res",
"[",
"'storages'",
"]",
",... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | StorageManager.get_storage | Return a Storage object from the API. | upcloud_api/cloud_manager/storage_mixin.py | def get_storage(self, storage):
"""
Return a Storage object from the API.
"""
res = self.get_request('/storage/' + str(storage))
return Storage(cloud_manager=self, **res['storage']) | def get_storage(self, storage):
"""
Return a Storage object from the API.
"""
res = self.get_request('/storage/' + str(storage))
return Storage(cloud_manager=self, **res['storage']) | [
"Return",
"a",
"Storage",
"object",
"from",
"the",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L23-L28 | [
"def",
"get_storage",
"(",
"self",
",",
"storage",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/storage/'",
"+",
"str",
"(",
"storage",
")",
")",
"return",
"Storage",
"(",
"cloud_manager",
"=",
"self",
",",
"*",
"*",
"res",
"[",
"'storage'... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | StorageManager.create_storage | Create a Storage object. Returns an object based on the API's response. | upcloud_api/cloud_manager/storage_mixin.py | def create_storage(self, size=10, tier='maxiops', title='Storage disk', zone='fi-hel1', backup_rule={}):
"""
Create a Storage object. Returns an object based on the API's response.
"""
body = {
'storage': {
'size': size,
'tier': tier,
... | def create_storage(self, size=10, tier='maxiops', title='Storage disk', zone='fi-hel1', backup_rule={}):
"""
Create a Storage object. Returns an object based on the API's response.
"""
body = {
'storage': {
'size': size,
'tier': tier,
... | [
"Create",
"a",
"Storage",
"object",
".",
"Returns",
"an",
"object",
"based",
"on",
"the",
"API",
"s",
"response",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L30-L44 | [
"def",
"create_storage",
"(",
"self",
",",
"size",
"=",
"10",
",",
"tier",
"=",
"'maxiops'",
",",
"title",
"=",
"'Storage disk'",
",",
"zone",
"=",
"'fi-hel1'",
",",
"backup_rule",
"=",
"{",
"}",
")",
":",
"body",
"=",
"{",
"'storage'",
":",
"{",
"'s... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | StorageManager.modify_storage | Modify a Storage object. Returns an object based on the API's response. | upcloud_api/cloud_manager/storage_mixin.py | def modify_storage(self, storage, size, title, backup_rule={}):
"""
Modify a Storage object. Returns an object based on the API's response.
"""
res = self._modify_storage(str(storage), size, title, backup_rule)
return Storage(cloud_manager=self, **res['storage']) | def modify_storage(self, storage, size, title, backup_rule={}):
"""
Modify a Storage object. Returns an object based on the API's response.
"""
res = self._modify_storage(str(storage), size, title, backup_rule)
return Storage(cloud_manager=self, **res['storage']) | [
"Modify",
"a",
"Storage",
"object",
".",
"Returns",
"an",
"object",
"based",
"on",
"the",
"API",
"s",
"response",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L56-L61 | [
"def",
"modify_storage",
"(",
"self",
",",
"storage",
",",
"size",
",",
"title",
",",
"backup_rule",
"=",
"{",
"}",
")",
":",
"res",
"=",
"self",
".",
"_modify_storage",
"(",
"str",
"(",
"storage",
")",
",",
"size",
",",
"title",
",",
"backup_rule",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | StorageManager.attach_storage | Attach a Storage object to a Server. Return a list of the server's storages. | upcloud_api/cloud_manager/storage_mixin.py | def attach_storage(self, server, storage, storage_type, address):
"""
Attach a Storage object to a Server. Return a list of the server's storages.
"""
body = {'storage_device': {}}
if storage:
body['storage_device']['storage'] = str(storage)
if storage_type:
... | def attach_storage(self, server, storage, storage_type, address):
"""
Attach a Storage object to a Server. Return a list of the server's storages.
"""
body = {'storage_device': {}}
if storage:
body['storage_device']['storage'] = str(storage)
if storage_type:
... | [
"Attach",
"a",
"Storage",
"object",
"to",
"a",
"Server",
".",
"Return",
"a",
"list",
"of",
"the",
"server",
"s",
"storages",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L69-L85 | [
"def",
"attach_storage",
"(",
"self",
",",
"server",
",",
"storage",
",",
"storage_type",
",",
"address",
")",
":",
"body",
"=",
"{",
"'storage_device'",
":",
"{",
"}",
"}",
"if",
"storage",
":",
"body",
"[",
"'storage_device'",
"]",
"[",
"'storage'",
"]... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | StorageManager.detach_storage | Detach a Storage object to a Server. Return a list of the server's storages. | upcloud_api/cloud_manager/storage_mixin.py | def detach_storage(self, server, address):
"""
Detach a Storage object to a Server. Return a list of the server's storages.
"""
body = {'storage_device': {'address': address}}
url = '/server/{0}/storage/detach'.format(server)
res = self.post_request(url, body)
ret... | def detach_storage(self, server, address):
"""
Detach a Storage object to a Server. Return a list of the server's storages.
"""
body = {'storage_device': {'address': address}}
url = '/server/{0}/storage/detach'.format(server)
res = self.post_request(url, body)
ret... | [
"Detach",
"a",
"Storage",
"object",
"to",
"a",
"Server",
".",
"Return",
"a",
"list",
"of",
"the",
"server",
"s",
"storages",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/storage_mixin.py#L87-L94 | [
"def",
"detach_storage",
"(",
"self",
",",
"server",
",",
"address",
")",
":",
"body",
"=",
"{",
"'storage_device'",
":",
"{",
"'address'",
":",
"address",
"}",
"}",
"url",
"=",
"'/server/{0}/storage/detach'",
".",
"format",
"(",
"server",
")",
"res",
"=",... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Storage._reset | Reset after repopulating from API. | upcloud_api/storage.py | def _reset(self, **kwargs):
"""
Reset after repopulating from API.
"""
# there are some inconsistenciens in the API regarding these
# note: this could be written in fancier ways, but this way is simpler
if 'uuid' in kwargs:
self.uuid = kwargs['uuid']
... | def _reset(self, **kwargs):
"""
Reset after repopulating from API.
"""
# there are some inconsistenciens in the API regarding these
# note: this could be written in fancier ways, but this way is simpler
if 'uuid' in kwargs:
self.uuid = kwargs['uuid']
... | [
"Reset",
"after",
"repopulating",
"from",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/storage.py#L29-L59 | [
"def",
"_reset",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# there are some inconsistenciens in the API regarding these",
"# note: this could be written in fancier ways, but this way is simpler",
"if",
"'uuid'",
"in",
"kwargs",
":",
"self",
".",
"uuid",
"=",
"kwargs"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Storage.save | Save (modify) the storage to the API.
Note: only size and title are updateable fields. | upcloud_api/storage.py | def save(self):
"""
Save (modify) the storage to the API.
Note: only size and title are updateable fields.
"""
res = self.cloud_manager._modify_storage(self, self.size, self.title)
self._reset(**res['storage']) | def save(self):
"""
Save (modify) the storage to the API.
Note: only size and title are updateable fields.
"""
res = self.cloud_manager._modify_storage(self, self.size, self.title)
self._reset(**res['storage']) | [
"Save",
"(",
"modify",
")",
"the",
"storage",
"to",
"the",
"API",
".",
"Note",
":",
"only",
"size",
"and",
"title",
"are",
"updateable",
"fields",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/storage.py#L67-L73 | [
"def",
"save",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"cloud_manager",
".",
"_modify_storage",
"(",
"self",
",",
"self",
".",
"size",
",",
"self",
".",
"title",
")",
"self",
".",
"_reset",
"(",
"*",
"*",
"res",
"[",
"'storage'",
"]",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Storage.to_dict | Return a dict that can be serialised to JSON and sent to UpCloud's API.
Uses the convenience attribute `os` for determining `action` and `storage`
fields. | upcloud_api/storage.py | def to_dict(self):
"""
Return a dict that can be serialised to JSON and sent to UpCloud's API.
Uses the convenience attribute `os` for determining `action` and `storage`
fields.
"""
body = {
'tier': self.tier,
'title': self.title,
'siz... | def to_dict(self):
"""
Return a dict that can be serialised to JSON and sent to UpCloud's API.
Uses the convenience attribute `os` for determining `action` and `storage`
fields.
"""
body = {
'tier': self.tier,
'title': self.title,
'siz... | [
"Return",
"a",
"dict",
"that",
"can",
"be",
"serialised",
"to",
"JSON",
"and",
"sent",
"to",
"UpCloud",
"s",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/storage.py#L82-L103 | [
"def",
"to_dict",
"(",
"self",
")",
":",
"body",
"=",
"{",
"'tier'",
":",
"self",
".",
"tier",
",",
"'title'",
":",
"self",
".",
"title",
",",
"'size'",
":",
"self",
".",
"size",
",",
"}",
"# optionals",
"if",
"hasattr",
"(",
"self",
",",
"'address... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | KKBOXAlbumFetcher.fetch_album | Fetches an album by given ID.
:param album_id: the album ID.
:type album_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.1/reference#albums-album_id`. | kkbox_developer_sdk/album_fetcher.py | def fetch_album(self, album_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches an album by given ID.
:param album_id: the album ID.
:type album_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.... | def fetch_album(self, album_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches an album by given ID.
:param album_id: the album ID.
:type album_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
See `https://docs-en.kkbox.codes/v1.... | [
"Fetches",
"an",
"album",
"by",
"given",
"ID",
"."
] | KKBOX/OpenAPI-Python | python | https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/album_fetcher.py#L13-L27 | [
"def",
"fetch_album",
"(",
"self",
",",
"album_id",
",",
"terr",
"=",
"KKBOXTerritory",
".",
"TAIWAN",
")",
":",
"url",
"=",
"'https://api.kkbox.com/v1.1/albums/%s'",
"%",
"album_id",
"url",
"+=",
"'?'",
"+",
"url_parse",
".",
"urlencode",
"(",
"{",
"'territor... | 77aa22fd300ed987d5507a5b66b149edcd28047d |
train | Torrent.lookup | Prints name, author, size and age | KickassAPI.py | def lookup(self):
"""
Prints name, author, size and age
"""
print "%s by %s, size: %s, uploaded %s ago" % (self.name, self.author,
self.size, self.age) | def lookup(self):
"""
Prints name, author, size and age
"""
print "%s by %s, size: %s, uploaded %s ago" % (self.name, self.author,
self.size, self.age) | [
"Prints",
"name",
"author",
"size",
"and",
"age"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L60-L65 | [
"def",
"lookup",
"(",
"self",
")",
":",
"print",
"\"%s by %s, size: %s, uploaded %s ago\"",
"%",
"(",
"self",
".",
"name",
",",
"self",
".",
"author",
",",
"self",
".",
"size",
",",
"self",
".",
"age",
")"
] | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Url._get_max_page | Open url and return amount of pages | KickassAPI.py | def _get_max_page(self, url):
"""
Open url and return amount of pages
"""
html = requests.get(url).text
pq = PyQuery(html)
try:
tds = int(pq("h2").text().split()[-1])
if tds % 25:
return tds / 25 + 1
return tds / 25
... | def _get_max_page(self, url):
"""
Open url and return amount of pages
"""
html = requests.get(url).text
pq = PyQuery(html)
try:
tds = int(pq("h2").text().split()[-1])
if tds % 25:
return tds / 25 + 1
return tds / 25
... | [
"Open",
"url",
"and",
"return",
"amount",
"of",
"pages"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L88-L100 | [
"def",
"_get_max_page",
"(",
"self",
",",
"url",
")",
":",
"html",
"=",
"requests",
".",
"get",
"(",
"url",
")",
".",
"text",
"pq",
"=",
"PyQuery",
"(",
"html",
")",
"try",
":",
"tds",
"=",
"int",
"(",
"pq",
"(",
"\"h2\"",
")",
".",
"text",
"("... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | SearchUrl.build | Build and return url. Also update max_page. | KickassAPI.py | def build(self, update=True):
"""
Build and return url. Also update max_page.
"""
ret = self.base + self.query
page = "".join(("/", str(self.page), "/"))
if self.category:
category = " category:" + self.category
else:
category = ""
... | def build(self, update=True):
"""
Build and return url. Also update max_page.
"""
ret = self.base + self.query
page = "".join(("/", str(self.page), "/"))
if self.category:
category = " category:" + self.category
else:
category = ""
... | [
"Build",
"and",
"return",
"url",
".",
"Also",
"update",
"max_page",
"."
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L143-L164 | [
"def",
"build",
"(",
"self",
",",
"update",
"=",
"True",
")",
":",
"ret",
"=",
"self",
".",
"base",
"+",
"self",
".",
"query",
"page",
"=",
"\"\"",
".",
"join",
"(",
"(",
"\"/\"",
",",
"str",
"(",
"self",
".",
"page",
")",
",",
"\"/\"",
")",
... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | UserUrl.build | Build and return url. Also update max_page.
URL structure for user torrent lists differs from other result lists
as the page number is part of the query string and not the URL path | KickassAPI.py | def build(self, update=True):
"""
Build and return url. Also update max_page.
URL structure for user torrent lists differs from other result lists
as the page number is part of the query string and not the URL path
"""
query_str = "?page={}".format(self.page)
if s... | def build(self, update=True):
"""
Build and return url. Also update max_page.
URL structure for user torrent lists differs from other result lists
as the page number is part of the query string and not the URL path
"""
query_str = "?page={}".format(self.page)
if s... | [
"Build",
"and",
"return",
"url",
".",
"Also",
"update",
"max_page",
".",
"URL",
"structure",
"for",
"user",
"torrent",
"lists",
"differs",
"from",
"other",
"result",
"lists",
"as",
"the",
"page",
"number",
"is",
"part",
"of",
"the",
"query",
"string",
"and... | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L177-L191 | [
"def",
"build",
"(",
"self",
",",
"update",
"=",
"True",
")",
":",
"query_str",
"=",
"\"?page={}\"",
".",
"format",
"(",
"self",
".",
"page",
")",
"if",
"self",
".",
"order",
":",
"query_str",
"+=",
"\"\"",
".",
"join",
"(",
"(",
"\"&field=\"",
",",
... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results._items | Parse url and yield namedtuple Torrent for every torrent on page | KickassAPI.py | def _items(self):
"""
Parse url and yield namedtuple Torrent for every torrent on page
"""
torrents = map(self._get_torrent, self._get_rows())
for t in torrents:
yield t | def _items(self):
"""
Parse url and yield namedtuple Torrent for every torrent on page
"""
torrents = map(self._get_torrent, self._get_rows())
for t in torrents:
yield t | [
"Parse",
"url",
"and",
"yield",
"namedtuple",
"Torrent",
"for",
"every",
"torrent",
"on",
"page"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L205-L212 | [
"def",
"_items",
"(",
"self",
")",
":",
"torrents",
"=",
"map",
"(",
"self",
".",
"_get_torrent",
",",
"self",
".",
"_get_rows",
"(",
")",
")",
"for",
"t",
"in",
"torrents",
":",
"yield",
"t"
] | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results._get_torrent | Parse row into namedtuple | KickassAPI.py | def _get_torrent(self, row):
"""
Parse row into namedtuple
"""
td = row("td")
name = td("a.cellMainLink").text()
name = name.replace(" . ", ".").replace(" .", ".")
author = td("a.plain").text()
verified_author = True if td(".lightgrey>.ka-verify") else Fal... | def _get_torrent(self, row):
"""
Parse row into namedtuple
"""
td = row("td")
name = td("a.cellMainLink").text()
name = name.replace(" . ", ".").replace(" .", ".")
author = td("a.plain").text()
verified_author = True if td(".lightgrey>.ka-verify") else Fal... | [
"Parse",
"row",
"into",
"namedtuple"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L222-L249 | [
"def",
"_get_torrent",
"(",
"self",
",",
"row",
")",
":",
"td",
"=",
"row",
"(",
"\"td\"",
")",
"name",
"=",
"td",
"(",
"\"a.cellMainLink\"",
")",
".",
"text",
"(",
")",
"name",
"=",
"name",
".",
"replace",
"(",
"\" . \"",
",",
"\".\"",
")",
".",
... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results._get_rows | Return all rows on page | KickassAPI.py | def _get_rows(self):
"""
Return all rows on page
"""
html = requests.get(self.url.build()).text
if re.search('did not match any documents', html):
return []
pq = PyQuery(html)
rows = pq("table.data").find("tr")
return map(rows.eq, range(rows.si... | def _get_rows(self):
"""
Return all rows on page
"""
html = requests.get(self.url.build()).text
if re.search('did not match any documents', html):
return []
pq = PyQuery(html)
rows = pq("table.data").find("tr")
return map(rows.eq, range(rows.si... | [
"Return",
"all",
"rows",
"on",
"page"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L251-L260 | [
"def",
"_get_rows",
"(",
"self",
")",
":",
"html",
"=",
"requests",
".",
"get",
"(",
"self",
".",
"url",
".",
"build",
"(",
")",
")",
".",
"text",
"if",
"re",
".",
"search",
"(",
"'did not match any documents'",
",",
"html",
")",
":",
"return",
"[",
... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results.pages | Yield torrents in range from page_from to page_to | KickassAPI.py | def pages(self, page_from, page_to):
"""
Yield torrents in range from page_from to page_to
"""
if not all([page_from < self.url.max_page, page_from > 0,
page_to <= self.url.max_page, page_to > page_from]):
raise IndexError("Invalid page numbers")
... | def pages(self, page_from, page_to):
"""
Yield torrents in range from page_from to page_to
"""
if not all([page_from < self.url.max_page, page_from > 0,
page_to <= self.url.max_page, page_to > page_from]):
raise IndexError("Invalid page numbers")
... | [
"Yield",
"torrents",
"in",
"range",
"from",
"page_from",
"to",
"page_to"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L283-L320 | [
"def",
"pages",
"(",
"self",
",",
"page_from",
",",
"page_to",
")",
":",
"if",
"not",
"all",
"(",
"[",
"page_from",
"<",
"self",
".",
"url",
".",
"max_page",
",",
"page_from",
">",
"0",
",",
"page_to",
"<=",
"self",
".",
"url",
".",
"max_page",
","... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results.all | Yield torrents in range from current page to last page | KickassAPI.py | def all(self):
"""
Yield torrents in range from current page to last page
"""
return self.pages(self.url.page, self.url.max_page) | def all(self):
"""
Yield torrents in range from current page to last page
"""
return self.pages(self.url.page, self.url.max_page) | [
"Yield",
"torrents",
"in",
"range",
"from",
"current",
"page",
"to",
"last",
"page"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L322-L326 | [
"def",
"all",
"(",
"self",
")",
":",
"return",
"self",
".",
"pages",
"(",
"self",
".",
"url",
".",
"page",
",",
"self",
".",
"url",
".",
"max_page",
")"
] | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Results.order | Set field and order set by arguments | KickassAPI.py | def order(self, field, order=None):
"""
Set field and order set by arguments
"""
if not order:
order = ORDER.DESC
self.url.order = (field, order)
self.url.set_page(1)
return self | def order(self, field, order=None):
"""
Set field and order set by arguments
"""
if not order:
order = ORDER.DESC
self.url.order = (field, order)
self.url.set_page(1)
return self | [
"Set",
"field",
"and",
"order",
"set",
"by",
"arguments"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L328-L336 | [
"def",
"order",
"(",
"self",
",",
"field",
",",
"order",
"=",
"None",
")",
":",
"if",
"not",
"order",
":",
"order",
"=",
"ORDER",
".",
"DESC",
"self",
".",
"url",
".",
"order",
"=",
"(",
"field",
",",
"order",
")",
"self",
".",
"url",
".",
"set... | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | Search.category | Change category of current search and return self | KickassAPI.py | def category(self, category):
"""
Change category of current search and return self
"""
self.url.category = category
self.url.set_page(1)
return self | def category(self, category):
"""
Change category of current search and return self
"""
self.url.category = category
self.url.set_page(1)
return self | [
"Change",
"category",
"of",
"current",
"search",
"and",
"return",
"self"
] | fm4d/KickassAPI | python | https://github.com/fm4d/KickassAPI/blob/6ecc6846dcec0d6f6e493bf776031aa92d55604f/KickassAPI.py#L362-L368 | [
"def",
"category",
"(",
"self",
",",
"category",
")",
":",
"self",
".",
"url",
".",
"category",
"=",
"category",
"self",
".",
"url",
".",
"set_page",
"(",
"1",
")",
"return",
"self"
] | 6ecc6846dcec0d6f6e493bf776031aa92d55604f |
train | FirewallRule.destroy | Remove this FirewallRule from the API.
This instance must be associated with a server for this method to work,
which is done by instantiating via server.get_firewall_rules(). | upcloud_api/firewall.py | def destroy(self):
"""
Remove this FirewallRule from the API.
This instance must be associated with a server for this method to work,
which is done by instantiating via server.get_firewall_rules().
"""
if not hasattr(self, 'server') or not self.server:
raise ... | def destroy(self):
"""
Remove this FirewallRule from the API.
This instance must be associated with a server for this method to work,
which is done by instantiating via server.get_firewall_rules().
"""
if not hasattr(self, 'server') or not self.server:
raise ... | [
"Remove",
"this",
"FirewallRule",
"from",
"the",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/firewall.py#L27-L43 | [
"def",
"destroy",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'server'",
")",
"or",
"not",
"self",
".",
"server",
":",
"raise",
"Exception",
"(",
"\"\"\"FirewallRule not associated with server;\n please use or server.get_firewall_rul... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | KKBOXNewReleaseCategoryFetcher.fetch_new_release_category | Fetches new release categories by given ID.
:param category_id: the station ID.
:type category_id: str
:param terr: the current territory.
:return: API response.
:rtype: list
See `https://docs-en.kkbox.codes/v1.1/reference#newreleasecategories-category_id` | kkbox_developer_sdk/new_release_category_fetcher.py | def fetch_new_release_category(self, category_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches new release categories by given ID.
:param category_id: the station ID.
:type category_id: str
:param terr: the current territory.
:return: API response.
:rtype: list
... | def fetch_new_release_category(self, category_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetches new release categories by given ID.
:param category_id: the station ID.
:type category_id: str
:param terr: the current territory.
:return: API response.
:rtype: list
... | [
"Fetches",
"new",
"release",
"categories",
"by",
"given",
"ID",
"."
] | KKBOX/OpenAPI-Python | python | https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/new_release_category_fetcher.py#L28-L42 | [
"def",
"fetch_new_release_category",
"(",
"self",
",",
"category_id",
",",
"terr",
"=",
"KKBOXTerritory",
".",
"TAIWAN",
")",
":",
"url",
"=",
"'https://api.kkbox.com/v1.1/new-release-categories/%s'",
"%",
"category_id",
"url",
"+=",
"'?'",
"+",
"url_parse",
".",
"u... | 77aa22fd300ed987d5507a5b66b149edcd28047d |
train | KKBOXArtistFetcher.fetch_top_tracks_of_artist | Fetcher top tracks belong to an artist by given ID.
:param artist_id: the artist ID.
:type artist_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
See 'https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id-toptracks' | kkbox_developer_sdk/artist_fetcher.py | def fetch_top_tracks_of_artist(self, artist_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetcher top tracks belong to an artist by given ID.
:param artist_id: the artist ID.
:type artist_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
... | def fetch_top_tracks_of_artist(self, artist_id, terr=KKBOXTerritory.TAIWAN):
'''
Fetcher top tracks belong to an artist by given ID.
:param artist_id: the artist ID.
:type artist_id: str
:param terr: the current territory.
:return: API response.
:rtype: dict
... | [
"Fetcher",
"top",
"tracks",
"belong",
"to",
"an",
"artist",
"by",
"given",
"ID",
"."
] | KKBOX/OpenAPI-Python | python | https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/artist_fetcher.py#L47-L61 | [
"def",
"fetch_top_tracks_of_artist",
"(",
"self",
",",
"artist_id",
",",
"terr",
"=",
"KKBOXTerritory",
".",
"TAIWAN",
")",
":",
"url",
"=",
"'https://api.kkbox.com/v1.1/artists/%s/top-tracks'",
"%",
"artist_id",
"url",
"+=",
"'?'",
"+",
"url_parse",
".",
"urlencode... | 77aa22fd300ed987d5507a5b66b149edcd28047d |
train | TagManager.get_tags | List all tags as Tag objects. | upcloud_api/cloud_manager/tag_mixin.py | def get_tags(self):
"""List all tags as Tag objects."""
res = self.get_request('/tag')
return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']] | def get_tags(self):
"""List all tags as Tag objects."""
res = self.get_request('/tag')
return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']] | [
"List",
"all",
"tags",
"as",
"Tag",
"objects",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L18-L21 | [
"def",
"get_tags",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/tag'",
")",
"return",
"[",
"Tag",
"(",
"cloud_manager",
"=",
"self",
",",
"*",
"*",
"tag",
")",
"for",
"tag",
"in",
"res",
"[",
"'tags'",
"]",
"[",
"'tag'",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | TagManager.get_tag | Return the tag as Tag object. | upcloud_api/cloud_manager/tag_mixin.py | def get_tag(self, name):
"""Return the tag as Tag object."""
res = self.get_request('/tag/' + name)
return Tag(cloud_manager=self, **res['tag']) | def get_tag(self, name):
"""Return the tag as Tag object."""
res = self.get_request('/tag/' + name)
return Tag(cloud_manager=self, **res['tag']) | [
"Return",
"the",
"tag",
"as",
"Tag",
"object",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L23-L26 | [
"def",
"get_tag",
"(",
"self",
",",
"name",
")",
":",
"res",
"=",
"self",
".",
"get_request",
"(",
"'/tag/'",
"+",
"name",
")",
"return",
"Tag",
"(",
"cloud_manager",
"=",
"self",
",",
"*",
"*",
"res",
"[",
"'tag'",
"]",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | TagManager.create_tag | Create a new Tag. Only name is mandatory.
Returns the created Tag object. | upcloud_api/cloud_manager/tag_mixin.py | def create_tag(self, name, description=None, servers=[]):
"""
Create a new Tag. Only name is mandatory.
Returns the created Tag object.
"""
servers = [str(server) for server in servers]
body = {'tag': Tag(name, description, servers).to_dict()}
res = self.request(... | def create_tag(self, name, description=None, servers=[]):
"""
Create a new Tag. Only name is mandatory.
Returns the created Tag object.
"""
servers = [str(server) for server in servers]
body = {'tag': Tag(name, description, servers).to_dict()}
res = self.request(... | [
"Create",
"a",
"new",
"Tag",
".",
"Only",
"name",
"is",
"mandatory",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L28-L38 | [
"def",
"create_tag",
"(",
"self",
",",
"name",
",",
"description",
"=",
"None",
",",
"servers",
"=",
"[",
"]",
")",
":",
"servers",
"=",
"[",
"str",
"(",
"server",
")",
"for",
"server",
"in",
"servers",
"]",
"body",
"=",
"{",
"'tag'",
":",
"Tag",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | TagManager._modify_tag | PUT /tag/name. Returns a dict that can be used to create a Tag object.
Private method used by the Tag class and TagManager.modify_tag. | upcloud_api/cloud_manager/tag_mixin.py | def _modify_tag(self, name, description, servers, new_name):
"""
PUT /tag/name. Returns a dict that can be used to create a Tag object.
Private method used by the Tag class and TagManager.modify_tag.
"""
body = {'tag': Tag(new_name, description, servers).to_dict()}
res =... | def _modify_tag(self, name, description, servers, new_name):
"""
PUT /tag/name. Returns a dict that can be used to create a Tag object.
Private method used by the Tag class and TagManager.modify_tag.
"""
body = {'tag': Tag(new_name, description, servers).to_dict()}
res =... | [
"PUT",
"/",
"tag",
"/",
"name",
".",
"Returns",
"a",
"dict",
"that",
"can",
"be",
"used",
"to",
"create",
"a",
"Tag",
"object",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L40-L48 | [
"def",
"_modify_tag",
"(",
"self",
",",
"name",
",",
"description",
",",
"servers",
",",
"new_name",
")",
":",
"body",
"=",
"{",
"'tag'",
":",
"Tag",
"(",
"new_name",
",",
"description",
",",
"servers",
")",
".",
"to_dict",
"(",
")",
"}",
"res",
"=",... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | TagManager.modify_tag | PUT /tag/name. Returns a new Tag object based on the API response. | upcloud_api/cloud_manager/tag_mixin.py | def modify_tag(self, name, description=None, servers=None, new_name=None):
"""
PUT /tag/name. Returns a new Tag object based on the API response.
"""
res = self._modify_tag(name, description, servers, new_name)
return Tag(cloud_manager=self, **res['tag']) | def modify_tag(self, name, description=None, servers=None, new_name=None):
"""
PUT /tag/name. Returns a new Tag object based on the API response.
"""
res = self._modify_tag(name, description, servers, new_name)
return Tag(cloud_manager=self, **res['tag']) | [
"PUT",
"/",
"tag",
"/",
"name",
".",
"Returns",
"a",
"new",
"Tag",
"object",
"based",
"on",
"the",
"API",
"response",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L50-L55 | [
"def",
"modify_tag",
"(",
"self",
",",
"name",
",",
"description",
"=",
"None",
",",
"servers",
"=",
"None",
",",
"new_name",
"=",
"None",
")",
":",
"res",
"=",
"self",
".",
"_modify_tag",
"(",
"name",
",",
"description",
",",
"servers",
",",
"new_name... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | TagManager.remove_tags | Remove tags from a server.
- server: Server object or UUID string
- tags: list of Tag objects or strings | upcloud_api/cloud_manager/tag_mixin.py | def remove_tags(self, server, tags):
"""
Remove tags from a server.
- server: Server object or UUID string
- tags: list of Tag objects or strings
"""
uuid = str(server)
tags = [str(tag) for tag in tags]
url = '/server/{0}/untag/{1}'.format(uuid, ','.join... | def remove_tags(self, server, tags):
"""
Remove tags from a server.
- server: Server object or UUID string
- tags: list of Tag objects or strings
"""
uuid = str(server)
tags = [str(tag) for tag in tags]
url = '/server/{0}/untag/{1}'.format(uuid, ','.join... | [
"Remove",
"tags",
"from",
"a",
"server",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L70-L81 | [
"def",
"remove_tags",
"(",
"self",
",",
"server",
",",
"tags",
")",
":",
"uuid",
"=",
"str",
"(",
"server",
")",
"tags",
"=",
"[",
"str",
"(",
"tag",
")",
"for",
"tag",
"in",
"tags",
"]",
"url",
"=",
"'/server/{0}/untag/{1}'",
".",
"format",
"(",
"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | assignIfExists | Helper for assigning object attributes from API responses. | upcloud_api/utils.py | def assignIfExists(opts, default=None, **kwargs):
"""
Helper for assigning object attributes from API responses.
"""
for opt in opts:
if(opt in kwargs):
return kwargs[opt]
return default | def assignIfExists(opts, default=None, **kwargs):
"""
Helper for assigning object attributes from API responses.
"""
for opt in opts:
if(opt in kwargs):
return kwargs[opt]
return default | [
"Helper",
"for",
"assigning",
"object",
"attributes",
"from",
"API",
"responses",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/utils.py#L7-L14 | [
"def",
"assignIfExists",
"(",
"opts",
",",
"default",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"opt",
"in",
"opts",
":",
"if",
"(",
"opt",
"in",
"kwargs",
")",
":",
"return",
"kwargs",
"[",
"opt",
"]",
"return",
"default"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | try_it_n_times | Try a given operation (API call) n times.
Raises if the API call fails with an error_code that is not expected.
Raises if the API call has not succeeded within n attempts.
Waits 3 seconds betwee each attempt. | upcloud_api/utils.py | def try_it_n_times(operation, expected_error_codes, custom_error='operation failed', n=10):
"""
Try a given operation (API call) n times.
Raises if the API call fails with an error_code that is not expected.
Raises if the API call has not succeeded within n attempts.
Waits 3 seconds betwee each att... | def try_it_n_times(operation, expected_error_codes, custom_error='operation failed', n=10):
"""
Try a given operation (API call) n times.
Raises if the API call fails with an error_code that is not expected.
Raises if the API call has not succeeded within n attempts.
Waits 3 seconds betwee each att... | [
"Try",
"a",
"given",
"operation",
"(",
"API",
"call",
")",
"n",
"times",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/utils.py#L17-L34 | [
"def",
"try_it_n_times",
"(",
"operation",
",",
"expected_error_codes",
",",
"custom_error",
"=",
"'operation failed'",
",",
"n",
"=",
"10",
")",
":",
"for",
"i",
"in",
"itertools",
".",
"count",
"(",
")",
":",
"try",
":",
"operation",
"(",
")",
"break",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | hkdf_extract | Extract a pseudorandom key suitable for use with hkdf_expand
from the input_key_material and a salt using HMAC with the
provided hash (default SHA-512).
salt should be a random, application-specific byte string. If
salt is None or the empty string, an all-zeros string of the same
length as the hash's block size w... | hkdf.py | def hkdf_extract(salt, input_key_material, hash=hashlib.sha512):
'''
Extract a pseudorandom key suitable for use with hkdf_expand
from the input_key_material and a salt using HMAC with the
provided hash (default SHA-512).
salt should be a random, application-specific byte string. If
salt is None or the empty str... | def hkdf_extract(salt, input_key_material, hash=hashlib.sha512):
'''
Extract a pseudorandom key suitable for use with hkdf_expand
from the input_key_material and a salt using HMAC with the
provided hash (default SHA-512).
salt should be a random, application-specific byte string. If
salt is None or the empty str... | [
"Extract",
"a",
"pseudorandom",
"key",
"suitable",
"for",
"use",
"with",
"hkdf_expand",
"from",
"the",
"input_key_material",
"and",
"a",
"salt",
"using",
"HMAC",
"with",
"the",
"provided",
"hash",
"(",
"default",
"SHA",
"-",
"512",
")",
"."
] | casebeer/python-hkdf | python | https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L10-L25 | [
"def",
"hkdf_extract",
"(",
"salt",
",",
"input_key_material",
",",
"hash",
"=",
"hashlib",
".",
"sha512",
")",
":",
"hash_len",
"=",
"hash",
"(",
")",
".",
"digest_size",
"if",
"salt",
"==",
"None",
"or",
"len",
"(",
"salt",
")",
"==",
"0",
":",
"sa... | cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307 |
train | hkdf_expand | Expand `pseudo_random_key` and `info` into a key of length `bytes` using
HKDF's expand function based on HMAC with the provided hash (default
SHA-512). See the HKDF draft RFC and paper for usage notes. | hkdf.py | def hkdf_expand(pseudo_random_key, info=b"", length=32, hash=hashlib.sha512):
'''
Expand `pseudo_random_key` and `info` into a key of length `bytes` using
HKDF's expand function based on HMAC with the provided hash (default
SHA-512). See the HKDF draft RFC and paper for usage notes.
'''
hash_len = hash().digest_s... | def hkdf_expand(pseudo_random_key, info=b"", length=32, hash=hashlib.sha512):
'''
Expand `pseudo_random_key` and `info` into a key of length `bytes` using
HKDF's expand function based on HMAC with the provided hash (default
SHA-512). See the HKDF draft RFC and paper for usage notes.
'''
hash_len = hash().digest_s... | [
"Expand",
"pseudo_random_key",
"and",
"info",
"into",
"a",
"key",
"of",
"length",
"bytes",
"using",
"HKDF",
"s",
"expand",
"function",
"based",
"on",
"HMAC",
"with",
"the",
"provided",
"hash",
"(",
"default",
"SHA",
"-",
"512",
")",
".",
"See",
"the",
"H... | casebeer/python-hkdf | python | https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L27-L45 | [
"def",
"hkdf_expand",
"(",
"pseudo_random_key",
",",
"info",
"=",
"b\"\"",
",",
"length",
"=",
"32",
",",
"hash",
"=",
"hashlib",
".",
"sha512",
")",
":",
"hash_len",
"=",
"hash",
"(",
")",
".",
"digest_size",
"length",
"=",
"int",
"(",
"length",
")",
... | cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307 |
train | Hkdf.expand | Generate output key material based on an `info` value
Arguments:
- info - context to generate the OKM
- length - length in bytes of the key to generate
See the HKDF draft RFC for guidance. | hkdf.py | def expand(self, info=b"", length=32):
'''
Generate output key material based on an `info` value
Arguments:
- info - context to generate the OKM
- length - length in bytes of the key to generate
See the HKDF draft RFC for guidance.
'''
return hkdf_expand(self._prk, info, length, self._hash) | def expand(self, info=b"", length=32):
'''
Generate output key material based on an `info` value
Arguments:
- info - context to generate the OKM
- length - length in bytes of the key to generate
See the HKDF draft RFC for guidance.
'''
return hkdf_expand(self._prk, info, length, self._hash) | [
"Generate",
"output",
"key",
"material",
"based",
"on",
"an",
"info",
"value"
] | casebeer/python-hkdf | python | https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L61-L71 | [
"def",
"expand",
"(",
"self",
",",
"info",
"=",
"b\"\"",
",",
"length",
"=",
"32",
")",
":",
"return",
"hkdf_expand",
"(",
"self",
".",
"_prk",
",",
"info",
",",
"length",
",",
"self",
".",
"_hash",
")"
] | cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307 |
train | login_user_block | Helper function for creating Server.login_user blocks.
(see: https://www.upcloud.com/api/8-servers/#create-server) | upcloud_api/server.py | def login_user_block(username, ssh_keys, create_password=True):
"""
Helper function for creating Server.login_user blocks.
(see: https://www.upcloud.com/api/8-servers/#create-server)
"""
block = {
'create_password': 'yes' if create_password is True else 'no',
'ssh_keys': {
... | def login_user_block(username, ssh_keys, create_password=True):
"""
Helper function for creating Server.login_user blocks.
(see: https://www.upcloud.com/api/8-servers/#create-server)
"""
block = {
'create_password': 'yes' if create_password is True else 'no',
'ssh_keys': {
... | [
"Helper",
"function",
"for",
"creating",
"Server",
".",
"login_user",
"blocks",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L10-L26 | [
"def",
"login_user_block",
"(",
"username",
",",
"ssh_keys",
",",
"create_password",
"=",
"True",
")",
":",
"block",
"=",
"{",
"'create_password'",
":",
"'yes'",
"if",
"create_password",
"is",
"True",
"else",
"'no'",
",",
"'ssh_keys'",
":",
"{",
"'ssh_key'",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server._reset | Reset the server object with new values given as params.
- server: a dict representing the server. e.g the API response.
- kwargs: any meta fields such as cloud_manager and populated.
Note: storage_devices and ip_addresses may be given in server as dicts or
in kwargs as lists containin... | upcloud_api/server.py | def _reset(self, server, **kwargs):
"""
Reset the server object with new values given as params.
- server: a dict representing the server. e.g the API response.
- kwargs: any meta fields such as cloud_manager and populated.
Note: storage_devices and ip_addresses may be given in... | def _reset(self, server, **kwargs):
"""
Reset the server object with new values given as params.
- server: a dict representing the server. e.g the API response.
- kwargs: any meta fields such as cloud_manager and populated.
Note: storage_devices and ip_addresses may be given in... | [
"Reset",
"the",
"server",
"object",
"with",
"new",
"values",
"given",
"as",
"params",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L74-L92 | [
"def",
"_reset",
"(",
"self",
",",
"server",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"server",
":",
"# handle storage, ip_address dicts and tags if they exist",
"Server",
".",
"_handle_server_subobjs",
"(",
"server",
",",
"kwargs",
".",
"get",
"(",
"'cloud_manage... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.populate | Sync changes from the API to the local object.
Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint) | upcloud_api/server.py | def populate(self):
"""
Sync changes from the API to the local object.
Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint)
"""
server, IPAddresses, storages = self.cloud_manager.get_server_data(self.uuid)
self._reset(
server,
... | def populate(self):
"""
Sync changes from the API to the local object.
Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint)
"""
server, IPAddresses, storages = self.cloud_manager.get_server_data(self.uuid)
self._reset(
server,
... | [
"Sync",
"changes",
"from",
"the",
"API",
"to",
"the",
"local",
"object",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L94-L107 | [
"def",
"populate",
"(",
"self",
")",
":",
"server",
",",
"IPAddresses",
",",
"storages",
"=",
"self",
".",
"cloud_manager",
".",
"get_server_data",
"(",
"self",
".",
"uuid",
")",
"self",
".",
"_reset",
"(",
"server",
",",
"ip_addresses",
"=",
"IPAddresses"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.save | Sync local changes in server's attributes to the API.
Note: DOES NOT sync IPAddresses and storage_devices,
use add_ip, add_storage, remove_ip, remove_storage instead. | upcloud_api/server.py | def save(self):
"""
Sync local changes in server's attributes to the API.
Note: DOES NOT sync IPAddresses and storage_devices,
use add_ip, add_storage, remove_ip, remove_storage instead.
"""
# dict comprehension that also works with 2.6
# http://stackoverflow.com... | def save(self):
"""
Sync local changes in server's attributes to the API.
Note: DOES NOT sync IPAddresses and storage_devices,
use add_ip, add_storage, remove_ip, remove_storage instead.
"""
# dict comprehension that also works with 2.6
# http://stackoverflow.com... | [
"Sync",
"local",
"changes",
"in",
"server",
"s",
"attributes",
"to",
"the",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L116-L132 | [
"def",
"save",
"(",
"self",
")",
":",
"# dict comprehension that also works with 2.6",
"# http://stackoverflow.com/questions/21069668/alternative-to-dict-comprehension-prior-to-python-2-7",
"kwargs",
"=",
"dict",
"(",
"(",
"field",
",",
"getattr",
"(",
"self",
",",
"field",
"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.shutdown | Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s.
After the a timeout a hard shutdown is performed if the server has not stopped.
Note: API responds immediately (unlike in start), with state: started.
This client will, however, set state as 'maintenance' to sig... | upcloud_api/server.py | def shutdown(self, hard=False, timeout=30):
"""
Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s.
After the a timeout a hard shutdown is performed if the server has not stopped.
Note: API responds immediately (unlike in start), with state: started.
... | def shutdown(self, hard=False, timeout=30):
"""
Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s.
After the a timeout a hard shutdown is performed if the server has not stopped.
Note: API responds immediately (unlike in start), with state: started.
... | [
"Shutdown",
"/",
"stop",
"the",
"server",
".",
"By",
"default",
"issue",
"a",
"soft",
"shutdown",
"with",
"a",
"timeout",
"of",
"30s",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L137-L155 | [
"def",
"shutdown",
"(",
"self",
",",
"hard",
"=",
"False",
",",
"timeout",
"=",
"30",
")",
":",
"body",
"=",
"dict",
"(",
")",
"body",
"[",
"'stop_server'",
"]",
"=",
"{",
"'stop_type'",
":",
"'hard'",
"if",
"hard",
"else",
"'soft'",
",",
"'timeout'"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.start | Start the server. Note: slow and blocking request.
The API waits for confirmation from UpCloud's IaaS backend before responding. | upcloud_api/server.py | def start(self, timeout=120):
"""
Start the server. Note: slow and blocking request.
The API waits for confirmation from UpCloud's IaaS backend before responding.
"""
path = '/server/{0}/start'.format(self.uuid)
self.cloud_manager.post_request(path, timeout=timeout)
... | def start(self, timeout=120):
"""
Start the server. Note: slow and blocking request.
The API waits for confirmation from UpCloud's IaaS backend before responding.
"""
path = '/server/{0}/start'.format(self.uuid)
self.cloud_manager.post_request(path, timeout=timeout)
... | [
"Start",
"the",
"server",
".",
"Note",
":",
"slow",
"and",
"blocking",
"request",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L163-L171 | [
"def",
"start",
"(",
"self",
",",
"timeout",
"=",
"120",
")",
":",
"path",
"=",
"'/server/{0}/start'",
".",
"format",
"(",
"self",
".",
"uuid",
")",
"self",
".",
"cloud_manager",
".",
"post_request",
"(",
"path",
",",
"timeout",
"=",
"timeout",
")",
"o... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.restart | Restart the server. By default, issue a soft restart with a timeout of 30s
and a hard restart after the timeout.
After the a timeout a hard restart is performed if the server has not stopped.
Note: API responds immediately (unlike in start), with state: started.
This client will, howev... | upcloud_api/server.py | def restart(self, hard=False, timeout=30, force=True):
"""
Restart the server. By default, issue a soft restart with a timeout of 30s
and a hard restart after the timeout.
After the a timeout a hard restart is performed if the server has not stopped.
Note: API responds immediat... | def restart(self, hard=False, timeout=30, force=True):
"""
Restart the server. By default, issue a soft restart with a timeout of 30s
and a hard restart after the timeout.
After the a timeout a hard restart is performed if the server has not stopped.
Note: API responds immediat... | [
"Restart",
"the",
"server",
".",
"By",
"default",
"issue",
"a",
"soft",
"restart",
"with",
"a",
"timeout",
"of",
"30s",
"and",
"a",
"hard",
"restart",
"after",
"the",
"timeout",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L173-L193 | [
"def",
"restart",
"(",
"self",
",",
"hard",
"=",
"False",
",",
"timeout",
"=",
"30",
",",
"force",
"=",
"True",
")",
":",
"body",
"=",
"dict",
"(",
")",
"body",
"[",
"'restart_server'",
"]",
"=",
"{",
"'stop_type'",
":",
"'hard'",
"if",
"hard",
"el... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.add_ip | Allocate a new (random) IP-address to the Server. | upcloud_api/server.py | def add_ip(self, family='IPv4'):
"""
Allocate a new (random) IP-address to the Server.
"""
IP = self.cloud_manager.attach_ip(self.uuid, family)
self.ip_addresses.append(IP)
return IP | def add_ip(self, family='IPv4'):
"""
Allocate a new (random) IP-address to the Server.
"""
IP = self.cloud_manager.attach_ip(self.uuid, family)
self.ip_addresses.append(IP)
return IP | [
"Allocate",
"a",
"new",
"(",
"random",
")",
"IP",
"-",
"address",
"to",
"the",
"Server",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L195-L201 | [
"def",
"add_ip",
"(",
"self",
",",
"family",
"=",
"'IPv4'",
")",
":",
"IP",
"=",
"self",
".",
"cloud_manager",
".",
"attach_ip",
"(",
"self",
".",
"uuid",
",",
"family",
")",
"self",
".",
"ip_addresses",
".",
"append",
"(",
"IP",
")",
"return",
"IP"
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.remove_ip | Release the specified IP-address from the server. | upcloud_api/server.py | def remove_ip(self, IPAddress):
"""
Release the specified IP-address from the server.
"""
self.cloud_manager.release_ip(IPAddress.address)
self.ip_addresses.remove(IPAddress) | def remove_ip(self, IPAddress):
"""
Release the specified IP-address from the server.
"""
self.cloud_manager.release_ip(IPAddress.address)
self.ip_addresses.remove(IPAddress) | [
"Release",
"the",
"specified",
"IP",
"-",
"address",
"from",
"the",
"server",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L203-L208 | [
"def",
"remove_ip",
"(",
"self",
",",
"IPAddress",
")",
":",
"self",
".",
"cloud_manager",
".",
"release_ip",
"(",
"IPAddress",
".",
"address",
")",
"self",
".",
"ip_addresses",
".",
"remove",
"(",
"IPAddress",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.add_storage | Attach the given storage to the Server.
Default address is next available. | upcloud_api/server.py | def add_storage(self, storage=None, type='disk', address=None):
"""
Attach the given storage to the Server.
Default address is next available.
"""
self.cloud_manager.attach_storage(server=self.uuid,
storage=storage.uuid,
... | def add_storage(self, storage=None, type='disk', address=None):
"""
Attach the given storage to the Server.
Default address is next available.
"""
self.cloud_manager.attach_storage(server=self.uuid,
storage=storage.uuid,
... | [
"Attach",
"the",
"given",
"storage",
"to",
"the",
"Server",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L210-L222 | [
"def",
"add_storage",
"(",
"self",
",",
"storage",
"=",
"None",
",",
"type",
"=",
"'disk'",
",",
"address",
"=",
"None",
")",
":",
"self",
".",
"cloud_manager",
".",
"attach_storage",
"(",
"server",
"=",
"self",
".",
"uuid",
",",
"storage",
"=",
"stora... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.remove_storage | Remove Storage from a Server.
The Storage must be a reference to an object in
Server.storage_devices or the method will throw and Exception.
A Storage from get_storage(uuid) will not work as it is missing the 'address' property. | upcloud_api/server.py | def remove_storage(self, storage):
"""
Remove Storage from a Server.
The Storage must be a reference to an object in
Server.storage_devices or the method will throw and Exception.
A Storage from get_storage(uuid) will not work as it is missing the 'address' property.
""... | def remove_storage(self, storage):
"""
Remove Storage from a Server.
The Storage must be a reference to an object in
Server.storage_devices or the method will throw and Exception.
A Storage from get_storage(uuid) will not work as it is missing the 'address' property.
""... | [
"Remove",
"Storage",
"from",
"a",
"Server",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L224-L242 | [
"def",
"remove_storage",
"(",
"self",
",",
"storage",
")",
":",
"if",
"not",
"hasattr",
"(",
"storage",
",",
"'address'",
")",
":",
"raise",
"Exception",
"(",
"(",
"'Storage does not have an address. '",
"'Access the Storage via Server.storage_devices '",
"'so they incl... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.add_tags | Add tags to a server. Accepts tags as strings or Tag objects. | upcloud_api/server.py | def add_tags(self, tags):
"""
Add tags to a server. Accepts tags as strings or Tag objects.
"""
if self.cloud_manager.assign_tags(self.uuid, tags):
tags = self.tags + [str(tag) for tag in tags]
object.__setattr__(self, 'tags', tags) | def add_tags(self, tags):
"""
Add tags to a server. Accepts tags as strings or Tag objects.
"""
if self.cloud_manager.assign_tags(self.uuid, tags):
tags = self.tags + [str(tag) for tag in tags]
object.__setattr__(self, 'tags', tags) | [
"Add",
"tags",
"to",
"a",
"server",
".",
"Accepts",
"tags",
"as",
"strings",
"or",
"Tag",
"objects",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L264-L270 | [
"def",
"add_tags",
"(",
"self",
",",
"tags",
")",
":",
"if",
"self",
".",
"cloud_manager",
".",
"assign_tags",
"(",
"self",
".",
"uuid",
",",
"tags",
")",
":",
"tags",
"=",
"self",
".",
"tags",
"+",
"[",
"str",
"(",
"tag",
")",
"for",
"tag",
"in"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.remove_tags | Add tags to a server. Accepts tags as strings or Tag objects. | upcloud_api/server.py | def remove_tags(self, tags):
"""
Add tags to a server. Accepts tags as strings or Tag objects.
"""
if self.cloud_manager.remove_tags(self, tags):
new_tags = [tag for tag in self.tags if tag not in tags]
object.__setattr__(self, 'tags', new_tags) | def remove_tags(self, tags):
"""
Add tags to a server. Accepts tags as strings or Tag objects.
"""
if self.cloud_manager.remove_tags(self, tags):
new_tags = [tag for tag in self.tags if tag not in tags]
object.__setattr__(self, 'tags', new_tags) | [
"Add",
"tags",
"to",
"a",
"server",
".",
"Accepts",
"tags",
"as",
"strings",
"or",
"Tag",
"objects",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L272-L278 | [
"def",
"remove_tags",
"(",
"self",
",",
"tags",
")",
":",
"if",
"self",
".",
"cloud_manager",
".",
"remove_tags",
"(",
"self",
",",
"tags",
")",
":",
"new_tags",
"=",
"[",
"tag",
"for",
"tag",
"in",
"self",
".",
"tags",
"if",
"tag",
"not",
"in",
"t... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.configure_firewall | Helper function for automatically adding several FirewallRules in series. | upcloud_api/server.py | def configure_firewall(self, FirewallRules):
"""
Helper function for automatically adding several FirewallRules in series.
"""
firewall_rule_bodies = [
FirewallRule.to_dict()
for FirewallRule in FirewallRules
]
return self.cloud_manager.configure_f... | def configure_firewall(self, FirewallRules):
"""
Helper function for automatically adding several FirewallRules in series.
"""
firewall_rule_bodies = [
FirewallRule.to_dict()
for FirewallRule in FirewallRules
]
return self.cloud_manager.configure_f... | [
"Helper",
"function",
"for",
"automatically",
"adding",
"several",
"FirewallRules",
"in",
"series",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L285-L293 | [
"def",
"configure_firewall",
"(",
"self",
",",
"FirewallRules",
")",
":",
"firewall_rule_bodies",
"=",
"[",
"FirewallRule",
".",
"to_dict",
"(",
")",
"for",
"FirewallRule",
"in",
"FirewallRules",
"]",
"return",
"self",
".",
"cloud_manager",
".",
"configure_firewal... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.prepare_post_body | Prepare a JSON serializable dict from a Server instance with nested.
Storage instances. | upcloud_api/server.py | def prepare_post_body(self):
"""
Prepare a JSON serializable dict from a Server instance with nested.
Storage instances.
"""
body = dict()
# mandatory
body['server'] = {
'hostname': self.hostname,
'zone': self.zone,
'title': se... | def prepare_post_body(self):
"""
Prepare a JSON serializable dict from a Server instance with nested.
Storage instances.
"""
body = dict()
# mandatory
body['server'] = {
'hostname': self.hostname,
'zone': self.zone,
'title': se... | [
"Prepare",
"a",
"JSON",
"serializable",
"dict",
"from",
"a",
"Server",
"instance",
"with",
"nested",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L295-L368 | [
"def",
"prepare_post_body",
"(",
"self",
")",
":",
"body",
"=",
"dict",
"(",
")",
"# mandatory",
"body",
"[",
"'server'",
"]",
"=",
"{",
"'hostname'",
":",
"self",
".",
"hostname",
",",
"'zone'",
":",
"self",
".",
"zone",
",",
"'title'",
":",
"self",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.to_dict | Prepare a JSON serializable dict for read-only purposes.
Includes storages and IP-addresses.
Use prepare_post_body for POST and .save() for PUT. | upcloud_api/server.py | def to_dict(self):
"""
Prepare a JSON serializable dict for read-only purposes.
Includes storages and IP-addresses.
Use prepare_post_body for POST and .save() for PUT.
"""
fields = dict(vars(self).items())
if self.populated:
fields['ip_addresses'] = ... | def to_dict(self):
"""
Prepare a JSON serializable dict for read-only purposes.
Includes storages and IP-addresses.
Use prepare_post_body for POST and .save() for PUT.
"""
fields = dict(vars(self).items())
if self.populated:
fields['ip_addresses'] = ... | [
"Prepare",
"a",
"JSON",
"serializable",
"dict",
"for",
"read",
"-",
"only",
"purposes",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L370-L400 | [
"def",
"to_dict",
"(",
"self",
")",
":",
"fields",
"=",
"dict",
"(",
"vars",
"(",
"self",
")",
".",
"items",
"(",
")",
")",
"if",
"self",
".",
"populated",
":",
"fields",
"[",
"'ip_addresses'",
"]",
"=",
"[",
"]",
"fields",
"[",
"'storage_devices'",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.get_ip | Return the server's IP address.
Params:
- addr_family: IPv4, IPv6 or None. None prefers IPv4 but will
return IPv6 if IPv4 addr was not available.
- access: 'public' or 'private' | upcloud_api/server.py | def get_ip(self, access='public', addr_family=None, strict=None):
"""
Return the server's IP address.
Params:
- addr_family: IPv4, IPv6 or None. None prefers IPv4 but will
return IPv6 if IPv4 addr was not available.
- access: 'public' or 'private'
... | def get_ip(self, access='public', addr_family=None, strict=None):
"""
Return the server's IP address.
Params:
- addr_family: IPv4, IPv6 or None. None prefers IPv4 but will
return IPv6 if IPv4 addr was not available.
- access: 'public' or 'private'
... | [
"Return",
"the",
"server",
"s",
"IP",
"address",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L402-L433 | [
"def",
"get_ip",
"(",
"self",
",",
"access",
"=",
"'public'",
",",
"addr_family",
"=",
"None",
",",
"strict",
"=",
"None",
")",
":",
"if",
"addr_family",
"not",
"in",
"[",
"'IPv4'",
",",
"'IPv6'",
",",
"None",
"]",
":",
"raise",
"Exception",
"(",
"\"... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.get_public_ip | Alias for get_ip('public') | upcloud_api/server.py | def get_public_ip(self, addr_family=None, *args, **kwargs):
"""Alias for get_ip('public')"""
return self.get_ip('public', addr_family, *args, **kwargs) | def get_public_ip(self, addr_family=None, *args, **kwargs):
"""Alias for get_ip('public')"""
return self.get_ip('public', addr_family, *args, **kwargs) | [
"Alias",
"for",
"get_ip",
"(",
"public",
")"
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L435-L437 | [
"def",
"get_public_ip",
"(",
"self",
",",
"addr_family",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"get_ip",
"(",
"'public'",
",",
"addr_family",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.get_private_ip | Alias for get_ip('private') | upcloud_api/server.py | def get_private_ip(self, addr_family=None, *args, **kwargs):
"""Alias for get_ip('private')"""
return self.get_ip('private', addr_family, *args, **kwargs) | def get_private_ip(self, addr_family=None, *args, **kwargs):
"""Alias for get_ip('private')"""
return self.get_ip('private', addr_family, *args, **kwargs) | [
"Alias",
"for",
"get_ip",
"(",
"private",
")"
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L439-L441 | [
"def",
"get_private_ip",
"(",
"self",
",",
"addr_family",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"get_ip",
"(",
"'private'",
",",
"addr_family",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server._wait_for_state_change | Blocking wait until target_state reached. update_interval is in seconds.
Warning: state change must begin before calling this method. | upcloud_api/server.py | def _wait_for_state_change(self, target_states, update_interval=10):
"""
Blocking wait until target_state reached. update_interval is in seconds.
Warning: state change must begin before calling this method.
"""
while self.state not in target_states:
if self.state == ... | def _wait_for_state_change(self, target_states, update_interval=10):
"""
Blocking wait until target_state reached. update_interval is in seconds.
Warning: state change must begin before calling this method.
"""
while self.state not in target_states:
if self.state == ... | [
"Blocking",
"wait",
"until",
"target_state",
"reached",
".",
"update_interval",
"is",
"in",
"seconds",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L443-L455 | [
"def",
"_wait_for_state_change",
"(",
"self",
",",
"target_states",
",",
"update_interval",
"=",
"10",
")",
":",
"while",
"self",
".",
"state",
"not",
"in",
"target_states",
":",
"if",
"self",
".",
"state",
"==",
"'error'",
":",
"raise",
"Exception",
"(",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.ensure_started | Start a server and waits (blocking wait) until it is fully started. | upcloud_api/server.py | def ensure_started(self):
"""
Start a server and waits (blocking wait) until it is fully started.
"""
# server is either starting or stopping (or error)
if self.state in ['maintenance', 'error']:
self._wait_for_state_change(['stopped', 'started'])
if self.sta... | def ensure_started(self):
"""
Start a server and waits (blocking wait) until it is fully started.
"""
# server is either starting or stopping (or error)
if self.state in ['maintenance', 'error']:
self._wait_for_state_change(['stopped', 'started'])
if self.sta... | [
"Start",
"a",
"server",
"and",
"waits",
"(",
"blocking",
"wait",
")",
"until",
"it",
"is",
"fully",
"started",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L457-L473 | [
"def",
"ensure_started",
"(",
"self",
")",
":",
"# server is either starting or stopping (or error)",
"if",
"self",
".",
"state",
"in",
"[",
"'maintenance'",
",",
"'error'",
"]",
":",
"self",
".",
"_wait_for_state_change",
"(",
"[",
"'stopped'",
",",
"'started'",
... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | Server.stop_and_destroy | Destroy a server and its storages. Stops the server before destroying.
Syncs the server state from the API, use sync=False to disable. | upcloud_api/server.py | def stop_and_destroy(self, sync=True):
"""
Destroy a server and its storages. Stops the server before destroying.
Syncs the server state from the API, use sync=False to disable.
"""
def _self_destruct():
"""destroy the server and all storages attached to it."""
... | def stop_and_destroy(self, sync=True):
"""
Destroy a server and its storages. Stops the server before destroying.
Syncs the server state from the API, use sync=False to disable.
"""
def _self_destruct():
"""destroy the server and all storages attached to it."""
... | [
"Destroy",
"a",
"server",
"and",
"its",
"storages",
".",
"Stops",
"the",
"server",
"before",
"destroying",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L475-L517 | [
"def",
"stop_and_destroy",
"(",
"self",
",",
"sync",
"=",
"True",
")",
":",
"def",
"_self_destruct",
"(",
")",
":",
"\"\"\"destroy the server and all storages attached to it.\"\"\"",
"# try_it_n_times util is used as a convenience because",
"# Servers and Storages can fluctuate bet... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | PersistentState.revert | Revert the state to the version stored on disc. | ofs/local/storedjson.py | def revert(self):
"""Revert the state to the version stored on disc."""
if self.filepath:
if path.isfile(self.filepath):
serialised_file = open(self.filepath, "r")
try:
self.state = json.load(serialised_file)
except ValueErr... | def revert(self):
"""Revert the state to the version stored on disc."""
if self.filepath:
if path.isfile(self.filepath):
serialised_file = open(self.filepath, "r")
try:
self.state = json.load(serialised_file)
except ValueErr... | [
"Revert",
"the",
"state",
"to",
"the",
"version",
"stored",
"on",
"disc",
"."
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/storedjson.py#L33-L49 | [
"def",
"revert",
"(",
"self",
")",
":",
"if",
"self",
".",
"filepath",
":",
"if",
"path",
".",
"isfile",
"(",
"self",
".",
"filepath",
")",
":",
"serialised_file",
"=",
"open",
"(",
"self",
".",
"filepath",
",",
"\"r\"",
")",
"try",
":",
"self",
".... | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
train | PersistentState.sync | Synchronise and update the stored state to the in-memory state. | ofs/local/storedjson.py | def sync(self):
"""Synchronise and update the stored state to the in-memory state."""
if self.filepath:
serialised_file = open(self.filepath, "w")
json.dump(self.state, serialised_file)
serialised_file.close()
else:
print("Filepath to the persisten... | def sync(self):
"""Synchronise and update the stored state to the in-memory state."""
if self.filepath:
serialised_file = open(self.filepath, "w")
json.dump(self.state, serialised_file)
serialised_file.close()
else:
print("Filepath to the persisten... | [
"Synchronise",
"and",
"update",
"the",
"stored",
"state",
"to",
"the",
"in",
"-",
"memory",
"state",
"."
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/storedjson.py#L51-L58 | [
"def",
"sync",
"(",
"self",
")",
":",
"if",
"self",
".",
"filepath",
":",
"serialised_file",
"=",
"open",
"(",
"self",
".",
"filepath",
",",
"\"w\"",
")",
"json",
".",
"dump",
"(",
"self",
".",
"state",
",",
"serialised_file",
")",
"serialised_file",
"... | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
train | UpCloudResource._reset | Reset after repopulating from API (or when initializing). | upcloud_api/upcloud_resource.py | def _reset(self, **kwargs):
"""
Reset after repopulating from API (or when initializing).
"""
# set object attributes from params
for key in kwargs:
setattr(self, key, kwargs[key])
# set defaults (if need be) where the default is not None
for attr in ... | def _reset(self, **kwargs):
"""
Reset after repopulating from API (or when initializing).
"""
# set object attributes from params
for key in kwargs:
setattr(self, key, kwargs[key])
# set defaults (if need be) where the default is not None
for attr in ... | [
"Reset",
"after",
"repopulating",
"from",
"API",
"(",
"or",
"when",
"initializing",
")",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/upcloud_resource.py#L27-L38 | [
"def",
"_reset",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# set object attributes from params",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"# set defaults (if need be) where the default is ... | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | UpCloudResource.to_dict | Return a dict that can be serialised to JSON and sent to UpCloud's API. | upcloud_api/upcloud_resource.py | def to_dict(self):
"""
Return a dict that can be serialised to JSON and sent to UpCloud's API.
"""
return dict(
(attr, getattr(self, attr))
for attr in self.ATTRIBUTES
if hasattr(self, attr)
) | def to_dict(self):
"""
Return a dict that can be serialised to JSON and sent to UpCloud's API.
"""
return dict(
(attr, getattr(self, attr))
for attr in self.ATTRIBUTES
if hasattr(self, attr)
) | [
"Return",
"a",
"dict",
"that",
"can",
"be",
"serialised",
"to",
"JSON",
"and",
"sent",
"to",
"UpCloud",
"s",
"API",
"."
] | UpCloudLtd/upcloud-python-api | python | https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/upcloud_resource.py#L47-L55 | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"dict",
"(",
"(",
"attr",
",",
"getattr",
"(",
"self",
",",
"attr",
")",
")",
"for",
"attr",
"in",
"self",
".",
"ATTRIBUTES",
"if",
"hasattr",
"(",
"self",
",",
"attr",
")",
")"
] | 954b0ad7c4b932b2be31a95d88975f6b0eeac8ed |
train | BotoOFS._require_bucket | Also try to create the bucket. | ofs/remote/botostore.py | def _require_bucket(self, bucket_name):
""" Also try to create the bucket. """
if not self.exists(bucket_name) and not self.claim_bucket(bucket_name):
raise OFSException("Invalid bucket: %s" % bucket_name)
return self._get_bucket(bucket_name) | def _require_bucket(self, bucket_name):
""" Also try to create the bucket. """
if not self.exists(bucket_name) and not self.claim_bucket(bucket_name):
raise OFSException("Invalid bucket: %s" % bucket_name)
return self._get_bucket(bucket_name) | [
"Also",
"try",
"to",
"create",
"the",
"bucket",
"."
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L42-L46 | [
"def",
"_require_bucket",
"(",
"self",
",",
"bucket_name",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
"bucket_name",
")",
"and",
"not",
"self",
".",
"claim_bucket",
"(",
"bucket_name",
")",
":",
"raise",
"OFSException",
"(",
"\"Invalid bucket: %s\"",
... | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
train | BotoOFS.del_stream | Will fail if the bucket or label don't exist | ofs/remote/botostore.py | def del_stream(self, bucket, label):
""" Will fail if the bucket or label don't exist """
bucket = self._require_bucket(bucket)
key = self._require_key(bucket, label)
key.delete() | def del_stream(self, bucket, label):
""" Will fail if the bucket or label don't exist """
bucket = self._require_bucket(bucket)
key = self._require_key(bucket, label)
key.delete() | [
"Will",
"fail",
"if",
"the",
"bucket",
"or",
"label",
"don",
"t",
"exist"
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L119-L123 | [
"def",
"del_stream",
"(",
"self",
",",
"bucket",
",",
"label",
")",
":",
"bucket",
"=",
"self",
".",
"_require_bucket",
"(",
"bucket",
")",
"key",
"=",
"self",
".",
"_require_key",
"(",
"bucket",
",",
"label",
")",
"key",
".",
"delete",
"(",
")"
] | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
train | BotoOFS.authenticate_request | Authenticate a HTTP request by filling in Authorization field header.
:param method: HTTP method (e.g. GET, PUT, POST)
:param bucket: name of the bucket.
:param key: name of key within bucket.
:param headers: dictionary of additional HTTP headers.
:return: boto.connection.HTTPR... | ofs/remote/botostore.py | def authenticate_request(self, method, bucket='', key='', headers=None):
'''Authenticate a HTTP request by filling in Authorization field header.
:param method: HTTP method (e.g. GET, PUT, POST)
:param bucket: name of the bucket.
:param key: name of key within bucket.
:param hea... | def authenticate_request(self, method, bucket='', key='', headers=None):
'''Authenticate a HTTP request by filling in Authorization field header.
:param method: HTTP method (e.g. GET, PUT, POST)
:param bucket: name of the bucket.
:param key: name of key within bucket.
:param hea... | [
"Authenticate",
"a",
"HTTP",
"request",
"by",
"filling",
"in",
"Authorization",
"field",
"header",
"."
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L172-L197 | [
"def",
"authenticate_request",
"(",
"self",
",",
"method",
",",
"bucket",
"=",
"''",
",",
"key",
"=",
"''",
",",
"headers",
"=",
"None",
")",
":",
"# following is extracted from S3Connection.make_request and the method",
"# it calls: AWSAuthConnection.make_request",
"path... | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
train | get_resources_to_check | Return a list of resource IDs to check for broken links.
Calls the client site's API to get a list of resource IDs.
:raises CouldNotGetResourceIDsError: if getting the resource IDs fails
for any reason | deadoralive/deadoralive.py | def get_resources_to_check(client_site_url, apikey):
"""Return a list of resource IDs to check for broken links.
Calls the client site's API to get a list of resource IDs.
:raises CouldNotGetResourceIDsError: if getting the resource IDs fails
for any reason
"""
url = client_site_url + u"d... | def get_resources_to_check(client_site_url, apikey):
"""Return a list of resource IDs to check for broken links.
Calls the client site's API to get a list of resource IDs.
:raises CouldNotGetResourceIDsError: if getting the resource IDs fails
for any reason
"""
url = client_site_url + u"d... | [
"Return",
"a",
"list",
"of",
"resource",
"IDs",
"to",
"check",
"for",
"broken",
"links",
"."
] | ckan/deadoralive | python | https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L26-L41 | [
"def",
"get_resources_to_check",
"(",
"client_site_url",
",",
"apikey",
")",
":",
"url",
"=",
"client_site_url",
"+",
"u\"deadoralive/get_resources_to_check\"",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"dict",
"(",
"Authorization",
... | 82eed6c73e17b9884476311a7a8fae9d2b379600 |
train | get_url_for_id | Return the URL for the given resource ID.
Contacts the client site's API to get the URL for the ID and returns it.
:raises CouldNotGetURLError: if getting the URL fails for any reason | deadoralive/deadoralive.py | def get_url_for_id(client_site_url, apikey, resource_id):
"""Return the URL for the given resource ID.
Contacts the client site's API to get the URL for the ID and returns it.
:raises CouldNotGetURLError: if getting the URL fails for any reason
"""
# TODO: Handle invalid responses from the client... | def get_url_for_id(client_site_url, apikey, resource_id):
"""Return the URL for the given resource ID.
Contacts the client site's API to get the URL for the ID and returns it.
:raises CouldNotGetURLError: if getting the URL fails for any reason
"""
# TODO: Handle invalid responses from the client... | [
"Return",
"the",
"URL",
"for",
"the",
"given",
"resource",
"ID",
"."
] | ckan/deadoralive | python | https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L49-L68 | [
"def",
"get_url_for_id",
"(",
"client_site_url",
",",
"apikey",
",",
"resource_id",
")",
":",
"# TODO: Handle invalid responses from the client site.",
"url",
"=",
"client_site_url",
"+",
"u\"deadoralive/get_url_for_resource_id\"",
"params",
"=",
"{",
"\"resource_id\"",
":",
... | 82eed6c73e17b9884476311a7a8fae9d2b379600 |
train | check_url | Check whether the given URL is dead or alive.
Returns a dict with four keys:
"url": The URL that was checked (string)
"alive": Whether the URL was working, True or False
"status": The HTTP status code of the response from the URL,
e.g. 200, 401, 500 (int)
"reason": The ... | deadoralive/deadoralive.py | def check_url(url):
"""Check whether the given URL is dead or alive.
Returns a dict with four keys:
"url": The URL that was checked (string)
"alive": Whether the URL was working, True or False
"status": The HTTP status code of the response from the URL,
e.g. 200, 401, 500 (... | def check_url(url):
"""Check whether the given URL is dead or alive.
Returns a dict with four keys:
"url": The URL that was checked (string)
"alive": Whether the URL was working, True or False
"status": The HTTP status code of the response from the URL,
e.g. 200, 401, 500 (... | [
"Check",
"whether",
"the",
"given",
"URL",
"is",
"dead",
"or",
"alive",
"."
] | ckan/deadoralive | python | https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L71-L121 | [
"def",
"check_url",
"(",
"url",
")",
":",
"result",
"=",
"{",
"\"url\"",
":",
"url",
"}",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
")",
"result",
"[",
"\"status\"",
"]",
"=",
"response",
".",
"status_code",
"result",
"[",
"\"r... | 82eed6c73e17b9884476311a7a8fae9d2b379600 |
train | upsert_result | Post the given link check result to the client site. | deadoralive/deadoralive.py | def upsert_result(client_site_url, apikey, resource_id, result):
"""Post the given link check result to the client site."""
# TODO: Handle exceptions and unexpected results.
url = client_site_url + u"deadoralive/upsert"
params = result.copy()
params["resource_id"] = resource_id
requests.post(ur... | def upsert_result(client_site_url, apikey, resource_id, result):
"""Post the given link check result to the client site."""
# TODO: Handle exceptions and unexpected results.
url = client_site_url + u"deadoralive/upsert"
params = result.copy()
params["resource_id"] = resource_id
requests.post(ur... | [
"Post",
"the",
"given",
"link",
"check",
"result",
"to",
"the",
"client",
"site",
"."
] | ckan/deadoralive | python | https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L124-L131 | [
"def",
"upsert_result",
"(",
"client_site_url",
",",
"apikey",
",",
"resource_id",
",",
"result",
")",
":",
"# TODO: Handle exceptions and unexpected results.",
"url",
"=",
"client_site_url",
"+",
"u\"deadoralive/upsert\"",
"params",
"=",
"result",
".",
"copy",
"(",
"... | 82eed6c73e17b9884476311a7a8fae9d2b379600 |
train | get_check_and_report | Get links from the client site, check them, and post the results back.
Get resource IDs from the client site, get the URL for each resource ID from
the client site, check each URL, and post the results back to the client
site.
This function can be called repeatedly to keep on getting more links from
... | deadoralive/deadoralive.py | def get_check_and_report(client_site_url, apikey, get_resource_ids_to_check,
get_url_for_id, check_url, upsert_result):
"""Get links from the client site, check them, and post the results back.
Get resource IDs from the client site, get the URL for each resource ID from
the client ... | def get_check_and_report(client_site_url, apikey, get_resource_ids_to_check,
get_url_for_id, check_url, upsert_result):
"""Get links from the client site, check them, and post the results back.
Get resource IDs from the client site, get the URL for each resource ID from
the client ... | [
"Get",
"links",
"from",
"the",
"client",
"site",
"check",
"them",
"and",
"post",
"the",
"results",
"back",
"."
] | ckan/deadoralive | python | https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L148-L210 | [
"def",
"get_check_and_report",
"(",
"client_site_url",
",",
"apikey",
",",
"get_resource_ids_to_check",
",",
"get_url_for_id",
",",
"check_url",
",",
"upsert_result",
")",
":",
"logger",
"=",
"_get_logger",
"(",
")",
"resource_ids",
"=",
"get_resource_ids_to_check",
"... | 82eed6c73e17b9884476311a7a8fae9d2b379600 |
train | ZipExtFile.peek | Returns buffered bytes without advancing the position. | ofs/local/zipfile.py | def peek(self, n=1):
"""Returns buffered bytes without advancing the position."""
if n > len(self._readbuffer) - self._offset:
chunk = self.read(n)
self._offset -= len(chunk)
# Return up to 512 bytes to reduce allocation overhead for tight loops.
return self._rea... | def peek(self, n=1):
"""Returns buffered bytes without advancing the position."""
if n > len(self._readbuffer) - self._offset:
chunk = self.read(n)
self._offset -= len(chunk)
# Return up to 512 bytes to reduce allocation overhead for tight loops.
return self._rea... | [
"Returns",
"buffered",
"bytes",
"without",
"advancing",
"the",
"position",
"."
] | okfn/ofs | python | https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L551-L558 | [
"def",
"peek",
"(",
"self",
",",
"n",
"=",
"1",
")",
":",
"if",
"n",
">",
"len",
"(",
"self",
".",
"_readbuffer",
")",
"-",
"self",
".",
"_offset",
":",
"chunk",
"=",
"self",
".",
"read",
"(",
"n",
")",
"self",
".",
"_offset",
"-=",
"len",
"(... | c110cbecd7d0ae7e877963914a1a5af030cd6d45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.