repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
bjodah/pyneqsys
examples/bi_dimensional.py
main
def main(guess_a=1., guess_b=0., power=3, savetxt='None', verbose=False): """ Example demonstrating how to solve a system of non-linear equations defined as SymPy expressions. The example shows how a non-linear problem can be given a command-line interface which may be preferred by end-users who are no...
python
def main(guess_a=1., guess_b=0., power=3, savetxt='None', verbose=False): """ Example demonstrating how to solve a system of non-linear equations defined as SymPy expressions. The example shows how a non-linear problem can be given a command-line interface which may be preferred by end-users who are no...
[ "def", "main", "(", "guess_a", "=", "1.", ",", "guess_b", "=", "0.", ",", "power", "=", "3", ",", "savetxt", "=", "'None'", ",", "verbose", "=", "False", ")", ":", "x", ",", "sol", "=", "solve", "(", "guess_a", ",", "guess_b", ",", "power", ")", ...
Example demonstrating how to solve a system of non-linear equations defined as SymPy expressions. The example shows how a non-linear problem can be given a command-line interface which may be preferred by end-users who are not familiar with Python.
[ "Example", "demonstrating", "how", "to", "solve", "a", "system", "of", "non", "-", "linear", "equations", "defined", "as", "SymPy", "expressions", "." ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/examples/bi_dimensional.py#L29-L44
bjodah/pyneqsys
pyneqsys/plotting.py
plot_series
def plot_series(xres, varied_data, indices=None, info=None, fail_vline=None, plot_kwargs_cb=None, ls=('-', '--', ':', '-.'), c=('k', 'r', 'g', 'b', 'c', 'm', 'y'), labels=None, ax=None, names=None, latex_names=None): """ Plot the values of the solution...
python
def plot_series(xres, varied_data, indices=None, info=None, fail_vline=None, plot_kwargs_cb=None, ls=('-', '--', ':', '-.'), c=('k', 'r', 'g', 'b', 'c', 'm', 'y'), labels=None, ax=None, names=None, latex_names=None): """ Plot the values of the solution...
[ "def", "plot_series", "(", "xres", ",", "varied_data", ",", "indices", "=", "None", ",", "info", "=", "None", ",", "fail_vline", "=", "None", ",", "plot_kwargs_cb", "=", "None", ",", "ls", "=", "(", "'-'", ",", "'--'", ",", "':'", ",", "'-.'", ")", ...
Plot the values of the solution vector vs the varied parameter. Parameters ---------- xres : array Solution vector of shape ``(varied_data.size, x0.size)``. varied_data : array Numerical values of the varied parameter. indices : iterable of integers, optional Indices of vari...
[ "Plot", "the", "values", "of", "the", "solution", "vector", "vs", "the", "varied", "parameter", "." ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/plotting.py#L4-L68
bjodah/pyneqsys
pyneqsys/plotting.py
mpl_outside_legend
def mpl_outside_legend(ax, **kwargs): """ Places a legend box outside a matplotlib Axes instance. """ box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.75, box.height]) # Put a legend to the right of the current axis ax.legend(loc='upper left', bbox_to_anchor=(1, 1), **kwargs)
python
def mpl_outside_legend(ax, **kwargs): """ Places a legend box outside a matplotlib Axes instance. """ box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.75, box.height]) # Put a legend to the right of the current axis ax.legend(loc='upper left', bbox_to_anchor=(1, 1), **kwargs)
[ "def", "mpl_outside_legend", "(", "ax", ",", "*", "*", "kwargs", ")", ":", "box", "=", "ax", ".", "get_position", "(", ")", "ax", ".", "set_position", "(", "[", "box", ".", "x0", ",", "box", ".", "y0", ",", "box", ".", "width", "*", "0.75", ",", ...
Places a legend box outside a matplotlib Axes instance.
[ "Places", "a", "legend", "box", "outside", "a", "matplotlib", "Axes", "instance", "." ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/plotting.py#L71-L76
bjodah/pyneqsys
pyneqsys/symbolic.py
linear_rref
def linear_rref(A, b, Matrix=None, S=None): """ Transform a linear system to reduced row-echelon form Transforms both the matrix and right-hand side of a linear system of equations to reduced row echelon form Parameters ---------- A : Matrix-like Iterable of rows. b : iterable ...
python
def linear_rref(A, b, Matrix=None, S=None): """ Transform a linear system to reduced row-echelon form Transforms both the matrix and right-hand side of a linear system of equations to reduced row echelon form Parameters ---------- A : Matrix-like Iterable of rows. b : iterable ...
[ "def", "linear_rref", "(", "A", ",", "b", ",", "Matrix", "=", "None", ",", "S", "=", "None", ")", ":", "if", "Matrix", "is", "None", ":", "from", "sympy", "import", "Matrix", "if", "S", "is", "None", ":", "from", "sympy", "import", "S", "mat_rows",...
Transform a linear system to reduced row-echelon form Transforms both the matrix and right-hand side of a linear system of equations to reduced row echelon form Parameters ---------- A : Matrix-like Iterable of rows. b : iterable Returns ------- A', b' - transformed versio...
[ "Transform", "a", "linear", "system", "to", "reduced", "row", "-", "echelon", "form" ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/symbolic.py#L284-L309
bjodah/pyneqsys
pyneqsys/symbolic.py
linear_exprs
def linear_exprs(A, x, b=None, rref=False, Matrix=None): """ Returns Ax - b Parameters ---------- A : matrix_like of numbers Of shape (len(b), len(x)). x : iterable of symbols b : array_like of numbers (default: None) When ``None``, assume zeros of length ``len(x)``. Matrix ...
python
def linear_exprs(A, x, b=None, rref=False, Matrix=None): """ Returns Ax - b Parameters ---------- A : matrix_like of numbers Of shape (len(b), len(x)). x : iterable of symbols b : array_like of numbers (default: None) When ``None``, assume zeros of length ``len(x)``. Matrix ...
[ "def", "linear_exprs", "(", "A", ",", "x", ",", "b", "=", "None", ",", "rref", "=", "False", ",", "Matrix", "=", "None", ")", ":", "if", "b", "is", "None", ":", "b", "=", "[", "0", "]", "*", "len", "(", "x", ")", "if", "rref", ":", "rA", ...
Returns Ax - b Parameters ---------- A : matrix_like of numbers Of shape (len(b), len(x)). x : iterable of symbols b : array_like of numbers (default: None) When ``None``, assume zeros of length ``len(x)``. Matrix : class When ``rref == True``: A matrix class which suppo...
[ "Returns", "Ax", "-", "b" ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/symbolic.py#L312-L342
bjodah/pyneqsys
pyneqsys/symbolic.py
SymbolicSys.from_callback
def from_callback(cls, cb, nx=None, nparams=None, **kwargs): """ Generate a SymbolicSys instance from a callback. Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. nx : int Number of unknowns, when not g...
python
def from_callback(cls, cb, nx=None, nparams=None, **kwargs): """ Generate a SymbolicSys instance from a callback. Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. nx : int Number of unknowns, when not g...
[ "def", "from_callback", "(", "cls", ",", "cb", ",", "nx", "=", "None", ",", "nparams", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "kwargs", ".", "get", "(", "'x_by_name'", ",", "False", ")", ":", "if", "'names'", "not", "in", "kwargs", ...
Generate a SymbolicSys instance from a callback. Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. nx : int Number of unknowns, when not given it is deduced from ``kwargs['names']``. nparams : int ...
[ "Generate", "a", "SymbolicSys", "instance", "from", "a", "callback", "." ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/symbolic.py#L88-L141
bjodah/pyneqsys
pyneqsys/symbolic.py
SymbolicSys.get_jac
def get_jac(self): """ Return the jacobian of the expressions """ if self._jac is True: if self.band is None: f = self.be.Matrix(self.nf, 1, self.exprs) _x = self.be.Matrix(self.nx, 1, self.x) return f.jacobian(_x) else: ...
python
def get_jac(self): """ Return the jacobian of the expressions """ if self._jac is True: if self.band is None: f = self.be.Matrix(self.nf, 1, self.exprs) _x = self.be.Matrix(self.nx, 1, self.x) return f.jacobian(_x) else: ...
[ "def", "get_jac", "(", "self", ")", ":", "if", "self", ".", "_jac", "is", "True", ":", "if", "self", ".", "band", "is", "None", ":", "f", "=", "self", ".", "be", ".", "Matrix", "(", "self", ".", "nf", ",", "1", ",", "self", ".", "exprs", ")",...
Return the jacobian of the expressions
[ "Return", "the", "jacobian", "of", "the", "expressions" ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/symbolic.py#L143-L157
bjodah/pyneqsys
pyneqsys/symbolic.py
TransformedSys.from_callback
def from_callback(cls, cb, transf_cbs, nx, nparams=0, pre_adj=None, **kwargs): """ Generate a TransformedSys instance from a callback Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. The c...
python
def from_callback(cls, cb, transf_cbs, nx, nparams=0, pre_adj=None, **kwargs): """ Generate a TransformedSys instance from a callback Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. The c...
[ "def", "from_callback", "(", "cls", ",", "cb", ",", "transf_cbs", ",", "nx", ",", "nparams", "=", "0", ",", "pre_adj", "=", "None", ",", "*", "*", "kwargs", ")", ":", "be", "=", "Backend", "(", "kwargs", ".", "pop", "(", "'backend'", ",", "None", ...
Generate a TransformedSys instance from a callback Parameters ---------- cb : callable Should have the signature ``cb(x, p, backend) -> list of exprs``. The callback ``cb`` should return *untransformed* expressions. transf_cbs : pair or iterable of pairs of calla...
[ "Generate", "a", "TransformedSys", "instance", "from", "a", "callback" ]
train
https://github.com/bjodah/pyneqsys/blob/1c8f2fe1ab2b6cc6cb55b7a1328aca2e3a3c5c77/pyneqsys/symbolic.py#L232-L281
EmbodiedCognition/py-c3d
c3d.py
Header.write
def write(self, handle): '''Write binary header data to a file handle. This method writes exactly 512 bytes to the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and then 512 by...
python
def write(self, handle): '''Write binary header data to a file handle. This method writes exactly 512 bytes to the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and then 512 by...
[ "def", "write", "(", "self", ",", "handle", ")", ":", "handle", ".", "seek", "(", "0", ")", "handle", ".", "write", "(", "struct", ".", "pack", "(", "self", ".", "BINARY_FORMAT", ",", "self", ".", "parameter_block", ",", "0x50", ",", "self", ".", "...
Write binary header data to a file handle. This method writes exactly 512 bytes to the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and then 512 bytes will be written to d...
[ "Write", "binary", "header", "data", "to", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L89-L118
EmbodiedCognition/py-c3d
c3d.py
Header.read
def read(self, handle): '''Read and parse binary header data from a file handle. This method reads exactly 512 bytes from the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and ...
python
def read(self, handle): '''Read and parse binary header data from a file handle. This method reads exactly 512 bytes from the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and ...
[ "def", "read", "(", "self", ",", "handle", ")", ":", "handle", ".", "seek", "(", "0", ")", "(", "self", ".", "parameter_block", ",", "magic", ",", "self", ".", "point_count", ",", "self", ".", "analog_count", ",", "self", ".", "first_frame", ",", "se...
Read and parse binary header data from a file handle. This method reads exactly 512 bytes from the beginning of the given file handle. Parameters ---------- handle : file handle The given handle will be reset to 0 using `seek` and then 512 bytes will be ...
[ "Read", "and", "parse", "binary", "header", "data", "from", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L136-L171
EmbodiedCognition/py-c3d
c3d.py
Param.binary_size
def binary_size(self): '''Return the number of bytes needed to store this parameter.''' return ( 1 + # group_id 2 + # next offset marker 1 + len(self.name.encode('utf-8')) + # size of name and name bytes 1 + # data size 1 + len(self.dimensions)...
python
def binary_size(self): '''Return the number of bytes needed to store this parameter.''' return ( 1 + # group_id 2 + # next offset marker 1 + len(self.name.encode('utf-8')) + # size of name and name bytes 1 + # data size 1 + len(self.dimensions)...
[ "def", "binary_size", "(", "self", ")", ":", "return", "(", "1", "+", "# group_id", "2", "+", "# next offset marker", "1", "+", "len", "(", "self", ".", "name", ".", "encode", "(", "'utf-8'", ")", ")", "+", "# size of name and name bytes", "1", "+", "# d...
Return the number of bytes needed to store this parameter.
[ "Return", "the", "number", "of", "bytes", "needed", "to", "store", "this", "parameter", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L227-L237
EmbodiedCognition/py-c3d
c3d.py
Param.write
def write(self, group_id, handle): '''Write binary data for this parameter to a file handle. Parameters ---------- group_id : int The numerical ID of the group that holds this parameter. handle : file handle An open, writable, binary file handle. ...
python
def write(self, group_id, handle): '''Write binary data for this parameter to a file handle. Parameters ---------- group_id : int The numerical ID of the group that holds this parameter. handle : file handle An open, writable, binary file handle. ...
[ "def", "write", "(", "self", ",", "group_id", ",", "handle", ")", ":", "name", "=", "self", ".", "name", ".", "encode", "(", "'utf-8'", ")", "handle", ".", "write", "(", "struct", ".", "pack", "(", "'bb'", ",", "len", "(", "name", ")", ",", "grou...
Write binary data for this parameter to a file handle. Parameters ---------- group_id : int The numerical ID of the group that holds this parameter. handle : file handle An open, writable, binary file handle.
[ "Write", "binary", "data", "for", "this", "parameter", "to", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L239-L260
EmbodiedCognition/py-c3d
c3d.py
Param.read
def read(self, handle): '''Read binary data for this parameter from a file handle. This reads exactly enough data from the current position in the file to initialize the parameter. ''' self.bytes_per_element, = struct.unpack('b', handle.read(1)) dims, = struct.unpack('B'...
python
def read(self, handle): '''Read binary data for this parameter from a file handle. This reads exactly enough data from the current position in the file to initialize the parameter. ''' self.bytes_per_element, = struct.unpack('b', handle.read(1)) dims, = struct.unpack('B'...
[ "def", "read", "(", "self", ",", "handle", ")", ":", "self", ".", "bytes_per_element", ",", "=", "struct", ".", "unpack", "(", "'b'", ",", "handle", ".", "read", "(", "1", ")", ")", "dims", ",", "=", "struct", ".", "unpack", "(", "'B'", ",", "han...
Read binary data for this parameter from a file handle. This reads exactly enough data from the current position in the file to initialize the parameter.
[ "Read", "binary", "data", "for", "this", "parameter", "from", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L262-L275
EmbodiedCognition/py-c3d
c3d.py
Param._as_array
def _as_array(self, fmt): '''Unpack the raw bytes of this param using the given data format.''' assert self.dimensions, \ '{}: cannot get value as {} array!'.format(self.name, fmt) elems = array.array(fmt) elems.fromstring(self.bytes) return np.array(elems).reshape(se...
python
def _as_array(self, fmt): '''Unpack the raw bytes of this param using the given data format.''' assert self.dimensions, \ '{}: cannot get value as {} array!'.format(self.name, fmt) elems = array.array(fmt) elems.fromstring(self.bytes) return np.array(elems).reshape(se...
[ "def", "_as_array", "(", "self", ",", "fmt", ")", ":", "assert", "self", ".", "dimensions", ",", "'{}: cannot get value as {} array!'", ".", "format", "(", "self", ".", "name", ",", "fmt", ")", "elems", "=", "array", ".", "array", "(", "fmt", ")", "elems...
Unpack the raw bytes of this param using the given data format.
[ "Unpack", "the", "raw", "bytes", "of", "this", "param", "using", "the", "given", "data", "format", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L326-L332
EmbodiedCognition/py-c3d
c3d.py
Param.bytes_array
def bytes_array(self): '''Get the param as an array of raw byte strings.''' assert len(self.dimensions) == 2, \ '{}: cannot get value as bytes array!'.format(self.name) l, n = self.dimensions return [self.bytes[i*l:(i+1)*l] for i in range(n)]
python
def bytes_array(self): '''Get the param as an array of raw byte strings.''' assert len(self.dimensions) == 2, \ '{}: cannot get value as bytes array!'.format(self.name) l, n = self.dimensions return [self.bytes[i*l:(i+1)*l] for i in range(n)]
[ "def", "bytes_array", "(", "self", ")", ":", "assert", "len", "(", "self", ".", "dimensions", ")", "==", "2", ",", "'{}: cannot get value as bytes array!'", ".", "format", "(", "self", ".", "name", ")", "l", ",", "n", "=", "self", ".", "dimensions", "ret...
Get the param as an array of raw byte strings.
[ "Get", "the", "param", "as", "an", "array", "of", "raw", "byte", "strings", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L370-L375
EmbodiedCognition/py-c3d
c3d.py
Param.string_array
def string_array(self): '''Get the param as a array of unicode strings.''' assert len(self.dimensions) == 2, \ '{}: cannot get value as string array!'.format(self.name) l, n = self.dimensions return [self.bytes[i*l:(i+1)*l].decode('utf-8') for i in range(n)]
python
def string_array(self): '''Get the param as a array of unicode strings.''' assert len(self.dimensions) == 2, \ '{}: cannot get value as string array!'.format(self.name) l, n = self.dimensions return [self.bytes[i*l:(i+1)*l].decode('utf-8') for i in range(n)]
[ "def", "string_array", "(", "self", ")", ":", "assert", "len", "(", "self", ".", "dimensions", ")", "==", "2", ",", "'{}: cannot get value as string array!'", ".", "format", "(", "self", ".", "name", ")", "l", ",", "n", "=", "self", ".", "dimensions", "r...
Get the param as a array of unicode strings.
[ "Get", "the", "param", "as", "a", "array", "of", "unicode", "strings", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L378-L383
EmbodiedCognition/py-c3d
c3d.py
Group.add_param
def add_param(self, name, **kwargs): '''Add a parameter to this group. Parameters ---------- name : str Name of the parameter to add to this group. The name will automatically be case-normalized. Additional keyword arguments will be passed to the `Param`...
python
def add_param(self, name, **kwargs): '''Add a parameter to this group. Parameters ---------- name : str Name of the parameter to add to this group. The name will automatically be case-normalized. Additional keyword arguments will be passed to the `Param`...
[ "def", "add_param", "(", "self", ",", "name", ",", "*", "*", "kwargs", ")", ":", "self", ".", "params", "[", "name", ".", "upper", "(", ")", "]", "=", "Param", "(", "name", ".", "upper", "(", ")", ",", "*", "*", "kwargs", ")" ]
Add a parameter to this group. Parameters ---------- name : str Name of the parameter to add to this group. The name will automatically be case-normalized. Additional keyword arguments will be passed to the `Param` constructor.
[ "Add", "a", "parameter", "to", "this", "group", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L425-L436
EmbodiedCognition/py-c3d
c3d.py
Group.binary_size
def binary_size(self): '''Return the number of bytes to store this group and its parameters.''' return ( 1 + # group_id 1 + len(self.name.encode('utf-8')) + # size of name and name bytes 2 + # next offset marker 1 + len(self.desc.encode('utf-8')) + # size ...
python
def binary_size(self): '''Return the number of bytes to store this group and its parameters.''' return ( 1 + # group_id 1 + len(self.name.encode('utf-8')) + # size of name and name bytes 2 + # next offset marker 1 + len(self.desc.encode('utf-8')) + # size ...
[ "def", "binary_size", "(", "self", ")", ":", "return", "(", "1", "+", "# group_id", "1", "+", "len", "(", "self", ".", "name", ".", "encode", "(", "'utf-8'", ")", ")", "+", "# size of name and name bytes", "2", "+", "# next offset marker", "1", "+", "len...
Return the number of bytes to store this group and its parameters.
[ "Return", "the", "number", "of", "bytes", "to", "store", "this", "group", "and", "its", "parameters", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L438-L445
EmbodiedCognition/py-c3d
c3d.py
Group.write
def write(self, group_id, handle): '''Write this parameter group, with parameters, to a file handle. Parameters ---------- group_id : int The numerical ID of the group. handle : file handle An open, writable, binary file handle. ''' name =...
python
def write(self, group_id, handle): '''Write this parameter group, with parameters, to a file handle. Parameters ---------- group_id : int The numerical ID of the group. handle : file handle An open, writable, binary file handle. ''' name =...
[ "def", "write", "(", "self", ",", "group_id", ",", "handle", ")", ":", "name", "=", "self", ".", "name", ".", "encode", "(", "'utf-8'", ")", "desc", "=", "self", ".", "desc", ".", "encode", "(", "'utf-8'", ")", "handle", ".", "write", "(", "struct"...
Write this parameter group, with parameters, to a file handle. Parameters ---------- group_id : int The numerical ID of the group. handle : file handle An open, writable, binary file handle.
[ "Write", "this", "parameter", "group", "with", "parameters", "to", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L447-L465
EmbodiedCognition/py-c3d
c3d.py
Manager.check_metadata
def check_metadata(self): '''Ensure that the metadata in our file is self-consistent.''' assert self.header.point_count == self.point_used, ( 'inconsistent point count! {} header != {} POINT:USED'.format( self.header.point_count, self.point_used, )...
python
def check_metadata(self): '''Ensure that the metadata in our file is self-consistent.''' assert self.header.point_count == self.point_used, ( 'inconsistent point count! {} header != {} POINT:USED'.format( self.header.point_count, self.point_used, )...
[ "def", "check_metadata", "(", "self", ")", ":", "assert", "self", ".", "header", ".", "point_count", "==", "self", ".", "point_used", ",", "(", "'inconsistent point count! {} header != {} POINT:USED'", ".", "format", "(", "self", ".", "header", ".", "point_count",...
Ensure that the metadata in our file is self-consistent.
[ "Ensure", "that", "the", "metadata", "in", "our", "file", "is", "self", "-", "consistent", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L522-L566
EmbodiedCognition/py-c3d
c3d.py
Manager.add_group
def add_group(self, group_id, name, desc): '''Add a new parameter group. Parameters ---------- group_id : int The numeric ID for a group to check or create. name : str, optional If a group is created, assign this name to the group. desc : str, opt...
python
def add_group(self, group_id, name, desc): '''Add a new parameter group. Parameters ---------- group_id : int The numeric ID for a group to check or create. name : str, optional If a group is created, assign this name to the group. desc : str, opt...
[ "def", "add_group", "(", "self", ",", "group_id", ",", "name", ",", "desc", ")", ":", "if", "group_id", "in", "self", ".", "groups", ":", "raise", "KeyError", "(", "group_id", ")", "name", "=", "name", ".", "upper", "(", ")", "if", "name", "in", "s...
Add a new parameter group. Parameters ---------- group_id : int The numeric ID for a group to check or create. name : str, optional If a group is created, assign this name to the group. desc : str, optional If a group is created, assign this d...
[ "Add", "a", "new", "parameter", "group", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L568-L596
EmbodiedCognition/py-c3d
c3d.py
Manager.get
def get(self, group, default=None): '''Get a group or parameter. Parameters ---------- group : str If this string contains a period (.), then the part before the period will be used to retrieve a group, and the part after the period will be used to re...
python
def get(self, group, default=None): '''Get a group or parameter. Parameters ---------- group : str If this string contains a period (.), then the part before the period will be used to retrieve a group, and the part after the period will be used to re...
[ "def", "get", "(", "self", ",", "group", ",", "default", "=", "None", ")", ":", "if", "isinstance", "(", "group", ",", "int", ")", ":", "return", "self", ".", "groups", ".", "get", "(", "group", ",", "default", ")", "group", "=", "group", ".", "u...
Get a group or parameter. Parameters ---------- group : str If this string contains a period (.), then the part before the period will be used to retrieve a group, and the part after the period will be used to retrieve a parameter from that group. If this ...
[ "Get", "a", "group", "or", "parameter", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L598-L631
EmbodiedCognition/py-c3d
c3d.py
Manager.parameter_blocks
def parameter_blocks(self): '''Compute the size (in 512B blocks) of the parameter section.''' bytes = 4. + sum(g.binary_size() for g in self.groups.values()) return int(np.ceil(bytes / 512))
python
def parameter_blocks(self): '''Compute the size (in 512B blocks) of the parameter section.''' bytes = 4. + sum(g.binary_size() for g in self.groups.values()) return int(np.ceil(bytes / 512))
[ "def", "parameter_blocks", "(", "self", ")", ":", "bytes", "=", "4.", "+", "sum", "(", "g", ".", "binary_size", "(", ")", "for", "g", "in", "self", ".", "groups", ".", "values", "(", ")", ")", "return", "int", "(", "np", ".", "ceil", "(", "bytes"...
Compute the size (in 512B blocks) of the parameter section.
[ "Compute", "the", "size", "(", "in", "512B", "blocks", ")", "of", "the", "parameter", "section", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L669-L672
EmbodiedCognition/py-c3d
c3d.py
Reader.read_frames
def read_frames(self, copy=True): '''Iterate over the data frames from our C3D file handle. Parameters ---------- copy : bool If False, the reader returns a reference to the same data buffers for every frame. The default is True, which causes the reader to ...
python
def read_frames(self, copy=True): '''Iterate over the data frames from our C3D file handle. Parameters ---------- copy : bool If False, the reader returns a reference to the same data buffers for every frame. The default is True, which causes the reader to ...
[ "def", "read_frames", "(", "self", ",", "copy", "=", "True", ")", ":", "scale", "=", "abs", "(", "self", ".", "point_scale", ")", "is_float", "=", "self", ".", "point_scale", "<", "0", "point_bytes", "=", "[", "2", ",", "4", "]", "[", "is_float", "...
Iterate over the data frames from our C3D file handle. Parameters ---------- copy : bool If False, the reader returns a reference to the same data buffers for every frame. The default is True, which causes the reader to return a unique data buffer for each fr...
[ "Iterate", "over", "the", "data", "frames", "from", "our", "C3D", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L804-L899
EmbodiedCognition/py-c3d
c3d.py
Writer._pad_block
def _pad_block(self, handle): '''Pad the file with 0s to the end of the next block boundary.''' extra = handle.tell() % 512 if extra: handle.write(b'\x00' * (512 - extra))
python
def _pad_block(self, handle): '''Pad the file with 0s to the end of the next block boundary.''' extra = handle.tell() % 512 if extra: handle.write(b'\x00' * (512 - extra))
[ "def", "_pad_block", "(", "self", ",", "handle", ")", ":", "extra", "=", "handle", ".", "tell", "(", ")", "%", "512", "if", "extra", ":", "handle", ".", "write", "(", "b'\\x00'", "*", "(", "512", "-", "extra", ")", ")" ]
Pad the file with 0s to the end of the next block boundary.
[ "Pad", "the", "file", "with", "0s", "to", "the", "end", "of", "the", "next", "block", "boundary", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L956-L960
EmbodiedCognition/py-c3d
c3d.py
Writer._write_metadata
def _write_metadata(self, handle): '''Write metadata to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' self.check_metadata() # he...
python
def _write_metadata(self, handle): '''Write metadata to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' self.check_metadata() # he...
[ "def", "_write_metadata", "(", "self", ",", "handle", ")", ":", "self", ".", "check_metadata", "(", ")", "# header", "self", ".", "header", ".", "write", "(", "handle", ")", "self", ".", "_pad_block", "(", "handle", ")", "assert", "handle", ".", "tell", ...
Write metadata to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle.
[ "Write", "metadata", "to", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L962-L989
EmbodiedCognition/py-c3d
c3d.py
Writer._write_frames
def _write_frames(self, handle): '''Write our frame data to the given file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' assert handle.tell() ==...
python
def _write_frames(self, handle): '''Write our frame data to the given file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' assert handle.tell() ==...
[ "def", "_write_frames", "(", "self", ",", "handle", ")", ":", "assert", "handle", ".", "tell", "(", ")", "==", "512", "*", "(", "self", ".", "header", ".", "data_block", "-", "1", ")", "scale", "=", "abs", "(", "self", ".", "point_scale", ")", "is_...
Write our frame data to the given file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle.
[ "Write", "our", "frame", "data", "to", "the", "given", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L991-L1021
EmbodiedCognition/py-c3d
c3d.py
Writer.write
def write(self, handle): '''Write metadata and point + analog frames to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' if not self._frames...
python
def write(self, handle): '''Write metadata and point + analog frames to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle. ''' if not self._frames...
[ "def", "write", "(", "self", ",", "handle", ")", ":", "if", "not", "self", ".", "_frames", ":", "return", "def", "add", "(", "name", ",", "desc", ",", "bpe", ",", "format", ",", "bytes", ",", "*", "dimensions", ")", ":", "group", ".", "add_param", ...
Write metadata and point + analog frames to a file handle. Parameters ---------- handle : file Write metadata and C3D motion frames to the given file handle. The writer does not close the handle.
[ "Write", "metadata", "and", "point", "+", "analog", "frames", "to", "a", "file", "handle", "." ]
train
https://github.com/EmbodiedCognition/py-c3d/blob/391493d9cb4c6b4aaeee4de2930685e3a67f5845/c3d.py#L1023-L1094
dbarrosop/sir
sir/helpers/SQLite3Helper.py
SQLite3Helper.aggregate_per_prefix
def aggregate_per_prefix(self, start_time, end_time, limit=0, net_masks='', exclude_net_masks=False, filter_proto=None): """ Given a time range aggregates bytes per prefix. Args: start_time: A string representing the starting time of the time range end_time: A string...
python
def aggregate_per_prefix(self, start_time, end_time, limit=0, net_masks='', exclude_net_masks=False, filter_proto=None): """ Given a time range aggregates bytes per prefix. Args: start_time: A string representing the starting time of the time range end_time: A string...
[ "def", "aggregate_per_prefix", "(", "self", ",", "start_time", ",", "end_time", ",", "limit", "=", "0", ",", "net_masks", "=", "''", ",", "exclude_net_masks", "=", "False", ",", "filter_proto", "=", "None", ")", ":", "if", "net_masks", "==", "''", ":", "...
Given a time range aggregates bytes per prefix. Args: start_time: A string representing the starting time of the time range end_time: A string representing the ending time of the time range limit: An optional integer. If it's >0 it will limit the amount of pr...
[ "Given", "a", "time", "range", "aggregates", "bytes", "per", "prefix", "." ]
train
https://github.com/dbarrosop/sir/blob/c1f4c086404b8474f0a560fcc6f49aa4c86f6916/sir/helpers/SQLite3Helper.py#L43-L91
dbarrosop/sir
sir/helpers/SQLite3Helper.py
SQLite3Helper.aggregate_per_as
def aggregate_per_as(self, start_time, end_time): """ Given a time range aggregates bytes per ASNs. Args: start_time: A string representing the starting time of the time range end_time: A string representing the ending time of the time range Returns: ...
python
def aggregate_per_as(self, start_time, end_time): """ Given a time range aggregates bytes per ASNs. Args: start_time: A string representing the starting time of the time range end_time: A string representing the ending time of the time range Returns: ...
[ "def", "aggregate_per_as", "(", "self", ",", "start_time", ",", "end_time", ")", ":", "query", "=", "''' SELECT as_dst as key, SUM(bytes) as sum_bytes\n from acct\n WHERE\n datetime(stamp_updated) BETWEEN datetime(?) AND datetime(?, \"...
Given a time range aggregates bytes per ASNs. Args: start_time: A string representing the starting time of the time range end_time: A string representing the ending time of the time range Returns: A list of prefixes sorted by sum_bytes. For examp...
[ "Given", "a", "time", "range", "aggregates", "bytes", "per", "ASNs", "." ]
train
https://github.com/dbarrosop/sir/blob/c1f4c086404b8474f0a560fcc6f49aa4c86f6916/sir/helpers/SQLite3Helper.py#L93-L118
tjvr/kurt
kurt/plugin.py
_workaround_no_vector_images
def _workaround_no_vector_images(project): """Replace vector images with fake ones.""" RED = (255, 0, 0) PLACEHOLDER = kurt.Image.new((32, 32), RED) for scriptable in [project.stage] + project.sprites: for costume in scriptable.costumes: if costume.image.format == "SVG": ...
python
def _workaround_no_vector_images(project): """Replace vector images with fake ones.""" RED = (255, 0, 0) PLACEHOLDER = kurt.Image.new((32, 32), RED) for scriptable in [project.stage] + project.sprites: for costume in scriptable.costumes: if costume.image.format == "SVG": ...
[ "def", "_workaround_no_vector_images", "(", "project", ")", ":", "RED", "=", "(", "255", ",", "0", ",", "0", ")", "PLACEHOLDER", "=", "kurt", ".", "Image", ".", "new", "(", "(", "32", ",", "32", ")", ",", "RED", ")", "for", "scriptable", "in", "[",...
Replace vector images with fake ones.
[ "Replace", "vector", "images", "with", "fake", "ones", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L313-L321
tjvr/kurt
kurt/plugin.py
_workaround_no_stage_specific_variables
def _workaround_no_stage_specific_variables(project): """Make Stage-specific variables global (move them to Project).""" for (name, var) in project.stage.variables.items(): yield "variable %s" % name for (name, _list) in project.stage.lists.items(): yield "list %s" % name project.variabl...
python
def _workaround_no_stage_specific_variables(project): """Make Stage-specific variables global (move them to Project).""" for (name, var) in project.stage.variables.items(): yield "variable %s" % name for (name, _list) in project.stage.lists.items(): yield "list %s" % name project.variabl...
[ "def", "_workaround_no_stage_specific_variables", "(", "project", ")", ":", "for", "(", "name", ",", "var", ")", "in", "project", ".", "stage", ".", "variables", ".", "items", "(", ")", ":", "yield", "\"variable %s\"", "%", "name", "for", "(", "name", ",",...
Make Stage-specific variables global (move them to Project).
[ "Make", "Stage", "-", "specific", "variables", "global", "(", "move", "them", "to", "Project", ")", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L328-L337
tjvr/kurt
kurt/plugin.py
Kurt.register
def register(cls, plugin): """Register a new :class:`KurtPlugin`. Once registered, the plugin can be used by :class:`Project`, when: * :attr:`Project.load` sees a file with the right extension * :attr:`Project.convert` is called with the format as a parameter """ cls....
python
def register(cls, plugin): """Register a new :class:`KurtPlugin`. Once registered, the plugin can be used by :class:`Project`, when: * :attr:`Project.load` sees a file with the right extension * :attr:`Project.convert` is called with the format as a parameter """ cls....
[ "def", "register", "(", "cls", ",", "plugin", ")", ":", "cls", ".", "plugins", "[", "plugin", ".", "name", "]", "=", "plugin", "# make features", "plugin", ".", "features", "=", "map", "(", "Feature", ".", "get", ",", "plugin", ".", "features", ")", ...
Register a new :class:`KurtPlugin`. Once registered, the plugin can be used by :class:`Project`, when: * :attr:`Project.load` sees a file with the right extension * :attr:`Project.convert` is called with the format as a parameter
[ "Register", "a", "new", ":", "class", ":", "KurtPlugin", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L150-L185
tjvr/kurt
kurt/plugin.py
Kurt.get_plugin
def get_plugin(cls, name=None, **kwargs): """Returns the first format plugin whose attributes match kwargs. For example:: get_plugin(extension="scratch14") Will return the :class:`KurtPlugin` whose :attr:`extension <KurtPlugin.extension>` attribute is ``"scratch14"``. ...
python
def get_plugin(cls, name=None, **kwargs): """Returns the first format plugin whose attributes match kwargs. For example:: get_plugin(extension="scratch14") Will return the :class:`KurtPlugin` whose :attr:`extension <KurtPlugin.extension>` attribute is ``"scratch14"``. ...
[ "def", "get_plugin", "(", "cls", ",", "name", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "isinstance", "(", "name", ",", "KurtPlugin", ")", ":", "return", "name", "if", "'extension'", "in", "kwargs", ":", "kwargs", "[", "'extension'", "]", ...
Returns the first format plugin whose attributes match kwargs. For example:: get_plugin(extension="scratch14") Will return the :class:`KurtPlugin` whose :attr:`extension <KurtPlugin.extension>` attribute is ``"scratch14"``. The :attr:`name <KurtPlugin.name>` is used as th...
[ "Returns", "the", "first", "format", "plugin", "whose", "attributes", "match", "kwargs", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L188-L223
tjvr/kurt
kurt/plugin.py
Kurt.block_by_command
def block_by_command(cls, command): """Return the block with the given :attr:`command`. Returns None if the block is not found. """ for block in cls.blocks: if block.has_command(command): return block
python
def block_by_command(cls, command): """Return the block with the given :attr:`command`. Returns None if the block is not found. """ for block in cls.blocks: if block.has_command(command): return block
[ "def", "block_by_command", "(", "cls", ",", "command", ")", ":", "for", "block", "in", "cls", ".", "blocks", ":", "if", "block", ".", "has_command", "(", "command", ")", ":", "return", "block" ]
Return the block with the given :attr:`command`. Returns None if the block is not found.
[ "Return", "the", "block", "with", "the", "given", ":", "attr", ":", "command", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L226-L234
tjvr/kurt
kurt/plugin.py
Kurt.blocks_by_text
def blocks_by_text(cls, text): """Return a list of blocks matching the given :attr:`text`. Capitalisation and spaces are ignored. """ text = kurt.BlockType._strip_text(text) matches = [] for block in cls.blocks: for pbt in block.conversions: ...
python
def blocks_by_text(cls, text): """Return a list of blocks matching the given :attr:`text`. Capitalisation and spaces are ignored. """ text = kurt.BlockType._strip_text(text) matches = [] for block in cls.blocks: for pbt in block.conversions: ...
[ "def", "blocks_by_text", "(", "cls", ",", "text", ")", ":", "text", "=", "kurt", ".", "BlockType", ".", "_strip_text", "(", "text", ")", "matches", "=", "[", "]", "for", "block", "in", "cls", ".", "blocks", ":", "for", "pbt", "in", "block", ".", "c...
Return a list of blocks matching the given :attr:`text`. Capitalisation and spaces are ignored.
[ "Return", "a", "list", "of", "blocks", "matching", "the", "given", ":", "attr", ":", "text", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/plugin.py#L237-L250
tjvr/kurt
kurt/scratch14/heights.py
clean_up
def clean_up(scripts): """Clean up the given list of scripts in-place so none of the scripts overlap. """ scripts_with_pos = [s for s in scripts if s.pos] scripts_with_pos.sort(key=lambda s: (s.pos[1], s.pos[0])) scripts = scripts_with_pos + [s for s in scripts if not s.pos] y = 20 for...
python
def clean_up(scripts): """Clean up the given list of scripts in-place so none of the scripts overlap. """ scripts_with_pos = [s for s in scripts if s.pos] scripts_with_pos.sort(key=lambda s: (s.pos[1], s.pos[0])) scripts = scripts_with_pos + [s for s in scripts if not s.pos] y = 20 for...
[ "def", "clean_up", "(", "scripts", ")", ":", "scripts_with_pos", "=", "[", "s", "for", "s", "in", "scripts", "if", "s", ".", "pos", "]", "scripts_with_pos", ".", "sort", "(", "key", "=", "lambda", "s", ":", "(", "s", ".", "pos", "[", "1", "]", ",...
Clean up the given list of scripts in-place so none of the scripts overlap.
[ "Clean", "up", "the", "given", "list", "of", "scripts", "in", "-", "place", "so", "none", "of", "the", "scripts", "overlap", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/heights.py#L106-L122
tjvr/kurt
kurt/scratch14/objtable.py
obj_classes_from_module
def obj_classes_from_module(module): """Return a list of classes in a module that have a 'classID' attribute.""" for name in dir(module): if not name.startswith('_'): cls = getattr(module, name) if getattr(cls, 'classID', None): yield (name, cls)
python
def obj_classes_from_module(module): """Return a list of classes in a module that have a 'classID' attribute.""" for name in dir(module): if not name.startswith('_'): cls = getattr(module, name) if getattr(cls, 'classID', None): yield (name, cls)
[ "def", "obj_classes_from_module", "(", "module", ")", ":", "for", "name", "in", "dir", "(", "module", ")", ":", "if", "not", "name", ".", "startswith", "(", "'_'", ")", ":", "cls", "=", "getattr", "(", "module", ",", "name", ")", "if", "getattr", "("...
Return a list of classes in a module that have a 'classID' attribute.
[ "Return", "a", "list", "of", "classes", "in", "a", "module", "that", "have", "a", "classID", "attribute", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L82-L88
tjvr/kurt
kurt/scratch14/objtable.py
decode_network
def decode_network(objects): """Return root object from ref-containing obj table entries""" def resolve_ref(obj, objects=objects): if isinstance(obj, Ref): # first entry is 1 return objects[obj.index - 1] else: return obj # Reading the ObjTable backwards ...
python
def decode_network(objects): """Return root object from ref-containing obj table entries""" def resolve_ref(obj, objects=objects): if isinstance(obj, Ref): # first entry is 1 return objects[obj.index - 1] else: return obj # Reading the ObjTable backwards ...
[ "def", "decode_network", "(", "objects", ")", ":", "def", "resolve_ref", "(", "obj", ",", "objects", "=", "objects", ")", ":", "if", "isinstance", "(", "obj", ",", "Ref", ")", ":", "# first entry is 1", "return", "objects", "[", "obj", ".", "index", "-",...
Return root object from ref-containing obj table entries
[ "Return", "root", "object", "from", "ref", "-", "containing", "obj", "table", "entries" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L251-L298
tjvr/kurt
kurt/scratch14/objtable.py
encode_network
def encode_network(root): """Yield ref-containing obj table entries from object network""" orig_objects = [] objects = [] def get_ref(value, objects=objects): """Returns the index of the given object in the object table, adding it if needed. """ value = PythonicAdapter(...
python
def encode_network(root): """Yield ref-containing obj table entries from object network""" orig_objects = [] objects = [] def get_ref(value, objects=objects): """Returns the index of the given object in the object table, adding it if needed. """ value = PythonicAdapter(...
[ "def", "encode_network", "(", "root", ")", ":", "orig_objects", "=", "[", "]", "objects", "=", "[", "]", "def", "get_ref", "(", "value", ",", "objects", "=", "objects", ")", ":", "\"\"\"Returns the index of the given object in the object table,\n adding it if n...
Yield ref-containing obj table entries from object network
[ "Yield", "ref", "-", "containing", "obj", "table", "entries", "from", "object", "network" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L300-L381
tjvr/kurt
kurt/scratch14/objtable.py
encode_network
def encode_network(root): """Yield ref-containing obj table entries from object network""" def fix_values(obj): if isinstance(obj, Container): obj.update((k, get_ref(v)) for (k, v) in obj.items() if k != 'class_name') fixed_obj = obj ...
python
def encode_network(root): """Yield ref-containing obj table entries from object network""" def fix_values(obj): if isinstance(obj, Container): obj.update((k, get_ref(v)) for (k, v) in obj.items() if k != 'class_name') fixed_obj = obj ...
[ "def", "encode_network", "(", "root", ")", ":", "def", "fix_values", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "Container", ")", ":", "obj", ".", "update", "(", "(", "k", ",", "get_ref", "(", "v", ")", ")", "for", "(", "k", ",", ...
Yield ref-containing obj table entries from object network
[ "Yield", "ref", "-", "containing", "obj", "table", "entries", "from", "object", "network" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L383-L443
tjvr/kurt
kurt/scratch14/objtable.py
decode_obj_table
def decode_obj_table(table_entries, plugin): """Return root of obj table. Converts user-class objects""" entries = [] for entry in table_entries: if isinstance(entry, Container): assert not hasattr(entry, '__recursion_lock__') user_obj_def = plugin.user_objects[entry.classID]...
python
def decode_obj_table(table_entries, plugin): """Return root of obj table. Converts user-class objects""" entries = [] for entry in table_entries: if isinstance(entry, Container): assert not hasattr(entry, '__recursion_lock__') user_obj_def = plugin.user_objects[entry.classID]...
[ "def", "decode_obj_table", "(", "table_entries", ",", "plugin", ")", ":", "entries", "=", "[", "]", "for", "entry", "in", "table_entries", ":", "if", "isinstance", "(", "entry", ",", "Container", ")", ":", "assert", "not", "hasattr", "(", "entry", ",", "...
Return root of obj table. Converts user-class objects
[ "Return", "root", "of", "obj", "table", ".", "Converts", "user", "-", "class", "objects" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L445-L458
tjvr/kurt
kurt/scratch14/objtable.py
encode_obj_table
def encode_obj_table(root, plugin): """Return list of obj table entries. Converts user-class objects""" entries = encode_network(root) table_entries = [] for entry in entries: if isinstance(entry, Container): assert not hasattr(entry, '__recursion_lock__') user_obj_def =...
python
def encode_obj_table(root, plugin): """Return list of obj table entries. Converts user-class objects""" entries = encode_network(root) table_entries = [] for entry in entries: if isinstance(entry, Container): assert not hasattr(entry, '__recursion_lock__') user_obj_def =...
[ "def", "encode_obj_table", "(", "root", ",", "plugin", ")", ":", "entries", "=", "encode_network", "(", "root", ")", "table_entries", "=", "[", "]", "for", "entry", "in", "entries", ":", "if", "isinstance", "(", "entry", ",", "Container", ")", ":", "asse...
Return list of obj table entries. Converts user-class objects
[ "Return", "list", "of", "obj", "table", "entries", ".", "Converts", "user", "-", "class", "objects" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L460-L477
tjvr/kurt
kurt/scratch14/objtable.py
ObjectAdapter._encode
def _encode(self, obj, context): """Encodes a class to a lower-level object using the class' own to_construct function. If no such function is defined, returns the object unchanged. """ func = getattr(obj, 'to_construct', None) if callable(func): return func(c...
python
def _encode(self, obj, context): """Encodes a class to a lower-level object using the class' own to_construct function. If no such function is defined, returns the object unchanged. """ func = getattr(obj, 'to_construct', None) if callable(func): return func(c...
[ "def", "_encode", "(", "self", ",", "obj", ",", "context", ")", ":", "func", "=", "getattr", "(", "obj", ",", "'to_construct'", ",", "None", ")", "if", "callable", "(", "func", ")", ":", "return", "func", "(", "context", ")", "else", ":", "return", ...
Encodes a class to a lower-level object using the class' own to_construct function. If no such function is defined, returns the object unchanged.
[ "Encodes", "a", "class", "to", "a", "lower", "-", "level", "object", "using", "the", "class", "own", "to_construct", "function", ".", "If", "no", "such", "function", "is", "defined", "returns", "the", "object", "unchanged", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L60-L69
tjvr/kurt
kurt/scratch14/objtable.py
ObjectAdapter._decode
def _decode(self, obj, context): """Initialises a new Python class from a construct using the mapping passed to the adapter. """ cls = self._get_class(obj.classID) return cls.from_construct(obj, context)
python
def _decode(self, obj, context): """Initialises a new Python class from a construct using the mapping passed to the adapter. """ cls = self._get_class(obj.classID) return cls.from_construct(obj, context)
[ "def", "_decode", "(", "self", ",", "obj", ",", "context", ")", ":", "cls", "=", "self", ".", "_get_class", "(", "obj", ".", "classID", ")", "return", "cls", ".", "from_construct", "(", "obj", ",", "context", ")" ]
Initialises a new Python class from a construct using the mapping passed to the adapter.
[ "Initialises", "a", "new", "Python", "class", "from", "a", "construct", "using", "the", "mapping", "passed", "to", "the", "adapter", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/objtable.py#L71-L76
tjvr/kurt
kurt/scratch20/__init__.py
ZipWriter.write_file
def write_file(self, name, contents): """Write file contents string into archive.""" # TODO: find a way to make ZipFile accept a file object. zi = zipfile.ZipInfo(name) zi.date_time = time.localtime(time.time())[:6] zi.compress_type = zipfile.ZIP_DEFLATED zi.external_attr...
python
def write_file(self, name, contents): """Write file contents string into archive.""" # TODO: find a way to make ZipFile accept a file object. zi = zipfile.ZipInfo(name) zi.date_time = time.localtime(time.time())[:6] zi.compress_type = zipfile.ZIP_DEFLATED zi.external_attr...
[ "def", "write_file", "(", "self", ",", "name", ",", "contents", ")", ":", "# TODO: find a way to make ZipFile accept a file object.", "zi", "=", "zipfile", ".", "ZipInfo", "(", "name", ")", "zi", ".", "date_time", "=", "time", ".", "localtime", "(", "time", "....
Write file contents string into archive.
[ "Write", "file", "contents", "string", "into", "archive", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch20/__init__.py#L348-L355
tjvr/kurt
examples/import_midi.py
load_midi_file
def load_midi_file(path): """Yield (pitch, start_beat, end_beat) for each note in midi file.""" midi_notes = [] def register_note(track, channel, pitch, velocity, start, end): midi_notes.append((pitch, start, end)) midi.register_note = register_note global m m = midi.MidiFile() m.o...
python
def load_midi_file(path): """Yield (pitch, start_beat, end_beat) for each note in midi file.""" midi_notes = [] def register_note(track, channel, pitch, velocity, start, end): midi_notes.append((pitch, start, end)) midi.register_note = register_note global m m = midi.MidiFile() m.o...
[ "def", "load_midi_file", "(", "path", ")", ":", "midi_notes", "=", "[", "]", "def", "register_note", "(", "track", ",", "channel", ",", "pitch", ",", "velocity", ",", "start", ",", "end", ")", ":", "midi_notes", ".", "append", "(", "(", "pitch", ",", ...
Yield (pitch, start_beat, end_beat) for each note in midi file.
[ "Yield", "(", "pitch", "start_beat", "end_beat", ")", "for", "each", "note", "in", "midi", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/examples/import_midi.py#L24-L41
tjvr/kurt
kurt/scratch14/__init__.py
Serializer.get_media
def get_media(self, v14_scriptable): """Return (images, sounds)""" images = [] sounds = [] for media in v14_scriptable.media: if media.class_name == 'SoundMedia': sounds.append(media) elif media.class_name == 'ImageMedia': images.ap...
python
def get_media(self, v14_scriptable): """Return (images, sounds)""" images = [] sounds = [] for media in v14_scriptable.media: if media.class_name == 'SoundMedia': sounds.append(media) elif media.class_name == 'ImageMedia': images.ap...
[ "def", "get_media", "(", "self", ",", "v14_scriptable", ")", ":", "images", "=", "[", "]", "sounds", "=", "[", "]", "for", "media", "in", "v14_scriptable", ".", "media", ":", "if", "media", ".", "class_name", "==", "'SoundMedia'", ":", "sounds", ".", "...
Return (images, sounds)
[ "Return", "(", "images", "sounds", ")" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/__init__.py#L216-L225
tjvr/kurt
kurt/scratch14/fixed_objects.py
Bitmap.from_byte_array
def from_byte_array(cls, bytes_): """Decodes a run-length encoded ByteArray and returns a Bitmap. The ByteArray decompresses to a sequence of 32-bit values, which are stored as a byte string. (The specific encoding depends on Form.depth.) """ runs = cls._length_run_coding.parse(b...
python
def from_byte_array(cls, bytes_): """Decodes a run-length encoded ByteArray and returns a Bitmap. The ByteArray decompresses to a sequence of 32-bit values, which are stored as a byte string. (The specific encoding depends on Form.depth.) """ runs = cls._length_run_coding.parse(b...
[ "def", "from_byte_array", "(", "cls", ",", "bytes_", ")", ":", "runs", "=", "cls", ".", "_length_run_coding", ".", "parse", "(", "bytes_", ")", "pixels", "=", "(", "run", ".", "pixels", "for", "run", "in", "runs", ".", "data", ")", "data", "=", "\"\"...
Decodes a run-length encoded ByteArray and returns a Bitmap. The ByteArray decompresses to a sequence of 32-bit values, which are stored as a byte string. (The specific encoding depends on Form.depth.)
[ "Decodes", "a", "run", "-", "length", "encoded", "ByteArray", "and", "returns", "a", "Bitmap", ".", "The", "ByteArray", "decompresses", "to", "a", "sequence", "of", "32", "-", "bit", "values", "which", "are", "stored", "as", "a", "byte", "string", ".", "...
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/fixed_objects.py#L521-L529
tjvr/kurt
kurt/scratch14/fixed_objects.py
Form.from_string
def from_string(cls, width, height, rgba_string): """Returns a Form with 32-bit RGBA pixels Accepts string containing raw RGBA color values """ # Convert RGBA string to ARGB raw = "" for i in range(0, len(rgba_string), 4): raw += rgba_string[i+3] # alpha ...
python
def from_string(cls, width, height, rgba_string): """Returns a Form with 32-bit RGBA pixels Accepts string containing raw RGBA color values """ # Convert RGBA string to ARGB raw = "" for i in range(0, len(rgba_string), 4): raw += rgba_string[i+3] # alpha ...
[ "def", "from_string", "(", "cls", ",", "width", ",", "height", ",", "rgba_string", ")", ":", "# Convert RGBA string to ARGB", "raw", "=", "\"\"", "for", "i", "in", "range", "(", "0", ",", "len", "(", "rgba_string", ")", ",", "4", ")", ":", "raw", "+=",...
Returns a Form with 32-bit RGBA pixels Accepts string containing raw RGBA color values
[ "Returns", "a", "Form", "with", "32", "-", "bit", "RGBA", "pixels", "Accepts", "string", "containing", "raw", "RGBA", "color", "values" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/scratch14/fixed_objects.py#L642-L659
tjvr/kurt
util/kurtgui.py
open_file
def open_file(path): """Opens Explorer/Finder with given path, depending on platform""" if sys.platform=='win32': os.startfile(path) #subprocess.Popen(['start', path], shell= True) elif sys.platform=='darwin': subprocess.Popen(['open', path]) else: try: ...
python
def open_file(path): """Opens Explorer/Finder with given path, depending on platform""" if sys.platform=='win32': os.startfile(path) #subprocess.Popen(['start', path], shell= True) elif sys.platform=='darwin': subprocess.Popen(['open', path]) else: try: ...
[ "def", "open_file", "(", "path", ")", ":", "if", "sys", ".", "platform", "==", "'win32'", ":", "os", ".", "startfile", "(", "path", ")", "#subprocess.Popen(['start', path], shell= True)", "elif", "sys", ".", "platform", "==", "'darwin'", ":", "subprocess", "."...
Opens Explorer/Finder with given path, depending on platform
[ "Opens", "Explorer", "/", "Finder", "with", "given", "path", "depending", "on", "platform" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/util/kurtgui.py#L60-L73
tjvr/kurt
util/kurtgui.py
App.set_file_path
def set_file_path(self, path): """Update the file_path Entry widget""" self.file_path.delete(0, END) self.file_path.insert(0, path)
python
def set_file_path(self, path): """Update the file_path Entry widget""" self.file_path.delete(0, END) self.file_path.insert(0, path)
[ "def", "set_file_path", "(", "self", ",", "path", ")", ":", "self", ".", "file_path", ".", "delete", "(", "0", ",", "END", ")", "self", ".", "file_path", ".", "insert", "(", "0", ",", "path", ")" ]
Update the file_path Entry widget
[ "Update", "the", "file_path", "Entry", "widget" ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/util/kurtgui.py#L175-L178
tjvr/kurt
kurt/__init__.py
Project.load
def load(cls, path, format=None): """Load project from file. Use ``format`` to specify the file format to use. Path can be a file-like object, in which case format is required. Otherwise, can guess the appropriate format from the extension. If you pass a file-like object, you'...
python
def load(cls, path, format=None): """Load project from file. Use ``format`` to specify the file format to use. Path can be a file-like object, in which case format is required. Otherwise, can guess the appropriate format from the extension. If you pass a file-like object, you'...
[ "def", "load", "(", "cls", ",", "path", ",", "format", "=", "None", ")", ":", "path_was_string", "=", "isinstance", "(", "path", ",", "basestring", ")", "if", "path_was_string", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "...
Load project from file. Use ``format`` to specify the file format to use. Path can be a file-like object, in which case format is required. Otherwise, can guess the appropriate format from the extension. If you pass a file-like object, you're responsible for closing the file. ...
[ "Load", "project", "from", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L232-L276
tjvr/kurt
kurt/__init__.py
Project.copy
def copy(self): """Return a new Project instance, deep-copying all the attributes.""" p = Project() p.name = self.name p.path = self.path p._plugin = self._plugin p.stage = self.stage.copy() p.stage.project = p for sprite in self.sprites: s = ...
python
def copy(self): """Return a new Project instance, deep-copying all the attributes.""" p = Project() p.name = self.name p.path = self.path p._plugin = self._plugin p.stage = self.stage.copy() p.stage.project = p for sprite in self.sprites: s = ...
[ "def", "copy", "(", "self", ")", ":", "p", "=", "Project", "(", ")", "p", ".", "name", "=", "self", ".", "name", "p", ".", "path", "=", "self", ".", "path", "p", ".", "_plugin", "=", "self", ".", "_plugin", "p", ".", "stage", "=", "self", "."...
Return a new Project instance, deep-copying all the attributes.
[ "Return", "a", "new", "Project", "instance", "deep", "-", "copying", "all", "the", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L278-L312
tjvr/kurt
kurt/__init__.py
Project.convert
def convert(self, format): """Convert the project in-place to a different file format. Returns a list of :class:`UnsupportedFeature` objects, which may give warnings about the conversion. :param format: :attr:`KurtFileFormat.name` eg. ``"scratch14"``. :raises: :class:`ValueErr...
python
def convert(self, format): """Convert the project in-place to a different file format. Returns a list of :class:`UnsupportedFeature` objects, which may give warnings about the conversion. :param format: :attr:`KurtFileFormat.name` eg. ``"scratch14"``. :raises: :class:`ValueErr...
[ "def", "convert", "(", "self", ",", "format", ")", ":", "self", ".", "_plugin", "=", "kurt", ".", "plugin", ".", "Kurt", ".", "get_plugin", "(", "format", ")", "return", "list", "(", "self", ".", "_normalize", "(", ")", ")" ]
Convert the project in-place to a different file format. Returns a list of :class:`UnsupportedFeature` objects, which may give warnings about the conversion. :param format: :attr:`KurtFileFormat.name` eg. ``"scratch14"``. :raises: :class:`ValueError` if the format doesn't exist.
[ "Convert", "the", "project", "in", "-", "place", "to", "a", "different", "file", "format", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L314-L326
tjvr/kurt
kurt/__init__.py
Project.save
def save(self, path=None, debug=False): """Save project to file. :param path: Path or file pointer. If you pass a file pointer, you're responsible for closing it. If path is not given, the :attr:`path` attribute is used, ...
python
def save(self, path=None, debug=False): """Save project to file. :param path: Path or file pointer. If you pass a file pointer, you're responsible for closing it. If path is not given, the :attr:`path` attribute is used, ...
[ "def", "save", "(", "self", ",", "path", "=", "None", ",", "debug", "=", "False", ")", ":", "p", "=", "self", ".", "copy", "(", ")", "plugin", "=", "p", ".", "_plugin", "# require path", "p", ".", "path", "=", "path", "or", "self", ".", "path", ...
Save project to file. :param path: Path or file pointer. If you pass a file pointer, you're responsible for closing it. If path is not given, the :attr:`path` attribute is used, usually the original path given to :attr:`load(...
[ "Save", "project", "to", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L328-L402
tjvr/kurt
kurt/__init__.py
Project._normalize
def _normalize(self): """Convert the project to a standardised form for the current plugin. Called after loading, before saving, and when converting to a new format. Yields UnsupportedFeature instances. """ unique_sprite_names = set(sprite.name for sprite in self.spri...
python
def _normalize(self): """Convert the project to a standardised form for the current plugin. Called after loading, before saving, and when converting to a new format. Yields UnsupportedFeature instances. """ unique_sprite_names = set(sprite.name for sprite in self.spri...
[ "def", "_normalize", "(", "self", ")", ":", "unique_sprite_names", "=", "set", "(", "sprite", ".", "name", "for", "sprite", "in", "self", ".", "sprites", ")", "if", "len", "(", "unique_sprite_names", ")", "<", "len", "(", "self", ".", "sprites", ")", "...
Convert the project to a standardised form for the current plugin. Called after loading, before saving, and when converting to a new format. Yields UnsupportedFeature instances.
[ "Convert", "the", "project", "to", "a", "standardised", "form", "for", "the", "current", "plugin", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L407-L506
tjvr/kurt
kurt/__init__.py
Scriptable.copy
def copy(self, o=None): """Return a new instance, deep-copying all the attributes.""" if o is None: o = self.__class__(self.project) o.scripts = [s.copy() for s in self.scripts] o.variables = dict((n, v.copy()) for (n, v) in self.variables.items()) o.lists = dict((n, l.copy()) fo...
python
def copy(self, o=None): """Return a new instance, deep-copying all the attributes.""" if o is None: o = self.__class__(self.project) o.scripts = [s.copy() for s in self.scripts] o.variables = dict((n, v.copy()) for (n, v) in self.variables.items()) o.lists = dict((n, l.copy()) fo...
[ "def", "copy", "(", "self", ",", "o", "=", "None", ")", ":", "if", "o", "is", "None", ":", "o", "=", "self", ".", "__class__", "(", "self", ".", "project", ")", "o", ".", "scripts", "=", "[", "s", ".", "copy", "(", ")", "for", "s", "in", "s...
Return a new instance, deep-copying all the attributes.
[ "Return", "a", "new", "instance", "deep", "-", "copying", "all", "the", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L675-L685
tjvr/kurt
kurt/__init__.py
Scriptable.parse
def parse(self, text): """Parse the given code and add it to :attr:`scripts`. The syntax matches :attr:`Script.stringify()`. See :mod:`kurt.text` for reference. """ self.scripts.append(kurt.text.parse(text, self))
python
def parse(self, text): """Parse the given code and add it to :attr:`scripts`. The syntax matches :attr:`Script.stringify()`. See :mod:`kurt.text` for reference. """ self.scripts.append(kurt.text.parse(text, self))
[ "def", "parse", "(", "self", ",", "text", ")", ":", "self", ".", "scripts", ".", "append", "(", "kurt", ".", "text", ".", "parse", "(", "text", ",", "self", ")", ")" ]
Parse the given code and add it to :attr:`scripts`. The syntax matches :attr:`Script.stringify()`. See :mod:`kurt.text` for reference.
[ "Parse", "the", "given", "code", "and", "add", "it", "to", ":", "attr", ":", "scripts", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L704-L711
tjvr/kurt
kurt/__init__.py
Sprite.copy
def copy(self): """Return a new instance, deep-copying all the attributes.""" o = self.__class__(self.project, self.name) Scriptable.copy(self, o) o.position = tuple(self.position) o.direction = self.direction o.rotation_style = self.rotation_style o.size = self.s...
python
def copy(self): """Return a new instance, deep-copying all the attributes.""" o = self.__class__(self.project, self.name) Scriptable.copy(self, o) o.position = tuple(self.position) o.direction = self.direction o.rotation_style = self.rotation_style o.size = self.s...
[ "def", "copy", "(", "self", ")", ":", "o", "=", "self", ".", "__class__", "(", "self", ".", "project", ",", "self", ".", "name", ")", "Scriptable", ".", "copy", "(", "self", ",", "o", ")", "o", ".", "position", "=", "tuple", "(", "self", ".", "...
Return a new instance, deep-copying all the attributes.
[ "Return", "a", "new", "instance", "deep", "-", "copying", "all", "the", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L825-L835
tjvr/kurt
kurt/__init__.py
Watcher.copy
def copy(self): """Return a new instance with the same attributes.""" o = self.__class__(self.target, self.block.copy(), self.style, self.is_visible, self.pos) o.slider_min = self.slider_min o.slider_max = self.slider_max ...
python
def copy(self): """Return a new instance with the same attributes.""" o = self.__class__(self.target, self.block.copy(), self.style, self.is_visible, self.pos) o.slider_min = self.slider_min o.slider_max = self.slider_max ...
[ "def", "copy", "(", "self", ")", ":", "o", "=", "self", ".", "__class__", "(", "self", ".", "target", ",", "self", ".", "block", ".", "copy", "(", ")", ",", "self", ".", "style", ",", "self", ".", "is_visible", ",", "self", ".", "pos", ")", "o"...
Return a new instance with the same attributes.
[ "Return", "a", "new", "instance", "with", "the", "same", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L918-L927
tjvr/kurt
kurt/__init__.py
Watcher.kind
def kind(self): """The type of value to watch, based on :attr:`block`. One of ``variable``, ``list``, or ``block``. ``block`` watchers watch the value of a reporter block. """ if self.block.type.has_command('readVariable'): return 'variable' elif self.block...
python
def kind(self): """The type of value to watch, based on :attr:`block`. One of ``variable``, ``list``, or ``block``. ``block`` watchers watch the value of a reporter block. """ if self.block.type.has_command('readVariable'): return 'variable' elif self.block...
[ "def", "kind", "(", "self", ")", ":", "if", "self", ".", "block", ".", "type", ".", "has_command", "(", "'readVariable'", ")", ":", "return", "'variable'", "elif", "self", ".", "block", ".", "type", ".", "has_command", "(", "'contentsOfList:'", ")", ":",...
The type of value to watch, based on :attr:`block`. One of ``variable``, ``list``, or ``block``. ``block`` watchers watch the value of a reporter block.
[ "The", "type", "of", "value", "to", "watch", "based", "on", ":", "attr", ":", "block", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L930-L943
tjvr/kurt
kurt/__init__.py
Watcher.value
def value(self): """Return the :class:`Variable` or :class:`List` to watch. Returns ``None`` if it's a block watcher. """ if self.kind == 'variable': return self.target.variables[self.block.args[0]] elif self.kind == 'list': return self.target.lists[self...
python
def value(self): """Return the :class:`Variable` or :class:`List` to watch. Returns ``None`` if it's a block watcher. """ if self.kind == 'variable': return self.target.variables[self.block.args[0]] elif self.kind == 'list': return self.target.lists[self...
[ "def", "value", "(", "self", ")", ":", "if", "self", ".", "kind", "==", "'variable'", ":", "return", "self", ".", "target", ".", "variables", "[", "self", ".", "block", ".", "args", "[", "0", "]", "]", "elif", "self", ".", "kind", "==", "'list'", ...
Return the :class:`Variable` or :class:`List` to watch. Returns ``None`` if it's a block watcher.
[ "Return", "the", ":", "class", ":", "Variable", "or", ":", "class", ":", "List", "to", "watch", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L946-L955
tjvr/kurt
kurt/__init__.py
Color.stringify
def stringify(self): """Returns the color value in hexcode format. eg. ``'#ff1056'`` """ hexcode = "#" for x in self.value: part = hex(x)[2:] if len(part) < 2: part = "0" + part hexcode += part return hexcode
python
def stringify(self): """Returns the color value in hexcode format. eg. ``'#ff1056'`` """ hexcode = "#" for x in self.value: part = hex(x)[2:] if len(part) < 2: part = "0" + part hexcode += part return hexcode
[ "def", "stringify", "(", "self", ")", ":", "hexcode", "=", "\"#\"", "for", "x", "in", "self", ".", "value", ":", "part", "=", "hex", "(", "x", ")", "[", "2", ":", "]", "if", "len", "(", "part", ")", "<", "2", ":", "part", "=", "\"0\"", "+", ...
Returns the color value in hexcode format. eg. ``'#ff1056'``
[ "Returns", "the", "color", "value", "in", "hexcode", "format", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1123-L1134
tjvr/kurt
kurt/__init__.py
Insert.options
def options(self, scriptable=None): """Return a list of valid options to a menu insert, given a Scriptable for context. Mostly complete, excepting 'attribute'. """ options = list(Insert.KIND_OPTIONS.get(self.kind, [])) if scriptable: if self.kind == 'var': ...
python
def options(self, scriptable=None): """Return a list of valid options to a menu insert, given a Scriptable for context. Mostly complete, excepting 'attribute'. """ options = list(Insert.KIND_OPTIONS.get(self.kind, [])) if scriptable: if self.kind == 'var': ...
[ "def", "options", "(", "self", ",", "scriptable", "=", "None", ")", ":", "options", "=", "list", "(", "Insert", ".", "KIND_OPTIONS", ".", "get", "(", "self", ".", "kind", ",", "[", "]", ")", ")", "if", "scriptable", ":", "if", "self", ".", "kind", ...
Return a list of valid options to a menu insert, given a Scriptable for context. Mostly complete, excepting 'attribute'.
[ "Return", "a", "list", "of", "valid", "options", "to", "a", "menu", "insert", "given", "a", "Scriptable", "for", "context", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1372-L1401
tjvr/kurt
kurt/__init__.py
BaseBlockType.text
def text(self): """The text displayed on the block. String containing ``"%s"`` in place of inserts. eg. ``'say %s for %s secs'`` """ parts = [("%s" if isinstance(p, Insert) else p) for p in self.parts] parts = [("%%" if p == "%" else p) for p in parts] # escape percent...
python
def text(self): """The text displayed on the block. String containing ``"%s"`` in place of inserts. eg. ``'say %s for %s secs'`` """ parts = [("%s" if isinstance(p, Insert) else p) for p in self.parts] parts = [("%%" if p == "%" else p) for p in parts] # escape percent...
[ "def", "text", "(", "self", ")", ":", "parts", "=", "[", "(", "\"%s\"", "if", "isinstance", "(", "p", ",", "Insert", ")", "else", "p", ")", "for", "p", "in", "self", ".", "parts", "]", "parts", "=", "[", "(", "\"%%\"", "if", "p", "==", "\"%\"",...
The text displayed on the block. String containing ``"%s"`` in place of inserts. eg. ``'say %s for %s secs'``
[ "The", "text", "displayed", "on", "the", "block", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1455-L1465
tjvr/kurt
kurt/__init__.py
BaseBlockType.stripped_text
def stripped_text(self): """The :attr:`text`, with spaces and inserts removed. Used by :class:`BlockType.get` to look up blocks. """ return BaseBlockType._strip_text( self.text % tuple((i.default if i.shape == 'inline' else '%s') for i ...
python
def stripped_text(self): """The :attr:`text`, with spaces and inserts removed. Used by :class:`BlockType.get` to look up blocks. """ return BaseBlockType._strip_text( self.text % tuple((i.default if i.shape == 'inline' else '%s') for i ...
[ "def", "stripped_text", "(", "self", ")", ":", "return", "BaseBlockType", ".", "_strip_text", "(", "self", ".", "text", "%", "tuple", "(", "(", "i", ".", "default", "if", "i", ".", "shape", "==", "'inline'", "else", "'%s'", ")", "for", "i", "in", "se...
The :attr:`text`, with spaces and inserts removed. Used by :class:`BlockType.get` to look up blocks.
[ "The", ":", "attr", ":", "text", "with", "spaces", "and", "inserts", "removed", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1482-L1490
tjvr/kurt
kurt/__init__.py
BaseBlockType._strip_text
def _strip_text(text): """Returns text with spaces and inserts removed.""" text = re.sub(r'[ ,?:]|%s', "", text.lower()) for chr in "-%": new_text = text.replace(chr, "") if new_text: text = new_text return text.lower()
python
def _strip_text(text): """Returns text with spaces and inserts removed.""" text = re.sub(r'[ ,?:]|%s', "", text.lower()) for chr in "-%": new_text = text.replace(chr, "") if new_text: text = new_text return text.lower()
[ "def", "_strip_text", "(", "text", ")", ":", "text", "=", "re", ".", "sub", "(", "r'[ ,?:]|%s'", ",", "\"\"", ",", "text", ".", "lower", "(", ")", ")", "for", "chr", "in", "\"-%\"", ":", "new_text", "=", "text", ".", "replace", "(", "chr", ",", "...
Returns text with spaces and inserts removed.
[ "Returns", "text", "with", "spaces", "and", "inserts", "removed", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1493-L1500
tjvr/kurt
kurt/__init__.py
BaseBlockType.has_insert
def has_insert(self, shape): """Returns True if any of the inserts have the given shape.""" for insert in self.inserts: if insert.shape == shape: return True return False
python
def has_insert(self, shape): """Returns True if any of the inserts have the given shape.""" for insert in self.inserts: if insert.shape == shape: return True return False
[ "def", "has_insert", "(", "self", ",", "shape", ")", ":", "for", "insert", "in", "self", ".", "inserts", ":", "if", "insert", ".", "shape", "==", "shape", ":", "return", "True", "return", "False" ]
Returns True if any of the inserts have the given shape.
[ "Returns", "True", "if", "any", "of", "the", "inserts", "have", "the", "given", "shape", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1526-L1531
tjvr/kurt
kurt/__init__.py
BlockType._add_conversion
def _add_conversion(self, plugin, pbt): """Add a new PluginBlockType conversion. If the plugin already exists, do nothing. """ assert self.shape == pbt.shape assert len(self.inserts) == len(pbt.inserts) for (i, o) in zip(self.inserts, pbt.inserts): assert i....
python
def _add_conversion(self, plugin, pbt): """Add a new PluginBlockType conversion. If the plugin already exists, do nothing. """ assert self.shape == pbt.shape assert len(self.inserts) == len(pbt.inserts) for (i, o) in zip(self.inserts, pbt.inserts): assert i....
[ "def", "_add_conversion", "(", "self", ",", "plugin", ",", "pbt", ")", ":", "assert", "self", ".", "shape", "==", "pbt", ".", "shape", "assert", "len", "(", "self", ".", "inserts", ")", "==", "len", "(", "pbt", ".", "inserts", ")", "for", "(", "i",...
Add a new PluginBlockType conversion. If the plugin already exists, do nothing.
[ "Add", "a", "new", "PluginBlockType", "conversion", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1558-L1571
tjvr/kurt
kurt/__init__.py
BlockType.convert
def convert(self, plugin=None): """Return a :class:`PluginBlockType` for the given plugin name. If plugin is ``None``, return the first registered plugin. """ if plugin: plugin = kurt.plugin.Kurt.get_plugin(plugin) if plugin.name in self._plugins: ...
python
def convert(self, plugin=None): """Return a :class:`PluginBlockType` for the given plugin name. If plugin is ``None``, return the first registered plugin. """ if plugin: plugin = kurt.plugin.Kurt.get_plugin(plugin) if plugin.name in self._plugins: ...
[ "def", "convert", "(", "self", ",", "plugin", "=", "None", ")", ":", "if", "plugin", ":", "plugin", "=", "kurt", ".", "plugin", ".", "Kurt", ".", "get_plugin", "(", "plugin", ")", "if", "plugin", ".", "name", "in", "self", ".", "_plugins", ":", "re...
Return a :class:`PluginBlockType` for the given plugin name. If plugin is ``None``, return the first registered plugin.
[ "Return", "a", ":", "class", ":", "PluginBlockType", "for", "the", "given", "plugin", "name", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1573-L1589
tjvr/kurt
kurt/__init__.py
BlockType.has_conversion
def has_conversion(self, plugin): """Return True if the plugin supports this block.""" plugin = kurt.plugin.Kurt.get_plugin(plugin) return plugin.name in self._plugins
python
def has_conversion(self, plugin): """Return True if the plugin supports this block.""" plugin = kurt.plugin.Kurt.get_plugin(plugin) return plugin.name in self._plugins
[ "def", "has_conversion", "(", "self", ",", "plugin", ")", ":", "plugin", "=", "kurt", ".", "plugin", ".", "Kurt", ".", "get_plugin", "(", "plugin", ")", "return", "plugin", ".", "name", "in", "self", ".", "_plugins" ]
Return True if the plugin supports this block.
[ "Return", "True", "if", "the", "plugin", "supports", "this", "block", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1596-L1599
tjvr/kurt
kurt/__init__.py
BlockType.has_command
def has_command(self, command): """Returns True if any of the plugins have the given command.""" for pbt in self._plugins.values(): if pbt.command == command: return True return False
python
def has_command(self, command): """Returns True if any of the plugins have the given command.""" for pbt in self._plugins.values(): if pbt.command == command: return True return False
[ "def", "has_command", "(", "self", ",", "command", ")", ":", "for", "pbt", "in", "self", ".", "_plugins", ".", "values", "(", ")", ":", "if", "pbt", ".", "command", "==", "command", ":", "return", "True", "return", "False" ]
Returns True if any of the plugins have the given command.
[ "Returns", "True", "if", "any", "of", "the", "plugins", "have", "the", "given", "command", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1601-L1606
tjvr/kurt
kurt/__init__.py
BlockType.get
def get(cls, block_type): """Return a :class:`BlockType` instance from the given parameter. * If it's already a BlockType instance, return that. * If it exactly matches the command on a :class:`PluginBlockType`, return the corresponding BlockType. * If it loosely matches the...
python
def get(cls, block_type): """Return a :class:`BlockType` instance from the given parameter. * If it's already a BlockType instance, return that. * If it exactly matches the command on a :class:`PluginBlockType`, return the corresponding BlockType. * If it loosely matches the...
[ "def", "get", "(", "cls", ",", "block_type", ")", ":", "if", "isinstance", "(", "block_type", ",", "(", "BlockType", ",", "CustomBlockType", ")", ")", ":", "return", "block_type", "if", "isinstance", "(", "block_type", ",", "PluginBlockType", ")", ":", "bl...
Return a :class:`BlockType` instance from the given parameter. * If it's already a BlockType instance, return that. * If it exactly matches the command on a :class:`PluginBlockType`, return the corresponding BlockType. * If it loosely matches the text on a PluginBlockType, return th...
[ "Return", "a", ":", "class", ":", "BlockType", "instance", "from", "the", "given", "parameter", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1617-L1653
tjvr/kurt
kurt/__init__.py
Block.copy
def copy(self): """Return a new Block instance with the same attributes.""" args = [] for arg in self.args: if isinstance(arg, Block): arg = arg.copy() elif isinstance(arg, list): arg = [b.copy() for b in arg] args.append(arg) ...
python
def copy(self): """Return a new Block instance with the same attributes.""" args = [] for arg in self.args: if isinstance(arg, Block): arg = arg.copy() elif isinstance(arg, list): arg = [b.copy() for b in arg] args.append(arg) ...
[ "def", "copy", "(", "self", ")", ":", "args", "=", "[", "]", "for", "arg", "in", "self", ".", "args", ":", "if", "isinstance", "(", "arg", ",", "Block", ")", ":", "arg", "=", "arg", ".", "copy", "(", ")", "elif", "isinstance", "(", "arg", ",", ...
Return a new Block instance with the same attributes.
[ "Return", "a", "new", "Block", "instance", "with", "the", "same", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1844-L1853
tjvr/kurt
kurt/__init__.py
Script.copy
def copy(self): """Return a new instance with the same attributes.""" return self.__class__([b.copy() for b in self.blocks], tuple(self.pos) if self.pos else None)
python
def copy(self): """Return a new instance with the same attributes.""" return self.__class__([b.copy() for b in self.blocks], tuple(self.pos) if self.pos else None)
[ "def", "copy", "(", "self", ")", ":", "return", "self", ".", "__class__", "(", "[", "b", ".", "copy", "(", ")", "for", "b", "in", "self", ".", "blocks", "]", ",", "tuple", "(", "self", ".", "pos", ")", "if", "self", ".", "pos", "else", "None", ...
Return a new instance with the same attributes.
[ "Return", "a", "new", "instance", "with", "the", "same", "attributes", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L1929-L1932
tjvr/kurt
kurt/__init__.py
Costume.load
def load(self, path): """Load costume from image file. Uses :attr:`Image.load`, but will set the Costume's name based on the image filename. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) return Costume(name, Image.lo...
python
def load(self, path): """Load costume from image file. Uses :attr:`Image.load`, but will set the Costume's name based on the image filename. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) return Costume(name, Image.lo...
[ "def", "load", "(", "self", ",", "path", ")", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "(", "name", ",", "extension", ")", "=", "os", ".", "path", ".", "splitext", "(", "filename", ")", "...
Load costume from image file. Uses :attr:`Image.load`, but will set the Costume's name based on the image filename.
[ "Load", "costume", "from", "image", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2043-L2052
tjvr/kurt
kurt/__init__.py
Image.pil_image
def pil_image(self): """A :class:`PIL.Image.Image` instance containing the image data.""" if not self._pil_image: if self._format == "SVG": raise VectorImageError("can't rasterise vector images") self._pil_image = PIL.Image.open(StringIO(self.contents)) re...
python
def pil_image(self): """A :class:`PIL.Image.Image` instance containing the image data.""" if not self._pil_image: if self._format == "SVG": raise VectorImageError("can't rasterise vector images") self._pil_image = PIL.Image.open(StringIO(self.contents)) re...
[ "def", "pil_image", "(", "self", ")", ":", "if", "not", "self", ".", "_pil_image", ":", "if", "self", ".", "_format", "==", "\"SVG\"", ":", "raise", "VectorImageError", "(", "\"can't rasterise vector images\"", ")", "self", ".", "_pil_image", "=", "PIL", "."...
A :class:`PIL.Image.Image` instance containing the image data.
[ "A", ":", "class", ":", "PIL", ".", "Image", ".", "Image", "instance", "containing", "the", "image", "data", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2145-L2151
tjvr/kurt
kurt/__init__.py
Image.contents
def contents(self): """The raw file contents as a string.""" if not self._contents: if self._path: # Read file into memory so we don't run out of file descriptors f = open(self._path, "rb") self._contents = f.read() f.close() ...
python
def contents(self): """The raw file contents as a string.""" if not self._contents: if self._path: # Read file into memory so we don't run out of file descriptors f = open(self._path, "rb") self._contents = f.read() f.close() ...
[ "def", "contents", "(", "self", ")", ":", "if", "not", "self", ".", "_contents", ":", "if", "self", ".", "_path", ":", "# Read file into memory so we don't run out of file descriptors", "f", "=", "open", "(", "self", ".", "_path", ",", "\"rb\"", ")", "self", ...
The raw file contents as a string.
[ "The", "raw", "file", "contents", "as", "a", "string", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2154-L2167
tjvr/kurt
kurt/__init__.py
Image.format
def format(self): """The format of the image file. An uppercase string corresponding to the :attr:`PIL.ImageFile.ImageFile.format` attribute. Valid values include ``"JPEG"`` and ``"PNG"``. """ if self._format: return self._format elif self.pil_image...
python
def format(self): """The format of the image file. An uppercase string corresponding to the :attr:`PIL.ImageFile.ImageFile.format` attribute. Valid values include ``"JPEG"`` and ``"PNG"``. """ if self._format: return self._format elif self.pil_image...
[ "def", "format", "(", "self", ")", ":", "if", "self", ".", "_format", ":", "return", "self", ".", "_format", "elif", "self", ".", "pil_image", ":", "return", "self", ".", "pil_image", ".", "format" ]
The format of the image file. An uppercase string corresponding to the :attr:`PIL.ImageFile.ImageFile.format` attribute. Valid values include ``"JPEG"`` and ``"PNG"``.
[ "The", "format", "of", "the", "image", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2170-L2181
tjvr/kurt
kurt/__init__.py
Image.size
def size(self): """``(width, height)`` in pixels.""" if self._size and not self._pil_image: return self._size else: return self.pil_image.size
python
def size(self): """``(width, height)`` in pixels.""" if self._size and not self._pil_image: return self._size else: return self.pil_image.size
[ "def", "size", "(", "self", ")", ":", "if", "self", ".", "_size", "and", "not", "self", ".", "_pil_image", ":", "return", "self", ".", "_size", "else", ":", "return", "self", ".", "pil_image", ".", "size" ]
``(width, height)`` in pixels.
[ "(", "width", "height", ")", "in", "pixels", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2193-L2198
tjvr/kurt
kurt/__init__.py
Image.load
def load(cls, path): """Load image from file.""" assert os.path.exists(path), "No such file: %r" % path (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) image = Image(None) image._path = path image._format = Image.image_for...
python
def load(cls, path): """Load image from file.""" assert os.path.exists(path), "No such file: %r" % path (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) image = Image(None) image._path = path image._format = Image.image_for...
[ "def", "load", "(", "cls", ",", "path", ")", ":", "assert", "os", ".", "path", ".", "exists", "(", "path", ")", ",", "\"No such file: %r\"", "%", "path", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", ...
Load image from file.
[ "Load", "image", "from", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2211-L2222
tjvr/kurt
kurt/__init__.py
Image.convert
def convert(self, *formats): """Return an Image instance with the first matching format. For each format in ``*args``: If the image's :attr:`format` attribute is the same as the format, return self, otherwise try the next format. If none of the formats match, return a new Image instanc...
python
def convert(self, *formats): """Return an Image instance with the first matching format. For each format in ``*args``: If the image's :attr:`format` attribute is the same as the format, return self, otherwise try the next format. If none of the formats match, return a new Image instanc...
[ "def", "convert", "(", "self", ",", "*", "formats", ")", ":", "for", "format", "in", "formats", ":", "format", "=", "Image", ".", "image_format", "(", "format", ")", "if", "self", ".", "format", "==", "format", ":", "return", "self", "else", ":", "re...
Return an Image instance with the first matching format. For each format in ``*args``: If the image's :attr:`format` attribute is the same as the format, return self, otherwise try the next format. If none of the formats match, return a new Image instance with the last format.
[ "Return", "an", "Image", "instance", "with", "the", "first", "matching", "format", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2224-L2239
tjvr/kurt
kurt/__init__.py
Image._convert
def _convert(self, format): """Return a new Image instance with the given format. Returns self if the format is already the same. """ if self.format == format: return self else: image = Image(self.pil_image) image._format = format ...
python
def _convert(self, format): """Return a new Image instance with the given format. Returns self if the format is already the same. """ if self.format == format: return self else: image = Image(self.pil_image) image._format = format ...
[ "def", "_convert", "(", "self", ",", "format", ")", ":", "if", "self", ".", "format", "==", "format", ":", "return", "self", "else", ":", "image", "=", "Image", "(", "self", ".", "pil_image", ")", "image", ".", "_format", "=", "format", "return", "im...
Return a new Image instance with the given format. Returns self if the format is already the same.
[ "Return", "a", "new", "Image", "instance", "with", "the", "given", "format", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2241-L2252
tjvr/kurt
kurt/__init__.py
Image.save
def save(self, path): """Save image to file path. The image format is guessed from the extension. If path has no extension, the image's :attr:`format` is used. :returns: Path to the saved file. """ (folder, filename) = os.path.split(path) (name, extension) = os...
python
def save(self, path): """Save image to file path. The image format is guessed from the extension. If path has no extension, the image's :attr:`format` is used. :returns: Path to the saved file. """ (folder, filename) = os.path.split(path) (name, extension) = os...
[ "def", "save", "(", "self", ",", "path", ")", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "(", "name", ",", "extension", ")", "=", "os", ".", "path", ".", "splitext", "(", "filename", ")", "...
Save image to file path. The image format is guessed from the extension. If path has no extension, the image's :attr:`format` is used. :returns: Path to the saved file.
[ "Save", "image", "to", "file", "path", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2254-L2284
tjvr/kurt
kurt/__init__.py
Image.new
def new(self, size, fill): """Return a new Image instance filled with a color.""" return Image(PIL.Image.new("RGB", size, fill))
python
def new(self, size, fill): """Return a new Image instance filled with a color.""" return Image(PIL.Image.new("RGB", size, fill))
[ "def", "new", "(", "self", ",", "size", ",", "fill", ")", ":", "return", "Image", "(", "PIL", ".", "Image", ".", "new", "(", "\"RGB\"", ",", "size", ",", "fill", ")", ")" ]
Return a new Image instance filled with a color.
[ "Return", "a", "new", "Image", "instance", "filled", "with", "a", "color", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2287-L2289
tjvr/kurt
kurt/__init__.py
Image.resize
def resize(self, size): """Return a new Image instance with the given size.""" return Image(self.pil_image.resize(size, PIL.Image.ANTIALIAS))
python
def resize(self, size): """Return a new Image instance with the given size.""" return Image(self.pil_image.resize(size, PIL.Image.ANTIALIAS))
[ "def", "resize", "(", "self", ",", "size", ")", ":", "return", "Image", "(", "self", ".", "pil_image", ".", "resize", "(", "size", ",", "PIL", ".", "Image", ".", "ANTIALIAS", ")", ")" ]
Return a new Image instance with the given size.
[ "Return", "a", "new", "Image", "instance", "with", "the", "given", "size", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2291-L2293
tjvr/kurt
kurt/__init__.py
Image.paste
def paste(self, other): """Return a new Image with the given image pasted on top. This image will show through transparent areas of the given image. """ r, g, b, alpha = other.pil_image.split() pil_image = self.pil_image.copy() pil_image.paste(other.pil_image, mask=alph...
python
def paste(self, other): """Return a new Image with the given image pasted on top. This image will show through transparent areas of the given image. """ r, g, b, alpha = other.pil_image.split() pil_image = self.pil_image.copy() pil_image.paste(other.pil_image, mask=alph...
[ "def", "paste", "(", "self", ",", "other", ")", ":", "r", ",", "g", ",", "b", ",", "alpha", "=", "other", ".", "pil_image", ".", "split", "(", ")", "pil_image", "=", "self", ".", "pil_image", ".", "copy", "(", ")", "pil_image", ".", "paste", "(",...
Return a new Image with the given image pasted on top. This image will show through transparent areas of the given image.
[ "Return", "a", "new", "Image", "with", "the", "given", "image", "pasted", "on", "top", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2295-L2304
tjvr/kurt
kurt/__init__.py
Sound.load
def load(self, path): """Load sound from wave file. Uses :attr:`Waveform.load`, but will set the Waveform's name based on the sound filename. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) return Sound(name, Waveform....
python
def load(self, path): """Load sound from wave file. Uses :attr:`Waveform.load`, but will set the Waveform's name based on the sound filename. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) return Sound(name, Waveform....
[ "def", "load", "(", "self", ",", "path", ")", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "(", "name", ",", "extension", ")", "=", "os", ".", "path", ".", "splitext", "(", "filename", ")", "...
Load sound from wave file. Uses :attr:`Waveform.load`, but will set the Waveform's name based on the sound filename.
[ "Load", "sound", "from", "wave", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2347-L2356
tjvr/kurt
kurt/__init__.py
Sound.save
def save(self, path): """Save the sound to a wave file at the given path. Uses :attr:`Waveform.save`, but if the path ends in a folder instead of a file, the filename is based on the project's :attr:`name`. :returns: Path to the saved file. """ (folder, filename) = os....
python
def save(self, path): """Save the sound to a wave file at the given path. Uses :attr:`Waveform.save`, but if the path ends in a folder instead of a file, the filename is based on the project's :attr:`name`. :returns: Path to the saved file. """ (folder, filename) = os....
[ "def", "save", "(", "self", ",", "path", ")", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "if", "not", "filename", ":", "filename", "=", "_clean_filename", "(", "self", ".", "name", ")", "path",...
Save the sound to a wave file at the given path. Uses :attr:`Waveform.save`, but if the path ends in a folder instead of a file, the filename is based on the project's :attr:`name`. :returns: Path to the saved file.
[ "Save", "the", "sound", "to", "a", "wave", "file", "at", "the", "given", "path", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2358-L2371
tjvr/kurt
kurt/__init__.py
Waveform.contents
def contents(self): """The raw file contents as a string.""" if not self._contents: if self._path: # Read file into memory so we don't run out of file descriptors f = open(self._path, "rb") self._contents = f.read() f.close() ...
python
def contents(self): """The raw file contents as a string.""" if not self._contents: if self._path: # Read file into memory so we don't run out of file descriptors f = open(self._path, "rb") self._contents = f.read() f.close() ...
[ "def", "contents", "(", "self", ")", ":", "if", "not", "self", ".", "_contents", ":", "if", "self", ".", "_path", ":", "# Read file into memory so we don't run out of file descriptors", "f", "=", "open", "(", "self", ".", "_path", ",", "\"rb\"", ")", "self", ...
The raw file contents as a string.
[ "The", "raw", "file", "contents", "as", "a", "string", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2405-L2413
tjvr/kurt
kurt/__init__.py
Waveform._wave
def _wave(self): """Return a wave.Wave_read instance from the ``wave`` module.""" try: return wave.open(StringIO(self.contents)) except wave.Error, err: err.message += "\nInvalid wave file: %s" % self err.args = (err.message,) raise
python
def _wave(self): """Return a wave.Wave_read instance from the ``wave`` module.""" try: return wave.open(StringIO(self.contents)) except wave.Error, err: err.message += "\nInvalid wave file: %s" % self err.args = (err.message,) raise
[ "def", "_wave", "(", "self", ")", ":", "try", ":", "return", "wave", ".", "open", "(", "StringIO", "(", "self", ".", "contents", ")", ")", "except", "wave", ".", "Error", ",", "err", ":", "err", ".", "message", "+=", "\"\\nInvalid wave file: %s\"", "%"...
Return a wave.Wave_read instance from the ``wave`` module.
[ "Return", "a", "wave", ".", "Wave_read", "instance", "from", "the", "wave", "module", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2416-L2423
tjvr/kurt
kurt/__init__.py
Waveform.load
def load(cls, path): """Load Waveform from file.""" assert os.path.exists(path), "No such file: %r" % path (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) wave = Waveform(None) wave._path = path return wave
python
def load(cls, path): """Load Waveform from file.""" assert os.path.exists(path), "No such file: %r" % path (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) wave = Waveform(None) wave._path = path return wave
[ "def", "load", "(", "cls", ",", "path", ")", ":", "assert", "os", ".", "path", ".", "exists", "(", "path", ")", ",", "\"No such file: %r\"", "%", "path", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", ...
Load Waveform from file.
[ "Load", "Waveform", "from", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2445-L2454
tjvr/kurt
kurt/__init__.py
Waveform.save
def save(self, path): """Save waveform to file path as a WAV file. :returns: Path to the saved file. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) if not name: raise ValueError, "name is required" path ...
python
def save(self, path): """Save waveform to file path as a WAV file. :returns: Path to the saved file. """ (folder, filename) = os.path.split(path) (name, extension) = os.path.splitext(filename) if not name: raise ValueError, "name is required" path ...
[ "def", "save", "(", "self", ",", "path", ")", ":", "(", "folder", ",", "filename", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "(", "name", ",", "extension", ")", "=", "os", ".", "path", ".", "splitext", "(", "filename", ")", "...
Save waveform to file path as a WAV file. :returns: Path to the saved file.
[ "Save", "waveform", "to", "file", "path", "as", "a", "WAV", "file", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/kurt/__init__.py#L2456-L2473
tjvr/kurt
examples/images.py
sort_nicely
def sort_nicely(l): """Sort the given list in the way that humans expect.""" convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] l.sort(key=alphanum_key)
python
def sort_nicely(l): """Sort the given list in the way that humans expect.""" convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] l.sort(key=alphanum_key)
[ "def", "sort_nicely", "(", "l", ")", ":", "convert", "=", "lambda", "text", ":", "int", "(", "text", ")", "if", "text", ".", "isdigit", "(", ")", "else", "text", "alphanum_key", "=", "lambda", "key", ":", "[", "convert", "(", "c", ")", "for", "c", ...
Sort the given list in the way that humans expect.
[ "Sort", "the", "given", "list", "in", "the", "way", "that", "humans", "expect", "." ]
train
https://github.com/tjvr/kurt/blob/fcccd80cae11dc233f6dd02b40ec9a388c62f259/examples/images.py#L22-L26
benjamin-hodgson/asynqp
src/asynqp/connection.py
Connection.open_channel
def open_channel(self): """ Open a new channel on this connection. This method is a :ref:`coroutine <coroutine>`. :return: The new :class:`Channel` object. """ if self._closing: raise ConnectionClosed("Closed by application") if self.closed.done(): ...
python
def open_channel(self): """ Open a new channel on this connection. This method is a :ref:`coroutine <coroutine>`. :return: The new :class:`Channel` object. """ if self._closing: raise ConnectionClosed("Closed by application") if self.closed.done(): ...
[ "def", "open_channel", "(", "self", ")", ":", "if", "self", ".", "_closing", ":", "raise", "ConnectionClosed", "(", "\"Closed by application\"", ")", "if", "self", ".", "closed", ".", "done", "(", ")", ":", "raise", "self", ".", "closed", ".", "exception",...
Open a new channel on this connection. This method is a :ref:`coroutine <coroutine>`. :return: The new :class:`Channel` object.
[ "Open", "a", "new", "channel", "on", "this", "connection", "." ]
train
https://github.com/benjamin-hodgson/asynqp/blob/ea8630d1803d10d4fd64b1a0e50f3097710b34d1/src/asynqp/connection.py#L50-L64
benjamin-hodgson/asynqp
src/asynqp/connection.py
Connection.close
def close(self): """ Close the connection by handshaking with the server. This method is a :ref:`coroutine <coroutine>`. """ if not self.is_closed(): self._closing = True # Let the ConnectionActor do the actual close operations. # It will do t...
python
def close(self): """ Close the connection by handshaking with the server. This method is a :ref:`coroutine <coroutine>`. """ if not self.is_closed(): self._closing = True # Let the ConnectionActor do the actual close operations. # It will do t...
[ "def", "close", "(", "self", ")", ":", "if", "not", "self", ".", "is_closed", "(", ")", ":", "self", ".", "_closing", "=", "True", "# Let the ConnectionActor do the actual close operations.", "# It will do the work on CloseOK", "self", ".", "sender", ".", "send_Clos...
Close the connection by handshaking with the server. This method is a :ref:`coroutine <coroutine>`.
[ "Close", "the", "connection", "by", "handshaking", "with", "the", "server", "." ]
train
https://github.com/benjamin-hodgson/asynqp/blob/ea8630d1803d10d4fd64b1a0e50f3097710b34d1/src/asynqp/connection.py#L71-L93
benjamin-hodgson/asynqp
src/asynqp/connection.py
ConnectionActor.handle_PoisonPillFrame
def handle_PoisonPillFrame(self, frame): """ Is sent in case protocol lost connection to server.""" # Will be delivered after Close or CloseOK handlers. It's for channels, # so ignore it. if self.connection.closed.done(): return # If connection was not closed already ...
python
def handle_PoisonPillFrame(self, frame): """ Is sent in case protocol lost connection to server.""" # Will be delivered after Close or CloseOK handlers. It's for channels, # so ignore it. if self.connection.closed.done(): return # If connection was not closed already ...
[ "def", "handle_PoisonPillFrame", "(", "self", ",", "frame", ")", ":", "# Will be delivered after Close or CloseOK handlers. It's for channels,", "# so ignore it.", "if", "self", ".", "connection", ".", "closed", ".", "done", "(", ")", ":", "return", "# If connection was n...
Is sent in case protocol lost connection to server.
[ "Is", "sent", "in", "case", "protocol", "lost", "connection", "to", "server", "." ]
train
https://github.com/benjamin-hodgson/asynqp/blob/ea8630d1803d10d4fd64b1a0e50f3097710b34d1/src/asynqp/connection.py#L174-L182
benjamin-hodgson/asynqp
src/asynqp/connection.py
ConnectionActor.handle_ConnectionClose
def handle_ConnectionClose(self, frame): """ AMQP server closed the channel with an error """ # Notify server we are OK to close. self.sender.send_CloseOK() exc = ConnectionClosed(frame.payload.reply_text, frame.payload.reply_code) self._close_all(...
python
def handle_ConnectionClose(self, frame): """ AMQP server closed the channel with an error """ # Notify server we are OK to close. self.sender.send_CloseOK() exc = ConnectionClosed(frame.payload.reply_text, frame.payload.reply_code) self._close_all(...
[ "def", "handle_ConnectionClose", "(", "self", ",", "frame", ")", ":", "# Notify server we are OK to close.", "self", ".", "sender", ".", "send_CloseOK", "(", ")", "exc", "=", "ConnectionClosed", "(", "frame", ".", "payload", ".", "reply_text", ",", "frame", ".",...
AMQP server closed the channel with an error
[ "AMQP", "server", "closed", "the", "channel", "with", "an", "error" ]
train
https://github.com/benjamin-hodgson/asynqp/blob/ea8630d1803d10d4fd64b1a0e50f3097710b34d1/src/asynqp/connection.py#L184-L194
benjamin-hodgson/asynqp
src/asynqp/exchange.py
Exchange.publish
def publish(self, message, routing_key, *, mandatory=True): """ Publish a message on the exchange, to be asynchronously delivered to queues. :param asynqp.Message message: the message to send :param str routing_key: the routing key with which to publish the message :param bool m...
python
def publish(self, message, routing_key, *, mandatory=True): """ Publish a message on the exchange, to be asynchronously delivered to queues. :param asynqp.Message message: the message to send :param str routing_key: the routing key with which to publish the message :param bool m...
[ "def", "publish", "(", "self", ",", "message", ",", "routing_key", ",", "*", ",", "mandatory", "=", "True", ")", ":", "self", ".", "sender", ".", "send_BasicPublish", "(", "self", ".", "name", ",", "routing_key", ",", "mandatory", ",", "message", ")" ]
Publish a message on the exchange, to be asynchronously delivered to queues. :param asynqp.Message message: the message to send :param str routing_key: the routing key with which to publish the message :param bool mandatory: if True (the default) undeliverable messages result in an error (see a...
[ "Publish", "a", "message", "on", "the", "exchange", "to", "be", "asynchronously", "delivered", "to", "queues", "." ]
train
https://github.com/benjamin-hodgson/asynqp/blob/ea8630d1803d10d4fd64b1a0e50f3097710b34d1/src/asynqp/exchange.py#L35-L43