id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
231,900
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.reset
def reset(self): "Initialises all needed variables to default values" self.metadata = {} self.items = [] self.spine = [] self.guide = [] self.pages = [] self.toc = [] self.bindings = [] self.IDENTIFIER_ID = 'id' self.FOLDER_NAME = 'EPUB' ...
python
def reset(self): "Initialises all needed variables to default values" self.metadata = {} self.items = [] self.spine = [] self.guide = [] self.pages = [] self.toc = [] self.bindings = [] self.IDENTIFIER_ID = 'id' self.FOLDER_NAME = 'EPUB' ...
[ "def", "reset", "(", "self", ")", ":", "self", ".", "metadata", "=", "{", "}", "self", ".", "items", "=", "[", "]", "self", ".", "spine", "=", "[", "]", "self", ".", "guide", "=", "[", "]", "self", ".", "pages", "=", "[", "]", "self", ".", ...
Initialises all needed variables to default values
[ "Initialises", "all", "needed", "variables", "to", "default", "values" ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L554-L592
231,901
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.set_identifier
def set_identifier(self, uid): """ Sets unique id for this epub :Args: - uid: Value of unique identifier for this book """ self.uid = uid self.set_unique_metadata('DC', 'identifier', self.uid, {'id': self.IDENTIFIER_ID})
python
def set_identifier(self, uid): """ Sets unique id for this epub :Args: - uid: Value of unique identifier for this book """ self.uid = uid self.set_unique_metadata('DC', 'identifier', self.uid, {'id': self.IDENTIFIER_ID})
[ "def", "set_identifier", "(", "self", ",", "uid", ")", ":", "self", ".", "uid", "=", "uid", "self", ".", "set_unique_metadata", "(", "'DC'", ",", "'identifier'", ",", "self", ".", "uid", ",", "{", "'id'", ":", "self", ".", "IDENTIFIER_ID", "}", ")" ]
Sets unique id for this epub :Args: - uid: Value of unique identifier for this book
[ "Sets", "unique", "id", "for", "this", "epub" ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L594-L604
231,902
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.set_title
def set_title(self, title): """ Set title. You can set multiple titles. :Args: - title: Title value """ self.title = title self.add_metadata('DC', 'title', self.title)
python
def set_title(self, title): """ Set title. You can set multiple titles. :Args: - title: Title value """ self.title = title self.add_metadata('DC', 'title', self.title)
[ "def", "set_title", "(", "self", ",", "title", ")", ":", "self", ".", "title", "=", "title", "self", ".", "add_metadata", "(", "'DC'", ",", "'title'", ",", "self", ".", "title", ")" ]
Set title. You can set multiple titles. :Args: - title: Title value
[ "Set", "title", ".", "You", "can", "set", "multiple", "titles", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L606-L616
231,903
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.set_cover
def set_cover(self, file_name, content, create_page=True): """ Set cover and create cover document if needed. :Args: - file_name: file name of the cover page - content: Content for the cover image - create_page: Should cover page be defined. Defined as bool value (...
python
def set_cover(self, file_name, content, create_page=True): """ Set cover and create cover document if needed. :Args: - file_name: file name of the cover page - content: Content for the cover image - create_page: Should cover page be defined. Defined as bool value (...
[ "def", "set_cover", "(", "self", ",", "file_name", ",", "content", ",", "create_page", "=", "True", ")", ":", "# as it is now, it can only be called once", "c0", "=", "EpubCover", "(", "file_name", "=", "file_name", ")", "c0", ".", "content", "=", "content", "...
Set cover and create cover document if needed. :Args: - file_name: file name of the cover page - content: Content for the cover image - create_page: Should cover page be defined. Defined as bool value (optional). Default value is True.
[ "Set", "cover", "and", "create", "cover", "document", "if", "needed", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L639-L658
231,904
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.add_author
def add_author(self, author, file_as=None, role=None, uid='creator'): "Add author for this document" self.add_metadata('DC', 'creator', author, {'id': uid}) if file_as: self.add_metadata(None, 'meta', file_as, {'refines': '#' + uid, ...
python
def add_author(self, author, file_as=None, role=None, uid='creator'): "Add author for this document" self.add_metadata('DC', 'creator', author, {'id': uid}) if file_as: self.add_metadata(None, 'meta', file_as, {'refines': '#' + uid, ...
[ "def", "add_author", "(", "self", ",", "author", ",", "file_as", "=", "None", ",", "role", "=", "None", ",", "uid", "=", "'creator'", ")", ":", "self", ".", "add_metadata", "(", "'DC'", ",", "'creator'", ",", "author", ",", "{", "'id'", ":", "uid", ...
Add author for this document
[ "Add", "author", "for", "this", "document" ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L660-L672
231,905
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.add_item
def add_item(self, item): """ Add additional item to the book. If not defined, media type and chapter id will be defined for the item. :Args: - item: Item instance """ if item.media_type == '': (has_guessed, media_type) = guess_type(item.get_name()....
python
def add_item(self, item): """ Add additional item to the book. If not defined, media type and chapter id will be defined for the item. :Args: - item: Item instance """ if item.media_type == '': (has_guessed, media_type) = guess_type(item.get_name()....
[ "def", "add_item", "(", "self", ",", "item", ")", ":", "if", "item", ".", "media_type", "==", "''", ":", "(", "has_guessed", ",", "media_type", ")", "=", "guess_type", "(", "item", ".", "get_name", "(", ")", ".", "lower", "(", ")", ")", "if", "has_...
Add additional item to the book. If not defined, media type and chapter id will be defined for the item. :Args: - item: Item instance
[ "Add", "additional", "item", "to", "the", "book", ".", "If", "not", "defined", "media", "type", "and", "chapter", "id", "will", "be", "defined", "for", "the", "item", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L707-L743
231,906
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.get_item_with_id
def get_item_with_id(self, uid): """ Returns item for defined UID. >>> book.get_item_with_id('image_001') :Args: - uid: UID for the item :Returns: Returns item object. Returns None if nothing was found. """ for item in self.get_items(): ...
python
def get_item_with_id(self, uid): """ Returns item for defined UID. >>> book.get_item_with_id('image_001') :Args: - uid: UID for the item :Returns: Returns item object. Returns None if nothing was found. """ for item in self.get_items(): ...
[ "def", "get_item_with_id", "(", "self", ",", "uid", ")", ":", "for", "item", "in", "self", ".", "get_items", "(", ")", ":", "if", "item", ".", "id", "==", "uid", ":", "return", "item", "return", "None" ]
Returns item for defined UID. >>> book.get_item_with_id('image_001') :Args: - uid: UID for the item :Returns: Returns item object. Returns None if nothing was found.
[ "Returns", "item", "for", "defined", "UID", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L745-L761
231,907
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.get_item_with_href
def get_item_with_href(self, href): """ Returns item for defined HREF. >>> book.get_item_with_href('EPUB/document.xhtml') :Args: - href: HREF for the item we are searching for :Returns: Returns item object. Returns None if nothing was found. """ ...
python
def get_item_with_href(self, href): """ Returns item for defined HREF. >>> book.get_item_with_href('EPUB/document.xhtml') :Args: - href: HREF for the item we are searching for :Returns: Returns item object. Returns None if nothing was found. """ ...
[ "def", "get_item_with_href", "(", "self", ",", "href", ")", ":", "for", "item", "in", "self", ".", "get_items", "(", ")", ":", "if", "item", ".", "get_name", "(", ")", "==", "href", ":", "return", "item", "return", "None" ]
Returns item for defined HREF. >>> book.get_item_with_href('EPUB/document.xhtml') :Args: - href: HREF for the item we are searching for :Returns: Returns item object. Returns None if nothing was found.
[ "Returns", "item", "for", "defined", "HREF", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L763-L779
231,908
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.get_items_of_type
def get_items_of_type(self, item_type): """ Returns all items of specified type. >>> book.get_items_of_type(epub.ITEM_IMAGE) :Args: - item_type: Type for items we are searching for :Returns: Returns found items as tuple. """ return (item for...
python
def get_items_of_type(self, item_type): """ Returns all items of specified type. >>> book.get_items_of_type(epub.ITEM_IMAGE) :Args: - item_type: Type for items we are searching for :Returns: Returns found items as tuple. """ return (item for...
[ "def", "get_items_of_type", "(", "self", ",", "item_type", ")", ":", "return", "(", "item", "for", "item", "in", "self", ".", "items", "if", "item", ".", "get_type", "(", ")", "==", "item_type", ")" ]
Returns all items of specified type. >>> book.get_items_of_type(epub.ITEM_IMAGE) :Args: - item_type: Type for items we are searching for :Returns: Returns found items as tuple.
[ "Returns", "all", "items", "of", "specified", "type", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L790-L802
231,909
aerkalov/ebooklib
ebooklib/epub.py
EpubBook.get_items_of_media_type
def get_items_of_media_type(self, media_type): """ Returns all items of specified media type. :Args: - media_type: Media type for items we are searching for :Returns: Returns found items as tuple. """ return (item for item in self.items if item.media...
python
def get_items_of_media_type(self, media_type): """ Returns all items of specified media type. :Args: - media_type: Media type for items we are searching for :Returns: Returns found items as tuple. """ return (item for item in self.items if item.media...
[ "def", "get_items_of_media_type", "(", "self", ",", "media_type", ")", ":", "return", "(", "item", "for", "item", "in", "self", ".", "items", "if", "item", ".", "media_type", "==", "media_type", ")" ]
Returns all items of specified media type. :Args: - media_type: Media type for items we are searching for :Returns: Returns found items as tuple.
[ "Returns", "all", "items", "of", "specified", "media", "type", "." ]
305f2dd7f02923ffabf9586a5d16266113d00c4a
https://github.com/aerkalov/ebooklib/blob/305f2dd7f02923ffabf9586a5d16266113d00c4a/ebooklib/epub.py#L804-L814
231,910
LuminosoInsight/python-ftfy
ftfy/cli.py
main
def main(): """ Run ftfy as a command-line utility. """ import argparse parser = argparse.ArgumentParser( description="ftfy (fixes text for you), version %s" % __version__ ) parser.add_argument('filename', default='-', nargs='?', help='The file whose Unicode ...
python
def main(): """ Run ftfy as a command-line utility. """ import argparse parser = argparse.ArgumentParser( description="ftfy (fixes text for you), version %s" % __version__ ) parser.add_argument('filename', default='-', nargs='?', help='The file whose Unicode ...
[ "def", "main", "(", ")", ":", "import", "argparse", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "\"ftfy (fixes text for you), version %s\"", "%", "__version__", ")", "parser", ".", "add_argument", "(", "'filename'", ",", "default", "...
Run ftfy as a command-line utility.
[ "Run", "ftfy", "as", "a", "command", "-", "line", "utility", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/cli.py#L42-L114
231,911
LuminosoInsight/python-ftfy
ftfy/fixes.py
fix_encoding_and_explain
def fix_encoding_and_explain(text): """ Re-decodes text that has been decoded incorrectly, and also return a "plan" indicating all the steps required to fix it. The resulting plan could be used with :func:`ftfy.fixes.apply_plan` to fix additional strings that are broken in the same way. """ ...
python
def fix_encoding_and_explain(text): """ Re-decodes text that has been decoded incorrectly, and also return a "plan" indicating all the steps required to fix it. The resulting plan could be used with :func:`ftfy.fixes.apply_plan` to fix additional strings that are broken in the same way. """ ...
[ "def", "fix_encoding_and_explain", "(", "text", ")", ":", "best_version", "=", "text", "best_cost", "=", "text_cost", "(", "text", ")", "best_plan", "=", "[", "]", "plan_so_far", "=", "[", "]", "while", "True", ":", "prevtext", "=", "text", "text", ",", ...
Re-decodes text that has been decoded incorrectly, and also return a "plan" indicating all the steps required to fix it. The resulting plan could be used with :func:`ftfy.fixes.apply_plan` to fix additional strings that are broken in the same way.
[ "Re", "-", "decodes", "text", "that", "has", "been", "decoded", "incorrectly", "and", "also", "return", "a", "plan", "indicating", "all", "the", "steps", "required", "to", "fix", "it", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L133-L158
231,912
LuminosoInsight/python-ftfy
ftfy/fixes.py
fix_one_step_and_explain
def fix_one_step_and_explain(text): """ Performs a single step of re-decoding text that's been decoded incorrectly. Returns the decoded text, plus a "plan" for how to reproduce what it did. """ if isinstance(text, bytes): raise UnicodeError(BYTES_ERROR_TEXT) if len(text) == 0: r...
python
def fix_one_step_and_explain(text): """ Performs a single step of re-decoding text that's been decoded incorrectly. Returns the decoded text, plus a "plan" for how to reproduce what it did. """ if isinstance(text, bytes): raise UnicodeError(BYTES_ERROR_TEXT) if len(text) == 0: r...
[ "def", "fix_one_step_and_explain", "(", "text", ")", ":", "if", "isinstance", "(", "text", ",", "bytes", ")", ":", "raise", "UnicodeError", "(", "BYTES_ERROR_TEXT", ")", "if", "len", "(", "text", ")", "==", "0", ":", "return", "text", ",", "[", "]", "#...
Performs a single step of re-decoding text that's been decoded incorrectly. Returns the decoded text, plus a "plan" for how to reproduce what it did.
[ "Performs", "a", "single", "step", "of", "re", "-", "decoding", "text", "that", "s", "been", "decoded", "incorrectly", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L161-L259
231,913
LuminosoInsight/python-ftfy
ftfy/fixes.py
apply_plan
def apply_plan(text, plan): """ Apply a plan for fixing the encoding of text. The plan is a list of tuples of the form (operation, encoding, cost): - `operation` is 'encode' if it turns a string into bytes, 'decode' if it turns bytes into a string, and 'transcode' if it keeps the type the same. ...
python
def apply_plan(text, plan): """ Apply a plan for fixing the encoding of text. The plan is a list of tuples of the form (operation, encoding, cost): - `operation` is 'encode' if it turns a string into bytes, 'decode' if it turns bytes into a string, and 'transcode' if it keeps the type the same. ...
[ "def", "apply_plan", "(", "text", ",", "plan", ")", ":", "obj", "=", "text", "for", "operation", ",", "encoding", ",", "_", "in", "plan", ":", "if", "operation", "==", "'encode'", ":", "obj", "=", "obj", ".", "encode", "(", "encoding", ")", "elif", ...
Apply a plan for fixing the encoding of text. The plan is a list of tuples of the form (operation, encoding, cost): - `operation` is 'encode' if it turns a string into bytes, 'decode' if it turns bytes into a string, and 'transcode' if it keeps the type the same. - `encoding` is the name of the enco...
[ "Apply", "a", "plan", "for", "fixing", "the", "encoding", "of", "text", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L262-L290
231,914
LuminosoInsight/python-ftfy
ftfy/fixes.py
_unescape_fixup
def _unescape_fixup(match): """ Replace one matched HTML entity with the character it represents, if possible. """ text = match.group(0) if text[:2] == "&#": # character reference try: if text[:3] == "&#x": codept = int(text[3:-1], 16) else...
python
def _unescape_fixup(match): """ Replace one matched HTML entity with the character it represents, if possible. """ text = match.group(0) if text[:2] == "&#": # character reference try: if text[:3] == "&#x": codept = int(text[3:-1], 16) else...
[ "def", "_unescape_fixup", "(", "match", ")", ":", "text", "=", "match", ".", "group", "(", "0", ")", "if", "text", "[", ":", "2", "]", "==", "\"&#\"", ":", "# character reference", "try", ":", "if", "text", "[", ":", "3", "]", "==", "\"&#x\"", ":",...
Replace one matched HTML entity with the character it represents, if possible.
[ "Replace", "one", "matched", "HTML", "entity", "with", "the", "character", "it", "represents", "if", "possible", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L296-L323
231,915
LuminosoInsight/python-ftfy
ftfy/fixes.py
convert_surrogate_pair
def convert_surrogate_pair(match): """ Convert a surrogate pair to the single codepoint it represents. This implements the formula described at: http://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates """ pair = match.group(0) codept = 0x10000 + (ord(pair[0]) - 0xd800) * ...
python
def convert_surrogate_pair(match): """ Convert a surrogate pair to the single codepoint it represents. This implements the formula described at: http://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates """ pair = match.group(0) codept = 0x10000 + (ord(pair[0]) - 0xd800) * ...
[ "def", "convert_surrogate_pair", "(", "match", ")", ":", "pair", "=", "match", ".", "group", "(", "0", ")", "codept", "=", "0x10000", "+", "(", "ord", "(", "pair", "[", "0", "]", ")", "-", "0xd800", ")", "*", "0x400", "+", "(", "ord", "(", "pair"...
Convert a surrogate pair to the single codepoint it represents. This implements the formula described at: http://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
[ "Convert", "a", "surrogate", "pair", "to", "the", "single", "codepoint", "it", "represents", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L457-L466
231,916
LuminosoInsight/python-ftfy
ftfy/fixes.py
restore_byte_a0
def restore_byte_a0(byts): """ Some mojibake has been additionally altered by a process that said "hmm, byte A0, that's basically a space!" and replaced it with an ASCII space. When the A0 is part of a sequence that we intend to decode as UTF-8, changing byte A0 to 20 would make it fail to decode. ...
python
def restore_byte_a0(byts): """ Some mojibake has been additionally altered by a process that said "hmm, byte A0, that's basically a space!" and replaced it with an ASCII space. When the A0 is part of a sequence that we intend to decode as UTF-8, changing byte A0 to 20 would make it fail to decode. ...
[ "def", "restore_byte_a0", "(", "byts", ")", ":", "def", "replacement", "(", "match", ")", ":", "\"The function to apply when this regex matches.\"", "return", "match", ".", "group", "(", "0", ")", ".", "replace", "(", "b'\\x20'", ",", "b'\\xa0'", ")", "return", ...
Some mojibake has been additionally altered by a process that said "hmm, byte A0, that's basically a space!" and replaced it with an ASCII space. When the A0 is part of a sequence that we intend to decode as UTF-8, changing byte A0 to 20 would make it fail to decode. This process finds sequences that w...
[ "Some", "mojibake", "has", "been", "additionally", "altered", "by", "a", "process", "that", "said", "hmm", "byte", "A0", "that", "s", "basically", "a", "space!", "and", "replaced", "it", "with", "an", "ASCII", "space", ".", "When", "the", "A0", "is", "pa...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L582-L600
231,917
LuminosoInsight/python-ftfy
ftfy/fixes.py
fix_partial_utf8_punct_in_1252
def fix_partial_utf8_punct_in_1252(text): """ Fix particular characters that seem to be found in the wild encoded in UTF-8 and decoded in Latin-1 or Windows-1252, even when this fix can't be consistently applied. One form of inconsistency we need to deal with is that some character might be fro...
python
def fix_partial_utf8_punct_in_1252(text): """ Fix particular characters that seem to be found in the wild encoded in UTF-8 and decoded in Latin-1 or Windows-1252, even when this fix can't be consistently applied. One form of inconsistency we need to deal with is that some character might be fro...
[ "def", "fix_partial_utf8_punct_in_1252", "(", "text", ")", ":", "def", "latin1_to_w1252", "(", "match", ")", ":", "\"The function to apply when this regex matches.\"", "return", "match", ".", "group", "(", "0", ")", ".", "encode", "(", "'latin-1'", ")", ".", "deco...
Fix particular characters that seem to be found in the wild encoded in UTF-8 and decoded in Latin-1 or Windows-1252, even when this fix can't be consistently applied. One form of inconsistency we need to deal with is that some character might be from the Latin-1 C1 control character set, while others a...
[ "Fix", "particular", "characters", "that", "seem", "to", "be", "found", "in", "the", "wild", "encoded", "in", "UTF", "-", "8", "and", "decoded", "in", "Latin", "-", "1", "or", "Windows", "-", "1252", "even", "when", "this", "fix", "can", "t", "be", "...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/fixes.py#L642-L664
231,918
LuminosoInsight/python-ftfy
ftfy/formatting.py
display_ljust
def display_ljust(text, width, fillchar=' '): """ Return `text` left-justified in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. "Left" here mea...
python
def display_ljust(text, width, fillchar=' '): """ Return `text` left-justified in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. "Left" here mea...
[ "def", "display_ljust", "(", "text", ",", "width", ",", "fillchar", "=", "' '", ")", ":", "if", "character_width", "(", "fillchar", ")", "!=", "1", ":", "raise", "ValueError", "(", "\"The padding character must have display width 1\"", ")", "text_width", "=", "m...
Return `text` left-justified in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. "Left" here means toward the beginning of the string, which may actually ...
[ "Return", "text", "left", "-", "justified", "in", "a", "Unicode", "string", "whose", "display", "width", "in", "a", "monospaced", "terminal", "should", "be", "at", "least", "width", "character", "cells", ".", "The", "rest", "of", "the", "string", "will", "...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/formatting.py#L67-L98
231,919
LuminosoInsight/python-ftfy
ftfy/formatting.py
display_center
def display_center(text, width, fillchar=' '): """ Return `text` centered in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. >>> lines = ['Table ...
python
def display_center(text, width, fillchar=' '): """ Return `text` centered in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. >>> lines = ['Table ...
[ "def", "display_center", "(", "text", ",", "width", ",", "fillchar", "=", "' '", ")", ":", "if", "character_width", "(", "fillchar", ")", "!=", "1", ":", "raise", "ValueError", "(", "\"The padding character must have display width 1\"", ")", "text_width", "=", "...
Return `text` centered in a Unicode string whose display width, in a monospaced terminal, should be at least `width` character cells. The rest of the string will be padded with `fillchar`, which must be a width-1 character. >>> lines = ['Table flip', '(╯°□°)╯︵ ┻━┻', 'ちゃぶ台返し'] >>> for line in lines:...
[ "Return", "text", "centered", "in", "a", "Unicode", "string", "whose", "display", "width", "in", "a", "monospaced", "terminal", "should", "be", "at", "least", "width", "character", "cells", ".", "The", "rest", "of", "the", "string", "will", "be", "padded", ...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/formatting.py#L130-L154
231,920
LuminosoInsight/python-ftfy
ftfy/bad_codecs/sloppy.py
make_sloppy_codec
def make_sloppy_codec(encoding): """ Take a codec name, and return a 'sloppy' version of that codec that can encode and decode the unassigned bytes in that encoding. Single-byte encodings in the standard library are defined using some boilerplate classes surrounding the functions that do the actual...
python
def make_sloppy_codec(encoding): """ Take a codec name, and return a 'sloppy' version of that codec that can encode and decode the unassigned bytes in that encoding. Single-byte encodings in the standard library are defined using some boilerplate classes surrounding the functions that do the actual...
[ "def", "make_sloppy_codec", "(", "encoding", ")", ":", "# Make a bytestring of all 256 possible bytes.", "all_bytes", "=", "bytes", "(", "range", "(", "256", ")", ")", "# Get a list of what they would decode to in Latin-1.", "sloppy_chars", "=", "list", "(", "all_bytes", ...
Take a codec name, and return a 'sloppy' version of that codec that can encode and decode the unassigned bytes in that encoding. Single-byte encodings in the standard library are defined using some boilerplate classes surrounding the functions that do the actual work, `codecs.charmap_decode` and `charm...
[ "Take", "a", "codec", "name", "and", "return", "a", "sloppy", "version", "of", "that", "codec", "that", "can", "encode", "and", "decode", "the", "unassigned", "bytes", "in", "that", "encoding", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/bad_codecs/sloppy.py#L79-L150
231,921
LuminosoInsight/python-ftfy
ftfy/badness.py
_make_weirdness_regex
def _make_weirdness_regex(): """ Creates a list of regexes that match 'weird' character sequences. The more matches there are, the weirder the text is. """ groups = [] # Match diacritical marks, except when they modify a non-cased letter or # another mark. # # You wouldn't put a dia...
python
def _make_weirdness_regex(): """ Creates a list of regexes that match 'weird' character sequences. The more matches there are, the weirder the text is. """ groups = [] # Match diacritical marks, except when they modify a non-cased letter or # another mark. # # You wouldn't put a dia...
[ "def", "_make_weirdness_regex", "(", ")", ":", "groups", "=", "[", "]", "# Match diacritical marks, except when they modify a non-cased letter or", "# another mark.", "#", "# You wouldn't put a diacritical mark on a digit or a space, for example.", "# You might put it on a Latin letter, bu...
Creates a list of regexes that match 'weird' character sequences. The more matches there are, the weirder the text is.
[ "Creates", "a", "list", "of", "regexes", "that", "match", "weird", "character", "sequences", ".", "The", "more", "matches", "there", "are", "the", "weirder", "the", "text", "is", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/badness.py#L31-L92
231,922
LuminosoInsight/python-ftfy
ftfy/badness.py
sequence_weirdness
def sequence_weirdness(text): """ Determine how often a text has unexpected characters or sequences of characters. This metric is used to disambiguate when text should be re-decoded or left as is. We start by normalizing text in NFC form, so that penalties for diacritical marks don't apply to c...
python
def sequence_weirdness(text): """ Determine how often a text has unexpected characters or sequences of characters. This metric is used to disambiguate when text should be re-decoded or left as is. We start by normalizing text in NFC form, so that penalties for diacritical marks don't apply to c...
[ "def", "sequence_weirdness", "(", "text", ")", ":", "text2", "=", "unicodedata", ".", "normalize", "(", "'NFC'", ",", "text", ")", "weirdness", "=", "len", "(", "WEIRDNESS_RE", ".", "findall", "(", "chars_to_classes", "(", "text2", ")", ")", ")", "adjustme...
Determine how often a text has unexpected characters or sequences of characters. This metric is used to disambiguate when text should be re-decoded or left as is. We start by normalizing text in NFC form, so that penalties for diacritical marks don't apply to characters that know what to do with th...
[ "Determine", "how", "often", "a", "text", "has", "unexpected", "characters", "or", "sequences", "of", "characters", ".", "This", "metric", "is", "used", "to", "disambiguate", "when", "text", "should", "be", "re", "-", "decoded", "or", "left", "as", "is", "...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/badness.py#L157-L190
231,923
LuminosoInsight/python-ftfy
ftfy/bad_codecs/__init__.py
search_function
def search_function(encoding): """ Register our "bad codecs" with Python's codecs API. This involves adding a search function that takes in an encoding name, and returns a codec for that encoding if it knows one, or None if it doesn't. The encodings this will match are: - Encodings of the form...
python
def search_function(encoding): """ Register our "bad codecs" with Python's codecs API. This involves adding a search function that takes in an encoding name, and returns a codec for that encoding if it knows one, or None if it doesn't. The encodings this will match are: - Encodings of the form...
[ "def", "search_function", "(", "encoding", ")", ":", "if", "encoding", "in", "_CACHE", ":", "return", "_CACHE", "[", "encoding", "]", "norm_encoding", "=", "normalize_encoding", "(", "encoding", ")", "codec", "=", "None", "if", "norm_encoding", "in", "UTF8_VAR...
Register our "bad codecs" with Python's codecs API. This involves adding a search function that takes in an encoding name, and returns a codec for that encoding if it knows one, or None if it doesn't. The encodings this will match are: - Encodings of the form 'sloppy-windows-NNNN' or 'sloppy-iso-8859-...
[ "Register", "our", "bad", "codecs", "with", "Python", "s", "codecs", "API", ".", "This", "involves", "adding", "a", "search", "function", "that", "takes", "in", "an", "encoding", "name", "and", "returns", "a", "codec", "for", "that", "encoding", "if", "it"...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/bad_codecs/__init__.py#L47-L76
231,924
LuminosoInsight/python-ftfy
ftfy/bad_codecs/utf8_variants.py
IncrementalDecoder._buffer_decode
def _buffer_decode(self, input, errors, final): """ Decode bytes that may be arriving in a stream, following the Codecs API. `input` is the incoming sequence of bytes. `errors` tells us how to handle errors, though we delegate all error-handling cases to the real UTF-8 d...
python
def _buffer_decode(self, input, errors, final): """ Decode bytes that may be arriving in a stream, following the Codecs API. `input` is the incoming sequence of bytes. `errors` tells us how to handle errors, though we delegate all error-handling cases to the real UTF-8 d...
[ "def", "_buffer_decode", "(", "self", ",", "input", ",", "errors", ",", "final", ")", ":", "# decoded_segments are the pieces of text we have decoded so far,", "# and position is our current position in the byte string. (Bytes", "# before this position have been consumed, and bytes after...
Decode bytes that may be arriving in a stream, following the Codecs API. `input` is the incoming sequence of bytes. `errors` tells us how to handle errors, though we delegate all error-handling cases to the real UTF-8 decoder to ensure correct behavior. `final` indicates whether ...
[ "Decode", "bytes", "that", "may", "be", "arriving", "in", "a", "stream", "following", "the", "Codecs", "API", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/bad_codecs/utf8_variants.py#L88-L129
231,925
LuminosoInsight/python-ftfy
ftfy/bad_codecs/utf8_variants.py
IncrementalDecoder._buffer_decode_surrogates
def _buffer_decode_surrogates(sup, input, errors, final): """ When we have improperly encoded surrogates, we can still see the bits that they were meant to represent. The surrogates were meant to encode a 20-bit number, to which we add 0x10000 to get a codepoint. That 20-bit num...
python
def _buffer_decode_surrogates(sup, input, errors, final): """ When we have improperly encoded surrogates, we can still see the bits that they were meant to represent. The surrogates were meant to encode a 20-bit number, to which we add 0x10000 to get a codepoint. That 20-bit num...
[ "def", "_buffer_decode_surrogates", "(", "sup", ",", "input", ",", "errors", ",", "final", ")", ":", "if", "len", "(", "input", ")", "<", "6", ":", "if", "final", ":", "# We found 0xed near the end of the stream, and there aren't", "# six bytes to decode. Delegate to ...
When we have improperly encoded surrogates, we can still see the bits that they were meant to represent. The surrogates were meant to encode a 20-bit number, to which we add 0x10000 to get a codepoint. That 20-bit number now appears in this form: 11101101 1010abcd 10efghij 11...
[ "When", "we", "have", "improperly", "encoded", "surrogates", "we", "can", "still", "see", "the", "bits", "that", "they", "were", "meant", "to", "represent", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/bad_codecs/utf8_variants.py#L173-L215
231,926
LuminosoInsight/python-ftfy
ftfy/__init__.py
fix_text
def fix_text(text, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, fix_line_breaks=True, fix_surrogates=Tr...
python
def fix_text(text, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, fix_line_breaks=True, fix_surrogates=Tr...
[ "def", "fix_text", "(", "text", ",", "*", ",", "fix_entities", "=", "'auto'", ",", "remove_terminal_escapes", "=", "True", ",", "fix_encoding", "=", "True", ",", "fix_latin_ligatures", "=", "True", ",", "fix_character_width", "=", "True", ",", "uncurl_quotes", ...
r""" Given Unicode text as input, fix inconsistencies and glitches in it, such as mojibake. Let's start with some examples: >>> print(fix_text('ünicode')) ünicode >>> print(fix_text('Broken text&hellip; it&#x2019;s flubberific!', ... normalization='NFKC')) ...
[ "r", "Given", "Unicode", "text", "as", "input", "fix", "inconsistencies", "and", "glitches", "in", "it", "such", "as", "mojibake", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/__init__.py#L20-L186
231,927
LuminosoInsight/python-ftfy
ftfy/__init__.py
fix_file
def fix_file(input_file, encoding=None, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, fix_line_breaks=Tr...
python
def fix_file(input_file, encoding=None, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, fix_line_breaks=Tr...
[ "def", "fix_file", "(", "input_file", ",", "encoding", "=", "None", ",", "*", ",", "fix_entities", "=", "'auto'", ",", "remove_terminal_escapes", "=", "True", ",", "fix_encoding", "=", "True", ",", "fix_latin_ligatures", "=", "True", ",", "fix_character_width", ...
Fix text that is found in a file. If the file is being read as Unicode text, use that. If it's being read as bytes, then we hope an encoding was supplied. If not, unfortunately, we have to guess what encoding it is. We'll try a few common encodings, but we make no promises. See the `guess_bytes` functi...
[ "Fix", "text", "that", "is", "found", "in", "a", "file", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/__init__.py#L195-L241
231,928
LuminosoInsight/python-ftfy
ftfy/__init__.py
fix_text_segment
def fix_text_segment(text, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, ...
python
def fix_text_segment(text, *, fix_entities='auto', remove_terminal_escapes=True, fix_encoding=True, fix_latin_ligatures=True, fix_character_width=True, uncurl_quotes=True, ...
[ "def", "fix_text_segment", "(", "text", ",", "*", ",", "fix_entities", "=", "'auto'", ",", "remove_terminal_escapes", "=", "True", ",", "fix_encoding", "=", "True", ",", "fix_latin_ligatures", "=", "True", ",", "fix_character_width", "=", "True", ",", "uncurl_qu...
Apply fixes to text in a single chunk. This could be a line of text within a larger run of `fix_text`, or it could be a larger amount of text that you are certain is in a consistent encoding. See `fix_text` for a description of the parameters.
[ "Apply", "fixes", "to", "text", "in", "a", "single", "chunk", ".", "This", "could", "be", "a", "line", "of", "text", "within", "a", "larger", "run", "of", "fix_text", "or", "it", "could", "be", "a", "larger", "amount", "of", "text", "that", "you", "a...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/__init__.py#L244-L296
231,929
LuminosoInsight/python-ftfy
ftfy/__init__.py
explain_unicode
def explain_unicode(text): """ A utility method that's useful for debugging mysterious Unicode. It breaks down a string, showing you for each codepoint its number in hexadecimal, its glyph, its category in the Unicode standard, and its name in the Unicode standard. >>> explain_unicode('(╯°...
python
def explain_unicode(text): """ A utility method that's useful for debugging mysterious Unicode. It breaks down a string, showing you for each codepoint its number in hexadecimal, its glyph, its category in the Unicode standard, and its name in the Unicode standard. >>> explain_unicode('(╯°...
[ "def", "explain_unicode", "(", "text", ")", ":", "for", "char", "in", "text", ":", "if", "char", ".", "isprintable", "(", ")", ":", "display", "=", "char", "else", ":", "display", "=", "char", ".", "encode", "(", "'unicode-escape'", ")", ".", "decode",...
A utility method that's useful for debugging mysterious Unicode. It breaks down a string, showing you for each codepoint its number in hexadecimal, its glyph, its category in the Unicode standard, and its name in the Unicode standard. >>> explain_unicode('(╯°□°)╯︵ ┻━┻') U+0028 ( [Ps...
[ "A", "utility", "method", "that", "s", "useful", "for", "debugging", "mysterious", "Unicode", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/__init__.py#L379-L411
231,930
LuminosoInsight/python-ftfy
ftfy/chardata.py
_build_regexes
def _build_regexes(): """ ENCODING_REGEXES contain reasonably fast ways to detect if we could represent a given string in a given encoding. The simplest one is the 'ascii' detector, which of course just determines if all characters are between U+0000 and U+007F. """ # Define a regex that mat...
python
def _build_regexes(): """ ENCODING_REGEXES contain reasonably fast ways to detect if we could represent a given string in a given encoding. The simplest one is the 'ascii' detector, which of course just determines if all characters are between U+0000 and U+007F. """ # Define a regex that mat...
[ "def", "_build_regexes", "(", ")", ":", "# Define a regex that matches ASCII text.", "encoding_regexes", "=", "{", "'ascii'", ":", "re", ".", "compile", "(", "'^[\\x00-\\x7f]*$'", ")", "}", "for", "encoding", "in", "CHARMAP_ENCODINGS", ":", "# Make a sequence of charact...
ENCODING_REGEXES contain reasonably fast ways to detect if we could represent a given string in a given encoding. The simplest one is the 'ascii' detector, which of course just determines if all characters are between U+0000 and U+007F.
[ "ENCODING_REGEXES", "contain", "reasonably", "fast", "ways", "to", "detect", "if", "we", "could", "represent", "a", "given", "string", "in", "a", "given", "encoding", ".", "The", "simplest", "one", "is", "the", "ascii", "detector", "which", "of", "course", "...
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/chardata.py#L25-L49
231,931
LuminosoInsight/python-ftfy
ftfy/chardata.py
_build_width_map
def _build_width_map(): """ Build a translate mapping that replaces halfwidth and fullwidth forms with their standard-width forms. """ # Though it's not listed as a fullwidth character, we'll want to convert # U+3000 IDEOGRAPHIC SPACE to U+20 SPACE on the same principle, so start # with that...
python
def _build_width_map(): """ Build a translate mapping that replaces halfwidth and fullwidth forms with their standard-width forms. """ # Though it's not listed as a fullwidth character, we'll want to convert # U+3000 IDEOGRAPHIC SPACE to U+20 SPACE on the same principle, so start # with that...
[ "def", "_build_width_map", "(", ")", ":", "# Though it's not listed as a fullwidth character, we'll want to convert", "# U+3000 IDEOGRAPHIC SPACE to U+20 SPACE on the same principle, so start", "# with that in the dictionary.", "width_map", "=", "{", "0x3000", ":", "' '", "}", "for", ...
Build a translate mapping that replaces halfwidth and fullwidth forms with their standard-width forms.
[ "Build", "a", "translate", "mapping", "that", "replaces", "halfwidth", "and", "fullwidth", "forms", "with", "their", "standard", "-", "width", "forms", "." ]
476acc6ad270bffe07f97d4f7cf2139acdc69633
https://github.com/LuminosoInsight/python-ftfy/blob/476acc6ad270bffe07f97d4f7cf2139acdc69633/ftfy/chardata.py#L222-L236
231,932
pydata/numexpr
numexpr/utils.py
set_vml_accuracy_mode
def set_vml_accuracy_mode(mode): """ Set the accuracy mode for VML operations. The `mode` parameter can take the values: - 'high': high accuracy mode (HA), <1 least significant bit - 'low': low accuracy mode (LA), typically 1-2 least significant bits - 'fast': enhanced performance mode (EP) ...
python
def set_vml_accuracy_mode(mode): """ Set the accuracy mode for VML operations. The `mode` parameter can take the values: - 'high': high accuracy mode (HA), <1 least significant bit - 'low': low accuracy mode (LA), typically 1-2 least significant bits - 'fast': enhanced performance mode (EP) ...
[ "def", "set_vml_accuracy_mode", "(", "mode", ")", ":", "if", "use_vml", ":", "acc_dict", "=", "{", "None", ":", "0", ",", "'low'", ":", "1", ",", "'high'", ":", "2", ",", "'fast'", ":", "3", "}", "acc_reverse_dict", "=", "{", "1", ":", "'low'", ","...
Set the accuracy mode for VML operations. The `mode` parameter can take the values: - 'high': high accuracy mode (HA), <1 least significant bit - 'low': low accuracy mode (LA), typically 1-2 least significant bits - 'fast': enhanced performance mode (EP) - None: mode settings are ignored This ...
[ "Set", "the", "accuracy", "mode", "for", "VML", "operations", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/utils.py#L34-L62
231,933
pydata/numexpr
numexpr/utils.py
_init_num_threads
def _init_num_threads(): """ Detects the environment variable 'NUMEXPR_MAX_THREADS' to set the threadpool size, and if necessary the slightly redundant 'NUMEXPR_NUM_THREADS' or 'OMP_NUM_THREADS' env vars to set the initial number of threads used by the virtual machine. """ # Any platform-...
python
def _init_num_threads(): """ Detects the environment variable 'NUMEXPR_MAX_THREADS' to set the threadpool size, and if necessary the slightly redundant 'NUMEXPR_NUM_THREADS' or 'OMP_NUM_THREADS' env vars to set the initial number of threads used by the virtual machine. """ # Any platform-...
[ "def", "_init_num_threads", "(", ")", ":", "# Any platform-specific short-circuits", "if", "'sparc'", "in", "platform", ".", "machine", "(", ")", ":", "log", ".", "warning", "(", "'The number of threads have been set to 1 because problems related '", "'to threading have been ...
Detects the environment variable 'NUMEXPR_MAX_THREADS' to set the threadpool size, and if necessary the slightly redundant 'NUMEXPR_NUM_THREADS' or 'OMP_NUM_THREADS' env vars to set the initial number of threads used by the virtual machine.
[ "Detects", "the", "environment", "variable", "NUMEXPR_MAX_THREADS", "to", "set", "the", "threadpool", "size", "and", "if", "necessary", "the", "slightly", "redundant", "NUMEXPR_NUM_THREADS", "or", "OMP_NUM_THREADS", "env", "vars", "to", "set", "the", "initial", "num...
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/utils.py#L100-L145
231,934
pydata/numexpr
numexpr/utils.py
detect_number_of_cores
def detect_number_of_cores(): """ Detects the number of cores on a system. Cribbed from pp. """ # Linux, Unix and MacOS: if hasattr(os, "sysconf"): if "SC_NPROCESSORS_ONLN" in os.sysconf_names: # Linux & Unix: ncpus = os.sysconf("SC_NPROCESSORS_ONLN") if i...
python
def detect_number_of_cores(): """ Detects the number of cores on a system. Cribbed from pp. """ # Linux, Unix and MacOS: if hasattr(os, "sysconf"): if "SC_NPROCESSORS_ONLN" in os.sysconf_names: # Linux & Unix: ncpus = os.sysconf("SC_NPROCESSORS_ONLN") if i...
[ "def", "detect_number_of_cores", "(", ")", ":", "# Linux, Unix and MacOS:", "if", "hasattr", "(", "os", ",", "\"sysconf\"", ")", ":", "if", "\"SC_NPROCESSORS_ONLN\"", "in", "os", ".", "sysconf_names", ":", "# Linux & Unix:", "ncpus", "=", "os", ".", "sysconf", "...
Detects the number of cores on a system. Cribbed from pp.
[ "Detects", "the", "number", "of", "cores", "on", "a", "system", ".", "Cribbed", "from", "pp", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/utils.py#L148-L168
231,935
pydata/numexpr
bench/multidim.py
chunkify
def chunkify(chunksize): """ Very stupid "chunk vectorizer" which keeps memory use down. This version requires all inputs to have the same number of elements, although it shouldn't be that hard to implement simple broadcasting. """ def chunkifier(func): def wrap(*args): ...
python
def chunkify(chunksize): """ Very stupid "chunk vectorizer" which keeps memory use down. This version requires all inputs to have the same number of elements, although it shouldn't be that hard to implement simple broadcasting. """ def chunkifier(func): def wrap(*args): ...
[ "def", "chunkify", "(", "chunksize", ")", ":", "def", "chunkifier", "(", "func", ")", ":", "def", "wrap", "(", "*", "args", ")", ":", "assert", "len", "(", "args", ")", ">", "0", "assert", "all", "(", "len", "(", "a", ".", "flat", ")", "==", "l...
Very stupid "chunk vectorizer" which keeps memory use down. This version requires all inputs to have the same number of elements, although it shouldn't be that hard to implement simple broadcasting.
[ "Very", "stupid", "chunk", "vectorizer", "which", "keeps", "memory", "use", "down", ".", "This", "version", "requires", "all", "inputs", "to", "have", "the", "same", "number", "of", "elements", "although", "it", "shouldn", "t", "be", "that", "hard", "to", ...
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/bench/multidim.py#L28-L57
231,936
pydata/numexpr
numexpr/necompiler.py
expressionToAST
def expressionToAST(ex): """Take an expression tree made out of expressions.ExpressionNode, and convert to an AST tree. This is necessary as ExpressionNode overrides many methods to act like a number. """ return ASTNode(ex.astType, ex.astKind, ex.value, [expressionToAST(c) fo...
python
def expressionToAST(ex): """Take an expression tree made out of expressions.ExpressionNode, and convert to an AST tree. This is necessary as ExpressionNode overrides many methods to act like a number. """ return ASTNode(ex.astType, ex.astKind, ex.value, [expressionToAST(c) fo...
[ "def", "expressionToAST", "(", "ex", ")", ":", "return", "ASTNode", "(", "ex", ".", "astType", ",", "ex", ".", "astKind", ",", "ex", ".", "value", ",", "[", "expressionToAST", "(", "c", ")", "for", "c", "in", "ex", ".", "children", "]", ")" ]
Take an expression tree made out of expressions.ExpressionNode, and convert to an AST tree. This is necessary as ExpressionNode overrides many methods to act like a number.
[ "Take", "an", "expression", "tree", "made", "out", "of", "expressions", ".", "ExpressionNode", "and", "convert", "to", "an", "AST", "tree", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L158-L166
231,937
pydata/numexpr
numexpr/necompiler.py
sigPerms
def sigPerms(s): """Generate all possible signatures derived by upcasting the given signature. """ codes = 'bilfdc' if not s: yield '' elif s[0] in codes: start = codes.index(s[0]) for x in codes[start:]: for y in sigPerms(s[1:]): yield x + y ...
python
def sigPerms(s): """Generate all possible signatures derived by upcasting the given signature. """ codes = 'bilfdc' if not s: yield '' elif s[0] in codes: start = codes.index(s[0]) for x in codes[start:]: for y in sigPerms(s[1:]): yield x + y ...
[ "def", "sigPerms", "(", "s", ")", ":", "codes", "=", "'bilfdc'", "if", "not", "s", ":", "yield", "''", "elif", "s", "[", "0", "]", "in", "codes", ":", "start", "=", "codes", ".", "index", "(", "s", "[", "0", "]", ")", "for", "x", "in", "codes...
Generate all possible signatures derived by upcasting the given signature.
[ "Generate", "all", "possible", "signatures", "derived", "by", "upcasting", "the", "given", "signature", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L169-L185
231,938
pydata/numexpr
numexpr/necompiler.py
typeCompileAst
def typeCompileAst(ast): """Assign appropiate types to each node in the AST. Will convert opcodes and functions to appropiate upcast version, and add "cast" ops if needed. """ children = list(ast.children) if ast.astType == 'op': retsig = ast.typecode() basesig = ''.join(x.typec...
python
def typeCompileAst(ast): """Assign appropiate types to each node in the AST. Will convert opcodes and functions to appropiate upcast version, and add "cast" ops if needed. """ children = list(ast.children) if ast.astType == 'op': retsig = ast.typecode() basesig = ''.join(x.typec...
[ "def", "typeCompileAst", "(", "ast", ")", ":", "children", "=", "list", "(", "ast", ".", "children", ")", "if", "ast", ".", "astType", "==", "'op'", ":", "retsig", "=", "ast", ".", "typecode", "(", ")", "basesig", "=", "''", ".", "join", "(", "x", ...
Assign appropiate types to each node in the AST. Will convert opcodes and functions to appropiate upcast version, and add "cast" ops if needed.
[ "Assign", "appropiate", "types", "to", "each", "node", "in", "the", "AST", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L188-L228
231,939
pydata/numexpr
numexpr/necompiler.py
stringToExpression
def stringToExpression(s, types, context): """Given a string, convert it to a tree of ExpressionNode's. """ old_ctx = expressions._context.get_current_context() try: expressions._context.set_new_context(context) # first compile to a code object to determine the names if context.g...
python
def stringToExpression(s, types, context): """Given a string, convert it to a tree of ExpressionNode's. """ old_ctx = expressions._context.get_current_context() try: expressions._context.set_new_context(context) # first compile to a code object to determine the names if context.g...
[ "def", "stringToExpression", "(", "s", ",", "types", ",", "context", ")", ":", "old_ctx", "=", "expressions", ".", "_context", ".", "get_current_context", "(", ")", "try", ":", "expressions", ".", "_context", ".", "set_new_context", "(", "context", ")", "# f...
Given a string, convert it to a tree of ExpressionNode's.
[ "Given", "a", "string", "convert", "it", "to", "a", "tree", "of", "ExpressionNode", "s", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L273-L306
231,940
pydata/numexpr
numexpr/necompiler.py
getInputOrder
def getInputOrder(ast, input_order=None): """Derive the input order of the variables in an expression. """ variables = {} for a in ast.allOf('variable'): variables[a.value] = a variable_names = set(variables.keys()) if input_order: if variable_names != set(input_order): ...
python
def getInputOrder(ast, input_order=None): """Derive the input order of the variables in an expression. """ variables = {} for a in ast.allOf('variable'): variables[a.value] = a variable_names = set(variables.keys()) if input_order: if variable_names != set(input_order): ...
[ "def", "getInputOrder", "(", "ast", ",", "input_order", "=", "None", ")", ":", "variables", "=", "{", "}", "for", "a", "in", "ast", ".", "allOf", "(", "'variable'", ")", ":", "variables", "[", "a", ".", "value", "]", "=", "a", "variable_names", "=", ...
Derive the input order of the variables in an expression.
[ "Derive", "the", "input", "order", "of", "the", "variables", "in", "an", "expression", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L314-L333
231,941
pydata/numexpr
numexpr/necompiler.py
assignLeafRegisters
def assignLeafRegisters(inodes, registerMaker): """Assign new registers to each of the leaf nodes. """ leafRegisters = {} for node in inodes: key = node.key() if key in leafRegisters: node.reg = leafRegisters[key] else: node.reg = leafRegisters[key] = regi...
python
def assignLeafRegisters(inodes, registerMaker): """Assign new registers to each of the leaf nodes. """ leafRegisters = {} for node in inodes: key = node.key() if key in leafRegisters: node.reg = leafRegisters[key] else: node.reg = leafRegisters[key] = regi...
[ "def", "assignLeafRegisters", "(", "inodes", ",", "registerMaker", ")", ":", "leafRegisters", "=", "{", "}", "for", "node", "in", "inodes", ":", "key", "=", "node", ".", "key", "(", ")", "if", "key", "in", "leafRegisters", ":", "node", ".", "reg", "=",...
Assign new registers to each of the leaf nodes.
[ "Assign", "new", "registers", "to", "each", "of", "the", "leaf", "nodes", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L368-L377
231,942
pydata/numexpr
numexpr/necompiler.py
assignBranchRegisters
def assignBranchRegisters(inodes, registerMaker): """Assign temporary registers to each of the branch nodes. """ for node in inodes: node.reg = registerMaker(node, temporary=True)
python
def assignBranchRegisters(inodes, registerMaker): """Assign temporary registers to each of the branch nodes. """ for node in inodes: node.reg = registerMaker(node, temporary=True)
[ "def", "assignBranchRegisters", "(", "inodes", ",", "registerMaker", ")", ":", "for", "node", "in", "inodes", ":", "node", ".", "reg", "=", "registerMaker", "(", "node", ",", "temporary", "=", "True", ")" ]
Assign temporary registers to each of the branch nodes.
[ "Assign", "temporary", "registers", "to", "each", "of", "the", "branch", "nodes", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L380-L384
231,943
pydata/numexpr
numexpr/necompiler.py
collapseDuplicateSubtrees
def collapseDuplicateSubtrees(ast): """Common subexpression elimination. """ seen = {} aliases = [] for a in ast.allOf('op'): if a in seen: target = seen[a] a.astType = 'alias' a.value = target a.children = () aliases.append(a) ...
python
def collapseDuplicateSubtrees(ast): """Common subexpression elimination. """ seen = {} aliases = [] for a in ast.allOf('op'): if a in seen: target = seen[a] a.astType = 'alias' a.value = target a.children = () aliases.append(a) ...
[ "def", "collapseDuplicateSubtrees", "(", "ast", ")", ":", "seen", "=", "{", "}", "aliases", "=", "[", "]", "for", "a", "in", "ast", ".", "allOf", "(", "'op'", ")", ":", "if", "a", "in", "seen", ":", "target", "=", "seen", "[", "a", "]", "a", "....
Common subexpression elimination.
[ "Common", "subexpression", "elimination", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L387-L406
231,944
pydata/numexpr
numexpr/necompiler.py
optimizeTemporariesAllocation
def optimizeTemporariesAllocation(ast): """Attempt to minimize the number of temporaries needed, by reusing old ones. """ nodes = [n for n in ast.postorderWalk() if n.reg.temporary] users_of = dict((n.reg, set()) for n in nodes) node_regs = dict((n, set(c.reg for c in n.children if c.reg.tempor...
python
def optimizeTemporariesAllocation(ast): """Attempt to minimize the number of temporaries needed, by reusing old ones. """ nodes = [n for n in ast.postorderWalk() if n.reg.temporary] users_of = dict((n.reg, set()) for n in nodes) node_regs = dict((n, set(c.reg for c in n.children if c.reg.tempor...
[ "def", "optimizeTemporariesAllocation", "(", "ast", ")", ":", "nodes", "=", "[", "n", "for", "n", "in", "ast", ".", "postorderWalk", "(", ")", "if", "n", ".", "reg", ".", "temporary", "]", "users_of", "=", "dict", "(", "(", "n", ".", "reg", ",", "s...
Attempt to minimize the number of temporaries needed, by reusing old ones.
[ "Attempt", "to", "minimize", "the", "number", "of", "temporaries", "needed", "by", "reusing", "old", "ones", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L409-L439
231,945
pydata/numexpr
numexpr/necompiler.py
setOrderedRegisterNumbers
def setOrderedRegisterNumbers(order, start): """Given an order of nodes, assign register numbers. """ for i, node in enumerate(order): node.reg.n = start + i return start + len(order)
python
def setOrderedRegisterNumbers(order, start): """Given an order of nodes, assign register numbers. """ for i, node in enumerate(order): node.reg.n = start + i return start + len(order)
[ "def", "setOrderedRegisterNumbers", "(", "order", ",", "start", ")", ":", "for", "i", ",", "node", "in", "enumerate", "(", "order", ")", ":", "node", ".", "reg", ".", "n", "=", "start", "+", "i", "return", "start", "+", "len", "(", "order", ")" ]
Given an order of nodes, assign register numbers.
[ "Given", "an", "order", "of", "nodes", "assign", "register", "numbers", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L442-L447
231,946
pydata/numexpr
numexpr/necompiler.py
setRegisterNumbersForTemporaries
def setRegisterNumbersForTemporaries(ast, start): """Assign register numbers for temporary registers, keeping track of aliases and handling immediate operands. """ seen = 0 signature = '' aliases = [] for node in ast.postorderWalk(): if node.astType == 'alias': aliases.ap...
python
def setRegisterNumbersForTemporaries(ast, start): """Assign register numbers for temporary registers, keeping track of aliases and handling immediate operands. """ seen = 0 signature = '' aliases = [] for node in ast.postorderWalk(): if node.astType == 'alias': aliases.ap...
[ "def", "setRegisterNumbersForTemporaries", "(", "ast", ",", "start", ")", ":", "seen", "=", "0", "signature", "=", "''", "aliases", "=", "[", "]", "for", "node", "in", "ast", ".", "postorderWalk", "(", ")", ":", "if", "node", ".", "astType", "==", "'al...
Assign register numbers for temporary registers, keeping track of aliases and handling immediate operands.
[ "Assign", "register", "numbers", "for", "temporary", "registers", "keeping", "track", "of", "aliases", "and", "handling", "immediate", "operands", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L450-L471
231,947
pydata/numexpr
numexpr/necompiler.py
convertASTtoThreeAddrForm
def convertASTtoThreeAddrForm(ast): """Convert an AST to a three address form. Three address form is (op, reg1, reg2, reg3), where reg1 is the destination of the result of the instruction. I suppose this should be called three register form, but three address form is found in compiler theory. ...
python
def convertASTtoThreeAddrForm(ast): """Convert an AST to a three address form. Three address form is (op, reg1, reg2, reg3), where reg1 is the destination of the result of the instruction. I suppose this should be called three register form, but three address form is found in compiler theory. ...
[ "def", "convertASTtoThreeAddrForm", "(", "ast", ")", ":", "return", "[", "(", "node", ".", "value", ",", "node", ".", "reg", ")", "+", "tuple", "(", "[", "c", ".", "reg", "for", "c", "in", "node", ".", "children", "]", ")", "for", "node", "in", "...
Convert an AST to a three address form. Three address form is (op, reg1, reg2, reg3), where reg1 is the destination of the result of the instruction. I suppose this should be called three register form, but three address form is found in compiler theory.
[ "Convert", "an", "AST", "to", "a", "three", "address", "form", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L474-L484
231,948
pydata/numexpr
numexpr/necompiler.py
compileThreeAddrForm
def compileThreeAddrForm(program): """Given a three address form of the program, compile it a string that the VM understands. """ def nToChr(reg): if reg is None: return b'\xff' elif reg.n < 0: raise ValueError("negative value for register number %s" % reg.n) ...
python
def compileThreeAddrForm(program): """Given a three address form of the program, compile it a string that the VM understands. """ def nToChr(reg): if reg is None: return b'\xff' elif reg.n < 0: raise ValueError("negative value for register number %s" % reg.n) ...
[ "def", "compileThreeAddrForm", "(", "program", ")", ":", "def", "nToChr", "(", "reg", ")", ":", "if", "reg", "is", "None", ":", "return", "b'\\xff'", "elif", "reg", ".", "n", "<", "0", ":", "raise", "ValueError", "(", "\"negative value for register number %s...
Given a three address form of the program, compile it a string that the VM understands.
[ "Given", "a", "three", "address", "form", "of", "the", "program", "compile", "it", "a", "string", "that", "the", "VM", "understands", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L487-L526
231,949
pydata/numexpr
numexpr/necompiler.py
precompile
def precompile(ex, signature=(), context={}): """Compile the expression to an intermediate form. """ types = dict(signature) input_order = [name for (name, type_) in signature] if isinstance(ex, (str, unicode)): ex = stringToExpression(ex, types, context) # the AST is like the expressi...
python
def precompile(ex, signature=(), context={}): """Compile the expression to an intermediate form. """ types = dict(signature) input_order = [name for (name, type_) in signature] if isinstance(ex, (str, unicode)): ex = stringToExpression(ex, types, context) # the AST is like the expressi...
[ "def", "precompile", "(", "ex", ",", "signature", "=", "(", ")", ",", "context", "=", "{", "}", ")", ":", "types", "=", "dict", "(", "signature", ")", "input_order", "=", "[", "name", "for", "(", "name", ",", "type_", ")", "in", "signature", "]", ...
Compile the expression to an intermediate form.
[ "Compile", "the", "expression", "to", "an", "intermediate", "form", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L554-L604
231,950
pydata/numexpr
numexpr/necompiler.py
disassemble
def disassemble(nex): """ Given a NumExpr object, return a list which is the program disassembled. """ rev_opcodes = {} for op in interpreter.opcodes: rev_opcodes[interpreter.opcodes[op]] = op r_constants = 1 + len(nex.signature) r_temps = r_constants + len(nex.constants) def ge...
python
def disassemble(nex): """ Given a NumExpr object, return a list which is the program disassembled. """ rev_opcodes = {} for op in interpreter.opcodes: rev_opcodes[interpreter.opcodes[op]] = op r_constants = 1 + len(nex.signature) r_temps = r_constants + len(nex.constants) def ge...
[ "def", "disassemble", "(", "nex", ")", ":", "rev_opcodes", "=", "{", "}", "for", "op", "in", "interpreter", ".", "opcodes", ":", "rev_opcodes", "[", "interpreter", ".", "opcodes", "[", "op", "]", "]", "=", "op", "r_constants", "=", "1", "+", "len", "...
Given a NumExpr object, return a list which is the program disassembled.
[ "Given", "a", "NumExpr", "object", "return", "a", "list", "which", "is", "the", "program", "disassembled", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L633-L682
231,951
pydata/numexpr
numexpr/necompiler.py
getArguments
def getArguments(names, local_dict=None, global_dict=None): """Get the arguments based on the names.""" call_frame = sys._getframe(2) clear_local_dict = False if local_dict is None: local_dict = call_frame.f_locals clear_local_dict = True try: frame_globals = call_frame.f_gl...
python
def getArguments(names, local_dict=None, global_dict=None): """Get the arguments based on the names.""" call_frame = sys._getframe(2) clear_local_dict = False if local_dict is None: local_dict = call_frame.f_locals clear_local_dict = True try: frame_globals = call_frame.f_gl...
[ "def", "getArguments", "(", "names", ",", "local_dict", "=", "None", ",", "global_dict", "=", "None", ")", ":", "call_frame", "=", "sys", ".", "_getframe", "(", "2", ")", "clear_local_dict", "=", "False", "if", "local_dict", "is", "None", ":", "local_dict"...
Get the arguments based on the names.
[ "Get", "the", "arguments", "based", "on", "the", "names", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L724-L755
231,952
pydata/numexpr
numexpr/necompiler.py
evaluate
def evaluate(ex, local_dict=None, global_dict=None, out=None, order='K', casting='safe', **kwargs): """Evaluate a simple array expression element-wise, using the new iterator. ex is a string forming an expression, like "2*a+3*b". The values for "a" and "b" will by default be taken from the cal...
python
def evaluate(ex, local_dict=None, global_dict=None, out=None, order='K', casting='safe', **kwargs): """Evaluate a simple array expression element-wise, using the new iterator. ex is a string forming an expression, like "2*a+3*b". The values for "a" and "b" will by default be taken from the cal...
[ "def", "evaluate", "(", "ex", ",", "local_dict", "=", "None", ",", "global_dict", "=", "None", ",", "out", "=", "None", ",", "order", "=", "'K'", ",", "casting", "=", "'safe'", ",", "*", "*", "kwargs", ")", ":", "global", "_numexpr_last", "if", "not"...
Evaluate a simple array expression element-wise, using the new iterator. ex is a string forming an expression, like "2*a+3*b". The values for "a" and "b" will by default be taken from the calling function's frame (through use of sys._getframe()). Alternatively, they can be specifed using the 'local_dic...
[ "Evaluate", "a", "simple", "array", "expression", "element", "-", "wise", "using", "the", "new", "iterator", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L765-L834
231,953
pydata/numexpr
numexpr/necompiler.py
re_evaluate
def re_evaluate(local_dict=None): """Re-evaluate the previous executed array expression without any check. This is meant for accelerating loops that are re-evaluating the same expression repeatedly without changing anything else than the operands. If unsure, use evaluate() which is safer. Paramete...
python
def re_evaluate(local_dict=None): """Re-evaluate the previous executed array expression without any check. This is meant for accelerating loops that are re-evaluating the same expression repeatedly without changing anything else than the operands. If unsure, use evaluate() which is safer. Paramete...
[ "def", "re_evaluate", "(", "local_dict", "=", "None", ")", ":", "try", ":", "compiled_ex", "=", "_numexpr_last", "[", "'ex'", "]", "except", "KeyError", ":", "raise", "RuntimeError", "(", "\"not a previous evaluate() execution found\"", ")", "argnames", "=", "_num...
Re-evaluate the previous executed array expression without any check. This is meant for accelerating loops that are re-evaluating the same expression repeatedly without changing anything else than the operands. If unsure, use evaluate() which is safer. Parameters ---------- local_dict : dicti...
[ "Re", "-", "evaluate", "the", "previous", "executed", "array", "expression", "without", "any", "check", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/numexpr/necompiler.py#L837-L859
231,954
pydata/numexpr
bench/poly.py
compute
def compute(): """Compute the polynomial.""" if what == "numpy": y = eval(expr) else: y = ne.evaluate(expr) return len(y)
python
def compute(): """Compute the polynomial.""" if what == "numpy": y = eval(expr) else: y = ne.evaluate(expr) return len(y)
[ "def", "compute", "(", ")", ":", "if", "what", "==", "\"numpy\"", ":", "y", "=", "eval", "(", "expr", ")", "else", ":", "y", "=", "ne", ".", "evaluate", "(", "expr", ")", "return", "len", "(", "y", ")" ]
Compute the polynomial.
[ "Compute", "the", "polynomial", "." ]
364bac13d84524e0e01db892301b2959d822dcff
https://github.com/pydata/numexpr/blob/364bac13d84524e0e01db892301b2959d822dcff/bench/poly.py#L34-L40
231,955
MaxHalford/prince
prince/mfa.py
MFA.partial_row_coordinates
def partial_row_coordinates(self, X): """Returns the row coordinates for each group.""" utils.validation.check_is_fitted(self, 's_') # Check input if self.check_input: utils.check_array(X, dtype=[str, np.number]) # Prepare input X = self._prepare_input(X) ...
python
def partial_row_coordinates(self, X): """Returns the row coordinates for each group.""" utils.validation.check_is_fitted(self, 's_') # Check input if self.check_input: utils.check_array(X, dtype=[str, np.number]) # Prepare input X = self._prepare_input(X) ...
[ "def", "partial_row_coordinates", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "# Check input", "if", "self", ".", "check_input", ":", "utils", ".", "check_array", "(", "X", ",", "dtype...
Returns the row coordinates for each group.
[ "Returns", "the", "row", "coordinates", "for", "each", "group", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/mfa.py#L158-L190
231,956
MaxHalford/prince
prince/mfa.py
MFA.column_correlations
def column_correlations(self, X): """Returns the column correlations.""" utils.validation.check_is_fitted(self, 's_') X_global = self._build_X_global(X) row_pc = self._row_coordinates_from_global(X_global) return pd.DataFrame({ component: { feature: ...
python
def column_correlations(self, X): """Returns the column correlations.""" utils.validation.check_is_fitted(self, 's_') X_global = self._build_X_global(X) row_pc = self._row_coordinates_from_global(X_global) return pd.DataFrame({ component: { feature: ...
[ "def", "column_correlations", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "X_global", "=", "self", ".", "_build_X_global", "(", "X", ")", "row_pc", "=", "self", ".", "_row_coordinates_...
Returns the column correlations.
[ "Returns", "the", "column", "correlations", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/mfa.py#L192-L205
231,957
MaxHalford/prince
prince/ca.py
CA.eigenvalues_
def eigenvalues_(self): """The eigenvalues associated with each principal component.""" utils.validation.check_is_fitted(self, 's_') return np.square(self.s_).tolist()
python
def eigenvalues_(self): """The eigenvalues associated with each principal component.""" utils.validation.check_is_fitted(self, 's_') return np.square(self.s_).tolist()
[ "def", "eigenvalues_", "(", "self", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "return", "np", ".", "square", "(", "self", ".", "s_", ")", ".", "tolist", "(", ")" ]
The eigenvalues associated with each principal component.
[ "The", "eigenvalues", "associated", "with", "each", "principal", "component", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/ca.py#L82-L85
231,958
MaxHalford/prince
prince/ca.py
CA.explained_inertia_
def explained_inertia_(self): """The percentage of explained inertia per principal component.""" utils.validation.check_is_fitted(self, 'total_inertia_') return [eig / self.total_inertia_ for eig in self.eigenvalues_]
python
def explained_inertia_(self): """The percentage of explained inertia per principal component.""" utils.validation.check_is_fitted(self, 'total_inertia_') return [eig / self.total_inertia_ for eig in self.eigenvalues_]
[ "def", "explained_inertia_", "(", "self", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'total_inertia_'", ")", "return", "[", "eig", "/", "self", ".", "total_inertia_", "for", "eig", "in", "self", ".", "eigenvalues_", "]" ...
The percentage of explained inertia per principal component.
[ "The", "percentage", "of", "explained", "inertia", "per", "principal", "component", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/ca.py#L88-L91
231,959
MaxHalford/prince
prince/ca.py
CA.row_coordinates
def row_coordinates(self, X): """The row principal coordinates.""" utils.validation.check_is_fitted(self, 'V_') _, row_names, _, _ = util.make_labels_and_names(X) if isinstance(X, pd.SparseDataFrame): X = X.to_coo().astype(float) elif isinstance(X, pd.DataFrame): ...
python
def row_coordinates(self, X): """The row principal coordinates.""" utils.validation.check_is_fitted(self, 'V_') _, row_names, _, _ = util.make_labels_and_names(X) if isinstance(X, pd.SparseDataFrame): X = X.to_coo().astype(float) elif isinstance(X, pd.DataFrame): ...
[ "def", "row_coordinates", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'V_'", ")", "_", ",", "row_names", ",", "_", ",", "_", "=", "util", ".", "make_labels_and_names", "(", "X", ")", "if", "...
The row principal coordinates.
[ "The", "row", "principal", "coordinates", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/ca.py#L93-L116
231,960
MaxHalford/prince
prince/ca.py
CA.column_coordinates
def column_coordinates(self, X): """The column principal coordinates.""" utils.validation.check_is_fitted(self, 'V_') _, _, _, col_names = util.make_labels_and_names(X) if isinstance(X, pd.SparseDataFrame): X = X.to_coo() elif isinstance(X, pd.DataFrame): ...
python
def column_coordinates(self, X): """The column principal coordinates.""" utils.validation.check_is_fitted(self, 'V_') _, _, _, col_names = util.make_labels_and_names(X) if isinstance(X, pd.SparseDataFrame): X = X.to_coo() elif isinstance(X, pd.DataFrame): ...
[ "def", "column_coordinates", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'V_'", ")", "_", ",", "_", ",", "_", ",", "col_names", "=", "util", ".", "make_labels_and_names", "(", "X", ")", "if", ...
The column principal coordinates.
[ "The", "column", "principal", "coordinates", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/ca.py#L118-L141
231,961
MaxHalford/prince
prince/ca.py
CA.plot_coordinates
def plot_coordinates(self, X, ax=None, figsize=(6, 6), x_component=0, y_component=1, show_row_labels=True, show_col_labels=True, **kwargs): """Plot the principal coordinates.""" utils.validation.check_is_fitted(self, 's_') if ax is None: fig, ax =...
python
def plot_coordinates(self, X, ax=None, figsize=(6, 6), x_component=0, y_component=1, show_row_labels=True, show_col_labels=True, **kwargs): """Plot the principal coordinates.""" utils.validation.check_is_fitted(self, 's_') if ax is None: fig, ax =...
[ "def", "plot_coordinates", "(", "self", ",", "X", ",", "ax", "=", "None", ",", "figsize", "=", "(", "6", ",", "6", ")", ",", "x_component", "=", "0", ",", "y_component", "=", "1", ",", "show_row_labels", "=", "True", ",", "show_col_labels", "=", "Tru...
Plot the principal coordinates.
[ "Plot", "the", "principal", "coordinates", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/ca.py#L143-L199
231,962
MaxHalford/prince
prince/mca.py
MCA.plot_coordinates
def plot_coordinates(self, X, ax=None, figsize=(6, 6), x_component=0, y_component=1, show_row_points=True, row_points_size=10, show_row_labels=False, show_column_points=True, column_points_size=30, show_column_label...
python
def plot_coordinates(self, X, ax=None, figsize=(6, 6), x_component=0, y_component=1, show_row_points=True, row_points_size=10, show_row_labels=False, show_column_points=True, column_points_size=30, show_column_label...
[ "def", "plot_coordinates", "(", "self", ",", "X", ",", "ax", "=", "None", ",", "figsize", "=", "(", "6", ",", "6", ")", ",", "x_component", "=", "0", ",", "y_component", "=", "1", ",", "show_row_points", "=", "True", ",", "row_points_size", "=", "10"...
Plot row and column principal coordinates. Args: ax (matplotlib.Axis): A fresh one will be created and returned if not provided. figsize ((float, float)): The desired figure size if `ax` is not provided. x_component (int): Number of the component used for the x-axis. ...
[ "Plot", "row", "and", "column", "principal", "coordinates", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/mca.py#L49-L126
231,963
MaxHalford/prince
prince/svd.py
compute_svd
def compute_svd(X, n_components, n_iter, random_state, engine): """Computes an SVD with k components.""" # Determine what SVD engine to use if engine == 'auto': engine = 'sklearn' # Compute the SVD if engine == 'fbpca': if FBPCA_INSTALLED: U, s, V = fbpca.pca(X, k=n_com...
python
def compute_svd(X, n_components, n_iter, random_state, engine): """Computes an SVD with k components.""" # Determine what SVD engine to use if engine == 'auto': engine = 'sklearn' # Compute the SVD if engine == 'fbpca': if FBPCA_INSTALLED: U, s, V = fbpca.pca(X, k=n_com...
[ "def", "compute_svd", "(", "X", ",", "n_components", ",", "n_iter", ",", "random_state", ",", "engine", ")", ":", "# Determine what SVD engine to use", "if", "engine", "==", "'auto'", ":", "engine", "=", "'sklearn'", "# Compute the SVD", "if", "engine", "==", "'...
Computes an SVD with k components.
[ "Computes", "an", "SVD", "with", "k", "components", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/svd.py#L10-L35
231,964
MaxHalford/prince
prince/pca.py
PCA.row_standard_coordinates
def row_standard_coordinates(self, X): """Returns the row standard coordinates. The row standard coordinates are obtained by dividing each row principal coordinate by it's associated eigenvalue. """ utils.validation.check_is_fitted(self, 's_') return self.row_coordinates...
python
def row_standard_coordinates(self, X): """Returns the row standard coordinates. The row standard coordinates are obtained by dividing each row principal coordinate by it's associated eigenvalue. """ utils.validation.check_is_fitted(self, 's_') return self.row_coordinates...
[ "def", "row_standard_coordinates", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "return", "self", ".", "row_coordinates", "(", "X", ")", ".", "div", "(", "self", ".", "eigenvalues_", ...
Returns the row standard coordinates. The row standard coordinates are obtained by dividing each row principal coordinate by it's associated eigenvalue.
[ "Returns", "the", "row", "standard", "coordinates", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/pca.py#L106-L113
231,965
MaxHalford/prince
prince/pca.py
PCA.row_cosine_similarities
def row_cosine_similarities(self, X): """Returns the cosine similarities between the rows and their principal components. The row cosine similarities are obtained by calculating the cosine of the angle shaped by the row principal coordinates and the row principal components. This is calculated ...
python
def row_cosine_similarities(self, X): """Returns the cosine similarities between the rows and their principal components. The row cosine similarities are obtained by calculating the cosine of the angle shaped by the row principal coordinates and the row principal components. This is calculated ...
[ "def", "row_cosine_similarities", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "squared_coordinates", "=", "np", ".", "square", "(", "self", ".", "row_coordinates", "(", "X", ")", ")", ...
Returns the cosine similarities between the rows and their principal components. The row cosine similarities are obtained by calculating the cosine of the angle shaped by the row principal coordinates and the row principal components. This is calculated by squaring each row projection coordinat...
[ "Returns", "the", "cosine", "similarities", "between", "the", "rows", "and", "their", "principal", "components", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/pca.py#L125-L137
231,966
MaxHalford/prince
prince/pca.py
PCA.column_correlations
def column_correlations(self, X): """Returns the column correlations with each principal component.""" utils.validation.check_is_fitted(self, 's_') # Convert numpy array to pandas DataFrame if isinstance(X, np.ndarray): X = pd.DataFrame(X) row_pc = self.row_coordina...
python
def column_correlations(self, X): """Returns the column correlations with each principal component.""" utils.validation.check_is_fitted(self, 's_') # Convert numpy array to pandas DataFrame if isinstance(X, np.ndarray): X = pd.DataFrame(X) row_pc = self.row_coordina...
[ "def", "column_correlations", "(", "self", ",", "X", ")", ":", "utils", ".", "validation", ".", "check_is_fitted", "(", "self", ",", "'s_'", ")", "# Convert numpy array to pandas DataFrame", "if", "isinstance", "(", "X", ",", "np", ".", "ndarray", ")", ":", ...
Returns the column correlations with each principal component.
[ "Returns", "the", "column", "correlations", "with", "each", "principal", "component", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/pca.py#L139-L155
231,967
MaxHalford/prince
prince/plot.py
build_ellipse
def build_ellipse(X, Y): """Construct ellipse coordinates from two arrays of numbers. Args: X (1D array_like) Y (1D array_like) Returns: float: The mean of `X`. float: The mean of `Y`. float: The width of the ellipse. float: The height of the ellipse. ...
python
def build_ellipse(X, Y): """Construct ellipse coordinates from two arrays of numbers. Args: X (1D array_like) Y (1D array_like) Returns: float: The mean of `X`. float: The mean of `Y`. float: The width of the ellipse. float: The height of the ellipse. ...
[ "def", "build_ellipse", "(", "X", ",", "Y", ")", ":", "x_mean", "=", "np", ".", "mean", "(", "X", ")", "y_mean", "=", "np", ".", "mean", "(", "Y", ")", "cov_matrix", "=", "np", ".", "cov", "(", "np", ".", "vstack", "(", "(", "X", ",", "Y", ...
Construct ellipse coordinates from two arrays of numbers. Args: X (1D array_like) Y (1D array_like) Returns: float: The mean of `X`. float: The mean of `Y`. float: The width of the ellipse. float: The height of the ellipse. float: The angle of orientatio...
[ "Construct", "ellipse", "coordinates", "from", "two", "arrays", "of", "numbers", "." ]
714c9cdfc4d9f8823eabf550a23ad01fe87c50d7
https://github.com/MaxHalford/prince/blob/714c9cdfc4d9f8823eabf550a23ad01fe87c50d7/prince/plot.py#L27-L55
231,968
projecthamster/hamster
src/hamster/widgets/timeinput.py
TimeInput.set_start_time
def set_start_time(self, start_time): """ set the start time. when start time is set, drop down list will start from start time and duration will be displayed in brackets """ start_time = start_time or dt.time() if isinstance(start_time, dt.time): # ensure that we...
python
def set_start_time(self, start_time): """ set the start time. when start time is set, drop down list will start from start time and duration will be displayed in brackets """ start_time = start_time or dt.time() if isinstance(start_time, dt.time): # ensure that we...
[ "def", "set_start_time", "(", "self", ",", "start_time", ")", ":", "start_time", "=", "start_time", "or", "dt", ".", "time", "(", ")", "if", "isinstance", "(", "start_time", ",", "dt", ".", "time", ")", ":", "# ensure that we operate with time", "self", ".",...
set the start time. when start time is set, drop down list will start from start time and duration will be displayed in brackets
[ "set", "the", "start", "time", ".", "when", "start", "time", "is", "set", "drop", "down", "list", "will", "start", "from", "start", "time", "and", "duration", "will", "be", "displayed", "in", "brackets" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/widgets/timeinput.py#L85-L94
231,969
projecthamster/hamster
src/hamster/lib/__init__.py
extract_time
def extract_time(match): """extract time from a time_re match.""" hour = int(match.group('hour')) minute = int(match.group('minute')) return dt.time(hour, minute)
python
def extract_time(match): """extract time from a time_re match.""" hour = int(match.group('hour')) minute = int(match.group('minute')) return dt.time(hour, minute)
[ "def", "extract_time", "(", "match", ")", ":", "hour", "=", "int", "(", "match", ".", "group", "(", "'hour'", ")", ")", "minute", "=", "int", "(", "match", ".", "group", "(", "'minute'", ")", ")", "return", "dt", ".", "time", "(", "hour", ",", "m...
extract time from a time_re match.
[ "extract", "time", "from", "a", "time_re", "match", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/__init__.py#L40-L44
231,970
projecthamster/hamster
src/hamster/lib/__init__.py
default_logger
def default_logger(name): """Return a toplevel logger. This should be used only in the toplevel file. Files deeper in the hierarchy should use ``logger = logging.getLogger(__name__)``, in order to considered as children of the toplevel logger. Beware that without a setLevel() somewhere, th...
python
def default_logger(name): """Return a toplevel logger. This should be used only in the toplevel file. Files deeper in the hierarchy should use ``logger = logging.getLogger(__name__)``, in order to considered as children of the toplevel logger. Beware that without a setLevel() somewhere, th...
[ "def", "default_logger", "(", "name", ")", ":", "# https://docs.python.org/3/howto/logging.html#logging-advanced-tutorial", "logger", "=", "logging", ".", "getLogger", "(", "name", ")", "# this is a basic handler, with output to stderr", "logger_handler", "=", "logging", ".", ...
Return a toplevel logger. This should be used only in the toplevel file. Files deeper in the hierarchy should use ``logger = logging.getLogger(__name__)``, in order to considered as children of the toplevel logger. Beware that without a setLevel() somewhere, the default value (warning) will be...
[ "Return", "a", "toplevel", "logger", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/__init__.py#L355-L381
231,971
projecthamster/hamster
src/hamster/lib/__init__.py
Fact.serialized
def serialized(self, prepend_date=True): """Return a string fully representing the fact.""" name = self.serialized_name() datetime = self.serialized_time(prepend_date) return "%s %s" % (datetime, name)
python
def serialized(self, prepend_date=True): """Return a string fully representing the fact.""" name = self.serialized_name() datetime = self.serialized_time(prepend_date) return "%s %s" % (datetime, name)
[ "def", "serialized", "(", "self", ",", "prepend_date", "=", "True", ")", ":", "name", "=", "self", ".", "serialized_name", "(", ")", "datetime", "=", "self", ".", "serialized_time", "(", "prepend_date", ")", "return", "\"%s %s\"", "%", "(", "datetime", ","...
Return a string fully representing the fact.
[ "Return", "a", "string", "fully", "representing", "the", "fact", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/__init__.py#L200-L204
231,972
projecthamster/hamster
src/hamster/lib/layout.py
Widget._with_rotation
def _with_rotation(self, w, h): """calculate the actual dimensions after rotation""" res_w = abs(w * math.cos(self.rotation) + h * math.sin(self.rotation)) res_h = abs(h * math.cos(self.rotation) + w * math.sin(self.rotation)) return res_w, res_h
python
def _with_rotation(self, w, h): """calculate the actual dimensions after rotation""" res_w = abs(w * math.cos(self.rotation) + h * math.sin(self.rotation)) res_h = abs(h * math.cos(self.rotation) + w * math.sin(self.rotation)) return res_w, res_h
[ "def", "_with_rotation", "(", "self", ",", "w", ",", "h", ")", ":", "res_w", "=", "abs", "(", "w", "*", "math", ".", "cos", "(", "self", ".", "rotation", ")", "+", "h", "*", "math", ".", "sin", "(", "self", ".", "rotation", ")", ")", "res_h", ...
calculate the actual dimensions after rotation
[ "calculate", "the", "actual", "dimensions", "after", "rotation" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L195-L199
231,973
projecthamster/hamster
src/hamster/lib/layout.py
Widget.queue_resize
def queue_resize(self): """request the element to re-check it's child sprite sizes""" self._children_resize_queued = True parent = getattr(self, "parent", None) if parent and isinstance(parent, graphics.Sprite) and hasattr(parent, "queue_resize"): parent.queue_resize()
python
def queue_resize(self): """request the element to re-check it's child sprite sizes""" self._children_resize_queued = True parent = getattr(self, "parent", None) if parent and isinstance(parent, graphics.Sprite) and hasattr(parent, "queue_resize"): parent.queue_resize()
[ "def", "queue_resize", "(", "self", ")", ":", "self", ".", "_children_resize_queued", "=", "True", "parent", "=", "getattr", "(", "self", ",", "\"parent\"", ",", "None", ")", "if", "parent", "and", "isinstance", "(", "parent", ",", "graphics", ".", "Sprite...
request the element to re-check it's child sprite sizes
[ "request", "the", "element", "to", "re", "-", "check", "it", "s", "child", "sprite", "sizes" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L241-L246
231,974
projecthamster/hamster
src/hamster/lib/layout.py
Widget.get_min_size
def get_min_size(self): """returns size required by the widget""" if self.visible == False: return 0, 0 else: return ((self.min_width or 0) + self.horizontal_padding + self.margin_left + self.margin_right, (self.min_height or 0) + self.vertical_padding...
python
def get_min_size(self): """returns size required by the widget""" if self.visible == False: return 0, 0 else: return ((self.min_width or 0) + self.horizontal_padding + self.margin_left + self.margin_right, (self.min_height or 0) + self.vertical_padding...
[ "def", "get_min_size", "(", "self", ")", ":", "if", "self", ".", "visible", "==", "False", ":", "return", "0", ",", "0", "else", ":", "return", "(", "(", "self", ".", "min_width", "or", "0", ")", "+", "self", ".", "horizontal_padding", "+", "self", ...
returns size required by the widget
[ "returns", "size", "required", "by", "the", "widget" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L249-L255
231,975
projecthamster/hamster
src/hamster/lib/layout.py
Widget.insert
def insert(self, index = 0, *widgets): """insert widget in the sprites list at the given index. by default will prepend.""" for widget in widgets: self._add(widget, index) index +=1 # as we are moving forwards self._sort()
python
def insert(self, index = 0, *widgets): """insert widget in the sprites list at the given index. by default will prepend.""" for widget in widgets: self._add(widget, index) index +=1 # as we are moving forwards self._sort()
[ "def", "insert", "(", "self", ",", "index", "=", "0", ",", "*", "widgets", ")", ":", "for", "widget", "in", "widgets", ":", "self", ".", "_add", "(", "widget", ",", "index", ")", "index", "+=", "1", "# as we are moving forwards", "self", ".", "_sort", ...
insert widget in the sprites list at the given index. by default will prepend.
[ "insert", "widget", "in", "the", "sprites", "list", "at", "the", "given", "index", ".", "by", "default", "will", "prepend", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L259-L265
231,976
projecthamster/hamster
src/hamster/lib/layout.py
Widget.insert_before
def insert_before(self, target): """insert this widget into the targets parent before the target""" if not target.parent: return target.parent.insert(target.parent.sprites.index(target), self)
python
def insert_before(self, target): """insert this widget into the targets parent before the target""" if not target.parent: return target.parent.insert(target.parent.sprites.index(target), self)
[ "def", "insert_before", "(", "self", ",", "target", ")", ":", "if", "not", "target", ".", "parent", ":", "return", "target", ".", "parent", ".", "insert", "(", "target", ".", "parent", ".", "sprites", ".", "index", "(", "target", ")", ",", "self", ")...
insert this widget into the targets parent before the target
[ "insert", "this", "widget", "into", "the", "targets", "parent", "before", "the", "target" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L268-L272
231,977
projecthamster/hamster
src/hamster/lib/layout.py
Widget.insert_after
def insert_after(self, target): """insert this widget into the targets parent container after the target""" if not target.parent: return target.parent.insert(target.parent.sprites.index(target) + 1, self)
python
def insert_after(self, target): """insert this widget into the targets parent container after the target""" if not target.parent: return target.parent.insert(target.parent.sprites.index(target) + 1, self)
[ "def", "insert_after", "(", "self", ",", "target", ")", ":", "if", "not", "target", ".", "parent", ":", "return", "target", ".", "parent", ".", "insert", "(", "target", ".", "parent", ".", "sprites", ".", "index", "(", "target", ")", "+", "1", ",", ...
insert this widget into the targets parent container after the target
[ "insert", "this", "widget", "into", "the", "targets", "parent", "container", "after", "the", "target" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L274-L278
231,978
projecthamster/hamster
src/hamster/lib/layout.py
Widget.width
def width(self): """width in pixels""" alloc_w = self.alloc_w if self.parent and isinstance(self.parent, graphics.Scene): alloc_w = self.parent.width def res(scene, event): if self.parent: self.queue_resize() else: ...
python
def width(self): """width in pixels""" alloc_w = self.alloc_w if self.parent and isinstance(self.parent, graphics.Scene): alloc_w = self.parent.width def res(scene, event): if self.parent: self.queue_resize() else: ...
[ "def", "width", "(", "self", ")", ":", "alloc_w", "=", "self", ".", "alloc_w", "if", "self", ".", "parent", "and", "isinstance", "(", "self", ".", "parent", ",", "graphics", ".", "Scene", ")", ":", "alloc_w", "=", "self", ".", "parent", ".", "width",...
width in pixels
[ "width", "in", "pixels" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L282-L305
231,979
projecthamster/hamster
src/hamster/lib/layout.py
Widget.height
def height(self): """height in pixels""" alloc_h = self.alloc_h if self.parent and isinstance(self.parent, graphics.Scene): alloc_h = self.parent.height min_height = (self.min_height or 0) + self.margin_top + self.margin_bottom h = alloc_h if alloc_h is not None and...
python
def height(self): """height in pixels""" alloc_h = self.alloc_h if self.parent and isinstance(self.parent, graphics.Scene): alloc_h = self.parent.height min_height = (self.min_height or 0) + self.margin_top + self.margin_bottom h = alloc_h if alloc_h is not None and...
[ "def", "height", "(", "self", ")", ":", "alloc_h", "=", "self", ".", "alloc_h", "if", "self", ".", "parent", "and", "isinstance", "(", "self", ".", "parent", ",", "graphics", ".", "Scene", ")", ":", "alloc_h", "=", "self", ".", "parent", ".", "height...
height in pixels
[ "height", "in", "pixels" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L308-L318
231,980
projecthamster/hamster
src/hamster/lib/layout.py
Widget.enabled
def enabled(self): """whether the user is allowed to interact with the widget. Item is enabled only if all it's parent elements are""" enabled = self._enabled if not enabled: return False if self.parent and isinstance(self.parent, Widget): if self.parent....
python
def enabled(self): """whether the user is allowed to interact with the widget. Item is enabled only if all it's parent elements are""" enabled = self._enabled if not enabled: return False if self.parent and isinstance(self.parent, Widget): if self.parent....
[ "def", "enabled", "(", "self", ")", ":", "enabled", "=", "self", ".", "_enabled", "if", "not", "enabled", ":", "return", "False", "if", "self", ".", "parent", "and", "isinstance", "(", "self", ".", "parent", ",", "Widget", ")", ":", "if", "self", "."...
whether the user is allowed to interact with the widget. Item is enabled only if all it's parent elements are
[ "whether", "the", "user", "is", "allowed", "to", "interact", "with", "the", "widget", ".", "Item", "is", "enabled", "only", "if", "all", "it", "s", "parent", "elements", "are" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L321-L332
231,981
projecthamster/hamster
src/hamster/lib/layout.py
Container.resize_children
def resize_children(self): """default container alignment is to pile stuff just up, respecting only padding, margin and element's alignment properties""" width = self.width - self.horizontal_padding height = self.height - self.vertical_padding for sprite, props in (get_props(spr...
python
def resize_children(self): """default container alignment is to pile stuff just up, respecting only padding, margin and element's alignment properties""" width = self.width - self.horizontal_padding height = self.height - self.vertical_padding for sprite, props in (get_props(spr...
[ "def", "resize_children", "(", "self", ")", ":", "width", "=", "self", ".", "width", "-", "self", ".", "horizontal_padding", "height", "=", "self", ".", "height", "-", "self", ".", "vertical_padding", "for", "sprite", ",", "props", "in", "(", "get_props", ...
default container alignment is to pile stuff just up, respecting only padding, margin and element's alignment properties
[ "default", "container", "alignment", "is", "to", "pile", "stuff", "just", "up", "respecting", "only", "padding", "margin", "and", "element", "s", "alignment", "properties" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/layout.py#L474-L496
231,982
projecthamster/hamster
src/hamster/lib/desktop.py
DesktopIntegrations.check_hamster
def check_hamster(self): """refresh hamster every x secs - load today, check last activity etc.""" try: # can't use the client because then we end up in a dbus loop # as this is initiated in storage todays_facts = self.storage._Storage__get_todays_facts() ...
python
def check_hamster(self): """refresh hamster every x secs - load today, check last activity etc.""" try: # can't use the client because then we end up in a dbus loop # as this is initiated in storage todays_facts = self.storage._Storage__get_todays_facts() ...
[ "def", "check_hamster", "(", "self", ")", ":", "try", ":", "# can't use the client because then we end up in a dbus loop", "# as this is initiated in storage", "todays_facts", "=", "self", ".", "storage", ".", "_Storage__get_todays_facts", "(", ")", "self", ".", "check_user...
refresh hamster every x secs - load today, check last activity etc.
[ "refresh", "hamster", "every", "x", "secs", "-", "load", "today", "check", "last", "activity", "etc", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/desktop.py#L52-L62
231,983
projecthamster/hamster
src/hamster/lib/desktop.py
DesktopIntegrations.check_user
def check_user(self, todays_facts): """check if we need to notify user perhaps""" interval = self.conf_notify_interval if interval <= 0 or interval >= 121: return now = dt.datetime.now() message = None last_activity = todays_facts[-1] if todays_facts else No...
python
def check_user(self, todays_facts): """check if we need to notify user perhaps""" interval = self.conf_notify_interval if interval <= 0 or interval >= 121: return now = dt.datetime.now() message = None last_activity = todays_facts[-1] if todays_facts else No...
[ "def", "check_user", "(", "self", ",", "todays_facts", ")", ":", "interval", "=", "self", ".", "conf_notify_interval", "if", "interval", "<=", "0", "or", "interval", ">=", "121", ":", "return", "now", "=", "dt", ".", "datetime", ".", "now", "(", ")", "...
check if we need to notify user perhaps
[ "check", "if", "we", "need", "to", "notify", "user", "perhaps" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/desktop.py#L65-L88
231,984
projecthamster/hamster
src/hamster/storage/storage.py
Storage.stop_tracking
def stop_tracking(self, end_time): """Stops tracking the current activity""" facts = self.__get_todays_facts() if facts and not facts[-1]['end_time']: self.__touch_fact(facts[-1], end_time) self.facts_changed()
python
def stop_tracking(self, end_time): """Stops tracking the current activity""" facts = self.__get_todays_facts() if facts and not facts[-1]['end_time']: self.__touch_fact(facts[-1], end_time) self.facts_changed()
[ "def", "stop_tracking", "(", "self", ",", "end_time", ")", ":", "facts", "=", "self", ".", "__get_todays_facts", "(", ")", "if", "facts", "and", "not", "facts", "[", "-", "1", "]", "[", "'end_time'", "]", ":", "self", ".", "__touch_fact", "(", "facts",...
Stops tracking the current activity
[ "Stops", "tracking", "the", "current", "activity" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/storage/storage.py#L67-L72
231,985
projecthamster/hamster
src/hamster/storage/storage.py
Storage.remove_fact
def remove_fact(self, fact_id): """Remove fact from storage by it's ID""" self.start_transaction() fact = self.__get_fact(fact_id) if fact: self.__remove_fact(fact_id) self.facts_changed() self.end_transaction()
python
def remove_fact(self, fact_id): """Remove fact from storage by it's ID""" self.start_transaction() fact = self.__get_fact(fact_id) if fact: self.__remove_fact(fact_id) self.facts_changed() self.end_transaction()
[ "def", "remove_fact", "(", "self", ",", "fact_id", ")", ":", "self", ".", "start_transaction", "(", ")", "fact", "=", "self", ".", "__get_fact", "(", "fact_id", ")", "if", "fact", ":", "self", ".", "__remove_fact", "(", "fact_id", ")", "self", ".", "fa...
Remove fact from storage by it's ID
[ "Remove", "fact", "from", "storage", "by", "it", "s", "ID" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/storage/storage.py#L75-L82
231,986
projecthamster/hamster
src/hamster/lib/configuration.py
load_ui_file
def load_ui_file(name): """loads interface from the glade file; sorts out the path business""" ui = gtk.Builder() ui.add_from_file(os.path.join(runtime.data_dir, name)) return ui
python
def load_ui_file(name): """loads interface from the glade file; sorts out the path business""" ui = gtk.Builder() ui.add_from_file(os.path.join(runtime.data_dir, name)) return ui
[ "def", "load_ui_file", "(", "name", ")", ":", "ui", "=", "gtk", ".", "Builder", "(", ")", "ui", ".", "add_from_file", "(", "os", ".", "path", ".", "join", "(", "runtime", ".", "data_dir", ",", "name", ")", ")", "return", "ui" ]
loads interface from the glade file; sorts out the path business
[ "loads", "interface", "from", "the", "glade", "file", ";", "sorts", "out", "the", "path", "business" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L87-L91
231,987
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore._fix_key
def _fix_key(self, key): """ Appends the GCONF_PREFIX to the key if needed @param key: The key to check @type key: C{string} @returns: The fixed key @rtype: C{string} """ if not key.startswith(self.GCONF_DIR): return self.GCONF_DIR + key ...
python
def _fix_key(self, key): """ Appends the GCONF_PREFIX to the key if needed @param key: The key to check @type key: C{string} @returns: The fixed key @rtype: C{string} """ if not key.startswith(self.GCONF_DIR): return self.GCONF_DIR + key ...
[ "def", "_fix_key", "(", "self", ",", "key", ")", ":", "if", "not", "key", ".", "startswith", "(", "self", ".", "GCONF_DIR", ")", ":", "return", "self", ".", "GCONF_DIR", "+", "key", "else", ":", "return", "key" ]
Appends the GCONF_PREFIX to the key if needed @param key: The key to check @type key: C{string} @returns: The fixed key @rtype: C{string}
[ "Appends", "the", "GCONF_PREFIX", "to", "the", "key", "if", "needed" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L224-L236
231,988
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore._key_changed
def _key_changed(self, client, cnxn_id, entry, data=None): """ Callback when a gconf key changes """ key = self._fix_key(entry.key)[len(self.GCONF_DIR):] value = self._get_value(entry.value, self.DEFAULTS[key]) self.emit('conf-changed', key, value)
python
def _key_changed(self, client, cnxn_id, entry, data=None): """ Callback when a gconf key changes """ key = self._fix_key(entry.key)[len(self.GCONF_DIR):] value = self._get_value(entry.value, self.DEFAULTS[key]) self.emit('conf-changed', key, value)
[ "def", "_key_changed", "(", "self", ",", "client", ",", "cnxn_id", ",", "entry", ",", "data", "=", "None", ")", ":", "key", "=", "self", ".", "_fix_key", "(", "entry", ".", "key", ")", "[", "len", "(", "self", ".", "GCONF_DIR", ")", ":", "]", "va...
Callback when a gconf key changes
[ "Callback", "when", "a", "gconf", "key", "changes" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L238-L245
231,989
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore._get_value
def _get_value(self, value, default): """calls appropriate gconf function by the default value""" vtype = type(default) if vtype is bool: return value.get_bool() elif vtype is str: return value.get_string() elif vtype is int: return value.get_...
python
def _get_value(self, value, default): """calls appropriate gconf function by the default value""" vtype = type(default) if vtype is bool: return value.get_bool() elif vtype is str: return value.get_string() elif vtype is int: return value.get_...
[ "def", "_get_value", "(", "self", ",", "value", ",", "default", ")", ":", "vtype", "=", "type", "(", "default", ")", "if", "vtype", "is", "bool", ":", "return", "value", ".", "get_bool", "(", ")", "elif", "vtype", "is", "str", ":", "return", "value",...
calls appropriate gconf function by the default value
[ "calls", "appropriate", "gconf", "function", "by", "the", "default", "value" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L248-L264
231,990
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore.get
def get(self, key, default=None): """ Returns the value of the key or the default value if the key is not yet in gconf """ #function arguments override defaults if default is None: default = self.DEFAULTS.get(key, None) vtype = type(default) ...
python
def get(self, key, default=None): """ Returns the value of the key or the default value if the key is not yet in gconf """ #function arguments override defaults if default is None: default = self.DEFAULTS.get(key, None) vtype = type(default) ...
[ "def", "get", "(", "self", ",", "key", ",", "default", "=", "None", ")", ":", "#function arguments override defaults", "if", "default", "is", "None", ":", "default", "=", "self", ".", "DEFAULTS", ".", "get", "(", "key", ",", "None", ")", "vtype", "=", ...
Returns the value of the key or the default value if the key is not yet in gconf
[ "Returns", "the", "value", "of", "the", "key", "or", "the", "default", "value", "if", "the", "key", "is", "not", "yet", "in", "gconf" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L266-L303
231,991
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore.set
def set(self, key, value): """ Sets the key value in gconf and connects adds a signal which is fired if the key changes """ logger.debug("Settings %s -> %s" % (key, value)) if key in self.DEFAULTS: vtype = type(self.DEFAULTS[key]) else: vty...
python
def set(self, key, value): """ Sets the key value in gconf and connects adds a signal which is fired if the key changes """ logger.debug("Settings %s -> %s" % (key, value)) if key in self.DEFAULTS: vtype = type(self.DEFAULTS[key]) else: vty...
[ "def", "set", "(", "self", ",", "key", ",", "value", ")", ":", "logger", ".", "debug", "(", "\"Settings %s -> %s\"", "%", "(", "key", ",", "value", ")", ")", "if", "key", "in", "self", ".", "DEFAULTS", ":", "vtype", "=", "type", "(", "self", ".", ...
Sets the key value in gconf and connects adds a signal which is fired if the key changes
[ "Sets", "the", "key", "value", "in", "gconf", "and", "connects", "adds", "a", "signal", "which", "is", "fired", "if", "the", "key", "changes" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L305-L334
231,992
projecthamster/hamster
src/hamster/lib/configuration.py
GConfStore.day_start
def day_start(self): """Start of the hamster day.""" day_start_minutes = self.get("day_start_minutes") hours, minutes = divmod(day_start_minutes, 60) return dt.time(hours, minutes)
python
def day_start(self): """Start of the hamster day.""" day_start_minutes = self.get("day_start_minutes") hours, minutes = divmod(day_start_minutes, 60) return dt.time(hours, minutes)
[ "def", "day_start", "(", "self", ")", ":", "day_start_minutes", "=", "self", ".", "get", "(", "\"day_start_minutes\"", ")", "hours", ",", "minutes", "=", "divmod", "(", "day_start_minutes", ",", "60", ")", "return", "dt", ".", "time", "(", "hours", ",", ...
Start of the hamster day.
[ "Start", "of", "the", "hamster", "day", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/lib/configuration.py#L337-L341
231,993
projecthamster/hamster
src/hamster/edit_activity.py
CustomFactController.localized_fact
def localized_fact(self): """Make sure fact has the correct start_time.""" fact = Fact(self.activity.get_text()) if fact.start_time: fact.date = self.date else: fact.start_time = dt.datetime.now() return fact
python
def localized_fact(self): """Make sure fact has the correct start_time.""" fact = Fact(self.activity.get_text()) if fact.start_time: fact.date = self.date else: fact.start_time = dt.datetime.now() return fact
[ "def", "localized_fact", "(", "self", ")", ":", "fact", "=", "Fact", "(", "self", ".", "activity", ".", "get_text", "(", ")", ")", "if", "fact", ".", "start_time", ":", "fact", ".", "date", "=", "self", ".", "date", "else", ":", "fact", ".", "start...
Make sure fact has the correct start_time.
[ "Make", "sure", "fact", "has", "the", "correct", "start_time", "." ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/edit_activity.py#L124-L131
231,994
projecthamster/hamster
src/hamster/widgets/activityentry.py
CompleteTree.set_row_positions
def set_row_positions(self): """creates a list of row positions for simpler manipulation""" self.row_positions = [i * self.row_height for i in range(len(self.rows))] self.set_size_request(0, self.row_positions[-1] + self.row_height if self.row_positions else 0)
python
def set_row_positions(self): """creates a list of row positions for simpler manipulation""" self.row_positions = [i * self.row_height for i in range(len(self.rows))] self.set_size_request(0, self.row_positions[-1] + self.row_height if self.row_positions else 0)
[ "def", "set_row_positions", "(", "self", ")", ":", "self", ".", "row_positions", "=", "[", "i", "*", "self", ".", "row_height", "for", "i", "in", "range", "(", "len", "(", "self", ".", "rows", ")", ")", "]", "self", ".", "set_size_request", "(", "0",...
creates a list of row positions for simpler manipulation
[ "creates", "a", "list", "of", "row", "positions", "for", "simpler", "manipulation" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/widgets/activityentry.py#L157-L160
231,995
projecthamster/hamster
src/hamster/client.py
from_dbus_fact
def from_dbus_fact(fact): """unpack the struct into a proper dict""" return Fact(fact[4], start_time = dt.datetime.utcfromtimestamp(fact[1]), end_time = dt.datetime.utcfromtimestamp(fact[2]) if fact[2] else None, description = fact[3], activity_id...
python
def from_dbus_fact(fact): """unpack the struct into a proper dict""" return Fact(fact[4], start_time = dt.datetime.utcfromtimestamp(fact[1]), end_time = dt.datetime.utcfromtimestamp(fact[2]) if fact[2] else None, description = fact[3], activity_id...
[ "def", "from_dbus_fact", "(", "fact", ")", ":", "return", "Fact", "(", "fact", "[", "4", "]", ",", "start_time", "=", "dt", ".", "datetime", ".", "utcfromtimestamp", "(", "fact", "[", "1", "]", ")", ",", "end_time", "=", "dt", ".", "datetime", ".", ...
unpack the struct into a proper dict
[ "unpack", "the", "struct", "into", "a", "proper", "dict" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/client.py#L28-L39
231,996
projecthamster/hamster
src/hamster/client.py
Storage.get_tags
def get_tags(self, only_autocomplete = False): """returns list of all tags. by default only those that have been set for autocomplete""" return self._to_dict(('id', 'name', 'autocomplete'), self.conn.GetTags(only_autocomplete))
python
def get_tags(self, only_autocomplete = False): """returns list of all tags. by default only those that have been set for autocomplete""" return self._to_dict(('id', 'name', 'autocomplete'), self.conn.GetTags(only_autocomplete))
[ "def", "get_tags", "(", "self", ",", "only_autocomplete", "=", "False", ")", ":", "return", "self", ".", "_to_dict", "(", "(", "'id'", ",", "'name'", ",", "'autocomplete'", ")", ",", "self", ".", "conn", ".", "GetTags", "(", "only_autocomplete", ")", ")"...
returns list of all tags. by default only those that have been set for autocomplete
[ "returns", "list", "of", "all", "tags", ".", "by", "default", "only", "those", "that", "have", "been", "set", "for", "autocomplete" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/client.py#L151-L153
231,997
projecthamster/hamster
src/hamster/client.py
Storage.stop_tracking
def stop_tracking(self, end_time = None): """Stop tracking current activity. end_time can be passed in if the activity should have other end time than the current moment""" end_time = timegm((end_time or dt.datetime.now()).timetuple()) return self.conn.StopTracking(end_time)
python
def stop_tracking(self, end_time = None): """Stop tracking current activity. end_time can be passed in if the activity should have other end time than the current moment""" end_time = timegm((end_time or dt.datetime.now()).timetuple()) return self.conn.StopTracking(end_time)
[ "def", "stop_tracking", "(", "self", ",", "end_time", "=", "None", ")", ":", "end_time", "=", "timegm", "(", "(", "end_time", "or", "dt", ".", "datetime", ".", "now", "(", ")", ")", ".", "timetuple", "(", ")", ")", "return", "self", ".", "conn", "....
Stop tracking current activity. end_time can be passed in if the activity should have other end time than the current moment
[ "Stop", "tracking", "current", "activity", ".", "end_time", "can", "be", "passed", "in", "if", "the", "activity", "should", "have", "other", "end", "time", "than", "the", "current", "moment" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/client.py#L201-L205
231,998
projecthamster/hamster
src/hamster/client.py
Storage.get_category_activities
def get_category_activities(self, category_id = None): """Return activities for category. If category is not specified, will return activities that have no category""" category_id = category_id or -1 return self._to_dict(('id', 'name', 'category_id', 'category'), self.conn.GetCategoryAct...
python
def get_category_activities(self, category_id = None): """Return activities for category. If category is not specified, will return activities that have no category""" category_id = category_id or -1 return self._to_dict(('id', 'name', 'category_id', 'category'), self.conn.GetCategoryAct...
[ "def", "get_category_activities", "(", "self", ",", "category_id", "=", "None", ")", ":", "category_id", "=", "category_id", "or", "-", "1", "return", "self", ".", "_to_dict", "(", "(", "'id'", ",", "'name'", ",", "'category_id'", ",", "'category'", ")", "...
Return activities for category. If category is not specified, will return activities that have no category
[ "Return", "activities", "for", "category", ".", "If", "category", "is", "not", "specified", "will", "return", "activities", "that", "have", "no", "category" ]
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/client.py#L232-L236
231,999
projecthamster/hamster
src/hamster/client.py
Storage.get_activity_by_name
def get_activity_by_name(self, activity, category_id = None, resurrect = True): """returns activity dict by name and optionally filtering by category. if activity is found but is marked as deleted, it will be resurrected unless told otherwise in the resurrect param """ cate...
python
def get_activity_by_name(self, activity, category_id = None, resurrect = True): """returns activity dict by name and optionally filtering by category. if activity is found but is marked as deleted, it will be resurrected unless told otherwise in the resurrect param """ cate...
[ "def", "get_activity_by_name", "(", "self", ",", "activity", ",", "category_id", "=", "None", ",", "resurrect", "=", "True", ")", ":", "category_id", "=", "category_id", "or", "0", "return", "self", ".", "conn", ".", "GetActivityByName", "(", "activity", ","...
returns activity dict by name and optionally filtering by category. if activity is found but is marked as deleted, it will be resurrected unless told otherwise in the resurrect param
[ "returns", "activity", "dict", "by", "name", "and", "optionally", "filtering", "by", "category", ".", "if", "activity", "is", "found", "but", "is", "marked", "as", "deleted", "it", "will", "be", "resurrected", "unless", "told", "otherwise", "in", "the", "res...
ca5254eff53172796ddafc72226c394ed1858245
https://github.com/projecthamster/hamster/blob/ca5254eff53172796ddafc72226c394ed1858245/src/hamster/client.py#L242-L248