repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
acutesoftware/virtual-AI-simulator | vais/character.py | Character.copy | def copy(self):
"""
make an identical copy of the character
"""
return Character(self.name, self.race,self.ch_class, self.stats, self.skills, self.story, self.inventory) | python | def copy(self):
"""
make an identical copy of the character
"""
return Character(self.name, self.race,self.ch_class, self.stats, self.skills, self.story, self.inventory) | [
"def",
"copy",
"(",
"self",
")",
":",
"return",
"Character",
"(",
"self",
".",
"name",
",",
"self",
".",
"race",
",",
"self",
".",
"ch_class",
",",
"self",
".",
"stats",
",",
"self",
".",
"skills",
",",
"self",
".",
"story",
",",
"self",
".",
"in... | make an identical copy of the character | [
"make",
"an",
"identical",
"copy",
"of",
"the",
"character"
] | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/character.py#L243-L247 | train | make an identical copy of the character |
LukeB42/Window | window.py | palette | def palette(fg, bg=-1):
"""
Since curses only supports a finite amount of initialised colour pairs
we memoise any selections you've made as an attribute on this function
"""
if not hasattr(palette, "counter"):
palette.counter = 1
if not hasattr(palette, "selections"):
palette.s... | python | def palette(fg, bg=-1):
"""
Since curses only supports a finite amount of initialised colour pairs
we memoise any selections you've made as an attribute on this function
"""
if not hasattr(palette, "counter"):
palette.counter = 1
if not hasattr(palette, "selections"):
palette.s... | [
"def",
"palette",
"(",
"fg",
",",
"bg",
"=",
"-",
"1",
")",
":",
"if",
"not",
"hasattr",
"(",
"palette",
",",
"\"counter\"",
")",
":",
"palette",
".",
"counter",
"=",
"1",
"if",
"not",
"hasattr",
"(",
"palette",
",",
"\"selections\"",
")",
":",
"pa... | Since curses only supports a finite amount of initialised colour pairs
we memoise any selections you've made as an attribute on this function | [
"Since",
"curses",
"only",
"supports",
"a",
"finite",
"amount",
"of",
"initialised",
"colour",
"pairs",
"we",
"memoise",
"any",
"selections",
"you",
"ve",
"made",
"as",
"an",
"attribute",
"on",
"this",
"function"
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L719-L750 | train | Return a new colour pair that can be used to draw a new color pair. |
LukeB42/Window | window.py | Window.start | def start(self):
"""
Window event loop
"""
self.window = _curses.initscr()
_curses.savetty()
_curses.start_color()
_curses.use_default_colors()
self.window.leaveok(1)
_curses.raw()
self.window.keypad(1)
_curses.noecho()
_cur... | python | def start(self):
"""
Window event loop
"""
self.window = _curses.initscr()
_curses.savetty()
_curses.start_color()
_curses.use_default_colors()
self.window.leaveok(1)
_curses.raw()
self.window.keypad(1)
_curses.noecho()
_cur... | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"window",
"=",
"_curses",
".",
"initscr",
"(",
")",
"_curses",
".",
"savetty",
"(",
")",
"_curses",
".",
"start_color",
"(",
")",
"_curses",
".",
"use_default_colors",
"(",
")",
"self",
".",
"window",... | Window event loop | [
"Window",
"event",
"loop"
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L63-L87 | train | Start the event loop for the current locale. |
LukeB42/Window | window.py | Window.stop | def stop(self):
"""
Restore the TTY to its original state.
"""
_curses.nocbreak()
self.window.keypad(0)
_curses.echo()
_curses.resetty()
_curses.endwin()
self.running = False | python | def stop(self):
"""
Restore the TTY to its original state.
"""
_curses.nocbreak()
self.window.keypad(0)
_curses.echo()
_curses.resetty()
_curses.endwin()
self.running = False | [
"def",
"stop",
"(",
"self",
")",
":",
"_curses",
".",
"nocbreak",
"(",
")",
"self",
".",
"window",
".",
"keypad",
"(",
"0",
")",
"_curses",
".",
"echo",
"(",
")",
"_curses",
".",
"resetty",
"(",
")",
"_curses",
".",
"endwin",
"(",
")",
"self",
".... | Restore the TTY to its original state. | [
"Restore",
"the",
"TTY",
"to",
"its",
"original",
"state",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L101-L110 | train | Stop the TTY. |
LukeB42/Window | window.py | Window.process_input | def process_input(self):
"""
Send input to panes marked as active after checking for
a request to redraw the screen (^L), a request to exit,
and optionally display character codes as they're received.
"""
try:
character = self.window.getch()
except Exc... | python | def process_input(self):
"""
Send input to panes marked as active after checking for
a request to redraw the screen (^L), a request to exit,
and optionally display character codes as they're received.
"""
try:
character = self.window.getch()
except Exc... | [
"def",
"process_input",
"(",
"self",
")",
":",
"try",
":",
"character",
"=",
"self",
".",
"window",
".",
"getch",
"(",
")",
"except",
"Exception",
"as",
"e",
":",
"character",
"=",
"-",
"1",
"if",
"self",
".",
"debug",
":",
"self",
".",
"addstr",
"... | Send input to panes marked as active after checking for
a request to redraw the screen (^L), a request to exit,
and optionally display character codes as they're received. | [
"Send",
"input",
"to",
"panes",
"marked",
"as",
"active",
"after",
"checking",
"for",
"a",
"request",
"to",
"redraw",
"the",
"screen",
"(",
"^L",
")",
"a",
"request",
"to",
"exit",
"and",
"optionally",
"display",
"character",
"codes",
"as",
"they",
"re",
... | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L290-L319 | train | Process input from the user and display the character codes as they re received. |
LukeB42/Window | window.py | Window.calculate_pane_heights_and_widths | def calculate_pane_heights_and_widths(self):
"""
Update pane heights and widths based on the current window and their desired geometry.
What to bear in mind:
Panes may have a fixed desired size.
Panes may be set to expand maximally on either axis.
Panes may be set ... | python | def calculate_pane_heights_and_widths(self):
"""
Update pane heights and widths based on the current window and their desired geometry.
What to bear in mind:
Panes may have a fixed desired size.
Panes may be set to expand maximally on either axis.
Panes may be set ... | [
"def",
"calculate_pane_heights_and_widths",
"(",
"self",
")",
":",
"# Do a pass for heights",
"# Every pane must be represented in order to map properly later",
"growing_panes",
"=",
"[",
"]",
"claimed_columns",
"=",
"0",
"for",
"v_index",
",",
"element",
"in",
"enumerate",
... | Update pane heights and widths based on the current window and their desired geometry.
What to bear in mind:
Panes may have a fixed desired size.
Panes may be set to expand maximally on either axis.
Panes may be set to fit to the sum of their content buffers (accounting for alignm... | [
"Update",
"pane",
"heights",
"and",
"widths",
"based",
"on",
"the",
"current",
"window",
"and",
"their",
"desired",
"geometry",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L321-L563 | train | Calculates the heights and widths of the panes in the current window and the current geometry. |
LukeB42/Window | window.py | Window.coordinate | def coordinate(self, panes=[], index=0):
"""
Update pane coordinate tuples based on their height and width relative to other panes
within the dimensions of the current window.
We account for panes with a height of 1 where the bottom coordinates are the same as the top.
Account f... | python | def coordinate(self, panes=[], index=0):
"""
Update pane coordinate tuples based on their height and width relative to other panes
within the dimensions of the current window.
We account for panes with a height of 1 where the bottom coordinates are the same as the top.
Account f... | [
"def",
"coordinate",
"(",
"self",
",",
"panes",
"=",
"[",
"]",
",",
"index",
"=",
"0",
")",
":",
"y",
"=",
"0",
"# height",
"for",
"i",
",",
"element",
"in",
"enumerate",
"(",
"self",
".",
"panes",
")",
":",
"x",
"=",
"0",
"# width",
"if",
"isi... | Update pane coordinate tuples based on their height and width relative to other panes
within the dimensions of the current window.
We account for panes with a height of 1 where the bottom coordinates are the same as the top.
Account for floating panes and self-coordinating panes adjacent to pan... | [
"Update",
"pane",
"coordinate",
"tuples",
"based",
"on",
"their",
"height",
"and",
"width",
"relative",
"to",
"other",
"panes",
"within",
"the",
"dimensions",
"of",
"the",
"current",
"window",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L565-L616 | train | Update the pane coordinates based on their height and width relative to other panes. |
LukeB42/Window | window.py | Window.addstr | def addstr(self, h, w, text, attrs=0):
"""
A safe addstr wrapper
"""
self.update_window_size()
if h > self.height or w > self.width:
return
try:
# Python curses addstr doesn't deal with non-ascii characters
#self.window.addstr(h, w, tex... | python | def addstr(self, h, w, text, attrs=0):
"""
A safe addstr wrapper
"""
self.update_window_size()
if h > self.height or w > self.width:
return
try:
# Python curses addstr doesn't deal with non-ascii characters
#self.window.addstr(h, w, tex... | [
"def",
"addstr",
"(",
"self",
",",
"h",
",",
"w",
",",
"text",
",",
"attrs",
"=",
"0",
")",
":",
"self",
".",
"update_window_size",
"(",
")",
"if",
"h",
">",
"self",
".",
"height",
"or",
"w",
">",
"self",
".",
"width",
":",
"return",
"try",
":"... | A safe addstr wrapper | [
"A",
"safe",
"addstr",
"wrapper"
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L618-L630 | train | A safe addstr wrapper that handles non - ascii characters and returns the new size. |
LukeB42/Window | window.py | Window.update_window_size | def update_window_size(self):
"""
Update the current window object with its current
height and width and clear the screen if they've changed.
"""
height, width = self.window.getmaxyx()
if self.height != height or self.width != width:
self.height, self.width = ... | python | def update_window_size(self):
"""
Update the current window object with its current
height and width and clear the screen if they've changed.
"""
height, width = self.window.getmaxyx()
if self.height != height or self.width != width:
self.height, self.width = ... | [
"def",
"update_window_size",
"(",
"self",
")",
":",
"height",
",",
"width",
"=",
"self",
".",
"window",
".",
"getmaxyx",
"(",
")",
"if",
"self",
".",
"height",
"!=",
"height",
"or",
"self",
".",
"width",
"!=",
"width",
":",
"self",
".",
"height",
","... | Update the current window object with its current
height and width and clear the screen if they've changed. | [
"Update",
"the",
"current",
"window",
"object",
"with",
"its",
"current",
"height",
"and",
"width",
"and",
"clear",
"the",
"screen",
"if",
"they",
"ve",
"changed",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L632-L640 | train | Update the current window height and width and clear the screen if they ve changed. |
LukeB42/Window | window.py | Window.add | def add(self, pane):
"""
Adds new panes to the window
"""
if isinstance(pane, list):
initialised_panes = []
for p in pane:
initialised_panes.append(self.init_pane(p))
self.panes.append(initialised_panes)
else:
pa... | python | def add(self, pane):
"""
Adds new panes to the window
"""
if isinstance(pane, list):
initialised_panes = []
for p in pane:
initialised_panes.append(self.init_pane(p))
self.panes.append(initialised_panes)
else:
pa... | [
"def",
"add",
"(",
"self",
",",
"pane",
")",
":",
"if",
"isinstance",
"(",
"pane",
",",
"list",
")",
":",
"initialised_panes",
"=",
"[",
"]",
"for",
"p",
"in",
"pane",
":",
"initialised_panes",
".",
"append",
"(",
"self",
".",
"init_pane",
"(",
"p",
... | Adds new panes to the window | [
"Adds",
"new",
"panes",
"to",
"the",
"window"
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L642-L653 | train | Adds new panes to the window. |
LukeB42/Window | window.py | Window.get | def get(self, name, default=None, cache=False):
"""
Get a pane by name, possibly from the cache. Return None if not found.
"""
if cache == True:
for pane in self.cache:
if pane.name == name:
return pane
return default
fo... | python | def get(self, name, default=None, cache=False):
"""
Get a pane by name, possibly from the cache. Return None if not found.
"""
if cache == True:
for pane in self.cache:
if pane.name == name:
return pane
return default
fo... | [
"def",
"get",
"(",
"self",
",",
"name",
",",
"default",
"=",
"None",
",",
"cache",
"=",
"False",
")",
":",
"if",
"cache",
"==",
"True",
":",
"for",
"pane",
"in",
"self",
".",
"cache",
":",
"if",
"pane",
".",
"name",
"==",
"name",
":",
"return",
... | Get a pane by name, possibly from the cache. Return None if not found. | [
"Get",
"a",
"pane",
"by",
"name",
"possibly",
"from",
"the",
"cache",
".",
"Return",
"None",
"if",
"not",
"found",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L673-L685 | train | Get a pane by name possibly from the cache. Return None if not found. |
LukeB42/Window | window.py | Pane.process_input | def process_input(self, character):
"""
A subclassable method for dealing with input characters.
"""
func = None
try:
func = getattr(self, "handle_%s" % chr(character), None)
except:
pass
if func:
func() | python | def process_input(self, character):
"""
A subclassable method for dealing with input characters.
"""
func = None
try:
func = getattr(self, "handle_%s" % chr(character), None)
except:
pass
if func:
func() | [
"def",
"process_input",
"(",
"self",
",",
"character",
")",
":",
"func",
"=",
"None",
"try",
":",
"func",
"=",
"getattr",
"(",
"self",
",",
"\"handle_%s\"",
"%",
"chr",
"(",
"character",
")",
",",
"None",
")",
"except",
":",
"pass",
"if",
"func",
":"... | A subclassable method for dealing with input characters. | [
"A",
"subclassable",
"method",
"for",
"dealing",
"with",
"input",
"characters",
"."
] | 6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62 | https://github.com/LukeB42/Window/blob/6d91c5ff94b8127e9c60f6eb78b7f9026d2faf62/window.py#L790-L800 | train | A subclassable method for dealing with input characters. |
tjcsl/cslbot | cslbot/commands/gcc.py | cmd | def cmd(send, msg, args):
"""Compiles stuff.
Syntax: {command} <code>
"""
if args['type'] == 'privmsg':
send('GCC is a group exercise!')
return
if 'include' in msg:
send("We're not a terribly inclusive community around here.")
return
if 'import' in msg:
... | python | def cmd(send, msg, args):
"""Compiles stuff.
Syntax: {command} <code>
"""
if args['type'] == 'privmsg':
send('GCC is a group exercise!')
return
if 'include' in msg:
send("We're not a terribly inclusive community around here.")
return
if 'import' in msg:
... | [
"def",
"cmd",
"(",
"send",
",",
"msg",
",",
"args",
")",
":",
"if",
"args",
"[",
"'type'",
"]",
"==",
"'privmsg'",
":",
"send",
"(",
"'GCC is a group exercise!'",
")",
"return",
"if",
"'include'",
"in",
"msg",
":",
"send",
"(",
"\"We're not a terribly incl... | Compiles stuff.
Syntax: {command} <code> | [
"Compiles",
"stuff",
"."
] | aebe07be47141f61d7c180706bddfb707f19b2b5 | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/gcc.py#L26-L59 | train | Compiles stuff. |
ymyzk/python-gyazo | gyazo/api.py | Api.get_image_list | def get_image_list(self, page=1, per_page=20):
"""Return a list of user's saved images
:param page: (optional) Page number (default: 1)
:param per_page: (optional) Number of images per page
(default: 20, min: 1, max: 100)
"""
url = self.api_url + '/api/i... | python | def get_image_list(self, page=1, per_page=20):
"""Return a list of user's saved images
:param page: (optional) Page number (default: 1)
:param per_page: (optional) Number of images per page
(default: 20, min: 1, max: 100)
"""
url = self.api_url + '/api/i... | [
"def",
"get_image_list",
"(",
"self",
",",
"page",
"=",
"1",
",",
"per_page",
"=",
"20",
")",
":",
"url",
"=",
"self",
".",
"api_url",
"+",
"'/api/images'",
"params",
"=",
"{",
"'page'",
":",
"page",
",",
"'per_page'",
":",
"per_page",
"}",
"response",... | Return a list of user's saved images
:param page: (optional) Page number (default: 1)
:param per_page: (optional) Number of images per page
(default: 20, min: 1, max: 100) | [
"Return",
"a",
"list",
"of",
"user",
"s",
"saved",
"images"
] | 52893118899ed308ff75245b55f73d745c98ed1d | https://github.com/ymyzk/python-gyazo/blob/52893118899ed308ff75245b55f73d745c98ed1d/gyazo/api.py#L33-L50 | train | Return a list of user s saved images. |
ymyzk/python-gyazo | gyazo/api.py | Api.upload_image | def upload_image(self,
image_file,
referer_url=None,
title=None,
desc=None,
created_at=None,
collection_id=None):
"""Upload an image
:param image_file: File-like object of an im... | python | def upload_image(self,
image_file,
referer_url=None,
title=None,
desc=None,
created_at=None,
collection_id=None):
"""Upload an image
:param image_file: File-like object of an im... | [
"def",
"upload_image",
"(",
"self",
",",
"image_file",
",",
"referer_url",
"=",
"None",
",",
"title",
"=",
"None",
",",
"desc",
"=",
"None",
",",
"created_at",
"=",
"None",
",",
"collection_id",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"upload_u... | Upload an image
:param image_file: File-like object of an image file
:param referer_url: Referer site URL
:param title: Site title
:param desc: Comment
:param created_at: Image's created time in unix time
:param collection_id: Collection ID | [
"Upload",
"an",
"image"
] | 52893118899ed308ff75245b55f73d745c98ed1d | https://github.com/ymyzk/python-gyazo/blob/52893118899ed308ff75245b55f73d745c98ed1d/gyazo/api.py#L52-L86 | train | Upload an image to the NCBI server. |
ymyzk/python-gyazo | gyazo/api.py | Api.delete_image | def delete_image(self, image_id):
"""Delete an image
:param image_id: Image ID
"""
url = self.api_url + '/api/images/' + image_id
response = self._request_url(url, 'delete', with_access_token=True)
headers, result = self._parse_and_check(response)
return Image.fr... | python | def delete_image(self, image_id):
"""Delete an image
:param image_id: Image ID
"""
url = self.api_url + '/api/images/' + image_id
response = self._request_url(url, 'delete', with_access_token=True)
headers, result = self._parse_and_check(response)
return Image.fr... | [
"def",
"delete_image",
"(",
"self",
",",
"image_id",
")",
":",
"url",
"=",
"self",
".",
"api_url",
"+",
"'/api/images/'",
"+",
"image_id",
"response",
"=",
"self",
".",
"_request_url",
"(",
"url",
",",
"'delete'",
",",
"with_access_token",
"=",
"True",
")"... | Delete an image
:param image_id: Image ID | [
"Delete",
"an",
"image"
] | 52893118899ed308ff75245b55f73d745c98ed1d | https://github.com/ymyzk/python-gyazo/blob/52893118899ed308ff75245b55f73d745c98ed1d/gyazo/api.py#L88-L96 | train | Delete an image from the cache. |
ymyzk/python-gyazo | gyazo/api.py | Api.get_oembed | def get_oembed(self, url):
"""Return an oEmbed format json dictionary
:param url: Image page URL (ex. http://gyazo.com/xxxxx)
"""
api_url = self.api_url + '/api/oembed'
parameters = {
'url': url
}
response = self._request_url(api_url, 'get', params=pa... | python | def get_oembed(self, url):
"""Return an oEmbed format json dictionary
:param url: Image page URL (ex. http://gyazo.com/xxxxx)
"""
api_url = self.api_url + '/api/oembed'
parameters = {
'url': url
}
response = self._request_url(api_url, 'get', params=pa... | [
"def",
"get_oembed",
"(",
"self",
",",
"url",
")",
":",
"api_url",
"=",
"self",
".",
"api_url",
"+",
"'/api/oembed'",
"parameters",
"=",
"{",
"'url'",
":",
"url",
"}",
"response",
"=",
"self",
".",
"_request_url",
"(",
"api_url",
",",
"'get'",
",",
"pa... | Return an oEmbed format json dictionary
:param url: Image page URL (ex. http://gyazo.com/xxxxx) | [
"Return",
"an",
"oEmbed",
"format",
"json",
"dictionary"
] | 52893118899ed308ff75245b55f73d745c98ed1d | https://github.com/ymyzk/python-gyazo/blob/52893118899ed308ff75245b55f73d745c98ed1d/gyazo/api.py#L98-L109 | train | Return an oEmbed format json dictionary |
ymyzk/python-gyazo | gyazo/api.py | Api._request_url | def _request_url(self,
url,
method,
params=None,
data=None,
files=None,
with_client_id=False,
with_access_token=False):
"""Send HTTP request
:param url: URL... | python | def _request_url(self,
url,
method,
params=None,
data=None,
files=None,
with_client_id=False,
with_access_token=False):
"""Send HTTP request
:param url: URL... | [
"def",
"_request_url",
"(",
"self",
",",
"url",
",",
"method",
",",
"params",
"=",
"None",
",",
"data",
"=",
"None",
",",
"files",
"=",
"None",
",",
"with_client_id",
"=",
"False",
",",
"with_access_token",
"=",
"False",
")",
":",
"headers",
"=",
"{",
... | Send HTTP request
:param url: URL
:param method: HTTP method (get, post or delete)
:param with_client_id: send request with client_id (default: false)
:param with_access_token: send request with with_access_token
(default: false)
:raise GyazoErr... | [
"Send",
"HTTP",
"request"
] | 52893118899ed308ff75245b55f73d745c98ed1d | https://github.com/ymyzk/python-gyazo/blob/52893118899ed308ff75245b55f73d745c98ed1d/gyazo/api.py#L111-L147 | train | Send HTTP request to the specified URL. |
Genida/archan | src/archan/dsm.py | validate_rows_length | def validate_rows_length(data, length, message=None, exception=MatrixError):
"""Validate that all rows have the same length."""
if message is None:
message = 'All rows must have the same length (same number of columns)'
for row in data:
if len(row) != length:
raise exception(mess... | python | def validate_rows_length(data, length, message=None, exception=MatrixError):
"""Validate that all rows have the same length."""
if message is None:
message = 'All rows must have the same length (same number of columns)'
for row in data:
if len(row) != length:
raise exception(mess... | [
"def",
"validate_rows_length",
"(",
"data",
",",
"length",
",",
"message",
"=",
"None",
",",
"exception",
"=",
"MatrixError",
")",
":",
"if",
"message",
"is",
"None",
":",
"message",
"=",
"'All rows must have the same length (same number of columns)'",
"for",
"row",... | Validate that all rows have the same length. | [
"Validate",
"that",
"all",
"rows",
"have",
"the",
"same",
"length",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L15-L21 | train | Validate that all rows have the same length. |
Genida/archan | src/archan/dsm.py | validate_square | def validate_square(data, message=None, exception=MatrixError):
"""Validate that the matrix has equal number of rows and columns."""
rows, columns = len(data), len(data[0]) if data else 0
if message is None:
message = 'Number of rows: %s != number of columns: %s in matrix' % (
rows, colu... | python | def validate_square(data, message=None, exception=MatrixError):
"""Validate that the matrix has equal number of rows and columns."""
rows, columns = len(data), len(data[0]) if data else 0
if message is None:
message = 'Number of rows: %s != number of columns: %s in matrix' % (
rows, colu... | [
"def",
"validate_square",
"(",
"data",
",",
"message",
"=",
"None",
",",
"exception",
"=",
"MatrixError",
")",
":",
"rows",
",",
"columns",
"=",
"len",
"(",
"data",
")",
",",
"len",
"(",
"data",
"[",
"0",
"]",
")",
"if",
"data",
"else",
"0",
"if",
... | Validate that the matrix has equal number of rows and columns. | [
"Validate",
"that",
"the",
"matrix",
"has",
"equal",
"number",
"of",
"rows",
"and",
"columns",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L24-L31 | train | Validate that the matrix has equal number of rows and columns. |
Genida/archan | src/archan/dsm.py | validate_categories_equal_entities | def validate_categories_equal_entities(categories, entities, message=None,
exception=MatrixError):
"""Validate that the matrix has equal number of entities and categories."""
nb_categories = len(categories)
nb_entities = len(entities)
if message is None:
me... | python | def validate_categories_equal_entities(categories, entities, message=None,
exception=MatrixError):
"""Validate that the matrix has equal number of entities and categories."""
nb_categories = len(categories)
nb_entities = len(entities)
if message is None:
me... | [
"def",
"validate_categories_equal_entities",
"(",
"categories",
",",
"entities",
",",
"message",
"=",
"None",
",",
"exception",
"=",
"MatrixError",
")",
":",
"nb_categories",
"=",
"len",
"(",
"categories",
")",
"nb_entities",
"=",
"len",
"(",
"entities",
")",
... | Validate that the matrix has equal number of entities and categories. | [
"Validate",
"that",
"the",
"matrix",
"has",
"equal",
"number",
"of",
"entities",
"and",
"categories",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L34-L43 | train | Validate that the matrix has equal number of entities and categories. |
Genida/archan | src/archan/dsm.py | BaseMatrix.validate | def validate(self):
"""Validate data (rows length, categories=entities, square)."""
validate_rows_length(self.data, self.columns, exception=self.error)
validate_categories_equal_entities(self.categories, self.entities,
exception=self.error)
if s... | python | def validate(self):
"""Validate data (rows length, categories=entities, square)."""
validate_rows_length(self.data, self.columns, exception=self.error)
validate_categories_equal_entities(self.categories, self.entities,
exception=self.error)
if s... | [
"def",
"validate",
"(",
"self",
")",
":",
"validate_rows_length",
"(",
"self",
".",
"data",
",",
"self",
".",
"columns",
",",
"exception",
"=",
"self",
".",
"error",
")",
"validate_categories_equal_entities",
"(",
"self",
".",
"categories",
",",
"self",
".",... | Validate data (rows length, categories=entities, square). | [
"Validate",
"data",
"(",
"rows",
"length",
"categories",
"=",
"entities",
"square",
")",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L90-L96 | train | Validate data. |
Genida/archan | src/archan/dsm.py | DesignStructureMatrix.validate | def validate(self):
"""Base validation + entities = rows."""
super().validate()
nb_entities = len(self.entities)
if nb_entities != self.rows:
raise self.error(
'Number of entities: %s != number of rows: %s' % (
nb_entities, self.rows)) | python | def validate(self):
"""Base validation + entities = rows."""
super().validate()
nb_entities = len(self.entities)
if nb_entities != self.rows:
raise self.error(
'Number of entities: %s != number of rows: %s' % (
nb_entities, self.rows)) | [
"def",
"validate",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"validate",
"(",
")",
"nb_entities",
"=",
"len",
"(",
"self",
".",
"entities",
")",
"if",
"nb_entities",
"!=",
"self",
".",
"rows",
":",
"raise",
"self",
".",
"error",
"(",
"'Number of... | Base validation + entities = rows. | [
"Base",
"validation",
"+",
"entities",
"=",
"rows",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L109-L116 | train | Base validation + entities = rows. |
Genida/archan | src/archan/dsm.py | DesignStructureMatrix.transitive_closure | def transitive_closure(self):
"""Compute the transitive closure of the matrix."""
data = [[1 if j else 0 for j in i] for i in self.data]
for k in range(self.rows):
for i in range(self.rows):
for j in range(self.rows):
if data[i][k] and data[k][j]:
... | python | def transitive_closure(self):
"""Compute the transitive closure of the matrix."""
data = [[1 if j else 0 for j in i] for i in self.data]
for k in range(self.rows):
for i in range(self.rows):
for j in range(self.rows):
if data[i][k] and data[k][j]:
... | [
"def",
"transitive_closure",
"(",
"self",
")",
":",
"data",
"=",
"[",
"[",
"1",
"if",
"j",
"else",
"0",
"for",
"j",
"in",
"i",
"]",
"for",
"i",
"in",
"self",
".",
"data",
"]",
"for",
"k",
"in",
"range",
"(",
"self",
".",
"rows",
")",
":",
"fo... | Compute the transitive closure of the matrix. | [
"Compute",
"the",
"transitive",
"closure",
"of",
"the",
"matrix",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L118-L126 | train | Compute the transitive closure of the matrix. |
Genida/archan | src/archan/dsm.py | DomainMappingMatrix.validate | def validate(self):
"""Base validation + entities = rows + columns."""
super().validate()
nb_entities = len(self.entities)
if nb_entities != self.rows + self.columns:
raise self.error(
'Number of entities: %s != number of rows + '
'number of co... | python | def validate(self):
"""Base validation + entities = rows + columns."""
super().validate()
nb_entities = len(self.entities)
if nb_entities != self.rows + self.columns:
raise self.error(
'Number of entities: %s != number of rows + '
'number of co... | [
"def",
"validate",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"validate",
"(",
")",
"nb_entities",
"=",
"len",
"(",
"self",
".",
"entities",
")",
"if",
"nb_entities",
"!=",
"self",
".",
"rows",
"+",
"self",
".",
"columns",
":",
"raise",
"self",
... | Base validation + entities = rows + columns. | [
"Base",
"validation",
"+",
"entities",
"=",
"rows",
"+",
"columns",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L134-L143 | train | Base validation + entities = rows + columns. |
Genida/archan | src/archan/dsm.py | DomainMappingMatrix.default_entities | def default_entities(self):
"""Return range from 0 to rows + columns."""
return [str(i) for i in range(self.rows + self.columns)] | python | def default_entities(self):
"""Return range from 0 to rows + columns."""
return [str(i) for i in range(self.rows + self.columns)] | [
"def",
"default_entities",
"(",
"self",
")",
":",
"return",
"[",
"str",
"(",
"i",
")",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"rows",
"+",
"self",
".",
"columns",
")",
"]"
] | Return range from 0 to rows + columns. | [
"Return",
"range",
"from",
"0",
"to",
"rows",
"+",
"columns",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L145-L147 | train | Return range from 0 to rows + columns. |
Genida/archan | src/archan/dsm.py | MultipleDomainMatrix.validate | def validate(self):
"""Base validation + each cell is instance of DSM or MDM."""
super().validate()
message_dsm = 'Matrix at [%s:%s] is not an instance of '\
'DesignStructureMatrix or MultipleDomainMatrix.'
message_ddm = 'Matrix at [%s:%s] is not an instance of '\
... | python | def validate(self):
"""Base validation + each cell is instance of DSM or MDM."""
super().validate()
message_dsm = 'Matrix at [%s:%s] is not an instance of '\
'DesignStructureMatrix or MultipleDomainMatrix.'
message_ddm = 'Matrix at [%s:%s] is not an instance of '\
... | [
"def",
"validate",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"validate",
"(",
")",
"message_dsm",
"=",
"'Matrix at [%s:%s] is not an instance of '",
"'DesignStructureMatrix or MultipleDomainMatrix.'",
"message_ddm",
"=",
"'Matrix at [%s:%s] is not an instance of '",
"'Do... | Base validation + each cell is instance of DSM or MDM. | [
"Base",
"validation",
"+",
"each",
"cell",
"is",
"instance",
"of",
"DSM",
"or",
"MDM",
"."
] | a026d3105c7e86f30e6c9507b93ceb736684bfdc | https://github.com/Genida/archan/blob/a026d3105c7e86f30e6c9507b93ceb736684bfdc/src/archan/dsm.py#L156-L174 | train | Base validation + each cell is instance of DSM or MDM. |
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans._calc_distortion | def _calc_distortion(self):
"""Calculates the distortion value of the current clusters
"""
m = self._X.shape[0]
self.distortion = 1/m * sum(
linalg.norm(self._X[i, :] - self.centroids[self.clusters[i]])**2 for i in range(m)
)
return self.distortion | python | def _calc_distortion(self):
"""Calculates the distortion value of the current clusters
"""
m = self._X.shape[0]
self.distortion = 1/m * sum(
linalg.norm(self._X[i, :] - self.centroids[self.clusters[i]])**2 for i in range(m)
)
return self.distortion | [
"def",
"_calc_distortion",
"(",
"self",
")",
":",
"m",
"=",
"self",
".",
"_X",
".",
"shape",
"[",
"0",
"]",
"self",
".",
"distortion",
"=",
"1",
"/",
"m",
"*",
"sum",
"(",
"linalg",
".",
"norm",
"(",
"self",
".",
"_X",
"[",
"i",
",",
":",
"]"... | Calculates the distortion value of the current clusters | [
"Calculates",
"the",
"distortion",
"value",
"of",
"the",
"current",
"clusters"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L30-L37 | train | Calculates the distortion value of the current clusters
|
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans._init_random_centroids | def _init_random_centroids(self):
"""Initialize the centroids as k random samples of X (k = n_clusters)
"""
self.centroids = self._X[np.random.choice(list(range(self._X.shape[0])), size=self.n_clusters), :] | python | def _init_random_centroids(self):
"""Initialize the centroids as k random samples of X (k = n_clusters)
"""
self.centroids = self._X[np.random.choice(list(range(self._X.shape[0])), size=self.n_clusters), :] | [
"def",
"_init_random_centroids",
"(",
"self",
")",
":",
"self",
".",
"centroids",
"=",
"self",
".",
"_X",
"[",
"np",
".",
"random",
".",
"choice",
"(",
"list",
"(",
"range",
"(",
"self",
".",
"_X",
".",
"shape",
"[",
"0",
"]",
")",
")",
",",
"siz... | Initialize the centroids as k random samples of X (k = n_clusters) | [
"Initialize",
"the",
"centroids",
"as",
"k",
"random",
"samples",
"of",
"X",
"(",
"k",
"=",
"n_clusters",
")"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L39-L42 | train | Initialize the centroids as k random samples of X |
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans._move_centroids | def _move_centroids(self):
"""Calculate new centroids as the means of the samples in each cluster
"""
for k in range(self.n_clusters):
if k in self.clusters:
centroid = np.mean(self._X[self.clusters == k, :], axis=0)
self.centroids[k] = centroid
... | python | def _move_centroids(self):
"""Calculate new centroids as the means of the samples in each cluster
"""
for k in range(self.n_clusters):
if k in self.clusters:
centroid = np.mean(self._X[self.clusters == k, :], axis=0)
self.centroids[k] = centroid
... | [
"def",
"_move_centroids",
"(",
"self",
")",
":",
"for",
"k",
"in",
"range",
"(",
"self",
".",
"n_clusters",
")",
":",
"if",
"k",
"in",
"self",
".",
"clusters",
":",
"centroid",
"=",
"np",
".",
"mean",
"(",
"self",
".",
"_X",
"[",
"self",
".",
"cl... | Calculate new centroids as the means of the samples in each cluster | [
"Calculate",
"new",
"centroids",
"as",
"the",
"means",
"of",
"the",
"samples",
"in",
"each",
"cluster"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L44-L56 | train | Move the centroids of the samples in each cluster to the mean of the samples in each cluster. |
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans._closest_centroid | def _closest_centroid(self, x):
"""Returns the index of the closest centroid to the sample
"""
closest_centroid = 0
distance = 10^9
for i in range(self.n_clusters):
current_distance = linalg.norm(x - self.centroids[i])
if current_distance < distance:
... | python | def _closest_centroid(self, x):
"""Returns the index of the closest centroid to the sample
"""
closest_centroid = 0
distance = 10^9
for i in range(self.n_clusters):
current_distance = linalg.norm(x - self.centroids[i])
if current_distance < distance:
... | [
"def",
"_closest_centroid",
"(",
"self",
",",
"x",
")",
":",
"closest_centroid",
"=",
"0",
"distance",
"=",
"10",
"^",
"9",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"n_clusters",
")",
":",
"current_distance",
"=",
"linalg",
".",
"norm",
"(",
"x",
... | Returns the index of the closest centroid to the sample | [
"Returns",
"the",
"index",
"of",
"the",
"closest",
"centroid",
"to",
"the",
"sample"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L58-L70 | train | Returns the index of the closest centroid to the sample
|
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans._assign_clusters | def _assign_clusters(self):
"""Assign the samples to the closest centroids to create clusters
"""
self.clusters = np.array([self._closest_centroid(x) for x in self._X]) | python | def _assign_clusters(self):
"""Assign the samples to the closest centroids to create clusters
"""
self.clusters = np.array([self._closest_centroid(x) for x in self._X]) | [
"def",
"_assign_clusters",
"(",
"self",
")",
":",
"self",
".",
"clusters",
"=",
"np",
".",
"array",
"(",
"[",
"self",
".",
"_closest_centroid",
"(",
"x",
")",
"for",
"x",
"in",
"self",
".",
"_X",
"]",
")"
] | Assign the samples to the closest centroids to create clusters | [
"Assign",
"the",
"samples",
"to",
"the",
"closest",
"centroids",
"to",
"create",
"clusters"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L72-L75 | train | Assign the samples to the closest centroids to create clusters
|
VIVelev/PyDojoML | dojo/cluster/kmeans.py | KMeans.fit | def fit(self, X):
"""The K-Means itself
"""
self._X = super().cluster(X)
candidates = []
for _ in range(self.n_runs):
self._init_random_centroids()
while True:
prev_clusters = self.clusters
self._assign_clusters()
... | python | def fit(self, X):
"""The K-Means itself
"""
self._X = super().cluster(X)
candidates = []
for _ in range(self.n_runs):
self._init_random_centroids()
while True:
prev_clusters = self.clusters
self._assign_clusters()
... | [
"def",
"fit",
"(",
"self",
",",
"X",
")",
":",
"self",
".",
"_X",
"=",
"super",
"(",
")",
".",
"cluster",
"(",
"X",
")",
"candidates",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"n_runs",
")",
":",
"self",
".",
"_init_random_ce... | The K-Means itself | [
"The",
"K",
"-",
"Means",
"itself"
] | 773fdce6866aa6decd306a5a85f94129fed816eb | https://github.com/VIVelev/PyDojoML/blob/773fdce6866aa6decd306a5a85f94129fed816eb/dojo/cluster/kmeans.py#L77-L102 | train | The K - Means itself is a K - Means object. This method computes the cluster distribution and sets the distortion and centroids of the K - Means object to the cluster distribution of the K - Means object. |
tjcsl/cslbot | cslbot/commands/jargon.py | cmd | def cmd(send, *_):
"""Causes the bot to generate some jargon.
Syntax: {command}
"""
words = [[verb, noun, abbrev, noun, adj, abbrev, noun], [verb, adj, abbrev, noun], [verb, abbrev, noun, verb, adj, noun],
[verb, noun, ingverb, adj, abbrev, noun], [adj, abbrev, noun, verb, adj, noun], [ab... | python | def cmd(send, *_):
"""Causes the bot to generate some jargon.
Syntax: {command}
"""
words = [[verb, noun, abbrev, noun, adj, abbrev, noun], [verb, adj, abbrev, noun], [verb, abbrev, noun, verb, adj, noun],
[verb, noun, ingverb, adj, abbrev, noun], [adj, abbrev, noun, verb, adj, noun], [ab... | [
"def",
"cmd",
"(",
"send",
",",
"*",
"_",
")",
":",
"words",
"=",
"[",
"[",
"verb",
",",
"noun",
",",
"abbrev",
",",
"noun",
",",
"adj",
",",
"abbrev",
",",
"noun",
"]",
",",
"[",
"verb",
",",
"adj",
",",
"abbrev",
",",
"noun",
"]",
",",
"[... | Causes the bot to generate some jargon.
Syntax: {command} | [
"Causes",
"the",
"bot",
"to",
"generate",
"some",
"jargon",
"."
] | aebe07be47141f61d7c180706bddfb707f19b2b5 | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/jargon.py#L49-L69 | train | A simple command that can generate some jargon. |
tjcsl/cslbot | cslbot/commands/fweather.py | cmd | def cmd(send, msg, _):
"""Gets the F***ING weather!
Syntax: {command} <location>
"""
try:
req = get('http://thefuckingweather.com/April/%s' % msg, timeout=5)
doc = fromstring(req.text)
elem = doc.find('.//h1')
except ReadTimeout:
elem = None
if elem is None:
... | python | def cmd(send, msg, _):
"""Gets the F***ING weather!
Syntax: {command} <location>
"""
try:
req = get('http://thefuckingweather.com/April/%s' % msg, timeout=5)
doc = fromstring(req.text)
elem = doc.find('.//h1')
except ReadTimeout:
elem = None
if elem is None:
... | [
"def",
"cmd",
"(",
"send",
",",
"msg",
",",
"_",
")",
":",
"try",
":",
"req",
"=",
"get",
"(",
"'http://thefuckingweather.com/April/%s'",
"%",
"msg",
",",
"timeout",
"=",
"5",
")",
"doc",
"=",
"fromstring",
"(",
"req",
".",
"text",
")",
"elem",
"=",
... | Gets the F***ING weather!
Syntax: {command} <location> | [
"Gets",
"the",
"F",
"***",
"ING",
"weather!",
"Syntax",
":",
"{",
"command",
"}",
"<location",
">"
] | aebe07be47141f61d7c180706bddfb707f19b2b5 | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/fweather.py#L27-L40 | train | Gets the F***ING weather! |
banesullivan/gendocs | gendocs/generator.py | Classifier.GetModuleText | def GetModuleText(heading, name, showprivate=False):
"""Returns the needed text to automatically document a module in RSF/sphinx"""
und = '='*len(heading)
if showprivate:
opts = ':private-members:'
else:
opts = ''
return r'''
%s
%s
.. automodule:: %s
... | python | def GetModuleText(heading, name, showprivate=False):
"""Returns the needed text to automatically document a module in RSF/sphinx"""
und = '='*len(heading)
if showprivate:
opts = ':private-members:'
else:
opts = ''
return r'''
%s
%s
.. automodule:: %s
... | [
"def",
"GetModuleText",
"(",
"heading",
",",
"name",
",",
"showprivate",
"=",
"False",
")",
":",
"und",
"=",
"'='",
"*",
"len",
"(",
"heading",
")",
"if",
"showprivate",
":",
"opts",
"=",
"':private-members:'",
"else",
":",
"opts",
"=",
"''",
"return",
... | Returns the needed text to automatically document a module in RSF/sphinx | [
"Returns",
"the",
"needed",
"text",
"to",
"automatically",
"document",
"a",
"module",
"in",
"RSF",
"/",
"sphinx"
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L128-L143 | train | Returns the needed text to automatically document a module in RSF. |
banesullivan/gendocs | gendocs/generator.py | Classifier.GetClassText | def GetClassText(heading, name, showprivate=False, showinh=False):
"""Returns the needed text to automatically document a class in RSF/sphinx"""
und = '-'*len(heading)
avail = [':private-members:', ':inherited-members:']
opts = []
if showprivate:
opts.append(avail[0])... | python | def GetClassText(heading, name, showprivate=False, showinh=False):
"""Returns the needed text to automatically document a class in RSF/sphinx"""
und = '-'*len(heading)
avail = [':private-members:', ':inherited-members:']
opts = []
if showprivate:
opts.append(avail[0])... | [
"def",
"GetClassText",
"(",
"heading",
",",
"name",
",",
"showprivate",
"=",
"False",
",",
"showinh",
"=",
"False",
")",
":",
"und",
"=",
"'-'",
"*",
"len",
"(",
"heading",
")",
"avail",
"=",
"[",
"':private-members:'",
",",
"':inherited-members:'",
"]",
... | Returns the needed text to automatically document a class in RSF/sphinx | [
"Returns",
"the",
"needed",
"text",
"to",
"automatically",
"document",
"a",
"class",
"in",
"RSF",
"/",
"sphinx"
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L148-L169 | train | Returns the needed text to automatically document a class in RSF. |
banesullivan/gendocs | gendocs/generator.py | Classifier.GetFunctionText | def GetFunctionText(heading, name):
"""Returns the needed text to automatically document a function in RSF/sphinx"""
und = '-'*len(heading)
return r'''
%s
%s
.. autofunction:: %s
''' % (heading, und, name) | python | def GetFunctionText(heading, name):
"""Returns the needed text to automatically document a function in RSF/sphinx"""
und = '-'*len(heading)
return r'''
%s
%s
.. autofunction:: %s
''' % (heading, und, name) | [
"def",
"GetFunctionText",
"(",
"heading",
",",
"name",
")",
":",
"und",
"=",
"'-'",
"*",
"len",
"(",
"heading",
")",
"return",
"r'''\n\n%s\n%s\n\n.. autofunction:: %s\n\n'''",
"%",
"(",
"heading",
",",
"und",
",",
"name",
")"
] | Returns the needed text to automatically document a function in RSF/sphinx | [
"Returns",
"the",
"needed",
"text",
"to",
"automatically",
"document",
"a",
"function",
"in",
"RSF",
"/",
"sphinx"
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L175-L185 | train | Returns the needed text to automatically document a function in RSF. |
banesullivan/gendocs | gendocs/generator.py | Generator._GenerateStaticsTable | def _GenerateStaticsTable(self, title='Current Statistics'):
"""Generates a statics table based on set categories"""
if len(self.__categories.keys()) < 1:
return ''
d = self.__categories
keys = sorted(d.keys())
cats = ', '.join(['"%s"' % k for k in keys])
vals... | python | def _GenerateStaticsTable(self, title='Current Statistics'):
"""Generates a statics table based on set categories"""
if len(self.__categories.keys()) < 1:
return ''
d = self.__categories
keys = sorted(d.keys())
cats = ', '.join(['"%s"' % k for k in keys])
vals... | [
"def",
"_GenerateStaticsTable",
"(",
"self",
",",
"title",
"=",
"'Current Statistics'",
")",
":",
"if",
"len",
"(",
"self",
".",
"__categories",
".",
"keys",
"(",
")",
")",
"<",
"1",
":",
"return",
"''",
"d",
"=",
"self",
".",
"__categories",
"keys",
"... | Generates a statics table based on set categories | [
"Generates",
"a",
"statics",
"table",
"based",
"on",
"set",
"categories"
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L212-L231 | train | Generates a statics table based on set categories |
banesullivan/gendocs | gendocs/generator.py | Generator._ProduceSingleContent | def _ProduceSingleContent(self, mod, showprivate=False, showinh=False):
"""An internal helper to create a page for a single module. This will
automatically generate the needed RSF to document the module
and save the module to its own page in its appropriate location.
Args:
m... | python | def _ProduceSingleContent(self, mod, showprivate=False, showinh=False):
"""An internal helper to create a page for a single module. This will
automatically generate the needed RSF to document the module
and save the module to its own page in its appropriate location.
Args:
m... | [
"def",
"_ProduceSingleContent",
"(",
"self",
",",
"mod",
",",
"showprivate",
"=",
"False",
",",
"showinh",
"=",
"False",
")",
":",
"try",
":",
"all",
"=",
"mod",
"[",
"1",
"]",
".",
"__all__",
"except",
"AttributeError",
":",
"raise",
"RuntimeError",
"("... | An internal helper to create a page for a single module. This will
automatically generate the needed RSF to document the module
and save the module to its own page in its appropriate location.
Args:
mod (module): The single module to document as its own page
showprivate ... | [
"An",
"internal",
"helper",
"to",
"create",
"a",
"page",
"for",
"a",
"single",
"module",
".",
"This",
"will",
"automatically",
"generate",
"the",
"needed",
"RSF",
"to",
"document",
"the",
"module",
"and",
"save",
"the",
"module",
"to",
"its",
"own",
"page"... | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L233-L285 | train | Internal helper to create a single page for a single module. |
banesullivan/gendocs | gendocs/generator.py | Generator._ProduceContent | def _ProduceContent(self, mods, showprivate=False, showinh=False):
"""An internal helper to create pages for several modules that do not have nested modules.
This will automatically generate the needed RSF to document each module module
and save the module to its own page appropriately.
... | python | def _ProduceContent(self, mods, showprivate=False, showinh=False):
"""An internal helper to create pages for several modules that do not have nested modules.
This will automatically generate the needed RSF to document each module module
and save the module to its own page appropriately.
... | [
"def",
"_ProduceContent",
"(",
"self",
",",
"mods",
",",
"showprivate",
"=",
"False",
",",
"showinh",
"=",
"False",
")",
":",
"result",
"=",
"''",
"nestedresult",
"=",
"''",
"# For each module",
"for",
"mod",
"in",
"mods",
":",
"# Test to see if module to docu... | An internal helper to create pages for several modules that do not have nested modules.
This will automatically generate the needed RSF to document each module module
and save the module to its own page appropriately.
Args:
mods (module): The modules to document that do not contain ... | [
"An",
"internal",
"helper",
"to",
"create",
"pages",
"for",
"several",
"modules",
"that",
"do",
"not",
"have",
"nested",
"modules",
".",
"This",
"will",
"automatically",
"generate",
"the",
"needed",
"RSF",
"to",
"document",
"each",
"module",
"module",
"and",
... | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L289-L316 | train | Internal helper to create pages for several modules that do not contain nested modules. This will automatically generate the needed RSF to document each module and save the module to its own page appropriately. |
banesullivan/gendocs | gendocs/generator.py | Generator._MakePackagePages | def _MakePackagePages(self, package, showprivate=False, nested=False, showinh=False):
"""An internal helper to generate all of the pages for a given package
Args:
package (module): The top-level package to document
showprivate (bool): A flag for whether or not to display private... | python | def _MakePackagePages(self, package, showprivate=False, nested=False, showinh=False):
"""An internal helper to generate all of the pages for a given package
Args:
package (module): The top-level package to document
showprivate (bool): A flag for whether or not to display private... | [
"def",
"_MakePackagePages",
"(",
"self",
",",
"package",
",",
"showprivate",
"=",
"False",
",",
"nested",
"=",
"False",
",",
"showinh",
"=",
"False",
")",
":",
"def",
"checkNoNested",
"(",
"mod",
")",
":",
"try",
":",
"all",
"=",
"mod",
".",
"__all__",... | An internal helper to generate all of the pages for a given package
Args:
package (module): The top-level package to document
showprivate (bool): A flag for whether or not to display private members
nested (bool): Foor internal use ONLY
Returns:
str: The... | [
"An",
"internal",
"helper",
"to",
"generate",
"all",
"of",
"the",
"pages",
"for",
"a",
"given",
"package"
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L321-L401 | train | Internal helper to generate all of the pages for a given top - level module and all of its sub - packages. |
banesullivan/gendocs | gendocs/generator.py | Generator._DocPackageFromTop | def _DocPackageFromTop(self, packages, showprivate=False, showinh=False):
"""Generates all of the documentation for given packages and
appends new tocrees to the index. All documentation pages will be under the
set relative path.
Args:
packages (list(module)): A package or l... | python | def _DocPackageFromTop(self, packages, showprivate=False, showinh=False):
"""Generates all of the documentation for given packages and
appends new tocrees to the index. All documentation pages will be under the
set relative path.
Args:
packages (list(module)): A package or l... | [
"def",
"_DocPackageFromTop",
"(",
"self",
",",
"packages",
",",
"showprivate",
"=",
"False",
",",
"showinh",
"=",
"False",
")",
":",
"appIndex",
"=",
"''",
"if",
"not",
"isinstance",
"(",
"packages",
",",
"list",
")",
":",
"packages",
"=",
"[",
"packages... | Generates all of the documentation for given packages and
appends new tocrees to the index. All documentation pages will be under the
set relative path.
Args:
packages (list(module)): A package or list of packages that contain submodules to document
showprivate (bool): A... | [
"Generates",
"all",
"of",
"the",
"documentation",
"for",
"given",
"packages",
"and",
"appends",
"new",
"tocrees",
"to",
"the",
"index",
".",
"All",
"documentation",
"pages",
"will",
"be",
"under",
"the",
"set",
"relative",
"path",
"."
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L405-L481 | train | Generates all of the documentation for given packages and appends new tocrees to the index. |
banesullivan/gendocs | gendocs/generator.py | Generator.DocumentPackages | def DocumentPackages(self, packages, index_base=None, showprivate=False,
notify=True, showinh=False, intro_pages=None,
append_material=None, extra=None):
"""This is the high level API to use to generate documentation pages for any given package(s).
Args... | python | def DocumentPackages(self, packages, index_base=None, showprivate=False,
notify=True, showinh=False, intro_pages=None,
append_material=None, extra=None):
"""This is the high level API to use to generate documentation pages for any given package(s).
Args... | [
"def",
"DocumentPackages",
"(",
"self",
",",
"packages",
",",
"index_base",
"=",
"None",
",",
"showprivate",
"=",
"False",
",",
"notify",
"=",
"True",
",",
"showinh",
"=",
"False",
",",
"intro_pages",
"=",
"None",
",",
"append_material",
"=",
"None",
",",
... | This is the high level API to use to generate documentation pages for any given package(s).
Args:
packages (list(module)): A list of packages that contain submodules to document
index_base (str): The index page file name. This content will be appended
showprivate (bool): A f... | [
"This",
"is",
"the",
"high",
"level",
"API",
"to",
"use",
"to",
"generate",
"documentation",
"pages",
"for",
"any",
"given",
"package",
"(",
"s",
")",
"."
] | 4ff6277370143ba698701beccc05d5eace43b632 | https://github.com/banesullivan/gendocs/blob/4ff6277370143ba698701beccc05d5eace43b632/gendocs/generator.py#L498-L555 | train | This function generates documentation pages for a list of packages. |
davisagli/eye | eye/__init__.py | eye | def eye(root=None, zodb_uri=None, port=8080):
"""Serves a WSGI app to browse objects based on a root object or ZODB URI.
"""
if root is not None:
root_factory = lambda request: Node(root)
elif zodb_uri is not None:
if '://' not in zodb_uri:
# treat it as a file://
... | python | def eye(root=None, zodb_uri=None, port=8080):
"""Serves a WSGI app to browse objects based on a root object or ZODB URI.
"""
if root is not None:
root_factory = lambda request: Node(root)
elif zodb_uri is not None:
if '://' not in zodb_uri:
# treat it as a file://
... | [
"def",
"eye",
"(",
"root",
"=",
"None",
",",
"zodb_uri",
"=",
"None",
",",
"port",
"=",
"8080",
")",
":",
"if",
"root",
"is",
"not",
"None",
":",
"root_factory",
"=",
"lambda",
"request",
":",
"Node",
"(",
"root",
")",
"elif",
"zodb_uri",
"is",
"no... | Serves a WSGI app to browse objects based on a root object or ZODB URI. | [
"Serves",
"a",
"WSGI",
"app",
"to",
"browse",
"objects",
"based",
"on",
"a",
"root",
"object",
"or",
"ZODB",
"URI",
"."
] | 4007b6b490ac667c8423c6cc789b303e93f9d03d | https://github.com/davisagli/eye/blob/4007b6b490ac667c8423c6cc789b303e93f9d03d/eye/__init__.py#L53-L75 | train | Serves a WSGI app to browse objects based on a root object or ZODB URI. |
tjcsl/cslbot | cslbot/commands/active.py | cmd | def cmd(send, _, args):
"""Returns stats on the active users.
Syntax: {command}
"""
if args['target'] == 'private':
send("You're all alone!")
return
with args['handler'].data_lock:
channel = args['handler'].channels[args['target']]
voiced = len([x for x in args['han... | python | def cmd(send, _, args):
"""Returns stats on the active users.
Syntax: {command}
"""
if args['target'] == 'private':
send("You're all alone!")
return
with args['handler'].data_lock:
channel = args['handler'].channels[args['target']]
voiced = len([x for x in args['han... | [
"def",
"cmd",
"(",
"send",
",",
"_",
",",
"args",
")",
":",
"if",
"args",
"[",
"'target'",
"]",
"==",
"'private'",
":",
"send",
"(",
"\"You're all alone!\"",
")",
"return",
"with",
"args",
"[",
"'handler'",
"]",
".",
"data_lock",
":",
"channel",
"=",
... | Returns stats on the active users.
Syntax: {command} | [
"Returns",
"stats",
"on",
"the",
"active",
"users",
"."
] | aebe07be47141f61d7c180706bddfb707f19b2b5 | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/active.py#L22-L35 | train | Returns stats on the active users. |
Aplopio/django_rip | rip/django_adapter/action_resolver.py | determine_end_point | def determine_end_point(http_request, url):
"""
returns detail, list or aggregates
"""
if url.endswith('aggregates') or url.endswith('aggregates/'):
return 'aggregates'
else:
return 'detail' if is_detail_url(http_request, url) else 'list' | python | def determine_end_point(http_request, url):
"""
returns detail, list or aggregates
"""
if url.endswith('aggregates') or url.endswith('aggregates/'):
return 'aggregates'
else:
return 'detail' if is_detail_url(http_request, url) else 'list' | [
"def",
"determine_end_point",
"(",
"http_request",
",",
"url",
")",
":",
"if",
"url",
".",
"endswith",
"(",
"'aggregates'",
")",
"or",
"url",
".",
"endswith",
"(",
"'aggregates/'",
")",
":",
"return",
"'aggregates'",
"else",
":",
"return",
"'detail'",
"if",
... | returns detail, list or aggregates | [
"returns",
"detail",
"list",
"or",
"aggregates"
] | 6b03962ccb778c1a95950a3803e5170c7a2392df | https://github.com/Aplopio/django_rip/blob/6b03962ccb778c1a95950a3803e5170c7a2392df/rip/django_adapter/action_resolver.py#L18-L25 | train | Determine the end point of the resource. |
acutesoftware/virtual-AI-simulator | vais/battle.py | BattleSimulator.run_simulation | def run_simulation(self):
"""
runs the simulation
"""
for _ in range(self.num_fights):
# restore health between each fight
self.c1.stats['Health'] = self.c1.stats['max_health']
self.c2.stats['Health'] = self.c2.stats['max_health']
... | python | def run_simulation(self):
"""
runs the simulation
"""
for _ in range(self.num_fights):
# restore health between each fight
self.c1.stats['Health'] = self.c1.stats['max_health']
self.c2.stats['Health'] = self.c2.stats['max_health']
... | [
"def",
"run_simulation",
"(",
"self",
")",
":",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"num_fights",
")",
":",
"# restore health between each fight",
"self",
".",
"c1",
".",
"stats",
"[",
"'Health'",
"]",
"=",
"self",
".",
"c1",
".",
"stats",
"[",
... | runs the simulation | [
"runs",
"the",
"simulation"
] | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/battle.py#L53-L74 | train | runs the simulation for the base class |
acutesoftware/virtual-AI-simulator | vais/battle.py | Battle.fight | def fight(self, moves, print_console):
"""
runs a series of fights - TODO switch order
of who attacks first, as this has an effect
on win rate over 1000 fights
"""
for _ in range(1, moves):
#if i == 1 and random.randint(1,100) > 50: # randomly choose who m... | python | def fight(self, moves, print_console):
"""
runs a series of fights - TODO switch order
of who attacks first, as this has an effect
on win rate over 1000 fights
"""
for _ in range(1, moves):
#if i == 1 and random.randint(1,100) > 50: # randomly choose who m... | [
"def",
"fight",
"(",
"self",
",",
"moves",
",",
"print_console",
")",
":",
"for",
"_",
"in",
"range",
"(",
"1",
",",
"moves",
")",
":",
"#if i == 1 and random.randint(1,100) > 50: # randomly choose who moves first",
"# player 1",
"result",
",",
"dmg",
"=",
"self... | runs a series of fights - TODO switch order
of who attacks first, as this has an effect
on win rate over 1000 fights | [
"runs",
"a",
"series",
"of",
"fights",
"-",
"TODO",
"switch",
"order",
"of",
"who",
"attacks",
"first",
"as",
"this",
"has",
"an",
"effect",
"on",
"win",
"rate",
"over",
"1000",
"fights"
] | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/battle.py#L95-L117 | train | runs a series of fights |
acutesoftware/virtual-AI-simulator | vais/battle.py | Battle.take_damage | def take_damage(self, c, dmg):
"""
wrapper to apply damage taken to a character
"""
if c.name == self.c1.name:
self.c1.stats['Health'] = self.c1.stats['Health'] - dmg
else:
self.c2.stats['Health'] = self.c2.stats['Health'] - dmg | python | def take_damage(self, c, dmg):
"""
wrapper to apply damage taken to a character
"""
if c.name == self.c1.name:
self.c1.stats['Health'] = self.c1.stats['Health'] - dmg
else:
self.c2.stats['Health'] = self.c2.stats['Health'] - dmg | [
"def",
"take_damage",
"(",
"self",
",",
"c",
",",
"dmg",
")",
":",
"if",
"c",
".",
"name",
"==",
"self",
".",
"c1",
".",
"name",
":",
"self",
".",
"c1",
".",
"stats",
"[",
"'Health'",
"]",
"=",
"self",
".",
"c1",
".",
"stats",
"[",
"'Health'",
... | wrapper to apply damage taken to a character | [
"wrapper",
"to",
"apply",
"damage",
"taken",
"to",
"a",
"character"
] | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/battle.py#L119-L126 | train | wrapper to apply damage taken to a character |
acutesoftware/virtual-AI-simulator | vais/battle.py | Battle.show_message | def show_message(self, c_attack, c_defend, result, dmg, print_console='Yes'):
"""
function to wrap the display of the battle messages
"""
perc_health_att = '[' + str(round((c_attack.stats['Health']*100) / c_attack.stats['max_health'] )) + '%]'
perc_health_def = '[' + str(round((c... | python | def show_message(self, c_attack, c_defend, result, dmg, print_console='Yes'):
"""
function to wrap the display of the battle messages
"""
perc_health_att = '[' + str(round((c_attack.stats['Health']*100) / c_attack.stats['max_health'] )) + '%]'
perc_health_def = '[' + str(round((c... | [
"def",
"show_message",
"(",
"self",
",",
"c_attack",
",",
"c_defend",
",",
"result",
",",
"dmg",
",",
"print_console",
"=",
"'Yes'",
")",
":",
"perc_health_att",
"=",
"'['",
"+",
"str",
"(",
"round",
"(",
"(",
"c_attack",
".",
"stats",
"[",
"'Health'",
... | function to wrap the display of the battle messages | [
"function",
"to",
"wrap",
"the",
"display",
"of",
"the",
"battle",
"messages"
] | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/battle.py#L129-L145 | train | function to wrap the display of the battle messages |
acutesoftware/virtual-AI-simulator | vais/battle.py | Battle.calc_move | def calc_move(self, c):
"""
calculate the amount of damage down using the battle.rules file
WARNING - shitty eval functions - careful with user input.
TODO = max_hit = parser.parse(self.rules['hit_max']).to_pyfunc()
"""
# first get local variables the same as bat... | python | def calc_move(self, c):
"""
calculate the amount of damage down using the battle.rules file
WARNING - shitty eval functions - careful with user input.
TODO = max_hit = parser.parse(self.rules['hit_max']).to_pyfunc()
"""
# first get local variables the same as bat... | [
"def",
"calc_move",
"(",
"self",
",",
"c",
")",
":",
"# first get local variables the same as battle.rules file so parser can interpret.",
"AGI",
"=",
"c",
".",
"stats",
"[",
"'AGI'",
"]",
"INT",
"=",
"c",
".",
"stats",
"[",
"'INT'",
"]",
"STR",
"=",
"c",
".",... | calculate the amount of damage down using the battle.rules file
WARNING - shitty eval functions - careful with user input.
TODO = max_hit = parser.parse(self.rules['hit_max']).to_pyfunc() | [
"calculate",
"the",
"amount",
"of",
"damage",
"down",
"using",
"the",
"battle",
".",
"rules",
"file",
"WARNING",
"-",
"shitty",
"eval",
"functions",
"-",
"careful",
"with",
"user",
"input",
".",
"TODO",
"=",
"max_hit",
"=",
"parser",
".",
"parse",
"(",
"... | 57de679a5b1a58c38fefe6aea58af1f3a7e79c58 | https://github.com/acutesoftware/virtual-AI-simulator/blob/57de679a5b1a58c38fefe6aea58af1f3a7e79c58/vais/battle.py#L147-L195 | train | calculate the amount of damage down using the battle. rules file |
gtsystem/parallelpipe | parallelpipe.py | iterqueue | def iterqueue(queue, expected):
"""Iterate all value from the queue until the ``expected`` number of EXIT elements is
received"""
while expected > 0:
for item in iter(queue.get, EXIT):
yield item
expected -= 1 | python | def iterqueue(queue, expected):
"""Iterate all value from the queue until the ``expected`` number of EXIT elements is
received"""
while expected > 0:
for item in iter(queue.get, EXIT):
yield item
expected -= 1 | [
"def",
"iterqueue",
"(",
"queue",
",",
"expected",
")",
":",
"while",
"expected",
">",
"0",
":",
"for",
"item",
"in",
"iter",
"(",
"queue",
".",
"get",
",",
"EXIT",
")",
":",
"yield",
"item",
"expected",
"-=",
"1"
] | Iterate all value from the queue until the ``expected`` number of EXIT elements is
received | [
"Iterate",
"all",
"value",
"from",
"the",
"queue",
"until",
"the",
"expected",
"number",
"of",
"EXIT",
"elements",
"is",
"received"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L16-L22 | train | Iterate all items from the queue until the expected number of EXIT elements is received |
gtsystem/parallelpipe | parallelpipe.py | Task.set_in | def set_in(self, que_in, num_senders):
"""Set the queue in input and the number of parallel tasks that send inputs"""
self._que_in = que_in
self._num_senders = num_senders | python | def set_in(self, que_in, num_senders):
"""Set the queue in input and the number of parallel tasks that send inputs"""
self._que_in = que_in
self._num_senders = num_senders | [
"def",
"set_in",
"(",
"self",
",",
"que_in",
",",
"num_senders",
")",
":",
"self",
".",
"_que_in",
"=",
"que_in",
"self",
".",
"_num_senders",
"=",
"num_senders"
] | Set the queue in input and the number of parallel tasks that send inputs | [
"Set",
"the",
"queue",
"in",
"input",
"and",
"the",
"number",
"of",
"parallel",
"tasks",
"that",
"send",
"inputs"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L35-L38 | train | Set the queue in input and the number of parallel tasks that send inputs |
gtsystem/parallelpipe | parallelpipe.py | Task.set_out | def set_out(self, que_out, num_followers):
"""Set the queue in output and the number of parallel tasks that follow"""
self._que_out = que_out
self._num_followers = num_followers | python | def set_out(self, que_out, num_followers):
"""Set the queue in output and the number of parallel tasks that follow"""
self._que_out = que_out
self._num_followers = num_followers | [
"def",
"set_out",
"(",
"self",
",",
"que_out",
",",
"num_followers",
")",
":",
"self",
".",
"_que_out",
"=",
"que_out",
"self",
".",
"_num_followers",
"=",
"num_followers"
] | Set the queue in output and the number of parallel tasks that follow | [
"Set",
"the",
"queue",
"in",
"output",
"and",
"the",
"number",
"of",
"parallel",
"tasks",
"that",
"follow"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L40-L43 | train | Set the queue in output and the number of parallel tasks that follow |
gtsystem/parallelpipe | parallelpipe.py | Task.run | def run(self):
"""Execute the task on all the input and send the needed number of EXIT at the end"""
input = self._consume()
put_item = self._que_out.put
try:
if input is None: # producer
res = self._callable(*self._args, **self._kwargs)
e... | python | def run(self):
"""Execute the task on all the input and send the needed number of EXIT at the end"""
input = self._consume()
put_item = self._que_out.put
try:
if input is None: # producer
res = self._callable(*self._args, **self._kwargs)
e... | [
"def",
"run",
"(",
"self",
")",
":",
"input",
"=",
"self",
".",
"_consume",
"(",
")",
"put_item",
"=",
"self",
".",
"_que_out",
".",
"put",
"try",
":",
"if",
"input",
"is",
"None",
":",
"# producer",
"res",
"=",
"self",
".",
"_callable",
"(",
"*",
... | Execute the task on all the input and send the needed number of EXIT at the end | [
"Execute",
"the",
"task",
"on",
"all",
"the",
"input",
"and",
"send",
"the",
"needed",
"number",
"of",
"EXIT",
"at",
"the",
"end"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L56-L83 | train | Execute the task on all the input and send the needed number of EXIT at the end |
gtsystem/parallelpipe | parallelpipe.py | Stage.setup | def setup(self, workers=1, qsize=0):
"""Setup the pool parameters like number of workers and output queue size"""
if workers <= 0:
raise ValueError("workers have to be greater then zero")
if qsize < 0:
raise ValueError("qsize have to be greater or equal zero")
sel... | python | def setup(self, workers=1, qsize=0):
"""Setup the pool parameters like number of workers and output queue size"""
if workers <= 0:
raise ValueError("workers have to be greater then zero")
if qsize < 0:
raise ValueError("qsize have to be greater or equal zero")
sel... | [
"def",
"setup",
"(",
"self",
",",
"workers",
"=",
"1",
",",
"qsize",
"=",
"0",
")",
":",
"if",
"workers",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"workers have to be greater then zero\"",
")",
"if",
"qsize",
"<",
"0",
":",
"raise",
"ValueError",
"(... | Setup the pool parameters like number of workers and output queue size | [
"Setup",
"the",
"pool",
"parameters",
"like",
"number",
"of",
"workers",
"and",
"output",
"queue",
"size"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L104-L112 | train | Setup the pool parameters like number of workers and output queue size |
gtsystem/parallelpipe | parallelpipe.py | Stage.processes | def processes(self):
"""Initialise and return the list of processes associated with this pool"""
if self._processes is None:
self._processes = []
for p in range(self.workers):
t = Task(self._target, self._args, self._kwargs)
t.name = "%s-%d" % (sel... | python | def processes(self):
"""Initialise and return the list of processes associated with this pool"""
if self._processes is None:
self._processes = []
for p in range(self.workers):
t = Task(self._target, self._args, self._kwargs)
t.name = "%s-%d" % (sel... | [
"def",
"processes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_processes",
"is",
"None",
":",
"self",
".",
"_processes",
"=",
"[",
"]",
"for",
"p",
"in",
"range",
"(",
"self",
".",
"workers",
")",
":",
"t",
"=",
"Task",
"(",
"self",
".",
"_targe... | Initialise and return the list of processes associated with this pool | [
"Initialise",
"and",
"return",
"the",
"list",
"of",
"processes",
"associated",
"with",
"this",
"pool"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L115-L124 | train | Initialise and return the list of processes associated with this pool |
gtsystem/parallelpipe | parallelpipe.py | Stage.set_in | def set_in(self, que_in, num_senders):
"""Set the queue in input and the number of parallel tasks that send inputs"""
for p in self.processes:
p.set_in(que_in, num_senders) | python | def set_in(self, que_in, num_senders):
"""Set the queue in input and the number of parallel tasks that send inputs"""
for p in self.processes:
p.set_in(que_in, num_senders) | [
"def",
"set_in",
"(",
"self",
",",
"que_in",
",",
"num_senders",
")",
":",
"for",
"p",
"in",
"self",
".",
"processes",
":",
"p",
".",
"set_in",
"(",
"que_in",
",",
"num_senders",
")"
] | Set the queue in input and the number of parallel tasks that send inputs | [
"Set",
"the",
"queue",
"in",
"input",
"and",
"the",
"number",
"of",
"parallel",
"tasks",
"that",
"send",
"inputs"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L126-L129 | train | Set the queue in input and the number of parallel tasks that send inputs |
gtsystem/parallelpipe | parallelpipe.py | Stage.set_out | def set_out(self, que_out, num_followers):
"""Set the queue in output and the number of parallel tasks that follow"""
for p in self.processes:
p.set_out(que_out, num_followers) | python | def set_out(self, que_out, num_followers):
"""Set the queue in output and the number of parallel tasks that follow"""
for p in self.processes:
p.set_out(que_out, num_followers) | [
"def",
"set_out",
"(",
"self",
",",
"que_out",
",",
"num_followers",
")",
":",
"for",
"p",
"in",
"self",
".",
"processes",
":",
"p",
".",
"set_out",
"(",
"que_out",
",",
"num_followers",
")"
] | Set the queue in output and the number of parallel tasks that follow | [
"Set",
"the",
"queue",
"in",
"output",
"and",
"the",
"number",
"of",
"parallel",
"tasks",
"that",
"follow"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L131-L134 | train | Set the queue in output and the number of parallel tasks that follow |
gtsystem/parallelpipe | parallelpipe.py | Pipeline.results | def results(self):
"""Start all the tasks and return data on an iterator"""
tt = None
for i, tf in enumerate(self[:-1]):
tt = self[i+1]
q = Queue(tf.qsize)
tf.set_out(q, tt.workers)
tt.set_in(q, tf.workers)
if tt is None: # we have only on... | python | def results(self):
"""Start all the tasks and return data on an iterator"""
tt = None
for i, tf in enumerate(self[:-1]):
tt = self[i+1]
q = Queue(tf.qsize)
tf.set_out(q, tt.workers)
tt.set_in(q, tf.workers)
if tt is None: # we have only on... | [
"def",
"results",
"(",
"self",
")",
":",
"tt",
"=",
"None",
"for",
"i",
",",
"tf",
"in",
"enumerate",
"(",
"self",
"[",
":",
"-",
"1",
"]",
")",
":",
"tt",
"=",
"self",
"[",
"i",
"+",
"1",
"]",
"q",
"=",
"Queue",
"(",
"tf",
".",
"qsize",
... | Start all the tasks and return data on an iterator | [
"Start",
"all",
"the",
"tasks",
"and",
"return",
"data",
"on",
"an",
"iterator"
] | b10eba28de6019cbf34e08ac575d31a4c493b39c | https://github.com/gtsystem/parallelpipe/blob/b10eba28de6019cbf34e08ac575d31a4c493b39c/parallelpipe.py#L215-L249 | train | Start all the tasks and return data on an iterator |
The-Politico/politico-civic-election-night | electionnight/managers/page_content.py | PageContentManager.office_content | def office_content(self, election_day, office):
"""
Return serialized content for an office page.
"""
from electionnight.models import PageType
office_type = ContentType.objects.get_for_model(office)
page_type = PageType.objects.get(
model_type=office_type,
... | python | def office_content(self, election_day, office):
"""
Return serialized content for an office page.
"""
from electionnight.models import PageType
office_type = ContentType.objects.get_for_model(office)
page_type = PageType.objects.get(
model_type=office_type,
... | [
"def",
"office_content",
"(",
"self",
",",
"election_day",
",",
"office",
")",
":",
"from",
"electionnight",
".",
"models",
"import",
"PageType",
"office_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"office",
")",
"page_type",
"=",
"Pa... | Return serialized content for an office page. | [
"Return",
"serialized",
"content",
"for",
"an",
"office",
"page",
"."
] | a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6 | https://github.com/The-Politico/politico-civic-election-night/blob/a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6/electionnight/managers/page_content.py#L17-L44 | train | Return serialized content for an office page. |
The-Politico/politico-civic-election-night | electionnight/managers/page_content.py | PageContentManager.body_content | def body_content(self, election_day, body, division=None):
"""
Return serialized content for a body page.
"""
from electionnight.models import PageType
body_type = ContentType.objects.get_for_model(body)
page_type = PageType.objects.get(
model_type=body_type,... | python | def body_content(self, election_day, body, division=None):
"""
Return serialized content for a body page.
"""
from electionnight.models import PageType
body_type = ContentType.objects.get_for_model(body)
page_type = PageType.objects.get(
model_type=body_type,... | [
"def",
"body_content",
"(",
"self",
",",
"election_day",
",",
"body",
",",
"division",
"=",
"None",
")",
":",
"from",
"electionnight",
".",
"models",
"import",
"PageType",
"body_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"body",
")... | Return serialized content for a body page. | [
"Return",
"serialized",
"content",
"for",
"a",
"body",
"page",
"."
] | a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6 | https://github.com/The-Politico/politico-civic-election-night/blob/a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6/electionnight/managers/page_content.py#L46-L83 | train | Return serialized content for a body page. |
The-Politico/politico-civic-election-night | electionnight/managers/page_content.py | PageContentManager.division_content | def division_content(self, election_day, division, special=False):
"""
Return serialized content for a division page.
"""
from electionnight.models import PageType
division_type = ContentType.objects.get_for_model(division)
page_type = PageType.objects.get(
m... | python | def division_content(self, election_day, division, special=False):
"""
Return serialized content for a division page.
"""
from electionnight.models import PageType
division_type = ContentType.objects.get_for_model(division)
page_type = PageType.objects.get(
m... | [
"def",
"division_content",
"(",
"self",
",",
"election_day",
",",
"division",
",",
"special",
"=",
"False",
")",
":",
"from",
"electionnight",
".",
"models",
"import",
"PageType",
"division_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
... | Return serialized content for a division page. | [
"Return",
"serialized",
"content",
"for",
"a",
"division",
"page",
"."
] | a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6 | https://github.com/The-Politico/politico-civic-election-night/blob/a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6/electionnight/managers/page_content.py#L85-L112 | train | Return serialized content for a division page. |
The-Politico/politico-civic-election-night | electionnight/managers/page_content.py | PageContentManager.site_content | def site_content(self, election_day):
"""
Site content represents content for the entire site on a
given election day.
"""
from electionnight.models import PageType
page_type = PageType.objects.get(
model_type=ContentType.objects.get(
app_labe... | python | def site_content(self, election_day):
"""
Site content represents content for the entire site on a
given election day.
"""
from electionnight.models import PageType
page_type = PageType.objects.get(
model_type=ContentType.objects.get(
app_labe... | [
"def",
"site_content",
"(",
"self",
",",
"election_day",
")",
":",
"from",
"electionnight",
".",
"models",
"import",
"PageType",
"page_type",
"=",
"PageType",
".",
"objects",
".",
"get",
"(",
"model_type",
"=",
"ContentType",
".",
"objects",
".",
"get",
"(",... | Site content represents content for the entire site on a
given election day. | [
"Site",
"content",
"represents",
"content",
"for",
"the",
"entire",
"site",
"on",
"a",
"given",
"election",
"day",
"."
] | a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6 | https://github.com/The-Politico/politico-civic-election-night/blob/a8aaf5be43872a7b84d2b0d7c2b6151d32d4d8b6/electionnight/managers/page_content.py#L114-L132 | train | Return a dictionary of site content for the entire site on an election day. |
mardix/Juice | juice/core.py | get_env | def get_env():
"""
Return the Capitalize environment name
It can be used to retrieve class base config
Default: Development
:returns: str
"""
env = "Development"
if _env_key in os.environ:
env = os.environ[_env_key].lower().capitalize()
return env | python | def get_env():
"""
Return the Capitalize environment name
It can be used to retrieve class base config
Default: Development
:returns: str
"""
env = "Development"
if _env_key in os.environ:
env = os.environ[_env_key].lower().capitalize()
return env | [
"def",
"get_env",
"(",
")",
":",
"env",
"=",
"\"Development\"",
"if",
"_env_key",
"in",
"os",
".",
"environ",
":",
"env",
"=",
"os",
".",
"environ",
"[",
"_env_key",
"]",
".",
"lower",
"(",
")",
".",
"capitalize",
"(",
")",
"return",
"env"
] | Return the Capitalize environment name
It can be used to retrieve class base config
Default: Development
:returns: str | [
"Return",
"the",
"Capitalize",
"environment",
"name",
"It",
"can",
"be",
"used",
"to",
"retrieve",
"class",
"base",
"config",
"Default",
":",
"Development",
":",
"returns",
":",
"str"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L52-L62 | train | Returns the Capitalize environment name |
mardix/Juice | juice/core.py | init_app | def init_app(kls):
"""
To bind middlewares, plugins that needs the 'app' object to init
Bound middlewares will be assigned on cls.init()
"""
if not hasattr(kls, "__call__"):
raise TypeError("init_app: '%s' is not callable" % kls)
View._init_apps.add(kls)
return kls | python | def init_app(kls):
"""
To bind middlewares, plugins that needs the 'app' object to init
Bound middlewares will be assigned on cls.init()
"""
if not hasattr(kls, "__call__"):
raise TypeError("init_app: '%s' is not callable" % kls)
View._init_apps.add(kls)
return kls | [
"def",
"init_app",
"(",
"kls",
")",
":",
"if",
"not",
"hasattr",
"(",
"kls",
",",
"\"__call__\"",
")",
":",
"raise",
"TypeError",
"(",
"\"init_app: '%s' is not callable\"",
"%",
"kls",
")",
"View",
".",
"_init_apps",
".",
"add",
"(",
"kls",
")",
"return",
... | To bind middlewares, plugins that needs the 'app' object to init
Bound middlewares will be assigned on cls.init() | [
"To",
"bind",
"middlewares",
"plugins",
"that",
"needs",
"the",
"app",
"object",
"to",
"init",
"Bound",
"middlewares",
"will",
"be",
"assigned",
"on",
"cls",
".",
"init",
"()"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L73-L81 | train | Add a function to the list of middlewares that need the app object to be used for the view |
mardix/Juice | juice/core.py | register_package | def register_package(pkg):
"""
Allow to register packages by loading and exposing: templates, static,
and exceptions for abort()
Structure of package
root
| $package_name
| __init__.py
|
| exceptions.py
|
... | python | def register_package(pkg):
"""
Allow to register packages by loading and exposing: templates, static,
and exceptions for abort()
Structure of package
root
| $package_name
| __init__.py
|
| exceptions.py
|
... | [
"def",
"register_package",
"(",
"pkg",
")",
":",
"root_pkg_dir",
"=",
"pkg",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"pkg",
")",
"and",
"\".\"",
"in",
"pkg",
":",
"root_pkg_dir",
"=",
"utils",
".",
"get_pkg_resources_filename",
"(",
"pkg",
")"... | Allow to register packages by loading and exposing: templates, static,
and exceptions for abort()
Structure of package
root
| $package_name
| __init__.py
|
| exceptions.py
|
| /templates
|
... | [
"Allow",
"to",
"register",
"packages",
"by",
"loading",
"and",
"exposing",
":",
"templates",
"static",
"and",
"exceptions",
"for",
"abort",
"()"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L84-L129 | train | Register a package with the jinja2 library. |
mardix/Juice | juice/core.py | get_interesting_members | def get_interesting_members(base_class, cls):
"""Returns a list of methods that can be routed to"""
base_members = dir(base_class)
predicate = inspect.ismethod if _py2 else inspect.isfunction
all_members = inspect.getmembers(cls, predicate=predicate)
return [member for member in all_members
... | python | def get_interesting_members(base_class, cls):
"""Returns a list of methods that can be routed to"""
base_members = dir(base_class)
predicate = inspect.ismethod if _py2 else inspect.isfunction
all_members = inspect.getmembers(cls, predicate=predicate)
return [member for member in all_members
... | [
"def",
"get_interesting_members",
"(",
"base_class",
",",
"cls",
")",
":",
"base_members",
"=",
"dir",
"(",
"base_class",
")",
"predicate",
"=",
"inspect",
".",
"ismethod",
"if",
"_py2",
"else",
"inspect",
".",
"isfunction",
"all_members",
"=",
"inspect",
".",... | Returns a list of methods that can be routed to | [
"Returns",
"a",
"list",
"of",
"methods",
"that",
"can",
"be",
"routed",
"to"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L688-L699 | train | Returns a list of methods that can be routed to cls |
mardix/Juice | juice/core.py | CustomAborter.map_from_module | def map_from_module(self, module):
"""
Map all classes the in $module with subclasses of exceptions.HTTPException
to be called as as error in with abort()
:param obj:
:return:
"""
maps = {}
for name in dir(module):
obj = getattr(module, name)
... | python | def map_from_module(self, module):
"""
Map all classes the in $module with subclasses of exceptions.HTTPException
to be called as as error in with abort()
:param obj:
:return:
"""
maps = {}
for name in dir(module):
obj = getattr(module, name)
... | [
"def",
"map_from_module",
"(",
"self",
",",
"module",
")",
":",
"maps",
"=",
"{",
"}",
"for",
"name",
"in",
"dir",
"(",
"module",
")",
":",
"obj",
"=",
"getattr",
"(",
"module",
",",
"name",
")",
"try",
":",
"if",
"issubclass",
"(",
"obj",
",",
"... | Map all classes the in $module with subclasses of exceptions.HTTPException
to be called as as error in with abort()
:param obj:
:return: | [
"Map",
"all",
"classes",
"the",
"in",
"$module",
"with",
"subclasses",
"of",
"exceptions",
".",
"HTTPException",
"to",
"be",
"called",
"as",
"as",
"error",
"in",
"with",
"abort",
"()",
":",
"param",
"obj",
":",
":",
"return",
":"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L169-L184 | train | Maps all classes in the given module with subclasses of exceptions. HTTPException
to be called as error in with abort |
mardix/Juice | juice/core.py | FlaskView.register | def register(cls, app, base_route=None, subdomain=None, route_prefix=None,
trailing_slash=None):
"""Registers a FlaskView class for use with a specific instance of a
Flask app. Any methods not prefixes with an underscore are candidates
to be routed and will have routes registere... | python | def register(cls, app, base_route=None, subdomain=None, route_prefix=None,
trailing_slash=None):
"""Registers a FlaskView class for use with a specific instance of a
Flask app. Any methods not prefixes with an underscore are candidates
to be routed and will have routes registere... | [
"def",
"register",
"(",
"cls",
",",
"app",
",",
"base_route",
"=",
"None",
",",
"subdomain",
"=",
"None",
",",
"route_prefix",
"=",
"None",
",",
"trailing_slash",
"=",
"None",
")",
":",
"if",
"cls",
"is",
"FlaskView",
":",
"raise",
"TypeError",
"(",
"\... | Registers a FlaskView class for use with a specific instance of a
Flask app. Any methods not prefixes with an underscore are candidates
to be routed and will have routes registered when this method is
called.
:param app: an instance of a Flask application
:param base_route: The... | [
"Registers",
"a",
"FlaskView",
"class",
"for",
"use",
"with",
"a",
"specific",
"instance",
"of",
"a",
"Flask",
"app",
".",
"Any",
"methods",
"not",
"prefixes",
"with",
"an",
"underscore",
"are",
"candidates",
"to",
"be",
"routed",
"and",
"will",
"have",
"r... | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L203-L313 | train | Registers a FlaskView class for use with a specific instance of a Flask application. |
mardix/Juice | juice/core.py | View.render_ | def render_(cls, data={}, template_=None, layout_=None, **kwargs):
"""
To render data to the associate template file of the action view
:param data: The context data to pass to the template
:param template_: The file template to use. By default it will map the classname/action.html
... | python | def render_(cls, data={}, template_=None, layout_=None, **kwargs):
"""
To render data to the associate template file of the action view
:param data: The context data to pass to the template
:param template_: The file template to use. By default it will map the classname/action.html
... | [
"def",
"render_",
"(",
"cls",
",",
"data",
"=",
"{",
"}",
",",
"template_",
"=",
"None",
",",
"layout_",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"template_",
":",
"stack",
"=",
"inspect",
".",
"stack",
"(",
")",
"[",
"1",
"... | To render data to the associate template file of the action view
:param data: The context data to pass to the template
:param template_: The file template to use. By default it will map the classname/action.html
:param layout_: The body layout, must contain {% include __template__ %} | [
"To",
"render",
"data",
"to",
"the",
"associate",
"template",
"file",
"of",
"the",
"action",
"view",
":",
"param",
"data",
":",
"The",
"context",
"data",
"to",
"pass",
"to",
"the",
"template",
":",
"param",
"template_",
":",
"The",
"file",
"template",
"t... | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L573-L597 | train | Render the template file of the action view
|
mardix/Juice | juice/core.py | View.meta_tags | def meta_tags(cls, **kwargs):
"""
Meta allows you to add meta data to site
:params **kwargs:
meta keys we're expecting:
title (str)
description (str)
url (str) (Will pick it up by itself if not set)
image (str)
site_name (str) ... | python | def meta_tags(cls, **kwargs):
"""
Meta allows you to add meta data to site
:params **kwargs:
meta keys we're expecting:
title (str)
description (str)
url (str) (Will pick it up by itself if not set)
image (str)
site_name (str) ... | [
"def",
"meta_tags",
"(",
"cls",
",",
"*",
"*",
"kwargs",
")",
":",
"page_meta",
"=",
"cls",
".",
"_global",
".",
"get",
"(",
"\"__META__\"",
",",
"{",
"}",
")",
"page_meta",
".",
"update",
"(",
"*",
"*",
"kwargs",
")",
"cls",
".",
"g",
"(",
"__ME... | Meta allows you to add meta data to site
:params **kwargs:
meta keys we're expecting:
title (str)
description (str)
url (str) (Will pick it up by itself if not set)
image (str)
site_name (str) (but can pick it up from config file)
... | [
"Meta",
"allows",
"you",
"to",
"add",
"meta",
"data",
"to",
"site",
":",
"params",
"**",
"kwargs",
":"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L600-L624 | train | Meta allows you to add meta data to site s meta tags. |
mardix/Juice | juice/core.py | View.get_config | def get_config(cls, key, default=None):
"""
Shortcut to access the application's config in your class
:param key: The key to access
:param default: The default value when None
:returns mixed:
"""
return cls._app.config.get(key, default) | python | def get_config(cls, key, default=None):
"""
Shortcut to access the application's config in your class
:param key: The key to access
:param default: The default value when None
:returns mixed:
"""
return cls._app.config.get(key, default) | [
"def",
"get_config",
"(",
"cls",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"return",
"cls",
".",
"_app",
".",
"config",
".",
"get",
"(",
"key",
",",
"default",
")"
] | Shortcut to access the application's config in your class
:param key: The key to access
:param default: The default value when None
:returns mixed: | [
"Shortcut",
"to",
"access",
"the",
"application",
"s",
"config",
"in",
"your",
"class",
":",
"param",
"key",
":",
"The",
"key",
"to",
"access",
":",
"param",
"default",
":",
"The",
"default",
"value",
"when",
"None",
":",
"returns",
"mixed",
":"
] | 7afa8d4238868235dfcdae82272bd77958dd416a | https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/core.py#L628-L635 | train | Shortcut to access the application s config in your class
|
BrianHicks/tinyobj | tinyobj/fields.py | Field.initialize | def initialize(self, value=()):
"""\
initialize returns a cleaned value or the default, raising ValueErrors
as necessary.
"""
if value == ():
try:
return self.default()
except TypeError:
return self.default
else:
... | python | def initialize(self, value=()):
"""\
initialize returns a cleaned value or the default, raising ValueErrors
as necessary.
"""
if value == ():
try:
return self.default()
except TypeError:
return self.default
else:
... | [
"def",
"initialize",
"(",
"self",
",",
"value",
"=",
"(",
")",
")",
":",
"if",
"value",
"==",
"(",
")",
":",
"try",
":",
"return",
"self",
".",
"default",
"(",
")",
"except",
"TypeError",
":",
"return",
"self",
".",
"default",
"else",
":",
"return"... | \
initialize returns a cleaned value or the default, raising ValueErrors
as necessary. | [
"\\",
"initialize",
"returns",
"a",
"cleaned",
"value",
"or",
"the",
"default",
"raising",
"ValueErrors",
"as",
"necessary",
"."
] | c1ea7a007d70c2b815b4879d383af3825c74e7e8 | https://github.com/BrianHicks/tinyobj/blob/c1ea7a007d70c2b815b4879d383af3825c74e7e8/tinyobj/fields.py#L10-L21 | train | \ initialize returns a cleaned value or the default value raising ValueErrors
as necessary. |
BrianHicks/tinyobj | tinyobj/fields.py | NumberField.clean | def clean(self, value):
"""clean a value, converting and performing bounds checking"""
if not isinstance(value, self.t):
value = self.t(value)
if not self.allow_negative and value < 0:
raise ValueError('value was negative')
if not self.allow_positive and value >... | python | def clean(self, value):
"""clean a value, converting and performing bounds checking"""
if not isinstance(value, self.t):
value = self.t(value)
if not self.allow_negative and value < 0:
raise ValueError('value was negative')
if not self.allow_positive and value >... | [
"def",
"clean",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"self",
".",
"t",
")",
":",
"value",
"=",
"self",
".",
"t",
"(",
"value",
")",
"if",
"not",
"self",
".",
"allow_negative",
"and",
"value",
"<",
"0"... | clean a value, converting and performing bounds checking | [
"clean",
"a",
"value",
"converting",
"and",
"performing",
"bounds",
"checking"
] | c1ea7a007d70c2b815b4879d383af3825c74e7e8 | https://github.com/BrianHicks/tinyobj/blob/c1ea7a007d70c2b815b4879d383af3825c74e7e8/tinyobj/fields.py#L40-L51 | train | clean a value converting and performing bounds checking |
adamheins/r12 | r12/arm.py | r12_serial_port | def r12_serial_port(port):
''' Create a serial connect to the arm. '''
return serial.Serial(port, baudrate=BAUD_RATE, parity=PARITY,
stopbits=STOP_BITS, bytesize=BYTE_SIZE) | python | def r12_serial_port(port):
''' Create a serial connect to the arm. '''
return serial.Serial(port, baudrate=BAUD_RATE, parity=PARITY,
stopbits=STOP_BITS, bytesize=BYTE_SIZE) | [
"def",
"r12_serial_port",
"(",
"port",
")",
":",
"return",
"serial",
".",
"Serial",
"(",
"port",
",",
"baudrate",
"=",
"BAUD_RATE",
",",
"parity",
"=",
"PARITY",
",",
"stopbits",
"=",
"STOP_BITS",
",",
"bytesize",
"=",
"BYTE_SIZE",
")"
] | Create a serial connect to the arm. | [
"Create",
"a",
"serial",
"connect",
"to",
"the",
"arm",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L36-L39 | train | Create a serial connection to the arm. |
adamheins/r12 | r12/arm.py | search_for_port | def search_for_port(port_glob, req, expected_res):
''' Find the serial port the arm is connected to. '''
# Check that the USB port actually exists, based on the known vendor and
# product ID.
if usb.core.find(idVendor=0x0403, idProduct=0x6001) is None:
return None
# Find ports matching the... | python | def search_for_port(port_glob, req, expected_res):
''' Find the serial port the arm is connected to. '''
# Check that the USB port actually exists, based on the known vendor and
# product ID.
if usb.core.find(idVendor=0x0403, idProduct=0x6001) is None:
return None
# Find ports matching the... | [
"def",
"search_for_port",
"(",
"port_glob",
",",
"req",
",",
"expected_res",
")",
":",
"# Check that the USB port actually exists, based on the known vendor and",
"# product ID.",
"if",
"usb",
".",
"core",
".",
"find",
"(",
"idVendor",
"=",
"0x0403",
",",
"idProduct",
... | Find the serial port the arm is connected to. | [
"Find",
"the",
"serial",
"port",
"the",
"arm",
"is",
"connected",
"to",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L42-L76 | train | Search for a USB port in the system. |
adamheins/r12 | r12/arm.py | Arm.connect | def connect(self, port=None):
''' Open a serial connection to the arm. '''
if port is None:
self.port = search_for_port('/dev/ttyUSB*', 'ROBOFORTH\r\n',
'ROBOFORTH')
else:
self.port = port
if self.port is None:
... | python | def connect(self, port=None):
''' Open a serial connection to the arm. '''
if port is None:
self.port = search_for_port('/dev/ttyUSB*', 'ROBOFORTH\r\n',
'ROBOFORTH')
else:
self.port = port
if self.port is None:
... | [
"def",
"connect",
"(",
"self",
",",
"port",
"=",
"None",
")",
":",
"if",
"port",
"is",
"None",
":",
"self",
".",
"port",
"=",
"search_for_port",
"(",
"'/dev/ttyUSB*'",
",",
"'ROBOFORTH\\r\\n'",
",",
"'ROBOFORTH'",
")",
"else",
":",
"self",
".",
"port",
... | Open a serial connection to the arm. | [
"Open",
"a",
"serial",
"connection",
"to",
"the",
"arm",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L97-L116 | train | Open a serial connection to the arm. |
adamheins/r12 | r12/arm.py | Arm.write | def write(self, text):
''' Write text out to the arm. '''
# Output is converted to bytes with Windows-style line endings.
if sys.version_info[0] == 2:
text_bytes = str(text.upper() + '\r\n').encode('utf-8')
else:
text_bytes = bytes(text.upper() + '\r\n', 'utf-8')
... | python | def write(self, text):
''' Write text out to the arm. '''
# Output is converted to bytes with Windows-style line endings.
if sys.version_info[0] == 2:
text_bytes = str(text.upper() + '\r\n').encode('utf-8')
else:
text_bytes = bytes(text.upper() + '\r\n', 'utf-8')
... | [
"def",
"write",
"(",
"self",
",",
"text",
")",
":",
"# Output is converted to bytes with Windows-style line endings.",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"==",
"2",
":",
"text_bytes",
"=",
"str",
"(",
"text",
".",
"upper",
"(",
")",
"+",
"'\\r\... | Write text out to the arm. | [
"Write",
"text",
"out",
"to",
"the",
"arm",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L126-L133 | train | Write text out to the arm. |
adamheins/r12 | r12/arm.py | Arm.read | def read(self, timeout=READ_TIMEOUT, raw=False):
''' Read data from the arm. Data is returned as a latin_1 encoded
string, or raw bytes if 'raw' is True. '''
time.sleep(READ_SLEEP_TIME)
raw_out = self.ser.read(self.ser.in_waiting)
out = raw_out.decode(OUTPUT_ENCODING)
... | python | def read(self, timeout=READ_TIMEOUT, raw=False):
''' Read data from the arm. Data is returned as a latin_1 encoded
string, or raw bytes if 'raw' is True. '''
time.sleep(READ_SLEEP_TIME)
raw_out = self.ser.read(self.ser.in_waiting)
out = raw_out.decode(OUTPUT_ENCODING)
... | [
"def",
"read",
"(",
"self",
",",
"timeout",
"=",
"READ_TIMEOUT",
",",
"raw",
"=",
"False",
")",
":",
"time",
".",
"sleep",
"(",
"READ_SLEEP_TIME",
")",
"raw_out",
"=",
"self",
".",
"ser",
".",
"read",
"(",
"self",
".",
"ser",
".",
"in_waiting",
")",
... | Read data from the arm. Data is returned as a latin_1 encoded
string, or raw bytes if 'raw' is True. | [
"Read",
"data",
"from",
"the",
"arm",
".",
"Data",
"is",
"returned",
"as",
"a",
"latin_1",
"encoded",
"string",
"or",
"raw",
"bytes",
"if",
"raw",
"is",
"True",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L136-L157 | train | Read data from the arm. |
adamheins/r12 | r12/arm.py | Arm.dump | def dump(self, raw=False):
''' Dump all output currently in the arm's output queue. '''
raw_out = self.ser.read(self.ser.in_waiting)
if raw:
return raw_out
return raw_out.decode(OUTPUT_ENCODING) | python | def dump(self, raw=False):
''' Dump all output currently in the arm's output queue. '''
raw_out = self.ser.read(self.ser.in_waiting)
if raw:
return raw_out
return raw_out.decode(OUTPUT_ENCODING) | [
"def",
"dump",
"(",
"self",
",",
"raw",
"=",
"False",
")",
":",
"raw_out",
"=",
"self",
".",
"ser",
".",
"read",
"(",
"self",
".",
"ser",
".",
"in_waiting",
")",
"if",
"raw",
":",
"return",
"raw_out",
"return",
"raw_out",
".",
"decode",
"(",
"OUTPU... | Dump all output currently in the arm's output queue. | [
"Dump",
"all",
"output",
"currently",
"in",
"the",
"arm",
"s",
"output",
"queue",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L160-L165 | train | Dump all output currently in the arm s output queue. |
adamheins/r12 | r12/arm.py | Arm.get_info | def get_info(self):
''' Returns status of the robot arm. '''
return {
'Connected': self.is_connected(),
'Port': self.port,
'Bytes Waiting': self.ser.in_waiting if self.ser else 0
} | python | def get_info(self):
''' Returns status of the robot arm. '''
return {
'Connected': self.is_connected(),
'Port': self.port,
'Bytes Waiting': self.ser.in_waiting if self.ser else 0
} | [
"def",
"get_info",
"(",
"self",
")",
":",
"return",
"{",
"'Connected'",
":",
"self",
".",
"is_connected",
"(",
")",
",",
"'Port'",
":",
"self",
".",
"port",
",",
"'Bytes Waiting'",
":",
"self",
".",
"ser",
".",
"in_waiting",
"if",
"self",
".",
"ser",
... | Returns status of the robot arm. | [
"Returns",
"status",
"of",
"the",
"robot",
"arm",
"."
] | ff78178332140930bf46a94a0b15ee082bb92491 | https://github.com/adamheins/r12/blob/ff78178332140930bf46a94a0b15ee082bb92491/r12/arm.py#L173-L179 | train | Returns status of the robot arm. |
fabaff/python-opensensemap-api | opensensemap_api/__init__.py | OpenSenseMap.get_data | async def get_data(self):
"""Get details of OpenSenseMap station."""
try:
async with async_timeout.timeout(5, loop=self._loop):
response = await self._session.get(self.base_url)
_LOGGER.info(
"Response from OpenSenseMap API: %s", response.status)
... | python | async def get_data(self):
"""Get details of OpenSenseMap station."""
try:
async with async_timeout.timeout(5, loop=self._loop):
response = await self._session.get(self.base_url)
_LOGGER.info(
"Response from OpenSenseMap API: %s", response.status)
... | [
"async",
"def",
"get_data",
"(",
"self",
")",
":",
"try",
":",
"async",
"with",
"async_timeout",
".",
"timeout",
"(",
"5",
",",
"loop",
"=",
"self",
".",
"_loop",
")",
":",
"response",
"=",
"await",
"self",
".",
"_session",
".",
"get",
"(",
"self",
... | Get details of OpenSenseMap station. | [
"Get",
"details",
"of",
"OpenSenseMap",
"station",
"."
] | 3c4f5473c514185087aae5d766ab4d5736ec1f30 | https://github.com/fabaff/python-opensensemap-api/blob/3c4f5473c514185087aae5d766ab4d5736ec1f30/opensensemap_api/__init__.py#L48-L61 | train | Get details of OpenSenseMap station. |
fabaff/python-opensensemap-api | opensensemap_api/__init__.py | OpenSenseMap.get_value | def get_value(self, key):
"""Extract a value for a given key."""
for title in _TITLES.get(key, ()) + (key,):
try:
value = [entry['lastMeasurement']['value'] for entry in
self.data['sensors'] if entry['title'] == title][0]
return value
... | python | def get_value(self, key):
"""Extract a value for a given key."""
for title in _TITLES.get(key, ()) + (key,):
try:
value = [entry['lastMeasurement']['value'] for entry in
self.data['sensors'] if entry['title'] == title][0]
return value
... | [
"def",
"get_value",
"(",
"self",
",",
"key",
")",
":",
"for",
"title",
"in",
"_TITLES",
".",
"get",
"(",
"key",
",",
"(",
")",
")",
"+",
"(",
"key",
",",
")",
":",
"try",
":",
"value",
"=",
"[",
"entry",
"[",
"'lastMeasurement'",
"]",
"[",
"'va... | Extract a value for a given key. | [
"Extract",
"a",
"value",
"for",
"a",
"given",
"key",
"."
] | 3c4f5473c514185087aae5d766ab4d5736ec1f30 | https://github.com/fabaff/python-opensensemap-api/blob/3c4f5473c514185087aae5d766ab4d5736ec1f30/opensensemap_api/__init__.py#L123-L132 | train | Extract a value for a given key. |
tjcsl/cslbot | cslbot/commands/note.py | cmd | def cmd(send, msg, args):
"""Leaves a note for a user or users.
Syntax: {command} <nick>[,nick2,...] <note>
"""
if not args['config']['feature'].getboolean('hooks'):
send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).")
return
if args['type... | python | def cmd(send, msg, args):
"""Leaves a note for a user or users.
Syntax: {command} <nick>[,nick2,...] <note>
"""
if not args['config']['feature'].getboolean('hooks'):
send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).")
return
if args['type... | [
"def",
"cmd",
"(",
"send",
",",
"msg",
",",
"args",
")",
":",
"if",
"not",
"args",
"[",
"'config'",
"]",
"[",
"'feature'",
"]",
".",
"getboolean",
"(",
"'hooks'",
")",
":",
"send",
"(",
"\"Hooks are disabled, and this command depends on hooks. Please contact the... | Leaves a note for a user or users.
Syntax: {command} <nick>[,nick2,...] <note> | [
"Leaves",
"a",
"note",
"for",
"a",
"user",
"or",
"users",
"."
] | aebe07be47141f61d7c180706bddfb707f19b2b5 | https://github.com/tjcsl/cslbot/blob/aebe07be47141f61d7c180706bddfb707f19b2b5/cslbot/commands/note.py#L26-L57 | train | Leaves a note for a user or users. |
ktdreyer/txkoji | txkoji/messages.py | BuildStateChange.from_frame | def from_frame(klass, frame, connection):
"""
Create a new BuildStateChange event from a Stompest Frame.
"""
event = frame.headers['new']
data = json.loads(frame.body)
info = data['info']
build = Build.fromDict(info)
build.connection = connection
r... | python | def from_frame(klass, frame, connection):
"""
Create a new BuildStateChange event from a Stompest Frame.
"""
event = frame.headers['new']
data = json.loads(frame.body)
info = data['info']
build = Build.fromDict(info)
build.connection = connection
r... | [
"def",
"from_frame",
"(",
"klass",
",",
"frame",
",",
"connection",
")",
":",
"event",
"=",
"frame",
".",
"headers",
"[",
"'new'",
"]",
"data",
"=",
"json",
".",
"loads",
"(",
"frame",
".",
"body",
")",
"info",
"=",
"data",
"[",
"'info'",
"]",
"bui... | Create a new BuildStateChange event from a Stompest Frame. | [
"Create",
"a",
"new",
"BuildStateChange",
"event",
"from",
"a",
"Stompest",
"Frame",
"."
] | a7de380f29f745bf11730b27217208f6d4da7733 | https://github.com/ktdreyer/txkoji/blob/a7de380f29f745bf11730b27217208f6d4da7733/txkoji/messages.py#L31-L40 | train | Create a new BuildStateChange event from a Stompest Frame. |
ktdreyer/txkoji | txkoji/messages.py | TaskStateChange.from_frame | def from_frame(klass, frame, connection):
"""
Create a new TaskStateChange event from a Stompest Frame.
"""
event = frame.headers['new']
data = json.loads(frame.body)
info = data['info']
task = Task.fromDict(info)
task.connection = connection
retur... | python | def from_frame(klass, frame, connection):
"""
Create a new TaskStateChange event from a Stompest Frame.
"""
event = frame.headers['new']
data = json.loads(frame.body)
info = data['info']
task = Task.fromDict(info)
task.connection = connection
retur... | [
"def",
"from_frame",
"(",
"klass",
",",
"frame",
",",
"connection",
")",
":",
"event",
"=",
"frame",
".",
"headers",
"[",
"'new'",
"]",
"data",
"=",
"json",
".",
"loads",
"(",
"frame",
".",
"body",
")",
"info",
"=",
"data",
"[",
"'info'",
"]",
"tas... | Create a new TaskStateChange event from a Stompest Frame. | [
"Create",
"a",
"new",
"TaskStateChange",
"event",
"from",
"a",
"Stompest",
"Frame",
"."
] | a7de380f29f745bf11730b27217208f6d4da7733 | https://github.com/ktdreyer/txkoji/blob/a7de380f29f745bf11730b27217208f6d4da7733/txkoji/messages.py#L60-L69 | train | Create a new TaskStateChange event from a Stompest Frame. |
ktdreyer/txkoji | txkoji/messages.py | TaskStateChange.tag | def tag(self):
""" Return a (deferred) cached Koji tag name for this change. """
name_or_id = self.task.tag
if name_or_id is None:
return defer.succeed(None)
if isinstance(name_or_id, StringType):
return defer.succeed(name_or_id)
if isinstance(name_or_id, ... | python | def tag(self):
""" Return a (deferred) cached Koji tag name for this change. """
name_or_id = self.task.tag
if name_or_id is None:
return defer.succeed(None)
if isinstance(name_or_id, StringType):
return defer.succeed(name_or_id)
if isinstance(name_or_id, ... | [
"def",
"tag",
"(",
"self",
")",
":",
"name_or_id",
"=",
"self",
".",
"task",
".",
"tag",
"if",
"name_or_id",
"is",
"None",
":",
"return",
"defer",
".",
"succeed",
"(",
"None",
")",
"if",
"isinstance",
"(",
"name_or_id",
",",
"StringType",
")",
":",
"... | Return a (deferred) cached Koji tag name for this change. | [
"Return",
"a",
"(",
"deferred",
")",
"cached",
"Koji",
"tag",
"name",
"for",
"this",
"change",
"."
] | a7de380f29f745bf11730b27217208f6d4da7733 | https://github.com/ktdreyer/txkoji/blob/a7de380f29f745bf11730b27217208f6d4da7733/txkoji/messages.py#L71-L80 | train | Return a deferred that will be fulfilled when the Koji tag is changed. |
ktdreyer/txkoji | txkoji/messages.py | TaskStateChange.user | def user(self):
""" Return a (deferred) cached Koji user name for this change. """
# Note, do any tasks really have an "owner_id", or are they all
# "owner"?
owner_id = getattr(self.task, 'owner_id', self.task.owner)
return self.task.connection.cache.user_name(owner_id) | python | def user(self):
""" Return a (deferred) cached Koji user name for this change. """
# Note, do any tasks really have an "owner_id", or are they all
# "owner"?
owner_id = getattr(self.task, 'owner_id', self.task.owner)
return self.task.connection.cache.user_name(owner_id) | [
"def",
"user",
"(",
"self",
")",
":",
"# Note, do any tasks really have an \"owner_id\", or are they all",
"# \"owner\"?",
"owner_id",
"=",
"getattr",
"(",
"self",
".",
"task",
",",
"'owner_id'",
",",
"self",
".",
"task",
".",
"owner",
")",
"return",
"self",
".",
... | Return a (deferred) cached Koji user name for this change. | [
"Return",
"a",
"(",
"deferred",
")",
"cached",
"Koji",
"user",
"name",
"for",
"this",
"change",
"."
] | a7de380f29f745bf11730b27217208f6d4da7733 | https://github.com/ktdreyer/txkoji/blob/a7de380f29f745bf11730b27217208f6d4da7733/txkoji/messages.py#L87-L92 | train | Return a deferred user name for this change. |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.add_raw | def add_raw(self, raw):
"""
Adds row aggregation state at the query
:param raw: list of raw stages or a dict of raw stage
:return: The current object
"""
if type(raw) == list:
self._q += raw
if type(raw) == dict:
self._q.append(raw)
... | python | def add_raw(self, raw):
"""
Adds row aggregation state at the query
:param raw: list of raw stages or a dict of raw stage
:return: The current object
"""
if type(raw) == list:
self._q += raw
if type(raw) == dict:
self._q.append(raw)
... | [
"def",
"add_raw",
"(",
"self",
",",
"raw",
")",
":",
"if",
"type",
"(",
"raw",
")",
"==",
"list",
":",
"self",
".",
"_q",
"+=",
"raw",
"if",
"type",
"(",
"raw",
")",
"==",
"dict",
":",
"self",
".",
"_q",
".",
"append",
"(",
"raw",
")",
"retur... | Adds row aggregation state at the query
:param raw: list of raw stages or a dict of raw stage
:return: The current object | [
"Adds",
"row",
"aggregation",
"state",
"at",
"the",
"query",
":",
"param",
"raw",
":",
"list",
"of",
"raw",
"stages",
"or",
"a",
"dict",
"of",
"raw",
"stage",
":",
"return",
":",
"The",
"current",
"object"
] | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L24-L34 | train | Adds row aggregation state at the query
|
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.project | def project(self, id=None, *args, **kwargs):
"""
Adds a projection stage at the query
:param id: Specifies if the id is in selected fields default value is None
:param args: The list of the fields that will be project
:param kwargs: The fields that will be generated
:retu... | python | def project(self, id=None, *args, **kwargs):
"""
Adds a projection stage at the query
:param id: Specifies if the id is in selected fields default value is None
:param args: The list of the fields that will be project
:param kwargs: The fields that will be generated
:retu... | [
"def",
"project",
"(",
"self",
",",
"id",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"projection",
"=",
"{",
"}",
"if",
"id",
"is",
"not",
"None",
":",
"projection",
"[",
"'_id'",
"]",
"=",
"id",
"for",
"arg",
"in",
"args... | Adds a projection stage at the query
:param id: Specifies if the id is in selected fields default value is None
:param args: The list of the fields that will be project
:param kwargs: The fields that will be generated
:return: | [
"Adds",
"a",
"projection",
"stage",
"at",
"the",
"query",
":",
"param",
"id",
":",
"Specifies",
"if",
"the",
"id",
"is",
"in",
"selected",
"fields",
"default",
"value",
"is",
"None",
":",
"param",
"args",
":",
"The",
"list",
"of",
"the",
"fields",
"tha... | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L54-L77 | train | Adds a projection stage at the query
|
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.match | def match(self, query_dict=None, **query):
"""
Adds a match stage at the query
:param query_dict: The params as dict
:param query: The parameters of the query
:return: The current object
"""
if query_dict:
self._q.append({'$match': query_dict})
... | python | def match(self, query_dict=None, **query):
"""
Adds a match stage at the query
:param query_dict: The params as dict
:param query: The parameters of the query
:return: The current object
"""
if query_dict:
self._q.append({'$match': query_dict})
... | [
"def",
"match",
"(",
"self",
",",
"query_dict",
"=",
"None",
",",
"*",
"*",
"query",
")",
":",
"if",
"query_dict",
":",
"self",
".",
"_q",
".",
"append",
"(",
"{",
"'$match'",
":",
"query_dict",
"}",
")",
"else",
":",
"self",
".",
"_q",
".",
"app... | Adds a match stage at the query
:param query_dict: The params as dict
:param query: The parameters of the query
:return: The current object | [
"Adds",
"a",
"match",
"stage",
"at",
"the",
"query",
":",
"param",
"query_dict",
":",
"The",
"params",
"as",
"dict",
":",
"param",
"query",
":",
"The",
"parameters",
"of",
"the",
"query",
":",
"return",
":",
"The",
"current",
"object"
] | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L79-L90 | train | Adds a match stage at the query
|
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.group | def group(self, id=None, **kwargs):
"""
Adds a group stage at aggregation query
:param id: The group id. Default value is None and group merge all documents
:param kwargs: The parameters-methods of group stage
:return: The current object
"""
if type(id) == str:
... | python | def group(self, id=None, **kwargs):
"""
Adds a group stage at aggregation query
:param id: The group id. Default value is None and group merge all documents
:param kwargs: The parameters-methods of group stage
:return: The current object
"""
if type(id) == str:
... | [
"def",
"group",
"(",
"self",
",",
"id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"type",
"(",
"id",
")",
"==",
"str",
":",
"if",
"not",
"id",
".",
"startswith",
"(",
"'$'",
")",
":",
"id",
"=",
"'$'",
"+",
"id",
"query",
"=",
"... | Adds a group stage at aggregation query
:param id: The group id. Default value is None and group merge all documents
:param kwargs: The parameters-methods of group stage
:return: The current object | [
"Adds",
"a",
"group",
"stage",
"at",
"aggregation",
"query",
":",
"param",
"id",
":",
"The",
"group",
"id",
".",
"Default",
"value",
"is",
"None",
"and",
"group",
"merge",
"all",
"documents",
":",
"param",
"kwargs",
":",
"The",
"parameters",
"-",
"method... | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L92-L110 | train | Adds a group stage at aggregation |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.unwind | def unwind(self, path, include_array_index=None, preserve_null_and_empty_arrays=False):
"""
Adds an unwind stage to deconstruct an array
:param path: Field path to an array field
:param include_array_index: The name of a new field to hold the array index of the element.
:param pr... | python | def unwind(self, path, include_array_index=None, preserve_null_and_empty_arrays=False):
"""
Adds an unwind stage to deconstruct an array
:param path: Field path to an array field
:param include_array_index: The name of a new field to hold the array index of the element.
:param pr... | [
"def",
"unwind",
"(",
"self",
",",
"path",
",",
"include_array_index",
"=",
"None",
",",
"preserve_null_and_empty_arrays",
"=",
"False",
")",
":",
"unwind_query",
"=",
"{",
"}",
"unwind_query",
"[",
"'$unwind'",
"]",
"=",
"path",
"if",
"path",
"[",
"0",
"]... | Adds an unwind stage to deconstruct an array
:param path: Field path to an array field
:param include_array_index: The name of a new field to hold the array index of the element.
:param preserve_null_and_empty_arrays:
If true, if the path is null, missing, or an empty array, $unwind ... | [
"Adds",
"an",
"unwind",
"stage",
"to",
"deconstruct",
"an",
"array",
":",
"param",
"path",
":",
"Field",
"path",
"to",
"an",
"array",
"field",
":",
"param",
"include_array_index",
":",
"The",
"name",
"of",
"a",
"new",
"field",
"to",
"hold",
"the",
"array... | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L112-L130 | train | Adds an unwind stage to deconstruct an array of class entry entries. |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.sort | def sort(self, **kwargs):
"""
Adds a sort stage to aggregation query
:param kwargs: Specifies the field(s) to sort by and the respective sort order.
:return: The current object
"""
query = {}
for field in kwargs:
query[field] = kwargs[field]
se... | python | def sort(self, **kwargs):
"""
Adds a sort stage to aggregation query
:param kwargs: Specifies the field(s) to sort by and the respective sort order.
:return: The current object
"""
query = {}
for field in kwargs:
query[field] = kwargs[field]
se... | [
"def",
"sort",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"query",
"=",
"{",
"}",
"for",
"field",
"in",
"kwargs",
":",
"query",
"[",
"field",
"]",
"=",
"kwargs",
"[",
"field",
"]",
"self",
".",
"_q",
".",
"append",
"(",
"{",
"'$sort'",
":"... | Adds a sort stage to aggregation query
:param kwargs: Specifies the field(s) to sort by and the respective sort order.
:return: The current object | [
"Adds",
"a",
"sort",
"stage",
"to",
"aggregation",
"query",
":",
"param",
"kwargs",
":",
"Specifies",
"the",
"field",
"(",
"s",
")",
"to",
"sort",
"by",
"and",
"the",
"respective",
"sort",
"order",
".",
":",
"return",
":",
"The",
"current",
"object"
] | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L132-L142 | train | Adds a sort stage to aggregation query
|
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.look_up | def look_up(self, _from, _localField, _foreignField, _as):
"""
Adds look up stage at query (left outer join)
:param _from: Specifies the collection in the same database to perform the join with.
:param _localField: Specifies the field from the documents input to the $lookup stage.
... | python | def look_up(self, _from, _localField, _foreignField, _as):
"""
Adds look up stage at query (left outer join)
:param _from: Specifies the collection in the same database to perform the join with.
:param _localField: Specifies the field from the documents input to the $lookup stage.
... | [
"def",
"look_up",
"(",
"self",
",",
"_from",
",",
"_localField",
",",
"_foreignField",
",",
"_as",
")",
":",
"query",
"=",
"{",
"'from'",
":",
"_from",
",",
"'localField'",
":",
"_localField",
",",
"'foreignField'",
":",
"_foreignField",
",",
"'as'",
":",
... | Adds look up stage at query (left outer join)
:param _from: Specifies the collection in the same database to perform the join with.
:param _localField: Specifies the field from the documents input to the $lookup stage.
:param _foreignField: Specifies the field from the documents in the from coll... | [
"Adds",
"look",
"up",
"stage",
"at",
"query",
"(",
"left",
"outer",
"join",
")",
":",
"param",
"_from",
":",
"Specifies",
"the",
"collection",
"in",
"the",
"same",
"database",
"to",
"perform",
"the",
"join",
"with",
".",
":",
"param",
"_localField",
":",... | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L153-L169 | train | Adds a look up stage at query to add the new array field to the current object. |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.graph_look_up | def graph_look_up(self, _from, _startWith, _connectFromField, _connectToField,
_as, _maxDepth=None, _depthField=None, _restrictSearchWithMatch=None):
"""
Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.
... | python | def graph_look_up(self, _from, _startWith, _connectFromField, _connectToField,
_as, _maxDepth=None, _depthField=None, _restrictSearchWithMatch=None):
"""
Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.
... | [
"def",
"graph_look_up",
"(",
"self",
",",
"_from",
",",
"_startWith",
",",
"_connectFromField",
",",
"_connectToField",
",",
"_as",
",",
"_maxDepth",
"=",
"None",
",",
"_depthField",
"=",
"None",
",",
"_restrictSearchWithMatch",
"=",
"None",
")",
":",
"query",... | Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.
:param _from: Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField.
:param _startWith: Expression that specifie... | [
"Performs",
"a",
"recursive",
"search",
"on",
"a",
"collection",
"with",
"options",
"for",
"restricting",
"the",
"search",
"by",
"recursion",
"depth",
"and",
"query",
"filter",
".",
":",
"param",
"_from",
":",
"Target",
"collection",
"for",
"the",
"$graphLooku... | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L171-L199 | train | Perform a graph lookup operation on a collection. |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.add_fields | def add_fields(self, **fields):
"""
Adds a stage to aggregation query which adds new fields to documents.
:param fields: The fields that will be created
:return: The current object
"""
query = {}
for field in fields:
query[field] = fields[field]
... | python | def add_fields(self, **fields):
"""
Adds a stage to aggregation query which adds new fields to documents.
:param fields: The fields that will be created
:return: The current object
"""
query = {}
for field in fields:
query[field] = fields[field]
... | [
"def",
"add_fields",
"(",
"self",
",",
"*",
"*",
"fields",
")",
":",
"query",
"=",
"{",
"}",
"for",
"field",
"in",
"fields",
":",
"query",
"[",
"field",
"]",
"=",
"fields",
"[",
"field",
"]",
"self",
".",
"_q",
".",
"append",
"(",
"{",
"'$addFiel... | Adds a stage to aggregation query which adds new fields to documents.
:param fields: The fields that will be created
:return: The current object | [
"Adds",
"a",
"stage",
"to",
"aggregation",
"query",
"which",
"adds",
"new",
"fields",
"to",
"documents",
".",
":",
"param",
"fields",
":",
"The",
"fields",
"that",
"will",
"be",
"created",
":",
"return",
":",
"The",
"current",
"object"
] | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L201-L211 | train | Adds a stage to aggregation query which adds new fields to documents. |
MosesSymeonidis/aggregation_builder | aggregation_builder/query_builder.py | AggregationQueryBuilder.execute | def execute(self):
"""
Executes the query if self.query_set_obj is set
:return: The result of aggregation query
"""
if self.query_set_obj is None:
return []
if self.is_mongoengine:
result = self.query_set_obj.aggregate(*self.get_query())
e... | python | def execute(self):
"""
Executes the query if self.query_set_obj is set
:return: The result of aggregation query
"""
if self.query_set_obj is None:
return []
if self.is_mongoengine:
result = self.query_set_obj.aggregate(*self.get_query())
e... | [
"def",
"execute",
"(",
"self",
")",
":",
"if",
"self",
".",
"query_set_obj",
"is",
"None",
":",
"return",
"[",
"]",
"if",
"self",
".",
"is_mongoengine",
":",
"result",
"=",
"self",
".",
"query_set_obj",
".",
"aggregate",
"(",
"*",
"self",
".",
"get_que... | Executes the query if self.query_set_obj is set
:return: The result of aggregation query | [
"Executes",
"the",
"query",
"if",
"self",
".",
"query_set_obj",
"is",
"set",
":",
"return",
":",
"The",
"result",
"of",
"aggregation",
"query"
] | a1f4b580401d400c53206e9c020e413166254274 | https://github.com/MosesSymeonidis/aggregation_builder/blob/a1f4b580401d400c53206e9c020e413166254274/aggregation_builder/query_builder.py#L216-L235 | train | Executes the query and returns the result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.