repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygWidgetsRadioButton.handleEvent | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
It handles showing the up, over, and down states of the button.
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
... | python | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
It handles showing the up, over, and down states of the button.
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
... | [
"def",
"handleEvent",
"(",
"self",
",",
"eventObj",
")",
":",
"if",
"eventObj",
".",
"type",
"not",
"in",
"(",
"MOUSEMOTION",
",",
"MOUSEBUTTONUP",
",",
"MOUSEBUTTONDOWN",
")",
"or",
"not",
"self",
".",
"visible",
":",
"# The radioButton only cares bout mouse-re... | This method should be called every time through the main loop.
It handles showing the up, over, and down states of the button.
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the time
| True... | [
"This",
"method",
"should",
"be",
"called",
"every",
"time",
"through",
"the",
"main",
"loop",
".",
"It",
"handles",
"showing",
"the",
"up",
"over",
"and",
"down",
"states",
"of",
"the",
"button",
".",
"Parameters",
":",
"|",
"eventObj",
"-",
"the",
"eve... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1174-L1246 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygWidgetsRadioButton.getSelectedRadioButton | def getSelectedRadioButton(self):
"""Returns the nickname of the currently selected radio button."""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
if radioButton.getValue():
... | python | def getSelectedRadioButton(self):
"""Returns the nickname of the currently selected radio button."""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
if radioButton.getValue():
... | [
"def",
"getSelectedRadioButton",
"(",
"self",
")",
":",
"radioButtonListInGroup",
"=",
"PygWidgetsRadioButton",
".",
"__PygWidgets__Radio__Buttons__Groups__Dicts__",
"[",
"self",
".",
"group",
"]",
"for",
"radioButton",
"in",
"radioButtonListInGroup",
":",
"if",
"radioBut... | Returns the nickname of the currently selected radio button. | [
"Returns",
"the",
"nickname",
"of",
"the",
"currently",
"selected",
"radio",
"button",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1248-L1256 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygWidgetsRadioButton.enableGroup | def enableGroup(self):
"""Enables all radio buttons in the group."""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
radioButton.enable() | python | def enableGroup(self):
"""Enables all radio buttons in the group."""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
radioButton.enable() | [
"def",
"enableGroup",
"(",
"self",
")",
":",
"radioButtonListInGroup",
"=",
"PygWidgetsRadioButton",
".",
"__PygWidgets__Radio__Buttons__Groups__Dicts__",
"[",
"self",
".",
"group",
"]",
"for",
"radioButton",
"in",
"radioButtonListInGroup",
":",
"radioButton",
".",
"ena... | Enables all radio buttons in the group. | [
"Enables",
"all",
"radio",
"buttons",
"in",
"the",
"group",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1289-L1293 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygWidgetsRadioButton.disableGroup | def disableGroup(self):
"""Disables all radio buttons in the group"""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
radioButton.disable() | python | def disableGroup(self):
"""Disables all radio buttons in the group"""
radioButtonListInGroup = PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]
for radioButton in radioButtonListInGroup:
radioButton.disable() | [
"def",
"disableGroup",
"(",
"self",
")",
":",
"radioButtonListInGroup",
"=",
"PygWidgetsRadioButton",
".",
"__PygWidgets__Radio__Buttons__Groups__Dicts__",
"[",
"self",
".",
"group",
"]",
"for",
"radioButton",
"in",
"radioButtonListInGroup",
":",
"radioButton",
".",
"di... | Disables all radio buttons in the group | [
"Disables",
"all",
"radio",
"buttons",
"in",
"the",
"group"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1301-L1305 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | DisplayText.setValue | def setValue(self, newText):
"""Sets a text value (string) into the text field."""
newText = str(newText) # attempt to convert to string (might be int or float ...)
if self.text == newText:
return # nothing to change
self.text = newText # save the new text
... | python | def setValue(self, newText):
"""Sets a text value (string) into the text field."""
newText = str(newText) # attempt to convert to string (might be int or float ...)
if self.text == newText:
return # nothing to change
self.text = newText # save the new text
... | [
"def",
"setValue",
"(",
"self",
",",
"newText",
")",
":",
"newText",
"=",
"str",
"(",
"newText",
")",
"# attempt to convert to string (might be int or float ...)\r",
"if",
"self",
".",
"text",
"==",
"newText",
":",
"return",
"# nothing to change\r",
"self",
".",
... | Sets a text value (string) into the text field. | [
"Sets",
"a",
"text",
"value",
"(",
"string",
")",
"into",
"the",
"text",
"field",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1585-L1661 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | DisplayText.draw | def draw(self):
"""Draws the current text in the window"""
if not self.visible:
return
self.window.blit(self.textImage, self.loc) | python | def draw(self):
"""Draws the current text in the window"""
if not self.visible:
return
self.window.blit(self.textImage, self.loc) | [
"def",
"draw",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"visible",
":",
"return",
"self",
".",
"window",
".",
"blit",
"(",
"self",
".",
"textImage",
",",
"self",
".",
"loc",
")"
] | Draws the current text in the window | [
"Draws",
"the",
"current",
"text",
"in",
"the",
"window"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1678-L1683 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | InputText._updateImage | def _updateImage(self):
"""Internal method to render text as an image."""
# Fill the background of the image
if self.backgroundColor is not None:
self.textImage.fill(self.backgroundColor)
# Render the text as a single line, and blit it onto the textImage surface
... | python | def _updateImage(self):
"""Internal method to render text as an image."""
# Fill the background of the image
if self.backgroundColor is not None:
self.textImage.fill(self.backgroundColor)
# Render the text as a single line, and blit it onto the textImage surface
... | [
"def",
"_updateImage",
"(",
"self",
")",
":",
"# Fill the background of the image\r",
"if",
"self",
".",
"backgroundColor",
"is",
"not",
"None",
":",
"self",
".",
"textImage",
".",
"fill",
"(",
"self",
".",
"backgroundColor",
")",
"# Render the text as a single line... | Internal method to render text as an image. | [
"Internal",
"method",
"to",
"render",
"text",
"as",
"an",
"image",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1783-L1796 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | InputText.handleEvent | def handleEvent(self, event):
"""This method should be called every time through the main loop.
It handles all of the keyboard key actions
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the tim... | python | def handleEvent(self, event):
"""This method should be called every time through the main loop.
It handles all of the keyboard key actions
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the tim... | [
"def",
"handleEvent",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"isEnabled",
":",
"return",
"False",
"if",
"(",
"event",
".",
"type",
"==",
"pygame",
".",
"MOUSEBUTTONDOWN",
")",
"and",
"(",
"event",
".",
"button",
"==",
"1",
")"... | This method should be called every time through the main loop.
It handles all of the keyboard key actions
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the time
| True when the user clicks... | [
"This",
"method",
"should",
"be",
"called",
"every",
"time",
"through",
"the",
"main",
"loop",
".",
"It",
"handles",
"all",
"of",
"the",
"keyboard",
"key",
"actions",
"Parameters",
":",
"|",
"eventObj",
"-",
"the",
"event",
"object",
"obtained",
"by",
"cal... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1799-L1921 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | InputText.draw | def draw(self):
"""Draws the Text in the window."""
if not self.visible:
return
# If this input text has focus, draw an outline around the text image
if self.focus:
pygame.draw.rect(self.window, self.focusColor, self.focusedImageRect, 1)
# Blit ... | python | def draw(self):
"""Draws the Text in the window."""
if not self.visible:
return
# If this input text has focus, draw an outline around the text image
if self.focus:
pygame.draw.rect(self.window, self.focusColor, self.focusedImageRect, 1)
# Blit ... | [
"def",
"draw",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"visible",
":",
"return",
"# If this input text has focus, draw an outline around the text image\r",
"if",
"self",
".",
"focus",
":",
"pygame",
".",
"draw",
".",
"rect",
"(",
"self",
".",
"window",
... | Draws the Text in the window. | [
"Draws",
"the",
"Text",
"in",
"the",
"window",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1924-L1951 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | InputText.setValue | def setValue(self, newText):
"""Sets new text into the field"""
self.text = newText
self.cursorPosition = len(self.text)
self._updateImage() | python | def setValue(self, newText):
"""Sets new text into the field"""
self.text = newText
self.cursorPosition = len(self.text)
self._updateImage() | [
"def",
"setValue",
"(",
"self",
",",
"newText",
")",
":",
"self",
".",
"text",
"=",
"newText",
"self",
".",
"cursorPosition",
"=",
"len",
"(",
"self",
".",
"text",
")",
"self",
".",
"_updateImage",
"(",
")"
] | Sets new text into the field | [
"Sets",
"new",
"text",
"into",
"the",
"field"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1963-L1967 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | InputText.clearText | def clearText(self, keepFocus=False):
"""Clear the text in the field"""
self.text = ''
self.focus = keepFocus
self._updateImage() | python | def clearText(self, keepFocus=False):
"""Clear the text in the field"""
self.text = ''
self.focus = keepFocus
self._updateImage() | [
"def",
"clearText",
"(",
"self",
",",
"keepFocus",
"=",
"False",
")",
":",
"self",
".",
"text",
"=",
"''",
"self",
".",
"focus",
"=",
"keepFocus",
"self",
".",
"_updateImage",
"(",
")"
] | Clear the text in the field | [
"Clear",
"the",
"text",
"in",
"the",
"field"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L1977-L1981 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Dragger.handleEvent | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
It handles all of the dragging
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the time
... | python | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
It handles all of the dragging
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the time
... | [
"def",
"handleEvent",
"(",
"self",
",",
"eventObj",
")",
":",
"if",
"not",
"self",
".",
"isEnabled",
":",
"return",
"False",
"if",
"eventObj",
".",
"type",
"not",
"in",
"(",
"MOUSEMOTION",
",",
"MOUSEBUTTONUP",
",",
"MOUSEBUTTONDOWN",
")",
":",
"# The drag... | This method should be called every time through the main loop.
It handles all of the dragging
Parameters:
| eventObj - the event object obtained by calling pygame.event.get()
Returns:
| False most of the time
| True when the user finishes dragging ... | [
"This",
"method",
"should",
"be",
"called",
"every",
"time",
"through",
"the",
"main",
"loop",
".",
"It",
"handles",
"all",
"of",
"the",
"dragging",
"Parameters",
":",
"|",
"eventObj",
"-",
"the",
"event",
"object",
"obtained",
"by",
"calling",
"pygame",
"... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2068-L2118 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Dragger.resetToPreviousLoc | def resetToPreviousLoc(self):
"""Resets the loc of the dragger to place where dragging started.
This could be used in a test situation if the dragger was dragged to an incorrect location.
"""
self.rect.left = self.startDraggingX
self.rect.top = self.startDraggingY | python | def resetToPreviousLoc(self):
"""Resets the loc of the dragger to place where dragging started.
This could be used in a test situation if the dragger was dragged to an incorrect location.
"""
self.rect.left = self.startDraggingX
self.rect.top = self.startDraggingY | [
"def",
"resetToPreviousLoc",
"(",
"self",
")",
":",
"self",
".",
"rect",
".",
"left",
"=",
"self",
".",
"startDraggingX",
"self",
".",
"rect",
".",
"top",
"=",
"self",
".",
"startDraggingY"
] | Resets the loc of the dragger to place where dragging started.
This could be used in a test situation if the dragger was dragged to an incorrect location. | [
"Resets",
"the",
"loc",
"of",
"the",
"dragger",
"to",
"place",
"where",
"dragging",
"started",
".",
"This",
"could",
"be",
"used",
"in",
"a",
"test",
"situation",
"if",
"the",
"dragger",
"was",
"dragged",
"to",
"an",
"incorrect",
"location",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2124-L2131 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Dragger.draw | def draw(self):
"""Draws the dragger at the current mouse location.
Should be called in every frame.
"""
if not self.visible:
return
if self.isEnabled:
# Draw the dragger's current appearance to the window.
if self.dragg... | python | def draw(self):
"""Draws the dragger at the current mouse location.
Should be called in every frame.
"""
if not self.visible:
return
if self.isEnabled:
# Draw the dragger's current appearance to the window.
if self.dragg... | [
"def",
"draw",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"visible",
":",
"return",
"if",
"self",
".",
"isEnabled",
":",
"# Draw the dragger's current appearance to the window.\r",
"if",
"self",
".",
"dragging",
":",
"self",
".",
"window",
".",
"blit",
... | Draws the dragger at the current mouse location.
Should be called in every frame. | [
"Draws",
"the",
"dragger",
"at",
"the",
"current",
"mouse",
"location",
".",
"Should",
"be",
"called",
"in",
"every",
"frame",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2133-L2153 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.flipHorizontal | def flipHorizontal(self):
""" flips an image object horizontally
"""
self.flipH = not self.flipH
self._transmogrophy(self.angle, self.percent, self.scaleFromCenter, self.flipH, self.flipV) | python | def flipHorizontal(self):
""" flips an image object horizontally
"""
self.flipH = not self.flipH
self._transmogrophy(self.angle, self.percent, self.scaleFromCenter, self.flipH, self.flipV) | [
"def",
"flipHorizontal",
"(",
"self",
")",
":",
"self",
".",
"flipH",
"=",
"not",
"self",
".",
"flipH",
"self",
".",
"_transmogrophy",
"(",
"self",
".",
"angle",
",",
"self",
".",
"percent",
",",
"self",
".",
"scaleFromCenter",
",",
"self",
".",
"flipH... | flips an image object horizontally | [
"flips",
"an",
"image",
"object",
"horizontally"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2205-L2210 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.flipVertical | def flipVertical(self):
""" flips an image object vertically
"""
self.flipV = not self.flipV
self._transmogrophy(self.angle, self.percent, self.scaleFromCenter, self.flipH, self.flipV) | python | def flipVertical(self):
""" flips an image object vertically
"""
self.flipV = not self.flipV
self._transmogrophy(self.angle, self.percent, self.scaleFromCenter, self.flipH, self.flipV) | [
"def",
"flipVertical",
"(",
"self",
")",
":",
"self",
".",
"flipV",
"=",
"not",
"self",
".",
"flipV",
"self",
".",
"_transmogrophy",
"(",
"self",
".",
"angle",
",",
"self",
".",
"percent",
",",
"self",
".",
"scaleFromCenter",
",",
"self",
".",
"flipH",... | flips an image object vertically | [
"flips",
"an",
"image",
"object",
"vertically"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2212-L2217 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.rotate | def rotate(self, nDegrees):
"""rotates the image a given number of degrees
Parameters:
| nDegrees - the number of degrees you want the image rotated (images start at zero degrees).
| Positive numbers are clockwise, negative numbers are counter-clockwise
... | python | def rotate(self, nDegrees):
"""rotates the image a given number of degrees
Parameters:
| nDegrees - the number of degrees you want the image rotated (images start at zero degrees).
| Positive numbers are clockwise, negative numbers are counter-clockwise
... | [
"def",
"rotate",
"(",
"self",
",",
"nDegrees",
")",
":",
"self",
".",
"angle",
"=",
"self",
".",
"angle",
"+",
"nDegrees",
"self",
".",
"_transmogrophy",
"(",
"self",
".",
"angle",
",",
"self",
".",
"percent",
",",
"self",
".",
"scaleFromCenter",
",",
... | rotates the image a given number of degrees
Parameters:
| nDegrees - the number of degrees you want the image rotated (images start at zero degrees).
| Positive numbers are clockwise, negative numbers are counter-clockwise | [
"rotates",
"the",
"image",
"a",
"given",
"number",
"of",
"degrees",
"Parameters",
":",
"|",
"nDegrees",
"-",
"the",
"number",
"of",
"degrees",
"you",
"want",
"the",
"image",
"rotated",
"(",
"images",
"start",
"at",
"zero",
"degrees",
")",
".",
"|",
"Posi... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2219-L2228 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.rotateTo | def rotateTo(self, angle):
"""rotates the image to a given angle
Parameters:
| angle - the angle that you want the image rotated to.
| Positive numbers are clockwise, negative numbers are counter-clockwise
"""
self._transmogrophy(angle, self.p... | python | def rotateTo(self, angle):
"""rotates the image to a given angle
Parameters:
| angle - the angle that you want the image rotated to.
| Positive numbers are clockwise, negative numbers are counter-clockwise
"""
self._transmogrophy(angle, self.p... | [
"def",
"rotateTo",
"(",
"self",
",",
"angle",
")",
":",
"self",
".",
"_transmogrophy",
"(",
"angle",
",",
"self",
".",
"percent",
",",
"self",
".",
"scaleFromCenter",
",",
"self",
".",
"flipH",
",",
"self",
".",
"flipV",
")"
] | rotates the image to a given angle
Parameters:
| angle - the angle that you want the image rotated to.
| Positive numbers are clockwise, negative numbers are counter-clockwise | [
"rotates",
"the",
"image",
"to",
"a",
"given",
"angle",
"Parameters",
":",
"|",
"angle",
"-",
"the",
"angle",
"that",
"you",
"want",
"the",
"image",
"rotated",
"to",
".",
"|",
"Positive",
"numbers",
"are",
"clockwise",
"negative",
"numbers",
"are",
"counte... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2231-L2239 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.scale | def scale(self, percent, scaleFromCenter=True):
"""scales an Image object
Parameters:
| percent - a percent of the original size
| numbers bigger than 100 scale up
| numbers less than 100 scale down
| 100 scales to the... | python | def scale(self, percent, scaleFromCenter=True):
"""scales an Image object
Parameters:
| percent - a percent of the original size
| numbers bigger than 100 scale up
| numbers less than 100 scale down
| 100 scales to the... | [
"def",
"scale",
"(",
"self",
",",
"percent",
",",
"scaleFromCenter",
"=",
"True",
")",
":",
"self",
".",
"_transmogrophy",
"(",
"self",
".",
"angle",
",",
"percent",
",",
"scaleFromCenter",
",",
"self",
".",
"flipH",
",",
"self",
".",
"flipV",
")"
] | scales an Image object
Parameters:
| percent - a percent of the original size
| numbers bigger than 100 scale up
| numbers less than 100 scale down
| 100 scales to the original size
Optional keyword parameters:
... | [
"scales",
"an",
"Image",
"object",
"Parameters",
":",
"|",
"percent",
"-",
"a",
"percent",
"of",
"the",
"original",
"size",
"|",
"numbers",
"bigger",
"than",
"100",
"scale",
"up",
"|",
"numbers",
"less",
"than",
"100",
"scale",
"down",
"|",
"100",
"scale... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2242-L2255 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image._transmogrophy | def _transmogrophy(self, angle, percent, scaleFromCenter, flipH, flipV):
'''
Internal method to scale and rotate
'''
self.angle = angle % 360
self.percent = percent
self.scaleFromCenter = scaleFromCenter
previousRect = self.rect
previousCente... | python | def _transmogrophy(self, angle, percent, scaleFromCenter, flipH, flipV):
'''
Internal method to scale and rotate
'''
self.angle = angle % 360
self.percent = percent
self.scaleFromCenter = scaleFromCenter
previousRect = self.rect
previousCente... | [
"def",
"_transmogrophy",
"(",
"self",
",",
"angle",
",",
"percent",
",",
"scaleFromCenter",
",",
"flipH",
",",
"flipV",
")",
":",
"self",
".",
"angle",
"=",
"angle",
"%",
"360",
"self",
".",
"percent",
"=",
"percent",
"self",
".",
"scaleFromCenter",
"=",... | Internal method to scale and rotate | [
"Internal",
"method",
"to",
"scale",
"and",
"rotate"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2258-L2301 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | Image.draw | def draw(self):
"""Draws the image at the given location."""
if not self.visible:
return
self.window.blit(self.image, self.loc) | python | def draw(self):
"""Draws the image at the given location."""
if not self.visible:
return
self.window.blit(self.image, self.loc) | [
"def",
"draw",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"visible",
":",
"return",
"self",
".",
"window",
".",
"blit",
"(",
"self",
".",
"image",
",",
"self",
".",
"loc",
")"
] | Draws the image at the given location. | [
"Draws",
"the",
"image",
"at",
"the",
"given",
"location",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2304-L2309 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | ImageCollection.replace | def replace(self, key):
"""Selects a different image to be shown.
Parameters:
| key - a key in the original dictionary to specify which image to show
"""
if not (key in self.imagesDict):
print('The key', key, 'was not found in the collection of images di... | python | def replace(self, key):
"""Selects a different image to be shown.
Parameters:
| key - a key in the original dictionary to specify which image to show
"""
if not (key in self.imagesDict):
print('The key', key, 'was not found in the collection of images di... | [
"def",
"replace",
"(",
"self",
",",
"key",
")",
":",
"if",
"not",
"(",
"key",
"in",
"self",
".",
"imagesDict",
")",
":",
"print",
"(",
"'The key'",
",",
"key",
",",
"'was not found in the collection of images dictionary'",
")",
"raise",
"KeyError",
"self",
"... | Selects a different image to be shown.
Parameters:
| key - a key in the original dictionary to specify which image to show | [
"Selects",
"a",
"different",
"image",
"to",
"be",
"shown",
".",
"Parameters",
":",
"|",
"key",
"-",
"a",
"key",
"in",
"the",
"original",
"dictionary",
"to",
"specify",
"which",
"image",
"to",
"show"
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2381-L2401 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.handleEvent | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
Returns:
False - if no event happens.
True - if the user clicks the animation to start it playing.
"""
if not self.visible:
return
if n... | python | def handleEvent(self, eventObj):
"""This method should be called every time through the main loop.
Returns:
False - if no event happens.
True - if the user clicks the animation to start it playing.
"""
if not self.visible:
return
if n... | [
"def",
"handleEvent",
"(",
"self",
",",
"eventObj",
")",
":",
"if",
"not",
"self",
".",
"visible",
":",
"return",
"if",
"not",
"self",
".",
"isEnabled",
":",
"return",
"False",
"if",
"eventObj",
".",
"type",
"!=",
"MOUSEBUTTONDOWN",
":",
"# The animation o... | This method should be called every time through the main loop.
Returns:
False - if no event happens.
True - if the user clicks the animation to start it playing. | [
"This",
"method",
"should",
"be",
"called",
"every",
"time",
"through",
"the",
"main",
"loop",
".",
"Returns",
":",
"False",
"-",
"if",
"no",
"event",
"happens",
".",
"True",
"-",
"if",
"the",
"user",
"clicks",
"the",
"animation",
"to",
"start",
"it",
... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2445-L2468 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.play | def play(self):
"""Starts an animation playing."""
if self.state == PygAnimation.PLAYING:
pass # nothing to do
elif self.state == PygAnimation.STOPPED: # restart from beginning of animation
self.index = 0 # first image in list
self.elapsed = 0
... | python | def play(self):
"""Starts an animation playing."""
if self.state == PygAnimation.PLAYING:
pass # nothing to do
elif self.state == PygAnimation.STOPPED: # restart from beginning of animation
self.index = 0 # first image in list
self.elapsed = 0
... | [
"def",
"play",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"PygAnimation",
".",
"PLAYING",
":",
"pass",
"# nothing to do\r",
"elif",
"self",
".",
"state",
"==",
"PygAnimation",
".",
"STOPPED",
":",
"# restart from beginning of animation\r",
"self",
... | Starts an animation playing. | [
"Starts",
"an",
"animation",
"playing",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2471-L2490 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.stop | def stop(self):
"""Stops a a playing animation. A subsequent call to play will start from the beginning."""
if self.state == PygAnimation.PLAYING:
self.index = 0 # set up for first image in list
self.elapsed = 0
self.nIterationsLeft = 0
elif self.sta... | python | def stop(self):
"""Stops a a playing animation. A subsequent call to play will start from the beginning."""
if self.state == PygAnimation.PLAYING:
self.index = 0 # set up for first image in list
self.elapsed = 0
self.nIterationsLeft = 0
elif self.sta... | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"PygAnimation",
".",
"PLAYING",
":",
"self",
".",
"index",
"=",
"0",
"# set up for first image in list\r",
"self",
".",
"elapsed",
"=",
"0",
"self",
".",
"nIterationsLeft",
"=",
"0",
... | Stops a a playing animation. A subsequent call to play will start from the beginning. | [
"Stops",
"a",
"a",
"playing",
"animation",
".",
"A",
"subsequent",
"call",
"to",
"play",
"will",
"start",
"from",
"the",
"beginning",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2492-L2506 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.pause | def pause(self):
"""Pauses a playing animation. A subsequent call to play will continue where it left off."""
if self.state == PygAnimation.PLAYING:
self.elapsedAtPause = self.elapsed
# only change state if it was playing
self.state = PygAnimation.PAUSED
... | python | def pause(self):
"""Pauses a playing animation. A subsequent call to play will continue where it left off."""
if self.state == PygAnimation.PLAYING:
self.elapsedAtPause = self.elapsed
# only change state if it was playing
self.state = PygAnimation.PAUSED
... | [
"def",
"pause",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"PygAnimation",
".",
"PLAYING",
":",
"self",
".",
"elapsedAtPause",
"=",
"self",
".",
"elapsed",
"# only change state if it was playing\r",
"self",
".",
"state",
"=",
"PygAnimation",
".",... | Pauses a playing animation. A subsequent call to play will continue where it left off. | [
"Pauses",
"a",
"playing",
"animation",
".",
"A",
"subsequent",
"call",
"to",
"play",
"will",
"continue",
"where",
"it",
"left",
"off",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2508-L2519 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.update | def update(self):
"""Updates the currently running animation.
This method should be called in every frame where you want an animation to run.
Its job is to figure out if it is time to move onto the next image in the animation.
"""
returnValue = False # typical return va... | python | def update(self):
"""Updates the currently running animation.
This method should be called in every frame where you want an animation to run.
Its job is to figure out if it is time to move onto the next image in the animation.
"""
returnValue = False # typical return va... | [
"def",
"update",
"(",
"self",
")",
":",
"returnValue",
"=",
"False",
"# typical return value\r",
"if",
"self",
".",
"state",
"!=",
"PygAnimation",
".",
"PLAYING",
":",
"return",
"returnValue",
"# The job here is to figure out the index of the image to show\r",
"# and the ... | Updates the currently running animation.
This method should be called in every frame where you want an animation to run.
Its job is to figure out if it is time to move onto the next image in the animation. | [
"Updates",
"the",
"currently",
"running",
"animation",
".",
"This",
"method",
"should",
"be",
"called",
"in",
"every",
"frame",
"where",
"you",
"want",
"an",
"animation",
"to",
"run",
".",
"Its",
"job",
"is",
"to",
"figure",
"out",
"if",
"it",
"is",
"tim... | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2521-L2557 |
IrvKalb/pygwidgets | pygwidgets/pygwidgets.py | PygAnimation.draw | def draw(self):
"""Draws the current frame of the animation
Should be called in every frame.
"""
# Assumes that self.index has been set earlier (typically in update method)
# it is used as the index of the current image/endTime/loc
theImage = self.imagesList[sel... | python | def draw(self):
"""Draws the current frame of the animation
Should be called in every frame.
"""
# Assumes that self.index has been set earlier (typically in update method)
# it is used as the index of the current image/endTime/loc
theImage = self.imagesList[sel... | [
"def",
"draw",
"(",
"self",
")",
":",
"# Assumes that self.index has been set earlier (typically in update method)\r",
"# it is used as the index of the current image/endTime/loc\r",
"theImage",
"=",
"self",
".",
"imagesList",
"[",
"self",
".",
"index",
"]",
"# choose the image t... | Draws the current frame of the animation
Should be called in every frame. | [
"Draws",
"the",
"current",
"frame",
"of",
"the",
"animation",
"Should",
"be",
"called",
"in",
"every",
"frame",
"."
] | train | https://github.com/IrvKalb/pygwidgets/blob/a830d8885d4d209e471cb53816277d30db56273c/pygwidgets/pygwidgets.py#L2559-L2575 |
ironfroggy/django-better-cache | bettercache/decorators.py | CachedMethod.cache | def cache(cls, key_attrs, expires=None):
"""Decorates a method to provide cached-memoization using a
combination of the positional arguments, keyword argments, and
whitelisted instance attributes.
"""
def decorator(func):
@functools.wraps(func)
def wrapp... | python | def cache(cls, key_attrs, expires=None):
"""Decorates a method to provide cached-memoization using a
combination of the positional arguments, keyword argments, and
whitelisted instance attributes.
"""
def decorator(func):
@functools.wraps(func)
def wrapp... | [
"def",
"cache",
"(",
"cls",
",",
"key_attrs",
",",
"expires",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwa... | Decorates a method to provide cached-memoization using a
combination of the positional arguments, keyword argments, and
whitelisted instance attributes. | [
"Decorates",
"a",
"method",
"to",
"provide",
"cached",
"-",
"memoization",
"using",
"a",
"combination",
"of",
"the",
"positional",
"arguments",
"keyword",
"argments",
"and",
"whitelisted",
"instance",
"attributes",
"."
] | train | https://github.com/ironfroggy/django-better-cache/blob/5350e8c646cef1c1ca74eab176f856ddd9eaf5c3/bettercache/decorators.py#L40-L87 |
crcresearch/py-utils | crc_nd/utils/error_mixins.py | CallerErrorMixin.assertCallerError | def assertCallerError(self, expected_arg0, callable_obj, *args, **kwargs):
"""
Assert that a callable raises an AssertionError with a particular argument.
:param expected_arg0: The expected value for the AssertionError instance's first argument
(i.e., instance.args... | python | def assertCallerError(self, expected_arg0, callable_obj, *args, **kwargs):
"""
Assert that a callable raises an AssertionError with a particular argument.
:param expected_arg0: The expected value for the AssertionError instance's first argument
(i.e., instance.args... | [
"def",
"assertCallerError",
"(",
"self",
",",
"expected_arg0",
",",
"callable_obj",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"callable_obj",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"fail",
"(",
"'Expected As... | Assert that a callable raises an AssertionError with a particular argument.
:param expected_arg0: The expected value for the AssertionError instance's first argument
(i.e., instance.args[0]). | [
"Assert",
"that",
"a",
"callable",
"raises",
"an",
"AssertionError",
"with",
"a",
"particular",
"argument",
"."
] | train | https://github.com/crcresearch/py-utils/blob/04caf0425a047baf900da726cf47c42413b0dd81/crc_nd/utils/error_mixins.py#L23-L36 |
cdeboever3/cdpybio | cdpybio/pysamext.py | get_region_nt_counts | def get_region_nt_counts(region, bam, stranded=False):
"""
Get counts of each nucleotide from a bam file for a given region. If R1 and
R2 reads both overlap a position, only one count will be added. If the R1
and R2 reads disagree at a position they both overlap, that read pair is not
used for that ... | python | def get_region_nt_counts(region, bam, stranded=False):
"""
Get counts of each nucleotide from a bam file for a given region. If R1 and
R2 reads both overlap a position, only one count will be added. If the R1
and R2 reads disagree at a position they both overlap, that read pair is not
used for that ... | [
"def",
"get_region_nt_counts",
"(",
"region",
",",
"bam",
",",
"stranded",
"=",
"False",
")",
":",
"# TODO: I should figure out what the different possible values are that",
"# pysam could give me back (so far I only have ATCGN). Can I get deletions",
"# and insertions? ",
"# TODO: Thi... | Get counts of each nucleotide from a bam file for a given region. If R1 and
R2 reads both overlap a position, only one count will be added. If the R1
and R2 reads disagree at a position they both overlap, that read pair is not
used for that position. Can optionally output strand-specific counts.
Param... | [
"Get",
"counts",
"of",
"each",
"nucleotide",
"from",
"a",
"bam",
"file",
"for",
"a",
"given",
"region",
".",
"If",
"R1",
"and",
"R2",
"reads",
"both",
"overlap",
"a",
"position",
"only",
"one",
"count",
"will",
"be",
"added",
".",
"If",
"the",
"R1",
... | train | https://github.com/cdeboever3/cdpybio/blob/38efdf0e11d01bc00a135921cb91a19c03db5d5c/cdpybio/pysamext.py#L11-L103 |
cdeboever3/cdpybio | cdpybio/pysamext.py | _pos_nt | def _pos_nt(pr, pos, stranded=False):
"""
Given a pileup read and a position, return the base that is covered by the
read at the given position if the position is covered.
Parameters
----------
pr : pysam.calignmentfile.PileupRead
Region of type chrom:start-end, chrom:start-end:strand, ... | python | def _pos_nt(pr, pos, stranded=False):
"""
Given a pileup read and a position, return the base that is covered by the
read at the given position if the position is covered.
Parameters
----------
pr : pysam.calignmentfile.PileupRead
Region of type chrom:start-end, chrom:start-end:strand, ... | [
"def",
"_pos_nt",
"(",
"pr",
",",
"pos",
",",
"stranded",
"=",
"False",
")",
":",
"nt",
"=",
"None",
"bases",
"=",
"dict",
"(",
"zip",
"(",
"pr",
".",
"alignment",
".",
"get_reference_positions",
"(",
")",
",",
"list",
"(",
"pr",
".",
"alignment",
... | Given a pileup read and a position, return the base that is covered by the
read at the given position if the position is covered.
Parameters
----------
pr : pysam.calignmentfile.PileupRead
Region of type chrom:start-end, chrom:start-end:strand, or [chrom,
pos : int
Zero-based p... | [
"Given",
"a",
"pileup",
"read",
"and",
"a",
"position",
"return",
"the",
"base",
"that",
"is",
"covered",
"by",
"the",
"read",
"at",
"the",
"given",
"position",
"if",
"the",
"position",
"is",
"covered",
"."
] | train | https://github.com/cdeboever3/cdpybio/blob/38efdf0e11d01bc00a135921cb91a19c03db5d5c/cdpybio/pysamext.py#L105-L150 |
cdeboever3/cdpybio | cdpybio/pysamext.py | nt_counts | def nt_counts(bam, positions, stranded=False, vcf=False, bed=False):
"""
Find the number of nucleotides covered at all positions in a bed or vcf
file.
Parameters
----------
bam : str or pysam.calignmentfile.AlignmentFile
Bam file opened with pysam or path to bam file (must
be s... | python | def nt_counts(bam, positions, stranded=False, vcf=False, bed=False):
"""
Find the number of nucleotides covered at all positions in a bed or vcf
file.
Parameters
----------
bam : str or pysam.calignmentfile.AlignmentFile
Bam file opened with pysam or path to bam file (must
be s... | [
"def",
"nt_counts",
"(",
"bam",
",",
"positions",
",",
"stranded",
"=",
"False",
",",
"vcf",
"=",
"False",
",",
"bed",
"=",
"False",
")",
":",
"if",
"not",
"bed",
"and",
"not",
"vcf",
":",
"if",
"type",
"(",
"positions",
")",
"==",
"pbt",
".",
"b... | Find the number of nucleotides covered at all positions in a bed or vcf
file.
Parameters
----------
bam : str or pysam.calignmentfile.AlignmentFile
Bam file opened with pysam or path to bam file (must
be sorted and indexed).
positions : str or pybedtools.BedTool
Path t... | [
"Find",
"the",
"number",
"of",
"nucleotides",
"covered",
"at",
"all",
"positions",
"in",
"a",
"bed",
"or",
"vcf",
"file",
"."
] | train | https://github.com/cdeboever3/cdpybio/blob/38efdf0e11d01bc00a135921cb91a19c03db5d5c/cdpybio/pysamext.py#L152-L213 |
AWegnerGitHub/smokeapi | smokeapi/smokeapi.py | SmokeAPI.fetch | def fetch(self, endpoint=None, page=1, **kwargs):
"""Returns the results of an API call.
This is the main work horse of the class. It builds the API query
string and sends the request to MetaSmoke. If there are multiple
pages of results, and we've configured `max_pages` to b... | python | def fetch(self, endpoint=None, page=1, **kwargs):
"""Returns the results of an API call.
This is the main work horse of the class. It builds the API query
string and sends the request to MetaSmoke. If there are multiple
pages of results, and we've configured `max_pages` to b... | [
"def",
"fetch",
"(",
"self",
",",
"endpoint",
"=",
"None",
",",
"page",
"=",
"1",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"endpoint",
":",
"raise",
"ValueError",
"(",
"'No endpoint provided.'",
")",
"self",
".",
"_endpoint",
"=",
"endpoint",
"p... | Returns the results of an API call.
This is the main work horse of the class. It builds the API query
string and sends the request to MetaSmoke. If there are multiple
pages of results, and we've configured `max_pages` to be greater than
1, it will automatically paginate ... | [
"Returns",
"the",
"results",
"of",
"an",
"API",
"call",
"."
] | train | https://github.com/AWegnerGitHub/smokeapi/blob/0ba786712e1f7377e5a83539a9ba8d5b3461b9c9/smokeapi/smokeapi.py#L63-L184 |
AWegnerGitHub/smokeapi | smokeapi/smokeapi.py | SmokeAPI.send_data | def send_data(self, endpoint=None, **kwargs):
"""Sends data to the API.
This call is similar to ``fetch``, but **sends** data to the API instead
of retrieving it.
Returned data will appear in the ``items`` key of the resulting
dictionary.
Sending data **requires** tha... | python | def send_data(self, endpoint=None, **kwargs):
"""Sends data to the API.
This call is similar to ``fetch``, but **sends** data to the API instead
of retrieving it.
Returned data will appear in the ``items`` key of the resulting
dictionary.
Sending data **requires** tha... | [
"def",
"send_data",
"(",
"self",
",",
"endpoint",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"endpoint",
":",
"raise",
"ValueError",
"(",
"'No end point provided.'",
")",
"if",
"not",
"self",
".",
"token",
":",
"raise",
"ValueError",
"(... | Sends data to the API.
This call is similar to ``fetch``, but **sends** data to the API instead
of retrieving it.
Returned data will appear in the ``items`` key of the resulting
dictionary.
Sending data **requires** that the ``token`` is set.
:param endpoint: (string)... | [
"Sends",
"data",
"to",
"the",
"API",
"."
] | train | https://github.com/AWegnerGitHub/smokeapi/blob/0ba786712e1f7377e5a83539a9ba8d5b3461b9c9/smokeapi/smokeapi.py#L186-L255 |
logston/py3s3 | py3s3/storage.py | Storage.save | def save(self, name, file):
"""
Saves new content to the file specified by name. The content should be
a proper File object or any python file-like object, ready to be read
from the beginning.
"""
# Get the proper name for the file, as it will actually be saved.
i... | python | def save(self, name, file):
"""
Saves new content to the file specified by name. The content should be
a proper File object or any python file-like object, ready to be read
from the beginning.
"""
# Get the proper name for the file, as it will actually be saved.
i... | [
"def",
"save",
"(",
"self",
",",
"name",
",",
"file",
")",
":",
"# Get the proper name for the file, as it will actually be saved.",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"file",
".",
"name",
"if",
"not",
"hasattr",
"(",
"file",
",",
"'chunks'",
")",
... | Saves new content to the file specified by name. The content should be
a proper File object or any python file-like object, ready to be read
from the beginning. | [
"Saves",
"new",
"content",
"to",
"the",
"file",
"specified",
"by",
"name",
".",
"The",
"content",
"should",
"be",
"a",
"proper",
"File",
"object",
"or",
"any",
"python",
"file",
"-",
"like",
"object",
"ready",
"to",
"be",
"read",
"from",
"the",
"beginnin... | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L50-L67 |
logston/py3s3 | py3s3/storage.py | S3Storage._prepend_name_prefix | def _prepend_name_prefix(self, name):
"""Return file name (ie. path) with the prefix directory prepended"""
if not self.name_prefix:
return name
base = self.name_prefix
if base[0] != '/':
base = '/' + base
if name[0] != '/':
name = '/' + name
... | python | def _prepend_name_prefix(self, name):
"""Return file name (ie. path) with the prefix directory prepended"""
if not self.name_prefix:
return name
base = self.name_prefix
if base[0] != '/':
base = '/' + base
if name[0] != '/':
name = '/' + name
... | [
"def",
"_prepend_name_prefix",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"self",
".",
"name_prefix",
":",
"return",
"name",
"base",
"=",
"self",
".",
"name_prefix",
"if",
"base",
"[",
"0",
"]",
"!=",
"'/'",
":",
"base",
"=",
"'/'",
"+",
"base"... | Return file name (ie. path) with the prefix directory prepended | [
"Return",
"file",
"name",
"(",
"ie",
".",
"path",
")",
"with",
"the",
"prefix",
"directory",
"prepended"
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L194-L203 |
logston/py3s3 | py3s3/storage.py | S3Storage.request_signature | def request_signature(self, stringtosign):
"""
Construct a signature by making an RFC2104 HMAC-SHA1
of the following and converting it to Base64 UTF-8 encoded string.
"""
digest = hmac.new(
self.secret_key.encode(ENCODING),
stringtosign.encode(ENCODING),
... | python | def request_signature(self, stringtosign):
"""
Construct a signature by making an RFC2104 HMAC-SHA1
of the following and converting it to Base64 UTF-8 encoded string.
"""
digest = hmac.new(
self.secret_key.encode(ENCODING),
stringtosign.encode(ENCODING),
... | [
"def",
"request_signature",
"(",
"self",
",",
"stringtosign",
")",
":",
"digest",
"=",
"hmac",
".",
"new",
"(",
"self",
".",
"secret_key",
".",
"encode",
"(",
"ENCODING",
")",
",",
"stringtosign",
".",
"encode",
"(",
"ENCODING",
")",
",",
"hashlib",
".",... | Construct a signature by making an RFC2104 HMAC-SHA1
of the following and converting it to Base64 UTF-8 encoded string. | [
"Construct",
"a",
"signature",
"by",
"making",
"an",
"RFC2104",
"HMAC",
"-",
"SHA1",
"of",
"the",
"following",
"and",
"converting",
"it",
"to",
"Base64",
"UTF",
"-",
"8",
"encoded",
"string",
"."
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L205-L215 |
logston/py3s3 | py3s3/storage.py | S3Storage._get_content_type | def _get_content_type(self, file):
"""
Return content type of file. If file does not
have a content type, make a guess.
"""
if file.mimetype:
return file.mimetype
# get file extension
_, extension = os.path.splitext(file.name)
extension = exte... | python | def _get_content_type(self, file):
"""
Return content type of file. If file does not
have a content type, make a guess.
"""
if file.mimetype:
return file.mimetype
# get file extension
_, extension = os.path.splitext(file.name)
extension = exte... | [
"def",
"_get_content_type",
"(",
"self",
",",
"file",
")",
":",
"if",
"file",
".",
"mimetype",
":",
"return",
"file",
".",
"mimetype",
"# get file extension",
"_",
",",
"extension",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"file",
".",
"name",
")",
... | Return content type of file. If file does not
have a content type, make a guess. | [
"Return",
"content",
"type",
"of",
"file",
".",
"If",
"file",
"does",
"not",
"have",
"a",
"content",
"type",
"make",
"a",
"guess",
"."
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L261-L274 |
logston/py3s3 | py3s3/storage.py | S3Storage._put_file | def _put_file(self, file):
"""Send PUT request to S3 with file contents"""
post_params = {
'file_size': file.size,
'file_hash': file.md5hash(),
'content_type': self._get_content_type(file),
}
headers = self._request_headers('PUT', file.prefixed_name... | python | def _put_file(self, file):
"""Send PUT request to S3 with file contents"""
post_params = {
'file_size': file.size,
'file_hash': file.md5hash(),
'content_type': self._get_content_type(file),
}
headers = self._request_headers('PUT', file.prefixed_name... | [
"def",
"_put_file",
"(",
"self",
",",
"file",
")",
":",
"post_params",
"=",
"{",
"'file_size'",
":",
"file",
".",
"size",
",",
"'file_hash'",
":",
"file",
".",
"md5hash",
"(",
")",
",",
"'content_type'",
":",
"self",
".",
"_get_content_type",
"(",
"file"... | Send PUT request to S3 with file contents | [
"Send",
"PUT",
"request",
"to",
"S3",
"with",
"file",
"contents"
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L276-L298 |
logston/py3s3 | py3s3/storage.py | S3Storage._get_file | def _get_file(self, prefixed_name):
"""
Return a signature for use in GET requests
"""
headers = self._request_headers('GET', prefixed_name)
file = S3ContentFile('')
with closing(HTTPConnection(self.netloc)) as conn:
conn.request('GET', prefixed_name, headers=... | python | def _get_file(self, prefixed_name):
"""
Return a signature for use in GET requests
"""
headers = self._request_headers('GET', prefixed_name)
file = S3ContentFile('')
with closing(HTTPConnection(self.netloc)) as conn:
conn.request('GET', prefixed_name, headers=... | [
"def",
"_get_file",
"(",
"self",
",",
"prefixed_name",
")",
":",
"headers",
"=",
"self",
".",
"_request_headers",
"(",
"'GET'",
",",
"prefixed_name",
")",
"file",
"=",
"S3ContentFile",
"(",
"''",
")",
"with",
"closing",
"(",
"HTTPConnection",
"(",
"self",
... | Return a signature for use in GET requests | [
"Return",
"a",
"signature",
"for",
"use",
"in",
"GET",
"requests"
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L300-L323 |
logston/py3s3 | py3s3/storage.py | S3Storage.url | def url(self, name):
"""Return URL of resource"""
scheme = 'http'
path = self._prepend_name_prefix(name)
query = ''
fragment = ''
url_tuple = (scheme, self.netloc, path, query, fragment)
return urllib.parse.urlunsplit(url_tuple) | python | def url(self, name):
"""Return URL of resource"""
scheme = 'http'
path = self._prepend_name_prefix(name)
query = ''
fragment = ''
url_tuple = (scheme, self.netloc, path, query, fragment)
return urllib.parse.urlunsplit(url_tuple) | [
"def",
"url",
"(",
"self",
",",
"name",
")",
":",
"scheme",
"=",
"'http'",
"path",
"=",
"self",
".",
"_prepend_name_prefix",
"(",
"name",
")",
"query",
"=",
"''",
"fragment",
"=",
"''",
"url_tuple",
"=",
"(",
"scheme",
",",
"self",
".",
"netloc",
","... | Return URL of resource | [
"Return",
"URL",
"of",
"resource"
] | train | https://github.com/logston/py3s3/blob/1910ca60c53a53d839d6f7b09c05b555f3bfccf4/py3s3/storage.py#L378-L385 |
pablorecio/Cobaya | src/cobaya/app.py | get_all_tasks | def get_all_tasks(conf):
"""Returns a list with every task registred on Hamster.
"""
db = HamsterDB(conf)
fact_list = db.all_facts_id
security_days = int(conf.get_option('tasks.security_days'))
today = datetime.today()
tasks = {}
for fact_id in fact_list:
ht = HamsterTask(fac... | python | def get_all_tasks(conf):
"""Returns a list with every task registred on Hamster.
"""
db = HamsterDB(conf)
fact_list = db.all_facts_id
security_days = int(conf.get_option('tasks.security_days'))
today = datetime.today()
tasks = {}
for fact_id in fact_list:
ht = HamsterTask(fac... | [
"def",
"get_all_tasks",
"(",
"conf",
")",
":",
"db",
"=",
"HamsterDB",
"(",
"conf",
")",
"fact_list",
"=",
"db",
".",
"all_facts_id",
"security_days",
"=",
"int",
"(",
"conf",
".",
"get_option",
"(",
"'tasks.security_days'",
")",
")",
"today",
"=",
"dateti... | Returns a list with every task registred on Hamster. | [
"Returns",
"a",
"list",
"with",
"every",
"task",
"registred",
"on",
"Hamster",
"."
] | train | https://github.com/pablorecio/Cobaya/blob/70b107dea5f31f51e7b6738da3c2a1df5b9f3f20/src/cobaya/app.py#L94-L117 |
edwards-lab/libGWAS | libgwas/impute_parser.py | SetEncoding | def SetEncoding(sval):
"""Sets the encoding variable according to the text passed
:param sval: text specification for the desired model
"""
global encoding
s=sval.lower()
if s == "additive":
encoding = Encoding.Additive
elif s == "dominant":
encoding = Encoding.Dominant
... | python | def SetEncoding(sval):
"""Sets the encoding variable according to the text passed
:param sval: text specification for the desired model
"""
global encoding
s=sval.lower()
if s == "additive":
encoding = Encoding.Additive
elif s == "dominant":
encoding = Encoding.Dominant
... | [
"def",
"SetEncoding",
"(",
"sval",
")",
":",
"global",
"encoding",
"s",
"=",
"sval",
".",
"lower",
"(",
")",
"if",
"s",
"==",
"\"additive\"",
":",
"encoding",
"=",
"Encoding",
".",
"Additive",
"elif",
"s",
"==",
"\"dominant\"",
":",
"encoding",
"=",
"E... | Sets the encoding variable according to the text passed
:param sval: text specification for the desired model | [
"Sets",
"the",
"encoding",
"variable",
"according",
"to",
"the",
"text",
"passed"
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L39-L57 |
edwards-lab/libGWAS | libgwas/impute_parser.py | Parser.ReportConfiguration | def ReportConfiguration(self, file):
"""
:param file: Destination for report details
:return: None
"""
global encodingpar
print >> file, BuildReportLine("FAM FILE", self.fam_details)
print >> file, BuildReportLine("IMPUTE_ARCHIVES", "%s:%s" % (str(self.chroms[0]),... | python | def ReportConfiguration(self, file):
"""
:param file: Destination for report details
:return: None
"""
global encodingpar
print >> file, BuildReportLine("FAM FILE", self.fam_details)
print >> file, BuildReportLine("IMPUTE_ARCHIVES", "%s:%s" % (str(self.chroms[0]),... | [
"def",
"ReportConfiguration",
"(",
"self",
",",
"file",
")",
":",
"global",
"encodingpar",
"print",
">>",
"file",
",",
"BuildReportLine",
"(",
"\"FAM FILE\"",
",",
"self",
".",
"fam_details",
")",
"print",
">>",
"file",
",",
"BuildReportLine",
"(",
"\"IMPUTE_A... | :param file: Destination for report details
:return: None | [
":",
"param",
"file",
":",
"Destination",
"for",
"report",
"details",
":",
"return",
":",
"None"
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L133-L147 |
edwards-lab/libGWAS | libgwas/impute_parser.py | Parser.load_family_details | def load_family_details(self, pheno_covar):
"""Load family data updating the pheno_covar with family ids found.
:param pheno_covar: Phenotype/covariate object
:return: None
"""
file = open(self.fam_details)
header = file.readline()
format = file.readline()
... | python | def load_family_details(self, pheno_covar):
"""Load family data updating the pheno_covar with family ids found.
:param pheno_covar: Phenotype/covariate object
:return: None
"""
file = open(self.fam_details)
header = file.readline()
format = file.readline()
... | [
"def",
"load_family_details",
"(",
"self",
",",
"pheno_covar",
")",
":",
"file",
"=",
"open",
"(",
"self",
".",
"fam_details",
")",
"header",
"=",
"file",
".",
"readline",
"(",
")",
"format",
"=",
"file",
".",
"readline",
"(",
")",
"self",
".",
"file_i... | Load family data updating the pheno_covar with family ids found.
:param pheno_covar: Phenotype/covariate object
:return: None | [
"Load",
"family",
"data",
"updating",
"the",
"pheno_covar",
"with",
"family",
"ids",
"found",
"."
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L149-L176 |
edwards-lab/libGWAS | libgwas/impute_parser.py | Parser.load_genotypes | def load_genotypes(self):
"""Prepares the files for genotype parsing.
:return: None
"""
if self.file_index < len(self.archives):
self.current_file = self.archives[self.file_index]
info_filename = self.current_file.replace(Parser.gen_ext, Parser.info_ext)
... | python | def load_genotypes(self):
"""Prepares the files for genotype parsing.
:return: None
"""
if self.file_index < len(self.archives):
self.current_file = self.archives[self.file_index]
info_filename = self.current_file.replace(Parser.gen_ext, Parser.info_ext)
... | [
"def",
"load_genotypes",
"(",
"self",
")",
":",
"if",
"self",
".",
"file_index",
"<",
"len",
"(",
"self",
".",
"archives",
")",
":",
"self",
".",
"current_file",
"=",
"self",
".",
"archives",
"[",
"self",
".",
"file_index",
"]",
"info_filename",
"=",
"... | Prepares the files for genotype parsing.
:return: None | [
"Prepares",
"the",
"files",
"for",
"genotype",
"parsing",
"."
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L178-L200 |
edwards-lab/libGWAS | libgwas/impute_parser.py | Parser.get_next_line | def get_next_line(self):
"""If we reach the end of the file, we simply open the next, until we \
run out of archives to process"""
line = self.freq_file.readline().strip().split()
if len(line) < 1:
self.load_genotypes()
line = self.freq_file.readline().strip().sp... | python | def get_next_line(self):
"""If we reach the end of the file, we simply open the next, until we \
run out of archives to process"""
line = self.freq_file.readline().strip().split()
if len(line) < 1:
self.load_genotypes()
line = self.freq_file.readline().strip().sp... | [
"def",
"get_next_line",
"(",
"self",
")",
":",
"line",
"=",
"self",
".",
"freq_file",
".",
"readline",
"(",
")",
".",
"strip",
"(",
")",
".",
"split",
"(",
")",
"if",
"len",
"(",
"line",
")",
"<",
"1",
":",
"self",
".",
"load_genotypes",
"(",
")"... | If we reach the end of the file, we simply open the next, until we \
run out of archives to process | [
"If",
"we",
"reach",
"the",
"end",
"of",
"the",
"file",
"we",
"simply",
"open",
"the",
"next",
"until",
"we",
"\\",
"run",
"out",
"of",
"archives",
"to",
"process"
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L202-L213 |
edwards-lab/libGWAS | libgwas/impute_parser.py | Parser.populate_iteration | def populate_iteration(self, iteration):
"""Parse genotypes from the file and iteration with relevant marker \
details.
:param iteration: ParseLocus object which is returned per iteration
:return: True indicates current locus is valid.
StopIteration is thrown if the marker ... | python | def populate_iteration(self, iteration):
"""Parse genotypes from the file and iteration with relevant marker \
details.
:param iteration: ParseLocus object which is returned per iteration
:return: True indicates current locus is valid.
StopIteration is thrown if the marker ... | [
"def",
"populate_iteration",
"(",
"self",
",",
"iteration",
")",
":",
"global",
"encoding",
"line",
",",
"info",
",",
"exp_freq",
"=",
"self",
".",
"get_next_line",
"(",
")",
"if",
"info",
">",
"Parser",
".",
"info_threshold",
":",
"junk",
",",
"iteration"... | Parse genotypes from the file and iteration with relevant marker \
details.
:param iteration: ParseLocus object which is returned per iteration
:return: True indicates current locus is valid.
StopIteration is thrown if the marker reaches the end of the file or
the valid gen... | [
"Parse",
"genotypes",
"from",
"the",
"file",
"and",
"iteration",
"with",
"relevant",
"marker",
"\\",
"details",
"."
] | train | https://github.com/edwards-lab/libGWAS/blob/d68c9a083d443dfa5d7c5112de29010909cfe23f/libgwas/impute_parser.py#L219-L283 |
gdoermann/voicebase | voicebase/api/__init__.py | VoicebaseApi.session | def session(self):
"""
This is what you should use to make requests. It sill authenticate for you.
:return: requests.sessions.Session
"""
if not self._session:
self._session = requests.Session()
self._session.headers.update(dict(Authorization='Bearer {0}'... | python | def session(self):
"""
This is what you should use to make requests. It sill authenticate for you.
:return: requests.sessions.Session
"""
if not self._session:
self._session = requests.Session()
self._session.headers.update(dict(Authorization='Bearer {0}'... | [
"def",
"session",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_session",
":",
"self",
".",
"_session",
"=",
"requests",
".",
"Session",
"(",
")",
"self",
".",
"_session",
".",
"headers",
".",
"update",
"(",
"dict",
"(",
"Authorization",
"=",
"'... | This is what you should use to make requests. It sill authenticate for you.
:return: requests.sessions.Session | [
"This",
"is",
"what",
"you",
"should",
"use",
"to",
"make",
"requests",
".",
"It",
"sill",
"authenticate",
"for",
"you",
".",
":",
"return",
":",
"requests",
".",
"sessions",
".",
"Session"
] | train | https://github.com/gdoermann/voicebase/blob/53cb4735327898a7a284dea3a60ace0b3956a8ec/voicebase/api/__init__.py#L39-L47 |
mayfield/shellish | shellish/command/command.py | parse_docstring | def parse_docstring(entity):
""" Return sanitized docstring from an entity. The first line of the
docstring is the title, and remaining lines are the details, aka git
style. """
doc = inspect.getdoc(entity)
if not doc:
return None, None
doc = doc.splitlines(keepends=True)
if not doc... | python | def parse_docstring(entity):
""" Return sanitized docstring from an entity. The first line of the
docstring is the title, and remaining lines are the details, aka git
style. """
doc = inspect.getdoc(entity)
if not doc:
return None, None
doc = doc.splitlines(keepends=True)
if not doc... | [
"def",
"parse_docstring",
"(",
"entity",
")",
":",
"doc",
"=",
"inspect",
".",
"getdoc",
"(",
"entity",
")",
"if",
"not",
"doc",
":",
"return",
"None",
",",
"None",
"doc",
"=",
"doc",
".",
"splitlines",
"(",
"keepends",
"=",
"True",
")",
"if",
"not",... | Return sanitized docstring from an entity. The first line of the
docstring is the title, and remaining lines are the details, aka git
style. | [
"Return",
"sanitized",
"docstring",
"from",
"an",
"entity",
".",
"The",
"first",
"line",
"of",
"the",
"docstring",
"is",
"the",
"title",
"and",
"remaining",
"lines",
"are",
"the",
"details",
"aka",
"git",
"style",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L16-L30 |
mayfield/shellish | shellish/command/command.py | Command.parse_args | def parse_args(self, argv=None):
""" Return an argparse.Namespace of the argv string or sys.argv if
argv is None. """
arg_input = shlex.split(argv) if argv is not None else None
self.get_or_create_session()
return self.argparser.parse_args(arg_input) | python | def parse_args(self, argv=None):
""" Return an argparse.Namespace of the argv string or sys.argv if
argv is None. """
arg_input = shlex.split(argv) if argv is not None else None
self.get_or_create_session()
return self.argparser.parse_args(arg_input) | [
"def",
"parse_args",
"(",
"self",
",",
"argv",
"=",
"None",
")",
":",
"arg_input",
"=",
"shlex",
".",
"split",
"(",
"argv",
")",
"if",
"argv",
"is",
"not",
"None",
"else",
"None",
"self",
".",
"get_or_create_session",
"(",
")",
"return",
"self",
".",
... | Return an argparse.Namespace of the argv string or sys.argv if
argv is None. | [
"Return",
"an",
"argparse",
".",
"Namespace",
"of",
"the",
"argv",
"string",
"or",
"sys",
".",
"argv",
"if",
"argv",
"is",
"None",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L105-L110 |
mayfield/shellish | shellish/command/command.py | Command.get_pager_spec | def get_pager_spec(self):
""" Find the best pager settings for this command. If the user has
specified overrides in the INI config file we prefer those. """
self_config = self.get_config()
pagercmd = self_config.get('pager')
istty = self_config.getboolean('pager_istty')
... | python | def get_pager_spec(self):
""" Find the best pager settings for this command. If the user has
specified overrides in the INI config file we prefer those. """
self_config = self.get_config()
pagercmd = self_config.get('pager')
istty = self_config.getboolean('pager_istty')
... | [
"def",
"get_pager_spec",
"(",
"self",
")",
":",
"self_config",
"=",
"self",
".",
"get_config",
"(",
")",
"pagercmd",
"=",
"self_config",
".",
"get",
"(",
"'pager'",
")",
"istty",
"=",
"self_config",
".",
"getboolean",
"(",
"'pager_istty'",
")",
"core_config"... | Find the best pager settings for this command. If the user has
specified overrides in the INI config file we prefer those. | [
"Find",
"the",
"best",
"pager",
"settings",
"for",
"this",
"command",
".",
"If",
"the",
"user",
"has",
"specified",
"overrides",
"in",
"the",
"INI",
"config",
"file",
"we",
"prefer",
"those",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L135-L149 |
mayfield/shellish | shellish/command/command.py | Command.run_wrap | def run_wrap(self, args):
""" Wrap some standard protocol around a command's run method. This
wrapper should generally never capture exceptions. It can look at
them and do things but prerun and postrun should always be symmetric.
Any exception suppression should happen in the `session.... | python | def run_wrap(self, args):
""" Wrap some standard protocol around a command's run method. This
wrapper should generally never capture exceptions. It can look at
them and do things but prerun and postrun should always be symmetric.
Any exception suppression should happen in the `session.... | [
"def",
"run_wrap",
"(",
"self",
",",
"args",
")",
":",
"self",
".",
"fire_event",
"(",
"'prerun'",
",",
"args",
")",
"self",
".",
"prerun",
"(",
"args",
")",
"try",
":",
"if",
"self",
".",
"session",
".",
"allow_pager",
"and",
"self",
".",
"use_pager... | Wrap some standard protocol around a command's run method. This
wrapper should generally never capture exceptions. It can look at
them and do things but prerun and postrun should always be symmetric.
Any exception suppression should happen in the `session.execute`. | [
"Wrap",
"some",
"standard",
"protocol",
"around",
"a",
"command",
"s",
"run",
"method",
".",
"This",
"wrapper",
"should",
"generally",
"never",
"capture",
"exceptions",
".",
"It",
"can",
"look",
"at",
"them",
"and",
"do",
"things",
"but",
"prerun",
"and",
... | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L151-L172 |
mayfield/shellish | shellish/command/command.py | Command.config_section | def config_section(self):
""" The string used in a .<ROOT>_config file section. Usually this
is just the full prog name for a command minus the root command. """
names = []
cmd = self
while cmd.parent:
names.append(cmd.name)
cmd = cmd.parent
if no... | python | def config_section(self):
""" The string used in a .<ROOT>_config file section. Usually this
is just the full prog name for a command minus the root command. """
names = []
cmd = self
while cmd.parent:
names.append(cmd.name)
cmd = cmd.parent
if no... | [
"def",
"config_section",
"(",
"self",
")",
":",
"names",
"=",
"[",
"]",
"cmd",
"=",
"self",
"while",
"cmd",
".",
"parent",
":",
"names",
".",
"append",
"(",
"cmd",
".",
"name",
")",
"cmd",
"=",
"cmd",
".",
"parent",
"if",
"not",
"names",
":",
"re... | The string used in a .<ROOT>_config file section. Usually this
is just the full prog name for a command minus the root command. | [
"The",
"string",
"used",
"in",
"a",
".",
"<ROOT",
">",
"_config",
"file",
"section",
".",
"Usually",
"this",
"is",
"just",
"the",
"full",
"prog",
"name",
"for",
"a",
"command",
"minus",
"the",
"root",
"command",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L174-L185 |
mayfield/shellish | shellish/command/command.py | Command.get_config | def get_config(self, section=None):
""" Return the merged end-user configuration for this command or a
specific section if set in `section`. """
config = self.session.config
section = self.config_section() if section is None else section
try:
return config[section]
... | python | def get_config(self, section=None):
""" Return the merged end-user configuration for this command or a
specific section if set in `section`. """
config = self.session.config
section = self.config_section() if section is None else section
try:
return config[section]
... | [
"def",
"get_config",
"(",
"self",
",",
"section",
"=",
"None",
")",
":",
"config",
"=",
"self",
".",
"session",
".",
"config",
"section",
"=",
"self",
".",
"config_section",
"(",
")",
"if",
"section",
"is",
"None",
"else",
"section",
"try",
":",
"retur... | Return the merged end-user configuration for this command or a
specific section if set in `section`. | [
"Return",
"the",
"merged",
"end",
"-",
"user",
"configuration",
"for",
"this",
"command",
"or",
"a",
"specific",
"section",
"if",
"set",
"in",
"section",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L194-L203 |
mayfield/shellish | shellish/command/command.py | Command.parent | def parent(self, parent):
""" Copy context from the parent into this instance as well as
adjusting or depth value to indicate where we exist in a command
tree. """
self._parent = parent
if parent:
pctx = dict((x, getattr(parent, x)) for x in parent.context_keys)
... | python | def parent(self, parent):
""" Copy context from the parent into this instance as well as
adjusting or depth value to indicate where we exist in a command
tree. """
self._parent = parent
if parent:
pctx = dict((x, getattr(parent, x)) for x in parent.context_keys)
... | [
"def",
"parent",
"(",
"self",
",",
"parent",
")",
":",
"self",
".",
"_parent",
"=",
"parent",
"if",
"parent",
":",
"pctx",
"=",
"dict",
"(",
"(",
"x",
",",
"getattr",
"(",
"parent",
",",
"x",
")",
")",
"for",
"x",
"in",
"parent",
".",
"context_ke... | Copy context from the parent into this instance as well as
adjusting or depth value to indicate where we exist in a command
tree. | [
"Copy",
"context",
"from",
"the",
"parent",
"into",
"this",
"instance",
"as",
"well",
"as",
"adjusting",
"or",
"depth",
"value",
"to",
"indicate",
"where",
"we",
"exist",
"in",
"a",
"command",
"tree",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L210-L222 |
mayfield/shellish | shellish/command/command.py | Command.find_root | def find_root(self):
""" Traverse parent refs to top. """
cmd = self
while cmd.parent:
cmd = cmd.parent
return cmd | python | def find_root(self):
""" Traverse parent refs to top. """
cmd = self
while cmd.parent:
cmd = cmd.parent
return cmd | [
"def",
"find_root",
"(",
"self",
")",
":",
"cmd",
"=",
"self",
"while",
"cmd",
".",
"parent",
":",
"cmd",
"=",
"cmd",
".",
"parent",
"return",
"cmd"
] | Traverse parent refs to top. | [
"Traverse",
"parent",
"refs",
"to",
"top",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L224-L229 |
mayfield/shellish | shellish/command/command.py | Command.inject_context | def inject_context(self, __context_dict__=None, **context):
""" Map context dict to this instance as attributes and keep note of
the keys being set so we can pass this along to any subcommands. """
context = context or __context_dict__
self.context_keys |= set(context.keys())
for... | python | def inject_context(self, __context_dict__=None, **context):
""" Map context dict to this instance as attributes and keep note of
the keys being set so we can pass this along to any subcommands. """
context = context or __context_dict__
self.context_keys |= set(context.keys())
for... | [
"def",
"inject_context",
"(",
"self",
",",
"__context_dict__",
"=",
"None",
",",
"*",
"*",
"context",
")",
":",
"context",
"=",
"context",
"or",
"__context_dict__",
"self",
".",
"context_keys",
"|=",
"set",
"(",
"context",
".",
"keys",
"(",
")",
")",
"fo... | Map context dict to this instance as attributes and keep note of
the keys being set so we can pass this along to any subcommands. | [
"Map",
"context",
"dict",
"to",
"this",
"instance",
"as",
"attributes",
"and",
"keep",
"note",
"of",
"the",
"keys",
"being",
"set",
"so",
"we",
"can",
"pass",
"this",
"along",
"to",
"any",
"subcommands",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L231-L239 |
mayfield/shellish | shellish/command/command.py | Command.prog | def prog(self, prog):
""" Update ourself and any of our subcommands. """
self.argparser.prog = prog
fmt = '%s %%s' % prog if prog else '%s'
for command in self.subcommands.values():
command.prog = fmt % command.name
# Rebind autoenv vars with recomputed key.
f... | python | def prog(self, prog):
""" Update ourself and any of our subcommands. """
self.argparser.prog = prog
fmt = '%s %%s' % prog if prog else '%s'
for command in self.subcommands.values():
command.prog = fmt % command.name
# Rebind autoenv vars with recomputed key.
f... | [
"def",
"prog",
"(",
"self",
",",
"prog",
")",
":",
"self",
".",
"argparser",
".",
"prog",
"=",
"prog",
"fmt",
"=",
"'%s %%s'",
"%",
"prog",
"if",
"prog",
"else",
"'%s'",
"for",
"command",
"in",
"self",
".",
"subcommands",
".",
"values",
"(",
")",
"... | Update ourself and any of our subcommands. | [
"Update",
"ourself",
"and",
"any",
"of",
"our",
"subcommands",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L246-L255 |
mayfield/shellish | shellish/command/command.py | Command.depth | def depth(self, value):
""" Update ourself and any of our subcommands. """
for command in self.subcommands.values():
command.depth = value + 1
del command.argparser._defaults[self.arg_label_fmt % self._depth]
command.argparser._defaults[self.arg_label_fmt % value] = c... | python | def depth(self, value):
""" Update ourself and any of our subcommands. """
for command in self.subcommands.values():
command.depth = value + 1
del command.argparser._defaults[self.arg_label_fmt % self._depth]
command.argparser._defaults[self.arg_label_fmt % value] = c... | [
"def",
"depth",
"(",
"self",
",",
"value",
")",
":",
"for",
"command",
"in",
"self",
".",
"subcommands",
".",
"values",
"(",
")",
":",
"command",
".",
"depth",
"=",
"value",
"+",
"1",
"del",
"command",
".",
"argparser",
".",
"_defaults",
"[",
"self",... | Update ourself and any of our subcommands. | [
"Update",
"ourself",
"and",
"any",
"of",
"our",
"subcommands",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L262-L268 |
mayfield/shellish | shellish/command/command.py | Command.add_argument | def add_argument(self, *args, parser=None, autoenv=False, env=None,
complete=None, **kwargs):
""" Allow cleaner action supplementation. Autoenv will generate an
environment variable to be usable as a defaults setter based on the
command name and the dest property of the act... | python | def add_argument(self, *args, parser=None, autoenv=False, env=None,
complete=None, **kwargs):
""" Allow cleaner action supplementation. Autoenv will generate an
environment variable to be usable as a defaults setter based on the
command name and the dest property of the act... | [
"def",
"add_argument",
"(",
"self",
",",
"*",
"args",
",",
"parser",
"=",
"None",
",",
"autoenv",
"=",
"False",
",",
"env",
"=",
"None",
",",
"complete",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"parser",
"is",
"None",
":",
"parser",
... | Allow cleaner action supplementation. Autoenv will generate an
environment variable to be usable as a defaults setter based on the
command name and the dest property of the action. | [
"Allow",
"cleaner",
"action",
"supplementation",
".",
"Autoenv",
"will",
"generate",
"an",
"environment",
"variable",
"to",
"be",
"usable",
"as",
"a",
"defaults",
"setter",
"based",
"on",
"the",
"command",
"name",
"and",
"the",
"dest",
"property",
"of",
"the",... | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L270-L289 |
mayfield/shellish | shellish/command/command.py | Command._make_autoenv | def _make_autoenv(self, action):
""" Generate a suitable env variable for this action. This is
dependant on our subcommand hierarchy. Review the prog setter for
details. """
env = ('%s_%s' % (self.prog, action.dest)).upper()
env = re.sub(self.env_scrub_re, '', env.strip())
... | python | def _make_autoenv(self, action):
""" Generate a suitable env variable for this action. This is
dependant on our subcommand hierarchy. Review the prog setter for
details. """
env = ('%s_%s' % (self.prog, action.dest)).upper()
env = re.sub(self.env_scrub_re, '', env.strip())
... | [
"def",
"_make_autoenv",
"(",
"self",
",",
"action",
")",
":",
"env",
"=",
"(",
"'%s_%s'",
"%",
"(",
"self",
".",
"prog",
",",
"action",
".",
"dest",
")",
")",
".",
"upper",
"(",
")",
"env",
"=",
"re",
".",
"sub",
"(",
"self",
".",
"env_scrub_re",... | Generate a suitable env variable for this action. This is
dependant on our subcommand hierarchy. Review the prog setter for
details. | [
"Generate",
"a",
"suitable",
"env",
"variable",
"for",
"this",
"action",
".",
"This",
"is",
"dependant",
"on",
"our",
"subcommand",
"hierarchy",
".",
"Review",
"the",
"prog",
"setter",
"for",
"details",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L291-L301 |
mayfield/shellish | shellish/command/command.py | Command.add_file_argument | def add_file_argument(self, *args, mode='r', buffering=1,
filetype_options=None, **kwargs):
""" Add a tab-completion safe FileType argument. This argument
differs from a normal argparse.FileType based argument in that the
value is a factory function that returns a file... | python | def add_file_argument(self, *args, mode='r', buffering=1,
filetype_options=None, **kwargs):
""" Add a tab-completion safe FileType argument. This argument
differs from a normal argparse.FileType based argument in that the
value is a factory function that returns a file... | [
"def",
"add_file_argument",
"(",
"self",
",",
"*",
"args",
",",
"mode",
"=",
"'r'",
",",
"buffering",
"=",
"1",
",",
"filetype_options",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"type_",
"=",
"supplement",
".",
"SafeFileType",
"(",
"mode",
"=",
... | Add a tab-completion safe FileType argument. This argument
differs from a normal argparse.FileType based argument in that the
value is a factory function that returns a file handle instead of
providing an already open file handle. There are various reasons
why this is a better approach... | [
"Add",
"a",
"tab",
"-",
"completion",
"safe",
"FileType",
"argument",
".",
"This",
"argument",
"differs",
"from",
"a",
"normal",
"argparse",
".",
"FileType",
"based",
"argument",
"in",
"that",
"the",
"value",
"is",
"a",
"factory",
"function",
"that",
"return... | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L303-L313 |
mayfield/shellish | shellish/command/command.py | Command.create_argparser | def create_argparser(self):
""" Factory for arg parser. Can be overridden as long as it returns
an ArgParser compatible instance. """
if self.desc:
if self.title:
fulldesc = '%s\n\n%s' % (self.title, self.desc)
else:
fulldesc = self.desc
... | python | def create_argparser(self):
""" Factory for arg parser. Can be overridden as long as it returns
an ArgParser compatible instance. """
if self.desc:
if self.title:
fulldesc = '%s\n\n%s' % (self.title, self.desc)
else:
fulldesc = self.desc
... | [
"def",
"create_argparser",
"(",
"self",
")",
":",
"if",
"self",
".",
"desc",
":",
"if",
"self",
".",
"title",
":",
"fulldesc",
"=",
"'%s\\n\\n%s'",
"%",
"(",
"self",
".",
"title",
",",
"self",
".",
"desc",
")",
"else",
":",
"fulldesc",
"=",
"self",
... | Factory for arg parser. Can be overridden as long as it returns
an ArgParser compatible instance. | [
"Factory",
"for",
"arg",
"parser",
".",
"Can",
"be",
"overridden",
"as",
"long",
"as",
"it",
"returns",
"an",
"ArgParser",
"compatible",
"instance",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L320-L331 |
mayfield/shellish | shellish/command/command.py | Command.attach_session | def attach_session(self):
""" Create a session and inject it as context for this command and any
subcommands. """
assert self.session is None
root = self.find_root()
session = self.Session(root)
root.inject_context(session=session)
return session | python | def attach_session(self):
""" Create a session and inject it as context for this command and any
subcommands. """
assert self.session is None
root = self.find_root()
session = self.Session(root)
root.inject_context(session=session)
return session | [
"def",
"attach_session",
"(",
"self",
")",
":",
"assert",
"self",
".",
"session",
"is",
"None",
"root",
"=",
"self",
".",
"find_root",
"(",
")",
"session",
"=",
"self",
".",
"Session",
"(",
"root",
")",
"root",
".",
"inject_context",
"(",
"session",
"=... | Create a session and inject it as context for this command and any
subcommands. | [
"Create",
"a",
"session",
"and",
"inject",
"it",
"as",
"context",
"for",
"this",
"command",
"and",
"any",
"subcommands",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L333-L340 |
mayfield/shellish | shellish/command/command.py | Command.complete | def complete(self, text, line, begin, end):
""" Get and format completer choices. Note that all internal calls to
completer functions must use [frozen]set()s. """
self.fire_event('precomplete', text, line, begin, end)
choices = self._complete(text, line, begin, end)
choices -= s... | python | def complete(self, text, line, begin, end):
""" Get and format completer choices. Note that all internal calls to
completer functions must use [frozen]set()s. """
self.fire_event('precomplete', text, line, begin, end)
choices = self._complete(text, line, begin, end)
choices -= s... | [
"def",
"complete",
"(",
"self",
",",
"text",
",",
"line",
",",
"begin",
",",
"end",
")",
":",
"self",
".",
"fire_event",
"(",
"'precomplete'",
",",
"text",
",",
"line",
",",
"begin",
",",
"end",
")",
"choices",
"=",
"self",
".",
"_complete",
"(",
"... | Get and format completer choices. Note that all internal calls to
completer functions must use [frozen]set()s. | [
"Get",
"and",
"format",
"completer",
"choices",
".",
"Note",
"that",
"all",
"internal",
"calls",
"to",
"completer",
"functions",
"must",
"use",
"[",
"frozen",
"]",
"set",
"()",
"s",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L342-L358 |
mayfield/shellish | shellish/command/command.py | Command._complete | def _complete(self, text, line, begin, end):
""" Do naive argument parsing so the completer has better ability to
understand expansion rules. """
line = line[:end] # Ignore characters following the cursor.
fullargs = self.split_line(line)[1:]
args = fullargs[:]
options =... | python | def _complete(self, text, line, begin, end):
""" Do naive argument parsing so the completer has better ability to
understand expansion rules. """
line = line[:end] # Ignore characters following the cursor.
fullargs = self.split_line(line)[1:]
args = fullargs[:]
options =... | [
"def",
"_complete",
"(",
"self",
",",
"text",
",",
"line",
",",
"begin",
",",
"end",
")",
":",
"line",
"=",
"line",
"[",
":",
"end",
"]",
"# Ignore characters following the cursor.",
"fullargs",
"=",
"self",
".",
"split_line",
"(",
"line",
")",
"[",
"1",... | Do naive argument parsing so the completer has better ability to
understand expansion rules. | [
"Do",
"naive",
"argument",
"parsing",
"so",
"the",
"completer",
"has",
"better",
"ability",
"to",
"understand",
"expansion",
"rules",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L360-L428 |
mayfield/shellish | shellish/command/command.py | Command.split_line | def split_line(self, line):
""" Try to do pure shlex.split unless it can't parse the line. In that
case we trim the input line until shlex can split the args and tack the
unparsable portion on as the last argument. """
remainder = []
while True:
try:
a... | python | def split_line(self, line):
""" Try to do pure shlex.split unless it can't parse the line. In that
case we trim the input line until shlex can split the args and tack the
unparsable portion on as the last argument. """
remainder = []
while True:
try:
a... | [
"def",
"split_line",
"(",
"self",
",",
"line",
")",
":",
"remainder",
"=",
"[",
"]",
"while",
"True",
":",
"try",
":",
"args",
"=",
"shlex",
".",
"split",
"(",
"line",
")",
"except",
"ValueError",
":",
"remainder",
".",
"append",
"(",
"line",
"[",
... | Try to do pure shlex.split unless it can't parse the line. In that
case we trim the input line until shlex can split the args and tack the
unparsable portion on as the last argument. | [
"Try",
"to",
"do",
"pure",
"shlex",
".",
"split",
"unless",
"it",
"can",
"t",
"parse",
"the",
"line",
".",
"In",
"that",
"case",
"we",
"trim",
"the",
"input",
"line",
"until",
"shlex",
"can",
"split",
"the",
"args",
"and",
"tack",
"the",
"unparsable",
... | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L430-L444 |
mayfield/shellish | shellish/command/command.py | Command.get_commands_from | def get_commands_from(self, args):
""" We have to code the key names for each depth. This method scans
for each level and returns a list of the command arguments. """
commands = []
for i in itertools.count(0):
try:
commands.append(getattr(args, self.arg_label... | python | def get_commands_from(self, args):
""" We have to code the key names for each depth. This method scans
for each level and returns a list of the command arguments. """
commands = []
for i in itertools.count(0):
try:
commands.append(getattr(args, self.arg_label... | [
"def",
"get_commands_from",
"(",
"self",
",",
"args",
")",
":",
"commands",
"=",
"[",
"]",
"for",
"i",
"in",
"itertools",
".",
"count",
"(",
"0",
")",
":",
"try",
":",
"commands",
".",
"append",
"(",
"getattr",
"(",
"args",
",",
"self",
".",
"arg_l... | We have to code the key names for each depth. This method scans
for each level and returns a list of the command arguments. | [
"We",
"have",
"to",
"code",
"the",
"key",
"names",
"for",
"each",
"depth",
".",
"This",
"method",
"scans",
"for",
"each",
"level",
"and",
"returns",
"a",
"list",
"of",
"the",
"command",
"arguments",
"."
] | train | https://github.com/mayfield/shellish/blob/df0f0e4612d138c34d8cb99b66ab5b8e47f1414a/shellish/command/command.py#L458-L467 |
Met48/inibin | inibin/util.py | _take_bits | def _take_bits(buf, count):
"""Return the booleans that were packed into bytes."""
# TODO: Verify output
bytes_count = (count + 7) // 8
bytes_mod = count % 8
data = _unpack_from(buf, 'B', bytes_count)
values = []
for i, byte in enumerate(data):
for _ in range(8 if i != bytes_count -... | python | def _take_bits(buf, count):
"""Return the booleans that were packed into bytes."""
# TODO: Verify output
bytes_count = (count + 7) // 8
bytes_mod = count % 8
data = _unpack_from(buf, 'B', bytes_count)
values = []
for i, byte in enumerate(data):
for _ in range(8 if i != bytes_count -... | [
"def",
"_take_bits",
"(",
"buf",
",",
"count",
")",
":",
"# TODO: Verify output",
"bytes_count",
"=",
"(",
"count",
"+",
"7",
")",
"//",
"8",
"bytes_mod",
"=",
"count",
"%",
"8",
"data",
"=",
"_unpack_from",
"(",
"buf",
",",
"'B'",
",",
"bytes_count",
... | Return the booleans that were packed into bytes. | [
"Return",
"the",
"booleans",
"that",
"were",
"packed",
"into",
"bytes",
"."
] | train | https://github.com/Met48/inibin/blob/6abfeb22cfc6750fc95abe395cf6bd024a04f394/inibin/util.py#L3-L16 |
Met48/inibin | inibin/util.py | _fix_keys | def _fix_keys(key_mapping, inibin, string_table=None):
"""
Return a human-readable dictionary from the inibin.
Arguments:
key_mapping -- Dictionary used for conversion. Supports nesting. Every other
value should be a numeric inibin key, or a tuple of the key and a
function to apply to t... | python | def _fix_keys(key_mapping, inibin, string_table=None):
"""
Return a human-readable dictionary from the inibin.
Arguments:
key_mapping -- Dictionary used for conversion. Supports nesting. Every other
value should be a numeric inibin key, or a tuple of the key and a
function to apply to t... | [
"def",
"_fix_keys",
"(",
"key_mapping",
",",
"inibin",
",",
"string_table",
"=",
"None",
")",
":",
"if",
"string_table",
"is",
"None",
":",
"string_table",
"=",
"{",
"}",
"def",
"walk",
"(",
"node",
",",
"out_node",
")",
":",
"# Walk the nodes of the key map... | Return a human-readable dictionary from the inibin.
Arguments:
key_mapping -- Dictionary used for conversion. Supports nesting. Every other
value should be a numeric inibin key, or a tuple of the key and a
function to apply to the result.
inibin -- The dictionary returned from reading an in... | [
"Return",
"a",
"human",
"-",
"readable",
"dictionary",
"from",
"the",
"inibin",
"."
] | train | https://github.com/Met48/inibin/blob/6abfeb22cfc6750fc95abe395cf6bd024a04f394/inibin/util.py#L19-L80 |
Met48/inibin | inibin/util.py | _unpack_from | def _unpack_from(buf, format_s, count=None, little_endian=True):
"""Read a binary format from the buffer."""
if count is not None:
assert count > 0
format_s = '%i%s' % (count, format_s)
if little_endian is True:
format_s = '<' + format_s
else:
format_s = '>' + format_s
... | python | def _unpack_from(buf, format_s, count=None, little_endian=True):
"""Read a binary format from the buffer."""
if count is not None:
assert count > 0
format_s = '%i%s' % (count, format_s)
if little_endian is True:
format_s = '<' + format_s
else:
format_s = '>' + format_s
... | [
"def",
"_unpack_from",
"(",
"buf",
",",
"format_s",
",",
"count",
"=",
"None",
",",
"little_endian",
"=",
"True",
")",
":",
"if",
"count",
"is",
"not",
"None",
":",
"assert",
"count",
">",
"0",
"format_s",
"=",
"'%i%s'",
"%",
"(",
"count",
",",
"form... | Read a binary format from the buffer. | [
"Read",
"a",
"binary",
"format",
"from",
"the",
"buffer",
"."
] | train | https://github.com/Met48/inibin/blob/6abfeb22cfc6750fc95abe395cf6bd024a04f394/inibin/util.py#L83-L101 |
mrstephenneal/dirutility | dirutility/permissions.py | make_octal_permissions_mode | def make_octal_permissions_mode(user=(False, False, False), group=(False, False, False), other=(False, False, False)):
"""
Create a permissions bit in absolute notation (octal).
The user, group and other parameters are tuples representing Read, Write and Execute values.
All are set disallowed (set to f... | python | def make_octal_permissions_mode(user=(False, False, False), group=(False, False, False), other=(False, False, False)):
"""
Create a permissions bit in absolute notation (octal).
The user, group and other parameters are tuples representing Read, Write and Execute values.
All are set disallowed (set to f... | [
"def",
"make_octal_permissions_mode",
"(",
"user",
"=",
"(",
"False",
",",
"False",
",",
"False",
")",
",",
"group",
"=",
"(",
"False",
",",
"False",
",",
"False",
")",
",",
"other",
"=",
"(",
"False",
",",
"False",
",",
"False",
")",
")",
":",
"# ... | Create a permissions bit in absolute notation (octal).
The user, group and other parameters are tuples representing Read, Write and Execute values.
All are set disallowed (set to false) by default and can be individually permitted.
:param user: User permissions
:param group: Group permissions
:par... | [
"Create",
"a",
"permissions",
"bit",
"in",
"absolute",
"notation",
"(",
"octal",
")",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L32-L79 |
mrstephenneal/dirutility | dirutility/permissions.py | set_permissions_mode_from_octal | def set_permissions_mode_from_octal(file_path, code):
"""
Set permissions for a file or directory.
:param file_path: Path to a file or directory
:param code: Permission code in absolute notation (octal)
:return:
"""
# Unpack permissions tuple
user, group, other = tuple(str(code[-3:])) i... | python | def set_permissions_mode_from_octal(file_path, code):
"""
Set permissions for a file or directory.
:param file_path: Path to a file or directory
:param code: Permission code in absolute notation (octal)
:return:
"""
# Unpack permissions tuple
user, group, other = tuple(str(code[-3:])) i... | [
"def",
"set_permissions_mode_from_octal",
"(",
"file_path",
",",
"code",
")",
":",
"# Unpack permissions tuple",
"user",
",",
"group",
",",
"other",
"=",
"tuple",
"(",
"str",
"(",
"code",
"[",
"-",
"3",
":",
"]",
")",
")",
"if",
"len",
"(",
"str",
"(",
... | Set permissions for a file or directory.
:param file_path: Path to a file or directory
:param code: Permission code in absolute notation (octal)
:return: | [
"Set",
"permissions",
"for",
"a",
"file",
"or",
"directory",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L82-L95 |
mrstephenneal/dirutility | dirutility/permissions.py | get_permissions_mode | def get_permissions_mode(permission_octal, name):
"""Retrieve a user name group permissions bitwise code."""
read = PERMISSIONS[name]['read']
write = PERMISSIONS[name]['write']
execute = PERMISSIONS[name]['execute']
# Read
if permission_octal == 4:
return read & ~write & ~execute
#... | python | def get_permissions_mode(permission_octal, name):
"""Retrieve a user name group permissions bitwise code."""
read = PERMISSIONS[name]['read']
write = PERMISSIONS[name]['write']
execute = PERMISSIONS[name]['execute']
# Read
if permission_octal == 4:
return read & ~write & ~execute
#... | [
"def",
"get_permissions_mode",
"(",
"permission_octal",
",",
"name",
")",
":",
"read",
"=",
"PERMISSIONS",
"[",
"name",
"]",
"[",
"'read'",
"]",
"write",
"=",
"PERMISSIONS",
"[",
"name",
"]",
"[",
"'write'",
"]",
"execute",
"=",
"PERMISSIONS",
"[",
"name",... | Retrieve a user name group permissions bitwise code. | [
"Retrieve",
"a",
"user",
"name",
"group",
"permissions",
"bitwise",
"code",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L98-L134 |
mrstephenneal/dirutility | dirutility/permissions.py | Permissions.allow | def allow(self, privilege):
"""Add an allowed privilege (read, write, execute, all)."""
assert privilege in PERMISSIONS['user'].keys()
reading = PERMISSIONS['user'][privilege] + PERMISSIONS['group'][privilege] + PERMISSIONS['other'][privilege]
os.chmod(self.file_path, reading) | python | def allow(self, privilege):
"""Add an allowed privilege (read, write, execute, all)."""
assert privilege in PERMISSIONS['user'].keys()
reading = PERMISSIONS['user'][privilege] + PERMISSIONS['group'][privilege] + PERMISSIONS['other'][privilege]
os.chmod(self.file_path, reading) | [
"def",
"allow",
"(",
"self",
",",
"privilege",
")",
":",
"assert",
"privilege",
"in",
"PERMISSIONS",
"[",
"'user'",
"]",
".",
"keys",
"(",
")",
"reading",
"=",
"PERMISSIONS",
"[",
"'user'",
"]",
"[",
"privilege",
"]",
"+",
"PERMISSIONS",
"[",
"'group'",
... | Add an allowed privilege (read, write, execute, all). | [
"Add",
"an",
"allowed",
"privilege",
"(",
"read",
"write",
"execute",
"all",
")",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L146-L150 |
mrstephenneal/dirutility | dirutility/permissions.py | Permissions.allow_rwe | def allow_rwe(self, name):
"""Allow all privileges for a particular name group (user, group, other)."""
assert name in PERMISSIONS.keys()
os.chmod(self.file_path, PERMISSIONS[name]['all']) | python | def allow_rwe(self, name):
"""Allow all privileges for a particular name group (user, group, other)."""
assert name in PERMISSIONS.keys()
os.chmod(self.file_path, PERMISSIONS[name]['all']) | [
"def",
"allow_rwe",
"(",
"self",
",",
"name",
")",
":",
"assert",
"name",
"in",
"PERMISSIONS",
".",
"keys",
"(",
")",
"os",
".",
"chmod",
"(",
"self",
".",
"file_path",
",",
"PERMISSIONS",
"[",
"name",
"]",
"[",
"'all'",
"]",
")"
] | Allow all privileges for a particular name group (user, group, other). | [
"Allow",
"all",
"privileges",
"for",
"a",
"particular",
"name",
"group",
"(",
"user",
"group",
"other",
")",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L156-L159 |
mrstephenneal/dirutility | dirutility/permissions.py | Permissions.revoke_access | def revoke_access(self):
"""Revoke all access to this path."""
reading = PERMISSIONS['user']['execute'] + PERMISSIONS['group']['execute'] + PERMISSIONS['other']['execute']
os.chmod(self.file_path, reading) | python | def revoke_access(self):
"""Revoke all access to this path."""
reading = PERMISSIONS['user']['execute'] + PERMISSIONS['group']['execute'] + PERMISSIONS['other']['execute']
os.chmod(self.file_path, reading) | [
"def",
"revoke_access",
"(",
"self",
")",
":",
"reading",
"=",
"PERMISSIONS",
"[",
"'user'",
"]",
"[",
"'execute'",
"]",
"+",
"PERMISSIONS",
"[",
"'group'",
"]",
"[",
"'execute'",
"]",
"+",
"PERMISSIONS",
"[",
"'other'",
"]",
"[",
"'execute'",
"]",
"os",... | Revoke all access to this path. | [
"Revoke",
"all",
"access",
"to",
"this",
"path",
"."
] | train | https://github.com/mrstephenneal/dirutility/blob/339378659e2d7e09c53acfc51c5df745bb0cd517/dirutility/permissions.py#L161-L164 |
donovan-duplessis/pwnurl | pwnurl/common/helpers.py | timestamp | def timestamp(format=DATEFMT, timezone='Africa/Johannesburg'):
""" Return current datetime with timezone applied
[all timezones] print sorted(pytz.all_timezones) """
return formatdate(datetime.now(tz=pytz.timezone(timezone))) | python | def timestamp(format=DATEFMT, timezone='Africa/Johannesburg'):
""" Return current datetime with timezone applied
[all timezones] print sorted(pytz.all_timezones) """
return formatdate(datetime.now(tz=pytz.timezone(timezone))) | [
"def",
"timestamp",
"(",
"format",
"=",
"DATEFMT",
",",
"timezone",
"=",
"'Africa/Johannesburg'",
")",
":",
"return",
"formatdate",
"(",
"datetime",
".",
"now",
"(",
"tz",
"=",
"pytz",
".",
"timezone",
"(",
"timezone",
")",
")",
")"
] | Return current datetime with timezone applied
[all timezones] print sorted(pytz.all_timezones) | [
"Return",
"current",
"datetime",
"with",
"timezone",
"applied",
"[",
"all",
"timezones",
"]",
"print",
"sorted",
"(",
"pytz",
".",
"all_timezones",
")"
] | train | https://github.com/donovan-duplessis/pwnurl/blob/a13e27694f738228d186ea437b4d15ef5a925a87/pwnurl/common/helpers.py#L19-L23 |
donovan-duplessis/pwnurl | pwnurl/common/helpers.py | module_functions | def module_functions(modulestr):
""" Return ordered dictionary of all functions declared in module """
funcs = dict(inspect.getmembers(import_module(modulestr),
inspect.isfunction))
return OrderedDict(sorted(funcs.items(), key=lambda f: f[0])) | python | def module_functions(modulestr):
""" Return ordered dictionary of all functions declared in module """
funcs = dict(inspect.getmembers(import_module(modulestr),
inspect.isfunction))
return OrderedDict(sorted(funcs.items(), key=lambda f: f[0])) | [
"def",
"module_functions",
"(",
"modulestr",
")",
":",
"funcs",
"=",
"dict",
"(",
"inspect",
".",
"getmembers",
"(",
"import_module",
"(",
"modulestr",
")",
",",
"inspect",
".",
"isfunction",
")",
")",
"return",
"OrderedDict",
"(",
"sorted",
"(",
"funcs",
... | Return ordered dictionary of all functions declared in module | [
"Return",
"ordered",
"dictionary",
"of",
"all",
"functions",
"declared",
"in",
"module"
] | train | https://github.com/donovan-duplessis/pwnurl/blob/a13e27694f738228d186ea437b4d15ef5a925a87/pwnurl/common/helpers.py#L32-L38 |
donovan-duplessis/pwnurl | pwnurl/common/helpers.py | flash_errors | def flash_errors(form, category='warning'):
""" Flash all form error messages """
for (field, errors) in form.errors.items():
for error in errors:
flash('{0} - {1}'.format(getattr(form, field).label.text, error),
category) | python | def flash_errors(form, category='warning'):
""" Flash all form error messages """
for (field, errors) in form.errors.items():
for error in errors:
flash('{0} - {1}'.format(getattr(form, field).label.text, error),
category) | [
"def",
"flash_errors",
"(",
"form",
",",
"category",
"=",
"'warning'",
")",
":",
"for",
"(",
"field",
",",
"errors",
")",
"in",
"form",
".",
"errors",
".",
"items",
"(",
")",
":",
"for",
"error",
"in",
"errors",
":",
"flash",
"(",
"'{0} - {1}'",
".",... | Flash all form error messages | [
"Flash",
"all",
"form",
"error",
"messages"
] | train | https://github.com/donovan-duplessis/pwnurl/blob/a13e27694f738228d186ea437b4d15ef5a925a87/pwnurl/common/helpers.py#L41-L47 |
BlackEarth/bf | bf/scss.py | SCSS.render_css | def render_css(self, fn=None, text=None, margin='', indent='\t'):
"""output css using the Sass processor"""
fn = fn or os.path.splitext(self.fn)[0]+'.css'
if not os.path.exists(os.path.dirname(fn)):
os.makedirs(os.path.dirname(fn))
curdir = os.path.abspath(os.curdir)
... | python | def render_css(self, fn=None, text=None, margin='', indent='\t'):
"""output css using the Sass processor"""
fn = fn or os.path.splitext(self.fn)[0]+'.css'
if not os.path.exists(os.path.dirname(fn)):
os.makedirs(os.path.dirname(fn))
curdir = os.path.abspath(os.curdir)
... | [
"def",
"render_css",
"(",
"self",
",",
"fn",
"=",
"None",
",",
"text",
"=",
"None",
",",
"margin",
"=",
"''",
",",
"indent",
"=",
"'\\t'",
")",
":",
"fn",
"=",
"fn",
"or",
"os",
".",
"path",
".",
"splitext",
"(",
"self",
".",
"fn",
")",
"[",
... | output css using the Sass processor | [
"output",
"css",
"using",
"the",
"Sass",
"processor"
] | train | https://github.com/BlackEarth/bf/blob/376041168874bbd6dee5ccfeece4a9e553223316/bf/scss.py#L13-L23 |
universalcore/unicore.hub.client | unicore/hub/client/userclient.py | User.get | def get(self, field):
"""
Returns the value of a user field.
:param str field:
The name of the user field.
:returns: str -- the value
"""
if field in ('username', 'uuid', 'app_data'):
return self.data[field]
else:
return self.d... | python | def get(self, field):
"""
Returns the value of a user field.
:param str field:
The name of the user field.
:returns: str -- the value
"""
if field in ('username', 'uuid', 'app_data'):
return self.data[field]
else:
return self.d... | [
"def",
"get",
"(",
"self",
",",
"field",
")",
":",
"if",
"field",
"in",
"(",
"'username'",
",",
"'uuid'",
",",
"'app_data'",
")",
":",
"return",
"self",
".",
"data",
"[",
"field",
"]",
"else",
":",
"return",
"self",
".",
"data",
".",
"get",
"(",
... | Returns the value of a user field.
:param str field:
The name of the user field.
:returns: str -- the value | [
"Returns",
"the",
"value",
"of",
"a",
"user",
"field",
"."
] | train | https://github.com/universalcore/unicore.hub.client/blob/c706f4d31e493bd4e7ea8236780a9b271b850b8b/unicore/hub/client/userclient.py#L79-L90 |
csaez/wishlib | wishlib/si/siwrapper.py | SIWrapper.auto_update | def auto_update(cls, function):
"""
This class method could be used as decorator on subclasses, it ensures
update method is called after function execution.
"""
def wrapper(self, *args, **kwargs):
f = function(self, *args, **kwargs)
self.update()
... | python | def auto_update(cls, function):
"""
This class method could be used as decorator on subclasses, it ensures
update method is called after function execution.
"""
def wrapper(self, *args, **kwargs):
f = function(self, *args, **kwargs)
self.update()
... | [
"def",
"auto_update",
"(",
"cls",
",",
"function",
")",
":",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"f",
"=",
"function",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"up... | This class method could be used as decorator on subclasses, it ensures
update method is called after function execution. | [
"This",
"class",
"method",
"could",
"be",
"used",
"as",
"decorator",
"on",
"subclasses",
"it",
"ensures",
"update",
"method",
"is",
"called",
"after",
"function",
"execution",
"."
] | train | https://github.com/csaez/wishlib/blob/c212fa7875006a332a4cefbf69885ced9647bc2f/wishlib/si/siwrapper.py#L69-L79 |
csaez/wishlib | wishlib/si/siwrapper.py | SIWrapper.update | def update(self):
"""
This method should be called when you want to ensure all cached attributes
are in sync with the actual object attributes at runtime.
This happens because attributes could store mutable objects and be
modified outside the scope of this class.
The most... | python | def update(self):
"""
This method should be called when you want to ensure all cached attributes
are in sync with the actual object attributes at runtime.
This happens because attributes could store mutable objects and be
modified outside the scope of this class.
The most... | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"holder",
"=",
"siget",
"(",
"self",
".",
"holder",
".",
"FullName",
")",
"# fix dispatch issues",
"for",
"key",
",",
"value",
"in",
"self",
".",
"__dict__",
".",
"iteritems",
"(",
")",
":",
"key",
... | This method should be called when you want to ensure all cached attributes
are in sync with the actual object attributes at runtime.
This happens because attributes could store mutable objects and be
modified outside the scope of this class.
The most common idiom that isn't automagically... | [
"This",
"method",
"should",
"be",
"called",
"when",
"you",
"want",
"to",
"ensure",
"all",
"cached",
"attributes",
"are",
"in",
"sync",
"with",
"the",
"actual",
"object",
"attributes",
"at",
"runtime",
".",
"This",
"happens",
"because",
"attributes",
"could",
... | train | https://github.com/csaez/wishlib/blob/c212fa7875006a332a4cefbf69885ced9647bc2f/wishlib/si/siwrapper.py#L108-L126 |
csaez/wishlib | wishlib/si/siwrapper.py | SIWrapper._validate_key | def _validate_key(self, key):
"""Returns a boolean indicating if the attribute name is valid or not"""
return not any([key.startswith(i) for i in self.EXCEPTIONS]) | python | def _validate_key(self, key):
"""Returns a boolean indicating if the attribute name is valid or not"""
return not any([key.startswith(i) for i in self.EXCEPTIONS]) | [
"def",
"_validate_key",
"(",
"self",
",",
"key",
")",
":",
"return",
"not",
"any",
"(",
"[",
"key",
".",
"startswith",
"(",
"i",
")",
"for",
"i",
"in",
"self",
".",
"EXCEPTIONS",
"]",
")"
] | Returns a boolean indicating if the attribute name is valid or not | [
"Returns",
"a",
"boolean",
"indicating",
"if",
"the",
"attribute",
"name",
"is",
"valid",
"or",
"not"
] | train | https://github.com/csaez/wishlib/blob/c212fa7875006a332a4cefbf69885ced9647bc2f/wishlib/si/siwrapper.py#L128-L130 |
webadmin87/midnight | midnight_main/views.py | pages | def pages(request, path=None, instance=None):
"""
Представление для отображения текстовых страниц
:param request: запрос
:param path: адрес
:param instance: страница
:return:
"""
if instance and instance.active:
p = instance
else:
raise Http404()
return render(r... | python | def pages(request, path=None, instance=None):
"""
Представление для отображения текстовых страниц
:param request: запрос
:param path: адрес
:param instance: страница
:return:
"""
if instance and instance.active:
p = instance
else:
raise Http404()
return render(r... | [
"def",
"pages",
"(",
"request",
",",
"path",
"=",
"None",
",",
"instance",
"=",
"None",
")",
":",
"if",
"instance",
"and",
"instance",
".",
"active",
":",
"p",
"=",
"instance",
"else",
":",
"raise",
"Http404",
"(",
")",
"return",
"render",
"(",
"requ... | Представление для отображения текстовых страниц
:param request: запрос
:param path: адрес
:param instance: страница
:return: | [
"Представление",
"для",
"отображения",
"текстовых",
"страниц",
":",
"param",
"request",
":",
"запрос",
":",
"param",
"path",
":",
"адрес",
":",
"param",
"instance",
":",
"страница",
":",
"return",
":"
] | train | https://github.com/webadmin87/midnight/blob/b60b3b257b4d633550b82a692f3ea3756c62a0a9/midnight_main/views.py#L39-L53 |
webadmin87/midnight | midnight_main/views.py | main_page | def main_page(request):
"""
Представление для отображения главной страницы
:param request: запрос
:return:
"""
p = get_object_or_404(Page, slug='main', active=True)
return render(request, p.tpl, get_page_tpl_ctx(p, request)) | python | def main_page(request):
"""
Представление для отображения главной страницы
:param request: запрос
:return:
"""
p = get_object_or_404(Page, slug='main', active=True)
return render(request, p.tpl, get_page_tpl_ctx(p, request)) | [
"def",
"main_page",
"(",
"request",
")",
":",
"p",
"=",
"get_object_or_404",
"(",
"Page",
",",
"slug",
"=",
"'main'",
",",
"active",
"=",
"True",
")",
"return",
"render",
"(",
"request",
",",
"p",
".",
"tpl",
",",
"get_page_tpl_ctx",
"(",
"p",
",",
"... | Представление для отображения главной страницы
:param request: запрос
:return: | [
"Представление",
"для",
"отображения",
"главной",
"страницы",
":",
"param",
"request",
":",
"запрос",
":",
"return",
":"
] | train | https://github.com/webadmin87/midnight/blob/b60b3b257b4d633550b82a692f3ea3756c62a0a9/midnight_main/views.py#L56-L63 |
pavelsof/ipalint | ipalint/cli.py | Cli.run | def run(self, raw_args=None):
"""
Parses the given arguments (if these are None, then argparse's parser
defaults to parsing sys.argv), inits a Core instance, calls its lint
method with the respective arguments, and then exits.
"""
args = self.parser.parse_args(raw_args)
core = Core()
try:
report = ... | python | def run(self, raw_args=None):
"""
Parses the given arguments (if these are None, then argparse's parser
defaults to parsing sys.argv), inits a Core instance, calls its lint
method with the respective arguments, and then exits.
"""
args = self.parser.parse_args(raw_args)
core = Core()
try:
report = ... | [
"def",
"run",
"(",
"self",
",",
"raw_args",
"=",
"None",
")",
":",
"args",
"=",
"self",
".",
"parser",
".",
"parse_args",
"(",
"raw_args",
")",
"core",
"=",
"Core",
"(",
")",
"try",
":",
"report",
"=",
"core",
".",
"lint",
"(",
"*",
"*",
"vars",
... | Parses the given arguments (if these are None, then argparse's parser
defaults to parsing sys.argv), inits a Core instance, calls its lint
method with the respective arguments, and then exits. | [
"Parses",
"the",
"given",
"arguments",
"(",
"if",
"these",
"are",
"None",
"then",
"argparse",
"s",
"parser",
"defaults",
"to",
"parsing",
"sys",
".",
"argv",
")",
"inits",
"a",
"Core",
"instance",
"calls",
"its",
"lint",
"method",
"with",
"the",
"respectiv... | train | https://github.com/pavelsof/ipalint/blob/763e5979ede6980cbfc746b06fd007b379762eeb/ipalint/cli.py#L63-L79 |
gdoermann/voicebase | voicebase/api/access.py | AccessEndpoint.get_user | def get_user(self, user_id):
"""
Details for a specific user.
Will pull from cached users first, or get and add to cached users.
:param username: the username or userId of the user
:return: VoicebaseUser
"""
if user_id in self._users:
return self._user... | python | def get_user(self, user_id):
"""
Details for a specific user.
Will pull from cached users first, or get and add to cached users.
:param username: the username or userId of the user
:return: VoicebaseUser
"""
if user_id in self._users:
return self._user... | [
"def",
"get_user",
"(",
"self",
",",
"user_id",
")",
":",
"if",
"user_id",
"in",
"self",
".",
"_users",
":",
"return",
"self",
".",
"_users",
".",
"get",
"(",
"user_id",
")",
"else",
":",
"# Load user",
"# Save user in cache",
"return"
] | Details for a specific user.
Will pull from cached users first, or get and add to cached users.
:param username: the username or userId of the user
:return: VoicebaseUser | [
"Details",
"for",
"a",
"specific",
"user",
".",
"Will",
"pull",
"from",
"cached",
"users",
"first",
"or",
"get",
"and",
"add",
"to",
"cached",
"users",
".",
":",
"param",
"username",
":",
"the",
"username",
"or",
"userId",
"of",
"the",
"user",
":",
"re... | train | https://github.com/gdoermann/voicebase/blob/53cb4735327898a7a284dea3a60ace0b3956a8ec/voicebase/api/access.py#L103-L115 |
jalanb/pysyte | pysyte/colours/colour_numbers.py | _extract_html_hex | def _extract_html_hex(string):
"""Get the first 3 or 6 hex digits in the string"""
try:
hex_string = string and _hex_regexp().search(string).group(0) or ''
except AttributeError:
return None
if len(hex_string) == 3:
hex_string = hex_string[0] * 2 + hex_string[1] * 2 + hex_string[... | python | def _extract_html_hex(string):
"""Get the first 3 or 6 hex digits in the string"""
try:
hex_string = string and _hex_regexp().search(string).group(0) or ''
except AttributeError:
return None
if len(hex_string) == 3:
hex_string = hex_string[0] * 2 + hex_string[1] * 2 + hex_string[... | [
"def",
"_extract_html_hex",
"(",
"string",
")",
":",
"try",
":",
"hex_string",
"=",
"string",
"and",
"_hex_regexp",
"(",
")",
".",
"search",
"(",
"string",
")",
".",
"group",
"(",
"0",
")",
"or",
"''",
"except",
"AttributeError",
":",
"return",
"None",
... | Get the first 3 or 6 hex digits in the string | [
"Get",
"the",
"first",
"3",
"or",
"6",
"hex",
"digits",
"in",
"the",
"string"
] | train | https://github.com/jalanb/pysyte/blob/4e278101943d1ceb1a6bcaf6ddc72052ecf13114/pysyte/colours/colour_numbers.py#L71-L79 |
jalanb/pysyte | pysyte/colours/colour_numbers.py | name_to_int | def name_to_int(name):
"""Get a number for that colour name
if not a name, then not a number
"""
if not name:
return float('nan')
lower = name.lower()
cga_names = {s: i for i, s in enumerate(colour_names.cga())}
return cga_names.get(lower) or html_to_small_ansi(lower) | python | def name_to_int(name):
"""Get a number for that colour name
if not a name, then not a number
"""
if not name:
return float('nan')
lower = name.lower()
cga_names = {s: i for i, s in enumerate(colour_names.cga())}
return cga_names.get(lower) or html_to_small_ansi(lower) | [
"def",
"name_to_int",
"(",
"name",
")",
":",
"if",
"not",
"name",
":",
"return",
"float",
"(",
"'nan'",
")",
"lower",
"=",
"name",
".",
"lower",
"(",
")",
"cga_names",
"=",
"{",
"s",
":",
"i",
"for",
"i",
",",
"s",
"in",
"enumerate",
"(",
"colour... | Get a number for that colour name
if not a name, then not a number | [
"Get",
"a",
"number",
"for",
"that",
"colour",
"name"
] | train | https://github.com/jalanb/pysyte/blob/4e278101943d1ceb1a6bcaf6ddc72052ecf13114/pysyte/colours/colour_numbers.py#L180-L189 |
shuge/helper_uri | helper_uri/__init__.py | HelperURI.urljoin | def urljoin(end_with_slash, *args):
"""
>>> HelperURI.urljoin(False, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload'
>>> HelperURI.urljoin(True, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload/'
"""
las... | python | def urljoin(end_with_slash, *args):
"""
>>> HelperURI.urljoin(False, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload'
>>> HelperURI.urljoin(True, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload/'
"""
las... | [
"def",
"urljoin",
"(",
"end_with_slash",
",",
"*",
"args",
")",
":",
"last",
"=",
"args",
"[",
"0",
"]",
"for",
"i",
"in",
"args",
"[",
"1",
":",
"]",
":",
"last",
"=",
"'%s/%s'",
"%",
"(",
"last",
".",
"strip",
"(",
"'/'",
")",
",",
"i",
"."... | >>> HelperURI.urljoin(False, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload'
>>> HelperURI.urljoin(True, *('http://127.0.0.1:8000', 'dumb_upload'))
'http://127.0.0.1:8000/dumb_upload/' | [
">>>",
"HelperURI",
".",
"urljoin",
"(",
"False",
"*",
"(",
"http",
":",
"//",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000",
"dumb_upload",
"))",
"http",
":",
"//",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000",
"/",
"dumb_upload"
] | train | https://github.com/shuge/helper_uri/blob/f64da47334bc07713f35cd1b6fdc163f0b0e3bbe/helper_uri/__init__.py#L28-L43 |
shuge/helper_uri | helper_uri/__init__.py | HelperURI.path2full_uri | def path2full_uri(path, prefix=None, default_protocol='http', end_with_slash=True):
"""
>>> HelperURI.path2full_uri(path='127.0.0.1:8000', end_with_slash=False)
'http://127.0.0.1:8000'
>>> HelperURI.path2full_uri(path='/api', prefix='192.168.1.100', end_with_slash=False)
'http:/... | python | def path2full_uri(path, prefix=None, default_protocol='http', end_with_slash=True):
"""
>>> HelperURI.path2full_uri(path='127.0.0.1:8000', end_with_slash=False)
'http://127.0.0.1:8000'
>>> HelperURI.path2full_uri(path='/api', prefix='192.168.1.100', end_with_slash=False)
'http:/... | [
"def",
"path2full_uri",
"(",
"path",
",",
"prefix",
"=",
"None",
",",
"default_protocol",
"=",
"'http'",
",",
"end_with_slash",
"=",
"True",
")",
":",
"if",
"path",
".",
"startswith",
"(",
"'http'",
")",
":",
"return",
"path",
"if",
"prefix",
":",
"if",
... | >>> HelperURI.path2full_uri(path='127.0.0.1:8000', end_with_slash=False)
'http://127.0.0.1:8000'
>>> HelperURI.path2full_uri(path='/api', prefix='192.168.1.100', end_with_slash=False)
'http://192.168.1.100/api'
>>> HelperURI.path2full_uri(path='/api/v1', prefix='192.168.1.100', default... | [
">>>",
"HelperURI",
".",
"path2full_uri",
"(",
"path",
"=",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000",
"end_with_slash",
"=",
"False",
")",
"http",
":",
"//",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000"
] | train | https://github.com/shuge/helper_uri/blob/f64da47334bc07713f35cd1b6fdc163f0b0e3bbe/helper_uri/__init__.py#L46-L72 |
antonev/authorizeme | authorizeme.py | Authorization.add_rule | def add_rule(self, rule_class, target_class=_Nothing):
"""Adds an authorization rule.
:param rule_class: a class of authorization rule.
:param target_class: (optional) a class
or an iterable with classes to associate the rule with.
"""
if isinstance(target_class, Ite... | python | def add_rule(self, rule_class, target_class=_Nothing):
"""Adds an authorization rule.
:param rule_class: a class of authorization rule.
:param target_class: (optional) a class
or an iterable with classes to associate the rule with.
"""
if isinstance(target_class, Ite... | [
"def",
"add_rule",
"(",
"self",
",",
"rule_class",
",",
"target_class",
"=",
"_Nothing",
")",
":",
"if",
"isinstance",
"(",
"target_class",
",",
"Iterable",
")",
":",
"for",
"cls",
"in",
"target_class",
":",
"self",
".",
"_rules",
"[",
"cls",
"]",
"=",
... | Adds an authorization rule.
:param rule_class: a class of authorization rule.
:param target_class: (optional) a class
or an iterable with classes to associate the rule with. | [
"Adds",
"an",
"authorization",
"rule",
"."
] | train | https://github.com/antonev/authorizeme/blob/aede202b6d58d19632175ad0c159064737b2b8d9/authorizeme.py#L37-L48 |
antonev/authorizeme | authorizeme.py | Authorization.rule_for | def rule_for(self, target_class):
"""Decorates and adds an authorization rule
for a specified class(es) of objects.
:param target_class: a class or an iterable with classes
to associate the rule with.
"""
def decorator(rule_class):
self.add_rule(rule_clas... | python | def rule_for(self, target_class):
"""Decorates and adds an authorization rule
for a specified class(es) of objects.
:param target_class: a class or an iterable with classes
to associate the rule with.
"""
def decorator(rule_class):
self.add_rule(rule_clas... | [
"def",
"rule_for",
"(",
"self",
",",
"target_class",
")",
":",
"def",
"decorator",
"(",
"rule_class",
")",
":",
"self",
".",
"add_rule",
"(",
"rule_class",
",",
"target_class",
")",
"return",
"rule_class",
"return",
"decorator"
] | Decorates and adds an authorization rule
for a specified class(es) of objects.
:param target_class: a class or an iterable with classes
to associate the rule with. | [
"Decorates",
"and",
"adds",
"an",
"authorization",
"rule",
"for",
"a",
"specified",
"class",
"(",
"es",
")",
"of",
"objects",
"."
] | train | https://github.com/antonev/authorizeme/blob/aede202b6d58d19632175ad0c159064737b2b8d9/authorizeme.py#L50-L60 |
antonev/authorizeme | authorizeme.py | Authorization.check | def check(self, user, permission, obj=_nothing):
"""Raises AuthorizationError when a user has no permission.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for.
"""
if not self.allows(user, permission, ob... | python | def check(self, user, permission, obj=_nothing):
"""Raises AuthorizationError when a user has no permission.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for.
"""
if not self.allows(user, permission, ob... | [
"def",
"check",
"(",
"self",
",",
"user",
",",
"permission",
",",
"obj",
"=",
"_nothing",
")",
":",
"if",
"not",
"self",
".",
"allows",
"(",
"user",
",",
"permission",
",",
"obj",
")",
":",
"raise",
"AuthorizationError",
"(",
"'Can\\'t {} object of class {... | Raises AuthorizationError when a user has no permission.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for. | [
"Raises",
"AuthorizationError",
"when",
"a",
"user",
"has",
"no",
"permission",
"."
] | train | https://github.com/antonev/authorizeme/blob/aede202b6d58d19632175ad0c159064737b2b8d9/authorizeme.py#L67-L77 |
antonev/authorizeme | authorizeme.py | Authorization.allows | def allows(self, user, permission, obj=_nothing):
"""Checks that a user has permission. Returns True or False.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for.
"""
rule = self._get_rule(obj)
i... | python | def allows(self, user, permission, obj=_nothing):
"""Checks that a user has permission. Returns True or False.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for.
"""
rule = self._get_rule(obj)
i... | [
"def",
"allows",
"(",
"self",
",",
"user",
",",
"permission",
",",
"obj",
"=",
"_nothing",
")",
":",
"rule",
"=",
"self",
".",
"_get_rule",
"(",
"obj",
")",
"if",
"not",
"isinstance",
"(",
"permission",
",",
"basestring",
")",
":",
"return",
"all",
"... | Checks that a user has permission. Returns True or False.
:param user: a user.
:param permission: permission to check.
:param obj: (optional) an object to check permission for. | [
"Checks",
"that",
"a",
"user",
"has",
"permission",
".",
"Returns",
"True",
"or",
"False",
"."
] | train | https://github.com/antonev/authorizeme/blob/aede202b6d58d19632175ad0c159064737b2b8d9/authorizeme.py#L79-L94 |
antonev/authorizeme | authorizeme.py | Authorization.get_permissions | def get_permissions(self, user, obj=_nothing):
"""Returns permissions of a user.
:param user: a user.
:param obj: (optional) an object to get permissions for.
"""
rule = self._get_rule(obj)
all_permissions = (
attr[len('can_'):] for attr in dir(rule)
... | python | def get_permissions(self, user, obj=_nothing):
"""Returns permissions of a user.
:param user: a user.
:param obj: (optional) an object to get permissions for.
"""
rule = self._get_rule(obj)
all_permissions = (
attr[len('can_'):] for attr in dir(rule)
... | [
"def",
"get_permissions",
"(",
"self",
",",
"user",
",",
"obj",
"=",
"_nothing",
")",
":",
"rule",
"=",
"self",
".",
"_get_rule",
"(",
"obj",
")",
"all_permissions",
"=",
"(",
"attr",
"[",
"len",
"(",
"'can_'",
")",
":",
"]",
"for",
"attr",
"in",
"... | Returns permissions of a user.
:param user: a user.
:param obj: (optional) an object to get permissions for. | [
"Returns",
"permissions",
"of",
"a",
"user",
"."
] | train | https://github.com/antonev/authorizeme/blob/aede202b6d58d19632175ad0c159064737b2b8d9/authorizeme.py#L125-L141 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.