id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
sequence
docstring
stringlengths
3
17.3k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
87
242
251,800
xgvargas/smartside
smartside/signal.py
SmartSignal.auto_connect
def auto_connect(self): """ Make a connection between every member function to a GUI signal. Every member function whose name is in format: '_on_' + <widget_name> + '__' + <widget_signal_name> are connected to the signal of a GUI widget if it exists. Also, every function with format: '_when_' + <group_name> + '__' + <widget_signal_name> should also define a string named: '_' + <group_name> on class level _group1 = 'btn_add, btn_remove, `btn_l.+`, btn_test' _when_group1__clicked(self): who = self.sender() #use who to discover who called this callback inside the string you can use regex surronded by `` to select related widgets """ for o in dir(self): if o.startswith('_on_') and '__' in o: func = getattr(self, o) wgt, sig = o.split('__') if self._do_connection(wgt[4:], sig, func): print('Failed to connect', o) if o.startswith('_when_') and '__' in o: func = getattr(self, o) lst, sig = o.split('__') lst = self._process_list(lst[5:]) #5 to keep _ at beggining for w in lst: if self._do_connection(w, sig, func): print('Failed to connect', o)
python
def auto_connect(self): """ Make a connection between every member function to a GUI signal. Every member function whose name is in format: '_on_' + <widget_name> + '__' + <widget_signal_name> are connected to the signal of a GUI widget if it exists. Also, every function with format: '_when_' + <group_name> + '__' + <widget_signal_name> should also define a string named: '_' + <group_name> on class level _group1 = 'btn_add, btn_remove, `btn_l.+`, btn_test' _when_group1__clicked(self): who = self.sender() #use who to discover who called this callback inside the string you can use regex surronded by `` to select related widgets """ for o in dir(self): if o.startswith('_on_') and '__' in o: func = getattr(self, o) wgt, sig = o.split('__') if self._do_connection(wgt[4:], sig, func): print('Failed to connect', o) if o.startswith('_when_') and '__' in o: func = getattr(self, o) lst, sig = o.split('__') lst = self._process_list(lst[5:]) #5 to keep _ at beggining for w in lst: if self._do_connection(w, sig, func): print('Failed to connect', o)
[ "def", "auto_connect", "(", "self", ")", ":", "for", "o", "in", "dir", "(", "self", ")", ":", "if", "o", ".", "startswith", "(", "'_on_'", ")", "and", "'__'", "in", "o", ":", "func", "=", "getattr", "(", "self", ",", "o", ")", "wgt", ",", "sig", "=", "o", ".", "split", "(", "'__'", ")", "if", "self", ".", "_do_connection", "(", "wgt", "[", "4", ":", "]", ",", "sig", ",", "func", ")", ":", "print", "(", "'Failed to connect'", ",", "o", ")", "if", "o", ".", "startswith", "(", "'_when_'", ")", "and", "'__'", "in", "o", ":", "func", "=", "getattr", "(", "self", ",", "o", ")", "lst", ",", "sig", "=", "o", ".", "split", "(", "'__'", ")", "lst", "=", "self", ".", "_process_list", "(", "lst", "[", "5", ":", "]", ")", "#5 to keep _ at beggining", "for", "w", "in", "lst", ":", "if", "self", ".", "_do_connection", "(", "w", ",", "sig", ",", "func", ")", ":", "print", "(", "'Failed to connect'", ",", "o", ")" ]
Make a connection between every member function to a GUI signal. Every member function whose name is in format: '_on_' + <widget_name> + '__' + <widget_signal_name> are connected to the signal of a GUI widget if it exists. Also, every function with format: '_when_' + <group_name> + '__' + <widget_signal_name> should also define a string named: '_' + <group_name> on class level _group1 = 'btn_add, btn_remove, `btn_l.+`, btn_test' _when_group1__clicked(self): who = self.sender() #use who to discover who called this callback inside the string you can use regex surronded by `` to select related widgets
[ "Make", "a", "connection", "between", "every", "member", "function", "to", "a", "GUI", "signal", "." ]
c63acb7d628b161f438e877eca12d550647de34d
https://github.com/xgvargas/smartside/blob/c63acb7d628b161f438e877eca12d550647de34d/smartside/signal.py#L60-L96
251,801
xgvargas/smartside
smartside/signal.py
SmartSignal.print_signals_and_slots
def print_signals_and_slots(self): """ List all active Slots and Signal. Credits to: http://visitusers.org/index.php?title=PySide_Recipes#Debugging """ for i in xrange(self.metaObject().methodCount()): m = self.metaObject().method(i) if m.methodType() == QMetaMethod.MethodType.Signal: print("SIGNAL: sig=", m.signature(), "hooked to nslots=", self.receivers(SIGNAL(m.signature()))) elif m.methodType() == QMetaMethod.MethodType.Slot: print("SLOT: sig=", m.signature())
python
def print_signals_and_slots(self): """ List all active Slots and Signal. Credits to: http://visitusers.org/index.php?title=PySide_Recipes#Debugging """ for i in xrange(self.metaObject().methodCount()): m = self.metaObject().method(i) if m.methodType() == QMetaMethod.MethodType.Signal: print("SIGNAL: sig=", m.signature(), "hooked to nslots=", self.receivers(SIGNAL(m.signature()))) elif m.methodType() == QMetaMethod.MethodType.Slot: print("SLOT: sig=", m.signature())
[ "def", "print_signals_and_slots", "(", "self", ")", ":", "for", "i", "in", "xrange", "(", "self", ".", "metaObject", "(", ")", ".", "methodCount", "(", ")", ")", ":", "m", "=", "self", ".", "metaObject", "(", ")", ".", "method", "(", "i", ")", "if", "m", ".", "methodType", "(", ")", "==", "QMetaMethod", ".", "MethodType", ".", "Signal", ":", "print", "(", "\"SIGNAL: sig=\"", ",", "m", ".", "signature", "(", ")", ",", "\"hooked to nslots=\"", ",", "self", ".", "receivers", "(", "SIGNAL", "(", "m", ".", "signature", "(", ")", ")", ")", ")", "elif", "m", ".", "methodType", "(", ")", "==", "QMetaMethod", ".", "MethodType", ".", "Slot", ":", "print", "(", "\"SLOT: sig=\"", ",", "m", ".", "signature", "(", ")", ")" ]
List all active Slots and Signal. Credits to: http://visitusers.org/index.php?title=PySide_Recipes#Debugging
[ "List", "all", "active", "Slots", "and", "Signal", "." ]
c63acb7d628b161f438e877eca12d550647de34d
https://github.com/xgvargas/smartside/blob/c63acb7d628b161f438e877eca12d550647de34d/smartside/signal.py#L98-L109
251,802
xgvargas/smartside
smartside/signal.py
SmartSignal.print_all_signals
def print_all_signals(self): """ Prints out every signal available for this widget and childs. """ for o in dir(self): obj= getattr(self, o) #print o, type(obj) div = False for c in dir(obj): cobj = getattr(obj, c) if isinstance(cobj, Signal): print('def _on_{}__{}(self):'.format(o, c)) div = True if div: print('-'*30)
python
def print_all_signals(self): """ Prints out every signal available for this widget and childs. """ for o in dir(self): obj= getattr(self, o) #print o, type(obj) div = False for c in dir(obj): cobj = getattr(obj, c) if isinstance(cobj, Signal): print('def _on_{}__{}(self):'.format(o, c)) div = True if div: print('-'*30)
[ "def", "print_all_signals", "(", "self", ")", ":", "for", "o", "in", "dir", "(", "self", ")", ":", "obj", "=", "getattr", "(", "self", ",", "o", ")", "#print o, type(obj)", "div", "=", "False", "for", "c", "in", "dir", "(", "obj", ")", ":", "cobj", "=", "getattr", "(", "obj", ",", "c", ")", "if", "isinstance", "(", "cobj", ",", "Signal", ")", ":", "print", "(", "'def _on_{}__{}(self):'", ".", "format", "(", "o", ",", "c", ")", ")", "div", "=", "True", "if", "div", ":", "print", "(", "'-'", "*", "30", ")" ]
Prints out every signal available for this widget and childs.
[ "Prints", "out", "every", "signal", "available", "for", "this", "widget", "and", "childs", "." ]
c63acb7d628b161f438e877eca12d550647de34d
https://github.com/xgvargas/smartside/blob/c63acb7d628b161f438e877eca12d550647de34d/smartside/signal.py#L111-L125
251,803
misli/django-staticfiles-downloader
staticfiles_downloader/__init__.py
DownloaderFinder.find
def find(self, path, all=False): ''' Looks for files in the app directories. ''' found = os.path.join(settings.STATIC_ROOT, path) if all: return [found] else: return found
python
def find(self, path, all=False): ''' Looks for files in the app directories. ''' found = os.path.join(settings.STATIC_ROOT, path) if all: return [found] else: return found
[ "def", "find", "(", "self", ",", "path", ",", "all", "=", "False", ")", ":", "found", "=", "os", ".", "path", ".", "join", "(", "settings", ".", "STATIC_ROOT", ",", "path", ")", "if", "all", ":", "return", "[", "found", "]", "else", ":", "return", "found" ]
Looks for files in the app directories.
[ "Looks", "for", "files", "in", "the", "app", "directories", "." ]
f6440f6998d8e31fae986a25a03a8061d587af5a
https://github.com/misli/django-staticfiles-downloader/blob/f6440f6998d8e31fae986a25a03a8061d587af5a/staticfiles_downloader/__init__.py#L160-L168
251,804
daknuett/py_register_machine2
engine_tools/output/gpu_alike/rendering.py
Renderer.interrupt
def interrupt(self): """ Invoked on a write operation into the IR of the RendererDevice. """ if(self.device.read(9) & 0x01): self.handle_request() self.device.clear_IR()
python
def interrupt(self): """ Invoked on a write operation into the IR of the RendererDevice. """ if(self.device.read(9) & 0x01): self.handle_request() self.device.clear_IR()
[ "def", "interrupt", "(", "self", ")", ":", "if", "(", "self", ".", "device", ".", "read", "(", "9", ")", "&", "0x01", ")", ":", "self", ".", "handle_request", "(", ")", "self", ".", "device", ".", "clear_IR", "(", ")" ]
Invoked on a write operation into the IR of the RendererDevice.
[ "Invoked", "on", "a", "write", "operation", "into", "the", "IR", "of", "the", "RendererDevice", "." ]
599c53cd7576297d0d7a53344ed5d9aa98acc751
https://github.com/daknuett/py_register_machine2/blob/599c53cd7576297d0d7a53344ed5d9aa98acc751/engine_tools/output/gpu_alike/rendering.py#L65-L71
251,805
daknuett/py_register_machine2
engine_tools/output/gpu_alike/rendering.py
Renderer.draw_char_screen
def draw_char_screen(self): """ Draws the output buffered in the char_buffer. """ self.screen = Image.new("RGB", (self.height, self.width)) self.drawer = ImageDraw.Draw(self.screen) for sy, line in enumerate(self.char_buffer): for sx, tinfo in enumerate(line): self.drawer.text((sx * 6, sy * 9), tinfo[0], fill=tinfo[1:]) self.output_device.interrupt()
python
def draw_char_screen(self): """ Draws the output buffered in the char_buffer. """ self.screen = Image.new("RGB", (self.height, self.width)) self.drawer = ImageDraw.Draw(self.screen) for sy, line in enumerate(self.char_buffer): for sx, tinfo in enumerate(line): self.drawer.text((sx * 6, sy * 9), tinfo[0], fill=tinfo[1:]) self.output_device.interrupt()
[ "def", "draw_char_screen", "(", "self", ")", ":", "self", ".", "screen", "=", "Image", ".", "new", "(", "\"RGB\"", ",", "(", "self", ".", "height", ",", "self", ".", "width", ")", ")", "self", ".", "drawer", "=", "ImageDraw", ".", "Draw", "(", "self", ".", "screen", ")", "for", "sy", ",", "line", "in", "enumerate", "(", "self", ".", "char_buffer", ")", ":", "for", "sx", ",", "tinfo", "in", "enumerate", "(", "line", ")", ":", "self", ".", "drawer", ".", "text", "(", "(", "sx", "*", "6", ",", "sy", "*", "9", ")", ",", "tinfo", "[", "0", "]", ",", "fill", "=", "tinfo", "[", "1", ":", "]", ")", "self", ".", "output_device", ".", "interrupt", "(", ")" ]
Draws the output buffered in the char_buffer.
[ "Draws", "the", "output", "buffered", "in", "the", "char_buffer", "." ]
599c53cd7576297d0d7a53344ed5d9aa98acc751
https://github.com/daknuett/py_register_machine2/blob/599c53cd7576297d0d7a53344ed5d9aa98acc751/engine_tools/output/gpu_alike/rendering.py#L129-L139
251,806
anrosent/cli
cli.py
CLI.add_cli
def add_cli(self, prefix, other_cli): """Adds the functionality of the other CLI to this one, where all commands to the other CLI are prefixed by the given prefix plus a hyphen. e.g. To execute command `greet anson 5` on other cli given prefix cli2, you can execute the following with this CLI: cli2 greet anson 5 """ if prefix not in self.clis and prefix not in self.cmds: self.clis[prefix] = other_cli else: raise ValueError('Attempting to overwrite cmd or extern CLI: %s' % prefix)
python
def add_cli(self, prefix, other_cli): """Adds the functionality of the other CLI to this one, where all commands to the other CLI are prefixed by the given prefix plus a hyphen. e.g. To execute command `greet anson 5` on other cli given prefix cli2, you can execute the following with this CLI: cli2 greet anson 5 """ if prefix not in self.clis and prefix not in self.cmds: self.clis[prefix] = other_cli else: raise ValueError('Attempting to overwrite cmd or extern CLI: %s' % prefix)
[ "def", "add_cli", "(", "self", ",", "prefix", ",", "other_cli", ")", ":", "if", "prefix", "not", "in", "self", ".", "clis", "and", "prefix", "not", "in", "self", ".", "cmds", ":", "self", ".", "clis", "[", "prefix", "]", "=", "other_cli", "else", ":", "raise", "ValueError", "(", "'Attempting to overwrite cmd or extern CLI: %s'", "%", "prefix", ")" ]
Adds the functionality of the other CLI to this one, where all commands to the other CLI are prefixed by the given prefix plus a hyphen. e.g. To execute command `greet anson 5` on other cli given prefix cli2, you can execute the following with this CLI: cli2 greet anson 5
[ "Adds", "the", "functionality", "of", "the", "other", "CLI", "to", "this", "one", "where", "all", "commands", "to", "the", "other", "CLI", "are", "prefixed", "by", "the", "given", "prefix", "plus", "a", "hyphen", "." ]
8f89df4564c5124c95aaa288441f9d574dfa89a3
https://github.com/anrosent/cli/blob/8f89df4564c5124c95aaa288441f9d574dfa89a3/cli.py#L52-L64
251,807
anrosent/cli
cli.py
CLI._dispatch
def _dispatch(self, cmd, args): """Attempt to run the given command with the given arguments """ if cmd in self.clis: extern_cmd, args = args[0], args[1:] self.clis[cmd]._dispatch(extern_cmd, args) else: if cmd in self.cmds: callback, parser = self.cmds[cmd] try: p_args = parser.parse_args(args) except SystemExit: return callback(**dict(filter(lambda p:p[1] != None, p_args._get_kwargs()))) else: self._invalid_cmd(command=cmd)
python
def _dispatch(self, cmd, args): """Attempt to run the given command with the given arguments """ if cmd in self.clis: extern_cmd, args = args[0], args[1:] self.clis[cmd]._dispatch(extern_cmd, args) else: if cmd in self.cmds: callback, parser = self.cmds[cmd] try: p_args = parser.parse_args(args) except SystemExit: return callback(**dict(filter(lambda p:p[1] != None, p_args._get_kwargs()))) else: self._invalid_cmd(command=cmd)
[ "def", "_dispatch", "(", "self", ",", "cmd", ",", "args", ")", ":", "if", "cmd", "in", "self", ".", "clis", ":", "extern_cmd", ",", "args", "=", "args", "[", "0", "]", ",", "args", "[", "1", ":", "]", "self", ".", "clis", "[", "cmd", "]", ".", "_dispatch", "(", "extern_cmd", ",", "args", ")", "else", ":", "if", "cmd", "in", "self", ".", "cmds", ":", "callback", ",", "parser", "=", "self", ".", "cmds", "[", "cmd", "]", "try", ":", "p_args", "=", "parser", ".", "parse_args", "(", "args", ")", "except", "SystemExit", ":", "return", "callback", "(", "*", "*", "dict", "(", "filter", "(", "lambda", "p", ":", "p", "[", "1", "]", "!=", "None", ",", "p_args", ".", "_get_kwargs", "(", ")", ")", ")", ")", "else", ":", "self", ".", "_invalid_cmd", "(", "command", "=", "cmd", ")" ]
Attempt to run the given command with the given arguments
[ "Attempt", "to", "run", "the", "given", "command", "with", "the", "given", "arguments" ]
8f89df4564c5124c95aaa288441f9d574dfa89a3
https://github.com/anrosent/cli/blob/8f89df4564c5124c95aaa288441f9d574dfa89a3/cli.py#L69-L84
251,808
anrosent/cli
cli.py
CLI.exec_cmd
def exec_cmd(self, cmdstr): """Parse line from CLI read loop and execute provided command """ parts = cmdstr.split() if len(parts): cmd, args = parts[0], parts[1:] self._dispatch(cmd, args) else: pass
python
def exec_cmd(self, cmdstr): """Parse line from CLI read loop and execute provided command """ parts = cmdstr.split() if len(parts): cmd, args = parts[0], parts[1:] self._dispatch(cmd, args) else: pass
[ "def", "exec_cmd", "(", "self", ",", "cmdstr", ")", ":", "parts", "=", "cmdstr", ".", "split", "(", ")", "if", "len", "(", "parts", ")", ":", "cmd", ",", "args", "=", "parts", "[", "0", "]", ",", "parts", "[", "1", ":", "]", "self", ".", "_dispatch", "(", "cmd", ",", "args", ")", "else", ":", "pass" ]
Parse line from CLI read loop and execute provided command
[ "Parse", "line", "from", "CLI", "read", "loop", "and", "execute", "provided", "command" ]
8f89df4564c5124c95aaa288441f9d574dfa89a3
https://github.com/anrosent/cli/blob/8f89df4564c5124c95aaa288441f9d574dfa89a3/cli.py#L86-L94
251,809
anrosent/cli
cli.py
CLI.print_help
def print_help(self): """Prints usage of all registered commands, collapsing aliases into one record """ seen_aliases = set() print('-'*80) for cmd in sorted(self.cmds): if cmd not in self.builtin_cmds: if cmd not in seen_aliases: if cmd in self.aliases: seen_aliases.update(self.aliases[cmd]) disp = '/'.join(self.aliases[cmd]) else: disp = cmd _, parser = self.cmds[cmd] usage = parser.format_usage() print('%s: %s' % (disp, ' '.join(usage.split()[2:]))) print('External CLIs: %s' % ', '.join(sorted(self.clis)))
python
def print_help(self): """Prints usage of all registered commands, collapsing aliases into one record """ seen_aliases = set() print('-'*80) for cmd in sorted(self.cmds): if cmd not in self.builtin_cmds: if cmd not in seen_aliases: if cmd in self.aliases: seen_aliases.update(self.aliases[cmd]) disp = '/'.join(self.aliases[cmd]) else: disp = cmd _, parser = self.cmds[cmd] usage = parser.format_usage() print('%s: %s' % (disp, ' '.join(usage.split()[2:]))) print('External CLIs: %s' % ', '.join(sorted(self.clis)))
[ "def", "print_help", "(", "self", ")", ":", "seen_aliases", "=", "set", "(", ")", "print", "(", "'-'", "*", "80", ")", "for", "cmd", "in", "sorted", "(", "self", ".", "cmds", ")", ":", "if", "cmd", "not", "in", "self", ".", "builtin_cmds", ":", "if", "cmd", "not", "in", "seen_aliases", ":", "if", "cmd", "in", "self", ".", "aliases", ":", "seen_aliases", ".", "update", "(", "self", ".", "aliases", "[", "cmd", "]", ")", "disp", "=", "'/'", ".", "join", "(", "self", ".", "aliases", "[", "cmd", "]", ")", "else", ":", "disp", "=", "cmd", "_", ",", "parser", "=", "self", ".", "cmds", "[", "cmd", "]", "usage", "=", "parser", ".", "format_usage", "(", ")", "print", "(", "'%s: %s'", "%", "(", "disp", ",", "' '", ".", "join", "(", "usage", ".", "split", "(", ")", "[", "2", ":", "]", ")", ")", ")", "print", "(", "'External CLIs: %s'", "%", "', '", ".", "join", "(", "sorted", "(", "self", ".", "clis", ")", ")", ")" ]
Prints usage of all registered commands, collapsing aliases into one record
[ "Prints", "usage", "of", "all", "registered", "commands", "collapsing", "aliases", "into", "one", "record" ]
8f89df4564c5124c95aaa288441f9d574dfa89a3
https://github.com/anrosent/cli/blob/8f89df4564c5124c95aaa288441f9d574dfa89a3/cli.py#L99-L116
251,810
anrosent/cli
cli.py
CLI.run
def run(self, instream=sys.stdin): """Runs the CLI, reading from sys.stdin by default """ sys.stdout.write(self.prompt) sys.stdout.flush() while True: line = instream.readline() try: self.exec_cmd(line) except Exception as e: self.errfun(e) sys.stdout.write(self.prompt) sys.stdout.flush()
python
def run(self, instream=sys.stdin): """Runs the CLI, reading from sys.stdin by default """ sys.stdout.write(self.prompt) sys.stdout.flush() while True: line = instream.readline() try: self.exec_cmd(line) except Exception as e: self.errfun(e) sys.stdout.write(self.prompt) sys.stdout.flush()
[ "def", "run", "(", "self", ",", "instream", "=", "sys", ".", "stdin", ")", ":", "sys", ".", "stdout", ".", "write", "(", "self", ".", "prompt", ")", "sys", ".", "stdout", ".", "flush", "(", ")", "while", "True", ":", "line", "=", "instream", ".", "readline", "(", ")", "try", ":", "self", ".", "exec_cmd", "(", "line", ")", "except", "Exception", "as", "e", ":", "self", ".", "errfun", "(", "e", ")", "sys", ".", "stdout", ".", "write", "(", "self", ".", "prompt", ")", "sys", ".", "stdout", ".", "flush", "(", ")" ]
Runs the CLI, reading from sys.stdin by default
[ "Runs", "the", "CLI", "reading", "from", "sys", ".", "stdin", "by", "default" ]
8f89df4564c5124c95aaa288441f9d574dfa89a3
https://github.com/anrosent/cli/blob/8f89df4564c5124c95aaa288441f9d574dfa89a3/cli.py#L124-L137
251,811
jmvrbanac/PackMap
packmap/cli.py
PackMapClient.execute_finder
def execute_finder(self, manager, package_name): """ Execute finder script within the temporary venv context. """ filename = '{env_path}/results.json'.format(env_path=manager.env_path) subprocess.call([ manager.venv_python, self._finder_path, package_name, filename ]) # Load results into this context json_str = open(filename, 'r').read() return json.loads(json_str)
python
def execute_finder(self, manager, package_name): """ Execute finder script within the temporary venv context. """ filename = '{env_path}/results.json'.format(env_path=manager.env_path) subprocess.call([ manager.venv_python, self._finder_path, package_name, filename ]) # Load results into this context json_str = open(filename, 'r').read() return json.loads(json_str)
[ "def", "execute_finder", "(", "self", ",", "manager", ",", "package_name", ")", ":", "filename", "=", "'{env_path}/results.json'", ".", "format", "(", "env_path", "=", "manager", ".", "env_path", ")", "subprocess", ".", "call", "(", "[", "manager", ".", "venv_python", ",", "self", ".", "_finder_path", ",", "package_name", ",", "filename", "]", ")", "# Load results into this context", "json_str", "=", "open", "(", "filename", ",", "'r'", ")", ".", "read", "(", ")", "return", "json", ".", "loads", "(", "json_str", ")" ]
Execute finder script within the temporary venv context.
[ "Execute", "finder", "script", "within", "the", "temporary", "venv", "context", "." ]
e35d12d21ab109cae1175e0dc94d7f4855256b23
https://github.com/jmvrbanac/PackMap/blob/e35d12d21ab109cae1175e0dc94d7f4855256b23/packmap/cli.py#L65-L74
251,812
corydodt/Crosscap
crosscap/urltool.py
urltool
def urltool(classqname, filt, reverse): """ Dump all urls branching from a class as OpenAPI 3 documentation The class must be given as a FQPN which points to a Klein() instance. Apply optional [FILT] as a regular expression searching within urls. For example, to match all urls beginning with api, you might use '^/api' """ filt = re.compile(filt or '.*') rootCls = namedAny(classqname) rules = list(_iterClass(rootCls)) arr = [] for item in sorted(rules): if item.subKlein: continue matched = filt.search(item.rulePath) matched = not matched if reverse else matched if matched: arr.append(tuple(item.toOpenAPIPath())) openapi3 = openapi.OpenAPI() for pathPath, pathItem in arr: if pathPath in openapi3.paths: openapi3.paths[pathPath].merge(pathItem) else: openapi3.paths[pathPath] = pathItem print(yaml.dump(openapi3, default_flow_style=False))
python
def urltool(classqname, filt, reverse): """ Dump all urls branching from a class as OpenAPI 3 documentation The class must be given as a FQPN which points to a Klein() instance. Apply optional [FILT] as a regular expression searching within urls. For example, to match all urls beginning with api, you might use '^/api' """ filt = re.compile(filt or '.*') rootCls = namedAny(classqname) rules = list(_iterClass(rootCls)) arr = [] for item in sorted(rules): if item.subKlein: continue matched = filt.search(item.rulePath) matched = not matched if reverse else matched if matched: arr.append(tuple(item.toOpenAPIPath())) openapi3 = openapi.OpenAPI() for pathPath, pathItem in arr: if pathPath in openapi3.paths: openapi3.paths[pathPath].merge(pathItem) else: openapi3.paths[pathPath] = pathItem print(yaml.dump(openapi3, default_flow_style=False))
[ "def", "urltool", "(", "classqname", ",", "filt", ",", "reverse", ")", ":", "filt", "=", "re", ".", "compile", "(", "filt", "or", "'.*'", ")", "rootCls", "=", "namedAny", "(", "classqname", ")", "rules", "=", "list", "(", "_iterClass", "(", "rootCls", ")", ")", "arr", "=", "[", "]", "for", "item", "in", "sorted", "(", "rules", ")", ":", "if", "item", ".", "subKlein", ":", "continue", "matched", "=", "filt", ".", "search", "(", "item", ".", "rulePath", ")", "matched", "=", "not", "matched", "if", "reverse", "else", "matched", "if", "matched", ":", "arr", ".", "append", "(", "tuple", "(", "item", ".", "toOpenAPIPath", "(", ")", ")", ")", "openapi3", "=", "openapi", ".", "OpenAPI", "(", ")", "for", "pathPath", ",", "pathItem", "in", "arr", ":", "if", "pathPath", "in", "openapi3", ".", "paths", ":", "openapi3", ".", "paths", "[", "pathPath", "]", ".", "merge", "(", "pathItem", ")", "else", ":", "openapi3", ".", "paths", "[", "pathPath", "]", "=", "pathItem", "print", "(", "yaml", ".", "dump", "(", "openapi3", ",", "default_flow_style", "=", "False", ")", ")" ]
Dump all urls branching from a class as OpenAPI 3 documentation The class must be given as a FQPN which points to a Klein() instance. Apply optional [FILT] as a regular expression searching within urls. For example, to match all urls beginning with api, you might use '^/api'
[ "Dump", "all", "urls", "branching", "from", "a", "class", "as", "OpenAPI", "3", "documentation" ]
388a2ec36b8aa85e8f1ed692bb6e43474ba76c8e
https://github.com/corydodt/Crosscap/blob/388a2ec36b8aa85e8f1ed692bb6e43474ba76c8e/crosscap/urltool.py#L46-L75
251,813
corydodt/Crosscap
crosscap/urltool.py
literal_unicode_representer
def literal_unicode_representer(dumper, data): """ Use |- literal syntax for long strings """ if '\n' in data: return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|') else: return dumper.represent_scalar(u'tag:yaml.org,2002:str', data)
python
def literal_unicode_representer(dumper, data): """ Use |- literal syntax for long strings """ if '\n' in data: return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|') else: return dumper.represent_scalar(u'tag:yaml.org,2002:str', data)
[ "def", "literal_unicode_representer", "(", "dumper", ",", "data", ")", ":", "if", "'\\n'", "in", "data", ":", "return", "dumper", ".", "represent_scalar", "(", "u'tag:yaml.org,2002:str'", ",", "data", ",", "style", "=", "'|'", ")", "else", ":", "return", "dumper", ".", "represent_scalar", "(", "u'tag:yaml.org,2002:str'", ",", "data", ")" ]
Use |- literal syntax for long strings
[ "Use", "|", "-", "literal", "syntax", "for", "long", "strings" ]
388a2ec36b8aa85e8f1ed692bb6e43474ba76c8e
https://github.com/corydodt/Crosscap/blob/388a2ec36b8aa85e8f1ed692bb6e43474ba76c8e/crosscap/urltool.py#L191-L198
251,814
ramrod-project/database-brain
schema/brain/queries/decorators.py
wrap_job_cursor
def wrap_job_cursor(func_, *args, **kwargs): """ wraps a filter generator. Types should be appropriate before passed to rethinkdb somewhat specific to the _jobs_cursor function :param func_: <callable function> :param args: <must have at least 3 arguments> :param kwargs: :return: returned value from func_ """ assert isinstance(args[0], str) assert isinstance(args[1], (str, type(None))) assert isinstance(args[2], (str, type(None))) if args[2] and not args[1]: raise ValueError("Must specify location if using port.") return func_(*args, **kwargs)
python
def wrap_job_cursor(func_, *args, **kwargs): """ wraps a filter generator. Types should be appropriate before passed to rethinkdb somewhat specific to the _jobs_cursor function :param func_: <callable function> :param args: <must have at least 3 arguments> :param kwargs: :return: returned value from func_ """ assert isinstance(args[0], str) assert isinstance(args[1], (str, type(None))) assert isinstance(args[2], (str, type(None))) if args[2] and not args[1]: raise ValueError("Must specify location if using port.") return func_(*args, **kwargs)
[ "def", "wrap_job_cursor", "(", "func_", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "assert", "isinstance", "(", "args", "[", "0", "]", ",", "str", ")", "assert", "isinstance", "(", "args", "[", "1", "]", ",", "(", "str", ",", "type", "(", "None", ")", ")", ")", "assert", "isinstance", "(", "args", "[", "2", "]", ",", "(", "str", ",", "type", "(", "None", ")", ")", ")", "if", "args", "[", "2", "]", "and", "not", "args", "[", "1", "]", ":", "raise", "ValueError", "(", "\"Must specify location if using port.\"", ")", "return", "func_", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
wraps a filter generator. Types should be appropriate before passed to rethinkdb somewhat specific to the _jobs_cursor function :param func_: <callable function> :param args: <must have at least 3 arguments> :param kwargs: :return: returned value from func_
[ "wraps", "a", "filter", "generator", ".", "Types", "should", "be", "appropriate", "before", "passed", "to", "rethinkdb" ]
b024cb44f34cabb9d80af38271ddb65c25767083
https://github.com/ramrod-project/database-brain/blob/b024cb44f34cabb9d80af38271ddb65c25767083/schema/brain/queries/decorators.py#L15-L32
251,815
obiwanus/django-qurl
qurl/__init__.py
qurl
def qurl(url, add=None, exclude=None, remove=None): """ Returns the url with changed parameters """ urlp = list(urlparse(url)) qp = parse_qsl(urlp[4]) # Add parameters add = add if add else {} for name, value in add.items(): if isinstance(value, (list, tuple)): # Append mode value = [smart_str(v) for v in value] qp = [p for p in qp if p[0] != name or p[1] not in value] qp.extend([(name, smart_str(val)) for val in value]) else: # Set mode qp = [p for p in qp if p[0] != name] qp.append((name, smart_str(value))) # Exclude parameters exclude = exclude if exclude else {} for name, value in exclude.items(): if not isinstance(value, (list, tuple)): value = [value] value = [smart_str(v) for v in value] qp = [p for p in qp if p[0] != name or p[1] not in value] # Remove parameters remove = remove if remove else [] for name in remove: qp = [p for p in qp if p[0] != name] urlp[4] = urlencode(qp, True) return urlunparse(urlp)
python
def qurl(url, add=None, exclude=None, remove=None): """ Returns the url with changed parameters """ urlp = list(urlparse(url)) qp = parse_qsl(urlp[4]) # Add parameters add = add if add else {} for name, value in add.items(): if isinstance(value, (list, tuple)): # Append mode value = [smart_str(v) for v in value] qp = [p for p in qp if p[0] != name or p[1] not in value] qp.extend([(name, smart_str(val)) for val in value]) else: # Set mode qp = [p for p in qp if p[0] != name] qp.append((name, smart_str(value))) # Exclude parameters exclude = exclude if exclude else {} for name, value in exclude.items(): if not isinstance(value, (list, tuple)): value = [value] value = [smart_str(v) for v in value] qp = [p for p in qp if p[0] != name or p[1] not in value] # Remove parameters remove = remove if remove else [] for name in remove: qp = [p for p in qp if p[0] != name] urlp[4] = urlencode(qp, True) return urlunparse(urlp)
[ "def", "qurl", "(", "url", ",", "add", "=", "None", ",", "exclude", "=", "None", ",", "remove", "=", "None", ")", ":", "urlp", "=", "list", "(", "urlparse", "(", "url", ")", ")", "qp", "=", "parse_qsl", "(", "urlp", "[", "4", "]", ")", "# Add parameters", "add", "=", "add", "if", "add", "else", "{", "}", "for", "name", ",", "value", "in", "add", ".", "items", "(", ")", ":", "if", "isinstance", "(", "value", ",", "(", "list", ",", "tuple", ")", ")", ":", "# Append mode", "value", "=", "[", "smart_str", "(", "v", ")", "for", "v", "in", "value", "]", "qp", "=", "[", "p", "for", "p", "in", "qp", "if", "p", "[", "0", "]", "!=", "name", "or", "p", "[", "1", "]", "not", "in", "value", "]", "qp", ".", "extend", "(", "[", "(", "name", ",", "smart_str", "(", "val", ")", ")", "for", "val", "in", "value", "]", ")", "else", ":", "# Set mode", "qp", "=", "[", "p", "for", "p", "in", "qp", "if", "p", "[", "0", "]", "!=", "name", "]", "qp", ".", "append", "(", "(", "name", ",", "smart_str", "(", "value", ")", ")", ")", "# Exclude parameters", "exclude", "=", "exclude", "if", "exclude", "else", "{", "}", "for", "name", ",", "value", "in", "exclude", ".", "items", "(", ")", ":", "if", "not", "isinstance", "(", "value", ",", "(", "list", ",", "tuple", ")", ")", ":", "value", "=", "[", "value", "]", "value", "=", "[", "smart_str", "(", "v", ")", "for", "v", "in", "value", "]", "qp", "=", "[", "p", "for", "p", "in", "qp", "if", "p", "[", "0", "]", "!=", "name", "or", "p", "[", "1", "]", "not", "in", "value", "]", "# Remove parameters", "remove", "=", "remove", "if", "remove", "else", "[", "]", "for", "name", "in", "remove", ":", "qp", "=", "[", "p", "for", "p", "in", "qp", "if", "p", "[", "0", "]", "!=", "name", "]", "urlp", "[", "4", "]", "=", "urlencode", "(", "qp", ",", "True", ")", "return", "urlunparse", "(", "urlp", ")" ]
Returns the url with changed parameters
[ "Returns", "the", "url", "with", "changed", "parameters" ]
745992fc4241fd7a2f034c202f6fe05da7437683
https://github.com/obiwanus/django-qurl/blob/745992fc4241fd7a2f034c202f6fe05da7437683/qurl/__init__.py#L11-L45
251,816
pjuren/pyokit
src/pyokit/datastruct/read.py
clip_adaptor
def clip_adaptor(read, adaptor): """ Clip an adaptor sequence from this sequence. We assume it's in the 3' end. This is basically a convenience wrapper for clipThreePrime. It requires 8 out of 10 of the first bases in the adaptor sequence to match for clipping to occur. :param adaptor: sequence to look for. We only use the first 10 bases; must be a full Sequence object, not just a string. """ missmatches = 2 adaptor = adaptor.truncate(10) read.clip_end(adaptor, len(adaptor) - missmatches)
python
def clip_adaptor(read, adaptor): """ Clip an adaptor sequence from this sequence. We assume it's in the 3' end. This is basically a convenience wrapper for clipThreePrime. It requires 8 out of 10 of the first bases in the adaptor sequence to match for clipping to occur. :param adaptor: sequence to look for. We only use the first 10 bases; must be a full Sequence object, not just a string. """ missmatches = 2 adaptor = adaptor.truncate(10) read.clip_end(adaptor, len(adaptor) - missmatches)
[ "def", "clip_adaptor", "(", "read", ",", "adaptor", ")", ":", "missmatches", "=", "2", "adaptor", "=", "adaptor", ".", "truncate", "(", "10", ")", "read", ".", "clip_end", "(", "adaptor", ",", "len", "(", "adaptor", ")", "-", "missmatches", ")" ]
Clip an adaptor sequence from this sequence. We assume it's in the 3' end. This is basically a convenience wrapper for clipThreePrime. It requires 8 out of 10 of the first bases in the adaptor sequence to match for clipping to occur. :param adaptor: sequence to look for. We only use the first 10 bases; must be a full Sequence object, not just a string.
[ "Clip", "an", "adaptor", "sequence", "from", "this", "sequence", ".", "We", "assume", "it", "s", "in", "the", "3", "end", ".", "This", "is", "basically", "a", "convenience", "wrapper", "for", "clipThreePrime", ".", "It", "requires", "8", "out", "of", "10", "of", "the", "first", "bases", "in", "the", "adaptor", "sequence", "to", "match", "for", "clipping", "to", "occur", "." ]
fddae123b5d817daa39496183f19c000d9c3791f
https://github.com/pjuren/pyokit/blob/fddae123b5d817daa39496183f19c000d9c3791f/src/pyokit/datastruct/read.py#L276-L288
251,817
pjuren/pyokit
src/pyokit/datastruct/read.py
contains_adaptor
def contains_adaptor(read, adaptor): """ Check whether this sequence contains adaptor contamination. If it exists, we assume it's in the 3' end. This function requires 8 out of 10 of the first bases in the adaptor sequence to match for an occurrence to be reported. :param adaptor: sequence to look for. We only use first 10 bases; must be a full Sequence object, not just string. :return: True if there is an occurence of <adaptor>, False otherwise """ origSeq = read.sequenceData clip_adaptor(read, adaptor) res = False if read.sequenceData != origSeq: res = True read.sequenceData = origSeq return res
python
def contains_adaptor(read, adaptor): """ Check whether this sequence contains adaptor contamination. If it exists, we assume it's in the 3' end. This function requires 8 out of 10 of the first bases in the adaptor sequence to match for an occurrence to be reported. :param adaptor: sequence to look for. We only use first 10 bases; must be a full Sequence object, not just string. :return: True if there is an occurence of <adaptor>, False otherwise """ origSeq = read.sequenceData clip_adaptor(read, adaptor) res = False if read.sequenceData != origSeq: res = True read.sequenceData = origSeq return res
[ "def", "contains_adaptor", "(", "read", ",", "adaptor", ")", ":", "origSeq", "=", "read", ".", "sequenceData", "clip_adaptor", "(", "read", ",", "adaptor", ")", "res", "=", "False", "if", "read", ".", "sequenceData", "!=", "origSeq", ":", "res", "=", "True", "read", ".", "sequenceData", "=", "origSeq", "return", "res" ]
Check whether this sequence contains adaptor contamination. If it exists, we assume it's in the 3' end. This function requires 8 out of 10 of the first bases in the adaptor sequence to match for an occurrence to be reported. :param adaptor: sequence to look for. We only use first 10 bases; must be a full Sequence object, not just string. :return: True if there is an occurence of <adaptor>, False otherwise
[ "Check", "whether", "this", "sequence", "contains", "adaptor", "contamination", ".", "If", "it", "exists", "we", "assume", "it", "s", "in", "the", "3", "end", ".", "This", "function", "requires", "8", "out", "of", "10", "of", "the", "first", "bases", "in", "the", "adaptor", "sequence", "to", "match", "for", "an", "occurrence", "to", "be", "reported", "." ]
fddae123b5d817daa39496183f19c000d9c3791f
https://github.com/pjuren/pyokit/blob/fddae123b5d817daa39496183f19c000d9c3791f/src/pyokit/datastruct/read.py#L291-L308
251,818
pjuren/pyokit
src/pyokit/datastruct/read.py
NGSRead.reverse_complement
def reverse_complement(self, is_RNA=None): """ Reverse complement this read in-place. """ Sequence.reverseComplement(self, is_RNA) self.seq_qual = self.seq_qual[::-1]
python
def reverse_complement(self, is_RNA=None): """ Reverse complement this read in-place. """ Sequence.reverseComplement(self, is_RNA) self.seq_qual = self.seq_qual[::-1]
[ "def", "reverse_complement", "(", "self", ",", "is_RNA", "=", "None", ")", ":", "Sequence", ".", "reverseComplement", "(", "self", ",", "is_RNA", ")", "self", ".", "seq_qual", "=", "self", ".", "seq_qual", "[", ":", ":", "-", "1", "]" ]
Reverse complement this read in-place.
[ "Reverse", "complement", "this", "read", "in", "-", "place", "." ]
fddae123b5d817daa39496183f19c000d9c3791f
https://github.com/pjuren/pyokit/blob/fddae123b5d817daa39496183f19c000d9c3791f/src/pyokit/datastruct/read.py#L192-L197
251,819
pjuren/pyokit
src/pyokit/datastruct/read.py
NGSRead.split
def split(self, point=None): """ Split this read into two halves. Original sequence is left unaltered. The name of the resultant reads will have '.1' and '.2' appended to the name from the original read. :param point: the point (index, starting from 0) at which to split this read -- everything before this index will be placed into the first sequence, and everything at or after this index will be placed in the second resultant sequence. If None (the default), then we split in the middle; if the original size is not a multiple of 2, the extra nucleotide is placed into the second resultant sequence. Must be >= 0 and <= length of sequence. :return: two NGSRead objects which correspond to the split of this sequence. """ if point is None: point = len(self) / 2 if point < 0: raise NGSReadError("Cannot split read at index less than 0 " + "(index provided: " + str(point) + ")") if point > len(self): raise NGSReadError("Cannot split read at index greater than read " + "length (index provided: " + str(point) + ")") r1 = NGSRead(self.sequenceData[:point], self.name + ".1", self.seq_qual[:point]) r2 = NGSRead(self.sequenceData[point:], self.name + ".2", self.seq_qual[point:]) return r1, r2
python
def split(self, point=None): """ Split this read into two halves. Original sequence is left unaltered. The name of the resultant reads will have '.1' and '.2' appended to the name from the original read. :param point: the point (index, starting from 0) at which to split this read -- everything before this index will be placed into the first sequence, and everything at or after this index will be placed in the second resultant sequence. If None (the default), then we split in the middle; if the original size is not a multiple of 2, the extra nucleotide is placed into the second resultant sequence. Must be >= 0 and <= length of sequence. :return: two NGSRead objects which correspond to the split of this sequence. """ if point is None: point = len(self) / 2 if point < 0: raise NGSReadError("Cannot split read at index less than 0 " + "(index provided: " + str(point) + ")") if point > len(self): raise NGSReadError("Cannot split read at index greater than read " + "length (index provided: " + str(point) + ")") r1 = NGSRead(self.sequenceData[:point], self.name + ".1", self.seq_qual[:point]) r2 = NGSRead(self.sequenceData[point:], self.name + ".2", self.seq_qual[point:]) return r1, r2
[ "def", "split", "(", "self", ",", "point", "=", "None", ")", ":", "if", "point", "is", "None", ":", "point", "=", "len", "(", "self", ")", "/", "2", "if", "point", "<", "0", ":", "raise", "NGSReadError", "(", "\"Cannot split read at index less than 0 \"", "+", "\"(index provided: \"", "+", "str", "(", "point", ")", "+", "\")\"", ")", "if", "point", ">", "len", "(", "self", ")", ":", "raise", "NGSReadError", "(", "\"Cannot split read at index greater than read \"", "+", "\"length (index provided: \"", "+", "str", "(", "point", ")", "+", "\")\"", ")", "r1", "=", "NGSRead", "(", "self", ".", "sequenceData", "[", ":", "point", "]", ",", "self", ".", "name", "+", "\".1\"", ",", "self", ".", "seq_qual", "[", ":", "point", "]", ")", "r2", "=", "NGSRead", "(", "self", ".", "sequenceData", "[", "point", ":", "]", ",", "self", ".", "name", "+", "\".2\"", ",", "self", ".", "seq_qual", "[", "point", ":", "]", ")", "return", "r1", ",", "r2" ]
Split this read into two halves. Original sequence is left unaltered. The name of the resultant reads will have '.1' and '.2' appended to the name from the original read. :param point: the point (index, starting from 0) at which to split this read -- everything before this index will be placed into the first sequence, and everything at or after this index will be placed in the second resultant sequence. If None (the default), then we split in the middle; if the original size is not a multiple of 2, the extra nucleotide is placed into the second resultant sequence. Must be >= 0 and <= length of sequence. :return: two NGSRead objects which correspond to the split of this sequence.
[ "Split", "this", "read", "into", "two", "halves", ".", "Original", "sequence", "is", "left", "unaltered", "." ]
fddae123b5d817daa39496183f19c000d9c3791f
https://github.com/pjuren/pyokit/blob/fddae123b5d817daa39496183f19c000d9c3791f/src/pyokit/datastruct/read.py#L199-L230