id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
17,900
scott-griffiths/bitstring
bitstring.py
Bits.findall
def findall(self, bs, start=None, end=None, count=None, bytealigned=None): """Find all occurrences of bs. Return generator of bit positions. bs -- The bitstring to find. start -- The bit position to start the search. Defaults to 0. end -- The bit position one past the last bit to search...
python
def findall(self, bs, start=None, end=None, count=None, bytealigned=None): """Find all occurrences of bs. Return generator of bit positions. bs -- The bitstring to find. start -- The bit position to start the search. Defaults to 0. end -- The bit position one past the last bit to search...
[ "def", "findall", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "if", "count", "is", "not", "None", "and", "count", "<", "0", ":", "raise", "Value...
Find all occurrences of bs. Return generator of bit positions. bs -- The bitstring to find. start -- The bit position to start the search. Defaults to 0. end -- The bit position one past the last bit to search. Defaults to self.len. count -- The maximum number of occurren...
[ "Find", "all", "occurrences", "of", "bs", ".", "Return", "generator", "of", "bit", "positions", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2449-L2499
17,901
scott-griffiths/bitstring
bitstring.py
Bits.rfind
def rfind(self, bs, start=None, end=None, bytealigned=None): """Find final occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is foun...
python
def rfind(self, bs, start=None, end=None, bytealigned=None): """Find final occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is foun...
[ "def", "rfind", "(", "self", ",", "bs", ",", "start", "=", "None", ",", "end", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",",...
Find final occurrence of substring bs. Returns a single item tuple with the bit position if found, or an empty tuple if not found. The bit position (pos property) will also be set to the start of the substring if it is found. bs -- The bitstring to find. start -- The bit positi...
[ "Find", "final", "occurrence", "of", "substring", "bs", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2501-L2538
17,902
scott-griffiths/bitstring
bitstring.py
Bits.cut
def cut(self, bits, start=None, end=None, count=None): """Return bitstring generator by cutting into bits sized chunks. bits -- The size in bits of the bitstring chunks to generate. start -- The bit position to start the first cut. Defaults to 0. end -- The bit position one past the las...
python
def cut(self, bits, start=None, end=None, count=None): """Return bitstring generator by cutting into bits sized chunks. bits -- The size in bits of the bitstring chunks to generate. start -- The bit position to start the first cut. Defaults to 0. end -- The bit position one past the las...
[ "def", "cut", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "count", "is", "not", ...
Return bitstring generator by cutting into bits sized chunks. bits -- The size in bits of the bitstring chunks to generate. start -- The bit position to start the first cut. Defaults to 0. end -- The bit position one past the last bit to use in the cut. Defaults to self.len. ...
[ "Return", "bitstring", "generator", "by", "cutting", "into", "bits", "sized", "chunks", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2540-L2565
17,903
scott-griffiths/bitstring
bitstring.py
Bits.split
def split(self, delimiter, start=None, end=None, count=None, bytealigned=None): """Return bitstring generator by splittling using a delimiter. The first item returned is the initial bitstring before the delimiter, which may be an empty bitstring. delimiter -- The bitstrin...
python
def split(self, delimiter, start=None, end=None, count=None, bytealigned=None): """Return bitstring generator by splittling using a delimiter. The first item returned is the initial bitstring before the delimiter, which may be an empty bitstring. delimiter -- The bitstrin...
[ "def", "split", "(", "self", ",", "delimiter", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "delimiter", "=", "Bits", "(", "delimiter", ")", "if", "not", "delimiter", ".", ...
Return bitstring generator by splittling using a delimiter. The first item returned is the initial bitstring before the delimiter, which may be an empty bitstring. delimiter -- The bitstring used as the divider. start -- The bit position to start the split. Defaults to 0. end -...
[ "Return", "bitstring", "generator", "by", "splittling", "using", "a", "delimiter", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2567-L2622
17,904
scott-griffiths/bitstring
bitstring.py
Bits.join
def join(self, sequence): """Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings. """ s = self.__class__() i = iter(sequence) try: s._append(Bits(next(i))) while True: n = next(i) ...
python
def join(self, sequence): """Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings. """ s = self.__class__() i = iter(sequence) try: s._append(Bits(next(i))) while True: n = next(i) ...
[ "def", "join", "(", "self", ",", "sequence", ")", ":", "s", "=", "self", ".", "__class__", "(", ")", "i", "=", "iter", "(", "sequence", ")", "try", ":", "s", ".", "_append", "(", "Bits", "(", "next", "(", "i", ")", ")", ")", "while", "True", ...
Return concatenation of bitstrings joined by self. sequence -- A sequence of bitstrings.
[ "Return", "concatenation", "of", "bitstrings", "joined", "by", "self", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2624-L2640
17,905
scott-griffiths/bitstring
bitstring.py
Bits.tobytes
def tobytes(self): """Return the bitstring as bytes, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align. """ d = offsetcopy(self._datastore, 0).rawbytes # Need to ensure that unused bits at end are set to zero unusedbits = 8 -...
python
def tobytes(self): """Return the bitstring as bytes, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align. """ d = offsetcopy(self._datastore, 0).rawbytes # Need to ensure that unused bits at end are set to zero unusedbits = 8 -...
[ "def", "tobytes", "(", "self", ")", ":", "d", "=", "offsetcopy", "(", "self", ".", "_datastore", ",", "0", ")", ".", "rawbytes", "# Need to ensure that unused bits at end are set to zero", "unusedbits", "=", "8", "-", "self", ".", "len", "%", "8", "if", "unu...
Return the bitstring as bytes, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align.
[ "Return", "the", "bitstring", "as", "bytes", "padding", "with", "zero", "bits", "if", "needed", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2642-L2653
17,906
scott-griffiths/bitstring
bitstring.py
Bits.tofile
def tofile(self, f): """Write the bitstring to a file object, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align. """ # If the bitstring is file based then we don't want to read it all # in to memory. chunksize = 1024 * 1024 #...
python
def tofile(self, f): """Write the bitstring to a file object, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align. """ # If the bitstring is file based then we don't want to read it all # in to memory. chunksize = 1024 * 1024 #...
[ "def", "tofile", "(", "self", ",", "f", ")", ":", "# If the bitstring is file based then we don't want to read it all", "# in to memory.", "chunksize", "=", "1024", "*", "1024", "# 1 MB chunks", "if", "not", "self", ".", "_offset", ":", "a", "=", "0", "bytelen", "...
Write the bitstring to a file object, padding with zero bits if needed. Up to seven zero bits will be added at the end to byte align.
[ "Write", "the", "bitstring", "to", "a", "file", "object", "padding", "with", "zero", "bits", "if", "needed", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2655-L2687
17,907
scott-griffiths/bitstring
bitstring.py
Bits.startswith
def startswith(self, prefix, start=None, end=None): """Return whether the current bitstring starts with prefix. prefix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len. """ pr...
python
def startswith(self, prefix, start=None, end=None): """Return whether the current bitstring starts with prefix. prefix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len. """ pr...
[ "def", "startswith", "(", "self", ",", "prefix", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "prefix", "=", "Bits", "(", "prefix", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if",...
Return whether the current bitstring starts with prefix. prefix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len.
[ "Return", "whether", "the", "current", "bitstring", "starts", "with", "prefix", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2689-L2702
17,908
scott-griffiths/bitstring
bitstring.py
Bits.endswith
def endswith(self, suffix, start=None, end=None): """Return whether the current bitstring ends with suffix. suffix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len. """ suffix...
python
def endswith(self, suffix, start=None, end=None): """Return whether the current bitstring ends with suffix. suffix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len. """ suffix...
[ "def", "endswith", "(", "self", ",", "suffix", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "suffix", "=", "Bits", "(", "suffix", ")", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", ...
Return whether the current bitstring ends with suffix. suffix -- The bitstring to search for. start -- The bit position to start from. Defaults to 0. end -- The bit position to end at. Defaults to self.len.
[ "Return", "whether", "the", "current", "bitstring", "ends", "with", "suffix", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2704-L2717
17,909
scott-griffiths/bitstring
bitstring.py
Bits.all
def all(self, value, pos=None): """Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way...
python
def all(self, value, pos=None): """Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way...
[ "def", "all", "(", "self", ",", "value", ",", "pos", "=", "None", ")", ":", "value", "=", "bool", "(", "value", ")", "length", "=", "self", ".", "len", "if", "pos", "is", "None", ":", "pos", "=", "xrange", "(", "self", ".", "len", ")", "for", ...
Return True if one or many bits are all set to value. value -- If value is True then checks for bits set to 1, otherwise checks for bits set to 0. pos -- An iterable of bit positions. Negative numbers are treated in the same way as slice indices. Defaults to the whole bi...
[ "Return", "True", "if", "one", "or", "many", "bits", "are", "all", "set", "to", "value", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2719-L2739
17,910
scott-griffiths/bitstring
bitstring.py
Bits.count
def count(self, value): """Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7 """ if not self.len: return 0 # co...
python
def count(self, value): """Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7 """ if not self.len: return 0 # co...
[ "def", "count", "(", "self", ",", "value", ")", ":", "if", "not", "self", ".", "len", ":", "return", "0", "# count the number of 1s (from which it's easy to work out the 0s).", "# Don't count the final byte yet.", "count", "=", "sum", "(", "BIT_COUNT", "[", "self", ...
Return count of total number of either zero or one bits. value -- If True then bits set to 1 are counted, otherwise bits set to 0 are counted. >>> Bits('0xef').count(1) 7
[ "Return", "count", "of", "total", "number", "of", "either", "zero", "or", "one", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L2763-L2784
17,911
scott-griffiths/bitstring
bitstring.py
BitArray.replace
def replace(self, old, new, start=None, end=None, count=None, bytealigned=None): """Replace all occurrences of old with new in place. Returns number of replacements made. old -- The bitstring to replace. new -- The replacement bitstring. start -- Any occurrences...
python
def replace(self, old, new, start=None, end=None, count=None, bytealigned=None): """Replace all occurrences of old with new in place. Returns number of replacements made. old -- The bitstring to replace. new -- The replacement bitstring. start -- Any occurrences...
[ "def", "replace", "(", "self", ",", "old", ",", "new", ",", "start", "=", "None", ",", "end", "=", "None", ",", "count", "=", "None", ",", "bytealigned", "=", "None", ")", ":", "old", "=", "Bits", "(", "old", ")", "new", "=", "Bits", "(", "new"...
Replace all occurrences of old with new in place. Returns number of replacements made. old -- The bitstring to replace. new -- The replacement bitstring. start -- Any occurrences that start before this will not be replaced. Defaults to 0. end -- Any occurrences...
[ "Replace", "all", "occurrences", "of", "old", "with", "new", "in", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3298-L3363
17,912
scott-griffiths/bitstring
bitstring.py
BitArray.insert
def insert(self, bs, pos=None): """Insert bs at bit position pos. bs -- The bitstring to insert. pos -- The bit position to insert at. Raises ValueError if pos < 0 or pos > self.len. """ bs = Bits(bs) if not bs.len: return self if bs is self...
python
def insert(self, bs, pos=None): """Insert bs at bit position pos. bs -- The bitstring to insert. pos -- The bit position to insert at. Raises ValueError if pos < 0 or pos > self.len. """ bs = Bits(bs) if not bs.len: return self if bs is self...
[ "def", "insert", "(", "self", ",", "bs", ",", "pos", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "return", "self", "if", "bs", "is", "self", ":", "bs", "=", "self", ".", "__copy__", "(", ")", ...
Insert bs at bit position pos. bs -- The bitstring to insert. pos -- The bit position to insert at. Raises ValueError if pos < 0 or pos > self.len.
[ "Insert", "bs", "at", "bit", "position", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3365-L3388
17,913
scott-griffiths/bitstring
bitstring.py
BitArray.overwrite
def overwrite(self, bs, pos=None): """Overwrite with bs at bit position pos. bs -- The bitstring to overwrite with. pos -- The bit position to begin overwriting from. Raises ValueError if pos < 0 or pos + bs.len > self.len """ bs = Bits(bs) if not bs.len: ...
python
def overwrite(self, bs, pos=None): """Overwrite with bs at bit position pos. bs -- The bitstring to overwrite with. pos -- The bit position to begin overwriting from. Raises ValueError if pos < 0 or pos + bs.len > self.len """ bs = Bits(bs) if not bs.len: ...
[ "def", "overwrite", "(", "self", ",", "bs", ",", "pos", "=", "None", ")", ":", "bs", "=", "Bits", "(", "bs", ")", "if", "not", "bs", ".", "len", ":", "return", "if", "pos", "is", "None", ":", "try", ":", "pos", "=", "self", ".", "_pos", "exce...
Overwrite with bs at bit position pos. bs -- The bitstring to overwrite with. pos -- The bit position to begin overwriting from. Raises ValueError if pos < 0 or pos + bs.len > self.len
[ "Overwrite", "with", "bs", "at", "bit", "position", "pos", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3390-L3415
17,914
scott-griffiths/bitstring
bitstring.py
BitArray.append
def append(self, bs): """Append a bitstring to the current bitstring. bs -- The bitstring to append. """ # The offset is a hint to make bs easily appendable. bs = self._converttobitstring(bs, offset=(self.len + self._offset) % 8) self._append(bs)
python
def append(self, bs): """Append a bitstring to the current bitstring. bs -- The bitstring to append. """ # The offset is a hint to make bs easily appendable. bs = self._converttobitstring(bs, offset=(self.len + self._offset) % 8) self._append(bs)
[ "def", "append", "(", "self", ",", "bs", ")", ":", "# The offset is a hint to make bs easily appendable.", "bs", "=", "self", ".", "_converttobitstring", "(", "bs", ",", "offset", "=", "(", "self", ".", "len", "+", "self", ".", "_offset", ")", "%", "8", ")...
Append a bitstring to the current bitstring. bs -- The bitstring to append.
[ "Append", "a", "bitstring", "to", "the", "current", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3417-L3425
17,915
scott-griffiths/bitstring
bitstring.py
BitArray.reverse
def reverse(self, start=None, end=None): """Reverse bits in-place. start -- Position of first bit to reverse. Defaults to 0. end -- One past the position of the last bit to reverse. Defaults to self.len. Using on an empty bitstring will have no effect. Raises Va...
python
def reverse(self, start=None, end=None): """Reverse bits in-place. start -- Position of first bit to reverse. Defaults to 0. end -- One past the position of the last bit to reverse. Defaults to self.len. Using on an empty bitstring will have no effect. Raises Va...
[ "def", "reverse", "(", "self", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "start", "==", "0", "and", "end", "==", "self", ".", "len"...
Reverse bits in-place. start -- Position of first bit to reverse. Defaults to 0. end -- One past the position of the last bit to reverse. Defaults to self.len. Using on an empty bitstring will have no effect. Raises ValueError if start < 0, end > self.len or end < start...
[ "Reverse", "bits", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3436-L3454
17,916
scott-griffiths/bitstring
bitstring.py
BitArray.set
def set(self, value, pos=None): """Set one or many bits to 1 or 0. value -- If True bits are set to 1, otherwise they are set to 0. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. D...
python
def set(self, value, pos=None): """Set one or many bits to 1 or 0. value -- If True bits are set to 1, otherwise they are set to 0. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. D...
[ "def", "set", "(", "self", ",", "value", ",", "pos", "=", "None", ")", ":", "f", "=", "self", ".", "_set", "if", "value", "else", "self", ".", "_unset", "if", "pos", "is", "None", ":", "pos", "=", "xrange", "(", "self", ".", "len", ")", "try", ...
Set one or many bits to 1 or 0. value -- If True bits are set to 1, otherwise they are set to 0. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. Defaults to the entire bitstring. R...
[ "Set", "one", "or", "many", "bits", "to", "1", "or", "0", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3456-L3484
17,917
scott-griffiths/bitstring
bitstring.py
BitArray.invert
def invert(self, pos=None): """Invert one or many bits from 0 to 1 or vice versa. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. Raises IndexError if pos < -self.len or pos >= self.len. ...
python
def invert(self, pos=None): """Invert one or many bits from 0 to 1 or vice versa. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. Raises IndexError if pos < -self.len or pos >= self.len. ...
[ "def", "invert", "(", "self", ",", "pos", "=", "None", ")", ":", "if", "pos", "is", "None", ":", "self", ".", "_invert_all", "(", ")", "return", "if", "not", "isinstance", "(", "pos", ",", "collections", ".", "Iterable", ")", ":", "pos", "=", "(", ...
Invert one or many bits from 0 to 1 or vice versa. pos -- Either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices. Raises IndexError if pos < -self.len or pos >= self.len.
[ "Invert", "one", "or", "many", "bits", "from", "0", "to", "1", "or", "vice", "versa", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3486-L3507
17,918
scott-griffiths/bitstring
bitstring.py
BitArray.ror
def ror(self, bits, start=None, end=None): """Rotate bits to the right in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0. """ i...
python
def ror(self, bits, start=None, end=None): """Rotate bits to the right in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0. """ i...
[ "def", "ror", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "if", "not", "self", ".", "len", ":", "raise", "Error", "(", "\"Cannot rotate an empty bitstring.\"", ")", "if", "bits", "<", "0", ":", "raise", "Va...
Rotate bits to the right in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0.
[ "Rotate", "bits", "to", "the", "right", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3509-L3529
17,919
scott-griffiths/bitstring
bitstring.py
BitArray.rol
def rol(self, bits, start=None, end=None): """Rotate bits to the left in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0. """ if...
python
def rol(self, bits, start=None, end=None): """Rotate bits to the left in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0. """ if...
[ "def", "rol", "(", "self", ",", "bits", ",", "start", "=", "None", ",", "end", "=", "None", ")", ":", "if", "not", "self", ".", "len", ":", "raise", "Error", "(", "\"Cannot rotate an empty bitstring.\"", ")", "if", "bits", "<", "0", ":", "raise", "Va...
Rotate bits to the left in-place. bits -- The number of bits to rotate by. start -- Start of slice to rotate. Defaults to 0. end -- End of slice to rotate. Defaults to self.len. Raises ValueError if bits < 0.
[ "Rotate", "bits", "to", "the", "left", "in", "-", "place", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3531-L3551
17,920
scott-griffiths/bitstring
bitstring.py
BitArray.byteswap
def byteswap(self, fmt=None, start=None, end=None, repeat=True): """Change the endianness in-place. Return number of repeats of fmt done. fmt -- A compact structure string, an integer number of bytes or an iterable of integers. Defaults to 0, which byte reverses the whole ...
python
def byteswap(self, fmt=None, start=None, end=None, repeat=True): """Change the endianness in-place. Return number of repeats of fmt done. fmt -- A compact structure string, an integer number of bytes or an iterable of integers. Defaults to 0, which byte reverses the whole ...
[ "def", "byteswap", "(", "self", ",", "fmt", "=", "None", ",", "start", "=", "None", ",", "end", "=", "None", ",", "repeat", "=", "True", ")", ":", "start", ",", "end", "=", "self", ".", "_validate_slice", "(", "start", ",", "end", ")", "if", "fmt...
Change the endianness in-place. Return number of repeats of fmt done. fmt -- A compact structure string, an integer number of bytes or an iterable of integers. Defaults to 0, which byte reverses the whole bitstring. start -- Start bit position, defaults to 0. end -...
[ "Change", "the", "endianness", "in", "-", "place", ".", "Return", "number", "of", "repeats", "of", "fmt", "done", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3553-L3611
17,921
scott-griffiths/bitstring
bitstring.py
ConstBitStream._setbitpos
def _setbitpos(self, pos): """Move to absolute postion bit in bitstream.""" if pos < 0: raise ValueError("Bit position cannot be negative.") if pos > self.len: raise ValueError("Cannot seek past the end of the data.") self._pos = pos
python
def _setbitpos(self, pos): """Move to absolute postion bit in bitstream.""" if pos < 0: raise ValueError("Bit position cannot be negative.") if pos > self.len: raise ValueError("Cannot seek past the end of the data.") self._pos = pos
[ "def", "_setbitpos", "(", "self", ",", "pos", ")", ":", "if", "pos", "<", "0", ":", "raise", "ValueError", "(", "\"Bit position cannot be negative.\"", ")", "if", "pos", ">", "self", ".", "len", ":", "raise", "ValueError", "(", "\"Cannot seek past the end of t...
Move to absolute postion bit in bitstream.
[ "Move", "to", "absolute", "postion", "bit", "in", "bitstream", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3806-L3812
17,922
scott-griffiths/bitstring
bitstring.py
ConstBitStream.read
def read(self, fmt): """Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer ...
python
def read(self, fmt): """Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer ...
[ "def", "read", "(", "self", ",", "fmt", ")", ":", "if", "isinstance", "(", "fmt", ",", "numbers", ".", "Integral", ")", ":", "if", "fmt", "<", "0", ":", "raise", "ValueError", "(", "\"Cannot read negative amount.\"", ")", "if", "fmt", ">", "self", ".",...
Interpret next bits according to the format string and return result. fmt -- Token string describing how to interpret the next bits. Token examples: 'int:12' : 12 bits as a signed integer 'uint:8' : 8 bits as an unsigned integer 'float:64' : 8 byt...
[ "Interpret", "next", "bits", "according", "to", "the", "format", "string", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3842-L3897
17,923
scott-griffiths/bitstring
bitstring.py
ConstBitStream.readto
def readto(self, bs, bytealigned=None): """Read up to and including next occurrence of bs and return result. bs -- The bitstring to find. An integer is not permitted. bytealigned -- If True the bitstring will only be found on byte boundaries. Raises ValueError if...
python
def readto(self, bs, bytealigned=None): """Read up to and including next occurrence of bs and return result. bs -- The bitstring to find. An integer is not permitted. bytealigned -- If True the bitstring will only be found on byte boundaries. Raises ValueError if...
[ "def", "readto", "(", "self", ",", "bs", ",", "bytealigned", "=", "None", ")", ":", "if", "isinstance", "(", "bs", ",", "numbers", ".", "Integral", ")", ":", "raise", "ValueError", "(", "\"Integers cannot be searched for\"", ")", "bs", "=", "Bits", "(", ...
Read up to and including next occurrence of bs and return result. bs -- The bitstring to find. An integer is not permitted. bytealigned -- If True the bitstring will only be found on byte boundaries. Raises ValueError if bs is empty. Raises ReadError if bs is not...
[ "Read", "up", "to", "and", "including", "next", "occurrence", "of", "bs", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3923-L3942
17,924
scott-griffiths/bitstring
bitstring.py
ConstBitStream.peek
def peek(self, fmt): """Interpret next bits according to format string and return result. fmt -- Token string describing how to interpret the next bits. The position in the bitstring is not changed. If not enough bits are available then all bits to the end of the bitstring will be used...
python
def peek(self, fmt): """Interpret next bits according to format string and return result. fmt -- Token string describing how to interpret the next bits. The position in the bitstring is not changed. If not enough bits are available then all bits to the end of the bitstring will be used...
[ "def", "peek", "(", "self", ",", "fmt", ")", ":", "pos_before", "=", "self", ".", "_pos", "value", "=", "self", ".", "read", "(", "fmt", ")", "self", ".", "_pos", "=", "pos_before", "return", "value" ]
Interpret next bits according to format string and return result. fmt -- Token string describing how to interpret the next bits. The position in the bitstring is not changed. If not enough bits are available then all bits to the end of the bitstring will be used. Raises ReadError if n...
[ "Interpret", "next", "bits", "according", "to", "format", "string", "and", "return", "result", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3944-L3961
17,925
scott-griffiths/bitstring
bitstring.py
ConstBitStream.bytealign
def bytealign(self): """Align to next byte and return number of skipped bits. Raises ValueError if the end of the bitstring is reached before aligning to the next byte. """ skipped = (8 - (self._pos % 8)) % 8 self.pos += self._offset + skipped assert self._asser...
python
def bytealign(self): """Align to next byte and return number of skipped bits. Raises ValueError if the end of the bitstring is reached before aligning to the next byte. """ skipped = (8 - (self._pos % 8)) % 8 self.pos += self._offset + skipped assert self._asser...
[ "def", "bytealign", "(", "self", ")", ":", "skipped", "=", "(", "8", "-", "(", "self", ".", "_pos", "%", "8", ")", ")", "%", "8", "self", ".", "pos", "+=", "self", ".", "_offset", "+", "skipped", "assert", "self", ".", "_assertsanity", "(", ")", ...
Align to next byte and return number of skipped bits. Raises ValueError if the end of the bitstring is reached before aligning to the next byte.
[ "Align", "to", "next", "byte", "and", "return", "number", "of", "skipped", "bits", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L3985-L3995
17,926
scott-griffiths/bitstring
bitstring.py
BitStream.prepend
def prepend(self, bs): """Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend. """ bs = self._converttobitstring(bs) self._prepend(bs) self._pos += bs.len
python
def prepend(self, bs): """Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend. """ bs = self._converttobitstring(bs) self._prepend(bs) self._pos += bs.len
[ "def", "prepend", "(", "self", ",", "bs", ")", ":", "bs", "=", "self", ".", "_converttobitstring", "(", "bs", ")", "self", ".", "_prepend", "(", "bs", ")", "self", ".", "_pos", "+=", "bs", ".", "len" ]
Prepend a bitstring to the current bitstring. bs -- The bitstring to prepend.
[ "Prepend", "a", "bitstring", "to", "the", "current", "bitstring", "." ]
ab40ae7f0b43fe223a39b63cbc0529b09f3ef653
https://github.com/scott-griffiths/bitstring/blob/ab40ae7f0b43fe223a39b63cbc0529b09f3ef653/bitstring.py#L4150-L4158
17,927
g2p/bedup
bedup/dedup.py
find_inodes_in_use
def find_inodes_in_use(fds): """ Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd a...
python
def find_inodes_in_use(fds): """ Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd a...
[ "def", "find_inodes_in_use", "(", "fds", ")", ":", "self_pid", "=", "os", ".", "getpid", "(", ")", "id_fd_assoc", "=", "collections", ".", "defaultdict", "(", "list", ")", "for", "fd", "in", "fds", ":", "st", "=", "os", ".", "fstat", "(", "fd", ")", ...
Find which of these inodes are in use, and give their open modes. Does not count the passed fds as an use of the inode they point to, but if the current process has the same inodes open with different file descriptors these will be listed. Looks at /proc/*/fd and /proc/*/map_files (Linux 3.3). Con...
[ "Find", "which", "of", "these", "inodes", "are", "in", "use", "and", "give", "their", "open", "modes", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/dedup.py#L120-L186
17,928
g2p/bedup
bedup/platform/ioprio.py
set_idle_priority
def set_idle_priority(pid=None): """ Puts a process in the idle io priority class. If pid is omitted, applies to the current process. """ if pid is None: pid = os.getpid() lib.ioprio_set( lib.IOPRIO_WHO_PROCESS, pid, lib.IOPRIO_PRIO_VALUE(lib.IOPRIO_CLASS_IDLE, 0))
python
def set_idle_priority(pid=None): """ Puts a process in the idle io priority class. If pid is omitted, applies to the current process. """ if pid is None: pid = os.getpid() lib.ioprio_set( lib.IOPRIO_WHO_PROCESS, pid, lib.IOPRIO_PRIO_VALUE(lib.IOPRIO_CLASS_IDLE, 0))
[ "def", "set_idle_priority", "(", "pid", "=", "None", ")", ":", "if", "pid", "is", "None", ":", "pid", "=", "os", ".", "getpid", "(", ")", "lib", ".", "ioprio_set", "(", "lib", ".", "IOPRIO_WHO_PROCESS", ",", "pid", ",", "lib", ".", "IOPRIO_PRIO_VALUE",...
Puts a process in the idle io priority class. If pid is omitted, applies to the current process.
[ "Puts", "a", "process", "in", "the", "idle", "io", "priority", "class", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/ioprio.py#L82-L93
17,929
g2p/bedup
bedup/platform/futimens.py
futimens
def futimens(fd, ns): """ set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution. """ # ctime can't easily be reset # also, we have no way to do mandatory locking without # changing the ctime. times = ffi.new('struct timespec[2]') a...
python
def futimens(fd, ns): """ set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution. """ # ctime can't easily be reset # also, we have no way to do mandatory locking without # changing the ctime. times = ffi.new('struct timespec[2]') a...
[ "def", "futimens", "(", "fd", ",", "ns", ")", ":", "# ctime can't easily be reset", "# also, we have no way to do mandatory locking without", "# changing the ctime.", "times", "=", "ffi", ".", "new", "(", "'struct timespec[2]'", ")", "atime", ",", "mtime", "=", "ns", ...
set inode atime and mtime ns is (atime, mtime), a pair of struct timespec with nanosecond resolution.
[ "set", "inode", "atime", "and", "mtime" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/futimens.py#L70-L90
17,930
g2p/bedup
bedup/platform/openat.py
fopenat
def fopenat(base_fd, path): """ Does openat read-only, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDONLY), 'rb')
python
def fopenat(base_fd, path): """ Does openat read-only, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDONLY), 'rb')
[ "def", "fopenat", "(", "base_fd", ",", "path", ")", ":", "return", "os", ".", "fdopen", "(", "openat", "(", "base_fd", ",", "path", ",", "os", ".", "O_RDONLY", ")", ",", "'rb'", ")" ]
Does openat read-only, then does fdopen to get a file object
[ "Does", "openat", "read", "-", "only", "then", "does", "fdopen", "to", "get", "a", "file", "object" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/openat.py#L44-L49
17,931
g2p/bedup
bedup/platform/openat.py
fopenat_rw
def fopenat_rw(base_fd, path): """ Does openat read-write, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDWR), 'rb+')
python
def fopenat_rw(base_fd, path): """ Does openat read-write, then does fdopen to get a file object """ return os.fdopen(openat(base_fd, path, os.O_RDWR), 'rb+')
[ "def", "fopenat_rw", "(", "base_fd", ",", "path", ")", ":", "return", "os", ".", "fdopen", "(", "openat", "(", "base_fd", ",", "path", ",", "os", ".", "O_RDWR", ")", ",", "'rb+'", ")" ]
Does openat read-write, then does fdopen to get a file object
[ "Does", "openat", "read", "-", "write", "then", "does", "fdopen", "to", "get", "a", "file", "object" ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/openat.py#L52-L57
17,932
g2p/bedup
bedup/platform/fiemap.py
fiemap
def fiemap(fd): """ Gets a map of file extents. """ count = 72 fiemap_cbuf = ffi.new( 'char[]', ffi.sizeof('struct fiemap') + count * ffi.sizeof('struct fiemap_extent')) fiemap_pybuf = ffi.buffer(fiemap_cbuf) fiemap_ptr = ffi.cast('struct fiemap*', fiemap_cbuf) a...
python
def fiemap(fd): """ Gets a map of file extents. """ count = 72 fiemap_cbuf = ffi.new( 'char[]', ffi.sizeof('struct fiemap') + count * ffi.sizeof('struct fiemap_extent')) fiemap_pybuf = ffi.buffer(fiemap_cbuf) fiemap_ptr = ffi.cast('struct fiemap*', fiemap_cbuf) a...
[ "def", "fiemap", "(", "fd", ")", ":", "count", "=", "72", "fiemap_cbuf", "=", "ffi", ".", "new", "(", "'char[]'", ",", "ffi", ".", "sizeof", "(", "'struct fiemap'", ")", "+", "count", "*", "ffi", ".", "sizeof", "(", "'struct fiemap_extent'", ")", ")", ...
Gets a map of file extents.
[ "Gets", "a", "map", "of", "file", "extents", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/fiemap.py#L93-L118
17,933
g2p/bedup
bedup/platform/chattr.py
getflags
def getflags(fd): """ Gets per-file filesystem flags. """ flags_ptr = ffi.new('uint64_t*') flags_buf = ffi.buffer(flags_ptr) fcntl.ioctl(fd, lib.FS_IOC_GETFLAGS, flags_buf) return flags_ptr[0]
python
def getflags(fd): """ Gets per-file filesystem flags. """ flags_ptr = ffi.new('uint64_t*') flags_buf = ffi.buffer(flags_ptr) fcntl.ioctl(fd, lib.FS_IOC_GETFLAGS, flags_buf) return flags_ptr[0]
[ "def", "getflags", "(", "fd", ")", ":", "flags_ptr", "=", "ffi", ".", "new", "(", "'uint64_t*'", ")", "flags_buf", "=", "ffi", ".", "buffer", "(", "flags_ptr", ")", "fcntl", ".", "ioctl", "(", "fd", ",", "lib", ".", "FS_IOC_GETFLAGS", ",", "flags_buf",...
Gets per-file filesystem flags.
[ "Gets", "per", "-", "file", "filesystem", "flags", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/chattr.py#L74-L82
17,934
g2p/bedup
bedup/platform/chattr.py
editflags
def editflags(fd, add_flags=0, remove_flags=0): """ Sets and unsets per-file filesystem flags. """ if add_flags & remove_flags != 0: raise ValueError( 'Added and removed flags shouldn\'t overlap', add_flags, remove_flags) # The ext2progs code uses int or unsigned lo...
python
def editflags(fd, add_flags=0, remove_flags=0): """ Sets and unsets per-file filesystem flags. """ if add_flags & remove_flags != 0: raise ValueError( 'Added and removed flags shouldn\'t overlap', add_flags, remove_flags) # The ext2progs code uses int or unsigned lo...
[ "def", "editflags", "(", "fd", ",", "add_flags", "=", "0", ",", "remove_flags", "=", "0", ")", ":", "if", "add_flags", "&", "remove_flags", "!=", "0", ":", "raise", "ValueError", "(", "'Added and removed flags shouldn\\'t overlap'", ",", "add_flags", ",", "rem...
Sets and unsets per-file filesystem flags.
[ "Sets", "and", "unsets", "per", "-", "file", "filesystem", "flags", "." ]
9694f6f718844c33017052eb271f68b6c0d0b7d3
https://github.com/g2p/bedup/blob/9694f6f718844c33017052eb271f68b6c0d0b7d3/bedup/platform/chattr.py#L85-L107
17,935
luqasz/librouteros
librouteros/__init__.py
connect
def connect(host, username, password, **kwargs): """ Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowe...
python
def connect(host, username, password, **kwargs): """ Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowe...
[ "def", "connect", "(", "host", ",", "username", ",", "password", ",", "*", "*", "kwargs", ")", ":", "arguments", "=", "ChainMap", "(", "kwargs", ",", "defaults", ")", "transport", "=", "create_transport", "(", "host", ",", "*", "*", "arguments", ")", "...
Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowed. :param timeout: Socket timeout. Defaults to 10. :p...
[ "Connect", "and", "login", "to", "routeros", "device", ".", "Upon", "success", "return", "a", "Api", "class", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/__init__.py#L26-L54
17,936
luqasz/librouteros
librouteros/api.py
Api._readSentence
def _readSentence(self): """ Read one sentence and parse words. :returns: Reply word, dict with attribute words. """ reply_word, words = self.protocol.readSentence() words = dict(parseWord(word) for word in words) return reply_word, words
python
def _readSentence(self): """ Read one sentence and parse words. :returns: Reply word, dict with attribute words. """ reply_word, words = self.protocol.readSentence() words = dict(parseWord(word) for word in words) return reply_word, words
[ "def", "_readSentence", "(", "self", ")", ":", "reply_word", ",", "words", "=", "self", ".", "protocol", ".", "readSentence", "(", ")", "words", "=", "dict", "(", "parseWord", "(", "word", ")", "for", "word", "in", "words", ")", "return", "reply_word", ...
Read one sentence and parse words. :returns: Reply word, dict with attribute words.
[ "Read", "one", "sentence", "and", "parse", "words", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/api.py#L29-L37
17,937
luqasz/librouteros
librouteros/api.py
Api._readResponse
def _readResponse(self): """ Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received. """ traps = [] reply_word = None while reply_word != '!done': repl...
python
def _readResponse(self): """ Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received. """ traps = [] reply_word = None while reply_word != '!done': repl...
[ "def", "_readResponse", "(", "self", ")", ":", "traps", "=", "[", "]", "reply_word", "=", "None", "while", "reply_word", "!=", "'!done'", ":", "reply_word", ",", "words", "=", "self", ".", "_readSentence", "(", ")", "if", "reply_word", "==", "'!trap'", "...
Yield each row of response untill !done is received. :throws TrapError: If one !trap is received. :throws MultiTrapError: If > 1 !trap is received.
[ "Yield", "each", "row", "of", "response", "untill", "!done", "is", "received", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/api.py#L39-L58
17,938
luqasz/librouteros
librouteros/connections.py
Encoder.encodeSentence
def encodeSentence(self, *words): """ Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence. """ encoded = map(self.encodeWord, words) encoded = b''.join(encoded) # append EOS (end of sentence) byte encoded...
python
def encodeSentence(self, *words): """ Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence. """ encoded = map(self.encodeWord, words) encoded = b''.join(encoded) # append EOS (end of sentence) byte encoded...
[ "def", "encodeSentence", "(", "self", ",", "*", "words", ")", ":", "encoded", "=", "map", "(", "self", ".", "encodeWord", ",", "words", ")", "encoded", "=", "b''", ".", "join", "(", "encoded", ")", "# append EOS (end of sentence) byte", "encoded", "+=", "b...
Encode given sentence in API format. :param words: Words to endoce. :returns: Encoded sentence.
[ "Encode", "given", "sentence", "in", "API", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L14-L25
17,939
luqasz/librouteros
librouteros/connections.py
Encoder.encodeWord
def encodeWord(self, word): """ Encode word in API format. :param word: Word to encode. :returns: Encoded word. """ encoded_word = word.encode(encoding=self.encoding, errors='strict') return Encoder.encodeLength(len(word)) + encoded_word
python
def encodeWord(self, word): """ Encode word in API format. :param word: Word to encode. :returns: Encoded word. """ encoded_word = word.encode(encoding=self.encoding, errors='strict') return Encoder.encodeLength(len(word)) + encoded_word
[ "def", "encodeWord", "(", "self", ",", "word", ")", ":", "encoded_word", "=", "word", ".", "encode", "(", "encoding", "=", "self", ".", "encoding", ",", "errors", "=", "'strict'", ")", "return", "Encoder", ".", "encodeLength", "(", "len", "(", "word", ...
Encode word in API format. :param word: Word to encode. :returns: Encoded word.
[ "Encode", "word", "in", "API", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L27-L35
17,940
luqasz/librouteros
librouteros/connections.py
Encoder.encodeLength
def encodeLength(length): """ Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length. """ if length < 128: ored_length = length offset = -1 elif length < 16384: ored_length = length...
python
def encodeLength(length): """ Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length. """ if length < 128: ored_length = length offset = -1 elif length < 16384: ored_length = length...
[ "def", "encodeLength", "(", "length", ")", ":", "if", "length", "<", "128", ":", "ored_length", "=", "length", "offset", "=", "-", "1", "elif", "length", "<", "16384", ":", "ored_length", "=", "length", "|", "0x8000", "offset", "=", "-", "2", "elif", ...
Encode given length in mikrotik format. :param length: Integer < 268435456. :returns: Encoded length.
[ "Encode", "given", "length", "in", "mikrotik", "format", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L38-L60
17,941
luqasz/librouteros
librouteros/connections.py
Decoder.determineLength
def determineLength(length): """ Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read. """ integer = ord(length) if integer < 128: ...
python
def determineLength(length): """ Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read. """ integer = ord(length) if integer < 128: ...
[ "def", "determineLength", "(", "length", ")", ":", "integer", "=", "ord", "(", "length", ")", "if", "integer", "<", "128", ":", "return", "0", "elif", "integer", "<", "192", ":", "return", "1", "elif", "integer", "<", "224", ":", "return", "2", "elif...
Given first read byte, determine how many more bytes needs to be known in order to get fully encoded length. :param length: First read byte. :return: How many bytes to read.
[ "Given", "first", "read", "byte", "determine", "how", "many", "more", "bytes", "needs", "to", "be", "known", "in", "order", "to", "get", "fully", "encoded", "length", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L66-L85
17,942
luqasz/librouteros
librouteros/connections.py
Decoder.decodeLength
def decodeLength(length): """ Decode length based on given bytes. :param length: Bytes string to decode. :return: Decoded length. """ bytes_length = len(length) if bytes_length < 2: offset = b'\x00\x00\x00' XOR = 0 elif bytes_leng...
python
def decodeLength(length): """ Decode length based on given bytes. :param length: Bytes string to decode. :return: Decoded length. """ bytes_length = len(length) if bytes_length < 2: offset = b'\x00\x00\x00' XOR = 0 elif bytes_leng...
[ "def", "decodeLength", "(", "length", ")", ":", "bytes_length", "=", "len", "(", "length", ")", "if", "bytes_length", "<", "2", ":", "offset", "=", "b'\\x00\\x00\\x00'", "XOR", "=", "0", "elif", "bytes_length", "<", "3", ":", "offset", "=", "b'\\x00\\x00'"...
Decode length based on given bytes. :param length: Bytes string to decode. :return: Decoded length.
[ "Decode", "length", "based", "on", "given", "bytes", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L88-L114
17,943
luqasz/librouteros
librouteros/connections.py
ApiProtocol.writeSentence
def writeSentence(self, cmd, *words): """ Write encoded sentence. :param cmd: Command word. :param words: Aditional words. """ encoded = self.encodeSentence(cmd, *words) self.log('<---', cmd, *words) self.transport.write(encoded)
python
def writeSentence(self, cmd, *words): """ Write encoded sentence. :param cmd: Command word. :param words: Aditional words. """ encoded = self.encodeSentence(cmd, *words) self.log('<---', cmd, *words) self.transport.write(encoded)
[ "def", "writeSentence", "(", "self", ",", "cmd", ",", "*", "words", ")", ":", "encoded", "=", "self", ".", "encodeSentence", "(", "cmd", ",", "*", "words", ")", "self", ".", "log", "(", "'<---'", ",", "cmd", ",", "*", "words", ")", "self", ".", "...
Write encoded sentence. :param cmd: Command word. :param words: Aditional words.
[ "Write", "encoded", "sentence", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L129-L138
17,944
luqasz/librouteros
librouteros/connections.py
SocketTransport.read
def read(self, length): """ Read as many bytes from socket as specified in length. Loop as long as every byte is read unless exception is raised. """ data = bytearray() while len(data) != length: data += self.sock.recv((length - len(data))) if not ...
python
def read(self, length): """ Read as many bytes from socket as specified in length. Loop as long as every byte is read unless exception is raised. """ data = bytearray() while len(data) != length: data += self.sock.recv((length - len(data))) if not ...
[ "def", "read", "(", "self", ",", "length", ")", ":", "data", "=", "bytearray", "(", ")", "while", "len", "(", "data", ")", "!=", "length", ":", "data", "+=", "self", ".", "sock", ".", "recv", "(", "(", "length", "-", "len", "(", "data", ")", ")...
Read as many bytes from socket as specified in length. Loop as long as every byte is read unless exception is raised.
[ "Read", "as", "many", "bytes", "from", "socket", "as", "specified", "in", "length", ".", "Loop", "as", "long", "as", "every", "byte", "is", "read", "unless", "exception", "is", "raised", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/connections.py#L178-L188
17,945
luqasz/librouteros
librouteros/protocol.py
parseWord
def parseWord(word): """ Split given attribute word to key, value pair. Values are casted to python equivalents. :param word: API word. :returns: Key, value pair. """ mapping = {'yes': True, 'true': True, 'no': False, 'false': False} _, key, value = word.split('=', 2) try: ...
python
def parseWord(word): """ Split given attribute word to key, value pair. Values are casted to python equivalents. :param word: API word. :returns: Key, value pair. """ mapping = {'yes': True, 'true': True, 'no': False, 'false': False} _, key, value = word.split('=', 2) try: ...
[ "def", "parseWord", "(", "word", ")", ":", "mapping", "=", "{", "'yes'", ":", "True", ",", "'true'", ":", "True", ",", "'no'", ":", "False", ",", "'false'", ":", "False", "}", "_", ",", "key", ",", "value", "=", "word", ".", "split", "(", "'='", ...
Split given attribute word to key, value pair. Values are casted to python equivalents. :param word: API word. :returns: Key, value pair.
[ "Split", "given", "attribute", "word", "to", "key", "value", "pair", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/protocol.py#L1-L16
17,946
luqasz/librouteros
librouteros/protocol.py
composeWord
def composeWord(key, value): """ Create a attribute word from key, value pair. Values are casted to api equivalents. """ mapping = {True: 'yes', False: 'no'} # this is necesary because 1 == True, 0 == False if type(value) == int: value = str(value) else: value = mapping.g...
python
def composeWord(key, value): """ Create a attribute word from key, value pair. Values are casted to api equivalents. """ mapping = {True: 'yes', False: 'no'} # this is necesary because 1 == True, 0 == False if type(value) == int: value = str(value) else: value = mapping.g...
[ "def", "composeWord", "(", "key", ",", "value", ")", ":", "mapping", "=", "{", "True", ":", "'yes'", ",", "False", ":", "'no'", "}", "# this is necesary because 1 == True, 0 == False", "if", "type", "(", "value", ")", "==", "int", ":", "value", "=", "str",...
Create a attribute word from key, value pair. Values are casted to api equivalents.
[ "Create", "a", "attribute", "word", "from", "key", "value", "pair", ".", "Values", "are", "casted", "to", "api", "equivalents", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/protocol.py#L19-L30
17,947
luqasz/librouteros
librouteros/login.py
login_token
def login_token(api, username, password): """Login using pre routeros 6.43 authorization method.""" sentence = api('/login') token = tuple(sentence)[0]['ret'] encoded = encode_password(token, password) tuple(api('/login', **{'name': username, 'response': encoded}))
python
def login_token(api, username, password): """Login using pre routeros 6.43 authorization method.""" sentence = api('/login') token = tuple(sentence)[0]['ret'] encoded = encode_password(token, password) tuple(api('/login', **{'name': username, 'response': encoded}))
[ "def", "login_token", "(", "api", ",", "username", ",", "password", ")", ":", "sentence", "=", "api", "(", "'/login'", ")", "token", "=", "tuple", "(", "sentence", ")", "[", "0", "]", "[", "'ret'", "]", "encoded", "=", "encode_password", "(", "token", ...
Login using pre routeros 6.43 authorization method.
[ "Login", "using", "pre", "routeros", "6", ".", "43", "authorization", "method", "." ]
59293eb49c07a339af87b0416e4619e78ca5176d
https://github.com/luqasz/librouteros/blob/59293eb49c07a339af87b0416e4619e78ca5176d/librouteros/login.py#L15-L20
17,948
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.check_relations
def check_relations(self, relations): """Recursive function which checks if a relation is valid.""" for rel in relations: if not rel: continue fields = rel.split('.', 1) local_field = fields[0] if local_field not in self.fields: ...
python
def check_relations(self, relations): """Recursive function which checks if a relation is valid.""" for rel in relations: if not rel: continue fields = rel.split('.', 1) local_field = fields[0] if local_field not in self.fields: ...
[ "def", "check_relations", "(", "self", ",", "relations", ")", ":", "for", "rel", "in", "relations", ":", "if", "not", "rel", ":", "continue", "fields", "=", "rel", ".", "split", "(", "'.'", ",", "1", ")", "local_field", "=", "fields", "[", "0", "]", ...
Recursive function which checks if a relation is valid.
[ "Recursive", "function", "which", "checks", "if", "a", "relation", "is", "valid", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L102-L120
17,949
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.format_json_api_response
def format_json_api_response(self, data, many): """Post-dump hook that formats serialized data as a top-level JSON API object. See: http://jsonapi.org/format/#document-top-level """ ret = self.format_items(data, many) ret = self.wrap_response(ret, many) ret = self.render...
python
def format_json_api_response(self, data, many): """Post-dump hook that formats serialized data as a top-level JSON API object. See: http://jsonapi.org/format/#document-top-level """ ret = self.format_items(data, many) ret = self.wrap_response(ret, many) ret = self.render...
[ "def", "format_json_api_response", "(", "self", ",", "data", ",", "many", ")", ":", "ret", "=", "self", ".", "format_items", "(", "data", ",", "many", ")", "ret", "=", "self", ".", "wrap_response", "(", "ret", ",", "many", ")", "ret", "=", "self", "....
Post-dump hook that formats serialized data as a top-level JSON API object. See: http://jsonapi.org/format/#document-top-level
[ "Post", "-", "dump", "hook", "that", "formats", "serialized", "data", "as", "a", "top", "-", "level", "JSON", "API", "object", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L123-L132
17,950
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema._do_load
def _do_load(self, data, many=None, **kwargs): """Override `marshmallow.Schema._do_load` for custom JSON API handling. Specifically, we do this to format errors as JSON API Error objects, and to support loading of included data. """ many = self.many if many is None else bool(man...
python
def _do_load(self, data, many=None, **kwargs): """Override `marshmallow.Schema._do_load` for custom JSON API handling. Specifically, we do this to format errors as JSON API Error objects, and to support loading of included data. """ many = self.many if many is None else bool(man...
[ "def", "_do_load", "(", "self", ",", "data", ",", "many", "=", "None", ",", "*", "*", "kwargs", ")", ":", "many", "=", "self", ".", "many", "if", "many", "is", "None", "else", "bool", "(", "many", ")", "# Store this on the instance so we have access to the...
Override `marshmallow.Schema._do_load` for custom JSON API handling. Specifically, we do this to format errors as JSON API Error objects, and to support loading of included data.
[ "Override", "marshmallow", ".", "Schema", ".", "_do_load", "for", "custom", "JSON", "API", "handling", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L229-L260
17,951
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema._extract_from_included
def _extract_from_included(self, data): """Extract included data matching the items in ``data``. For each item in ``data``, extract the full data from the included data. """ return (item for item in self.included_data if item['type'] == data['type'] and ...
python
def _extract_from_included(self, data): """Extract included data matching the items in ``data``. For each item in ``data``, extract the full data from the included data. """ return (item for item in self.included_data if item['type'] == data['type'] and ...
[ "def", "_extract_from_included", "(", "self", ",", "data", ")", ":", "return", "(", "item", "for", "item", "in", "self", ".", "included_data", "if", "item", "[", "'type'", "]", "==", "data", "[", "'type'", "]", "and", "str", "(", "item", "[", "'id'", ...
Extract included data matching the items in ``data``. For each item in ``data``, extract the full data from the included data.
[ "Extract", "included", "data", "matching", "the", "items", "in", "data", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L262-L270
17,952
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.inflect
def inflect(self, text): """Inflect ``text`` if the ``inflect`` class Meta option is defined, otherwise do nothing. """ return self.opts.inflect(text) if self.opts.inflect else text
python
def inflect(self, text): """Inflect ``text`` if the ``inflect`` class Meta option is defined, otherwise do nothing. """ return self.opts.inflect(text) if self.opts.inflect else text
[ "def", "inflect", "(", "self", ",", "text", ")", ":", "return", "self", ".", "opts", ".", "inflect", "(", "text", ")", "if", "self", ".", "opts", ".", "inflect", "else", "text" ]
Inflect ``text`` if the ``inflect`` class Meta option is defined, otherwise do nothing.
[ "Inflect", "text", "if", "the", "inflect", "class", "Meta", "option", "is", "defined", "otherwise", "do", "nothing", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L272-L276
17,953
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.format_errors
def format_errors(self, errors, many): """Format validation errors as JSON Error objects.""" if not errors: return {} if isinstance(errors, (list, tuple)): return {'errors': errors} formatted_errors = [] if many: for index, errors in iteritems...
python
def format_errors(self, errors, many): """Format validation errors as JSON Error objects.""" if not errors: return {} if isinstance(errors, (list, tuple)): return {'errors': errors} formatted_errors = [] if many: for index, errors in iteritems...
[ "def", "format_errors", "(", "self", ",", "errors", ",", "many", ")", ":", "if", "not", "errors", ":", "return", "{", "}", "if", "isinstance", "(", "errors", ",", "(", "list", ",", "tuple", ")", ")", ":", "return", "{", "'errors'", ":", "errors", "...
Format validation errors as JSON Error objects.
[ "Format", "validation", "errors", "as", "JSON", "Error", "objects", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L280-L301
17,954
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.format_error
def format_error(self, field_name, message, index=None): """Override-able hook to format a single error message as an Error object. See: http://jsonapi.org/format/#error-objects """ pointer = ['/data'] if index is not None: pointer.append(str(index)) relati...
python
def format_error(self, field_name, message, index=None): """Override-able hook to format a single error message as an Error object. See: http://jsonapi.org/format/#error-objects """ pointer = ['/data'] if index is not None: pointer.append(str(index)) relati...
[ "def", "format_error", "(", "self", ",", "field_name", ",", "message", ",", "index", "=", "None", ")", ":", "pointer", "=", "[", "'/data'", "]", "if", "index", "is", "not", "None", ":", "pointer", ".", "append", "(", "str", "(", "index", ")", ")", ...
Override-able hook to format a single error message as an Error object. See: http://jsonapi.org/format/#error-objects
[ "Override", "-", "able", "hook", "to", "format", "a", "single", "error", "message", "as", "an", "Error", "object", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L303-L332
17,955
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.format_item
def format_item(self, item): """Format a single datum as a Resource object. See: http://jsonapi.org/format/#document-resource-objects """ # http://jsonapi.org/format/#document-top-level # Primary data MUST be either... a single resource object, a single resource # identi...
python
def format_item(self, item): """Format a single datum as a Resource object. See: http://jsonapi.org/format/#document-resource-objects """ # http://jsonapi.org/format/#document-top-level # Primary data MUST be either... a single resource object, a single resource # identi...
[ "def", "format_item", "(", "self", ",", "item", ")", ":", "# http://jsonapi.org/format/#document-top-level", "# Primary data MUST be either... a single resource object, a single resource", "# identifier object, or null, for requests that target single resources", "if", "not", "item", ":"...
Format a single datum as a Resource object. See: http://jsonapi.org/format/#document-resource-objects
[ "Format", "a", "single", "datum", "as", "a", "Resource", "object", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L334-L379
17,956
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.format_items
def format_items(self, data, many): """Format data as a Resource object or list of Resource objects. See: http://jsonapi.org/format/#document-resource-objects """ if many: return [self.format_item(item) for item in data] else: return self.format_item(data...
python
def format_items(self, data, many): """Format data as a Resource object or list of Resource objects. See: http://jsonapi.org/format/#document-resource-objects """ if many: return [self.format_item(item) for item in data] else: return self.format_item(data...
[ "def", "format_items", "(", "self", ",", "data", ",", "many", ")", ":", "if", "many", ":", "return", "[", "self", ".", "format_item", "(", "item", ")", "for", "item", "in", "data", "]", "else", ":", "return", "self", ".", "format_item", "(", "data", ...
Format data as a Resource object or list of Resource objects. See: http://jsonapi.org/format/#document-resource-objects
[ "Format", "data", "as", "a", "Resource", "object", "or", "list", "of", "Resource", "objects", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L381-L389
17,957
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.get_top_level_links
def get_top_level_links(self, data, many): """Hook for adding links to the root of the response data.""" self_link = None if many: if self.opts.self_url_many: self_link = self.generate_url(self.opts.self_url_many) else: if self.opts.self_url: ...
python
def get_top_level_links(self, data, many): """Hook for adding links to the root of the response data.""" self_link = None if many: if self.opts.self_url_many: self_link = self.generate_url(self.opts.self_url_many) else: if self.opts.self_url: ...
[ "def", "get_top_level_links", "(", "self", ",", "data", ",", "many", ")", ":", "self_link", "=", "None", "if", "many", ":", "if", "self", ".", "opts", ".", "self_url_many", ":", "self_link", "=", "self", ".", "generate_url", "(", "self", ".", "opts", "...
Hook for adding links to the root of the response data.
[ "Hook", "for", "adding", "links", "to", "the", "root", "of", "the", "response", "data", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L391-L402
17,958
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.get_resource_links
def get_resource_links(self, item): """Hook for adding links to a resource object.""" if self.opts.self_url: ret = self.dict_class() kwargs = resolve_params(item, self.opts.self_url_kwargs or {}) ret['self'] = self.generate_url(self.opts.self_url, **kwargs) ...
python
def get_resource_links(self, item): """Hook for adding links to a resource object.""" if self.opts.self_url: ret = self.dict_class() kwargs = resolve_params(item, self.opts.self_url_kwargs or {}) ret['self'] = self.generate_url(self.opts.self_url, **kwargs) ...
[ "def", "get_resource_links", "(", "self", ",", "item", ")", ":", "if", "self", ".", "opts", ".", "self_url", ":", "ret", "=", "self", ".", "dict_class", "(", ")", "kwargs", "=", "resolve_params", "(", "item", ",", "self", ".", "opts", ".", "self_url_kw...
Hook for adding links to a resource object.
[ "Hook", "for", "adding", "links", "to", "a", "resource", "object", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L404-L411
17,959
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/schema.py
Schema.wrap_response
def wrap_response(self, data, many): """Wrap data and links according to the JSON API """ ret = {'data': data} # self_url_many is still valid when there isn't any data, but self_url # may only be included if there is data in the ret if many or data: top_level_links = ...
python
def wrap_response(self, data, many): """Wrap data and links according to the JSON API """ ret = {'data': data} # self_url_many is still valid when there isn't any data, but self_url # may only be included if there is data in the ret if many or data: top_level_links = ...
[ "def", "wrap_response", "(", "self", ",", "data", ",", "many", ")", ":", "ret", "=", "{", "'data'", ":", "data", "}", "# self_url_many is still valid when there isn't any data, but self_url", "# may only be included if there is data in the ret", "if", "many", "or", "data"...
Wrap data and links according to the JSON API
[ "Wrap", "data", "and", "links", "according", "to", "the", "JSON", "API" ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/schema.py#L413-L422
17,960
marshmallow-code/marshmallow-jsonapi
marshmallow_jsonapi/fields.py
Relationship.extract_value
def extract_value(self, data): """Extract the id key and validate the request structure.""" errors = [] if 'id' not in data: errors.append('Must have an `id` field') if 'type' not in data: errors.append('Must have a `type` field') elif data['type'] != self...
python
def extract_value(self, data): """Extract the id key and validate the request structure.""" errors = [] if 'id' not in data: errors.append('Must have an `id` field') if 'type' not in data: errors.append('Must have a `type` field') elif data['type'] != self...
[ "def", "extract_value", "(", "self", ",", "data", ")", ":", "errors", "=", "[", "]", "if", "'id'", "not", "in", "data", ":", "errors", ".", "append", "(", "'Must have an `id` field'", ")", "if", "'type'", "not", "in", "data", ":", "errors", ".", "appen...
Extract the id key and validate the request structure.
[ "Extract", "the", "id", "key", "and", "validate", "the", "request", "structure", "." ]
7183c9bb5cdeace4143e6678bab48d433ac439a1
https://github.com/marshmallow-code/marshmallow-jsonapi/blob/7183c9bb5cdeace4143e6678bab48d433ac439a1/marshmallow_jsonapi/fields.py#L183-L208
17,961
thoth-station/python
thoth/python/helpers.py
fill_package_digests
def fill_package_digests(generated_project: Project) -> Project: """Temporary fill package digests stated in Pipfile.lock.""" for package_version in chain(generated_project.pipfile_lock.packages, generated_project.pipfile_lock.dev_packages): if package_version.hashes: # Already filled from t...
python
def fill_package_digests(generated_project: Project) -> Project: """Temporary fill package digests stated in Pipfile.lock.""" for package_version in chain(generated_project.pipfile_lock.packages, generated_project.pipfile_lock.dev_packages): if package_version.hashes: # Already filled from t...
[ "def", "fill_package_digests", "(", "generated_project", ":", "Project", ")", "->", "Project", ":", "for", "package_version", "in", "chain", "(", "generated_project", ".", "pipfile_lock", ".", "packages", ",", "generated_project", ".", "pipfile_lock", ".", "dev_pack...
Temporary fill package digests stated in Pipfile.lock.
[ "Temporary", "fill", "package", "digests", "stated", "in", "Pipfile", ".", "lock", "." ]
bd2a4a4f552faf54834ce9febea4e2834a1d0bab
https://github.com/thoth-station/python/blob/bd2a4a4f552faf54834ce9febea4e2834a1d0bab/thoth/python/helpers.py#L26-L50
17,962
thoth-station/python
thoth/python/digests_fetcher.py
PythonDigestsFetcher.fetch_digests
def fetch_digests(self, package_name: str, package_version: str) -> dict: """Fetch digests for the given package in specified version from the given package index.""" report = {} for source in self._sources: try: report[source.url] = source.get_package_hashes(package...
python
def fetch_digests(self, package_name: str, package_version: str) -> dict: """Fetch digests for the given package in specified version from the given package index.""" report = {} for source in self._sources: try: report[source.url] = source.get_package_hashes(package...
[ "def", "fetch_digests", "(", "self", ",", "package_name", ":", "str", ",", "package_version", ":", "str", ")", "->", "dict", ":", "report", "=", "{", "}", "for", "source", "in", "self", ".", "_sources", ":", "try", ":", "report", "[", "source", ".", ...
Fetch digests for the given package in specified version from the given package index.
[ "Fetch", "digests", "for", "the", "given", "package", "in", "specified", "version", "from", "the", "given", "package", "index", "." ]
bd2a4a4f552faf54834ce9febea4e2834a1d0bab
https://github.com/thoth-station/python/blob/bd2a4a4f552faf54834ce9febea4e2834a1d0bab/thoth/python/digests_fetcher.py#L44-L57
17,963
blockstack/pybitcoin
pybitcoin/passphrases/legacy.py
random_passphrase_from_wordlist
def random_passphrase_from_wordlist(phrase_length, wordlist): """ An extremely entropy efficient passphrase generator. This function: -Pulls entropy from the safer alternative to /dev/urandom: /dev/random -Doesn't rely on random.seed (words are selected right from the entropy) -Only...
python
def random_passphrase_from_wordlist(phrase_length, wordlist): """ An extremely entropy efficient passphrase generator. This function: -Pulls entropy from the safer alternative to /dev/urandom: /dev/random -Doesn't rely on random.seed (words are selected right from the entropy) -Only...
[ "def", "random_passphrase_from_wordlist", "(", "phrase_length", ",", "wordlist", ")", ":", "passphrase_words", "=", "[", "]", "numbytes_of_entropy", "=", "phrase_length", "*", "2", "entropy", "=", "list", "(", "dev_random_entropy", "(", "numbytes_of_entropy", ",", "...
An extremely entropy efficient passphrase generator. This function: -Pulls entropy from the safer alternative to /dev/urandom: /dev/random -Doesn't rely on random.seed (words are selected right from the entropy) -Only requires 2 entropy bytes/word for word lists of up to 65536 words
[ "An", "extremely", "entropy", "efficient", "passphrase", "generator", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/passphrases/legacy.py#L15-L41
17,964
blockstack/pybitcoin
pybitcoin/hash.py
reverse_hash
def reverse_hash(hash, hex_format=True): """ hash is in hex or binary format """ if not hex_format: hash = hexlify(hash) return "".join(reversed([hash[i:i+2] for i in range(0, len(hash), 2)]))
python
def reverse_hash(hash, hex_format=True): """ hash is in hex or binary format """ if not hex_format: hash = hexlify(hash) return "".join(reversed([hash[i:i+2] for i in range(0, len(hash), 2)]))
[ "def", "reverse_hash", "(", "hash", ",", "hex_format", "=", "True", ")", ":", "if", "not", "hex_format", ":", "hash", "=", "hexlify", "(", "hash", ")", "return", "\"\"", ".", "join", "(", "reversed", "(", "[", "hash", "[", "i", ":", "i", "+", "2", ...
hash is in hex or binary format
[ "hash", "is", "in", "hex", "or", "binary", "format" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/hash.py#L45-L50
17,965
blockstack/pybitcoin
pybitcoin/passphrases/passphrase.py
get_num_words_with_entropy
def get_num_words_with_entropy(bits_of_entropy, wordlist): """ Gets the number of words randomly selected from a given wordlist that would result in the number of bits of entropy specified. """ entropy_per_word = math.log(len(wordlist))/math.log(2) num_words = int(math.ceil(bits_of_entropy/entro...
python
def get_num_words_with_entropy(bits_of_entropy, wordlist): """ Gets the number of words randomly selected from a given wordlist that would result in the number of bits of entropy specified. """ entropy_per_word = math.log(len(wordlist))/math.log(2) num_words = int(math.ceil(bits_of_entropy/entro...
[ "def", "get_num_words_with_entropy", "(", "bits_of_entropy", ",", "wordlist", ")", ":", "entropy_per_word", "=", "math", ".", "log", "(", "len", "(", "wordlist", ")", ")", "/", "math", ".", "log", "(", "2", ")", "num_words", "=", "int", "(", "math", ".",...
Gets the number of words randomly selected from a given wordlist that would result in the number of bits of entropy specified.
[ "Gets", "the", "number", "of", "words", "randomly", "selected", "from", "a", "given", "wordlist", "that", "would", "result", "in", "the", "number", "of", "bits", "of", "entropy", "specified", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/passphrases/passphrase.py#L29-L35
17,966
blockstack/pybitcoin
pybitcoin/passphrases/passphrase.py
create_passphrase
def create_passphrase(bits_of_entropy=None, num_words=None, language='english', word_source='wiktionary'): """ Creates a passphrase that has a certain number of bits of entropy OR a certain number of words. """ wordlist = get_wordlist(language, word_source) if not num_word...
python
def create_passphrase(bits_of_entropy=None, num_words=None, language='english', word_source='wiktionary'): """ Creates a passphrase that has a certain number of bits of entropy OR a certain number of words. """ wordlist = get_wordlist(language, word_source) if not num_word...
[ "def", "create_passphrase", "(", "bits_of_entropy", "=", "None", ",", "num_words", "=", "None", ",", "language", "=", "'english'", ",", "word_source", "=", "'wiktionary'", ")", ":", "wordlist", "=", "get_wordlist", "(", "language", ",", "word_source", ")", "if...
Creates a passphrase that has a certain number of bits of entropy OR a certain number of words.
[ "Creates", "a", "passphrase", "that", "has", "a", "certain", "number", "of", "bits", "of", "entropy", "OR", "a", "certain", "number", "of", "words", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/passphrases/passphrase.py#L42-L54
17,967
blockstack/pybitcoin
pybitcoin/transactions/serialize.py
serialize_input
def serialize_input(input, signature_script_hex=''): """ Serializes a transaction input. """ if not (isinstance(input, dict) and 'transaction_hash' in input \ and 'output_index' in input): raise Exception('Required parameters: transaction_hash, output_index') if is_hex(str(input['tr...
python
def serialize_input(input, signature_script_hex=''): """ Serializes a transaction input. """ if not (isinstance(input, dict) and 'transaction_hash' in input \ and 'output_index' in input): raise Exception('Required parameters: transaction_hash, output_index') if is_hex(str(input['tr...
[ "def", "serialize_input", "(", "input", ",", "signature_script_hex", "=", "''", ")", ":", "if", "not", "(", "isinstance", "(", "input", ",", "dict", ")", "and", "'transaction_hash'", "in", "input", "and", "'output_index'", "in", "input", ")", ":", "raise", ...
Serializes a transaction input.
[ "Serializes", "a", "transaction", "input", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/serialize.py#L20-L42
17,968
blockstack/pybitcoin
pybitcoin/transactions/serialize.py
serialize_output
def serialize_output(output): """ Serializes a transaction output. """ if not ('value' in output and 'script_hex' in output): raise Exception('Invalid output') return ''.join([ hexlify(struct.pack('<Q', output['value'])), # pack into 8 bites hexlify(variable_length_int(len(outpu...
python
def serialize_output(output): """ Serializes a transaction output. """ if not ('value' in output and 'script_hex' in output): raise Exception('Invalid output') return ''.join([ hexlify(struct.pack('<Q', output['value'])), # pack into 8 bites hexlify(variable_length_int(len(outpu...
[ "def", "serialize_output", "(", "output", ")", ":", "if", "not", "(", "'value'", "in", "output", "and", "'script_hex'", "in", "output", ")", ":", "raise", "Exception", "(", "'Invalid output'", ")", "return", "''", ".", "join", "(", "[", "hexlify", "(", "...
Serializes a transaction output.
[ "Serializes", "a", "transaction", "output", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/serialize.py#L45-L55
17,969
blockstack/pybitcoin
pybitcoin/transactions/serialize.py
serialize_transaction
def serialize_transaction(inputs, outputs, lock_time=0, version=1): """ Serializes a transaction. """ # add in the inputs serialized_inputs = ''.join([serialize_input(input) for input in inputs]) # add in the outputs serialized_outputs = ''.join([serialize_output(output) for output in outputs]...
python
def serialize_transaction(inputs, outputs, lock_time=0, version=1): """ Serializes a transaction. """ # add in the inputs serialized_inputs = ''.join([serialize_input(input) for input in inputs]) # add in the outputs serialized_outputs = ''.join([serialize_output(output) for output in outputs]...
[ "def", "serialize_transaction", "(", "inputs", ",", "outputs", ",", "lock_time", "=", "0", ",", "version", "=", "1", ")", ":", "# add in the inputs", "serialized_inputs", "=", "''", ".", "join", "(", "[", "serialize_input", "(", "input", ")", "for", "input",...
Serializes a transaction.
[ "Serializes", "a", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/serialize.py#L58-L81
17,970
blockstack/pybitcoin
pybitcoin/transactions/serialize.py
deserialize_transaction
def deserialize_transaction(tx_hex): """ Given a serialized transaction, return its inputs, outputs, locktime, and version Each input will have: * transaction_hash: string * output_index: int * [optional] sequence: int * [optional] script_sig: string ...
python
def deserialize_transaction(tx_hex): """ Given a serialized transaction, return its inputs, outputs, locktime, and version Each input will have: * transaction_hash: string * output_index: int * [optional] sequence: int * [optional] script_sig: string ...
[ "def", "deserialize_transaction", "(", "tx_hex", ")", ":", "tx", "=", "bitcoin", ".", "deserialize", "(", "str", "(", "tx_hex", ")", ")", "inputs", "=", "tx", "[", "\"ins\"", "]", "outputs", "=", "tx", "[", "\"outs\"", "]", "ret_inputs", "=", "[", "]",...
Given a serialized transaction, return its inputs, outputs, locktime, and version Each input will have: * transaction_hash: string * output_index: int * [optional] sequence: int * [optional] script_sig: string Each output will have: * value: int ...
[ "Given", "a", "serialized", "transaction", "return", "its", "inputs", "outputs", "locktime", "and", "version" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/serialize.py#L84-L130
17,971
blockstack/pybitcoin
pybitcoin/transactions/utils.py
variable_length_int
def variable_length_int(i): """ Encodes integers into variable length integers, which are used in Bitcoin in order to save space. """ if not isinstance(i, (int,long)): raise Exception('i must be an integer') if i < (2**8-3): return chr(i) # pack the integer into one byte eli...
python
def variable_length_int(i): """ Encodes integers into variable length integers, which are used in Bitcoin in order to save space. """ if not isinstance(i, (int,long)): raise Exception('i must be an integer') if i < (2**8-3): return chr(i) # pack the integer into one byte eli...
[ "def", "variable_length_int", "(", "i", ")", ":", "if", "not", "isinstance", "(", "i", ",", "(", "int", ",", "long", ")", ")", ":", "raise", "Exception", "(", "'i must be an integer'", ")", "if", "i", "<", "(", "2", "**", "8", "-", "3", ")", ":", ...
Encodes integers into variable length integers, which are used in Bitcoin in order to save space.
[ "Encodes", "integers", "into", "variable", "length", "integers", "which", "are", "used", "in", "Bitcoin", "in", "order", "to", "save", "space", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/utils.py#L25-L41
17,972
blockstack/pybitcoin
pybitcoin/transactions/scripts.py
make_pay_to_address_script
def make_pay_to_address_script(address): """ Takes in an address and returns the script """ hash160 = hexlify(b58check_decode(address)) script_string = 'OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG' % hash160 return script_to_hex(script_string)
python
def make_pay_to_address_script(address): """ Takes in an address and returns the script """ hash160 = hexlify(b58check_decode(address)) script_string = 'OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG' % hash160 return script_to_hex(script_string)
[ "def", "make_pay_to_address_script", "(", "address", ")", ":", "hash160", "=", "hexlify", "(", "b58check_decode", "(", "address", ")", ")", "script_string", "=", "'OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG'", "%", "hash160", "return", "script_to_hex", "(", "script...
Takes in an address and returns the script
[ "Takes", "in", "an", "address", "and", "returns", "the", "script" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/scripts.py#L37-L42
17,973
blockstack/pybitcoin
pybitcoin/transactions/scripts.py
make_op_return_script
def make_op_return_script(data, format='bin'): """ Takes in raw ascii data to be embedded and returns a script. """ if format == 'hex': assert(is_hex(data)) hex_data = data elif format == 'bin': hex_data = hexlify(data) else: raise Exception("Format must be either 'he...
python
def make_op_return_script(data, format='bin'): """ Takes in raw ascii data to be embedded and returns a script. """ if format == 'hex': assert(is_hex(data)) hex_data = data elif format == 'bin': hex_data = hexlify(data) else: raise Exception("Format must be either 'he...
[ "def", "make_op_return_script", "(", "data", ",", "format", "=", "'bin'", ")", ":", "if", "format", "==", "'hex'", ":", "assert", "(", "is_hex", "(", "data", ")", ")", "hex_data", "=", "data", "elif", "format", "==", "'bin'", ":", "hex_data", "=", "hex...
Takes in raw ascii data to be embedded and returns a script.
[ "Takes", "in", "raw", "ascii", "data", "to", "be", "embedded", "and", "returns", "a", "script", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/scripts.py#L44-L60
17,974
blockstack/pybitcoin
pybitcoin/services/bitcoind.py
create_bitcoind_service_proxy
def create_bitcoind_service_proxy( rpc_username, rpc_password, server='127.0.0.1', port=8332, use_https=False): """ create a bitcoind service proxy """ protocol = 'https' if use_https else 'http' uri = '%s://%s:%s@%s:%s' % (protocol, rpc_username, rpc_password, server, port) return AuthS...
python
def create_bitcoind_service_proxy( rpc_username, rpc_password, server='127.0.0.1', port=8332, use_https=False): """ create a bitcoind service proxy """ protocol = 'https' if use_https else 'http' uri = '%s://%s:%s@%s:%s' % (protocol, rpc_username, rpc_password, server, port) return AuthS...
[ "def", "create_bitcoind_service_proxy", "(", "rpc_username", ",", "rpc_password", ",", "server", "=", "'127.0.0.1'", ",", "port", "=", "8332", ",", "use_https", "=", "False", ")", ":", "protocol", "=", "'https'", "if", "use_https", "else", "'http'", "uri", "="...
create a bitcoind service proxy
[ "create", "a", "bitcoind", "service", "proxy" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/services/bitcoind.py#L21-L28
17,975
blockstack/pybitcoin
pybitcoin/transactions/network.py
get_unspents
def get_unspents(address, blockchain_client=BlockchainInfoClient()): """ Gets the unspent outputs for a given address. """ if isinstance(blockchain_client, BlockcypherClient): return blockcypher.get_unspents(address, blockchain_client) elif isinstance(blockchain_client, BlockchainInfoClient): ...
python
def get_unspents(address, blockchain_client=BlockchainInfoClient()): """ Gets the unspent outputs for a given address. """ if isinstance(blockchain_client, BlockcypherClient): return blockcypher.get_unspents(address, blockchain_client) elif isinstance(blockchain_client, BlockchainInfoClient): ...
[ "def", "get_unspents", "(", "address", ",", "blockchain_client", "=", "BlockchainInfoClient", "(", ")", ")", ":", "if", "isinstance", "(", "blockchain_client", ",", "BlockcypherClient", ")", ":", "return", "blockcypher", ".", "get_unspents", "(", "address", ",", ...
Gets the unspent outputs for a given address.
[ "Gets", "the", "unspent", "outputs", "for", "a", "given", "address", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L32-L48
17,976
blockstack/pybitcoin
pybitcoin/transactions/network.py
broadcast_transaction
def broadcast_transaction(hex_tx, blockchain_client): """ Dispatches a raw hex transaction to the network. """ if isinstance(blockchain_client, BlockcypherClient): return blockcypher.broadcast_transaction(hex_tx, blockchain_client) elif isinstance(blockchain_client, BlockchainInfoClient): ...
python
def broadcast_transaction(hex_tx, blockchain_client): """ Dispatches a raw hex transaction to the network. """ if isinstance(blockchain_client, BlockcypherClient): return blockcypher.broadcast_transaction(hex_tx, blockchain_client) elif isinstance(blockchain_client, BlockchainInfoClient): ...
[ "def", "broadcast_transaction", "(", "hex_tx", ",", "blockchain_client", ")", ":", "if", "isinstance", "(", "blockchain_client", ",", "BlockcypherClient", ")", ":", "return", "blockcypher", ".", "broadcast_transaction", "(", "hex_tx", ",", "blockchain_client", ")", ...
Dispatches a raw hex transaction to the network.
[ "Dispatches", "a", "raw", "hex", "transaction", "to", "the", "network", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L51-L67
17,977
blockstack/pybitcoin
pybitcoin/transactions/network.py
make_send_to_address_tx
def make_send_to_address_tx(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds and signs a "send to address" transaction. """ # get out the private key object, sending address, and inputs private_key_obj, f...
python
def make_send_to_address_tx(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds and signs a "send to address" transaction. """ # get out the private key object, sending address, and inputs private_key_obj, f...
[ "def", "make_send_to_address_tx", "(", "recipient_address", ",", "amount", ",", "private_key", ",", "blockchain_client", "=", "BlockchainInfoClient", "(", ")", ",", "fee", "=", "STANDARD_FEE", ",", "change_address", "=", "None", ")", ":", "# get out the private key ob...
Builds and signs a "send to address" transaction.
[ "Builds", "and", "signs", "a", "send", "to", "address", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L87-L110
17,978
blockstack/pybitcoin
pybitcoin/transactions/network.py
make_op_return_tx
def make_op_return_tx(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds and signs an OP_RETURN transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs...
python
def make_op_return_tx(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds and signs an OP_RETURN transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs...
[ "def", "make_op_return_tx", "(", "data", ",", "private_key", ",", "blockchain_client", "=", "BlockchainInfoClient", "(", ")", ",", "fee", "=", "OP_RETURN_FEE", ",", "change_address", "=", "None", ",", "format", "=", "'bin'", ")", ":", "# get out the private key ob...
Builds and signs an OP_RETURN transaction.
[ "Builds", "and", "signs", "an", "OP_RETURN", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L113-L136
17,979
blockstack/pybitcoin
pybitcoin/transactions/network.py
send_to_address
def send_to_address(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds, signs, and dispatches a "send to address" transaction. """ # build and sign the tx signed_tx = make_send_to_address_tx(recipient_addre...
python
def send_to_address(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds, signs, and dispatches a "send to address" transaction. """ # build and sign the tx signed_tx = make_send_to_address_tx(recipient_addre...
[ "def", "send_to_address", "(", "recipient_address", ",", "amount", ",", "private_key", ",", "blockchain_client", "=", "BlockchainInfoClient", "(", ")", ",", "fee", "=", "STANDARD_FEE", ",", "change_address", "=", "None", ")", ":", "# build and sign the tx", "signed_...
Builds, signs, and dispatches a "send to address" transaction.
[ "Builds", "signs", "and", "dispatches", "a", "send", "to", "address", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L139-L151
17,980
blockstack/pybitcoin
pybitcoin/transactions/network.py
embed_data_in_blockchain
def embed_data_in_blockchain(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds, signs, and dispatches an OP_RETURN transaction. """ # build and sign the tx signed_tx = make_op_return_tx(data, private_key, blockc...
python
def embed_data_in_blockchain(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds, signs, and dispatches an OP_RETURN transaction. """ # build and sign the tx signed_tx = make_op_return_tx(data, private_key, blockc...
[ "def", "embed_data_in_blockchain", "(", "data", ",", "private_key", ",", "blockchain_client", "=", "BlockchainInfoClient", "(", ")", ",", "fee", "=", "OP_RETURN_FEE", ",", "change_address", "=", "None", ",", "format", "=", "'bin'", ")", ":", "# build and sign the ...
Builds, signs, and dispatches an OP_RETURN transaction.
[ "Builds", "signs", "and", "dispatches", "an", "OP_RETURN", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L154-L165
17,981
blockstack/pybitcoin
pybitcoin/transactions/network.py
sign_all_unsigned_inputs
def sign_all_unsigned_inputs(hex_privkey, unsigned_tx_hex): """ Sign a serialized transaction's unsigned inputs @hex_privkey: private key that should sign inputs @unsigned_tx_hex: hex transaction with unsigned inputs Returns: signed hex transaction """ inputs, outputs, lock...
python
def sign_all_unsigned_inputs(hex_privkey, unsigned_tx_hex): """ Sign a serialized transaction's unsigned inputs @hex_privkey: private key that should sign inputs @unsigned_tx_hex: hex transaction with unsigned inputs Returns: signed hex transaction """ inputs, outputs, lock...
[ "def", "sign_all_unsigned_inputs", "(", "hex_privkey", ",", "unsigned_tx_hex", ")", ":", "inputs", ",", "outputs", ",", "locktime", ",", "version", "=", "deserialize_transaction", "(", "unsigned_tx_hex", ")", "tx_hex", "=", "unsigned_tx_hex", "for", "index", "in", ...
Sign a serialized transaction's unsigned inputs @hex_privkey: private key that should sign inputs @unsigned_tx_hex: hex transaction with unsigned inputs Returns: signed hex transaction
[ "Sign", "a", "serialized", "transaction", "s", "unsigned", "inputs" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/network.py#L187-L205
17,982
blockstack/pybitcoin
pybitcoin/merkle.py
calculate_merkle_root
def calculate_merkle_root(hashes, hash_function=bin_double_sha256, hex_format=True): """ takes in a list of binary hashes, returns a binary hash """ if hex_format: hashes = hex_to_bin_reversed_hashes(hashes) # keep moving up the merkle tree, constructing one row at a ti...
python
def calculate_merkle_root(hashes, hash_function=bin_double_sha256, hex_format=True): """ takes in a list of binary hashes, returns a binary hash """ if hex_format: hashes = hex_to_bin_reversed_hashes(hashes) # keep moving up the merkle tree, constructing one row at a ti...
[ "def", "calculate_merkle_root", "(", "hashes", ",", "hash_function", "=", "bin_double_sha256", ",", "hex_format", "=", "True", ")", ":", "if", "hex_format", ":", "hashes", "=", "hex_to_bin_reversed_hashes", "(", "hashes", ")", "# keep moving up the merkle tree, construc...
takes in a list of binary hashes, returns a binary hash
[ "takes", "in", "a", "list", "of", "binary", "hashes", "returns", "a", "binary", "hash" ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/merkle.py#L23-L38
17,983
blockstack/pybitcoin
pybitcoin/b58check.py
b58check_encode
def b58check_encode(bin_s, version_byte=0): """ Takes in a binary string and converts it to a base 58 check string. """ # append the version byte to the beginning bin_s = chr(int(version_byte)) + bin_s # calculate the number of leading zeros num_leading_zeros = len(re.match(r'^\x00*', bin_s).group(0...
python
def b58check_encode(bin_s, version_byte=0): """ Takes in a binary string and converts it to a base 58 check string. """ # append the version byte to the beginning bin_s = chr(int(version_byte)) + bin_s # calculate the number of leading zeros num_leading_zeros = len(re.match(r'^\x00*', bin_s).group(0...
[ "def", "b58check_encode", "(", "bin_s", ",", "version_byte", "=", "0", ")", ":", "# append the version byte to the beginning", "bin_s", "=", "chr", "(", "int", "(", "version_byte", ")", ")", "+", "bin_s", "# calculate the number of leading zeros", "num_leading_zeros", ...
Takes in a binary string and converts it to a base 58 check string.
[ "Takes", "in", "a", "binary", "string", "and", "converts", "it", "to", "a", "base", "58", "check", "string", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/b58check.py#L20-L33
17,984
blockstack/pybitcoin
pybitcoin/transactions/outputs.py
make_pay_to_address_outputs
def make_pay_to_address_outputs(to_address, send_amount, inputs, change_address, fee=STANDARD_FEE): """ Builds the outputs for a "pay to address" transaction. """ return [ # main output { "script_hex": make_pay_to_address_script(to_address), "value": send_amou...
python
def make_pay_to_address_outputs(to_address, send_amount, inputs, change_address, fee=STANDARD_FEE): """ Builds the outputs for a "pay to address" transaction. """ return [ # main output { "script_hex": make_pay_to_address_script(to_address), "value": send_amou...
[ "def", "make_pay_to_address_outputs", "(", "to_address", ",", "send_amount", ",", "inputs", ",", "change_address", ",", "fee", "=", "STANDARD_FEE", ")", ":", "return", "[", "# main output", "{", "\"script_hex\"", ":", "make_pay_to_address_script", "(", "to_address", ...
Builds the outputs for a "pay to address" transaction.
[ "Builds", "the", "outputs", "for", "a", "pay", "to", "address", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/outputs.py#L23-L34
17,985
blockstack/pybitcoin
pybitcoin/transactions/outputs.py
make_op_return_outputs
def make_op_return_outputs(data, inputs, change_address, fee=OP_RETURN_FEE, send_amount=0, format='bin'): """ Builds the outputs for an OP_RETURN transaction. """ return [ # main output { "script_hex": make_op_return_script(data, format=format), "value": send_amoun...
python
def make_op_return_outputs(data, inputs, change_address, fee=OP_RETURN_FEE, send_amount=0, format='bin'): """ Builds the outputs for an OP_RETURN transaction. """ return [ # main output { "script_hex": make_op_return_script(data, format=format), "value": send_amoun...
[ "def", "make_op_return_outputs", "(", "data", ",", "inputs", ",", "change_address", ",", "fee", "=", "OP_RETURN_FEE", ",", "send_amount", "=", "0", ",", "format", "=", "'bin'", ")", ":", "return", "[", "# main output", "{", "\"script_hex\"", ":", "make_op_retu...
Builds the outputs for an OP_RETURN transaction.
[ "Builds", "the", "outputs", "for", "an", "OP_RETURN", "transaction", "." ]
92c8da63c40f7418594b1ce395990c3f5a4787cc
https://github.com/blockstack/pybitcoin/blob/92c8da63c40f7418594b1ce395990c3f5a4787cc/pybitcoin/transactions/outputs.py#L36-L47
17,986
caktus/django-timepiece
timepiece/utils/__init__.py
add_timezone
def add_timezone(value, tz=None): """If the value is naive, then the timezone is added to it. If no timezone is given, timezone.get_current_timezone() is used. """ tz = tz or timezone.get_current_timezone() try: if timezone.is_naive(value): return timezone.make_aware(value, tz) ...
python
def add_timezone(value, tz=None): """If the value is naive, then the timezone is added to it. If no timezone is given, timezone.get_current_timezone() is used. """ tz = tz or timezone.get_current_timezone() try: if timezone.is_naive(value): return timezone.make_aware(value, tz) ...
[ "def", "add_timezone", "(", "value", ",", "tz", "=", "None", ")", ":", "tz", "=", "tz", "or", "timezone", ".", "get_current_timezone", "(", ")", "try", ":", "if", "timezone", ".", "is_naive", "(", "value", ")", ":", "return", "timezone", ".", "make_awa...
If the value is naive, then the timezone is added to it. If no timezone is given, timezone.get_current_timezone() is used.
[ "If", "the", "value", "is", "naive", "then", "the", "timezone", "is", "added", "to", "it", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L16-L28
17,987
caktus/django-timepiece
timepiece/utils/__init__.py
get_active_entry
def get_active_entry(user, select_for_update=False): """Returns the user's currently-active entry, or None.""" entries = apps.get_model('entries', 'Entry').no_join if select_for_update: entries = entries.select_for_update() entries = entries.filter(user=user, end_time__isnull=True) if not e...
python
def get_active_entry(user, select_for_update=False): """Returns the user's currently-active entry, or None.""" entries = apps.get_model('entries', 'Entry').no_join if select_for_update: entries = entries.select_for_update() entries = entries.filter(user=user, end_time__isnull=True) if not e...
[ "def", "get_active_entry", "(", "user", ",", "select_for_update", "=", "False", ")", ":", "entries", "=", "apps", ".", "get_model", "(", "'entries'", ",", "'Entry'", ")", ".", "no_join", "if", "select_for_update", ":", "entries", "=", "entries", ".", "select...
Returns the user's currently-active entry, or None.
[ "Returns", "the", "user", "s", "currently", "-", "active", "entry", "or", "None", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L31-L42
17,988
caktus/django-timepiece
timepiece/utils/__init__.py
get_month_start
def get_month_start(day=None): """Returns the first day of the given month.""" day = add_timezone(day or datetime.date.today()) return day.replace(day=1)
python
def get_month_start(day=None): """Returns the first day of the given month.""" day = add_timezone(day or datetime.date.today()) return day.replace(day=1)
[ "def", "get_month_start", "(", "day", "=", "None", ")", ":", "day", "=", "add_timezone", "(", "day", "or", "datetime", ".", "date", ".", "today", "(", ")", ")", "return", "day", ".", "replace", "(", "day", "=", "1", ")" ]
Returns the first day of the given month.
[ "Returns", "the", "first", "day", "of", "the", "given", "month", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L64-L67
17,989
caktus/django-timepiece
timepiece/utils/__init__.py
get_setting
def get_setting(name, **kwargs): """Returns the user-defined value for the setting, or a default value.""" if hasattr(settings, name): # Try user-defined settings first. return getattr(settings, name) if 'default' in kwargs: # Fall back to a specified default value. return kwargs['default'...
python
def get_setting(name, **kwargs): """Returns the user-defined value for the setting, or a default value.""" if hasattr(settings, name): # Try user-defined settings first. return getattr(settings, name) if 'default' in kwargs: # Fall back to a specified default value. return kwargs['default'...
[ "def", "get_setting", "(", "name", ",", "*", "*", "kwargs", ")", ":", "if", "hasattr", "(", "settings", ",", "name", ")", ":", "# Try user-defined settings first.", "return", "getattr", "(", "settings", ",", "name", ")", "if", "'default'", "in", "kwargs", ...
Returns the user-defined value for the setting, or a default value.
[ "Returns", "the", "user", "-", "defined", "value", "for", "the", "setting", "or", "a", "default", "value", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L73-L82
17,990
caktus/django-timepiece
timepiece/utils/__init__.py
get_week_start
def get_week_start(day=None): """Returns the Monday of the given week.""" day = add_timezone(day or datetime.date.today()) days_since_monday = day.weekday() if days_since_monday != 0: day = day - relativedelta(days=days_since_monday) return day
python
def get_week_start(day=None): """Returns the Monday of the given week.""" day = add_timezone(day or datetime.date.today()) days_since_monday = day.weekday() if days_since_monday != 0: day = day - relativedelta(days=days_since_monday) return day
[ "def", "get_week_start", "(", "day", "=", "None", ")", ":", "day", "=", "add_timezone", "(", "day", "or", "datetime", ".", "date", ".", "today", "(", ")", ")", "days_since_monday", "=", "day", ".", "weekday", "(", ")", "if", "days_since_monday", "!=", ...
Returns the Monday of the given week.
[ "Returns", "the", "Monday", "of", "the", "given", "week", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L85-L91
17,991
caktus/django-timepiece
timepiece/utils/__init__.py
get_year_start
def get_year_start(day=None): """Returns January 1 of the given year.""" day = add_timezone(day or datetime.date.today()) return day.replace(month=1).replace(day=1)
python
def get_year_start(day=None): """Returns January 1 of the given year.""" day = add_timezone(day or datetime.date.today()) return day.replace(month=1).replace(day=1)
[ "def", "get_year_start", "(", "day", "=", "None", ")", ":", "day", "=", "add_timezone", "(", "day", "or", "datetime", ".", "date", ".", "today", "(", ")", ")", "return", "day", ".", "replace", "(", "month", "=", "1", ")", ".", "replace", "(", "day"...
Returns January 1 of the given year.
[ "Returns", "January", "1", "of", "the", "given", "year", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L94-L97
17,992
caktus/django-timepiece
timepiece/utils/__init__.py
to_datetime
def to_datetime(date): """Transforms a date or datetime object into a date object.""" return datetime.datetime(date.year, date.month, date.day)
python
def to_datetime(date): """Transforms a date or datetime object into a date object.""" return datetime.datetime(date.year, date.month, date.day)
[ "def", "to_datetime", "(", "date", ")", ":", "return", "datetime", ".", "datetime", "(", "date", ".", "year", ",", "date", ".", "month", ",", "date", ".", "day", ")" ]
Transforms a date or datetime object into a date object.
[ "Transforms", "a", "date", "or", "datetime", "object", "into", "a", "date", "object", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/utils/__init__.py#L100-L102
17,993
caktus/django-timepiece
timepiece/reports/views.py
report_estimation_accuracy
def report_estimation_accuracy(request): """ Idea from Software Estimation, Demystifying the Black Art, McConnel 2006 Fig 3-3. """ contracts = ProjectContract.objects.filter( status=ProjectContract.STATUS_COMPLETE, type=ProjectContract.PROJECT_FIXED ) data = [('Target (hrs)', 'Ac...
python
def report_estimation_accuracy(request): """ Idea from Software Estimation, Demystifying the Black Art, McConnel 2006 Fig 3-3. """ contracts = ProjectContract.objects.filter( status=ProjectContract.STATUS_COMPLETE, type=ProjectContract.PROJECT_FIXED ) data = [('Target (hrs)', 'Ac...
[ "def", "report_estimation_accuracy", "(", "request", ")", ":", "contracts", "=", "ProjectContract", ".", "objects", ".", "filter", "(", "status", "=", "ProjectContract", ".", "STATUS_COMPLETE", ",", "type", "=", "ProjectContract", ".", "PROJECT_FIXED", ")", "data"...
Idea from Software Estimation, Demystifying the Black Art, McConnel 2006 Fig 3-3.
[ "Idea", "from", "Software", "Estimation", "Demystifying", "the", "Black", "Art", "McConnel", "2006", "Fig", "3", "-", "3", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L468-L487
17,994
caktus/django-timepiece
timepiece/reports/views.py
ReportMixin.get_context_data
def get_context_data(self, **kwargs): """Processes form data to get relevant entries & date_headers.""" context = super(ReportMixin, self).get_context_data(**kwargs) form = self.get_form() if form.is_valid(): data = form.cleaned_data start, end = form.save() ...
python
def get_context_data(self, **kwargs): """Processes form data to get relevant entries & date_headers.""" context = super(ReportMixin, self).get_context_data(**kwargs) form = self.get_form() if form.is_valid(): data = form.cleaned_data start, end = form.save() ...
[ "def", "get_context_data", "(", "self", ",", "*", "*", "kwargs", ")", ":", "context", "=", "super", "(", "ReportMixin", ",", "self", ")", ".", "get_context_data", "(", "*", "*", "kwargs", ")", "form", "=", "self", ".", "get_form", "(", ")", "if", "fo...
Processes form data to get relevant entries & date_headers.
[ "Processes", "form", "data", "to", "get", "relevant", "entries", "&", "date_headers", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L36-L74
17,995
caktus/django-timepiece
timepiece/reports/views.py
ReportMixin.get_entry_query
def get_entry_query(self, start, end, data): """Builds Entry query from form data.""" # Entry types. incl_billable = data.get('billable', True) incl_nonbillable = data.get('non_billable', True) incl_leave = data.get('paid_leave', True) # If no types are selected, shortcu...
python
def get_entry_query(self, start, end, data): """Builds Entry query from form data.""" # Entry types. incl_billable = data.get('billable', True) incl_nonbillable = data.get('non_billable', True) incl_leave = data.get('paid_leave', True) # If no types are selected, shortcu...
[ "def", "get_entry_query", "(", "self", ",", "start", ",", "end", ",", "data", ")", ":", "# Entry types.", "incl_billable", "=", "data", ".", "get", "(", "'billable'", ",", "True", ")", "incl_nonbillable", "=", "data", ".", "get", "(", "'non_billable'", ","...
Builds Entry query from form data.
[ "Builds", "Entry", "query", "from", "form", "data", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L76-L121
17,996
caktus/django-timepiece
timepiece/reports/views.py
ReportMixin.get_headers
def get_headers(self, date_headers, from_date, to_date, trunc): """Adjust date headers & get range headers.""" date_headers = list(date_headers) # Earliest date should be no earlier than from_date. if date_headers and date_headers[0] < from_date: date_headers[0] = from_date ...
python
def get_headers(self, date_headers, from_date, to_date, trunc): """Adjust date headers & get range headers.""" date_headers = list(date_headers) # Earliest date should be no earlier than from_date. if date_headers and date_headers[0] < from_date: date_headers[0] = from_date ...
[ "def", "get_headers", "(", "self", ",", "date_headers", ",", "from_date", ",", "to_date", ",", "trunc", ")", ":", "date_headers", "=", "list", "(", "date_headers", ")", "# Earliest date should be no earlier than from_date.", "if", "date_headers", "and", "date_headers"...
Adjust date headers & get range headers.
[ "Adjust", "date", "headers", "&", "get", "range", "headers", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L123-L142
17,997
caktus/django-timepiece
timepiece/reports/views.py
ReportMixin.get_previous_month
def get_previous_month(self): """Returns date range for the previous full month.""" end = utils.get_month_start() - relativedelta(days=1) end = utils.to_datetime(end) start = utils.get_month_start(end) return start, end
python
def get_previous_month(self): """Returns date range for the previous full month.""" end = utils.get_month_start() - relativedelta(days=1) end = utils.to_datetime(end) start = utils.get_month_start(end) return start, end
[ "def", "get_previous_month", "(", "self", ")", ":", "end", "=", "utils", ".", "get_month_start", "(", ")", "-", "relativedelta", "(", "days", "=", "1", ")", "end", "=", "utils", ".", "to_datetime", "(", "end", ")", "start", "=", "utils", ".", "get_mont...
Returns date range for the previous full month.
[ "Returns", "date", "range", "for", "the", "previous", "full", "month", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L144-L149
17,998
caktus/django-timepiece
timepiece/reports/views.py
HourlyReport.convert_context_to_csv
def convert_context_to_csv(self, context): """Convert the context dictionary into a CSV file.""" content = [] date_headers = context['date_headers'] headers = ['Name'] headers.extend([date.strftime('%m/%d/%Y') for date in date_headers]) headers.append('Total') co...
python
def convert_context_to_csv(self, context): """Convert the context dictionary into a CSV file.""" content = [] date_headers = context['date_headers'] headers = ['Name'] headers.extend([date.strftime('%m/%d/%Y') for date in date_headers]) headers.append('Total') co...
[ "def", "convert_context_to_csv", "(", "self", ",", "context", ")", ":", "content", "=", "[", "]", "date_headers", "=", "context", "[", "'date_headers'", "]", "headers", "=", "[", "'Name'", "]", "headers", ".", "extend", "(", "[", "date", ".", "strftime", ...
Convert the context dictionary into a CSV file.
[ "Convert", "the", "context", "dictionary", "into", "a", "CSV", "file", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L155-L177
17,999
caktus/django-timepiece
timepiece/reports/views.py
HourlyReport.defaults
def defaults(self): """Default filter form data when no GET data is provided.""" # Set default date span to previous week. (start, end) = get_week_window(timezone.now() - relativedelta(days=7)) return { 'from_date': start, 'to_date': end, 'billable': T...
python
def defaults(self): """Default filter form data when no GET data is provided.""" # Set default date span to previous week. (start, end) = get_week_window(timezone.now() - relativedelta(days=7)) return { 'from_date': start, 'to_date': end, 'billable': T...
[ "def", "defaults", "(", "self", ")", ":", "# Set default date span to previous week.", "(", "start", ",", "end", ")", "=", "get_week_window", "(", "timezone", ".", "now", "(", ")", "-", "relativedelta", "(", "days", "=", "7", ")", ")", "return", "{", "'fro...
Default filter form data when no GET data is provided.
[ "Default", "filter", "form", "data", "when", "no", "GET", "data", "is", "provided", "." ]
52515dec027664890efbc535429e1ba1ee152f40
https://github.com/caktus/django-timepiece/blob/52515dec027664890efbc535429e1ba1ee152f40/timepiece/reports/views.py#L180-L192