partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
MijnWoordenBoekNl.pos
Tries to decide about the part of speech.
lltk/nl/scrapers/mijnwoordenboek.py
def pos(self): ''' Tries to decide about the part of speech. ''' tags = [] if self.tree.xpath('//div[@class="grad733100"]/h2[@class="inline"]//text()'): info = self.tree.xpath('//div[@class="grad733100"]/h2[@class="inline"]')[0].text_content() info = info.strip('I ') if info.startswith(('de', 'het')): ...
def pos(self): ''' Tries to decide about the part of speech. ''' tags = [] if self.tree.xpath('//div[@class="grad733100"]/h2[@class="inline"]//text()'): info = self.tree.xpath('//div[@class="grad733100"]/h2[@class="inline"]')[0].text_content() info = info.strip('I ') if info.startswith(('de', 'het')): ...
[ "Tries", "to", "decide", "about", "the", "part", "of", "speech", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/nl/scrapers/mijnwoordenboek.py#L26-L39
[ "def", "pos", "(", "self", ")", ":", "tags", "=", "[", "]", "if", "self", ".", "tree", ".", "xpath", "(", "'//div[@class=\"grad733100\"]/h2[@class=\"inline\"]//text()'", ")", ":", "info", "=", "self", ".", "tree", ".", "xpath", "(", "'//div[@class=\"grad733100...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
VerbixFr._normalize
Returns a sanitized string.
lltk/fr/scrapers/verbix.py
def _normalize(self, string): ''' Returns a sanitized string. ''' string = super(VerbixFr, self)._normalize(string) string = string.replace('il; elle', 'il/elle') string = string.replace('ils; elles', 'ils/elles') string = string.strip() return string
def _normalize(self, string): ''' Returns a sanitized string. ''' string = super(VerbixFr, self)._normalize(string) string = string.replace('il; elle', 'il/elle') string = string.replace('ils; elles', 'ils/elles') string = string.strip() return string
[ "Returns", "a", "sanitized", "string", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/fr/scrapers/verbix.py#L23-L30
[ "def", "_normalize", "(", "self", ",", "string", ")", ":", "string", "=", "super", "(", "VerbixFr", ",", "self", ")", ".", "_normalize", "(", "string", ")", "string", "=", "string", ".", "replace", "(", "'il; elle'", ",", "'il/elle'", ")", "string", "=...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
LeoIt.pos
Tries to decide about the part of speech.
lltk/it/scrapers/leo.py
def pos(self, element = None): ''' Tries to decide about the part of speech. ''' tags = [] if element: if re.search('[\w|\s]+ [m|f]\.', element, re.U): tags.append('NN') if '[VERB]' in element: tags.append('VB') if 'adj.' in element and re.search('([\w|\s]+, [\w|\s]+)', element, re.U): tags....
def pos(self, element = None): ''' Tries to decide about the part of speech. ''' tags = [] if element: if re.search('[\w|\s]+ [m|f]\.', element, re.U): tags.append('NN') if '[VERB]' in element: tags.append('VB') if 'adj.' in element and re.search('([\w|\s]+, [\w|\s]+)', element, re.U): tags....
[ "Tries", "to", "decide", "about", "the", "part", "of", "speech", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/it/scrapers/leo.py#L45-L60
[ "def", "pos", "(", "self", ",", "element", "=", "None", ")", ":", "tags", "=", "[", "]", "if", "element", ":", "if", "re", ".", "search", "(", "'[\\w|\\s]+ [m|f]\\.'", ",", "element", ",", "re", ".", "U", ")", ":", "tags", ".", "append", "(", "'N...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
LeoIt.gender
Tries to scrape the gender for a given noun from leo.org.
lltk/it/scrapers/leo.py
def gender(self): ''' Tries to scrape the gender for a given noun from leo.org. ''' element = self._first('NN') if element: if re.search('([m|f|n)])\.', element, re.U): genus = re.findall('([m|f|n)])\.', element, re.U)[0] return genus
def gender(self): ''' Tries to scrape the gender for a given noun from leo.org. ''' element = self._first('NN') if element: if re.search('([m|f|n)])\.', element, re.U): genus = re.findall('([m|f|n)])\.', element, re.U)[0] return genus
[ "Tries", "to", "scrape", "the", "gender", "for", "a", "given", "noun", "from", "leo", ".", "org", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/it/scrapers/leo.py#L63-L70
[ "def", "gender", "(", "self", ")", ":", "element", "=", "self", ".", "_first", "(", "'NN'", ")", "if", "element", ":", "if", "re", ".", "search", "(", "'([m|f|n)])\\.'", ",", "element", ",", "re", ".", "U", ")", ":", "genus", "=", "re", ".", "fin...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
isempty
Finds out if a scraping result should be considered empty.
lltk/utils.py
def isempty(result): ''' Finds out if a scraping result should be considered empty. ''' if isinstance(result, list): for element in result: if isinstance(element, list): if not isempty(element): return False else: if element is not None: return False else: if result is not None: retur...
def isempty(result): ''' Finds out if a scraping result should be considered empty. ''' if isinstance(result, list): for element in result: if isinstance(element, list): if not isempty(element): return False else: if element is not None: return False else: if result is not None: retur...
[ "Finds", "out", "if", "a", "scraping", "result", "should", "be", "considered", "empty", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/utils.py#L6-L20
[ "def", "isempty", "(", "result", ")", ":", "if", "isinstance", "(", "result", ",", "list", ")", ":", "for", "element", "in", "result", ":", "if", "isinstance", "(", "element", ",", "list", ")", ":", "if", "not", "isempty", "(", "element", ")", ":", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
method2pos
Returns a list of valid POS-tags for a given method.
lltk/utils.py
def method2pos(method): ''' Returns a list of valid POS-tags for a given method. ''' if method in ('articles', 'plural', 'miniaturize', 'gender'): pos = ['NN'] elif method in ('conjugate',): pos = ['VB'] elif method in ('comparative, superlative'): pos = ['JJ'] else: pos = ['*'] return pos
def method2pos(method): ''' Returns a list of valid POS-tags for a given method. ''' if method in ('articles', 'plural', 'miniaturize', 'gender'): pos = ['NN'] elif method in ('conjugate',): pos = ['VB'] elif method in ('comparative, superlative'): pos = ['JJ'] else: pos = ['*'] return pos
[ "Returns", "a", "list", "of", "valid", "POS", "-", "tags", "for", "a", "given", "method", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/utils.py#L22-L33
[ "def", "method2pos", "(", "method", ")", ":", "if", "method", "in", "(", "'articles'", ",", "'plural'", ",", "'miniaturize'", ",", "'gender'", ")", ":", "pos", "=", "[", "'NN'", "]", "elif", "method", "in", "(", "'conjugate'", ",", ")", ":", "pos", "...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
register
Registers a scraper to make it available for the generic scraping interface.
lltk/scraping.py
def register(scraper): ''' Registers a scraper to make it available for the generic scraping interface. ''' global scrapers language = scraper('').language if not language: raise Exception('No language specified for your scraper.') if scrapers.has_key(language): scrapers[language].append(scraper) else: scr...
def register(scraper): ''' Registers a scraper to make it available for the generic scraping interface. ''' global scrapers language = scraper('').language if not language: raise Exception('No language specified for your scraper.') if scrapers.has_key(language): scrapers[language].append(scraper) else: scr...
[ "Registers", "a", "scraper", "to", "make", "it", "available", "for", "the", "generic", "scraping", "interface", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L19-L29
[ "def", "register", "(", "scraper", ")", ":", "global", "scrapers", "language", "=", "scraper", "(", "''", ")", ".", "language", "if", "not", "language", ":", "raise", "Exception", "(", "'No language specified for your scraper.'", ")", "if", "scrapers", ".", "h...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
discover
Discovers all registered scrapers to be used for the generic scraping interface.
lltk/scraping.py
def discover(language): ''' Discovers all registered scrapers to be used for the generic scraping interface. ''' debug('Discovering scrapers for \'%s\'...' % (language,)) global scrapers, discovered for language in scrapers.iterkeys(): discovered[language] = {} for scraper in scrapers[language]: blacklist =...
def discover(language): ''' Discovers all registered scrapers to be used for the generic scraping interface. ''' debug('Discovering scrapers for \'%s\'...' % (language,)) global scrapers, discovered for language in scrapers.iterkeys(): discovered[language] = {} for scraper in scrapers[language]: blacklist =...
[ "Discovers", "all", "registered", "scrapers", "to", "be", "used", "for", "the", "generic", "scraping", "interface", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L31-L46
[ "def", "discover", "(", "language", ")", ":", "debug", "(", "'Discovering scrapers for \\'%s\\'...'", "%", "(", "language", ",", ")", ")", "global", "scrapers", ",", "discovered", "for", "language", "in", "scrapers", ".", "iterkeys", "(", ")", ":", "discovered...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
scrape
Uses custom scrapers and calls provided method.
lltk/scraping.py
def scrape(language, method, word, *args, **kwargs): ''' Uses custom scrapers and calls provided method. ''' scraper = Scrape(language, word) if hasattr(scraper, method): function = getattr(scraper, method) if callable(function): return function(*args, **kwargs) else: raise NotImplementedError('The method...
def scrape(language, method, word, *args, **kwargs): ''' Uses custom scrapers and calls provided method. ''' scraper = Scrape(language, word) if hasattr(scraper, method): function = getattr(scraper, method) if callable(function): return function(*args, **kwargs) else: raise NotImplementedError('The method...
[ "Uses", "custom", "scrapers", "and", "calls", "provided", "method", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L48-L57
[ "def", "scrape", "(", "language", ",", "method", ",", "word", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "scraper", "=", "Scrape", "(", "language", ",", "word", ")", "if", "hasattr", "(", "scraper", ",", "method", ")", ":", "function", "=...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Scrape.iterscrapers
Iterates over all available scrapers.
lltk/scraping.py
def iterscrapers(self, method, mode = None): ''' Iterates over all available scrapers. ''' global discovered if discovered.has_key(self.language) and discovered[self.language].has_key(method): for Scraper in discovered[self.language][method]: yield Scraper
def iterscrapers(self, method, mode = None): ''' Iterates over all available scrapers. ''' global discovered if discovered.has_key(self.language) and discovered[self.language].has_key(method): for Scraper in discovered[self.language][method]: yield Scraper
[ "Iterates", "over", "all", "available", "scrapers", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L99-L105
[ "def", "iterscrapers", "(", "self", ",", "method", ",", "mode", "=", "None", ")", ":", "global", "discovered", "if", "discovered", ".", "has_key", "(", "self", ".", "language", ")", "and", "discovered", "[", "self", ".", "language", "]", ".", "has_key", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Scrape.merge
Merges all scraping results to a list sorted by frequency of occurrence.
lltk/scraping.py
def merge(self, elements): ''' Merges all scraping results to a list sorted by frequency of occurrence. ''' from collections import Counter from lltk.utils import list2tuple, tuple2list # The list2tuple conversion is necessary because mutable objects (e.g. lists) are not hashable merged = tuple2list([value f...
def merge(self, elements): ''' Merges all scraping results to a list sorted by frequency of occurrence. ''' from collections import Counter from lltk.utils import list2tuple, tuple2list # The list2tuple conversion is necessary because mutable objects (e.g. lists) are not hashable merged = tuple2list([value f...
[ "Merges", "all", "scraping", "results", "to", "a", "list", "sorted", "by", "frequency", "of", "occurrence", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L147-L154
[ "def", "merge", "(", "self", ",", "elements", ")", ":", "from", "collections", "import", "Counter", "from", "lltk", ".", "utils", "import", "list2tuple", ",", "tuple2list", "# The list2tuple conversion is necessary because mutable objects (e.g. lists) are not hashable", "me...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Scrape.clean
Removes empty or incomplete answers.
lltk/scraping.py
def clean(self, elements): ''' Removes empty or incomplete answers. ''' cleanelements = [] for i in xrange(len(elements)): if isempty(elements[i]): return [] next = elements[i] if isinstance(elements[i], (list, tuple)): next = self.clean(elements[i]) if next: cleanelements.append(elements...
def clean(self, elements): ''' Removes empty or incomplete answers. ''' cleanelements = [] for i in xrange(len(elements)): if isempty(elements[i]): return [] next = elements[i] if isinstance(elements[i], (list, tuple)): next = self.clean(elements[i]) if next: cleanelements.append(elements...
[ "Removes", "empty", "or", "incomplete", "answers", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L156-L168
[ "def", "clean", "(", "self", ",", "elements", ")", ":", "cleanelements", "=", "[", "]", "for", "i", "in", "xrange", "(", "len", "(", "elements", ")", ")", ":", "if", "isempty", "(", "elements", "[", "i", "]", ")", ":", "return", "[", "]", "next",...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
GenericScraper._needs_download
Decorator used to make sure that the downloading happens prior to running the task.
lltk/scraping.py
def _needs_download(self, f): ''' Decorator used to make sure that the downloading happens prior to running the task. ''' @wraps(f) def wrapper(self, *args, **kwargs): if not self.isdownloaded(): self.download() return f(self, *args, **kwargs) return wrapper
def _needs_download(self, f): ''' Decorator used to make sure that the downloading happens prior to running the task. ''' @wraps(f) def wrapper(self, *args, **kwargs): if not self.isdownloaded(): self.download() return f(self, *args, **kwargs) return wrapper
[ "Decorator", "used", "to", "make", "sure", "that", "the", "downloading", "happens", "prior", "to", "running", "the", "task", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L188-L196
[ "def", "_needs_download", "(", "self", ",", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "isdownloaded", "(", ")", ":", "self", ".", "d...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
GenericScraper.download
Downloads HTML from url.
lltk/scraping.py
def download(self): ''' Downloads HTML from url. ''' self.page = requests.get(self.url) self.tree = html.fromstring(self.page.text)
def download(self): ''' Downloads HTML from url. ''' self.page = requests.get(self.url) self.tree = html.fromstring(self.page.text)
[ "Downloads", "HTML", "from", "url", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L198-L202
[ "def", "download", "(", "self", ")", ":", "self", ".", "page", "=", "requests", ".", "get", "(", "self", ".", "url", ")", "self", ".", "tree", "=", "html", ".", "fromstring", "(", "self", ".", "page", ".", "text", ")" ]
d171de55c1b97695fddedf4b02401ae27bf1d634
train
DictScraper._needs_elements
Decorator used to make sure that there are elements prior to running the task.
lltk/scraping.py
def _needs_elements(self, f): ''' Decorator used to make sure that there are elements prior to running the task. ''' @wraps(f) def wrapper(self, *args, **kwargs): if self.elements == None: self.getelements() return f(self, *args, **kwargs) return wrapper
def _needs_elements(self, f): ''' Decorator used to make sure that there are elements prior to running the task. ''' @wraps(f) def wrapper(self, *args, **kwargs): if self.elements == None: self.getelements() return f(self, *args, **kwargs) return wrapper
[ "Decorator", "used", "to", "make", "sure", "that", "there", "are", "elements", "prior", "to", "running", "the", "task", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L252-L260
[ "def", "_needs_elements", "(", "self", ",", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "elements", "==", "None", ":", "self", ".", "getelement...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
DictScraper._first
Returns the first element with required POS-tag.
lltk/scraping.py
def _first(self, tag): ''' Returns the first element with required POS-tag. ''' self.getelements() for element in self.elements: if tag in self.pos(element): return element return None
def _first(self, tag): ''' Returns the first element with required POS-tag. ''' self.getelements() for element in self.elements: if tag in self.pos(element): return element return None
[ "Returns", "the", "first", "element", "with", "required", "POS", "-", "tag", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scraping.py#L262-L269
[ "def", "_first", "(", "self", ",", "tag", ")", ":", "self", ".", "getelements", "(", ")", "for", "element", "in", "self", ".", "elements", ":", "if", "tag", "in", "self", ".", "pos", "(", "element", ")", ":", "return", "element", "return", "None" ]
d171de55c1b97695fddedf4b02401ae27bf1d634
train
PonsDe._normalize
Returns a sanitized string.
lltk/de/scrapers/pons.py
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xb7', '') string = string.replace(u'\u0331', '') string = string.replace(u'\u0323', '') string = string.strip(' \n\rI.') return string
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xb7', '') string = string.replace(u'\u0331', '') string = string.replace(u'\u0323', '') string = string.strip(' \n\rI.') return string
[ "Returns", "a", "sanitized", "string", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/pons.py#L20-L27
[ "def", "_normalize", "(", "self", ",", "string", ")", ":", "string", "=", "string", ".", "replace", "(", "u'\\xb7'", ",", "''", ")", "string", "=", "string", ".", "replace", "(", "u'\\u0331'", ",", "''", ")", "string", "=", "string", ".", "replace", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
PonsDe.pos
Tries to decide about the part of speech.
lltk/de/scrapers/pons.py
def pos(self, element = None): ''' Tries to decide about the part of speech. ''' tags = [] if element: if element.startswith(('der', 'die', 'das')): tags.append('NN') if ' VERB' in element: tags.append('VB') if ' ADJ' in element: tags.append('JJ') else: for element in self.elements: ...
def pos(self, element = None): ''' Tries to decide about the part of speech. ''' tags = [] if element: if element.startswith(('der', 'die', 'das')): tags.append('NN') if ' VERB' in element: tags.append('VB') if ' ADJ' in element: tags.append('JJ') else: for element in self.elements: ...
[ "Tries", "to", "decide", "about", "the", "part", "of", "speech", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/pons.py#L46-L61
[ "def", "pos", "(", "self", ",", "element", "=", "None", ")", ":", "tags", "=", "[", "]", "if", "element", ":", "if", "element", ".", "startswith", "(", "(", "'der'", ",", "'die'", ",", "'das'", ")", ")", ":", "tags", ".", "append", "(", "'NN'", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
PonsDe.articles
Tries to scrape the correct articles for singular and plural from de.pons.eu.
lltk/de/scrapers/pons.py
def articles(self): ''' Tries to scrape the correct articles for singular and plural from de.pons.eu. ''' result = [None, None] element = self._first('NN') if element: result[0] = [element.split(' ')[0].replace('(die)', '').strip()] if 'kein Plur' in element: # There is no plural result[1] = ['']...
def articles(self): ''' Tries to scrape the correct articles for singular and plural from de.pons.eu. ''' result = [None, None] element = self._first('NN') if element: result[0] = [element.split(' ')[0].replace('(die)', '').strip()] if 'kein Plur' in element: # There is no plural result[1] = ['']...
[ "Tries", "to", "scrape", "the", "correct", "articles", "for", "singular", "and", "plural", "from", "de", ".", "pons", ".", "eu", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/pons.py#L64-L77
[ "def", "articles", "(", "self", ")", ":", "result", "=", "[", "None", ",", "None", "]", "element", "=", "self", ".", "_first", "(", "'NN'", ")", "if", "element", ":", "result", "[", "0", "]", "=", "[", "element", ".", "split", "(", "' '", ")", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
PonsDe.plural
Tries to scrape the plural version from pons.eu.
lltk/de/scrapers/pons.py
def plural(self): ''' Tries to scrape the plural version from pons.eu. ''' element = self._first('NN') if element: if 'kein Plur' in element: # There is no plural return [''] if re.search(', ([\w|\s|/]+)>', element, re.U): # Plural form is provided return re.findall(', ([\w|\s|/]+)>', eleme...
def plural(self): ''' Tries to scrape the plural version from pons.eu. ''' element = self._first('NN') if element: if 'kein Plur' in element: # There is no plural return [''] if re.search(', ([\w|\s|/]+)>', element, re.U): # Plural form is provided return re.findall(', ([\w|\s|/]+)>', eleme...
[ "Tries", "to", "scrape", "the", "plural", "version", "from", "pons", ".", "eu", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/pons.py#L80-L98
[ "def", "plural", "(", "self", ")", ":", "element", "=", "self", ".", "_first", "(", "'NN'", ")", "if", "element", ":", "if", "'kein Plur'", "in", "element", ":", "# There is no plural", "return", "[", "''", "]", "if", "re", ".", "search", "(", "', ([\\...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
reference
Returns the articles (singular and plural) combined with singular and plural for a given noun.
lltk/generic.py
def reference(language, word): ''' Returns the articles (singular and plural) combined with singular and plural for a given noun. ''' sg, pl, art = word, '/'.join(plural(language, word) or ['-']), [[''], ['']] art[0], art[1] = articles(language, word) or (['-'], ['-']) result = ['%s %s' % ('/'.join(art[0]), sg), ...
def reference(language, word): ''' Returns the articles (singular and plural) combined with singular and plural for a given noun. ''' sg, pl, art = word, '/'.join(plural(language, word) or ['-']), [[''], ['']] art[0], art[1] = articles(language, word) or (['-'], ['-']) result = ['%s %s' % ('/'.join(art[0]), sg), ...
[ "Returns", "the", "articles", "(", "singular", "and", "plural", ")", "combined", "with", "singular", "and", "plural", "for", "a", "given", "noun", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/generic.py#L54-L61
[ "def", "reference", "(", "language", ",", "word", ")", ":", "sg", ",", "pl", ",", "art", "=", "word", ",", "'/'", ".", "join", "(", "plural", "(", "language", ",", "word", ")", "or", "[", "'-'", "]", ")", ",", "[", "[", "''", "]", ",", "[", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
translate
Translates a word using Google Translate.
lltk/generic.py
def translate(src, dest, word): ''' Translates a word using Google Translate. ''' results = [] try: from textblob import TextBlob results.append(TextBlob(word).translate(from_lang = src, to = dest).string) except ImportError: pass if not results: return [None] return results
def translate(src, dest, word): ''' Translates a word using Google Translate. ''' results = [] try: from textblob import TextBlob results.append(TextBlob(word).translate(from_lang = src, to = dest).string) except ImportError: pass if not results: return [None] return results
[ "Translates", "a", "word", "using", "Google", "Translate", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/generic.py#L64-L77
[ "def", "translate", "(", "src", ",", "dest", ",", "word", ")", ":", "results", "=", "[", "]", "try", ":", "from", "textblob", "import", "TextBlob", "results", ".", "append", "(", "TextBlob", "(", "word", ")", ".", "translate", "(", "from_lang", "=", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
audiosamples
Returns a list of URLs to suitable audiosamples for a given word.
lltk/generic.py
def audiosamples(language, word, key = ''): ''' Returns a list of URLs to suitable audiosamples for a given word. ''' from lltk.audiosamples import forvo, google urls = [] urls += forvo(language, word, key) urls += google(language, word) return urls
def audiosamples(language, word, key = ''): ''' Returns a list of URLs to suitable audiosamples for a given word. ''' from lltk.audiosamples import forvo, google urls = [] urls += forvo(language, word, key) urls += google(language, word) return urls
[ "Returns", "a", "list", "of", "URLs", "to", "suitable", "audiosamples", "for", "a", "given", "word", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/generic.py#L81-L89
[ "def", "audiosamples", "(", "language", ",", "word", ",", "key", "=", "''", ")", ":", "from", "lltk", ".", "audiosamples", "import", "forvo", ",", "google", "urls", "=", "[", "]", "urls", "+=", "forvo", "(", "language", ",", "word", ",", "key", ")", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
images
Returns a list of URLs to suitable images for a given word.
lltk/generic.py
def images(language, word, n = 20, *args, **kwargs): ''' Returns a list of URLs to suitable images for a given word.''' from lltk.images import google return google(language, word, n, *args, **kwargs)
def images(language, word, n = 20, *args, **kwargs): ''' Returns a list of URLs to suitable images for a given word.''' from lltk.images import google return google(language, word, n, *args, **kwargs)
[ "Returns", "a", "list", "of", "URLs", "to", "suitable", "images", "for", "a", "given", "word", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/generic.py#L99-L103
[ "def", "images", "(", "language", ",", "word", ",", "n", "=", "20", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "from", "lltk", ".", "images", "import", "google", "return", "google", "(", "language", ",", "word", ",", "n", ",", "*", "arg...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
articles
Returns the articles (singular and plural) for a given noun.
lltk/it/it.py
def articles(word): ''' Returns the articles (singular and plural) for a given noun. ''' from pattern.it import article result = [[None], [None]] genus = gender(word) or 'f' result[0] = [article(word, function = 'definite', gender = genus)] result[1] = [article(plural(word)[0], function = 'definite', gender = (...
def articles(word): ''' Returns the articles (singular and plural) for a given noun. ''' from pattern.it import article result = [[None], [None]] genus = gender(word) or 'f' result[0] = [article(word, function = 'definite', gender = genus)] result[1] = [article(plural(word)[0], function = 'definite', gender = (...
[ "Returns", "the", "articles", "(", "singular", "and", "plural", ")", "for", "a", "given", "noun", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/it/it.py#L17-L26
[ "def", "articles", "(", "word", ")", ":", "from", "pattern", ".", "it", "import", "article", "result", "=", "[", "[", "None", "]", ",", "[", "None", "]", "]", "genus", "=", "gender", "(", "word", ")", "or", "'f'", "result", "[", "0", "]", "=", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
google
Downloads suitable images for a given word from Google Images.
lltk/images/google.py
def google(language, word, n = 8, *args, **kwargs): ''' Downloads suitable images for a given word from Google Images. ''' if not kwargs.has_key('start'): kwargs['start'] = 0 if not kwargs.has_key('itype'): kwargs['itype'] = 'photo|clipart|lineart' if not kwargs.has_key('isize'): kwargs['isize'] = 'small|med...
def google(language, word, n = 8, *args, **kwargs): ''' Downloads suitable images for a given word from Google Images. ''' if not kwargs.has_key('start'): kwargs['start'] = 0 if not kwargs.has_key('itype'): kwargs['itype'] = 'photo|clipart|lineart' if not kwargs.has_key('isize'): kwargs['isize'] = 'small|med...
[ "Downloads", "suitable", "images", "for", "a", "given", "word", "from", "Google", "Images", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/images/google.py#L9-L37
[ "def", "google", "(", "language", ",", "word", ",", "n", "=", "8", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "kwargs", ".", "has_key", "(", "'start'", ")", ":", "kwargs", "[", "'start'", "]", "=", "0", "if", "not", "kwar...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Verbix._normalize
Returns a sanitized string.
lltk/scrapers/verbix.py
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xa0', '') string = string.strip() return string
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xa0', '') string = string.strip() return string
[ "Returns", "a", "sanitized", "string", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scrapers/verbix.py#L22-L27
[ "def", "_normalize", "(", "self", ",", "string", ")", ":", "string", "=", "string", ".", "replace", "(", "u'\\xa0'", ",", "''", ")", "string", "=", "string", ".", "strip", "(", ")", "return", "string" ]
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Verbix._extract
Extracts data from conjugation table.
lltk/scrapers/verbix.py
def _extract(self, identifier): ''' Extracts data from conjugation table. ''' conjugation = [] if self.tree.xpath('//p/b[normalize-space(text()) = "' + identifier.decode('utf-8') + '"]'): p = self.tree.xpath('//p/b[normalize-space(text()) = "' + identifier.decode('utf-8') + '"]')[0].getparent() for font in...
def _extract(self, identifier): ''' Extracts data from conjugation table. ''' conjugation = [] if self.tree.xpath('//p/b[normalize-space(text()) = "' + identifier.decode('utf-8') + '"]'): p = self.tree.xpath('//p/b[normalize-space(text()) = "' + identifier.decode('utf-8') + '"]')[0].getparent() for font in...
[ "Extracts", "data", "from", "conjugation", "table", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scrapers/verbix.py#L30-L46
[ "def", "_extract", "(", "self", ",", "identifier", ")", ":", "conjugation", "=", "[", "]", "if", "self", ".", "tree", ".", "xpath", "(", "'//p/b[normalize-space(text()) = \"'", "+", "identifier", ".", "decode", "(", "'utf-8'", ")", "+", "'\"]'", ")", ":", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Verbix.conjugate
Tries to conjugate a given verb using verbix.com.
lltk/scrapers/verbix.py
def conjugate(self, tense = 'present'): ''' Tries to conjugate a given verb using verbix.com.''' if self.tenses.has_key(tense): return self._extract(self.tenses[tense]) elif self.tenses.has_key(tense.title()): return self._extract(self.tenses[tense.title()]) return [None]
def conjugate(self, tense = 'present'): ''' Tries to conjugate a given verb using verbix.com.''' if self.tenses.has_key(tense): return self._extract(self.tenses[tense]) elif self.tenses.has_key(tense.title()): return self._extract(self.tenses[tense.title()]) return [None]
[ "Tries", "to", "conjugate", "a", "given", "verb", "using", "verbix", ".", "com", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/scrapers/verbix.py#L48-L55
[ "def", "conjugate", "(", "self", ",", "tense", "=", "'present'", ")", ":", "if", "self", ".", "tenses", ".", "has_key", "(", "tense", ")", ":", "return", "self", ".", "_extract", "(", "self", ".", "tenses", "[", "tense", "]", ")", "elif", "self", "...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Config.load
Loads a configuration file (JSON).
lltk/config/__init__.py
def load(self, filename, replace = False): ''' Loads a configuration file (JSON). ''' import os, json, re if os.path.exists(filename): f = open(filename, 'r') content = f.read() content = re.sub('[\t ]*?[#].*?\n', '', content) try: settings = json.loads(content) except ValueError: # This m...
def load(self, filename, replace = False): ''' Loads a configuration file (JSON). ''' import os, json, re if os.path.exists(filename): f = open(filename, 'r') content = f.read() content = re.sub('[\t ]*?[#].*?\n', '', content) try: settings = json.loads(content) except ValueError: # This m...
[ "Loads", "a", "configuration", "file", "(", "JSON", ")", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/config/__init__.py#L39-L64
[ "def", "load", "(", "self", ",", "filename", ",", "replace", "=", "False", ")", ":", "import", "os", ",", "json", ",", "re", "if", "os", ".", "path", ".", "exists", "(", "filename", ")", ":", "f", "=", "open", "(", "filename", ",", "'r'", ")", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Config.save
Saves the current configuration to file 'filename' (JSON).
lltk/config/__init__.py
def save(self, filename): ''' Saves the current configuration to file 'filename' (JSON). ''' import json f = open(filename, 'w') json.dump(self.settings, f, indent = 4) f.close()
def save(self, filename): ''' Saves the current configuration to file 'filename' (JSON). ''' import json f = open(filename, 'w') json.dump(self.settings, f, indent = 4) f.close()
[ "Saves", "the", "current", "configuration", "to", "file", "filename", "(", "JSON", ")", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/config/__init__.py#L66-L72
[ "def", "save", "(", "self", ",", "filename", ")", ":", "import", "json", "f", "=", "open", "(", "filename", ",", "'w'", ")", "json", ".", "dump", "(", "self", ".", "settings", ",", "f", ",", "indent", "=", "4", ")", "f", ".", "close", "(", ")" ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
forvo
Returns a list of suitable audiosamples for a given word from Forvo.com.
lltk/audiosamples/forvo.py
def forvo(language, word, key): ''' Returns a list of suitable audiosamples for a given word from Forvo.com. ''' from requests import get url = 'http://apifree.forvo.com/action/word-pronunciations/format/json/word/%s/language/%s/key/%s/' % (word, language, key) urls = [] page = get(url) if page.status_code == ...
def forvo(language, word, key): ''' Returns a list of suitable audiosamples for a given word from Forvo.com. ''' from requests import get url = 'http://apifree.forvo.com/action/word-pronunciations/format/json/word/%s/language/%s/key/%s/' % (word, language, key) urls = [] page = get(url) if page.status_code == ...
[ "Returns", "a", "list", "of", "suitable", "audiosamples", "for", "a", "given", "word", "from", "Forvo", ".", "com", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/audiosamples/forvo.py#L4-L25
[ "def", "forvo", "(", "language", ",", "word", ",", "key", ")", ":", "from", "requests", "import", "get", "url", "=", "'http://apifree.forvo.com/action/word-pronunciations/format/json/word/%s/language/%s/key/%s/'", "%", "(", "word", ",", "language", ",", "key", ")", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
WiktionaryDe._normalize
Returns a sanitized string.
lltk/de/scrapers/wiktionary.py
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xb7', '') string = string.replace(u'\xa0', ' ') string = string.replace('selten: ', '') string = string.replace('Alte Rechtschreibung', '') string = string.strip() return string
def _normalize(self, string): ''' Returns a sanitized string. ''' string = string.replace(u'\xb7', '') string = string.replace(u'\xa0', ' ') string = string.replace('selten: ', '') string = string.replace('Alte Rechtschreibung', '') string = string.strip() return string
[ "Returns", "a", "sanitized", "string", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/wiktionary.py#L20-L28
[ "def", "_normalize", "(", "self", ",", "string", ")", ":", "string", "=", "string", ".", "replace", "(", "u'\\xb7'", ",", "''", ")", "string", "=", "string", ".", "replace", "(", "u'\\xa0'", ",", "' '", ")", "string", "=", "string", ".", "replace", "...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
WiktionaryDe.pos
Tries to decide about the part of speech.
lltk/de/scrapers/wiktionary.py
def pos(self): ''' Tries to decide about the part of speech. ''' tags = [] if self.tree.xpath('//div[@id="mw-content-text"]//a[@title="Hilfe:Wortart"]/text()'): info = self.tree.xpath('//div[@id="mw-content-text"]//a[@title="Hilfe:Wortart"]/text()')[0] if info == 'Substantiv': tags.append('NN') if i...
def pos(self): ''' Tries to decide about the part of speech. ''' tags = [] if self.tree.xpath('//div[@id="mw-content-text"]//a[@title="Hilfe:Wortart"]/text()'): info = self.tree.xpath('//div[@id="mw-content-text"]//a[@title="Hilfe:Wortart"]/text()')[0] if info == 'Substantiv': tags.append('NN') if i...
[ "Tries", "to", "decide", "about", "the", "part", "of", "speech", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/de/scrapers/wiktionary.py#L31-L43
[ "def", "pos", "(", "self", ")", ":", "tags", "=", "[", "]", "if", "self", ".", "tree", ".", "xpath", "(", "'//div[@id=\"mw-content-text\"]//a[@title=\"Hilfe:Wortart\"]/text()'", ")", ":", "info", "=", "self", ".", "tree", ".", "xpath", "(", "'//div[@id=\"mw-co...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
register
Registers a cache.
lltk/caching.py
def register(cache): ''' Registers a cache. ''' global caches name = cache().name if not caches.has_key(name): caches[name] = cache
def register(cache): ''' Registers a cache. ''' global caches name = cache().name if not caches.has_key(name): caches[name] = cache
[ "Registers", "a", "cache", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/caching.py#L15-L21
[ "def", "register", "(", "cache", ")", ":", "global", "caches", "name", "=", "cache", "(", ")", ".", "name", "if", "not", "caches", ".", "has_key", "(", "name", ")", ":", "caches", "[", "name", "]", "=", "cache" ]
d171de55c1b97695fddedf4b02401ae27bf1d634
train
enable
Enables a specific cache for the current session. Remember that is has to be registered.
lltk/caching.py
def enable(identifier = None, *args, **kwargs): ''' Enables a specific cache for the current session. Remember that is has to be registered. ''' global cache if not identifier: for item in (config['default-caches'] + ['NoCache']): if caches.has_key(item): debug('Enabling default cache %s...' % (item,)) ...
def enable(identifier = None, *args, **kwargs): ''' Enables a specific cache for the current session. Remember that is has to be registered. ''' global cache if not identifier: for item in (config['default-caches'] + ['NoCache']): if caches.has_key(item): debug('Enabling default cache %s...' % (item,)) ...
[ "Enables", "a", "specific", "cache", "for", "the", "current", "session", ".", "Remember", "that", "is", "has", "to", "be", "registered", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/caching.py#L23-L47
[ "def", "enable", "(", "identifier", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "global", "cache", "if", "not", "identifier", ":", "for", "item", "in", "(", "config", "[", "'default-caches'", "]", "+", "[", "'NoCache'", "]", ")"...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
cached
Decorator used for caching.
lltk/caching.py
def cached(key = None, extradata = {}): ''' Decorator used for caching. ''' def decorator(f): @wraps(f) def wrapper(*args, **kwargs): uid = key if not uid: from hashlib import md5 arguments = list(args) + [(a, kwargs[a]) for a in sorted(kwargs.keys())] uid = md5(str(arguments)).hexdigest() ...
def cached(key = None, extradata = {}): ''' Decorator used for caching. ''' def decorator(f): @wraps(f) def wrapper(*args, **kwargs): uid = key if not uid: from hashlib import md5 arguments = list(args) + [(a, kwargs[a]) for a in sorted(kwargs.keys())] uid = md5(str(arguments)).hexdigest() ...
[ "Decorator", "used", "for", "caching", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/caching.py#L85-L109
[ "def", "cached", "(", "key", "=", "None", ",", "extradata", "=", "{", "}", ")", ":", "def", "decorator", "(", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "uid", "=", "key"...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
GenericCache.needsconnection
Decorator used to make sure that the connection has been established.
lltk/caching.py
def needsconnection(self, f): ''' Decorator used to make sure that the connection has been established. ''' @wraps(f) def wrapper(self, *args, **kwargs): if not self.connection: self.connect() return f(self, *args, **kwargs) return wrapper
def needsconnection(self, f): ''' Decorator used to make sure that the connection has been established. ''' @wraps(f) def wrapper(self, *args, **kwargs): if not self.connection: self.connect() return f(self, *args, **kwargs) return wrapper
[ "Decorator", "used", "to", "make", "sure", "that", "the", "connection", "has", "been", "established", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/caching.py#L142-L150
[ "def", "needsconnection", "(", "self", ",", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "connection", ":", "self", ".", "connect", "(", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
language
Use this as a decorator (implicitly or explicitly).
lltk/decorators.py
def language(l): ''' Use this as a decorator (implicitly or explicitly). ''' # Usage: @language('en') or function = language('en')(function) def decorator(f): ''' Decorator used to prepend the language as an argument. ''' @wraps(f) def wrapper(*args, **kwargs): return f(l, *args, **kwargs) return wrapp...
def language(l): ''' Use this as a decorator (implicitly or explicitly). ''' # Usage: @language('en') or function = language('en')(function) def decorator(f): ''' Decorator used to prepend the language as an argument. ''' @wraps(f) def wrapper(*args, **kwargs): return f(l, *args, **kwargs) return wrapp...
[ "Use", "this", "as", "a", "decorator", "(", "implicitly", "or", "explicitly", ")", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/decorators.py#L6-L19
[ "def", "language", "(", "l", ")", ":", "# Usage: @language('en') or function = language('en')(function)", "def", "decorator", "(", "f", ")", ":", "''' Decorator used to prepend the language as an argument. '''", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "*", "...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
_load_language_or_die
Decorator used to load a custom method for a given language.
lltk/decorators.py
def _load_language_or_die(f): ''' Decorator used to load a custom method for a given language. ''' # This decorator checks if there's a custom method for a given language. # If so, prefer the custom method, otherwise raise exception NotImplementedError. @wraps(f) def loader(language, word, *args, **kwargs): me...
def _load_language_or_die(f): ''' Decorator used to load a custom method for a given language. ''' # This decorator checks if there's a custom method for a given language. # If so, prefer the custom method, otherwise raise exception NotImplementedError. @wraps(f) def loader(language, word, *args, **kwargs): me...
[ "Decorator", "used", "to", "load", "a", "custom", "method", "for", "a", "given", "language", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/decorators.py#L47-L71
[ "def", "_load_language_or_die", "(", "f", ")", ":", "# This decorator checks if there's a custom method for a given language.", "# If so, prefer the custom method, otherwise raise exception NotImplementedError.", "@", "wraps", "(", "f", ")", "def", "loader", "(", "language", ",", ...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
tatoeba
Returns a list of suitable textsamples for a given word using Tatoeba.org.
lltk/textsamples/tatoeba.py
def tatoeba(language, word, minlength = 10, maxlength = 100): ''' Returns a list of suitable textsamples for a given word using Tatoeba.org. ''' word, sentences = unicode(word), [] page = requests.get('http://tatoeba.org/deu/sentences/search?query=%s&from=%s&to=und' % (word, lltk.locale.iso639_1to3(language))) tre...
def tatoeba(language, word, minlength = 10, maxlength = 100): ''' Returns a list of suitable textsamples for a given word using Tatoeba.org. ''' word, sentences = unicode(word), [] page = requests.get('http://tatoeba.org/deu/sentences/search?query=%s&from=%s&to=und' % (word, lltk.locale.iso639_1to3(language))) tre...
[ "Returns", "a", "list", "of", "suitable", "textsamples", "for", "a", "given", "word", "using", "Tatoeba", ".", "org", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/textsamples/tatoeba.py#L8-L18
[ "def", "tatoeba", "(", "language", ",", "word", ",", "minlength", "=", "10", ",", "maxlength", "=", "100", ")", ":", "word", ",", "sentences", "=", "unicode", "(", "word", ")", ",", "[", "]", "page", "=", "requests", ".", "get", "(", "'http://tatoeba...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
WordreferenceIt.gender
Tries to scrape the correct gender for a given word from wordreference.com
lltk/it/scrapers/wordreference.py
def gender(self): ''' Tries to scrape the correct gender for a given word from wordreference.com ''' elements = self.tree.xpath('//table[@class="WRD"]') if len(elements): elements = self.tree.xpath('//table[@class="WRD"]')[0] if len(elements): if '/iten/' in self.page.url: elements = elements.xpat...
def gender(self): ''' Tries to scrape the correct gender for a given word from wordreference.com ''' elements = self.tree.xpath('//table[@class="WRD"]') if len(elements): elements = self.tree.xpath('//table[@class="WRD"]')[0] if len(elements): if '/iten/' in self.page.url: elements = elements.xpat...
[ "Tries", "to", "scrape", "the", "correct", "gender", "for", "a", "given", "word", "from", "wordreference", ".", "com" ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/it/scrapers/wordreference.py#L20-L38
[ "def", "gender", "(", "self", ")", ":", "elements", "=", "self", ".", "tree", ".", "xpath", "(", "'//table[@class=\"WRD\"]'", ")", "if", "len", "(", "elements", ")", ":", "elements", "=", "self", ".", "tree", ".", "xpath", "(", "'//table[@class=\"WRD\"]'",...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
humanize
Converts ISO639 language identifier to the corresponding (human readable) language name.
lltk/locale/locale.py
def humanize(iso639): ''' Converts ISO639 language identifier to the corresponding (human readable) language name. ''' for i, element in enumerate(LANGUAGES): if element[1] == iso639 or element[2] == iso639: return element[0] return None
def humanize(iso639): ''' Converts ISO639 language identifier to the corresponding (human readable) language name. ''' for i, element in enumerate(LANGUAGES): if element[1] == iso639 or element[2] == iso639: return element[0] return None
[ "Converts", "ISO639", "language", "identifier", "to", "the", "corresponding", "(", "human", "readable", ")", "language", "name", "." ]
lltk/lltk
python
https://github.com/lltk/lltk/blob/d171de55c1b97695fddedf4b02401ae27bf1d634/lltk/locale/locale.py#L220-L226
[ "def", "humanize", "(", "iso639", ")", ":", "for", "i", ",", "element", "in", "enumerate", "(", "LANGUAGES", ")", ":", "if", "element", "[", "1", "]", "==", "iso639", "or", "element", "[", "2", "]", "==", "iso639", ":", "return", "element", "[", "0...
d171de55c1b97695fddedf4b02401ae27bf1d634
train
Cluster.add_host
Adds a new host to the cluster. This is only really useful for unittests as normally hosts are added through the constructor and changes after the cluster has been used for the first time are unlikely to make sense.
rb/cluster.py
def add_host(self, host_id=None, host='localhost', port=6379, unix_socket_path=None, db=0, password=None, ssl=False, ssl_options=None): """Adds a new host to the cluster. This is only really useful for unittests as normally hosts are added through the constructor and ...
def add_host(self, host_id=None, host='localhost', port=6379, unix_socket_path=None, db=0, password=None, ssl=False, ssl_options=None): """Adds a new host to the cluster. This is only really useful for unittests as normally hosts are added through the constructor and ...
[ "Adds", "a", "new", "host", "to", "the", "cluster", ".", "This", "is", "only", "really", "useful", "for", "unittests", "as", "normally", "hosts", "are", "added", "through", "the", "constructor", "and", "changes", "after", "the", "cluster", "has", "been", "...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L111-L133
[ "def", "add_host", "(", "self", ",", "host_id", "=", "None", ",", "host", "=", "'localhost'", ",", "port", "=", "6379", ",", "unix_socket_path", "=", "None", ",", "db", "=", "0", ",", "password", "=", "None", ",", "ssl", "=", "False", ",", "ssl_optio...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.remove_host
Removes a host from the client. This only really useful for unittests.
rb/cluster.py
def remove_host(self, host_id): """Removes a host from the client. This only really useful for unittests. """ with self._lock: rv = self._hosts.pop(host_id, None) is not None pool = self._pools.pop(host_id, None) if pool is not None: p...
def remove_host(self, host_id): """Removes a host from the client. This only really useful for unittests. """ with self._lock: rv = self._hosts.pop(host_id, None) is not None pool = self._pools.pop(host_id, None) if pool is not None: p...
[ "Removes", "a", "host", "from", "the", "client", ".", "This", "only", "really", "useful", "for", "unittests", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L135-L145
[ "def", "remove_host", "(", "self", ",", "host_id", ")", ":", "with", "self", ".", "_lock", ":", "rv", "=", "self", ".", "_hosts", ".", "pop", "(", "host_id", ",", "None", ")", "is", "not", "None", "pool", "=", "self", ".", "_pools", ".", "pop", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.disconnect_pools
Disconnects all connections from the internal pools.
rb/cluster.py
def disconnect_pools(self): """Disconnects all connections from the internal pools.""" with self._lock: for pool in self._pools.itervalues(): pool.disconnect() self._pools.clear()
def disconnect_pools(self): """Disconnects all connections from the internal pools.""" with self._lock: for pool in self._pools.itervalues(): pool.disconnect() self._pools.clear()
[ "Disconnects", "all", "connections", "from", "the", "internal", "pools", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L147-L152
[ "def", "disconnect_pools", "(", "self", ")", ":", "with", "self", ".", "_lock", ":", "for", "pool", "in", "self", ".", "_pools", ".", "itervalues", "(", ")", ":", "pool", ".", "disconnect", "(", ")", "self", ".", "_pools", ".", "clear", "(", ")" ]
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.get_router
Returns the router for the cluster. If the cluster reconfigures the router will be recreated. Usually you do not need to interface with the router yourself as the cluster's routing client does that automatically. This returns an instance of :class:`BaseRouter`.
rb/cluster.py
def get_router(self): """Returns the router for the cluster. If the cluster reconfigures the router will be recreated. Usually you do not need to interface with the router yourself as the cluster's routing client does that automatically. This returns an instance of :class:`Bas...
def get_router(self): """Returns the router for the cluster. If the cluster reconfigures the router will be recreated. Usually you do not need to interface with the router yourself as the cluster's routing client does that automatically. This returns an instance of :class:`Bas...
[ "Returns", "the", "router", "for", "the", "cluster", ".", "If", "the", "cluster", "reconfigures", "the", "router", "will", "be", "recreated", ".", "Usually", "you", "do", "not", "need", "to", "interface", "with", "the", "router", "yourself", "as", "the", "...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L154-L173
[ "def", "get_router", "(", "self", ")", ":", "cached_router", "=", "self", ".", "_router", "ref_age", "=", "self", ".", "_hosts_age", "if", "cached_router", "is", "not", "None", ":", "router", ",", "router_age", "=", "cached_router", "if", "router_age", "==",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.get_pool_for_host
Returns the connection pool for the given host. This connection pool is used by the redis clients to make sure that it does not have to reconnect constantly. If you want to use a custom redis client you can pass this in as connection pool manually.
rb/cluster.py
def get_pool_for_host(self, host_id): """Returns the connection pool for the given host. This connection pool is used by the redis clients to make sure that it does not have to reconnect constantly. If you want to use a custom redis client you can pass this in as connection pool ...
def get_pool_for_host(self, host_id): """Returns the connection pool for the given host. This connection pool is used by the redis clients to make sure that it does not have to reconnect constantly. If you want to use a custom redis client you can pass this in as connection pool ...
[ "Returns", "the", "connection", "pool", "for", "the", "given", "host", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L175-L218
[ "def", "get_pool_for_host", "(", "self", ",", "host_id", ")", ":", "if", "isinstance", "(", "host_id", ",", "HostInfo", ")", ":", "host_info", "=", "host_id", "host_id", "=", "host_info", ".", "host_id", "else", ":", "host_info", "=", "self", ".", "hosts",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.map
Shortcut context manager for getting a routing client, beginning a map operation and joining over the result. `max_concurrency` defines how many outstanding parallel queries can exist before an implicit join takes place. In the context manager the client available is a :class:`...
rb/cluster.py
def map(self, timeout=None, max_concurrency=64, auto_batch=True): """Shortcut context manager for getting a routing client, beginning a map operation and joining over the result. `max_concurrency` defines how many outstanding parallel queries can exist before an implicit join takes plac...
def map(self, timeout=None, max_concurrency=64, auto_batch=True): """Shortcut context manager for getting a routing client, beginning a map operation and joining over the result. `max_concurrency` defines how many outstanding parallel queries can exist before an implicit join takes plac...
[ "Shortcut", "context", "manager", "for", "getting", "a", "routing", "client", "beginning", "a", "map", "operation", "and", "joining", "over", "the", "result", ".", "max_concurrency", "defines", "how", "many", "outstanding", "parallel", "queries", "can", "exist", ...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L252-L269
[ "def", "map", "(", "self", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "True", ")", ":", "return", "self", ".", "get_routing_client", "(", "auto_batch", ")", ".", "map", "(", "timeout", "=", "timeout", ",", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.fanout
Shortcut context manager for getting a routing client, beginning a fanout operation and joining over the result. In the context manager the client available is a :class:`FanoutClient`. Example usage:: with cluster.fanout(hosts='all') as client: client.flushdb()
rb/cluster.py
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=True): """Shortcut context manager for getting a routing client, beginning a fanout operation and joining over the result. In the context manager the client available is a :class:`FanoutClient`. Ex...
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=True): """Shortcut context manager for getting a routing client, beginning a fanout operation and joining over the result. In the context manager the client available is a :class:`FanoutClient`. Ex...
[ "Shortcut", "context", "manager", "for", "getting", "a", "routing", "client", "beginning", "a", "fanout", "operation", "and", "joining", "over", "the", "result", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L271-L283
[ "def", "fanout", "(", "self", ",", "hosts", "=", "None", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "True", ")", ":", "return", "self", ".", "get_routing_client", "(", "auto_batch", ")", ".", "fanout", "(", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.all
Fanout to all hosts. Works otherwise exactly like :meth:`fanout`. Example:: with cluster.all() as client: client.flushdb()
rb/cluster.py
def all(self, timeout=None, max_concurrency=64, auto_batch=True): """Fanout to all hosts. Works otherwise exactly like :meth:`fanout`. Example:: with cluster.all() as client: client.flushdb() """ return self.fanout('all', timeout=timeout, ...
def all(self, timeout=None, max_concurrency=64, auto_batch=True): """Fanout to all hosts. Works otherwise exactly like :meth:`fanout`. Example:: with cluster.all() as client: client.flushdb() """ return self.fanout('all', timeout=timeout, ...
[ "Fanout", "to", "all", "hosts", ".", "Works", "otherwise", "exactly", "like", ":", "meth", ":", "fanout", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L285-L295
[ "def", "all", "(", "self", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "True", ")", ":", "return", "self", ".", "fanout", "(", "'all'", ",", "timeout", "=", "timeout", ",", "max_concurrency", "=", "max_concurre...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Cluster.execute_commands
Concurrently executes a sequence of commands on a Redis cluster that are associated with a routing key, returning a new mapping where values are a list of results that correspond to the command in the same position. For example:: >>> cluster.execute_commands({ ... 'foo...
rb/cluster.py
def execute_commands(self, mapping, *args, **kwargs): """Concurrently executes a sequence of commands on a Redis cluster that are associated with a routing key, returning a new mapping where values are a list of results that correspond to the command in the same position. For example:: ...
def execute_commands(self, mapping, *args, **kwargs): """Concurrently executes a sequence of commands on a Redis cluster that are associated with a routing key, returning a new mapping where values are a list of results that correspond to the command in the same position. For example:: ...
[ "Concurrently", "executes", "a", "sequence", "of", "commands", "on", "a", "Redis", "cluster", "that", "are", "associated", "with", "a", "routing", "key", "returning", "a", "new", "mapping", "where", "values", "are", "a", "list", "of", "results", "that", "cor...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/cluster.py#L297-L392
[ "def", "execute_commands", "(", "self", ",", "mapping", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "is_script_command", "(", "command", ")", ":", "return", "isinstance", "(", "command", "[", "0", "]", ",", "Script", ")", "def", "check_...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
auto_batch_commands
Given a pipeline of commands this attempts to merge the commands into more efficient ones if that is possible.
rb/clients.py
def auto_batch_commands(commands): """Given a pipeline of commands this attempts to merge the commands into more efficient ones if that is possible. """ pending_batch = None for command_name, args, options, promise in commands: # This command cannot be batched, return it as such. if...
def auto_batch_commands(commands): """Given a pipeline of commands this attempts to merge the commands into more efficient ones if that is possible. """ pending_batch = None for command_name, args, options, promise in commands: # This command cannot be batched, return it as such. if...
[ "Given", "a", "pipeline", "of", "commands", "this", "attempts", "to", "merge", "the", "commands", "into", "more", "efficient", "ones", "if", "that", "is", "possible", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L56-L80
[ "def", "auto_batch_commands", "(", "commands", ")", ":", "pending_batch", "=", "None", "for", "command_name", ",", "args", ",", "options", ",", "promise", "in", "commands", ":", "# This command cannot be batched, return it as such.", "if", "command_name", "not", "in",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
CommandBuffer.enqueue_command
Enqueue a new command into this pipeline.
rb/clients.py
def enqueue_command(self, command_name, args, options): """Enqueue a new command into this pipeline.""" assert_open(self) promise = Promise() self.commands.append((command_name, args, options, promise)) return promise
def enqueue_command(self, command_name, args, options): """Enqueue a new command into this pipeline.""" assert_open(self) promise = Promise() self.commands.append((command_name, args, options, promise)) return promise
[ "Enqueue", "a", "new", "command", "into", "this", "pipeline", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L129-L134
[ "def", "enqueue_command", "(", "self", ",", "command_name", ",", "args", ",", "options", ")", ":", "assert_open", "(", "self", ")", "promise", "=", "Promise", "(", ")", "self", ".", "commands", ".", "append", "(", "(", "command_name", ",", "args", ",", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
CommandBuffer.send_buffer
Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place.
rb/clients.py
def send_buffer(self): """Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place. """ buf = self._send_buf sock = self.connection._sock try: timeout = sock.gettimeout() sock...
def send_buffer(self): """Utility function that sends the buffer into the provided socket. The buffer itself will slowly clear out and is modified in place. """ buf = self._send_buf sock = self.connection._sock try: timeout = sock.gettimeout() sock...
[ "Utility", "function", "that", "sends", "the", "buffer", "into", "the", "provided", "socket", ".", "The", "buffer", "itself", "will", "slowly", "clear", "out", "and", "is", "modified", "in", "place", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L143-L179
[ "def", "send_buffer", "(", "self", ")", ":", "buf", "=", "self", ".", "_send_buf", "sock", "=", "self", ".", "connection", ".", "_sock", "try", ":", "timeout", "=", "sock", ".", "gettimeout", "(", ")", "sock", ".", "setblocking", "(", "False", ")", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
CommandBuffer.send_pending_requests
Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over.
rb/clients.py
def send_pending_requests(self): """Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over. """ assert_open(self...
def send_pending_requests(self): """Sends all pending requests into the connection. The default is to only send pending data that fits into the socket without blocking. This returns `True` if all data was sent or `False` if pending data is left over. """ assert_open(self...
[ "Sends", "all", "pending", "requests", "into", "the", "connection", ".", "The", "default", "is", "to", "only", "send", "pending", "data", "that", "fits", "into", "the", "socket", "without", "blocking", ".", "This", "returns", "True", "if", "all", "data", "...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L181-L208
[ "def", "send_pending_requests", "(", "self", ")", ":", "assert_open", "(", "self", ")", "unsent_commands", "=", "self", ".", "commands", "if", "unsent_commands", ":", "self", ".", "commands", "=", "[", "]", "if", "self", ".", "auto_batch", ":", "unsent_comma...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
CommandBuffer.wait_for_responses
Waits for all responses to come back and resolves the eventual results.
rb/clients.py
def wait_for_responses(self, client): """Waits for all responses to come back and resolves the eventual results. """ assert_open(self) if self.has_pending_requests: raise RuntimeError('Cannot wait for responses if there are ' 'pending r...
def wait_for_responses(self, client): """Waits for all responses to come back and resolves the eventual results. """ assert_open(self) if self.has_pending_requests: raise RuntimeError('Cannot wait for responses if there are ' 'pending r...
[ "Waits", "for", "all", "responses", "to", "come", "back", "and", "resolves", "the", "eventual", "results", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L210-L227
[ "def", "wait_for_responses", "(", "self", ",", "client", ")", ":", "assert_open", "(", "self", ")", "if", "self", ".", "has_pending_requests", ":", "raise", "RuntimeError", "(", "'Cannot wait for responses if there are '", "'pending requests outstanding. You need '", "'t...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
MappingClient._get_command_buffer
Returns the command buffer for the given command and arguments.
rb/clients.py
def _get_command_buffer(self, host_id, command_name): """Returns the command buffer for the given command and arguments.""" buf = self._cb_poll.get(host_id) if buf is not None: return buf if self._max_concurrency is not None: while len(self._cb_poll) >= self._max...
def _get_command_buffer(self, host_id, command_name): """Returns the command buffer for the given command and arguments.""" buf = self._cb_poll.get(host_id) if buf is not None: return buf if self._max_concurrency is not None: while len(self._cb_poll) >= self._max...
[ "Returns", "the", "command", "buffer", "for", "the", "given", "command", "and", "arguments", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L338-L353
[ "def", "_get_command_buffer", "(", "self", ",", "host_id", ",", "command_name", ")", ":", "buf", "=", "self", ".", "_cb_poll", ".", "get", "(", "host_id", ")", "if", "buf", "is", "not", "None", ":", "return", "buf", "if", "self", ".", "_max_concurrency",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
MappingClient._release_command_buffer
This is called by the command buffer when it closes.
rb/clients.py
def _release_command_buffer(self, command_buffer): """This is called by the command buffer when it closes.""" if command_buffer.closed: return self._cb_poll.unregister(command_buffer.host_id) self.connection_pool.release(command_buffer.connection) command_buffer.conn...
def _release_command_buffer(self, command_buffer): """This is called by the command buffer when it closes.""" if command_buffer.closed: return self._cb_poll.unregister(command_buffer.host_id) self.connection_pool.release(command_buffer.connection) command_buffer.conn...
[ "This", "is", "called", "by", "the", "command", "buffer", "when", "it", "closes", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L355-L362
[ "def", "_release_command_buffer", "(", "self", ",", "command_buffer", ")", ":", "if", "command_buffer", ".", "closed", ":", "return", "self", ".", "_cb_poll", ".", "unregister", "(", "command_buffer", ".", "host_id", ")", "self", ".", "connection_pool", ".", "...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
MappingClient.join
Waits for all outstanding responses to come back or the timeout to be hit.
rb/clients.py
def join(self, timeout=None): """Waits for all outstanding responses to come back or the timeout to be hit. """ remaining = timeout while self._cb_poll and (remaining is None or remaining > 0): now = time.time() rv = self._cb_poll.poll(remaining) ...
def join(self, timeout=None): """Waits for all outstanding responses to come back or the timeout to be hit. """ remaining = timeout while self._cb_poll and (remaining is None or remaining > 0): now = time.time() rv = self._cb_poll.poll(remaining) ...
[ "Waits", "for", "all", "outstanding", "responses", "to", "come", "back", "or", "the", "timeout", "to", "be", "hit", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L384-L418
[ "def", "join", "(", "self", ",", "timeout", "=", "None", ")", ":", "remaining", "=", "timeout", "while", "self", ".", "_cb_poll", "and", "(", "remaining", "is", "None", "or", "remaining", ">", "0", ")", ":", "now", "=", "time", ".", "time", "(", ")...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
FanoutClient.target
Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call.
rb/clients.py
def target(self, hosts): """Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call. """ if self.__is_retargeted: raise TypeError('Cannot use target more than once.') rv = FanoutClient(hosts, connection_poo...
def target(self, hosts): """Temporarily retarget the client for one call. This is useful when having to deal with a subset of hosts for one call. """ if self.__is_retargeted: raise TypeError('Cannot use target more than once.') rv = FanoutClient(hosts, connection_poo...
[ "Temporarily", "retarget", "the", "client", "for", "one", "call", ".", "This", "is", "useful", "when", "having", "to", "deal", "with", "a", "subset", "of", "hosts", "for", "one", "call", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L444-L454
[ "def", "target", "(", "self", ",", "hosts", ")", ":", "if", "self", ".", "__is_retargeted", ":", "raise", "TypeError", "(", "'Cannot use target more than once.'", ")", "rv", "=", "FanoutClient", "(", "hosts", ",", "connection_pool", "=", "self", ".", "connecti...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
FanoutClient.target_key
Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3
rb/clients.py
def target_key(self, key): """Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3 """ ...
def target_key(self, key): """Temporarily retarget the client for one call to route specifically to the one host that the given key routes to. In that case the result on the promise is just the one host's value instead of a dictionary. .. versionadded:: 1.3 """ ...
[ "Temporarily", "retarget", "the", "client", "for", "one", "call", "to", "route", "specifically", "to", "the", "one", "host", "that", "the", "given", "key", "routes", "to", ".", "In", "that", "case", "the", "result", "on", "the", "promise", "is", "just", ...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L456-L468
[ "def", "target_key", "(", "self", ",", "key", ")", ":", "router", "=", "self", ".", "connection_pool", ".", "cluster", ".", "get_router", "(", ")", "host_id", "=", "router", ".", "get_host_for_key", "(", "key", ")", "rv", "=", "self", ".", "target", "(...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
RoutingClient.get_mapping_client
Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :meth:`map` context manager which automatically joins. Returns...
rb/clients.py
def get_mapping_client(self, max_concurrency=64, auto_batch=None): """Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :...
def get_mapping_client(self, max_concurrency=64, auto_batch=None): """Returns a thread unsafe mapping client. This client works similar to a redis pipeline and returns eventual result objects. It needs to be joined on to work properly. Instead of using this directly you shold use the :...
[ "Returns", "a", "thread", "unsafe", "mapping", "client", ".", "This", "client", "works", "similar", "to", "a", "redis", "pipeline", "and", "returns", "eventual", "result", "objects", ".", "It", "needs", "to", "be", "joined", "on", "to", "work", "properly", ...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L522-L535
[ "def", "get_mapping_client", "(", "self", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "if", "auto_batch", "is", "None", ":", "auto_batch", "=", "self", ".", "auto_batch", "return", "MappingClient", "(", "connection_pool", "=", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
RoutingClient.get_fanout_client
Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`.
rb/clients.py
def get_fanout_client(self, hosts, max_concurrency=64, auto_batch=None): """Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`. """ if auto_batch is None: auto_batch = self.auto_batch return FanoutClient(host...
def get_fanout_client(self, hosts, max_concurrency=64, auto_batch=None): """Returns a thread unsafe fanout client. Returns an instance of :class:`FanoutClient`. """ if auto_batch is None: auto_batch = self.auto_batch return FanoutClient(host...
[ "Returns", "a", "thread", "unsafe", "fanout", "client", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L537-L547
[ "def", "get_fanout_client", "(", "self", ",", "hosts", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "if", "auto_batch", "is", "None", ":", "auto_batch", "=", "self", ".", "auto_batch", "return", "FanoutClient", "(", "hosts", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
RoutingClient.map
Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. Example usage:: results = {} with cluster.map() as ...
rb/clients.py
def map(self, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. ...
def map(self, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation. This runs multiple queries in parallel and then joins in the end to collect all results. In the context manager the client available is a :class:`MappingClient`. ...
[ "Returns", "a", "context", "manager", "for", "a", "map", "operation", ".", "This", "runs", "multiple", "queries", "in", "parallel", "and", "then", "joins", "in", "the", "end", "to", "collect", "all", "results", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L549-L565
[ "def", "map", "(", "self", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "return", "MapManager", "(", "self", ".", "get_mapping_client", "(", "max_concurrency", ",", "auto_batch", ")", ",", "timeo...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
RoutingClient.fanout
Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The context manager returns a :class:`FanoutClient`. Example usage:: with cluster.fanout(...
rb/clients.py
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The ...
def fanout(self, hosts=None, timeout=None, max_concurrency=64, auto_batch=None): """Returns a context manager for a map operation that fans out to manually specified hosts instead of using the routing system. This can for instance be used to empty the database on all hosts. The ...
[ "Returns", "a", "context", "manager", "for", "a", "map", "operation", "that", "fans", "out", "to", "manually", "specified", "hosts", "instead", "of", "using", "the", "routing", "system", ".", "This", "can", "for", "instance", "be", "used", "to", "empty", "...
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/clients.py#L567-L591
[ "def", "fanout", "(", "self", ",", "hosts", "=", "None", ",", "timeout", "=", "None", ",", "max_concurrency", "=", "64", ",", "auto_batch", "=", "None", ")", ":", "return", "MapManager", "(", "self", ".", "get_fanout_client", "(", "hosts", ",", "max_conc...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.resolved
Creates a promise object resolved with a certain value.
rb/promise.py
def resolved(value): """Creates a promise object resolved with a certain value.""" p = Promise() p._state = 'resolved' p.value = value return p
def resolved(value): """Creates a promise object resolved with a certain value.""" p = Promise() p._state = 'resolved' p.value = value return p
[ "Creates", "a", "promise", "object", "resolved", "with", "a", "certain", "value", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L22-L27
[ "def", "resolved", "(", "value", ")", ":", "p", "=", "Promise", "(", ")", "p", ".", "_state", "=", "'resolved'", "p", ".", "value", "=", "value", "return", "p" ]
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.rejected
Creates a promise object rejected with a certain value.
rb/promise.py
def rejected(reason): """Creates a promise object rejected with a certain value.""" p = Promise() p._state = 'rejected' p.reason = reason return p
def rejected(reason): """Creates a promise object rejected with a certain value.""" p = Promise() p._state = 'rejected' p.reason = reason return p
[ "Creates", "a", "promise", "object", "rejected", "with", "a", "certain", "value", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L30-L35
[ "def", "rejected", "(", "reason", ")", ":", "p", "=", "Promise", "(", ")", "p", ".", "_state", "=", "'rejected'", "p", ".", "reason", "=", "reason", "return", "p" ]
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.resolve
Resolves the promise with the given value.
rb/promise.py
def resolve(self, value): """Resolves the promise with the given value.""" if self is value: raise TypeError('Cannot resolve promise with itself.') if isinstance(value, Promise): value.done(self.resolve, self.reject) return if self._state != 'pending...
def resolve(self, value): """Resolves the promise with the given value.""" if self is value: raise TypeError('Cannot resolve promise with itself.') if isinstance(value, Promise): value.done(self.resolve, self.reject) return if self._state != 'pending...
[ "Resolves", "the", "promise", "with", "the", "given", "value", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L46-L63
[ "def", "resolve", "(", "self", ",", "value", ")", ":", "if", "self", "is", "value", ":", "raise", "TypeError", "(", "'Cannot resolve promise with itself.'", ")", "if", "isinstance", "(", "value", ",", "Promise", ")", ":", "value", ".", "done", "(", "self",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.reject
Rejects the promise with the given reason.
rb/promise.py
def reject(self, reason): """Rejects the promise with the given reason.""" if self._state != 'pending': raise RuntimeError('Promise is no longer pending.') self.reason = reason self._state = 'rejected' errbacks = self._errbacks self._errbacks = None f...
def reject(self, reason): """Rejects the promise with the given reason.""" if self._state != 'pending': raise RuntimeError('Promise is no longer pending.') self.reason = reason self._state = 'rejected' errbacks = self._errbacks self._errbacks = None f...
[ "Rejects", "the", "promise", "with", "the", "given", "reason", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L65-L75
[ "def", "reject", "(", "self", ",", "reason", ")", ":", "if", "self", ".", "_state", "!=", "'pending'", ":", "raise", "RuntimeError", "(", "'Promise is no longer pending.'", ")", "self", ".", "reason", "=", "reason", "self", ".", "_state", "=", "'rejected'", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.done
Attaches some callbacks to the promise and returns the promise.
rb/promise.py
def done(self, on_success=None, on_failure=None): """Attaches some callbacks to the promise and returns the promise.""" if on_success is not None: if self._state == 'pending': self._callbacks.append(on_success) elif self._state == 'resolved': on_su...
def done(self, on_success=None, on_failure=None): """Attaches some callbacks to the promise and returns the promise.""" if on_success is not None: if self._state == 'pending': self._callbacks.append(on_success) elif self._state == 'resolved': on_su...
[ "Attaches", "some", "callbacks", "to", "the", "promise", "and", "returns", "the", "promise", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L92-L104
[ "def", "done", "(", "self", ",", "on_success", "=", "None", ",", "on_failure", "=", "None", ")", ":", "if", "on_success", "is", "not", "None", ":", "if", "self", ".", "_state", "==", "'pending'", ":", "self", ".", "_callbacks", ".", "append", "(", "o...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Promise.then
A utility method to add success and/or failure callback to the promise which will also return another promise in the process.
rb/promise.py
def then(self, success=None, failure=None): """A utility method to add success and/or failure callback to the promise which will also return another promise in the process. """ rv = Promise() def on_success(v): try: rv.resolve(success(v)) ...
def then(self, success=None, failure=None): """A utility method to add success and/or failure callback to the promise which will also return another promise in the process. """ rv = Promise() def on_success(v): try: rv.resolve(success(v)) ...
[ "A", "utility", "method", "to", "add", "success", "and", "/", "or", "failure", "callback", "to", "the", "promise", "which", "will", "also", "return", "another", "promise", "in", "the", "process", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/promise.py#L106-L125
[ "def", "then", "(", "self", ",", "success", "=", "None", ",", "failure", "=", "None", ")", ":", "rv", "=", "Promise", "(", ")", "def", "on_success", "(", "v", ")", ":", "try", ":", "rv", ".", "resolve", "(", "success", "(", "v", ")", ")", "exce...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
BaseRouter.get_key
Returns the key a command operates on.
rb/router.py
def get_key(self, command, args): """Returns the key a command operates on.""" spec = COMMANDS.get(command.upper()) if spec is None: raise UnroutableCommand('The command "%r" is unknown to the ' 'router and cannot be handled as a ' ...
def get_key(self, command, args): """Returns the key a command operates on.""" spec = COMMANDS.get(command.upper()) if spec is None: raise UnroutableCommand('The command "%r" is unknown to the ' 'router and cannot be handled as a ' ...
[ "Returns", "the", "key", "a", "command", "operates", "on", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/router.py#L60-L85
[ "def", "get_key", "(", "self", ",", "command", ",", "args", ")", ":", "spec", "=", "COMMANDS", ".", "get", "(", "command", ".", "upper", "(", ")", ")", "if", "spec", "is", "None", ":", "raise", "UnroutableCommand", "(", "'The command \"%r\" is unknown to t...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
BaseRouter.get_host_for_command
Returns the host this command should be executed against.
rb/router.py
def get_host_for_command(self, command, args): """Returns the host this command should be executed against.""" return self.get_host_for_key(self.get_key(command, args))
def get_host_for_command(self, command, args): """Returns the host this command should be executed against.""" return self.get_host_for_key(self.get_key(command, args))
[ "Returns", "the", "host", "this", "command", "should", "be", "executed", "against", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/router.py#L87-L89
[ "def", "get_host_for_command", "(", "self", ",", "command", ",", "args", ")", ":", "return", "self", ".", "get_host_for_key", "(", "self", ".", "get_key", "(", "command", ",", "args", ")", ")" ]
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Ketama._rebuild_circle
Updates the hash ring.
rb/ketama.py
def _rebuild_circle(self): """Updates the hash ring.""" self._hashring = {} self._sorted_keys = [] total_weight = 0 for node in self._nodes: total_weight += self._weights.get(node, 1) for node in self._nodes: weight = self._weights.get(node, 1) ...
def _rebuild_circle(self): """Updates the hash ring.""" self._hashring = {} self._sorted_keys = [] total_weight = 0 for node in self._nodes: total_weight += self._weights.get(node, 1) for node in self._nodes: weight = self._weights.get(node, 1) ...
[ "Updates", "the", "hash", "ring", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L21-L43
[ "def", "_rebuild_circle", "(", "self", ")", ":", "self", ".", "_hashring", "=", "{", "}", "self", ".", "_sorted_keys", "=", "[", "]", "total_weight", "=", "0", "for", "node", "in", "self", ".", "_nodes", ":", "total_weight", "+=", "self", ".", "_weight...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Ketama._get_node_pos
Return node position(integer) for a given key or None.
rb/ketama.py
def _get_node_pos(self, key): """Return node position(integer) for a given key or None.""" if not self._hashring: return k = md5_bytes(key) key = (k[3] << 24) | (k[2] << 16) | (k[1] << 8) | k[0] nodes = self._sorted_keys pos = bisect(nodes, key) if ...
def _get_node_pos(self, key): """Return node position(integer) for a given key or None.""" if not self._hashring: return k = md5_bytes(key) key = (k[3] << 24) | (k[2] << 16) | (k[1] << 8) | k[0] nodes = self._sorted_keys pos = bisect(nodes, key) if ...
[ "Return", "node", "position", "(", "integer", ")", "for", "a", "given", "key", "or", "None", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L45-L58
[ "def", "_get_node_pos", "(", "self", ",", "key", ")", ":", "if", "not", "self", ".", "_hashring", ":", "return", "k", "=", "md5_bytes", "(", "key", ")", "key", "=", "(", "k", "[", "3", "]", "<<", "24", ")", "|", "(", "k", "[", "2", "]", "<<",...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Ketama.remove_node
Removes node from circle and rebuild it.
rb/ketama.py
def remove_node(self, node): """Removes node from circle and rebuild it.""" try: self._nodes.remove(node) del self._weights[node] except (KeyError, ValueError): pass self._rebuild_circle()
def remove_node(self, node): """Removes node from circle and rebuild it.""" try: self._nodes.remove(node) del self._weights[node] except (KeyError, ValueError): pass self._rebuild_circle()
[ "Removes", "node", "from", "circle", "and", "rebuild", "it", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L60-L67
[ "def", "remove_node", "(", "self", ",", "node", ")", ":", "try", ":", "self", ".", "_nodes", ".", "remove", "(", "node", ")", "del", "self", ".", "_weights", "[", "node", "]", "except", "(", "KeyError", ",", "ValueError", ")", ":", "pass", "self", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Ketama.add_node
Adds node to circle and rebuild it.
rb/ketama.py
def add_node(self, node, weight=1): """Adds node to circle and rebuild it.""" self._nodes.add(node) self._weights[node] = weight self._rebuild_circle()
def add_node(self, node, weight=1): """Adds node to circle and rebuild it.""" self._nodes.add(node) self._weights[node] = weight self._rebuild_circle()
[ "Adds", "node", "to", "circle", "and", "rebuild", "it", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L69-L73
[ "def", "add_node", "(", "self", ",", "node", ",", "weight", "=", "1", ")", ":", "self", ".", "_nodes", ".", "add", "(", "node", ")", "self", ".", "_weights", "[", "node", "]", "=", "weight", "self", ".", "_rebuild_circle", "(", ")" ]
569d1d13311f6c04bae537fc17e75da430e4ec45
train
Ketama.get_node
Return node for a given key. Else return None.
rb/ketama.py
def get_node(self, key): """Return node for a given key. Else return None.""" pos = self._get_node_pos(key) if pos is None: return None return self._hashring[self._sorted_keys[pos]]
def get_node(self, key): """Return node for a given key. Else return None.""" pos = self._get_node_pos(key) if pos is None: return None return self._hashring[self._sorted_keys[pos]]
[ "Return", "node", "for", "a", "given", "key", ".", "Else", "return", "None", "." ]
getsentry/rb
python
https://github.com/getsentry/rb/blob/569d1d13311f6c04bae537fc17e75da430e4ec45/rb/ketama.py#L75-L80
[ "def", "get_node", "(", "self", ",", "key", ")", ":", "pos", "=", "self", ".", "_get_node_pos", "(", "key", ")", "if", "pos", "is", "None", ":", "return", "None", "return", "self", ".", "_hashring", "[", "self", ".", "_sorted_keys", "[", "pos", "]", ...
569d1d13311f6c04bae537fc17e75da430e4ec45
train
check_error
Error checking proper value returns
mgrs/core.py
def check_error(result, func, cargs): "Error checking proper value returns" if result != 0: msg = 'Error in "%s": %s' % (func.__name__, get_errors(result) ) raise RTreeError(msg) return
def check_error(result, func, cargs): "Error checking proper value returns" if result != 0: msg = 'Error in "%s": %s' % (func.__name__, get_errors(result) ) raise RTreeError(msg) return
[ "Error", "checking", "proper", "value", "returns" ]
hobu/mgrs
python
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/core.py#L77-L82
[ "def", "check_error", "(", "result", ",", "func", ",", "cargs", ")", ":", "if", "result", "!=", "0", ":", "msg", "=", "'Error in \"%s\": %s'", "%", "(", "func", ".", "__name__", ",", "get_errors", "(", "result", ")", ")", "raise", "RTreeError", "(", "m...
759b3aba86779318854c73b8843ea956acb5eb3f
train
MGRS.ddtodms
Take in dd string and convert to dms
mgrs/__init__.py
def ddtodms(self, dd): """Take in dd string and convert to dms""" negative = dd < 0 dd = abs(dd) minutes,seconds = divmod(dd*3600,60) degrees,minutes = divmod(minutes,60) if negative: if degrees > 0: degrees = -degrees elif minutes ...
def ddtodms(self, dd): """Take in dd string and convert to dms""" negative = dd < 0 dd = abs(dd) minutes,seconds = divmod(dd*3600,60) degrees,minutes = divmod(minutes,60) if negative: if degrees > 0: degrees = -degrees elif minutes ...
[ "Take", "in", "dd", "string", "and", "convert", "to", "dms" ]
hobu/mgrs
python
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/__init__.py#L13-L26
[ "def", "ddtodms", "(", "self", ",", "dd", ")", ":", "negative", "=", "dd", "<", "0", "dd", "=", "abs", "(", "dd", ")", "minutes", ",", "seconds", "=", "divmod", "(", "dd", "*", "3600", ",", "60", ")", "degrees", ",", "minutes", "=", "divmod", "...
759b3aba86779318854c73b8843ea956acb5eb3f
train
MGRS.dmstodd
convert dms to dd
mgrs/__init__.py
def dmstodd(self, dms): """ convert dms to dd""" size = len(dms) letters = 'WENS' is_annotated = False try: float(dms) except ValueError: for letter in letters: if letter in dms.upper(): is_annotated = True ...
def dmstodd(self, dms): """ convert dms to dd""" size = len(dms) letters = 'WENS' is_annotated = False try: float(dms) except ValueError: for letter in letters: if letter in dms.upper(): is_annotated = True ...
[ "convert", "dms", "to", "dd" ]
hobu/mgrs
python
https://github.com/hobu/mgrs/blob/759b3aba86779318854c73b8843ea956acb5eb3f/mgrs/__init__.py#L28-L80
[ "def", "dmstodd", "(", "self", ",", "dms", ")", ":", "size", "=", "len", "(", "dms", ")", "letters", "=", "'WENS'", "is_annotated", "=", "False", "try", ":", "float", "(", "dms", ")", "except", "ValueError", ":", "for", "letter", "in", "letters", ":"...
759b3aba86779318854c73b8843ea956acb5eb3f
train
get_fobj
Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parameter. mode : str The mode of...
pydot_ng/__init__.py
def get_fobj(fname, mode='w+'): """Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parame...
def get_fobj(fname, mode='w+'): """Obtain a proper file object. Parameters ---------- fname : string, file object, file descriptor If a string or file descriptor, then we create a file object. If *fname* is a file object, then we do nothing and ignore the specified *mode* parame...
[ "Obtain", "a", "proper", "file", "object", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L111-L146
[ "def", "get_fobj", "(", "fname", ",", "mode", "=", "'w+'", ")", ":", "if", "is_string_like", "(", "fname", ")", ":", "fobj", "=", "open", "(", "fname", ",", "mode", ")", "close", "=", "True", "elif", "hasattr", "(", "fname", ",", "'write'", ")", ":...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
graph_from_dot_file
Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph.
pydot_ng/__init__.py
def graph_from_dot_file(path): """Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph. """ fd = open(path, 'rb') data = fd.read() fd.close() return graph_from_dot_data(data...
def graph_from_dot_file(path): """Load graph as defined by a DOT file. The file is assumed to be in DOT format. It will be loaded, parsed and a Dot class will be returned, representing the graph. """ fd = open(path, 'rb') data = fd.read() fd.close() return graph_from_dot_data(data...
[ "Load", "graph", "as", "defined", "by", "a", "DOT", "file", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L286-L298
[ "def", "graph_from_dot_file", "(", "path", ")", ":", "fd", "=", "open", "(", "path", ",", "'rb'", ")", "data", "=", "fd", ".", "read", "(", ")", "fd", ".", "close", "(", ")", "return", "graph_from_dot_data", "(", "data", ")" ]
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
graph_from_edges
Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only calculated from one of the symmetric halves of the matrix.
pydot_ng/__init__.py
def graph_from_edges(edge_list, node_prefix='', directed=False): """Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only...
def graph_from_edges(edge_list, node_prefix='', directed=False): """Creates a basic graph out of an edge list. The edge list has to be a list of tuples representing the nodes connected by the edge. The values can be anything: bool, int, float, str. If the graph is undirected by default, it is only...
[ "Creates", "a", "basic", "graph", "out", "of", "an", "edge", "list", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L301-L325
[ "def", "graph_from_edges", "(", "edge_list", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "if", "edge_list", "is", "None", ":", "edge_list", "=", "[", "]", "graph_type", "=", "\"digraph\"", "if", "directed", "else", "\"graph\"", ...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
graph_from_adjacency_matrix
Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False.
pydot_ng/__init__.py
def graph_from_adjacency_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
def graph_from_adjacency_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an adjacency matrix. The matrix has to be a list of rows of values representing an adjacency matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
[ "Creates", "a", "basic", "graph", "out", "of", "an", "adjacency", "matrix", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L328-L362
[ "def", "graph_from_adjacency_matrix", "(", "matrix", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "node_orig", "=", "1", "if", "directed", ":", "graph", "=", "Dot", "(", "graph_type", "=", "'digraph'", ")", "else", ":", "graph", ...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
graph_from_incidence_matrix
Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False.
pydot_ng/__init__.py
def graph_from_incidence_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
def graph_from_incidence_matrix(matrix, node_prefix='', directed=False): """Creates a basic graph out of an incidence matrix. The matrix has to be a list of rows of values representing an incidence matrix. The values can be anything: bool, int, float, as long as they can evaluate to True or False. ...
[ "Creates", "a", "basic", "graph", "out", "of", "an", "incidence", "matrix", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L365-L399
[ "def", "graph_from_incidence_matrix", "(", "matrix", ",", "node_prefix", "=", "''", ",", "directed", "=", "False", ")", ":", "if", "directed", ":", "graph", "=", "Dot", "(", "graph_type", "=", "'digraph'", ")", "else", ":", "graph", "=", "Dot", "(", "gra...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
__find_executables
Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None
pydot_ng/__init__.py
def __find_executables(path): """Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None """ success = False progs = { "do...
def __find_executables(path): """Used by find_graphviz path - single directory as a string If any of the executables are found, it will return a dictionary containing the program names as keys and their paths as values. Otherwise returns None """ success = False progs = { "do...
[ "Used", "by", "find_graphviz" ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L402-L454
[ "def", "__find_executables", "(", "path", ")", ":", "success", "=", "False", "progs", "=", "{", "\"dot\"", ":", "\"\"", ",", "\"twopi\"", ":", "\"\"", ",", "\"neato\"", ":", "\"\"", ",", "\"circo\"", ":", "\"\"", ",", "\"fdp\"", ":", "\"\"", ",", "\"sf...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
find_graphviz
Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the PATH environment variable. ...
pydot_ng/__init__.py
def find_graphviz(): """Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the...
def find_graphviz(): """Locate Graphviz's executables in the system. Tries three methods: First: Windows Registry (Windows only) This requires Mark Hammond's pywin32 is installed. Secondly: Search the path It will look for 'dot', 'twopi' and 'neato' in all the directories specified in the...
[ "Locate", "Graphviz", "s", "executables", "in", "the", "system", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L459-L599
[ "def", "find_graphviz", "(", ")", ":", "# Method 1 (Windows only)", "if", "os", ".", "sys", ".", "platform", "==", "'win32'", ":", "HKEY_LOCAL_MACHINE", "=", "0x80000002", "KEY_QUERY_VALUE", "=", "0x0001", "RegOpenKeyEx", "=", "None", "RegQueryValueEx", "=", "None...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
Graph.get_node_list
Get the list of Node instances. This method returns the list of Node instances composing the graph.
pydot_ng/__init__.py
def get_node_list(self): """Get the list of Node instances. This method returns the list of Node instances composing the graph. """ node_objs = list() for obj_dict_list in self.obj_dict['nodes'].values(): node_objs.extend([ Node(obj_dict=obj_...
def get_node_list(self): """Get the list of Node instances. This method returns the list of Node instances composing the graph. """ node_objs = list() for obj_dict_list in self.obj_dict['nodes'].values(): node_objs.extend([ Node(obj_dict=obj_...
[ "Get", "the", "list", "of", "Node", "instances", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1250-L1264
[ "def", "get_node_list", "(", "self", ")", ":", "node_objs", "=", "list", "(", ")", "for", "obj_dict_list", "in", "self", ".", "obj_dict", "[", "'nodes'", "]", ".", "values", "(", ")", ":", "node_objs", ".", "extend", "(", "[", "Node", "(", "obj_dict", ...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
Graph.del_edge
Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is given, only the edge in that position will be deleted. 'i...
pydot_ng/__init__.py
def del_edge(self, src_or_list, dst=None, index=None): """Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is ...
def del_edge(self, src_or_list, dst=None, index=None): """Delete an edge from the graph. Given an edge's (source, destination) node names all matching edges(s) will be deleted if 'index' is not specified or set to None. If there are several matching edges and 'index' is ...
[ "Delete", "an", "edge", "from", "the", "graph", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1287-L1326
[ "def", "del_edge", "(", "self", ",", "src_or_list", ",", "dst", "=", "None", ",", "index", "=", "None", ")", ":", "if", "isinstance", "(", "src_or_list", ",", "(", "list", ",", "tuple", ")", ")", ":", "if", "dst", "is", "not", "None", "and", "isins...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
Graph.get_edge_list
Get the list of Edge instances. This method returns the list of Edge instances composing the graph.
pydot_ng/__init__.py
def get_edge_list(self): """Get the list of Edge instances. This method returns the list of Edge instances composing the graph. """ edge_objs = list() for obj_dict_list in self.obj_dict['edges'].values(): edge_objs.extend([ Edge(obj_dict=obj_...
def get_edge_list(self): """Get the list of Edge instances. This method returns the list of Edge instances composing the graph. """ edge_objs = list() for obj_dict_list in self.obj_dict['edges'].values(): edge_objs.extend([ Edge(obj_dict=obj_...
[ "Get", "the", "list", "of", "Edge", "instances", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1366-L1380
[ "def", "get_edge_list", "(", "self", ")", ":", "edge_objs", "=", "list", "(", ")", "for", "obj_dict_list", "in", "self", ".", "obj_dict", "[", "'edges'", "]", ".", "values", "(", ")", ":", "edge_objs", ".", "extend", "(", "[", "Edge", "(", "obj_dict", ...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
Graph.to_string
Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from.
pydot_ng/__init__.py
def to_string(self): """Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from. """ graph = list() if self.obj_dict.get('strict', None) is not None: if self == self.get_parent_graph() and self.o...
def to_string(self): """Returns a string representation of the graph in dot language. It will return the graph and all its subelements in string from. """ graph = list() if self.obj_dict.get('strict', None) is not None: if self == self.get_parent_graph() and self.o...
[ "Returns", "a", "string", "representation", "of", "the", "graph", "in", "dot", "language", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1463-L1545
[ "def", "to_string", "(", "self", ")", ":", "graph", "=", "list", "(", ")", "if", "self", ".", "obj_dict", ".", "get", "(", "'strict'", ",", "None", ")", "is", "not", "None", ":", "if", "self", "==", "self", ".", "get_parent_graph", "(", ")", "and",...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
Dot.write
Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' can also be an open file-like object, such as a Stri...
pydot_ng/__init__.py
def write(self, path, prog=None, format='raw'): """Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' c...
def write(self, path, prog=None, format='raw'): """Write graph to file in selected format. Given a filename 'path' it will open/create and truncate such file and write on it a representation of the graph defined by the dot object and in the format specified by 'format'. 'path' c...
[ "Write", "graph", "to", "file", "in", "selected", "format", "." ]
pydot/pydot-ng
python
https://github.com/pydot/pydot-ng/blob/16f39800b6f5dc28d291a4d7763bbac04b9efe72/pydot_ng/__init__.py#L1728-L1784
[ "def", "write", "(", "self", ",", "path", ",", "prog", "=", "None", ",", "format", "=", "'raw'", ")", ":", "if", "prog", "is", "None", ":", "prog", "=", "self", ".", "prog", "fobj", ",", "close", "=", "get_fobj", "(", "path", ",", "'w+b'", ")", ...
16f39800b6f5dc28d291a4d7763bbac04b9efe72
train
DashboardView.get_crumbs
Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``.
src/suit_dashboard/views.py
def get_crumbs(self): """ Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``. """ crumbs = [] for cls in reversed(type(self)....
def get_crumbs(self): """ Get crumbs for navigation links. Returns: tuple: concatenated list of crumbs using these crumbs and the crumbs of the parent classes through ``__mro__``. """ crumbs = [] for cls in reversed(type(self)....
[ "Get", "crumbs", "for", "navigation", "links", "." ]
pawamoy/django-suit-dashboard
python
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/views.py#L30-L43
[ "def", "get_crumbs", "(", "self", ")", ":", "crumbs", "=", "[", "]", "for", "cls", "in", "reversed", "(", "type", "(", "self", ")", ".", "__mro__", "[", "1", ":", "]", ")", ":", "crumbs", ".", "extend", "(", "getattr", "(", "cls", ",", "'crumbs'"...
c008f55f4168f7af62ba31e8b621df214bea1e96
train
DashboardView.get
Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: response: render to response with context.
src/suit_dashboard/views.py
def get(self, request, *args, **kwargs): """ Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: ...
def get(self, request, *args, **kwargs): """ Django view get function. Add items of extra_context, crumbs and grid to context. Args: request (): Django's request object. *args (): request args. **kwargs (): request kwargs. Returns: ...
[ "Django", "view", "get", "function", "." ]
pawamoy/django-suit-dashboard
python
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/views.py#L45-L66
[ "def", "get", "(", "self", ",", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "context", "=", "self", ".", "get_context_data", "(", "*", "*", "kwargs", ")", "context", ".", "update", "(", "self", ".", "extra_context", ")", "context"...
c008f55f4168f7af62ba31e8b621df214bea1e96
train
realtime
Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be matched. time_interval (int): the interval of refreshment in milliseconds. Re...
src/suit_dashboard/widgets.py
def realtime(widget, url_name=None, url_regex=None, time_interval=None): """ Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be match...
def realtime(widget, url_name=None, url_regex=None, time_interval=None): """ Return a widget as real-time. Args: widget (Widget): the widget to register and return as real-time. url_name (str): the URL name to call to get updated content. url_regex (regex): the URL regex to be match...
[ "Return", "a", "widget", "as", "real", "-", "time", "." ]
pawamoy/django-suit-dashboard
python
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/widgets.py#L22-L97
[ "def", "realtime", "(", "widget", ",", "url_name", "=", "None", ",", "url_regex", "=", "None", ",", "time_interval", "=", "None", ")", ":", "if", "not", "hasattr", "(", "widget", ",", "'get_updated_content'", ")", ":", "raise", "AttributeError", "(", "'Wid...
c008f55f4168f7af62ba31e8b621df214bea1e96
train
get_realtime_urls
Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``.
src/suit_dashboard/urls.py
def get_realtime_urls(admin_view_func=lambda x: x): """ Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``. """ ...
def get_realtime_urls(admin_view_func=lambda x: x): """ Get the URL for real-time widgets. Args: admin_view_func (callable): an admin_view method from an AdminSite instance. By default: identity. Returns: list: the list of the real-time URLs as django's ``url()``. """ ...
[ "Get", "the", "URL", "for", "real", "-", "time", "widgets", "." ]
pawamoy/django-suit-dashboard
python
https://github.com/pawamoy/django-suit-dashboard/blob/c008f55f4168f7af62ba31e8b621df214bea1e96/src/suit_dashboard/urls.py#L10-L23
[ "def", "get_realtime_urls", "(", "admin_view_func", "=", "lambda", "x", ":", "x", ")", ":", "from", ".", "widgets", "import", "REALTIME_WIDGETS", "return", "[", "url", "(", "w", ".", "url_regex", ",", "admin_view_func", "(", "w", ".", "as_view", "(", ")", ...
c008f55f4168f7af62ba31e8b621df214bea1e96
train
setup_db
Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file.
beeswarm/server/db/database_setup.py
def setup_db(connection_string): """ Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file. """ global DB_Session, engine new_database = False if connectio...
def setup_db(connection_string): """ Sets up the database schema and adds defaults. :param connection_string: Database URL. e.g: sqlite:///filename.db This is usually taken from the config file. """ global DB_Session, engine new_database = False if connectio...
[ "Sets", "up", "the", "database", "schema", "and", "adds", "defaults", ".", ":", "param", "connection_string", ":", "Database", "URL", ".", "e", ".", "g", ":", "sqlite", ":", "///", "filename", ".", "db", "This", "is", "usually", "taken", "from", "the", ...
honeynet/beeswarm
python
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/server/db/database_setup.py#L37-L85
[ "def", "setup_db", "(", "connection_string", ")", ":", "global", "DB_Session", ",", "engine", "new_database", "=", "False", "if", "connection_string", "==", "'sqlite://'", "or", "not", "database_exists", "(", "connection_string", ")", ":", "new_database", "=", "Tr...
db51ea0bc29f631c3e3b5312b479ac9d5e31079a
train
SshWrapper.start_pty_request
Start a PTY - intended to run it a (green)thread.
beeswarm/drones/honeypot/capabilities/ssh.py
def start_pty_request(self, channel, term, modes): """Start a PTY - intended to run it a (green)thread.""" request = self.dummy_request() request._sock = channel request.modes = modes request.term = term request.username = self.username # This should block until ...
def start_pty_request(self, channel, term, modes): """Start a PTY - intended to run it a (green)thread.""" request = self.dummy_request() request._sock = channel request.modes = modes request.term = term request.username = self.username # This should block until ...
[ "Start", "a", "PTY", "-", "intended", "to", "run", "it", "a", "(", "green", ")", "thread", "." ]
honeynet/beeswarm
python
https://github.com/honeynet/beeswarm/blob/db51ea0bc29f631c3e3b5312b479ac9d5e31079a/beeswarm/drones/honeypot/capabilities/ssh.py#L118-L130
[ "def", "start_pty_request", "(", "self", ",", "channel", ",", "term", ",", "modes", ")", ":", "request", "=", "self", ".", "dummy_request", "(", ")", "request", ".", "_sock", "=", "channel", "request", ".", "modes", "=", "modes", "request", ".", "term", ...
db51ea0bc29f631c3e3b5312b479ac9d5e31079a