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
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
241,200
nfcpy/nfcpy
src/nfc/tag/tt2.py
Type2Tag.write
def write(self, page, data): """Send a WRITE command to store data on the tag. The *page* argument specifies the offset in multiples of 4 bytes. The *data* argument must be a string or bytearray of length 4. Command execution errors raise :exc:`Type2TagCommandError`. "...
python
def write(self, page, data): if len(data) != 4: raise ValueError("data must be a four byte string or array") log.debug("write {0} to page {1}".format(hexlify(data), page)) rsp = self.transceive("\xA2" + chr(page % 256) + data) if len(rsp) != 1: log.debug("invali...
[ "def", "write", "(", "self", ",", "page", ",", "data", ")", ":", "if", "len", "(", "data", ")", "!=", "4", ":", "raise", "ValueError", "(", "\"data must be a four byte string or array\"", ")", "log", ".", "debug", "(", "\"write {0} to page {1}\"", ".", "form...
Send a WRITE command to store data on the tag. The *page* argument specifies the offset in multiples of 4 bytes. The *data* argument must be a string or bytearray of length 4. Command execution errors raise :exc:`Type2TagCommandError`.
[ "Send", "a", "WRITE", "command", "to", "store", "data", "on", "the", "tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt2.py#L496-L520
241,201
nfcpy/nfcpy
src/nfc/tag/tt2.py
Type2Tag.sector_select
def sector_select(self, sector): """Send a SECTOR_SELECT command to switch the 1K address sector. The command is only send to the tag if the *sector* number is different from the currently selected sector number (set to 0 when the tag instance is created). If the command was suc...
python
def sector_select(self, sector): if sector != self._current_sector: log.debug("select sector {0} (pages {1} to {2})".format( sector, sector << 10, ((sector+1) << 8) - 1)) sector_select_1 = b'\xC2\xFF' sector_select_2 = pack('Bxxx', sector) rsp = ...
[ "def", "sector_select", "(", "self", ",", "sector", ")", ":", "if", "sector", "!=", "self", ".", "_current_sector", ":", "log", ".", "debug", "(", "\"select sector {0} (pages {1} to {2})\"", ".", "format", "(", "sector", ",", "sector", "<<", "10", ",", "(", ...
Send a SECTOR_SELECT command to switch the 1K address sector. The command is only send to the tag if the *sector* number is different from the currently selected sector number (set to 0 when the tag instance is created). If the command was successful, the currently selected sector numbe...
[ "Send", "a", "SECTOR_SELECT", "command", "to", "switch", "the", "1K", "address", "sector", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt2.py#L522-L559
241,202
nfcpy/nfcpy
src/nfc/tag/tt2.py
Type2Tag.transceive
def transceive(self, data, timeout=0.1, retries=2): """Send a Type 2 Tag command and receive the response. :meth:`transceive` is a type 2 tag specific wrapper around the :meth:`nfc.ContactlessFrontend.exchange` method. It can be used to send custom commands as a sequence of *data* bytes...
python
def transceive(self, data, timeout=0.1, retries=2): log.debug(">> {0} ({1:f}s)".format(hexlify(data), timeout)) if not self.target: # Sometimes we have to (re)sense the target during # communication. If that failed (tag gone) then any # further attempt to transceive(...
[ "def", "transceive", "(", "self", ",", "data", ",", "timeout", "=", "0.1", ",", "retries", "=", "2", ")", ":", "log", ".", "debug", "(", "\">> {0} ({1:f}s)\"", ".", "format", "(", "hexlify", "(", "data", ")", ",", "timeout", ")", ")", "if", "not", ...
Send a Type 2 Tag command and receive the response. :meth:`transceive` is a type 2 tag specific wrapper around the :meth:`nfc.ContactlessFrontend.exchange` method. It can be used to send custom commands as a sequence of *data* bytes to the tag and receive the response data bytes. If *ti...
[ "Send", "a", "Type", "2", "Tag", "command", "and", "receive", "the", "response", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt2.py#L561-L603
241,203
nfcpy/nfcpy
src/nfc/llcp/socket.py
Socket.setsockopt
def setsockopt(self, option, value): """Set the value of the given socket option and return the current value which may have been corrected if it was out of bounds.""" return self.llc.setsockopt(self._tco, option, value)
python
def setsockopt(self, option, value): return self.llc.setsockopt(self._tco, option, value)
[ "def", "setsockopt", "(", "self", ",", "option", ",", "value", ")", ":", "return", "self", ".", "llc", ".", "setsockopt", "(", "self", ".", "_tco", ",", "option", ",", "value", ")" ]
Set the value of the given socket option and return the current value which may have been corrected if it was out of bounds.
[ "Set", "the", "value", "of", "the", "given", "socket", "option", "and", "return", "the", "current", "value", "which", "may", "have", "been", "corrected", "if", "it", "was", "out", "of", "bounds", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/llcp/socket.py#L64-L68
241,204
nfcpy/nfcpy
src/nfc/llcp/socket.py
Socket.accept
def accept(self): """Accept a connection. The socket must be bound to an address and listening for connections. The return value is a new socket object usable to send and receive data on the connection.""" socket = Socket(self._llc, None) socket._tco = self.llc.accept(sel...
python
def accept(self): socket = Socket(self._llc, None) socket._tco = self.llc.accept(self._tco) return socket
[ "def", "accept", "(", "self", ")", ":", "socket", "=", "Socket", "(", "self", ".", "_llc", ",", "None", ")", "socket", ".", "_tco", "=", "self", ".", "llc", ".", "accept", "(", "self", ".", "_tco", ")", "return", "socket" ]
Accept a connection. The socket must be bound to an address and listening for connections. The return value is a new socket object usable to send and receive data on the connection.
[ "Accept", "a", "connection", ".", "The", "socket", "must", "be", "bound", "to", "an", "address", "and", "listening", "for", "connections", ".", "The", "return", "value", "is", "a", "new", "socket", "object", "usable", "to", "send", "and", "receive", "data"...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/llcp/socket.py#L102-L109
241,205
nfcpy/nfcpy
src/nfc/llcp/socket.py
Socket.send
def send(self, data, flags=0): """Send data to the socket. The socket must be connected to a remote socket. Returns a boolean value that indicates success or failure. A false value is typically an indication that the socket or connection was closed. """ return self.llc.s...
python
def send(self, data, flags=0): return self.llc.send(self._tco, data, flags)
[ "def", "send", "(", "self", ",", "data", ",", "flags", "=", "0", ")", ":", "return", "self", ".", "llc", ".", "send", "(", "self", ".", "_tco", ",", "data", ",", "flags", ")" ]
Send data to the socket. The socket must be connected to a remote socket. Returns a boolean value that indicates success or failure. A false value is typically an indication that the socket or connection was closed.
[ "Send", "data", "to", "the", "socket", ".", "The", "socket", "must", "be", "connected", "to", "a", "remote", "socket", ".", "Returns", "a", "boolean", "value", "that", "indicates", "success", "or", "failure", ".", "A", "false", "value", "is", "typically", ...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/llcp/socket.py#L111-L118
241,206
nfcpy/nfcpy
src/nfc/llcp/socket.py
Socket.sendto
def sendto(self, data, addr, flags=0): """Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by addr. Returns a boolean value that indicates success or failure. Failure to send is generally an indication that ...
python
def sendto(self, data, addr, flags=0): return self.llc.sendto(self._tco, data, addr, flags)
[ "def", "sendto", "(", "self", ",", "data", ",", "addr", ",", "flags", "=", "0", ")", ":", "return", "self", ".", "llc", ".", "sendto", "(", "self", ".", "_tco", ",", "data", ",", "addr", ",", "flags", ")" ]
Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by addr. Returns a boolean value that indicates success or failure. Failure to send is generally an indication that the socket was closed.
[ "Send", "data", "to", "the", "socket", ".", "The", "socket", "should", "not", "be", "connected", "to", "a", "remote", "socket", "since", "the", "destination", "socket", "is", "specified", "by", "addr", ".", "Returns", "a", "boolean", "value", "that", "indi...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/llcp/socket.py#L120-L126
241,207
nfcpy/nfcpy
src/nfc/ndef/bt_record.py
BluetoothConfigRecord.simple_pairing_hash
def simple_pairing_hash(self): """Simple Pairing Hash C. Received and transmitted as EIR type 0x0E. Set to None if not received or not to be transmitted. Raises nfc.ndef.DecodeError if the received value or nfc.ndef.EncodeError if the assigned value is not a sequence of 16 octets...
python
def simple_pairing_hash(self): try: if len(self.eir[0x0E]) != 16: raise DecodeError("wrong length of simple pairing hash") return bytearray(self.eir[0x0E]) except KeyError: return None
[ "def", "simple_pairing_hash", "(", "self", ")", ":", "try", ":", "if", "len", "(", "self", ".", "eir", "[", "0x0E", "]", ")", "!=", "16", ":", "raise", "DecodeError", "(", "\"wrong length of simple pairing hash\"", ")", "return", "bytearray", "(", "self", ...
Simple Pairing Hash C. Received and transmitted as EIR type 0x0E. Set to None if not received or not to be transmitted. Raises nfc.ndef.DecodeError if the received value or nfc.ndef.EncodeError if the assigned value is not a sequence of 16 octets.
[ "Simple", "Pairing", "Hash", "C", ".", "Received", "and", "transmitted", "as", "EIR", "type", "0x0E", ".", "Set", "to", "None", "if", "not", "received", "or", "not", "to", "be", "transmitted", ".", "Raises", "nfc", ".", "ndef", ".", "DecodeError", "if", ...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/bt_record.py#L101-L112
241,208
nfcpy/nfcpy
src/nfc/ndef/bt_record.py
BluetoothConfigRecord.simple_pairing_rand
def simple_pairing_rand(self): """Simple Pairing Randomizer R. Received and transmitted as EIR type 0x0F. Set to None if not received or not to be transmitted. Raises nfc.ndef.DecodeError if the received value or nfc.ndef.EncodeError if the assigned value is not a sequence of 16 ...
python
def simple_pairing_rand(self): try: if len(self.eir[0x0F]) != 16: raise DecodeError("wrong length of simple pairing hash") return bytearray(self.eir[0x0F]) except KeyError: return None
[ "def", "simple_pairing_rand", "(", "self", ")", ":", "try", ":", "if", "len", "(", "self", ".", "eir", "[", "0x0F", "]", ")", "!=", "16", ":", "raise", "DecodeError", "(", "\"wrong length of simple pairing hash\"", ")", "return", "bytearray", "(", "self", ...
Simple Pairing Randomizer R. Received and transmitted as EIR type 0x0F. Set to None if not received or not to be transmitted. Raises nfc.ndef.DecodeError if the received value or nfc.ndef.EncodeError if the assigned value is not a sequence of 16 octets.
[ "Simple", "Pairing", "Randomizer", "R", ".", "Received", "and", "transmitted", "as", "EIR", "type", "0x0F", ".", "Set", "to", "None", "if", "not", "received", "or", "not", "to", "be", "transmitted", ".", "Raises", "nfc", ".", "ndef", ".", "DecodeError", ...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/bt_record.py#L124-L135
241,209
nfcpy/nfcpy
src/nfc/ndef/handover.py
HandoverRequestMessage.add_carrier
def add_carrier(self, carrier_record, power_state, aux_data_records=None): """Add a new carrier to the handover request message. :param carrier_record: a record providing carrier information :param power_state: a string describing the carrier power state :param aux_data_records: list of...
python
def add_carrier(self, carrier_record, power_state, aux_data_records=None): carrier = Carrier(carrier_record, power_state) if aux_data_records is not None: for aux in RecordList(aux_data_records): carrier.auxiliary_data_records.append(aux) self.carriers.append(carrier)
[ "def", "add_carrier", "(", "self", ",", "carrier_record", ",", "power_state", ",", "aux_data_records", "=", "None", ")", ":", "carrier", "=", "Carrier", "(", "carrier_record", ",", "power_state", ")", "if", "aux_data_records", "is", "not", "None", ":", "for", ...
Add a new carrier to the handover request message. :param carrier_record: a record providing carrier information :param power_state: a string describing the carrier power state :param aux_data_records: list of auxiliary data records :type carrier_record: :class:`nfc.ndef.Record` ...
[ "Add", "a", "new", "carrier", "to", "the", "handover", "request", "message", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/handover.py#L172-L189
241,210
nfcpy/nfcpy
src/nfc/ndef/handover.py
HandoverSelectMessage.pretty
def pretty(self, indent=0): """Returns a string with a formatted representation that might be considered pretty-printable.""" indent = indent * ' ' lines = list() version_string = "{v.major}.{v.minor}".format(v=self.version) lines.append(("handover version", version_strin...
python
def pretty(self, indent=0): indent = indent * ' ' lines = list() version_string = "{v.major}.{v.minor}".format(v=self.version) lines.append(("handover version", version_string)) if self.error.reason: lines.append(("error reason", self.error.reason)) lines....
[ "def", "pretty", "(", "self", ",", "indent", "=", "0", ")", ":", "indent", "=", "indent", "*", "' '", "lines", "=", "list", "(", ")", "version_string", "=", "\"{v.major}.{v.minor}\"", ".", "format", "(", "v", "=", "self", ".", "version", ")", "lines", ...
Returns a string with a formatted representation that might be considered pretty-printable.
[ "Returns", "a", "string", "with", "a", "formatted", "representation", "that", "might", "be", "considered", "pretty", "-", "printable", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/handover.py#L431-L468
241,211
nfcpy/nfcpy
src/nfc/dep.py
Target.activate
def activate(self, timeout=None, **options): """Activate DEP communication as a target.""" if timeout is None: timeout = 1.0 gbt = options.get('gbt', '')[0:47] lrt = min(max(0, options.get('lrt', 3)), 3) rwt = min(max(0, options.get('rwt', 8)), 14) pp = (lrt...
python
def activate(self, timeout=None, **options): if timeout is None: timeout = 1.0 gbt = options.get('gbt', '')[0:47] lrt = min(max(0, options.get('lrt', 3)), 3) rwt = min(max(0, options.get('rwt', 8)), 14) pp = (lrt << 4) | (bool(gbt) << 1) | int(bool(self.nad)) ...
[ "def", "activate", "(", "self", ",", "timeout", "=", "None", ",", "*", "*", "options", ")", ":", "if", "timeout", "is", "None", ":", "timeout", "=", "1.0", "gbt", "=", "options", ".", "get", "(", "'gbt'", ",", "''", ")", "[", "0", ":", "47", "]...
Activate DEP communication as a target.
[ "Activate", "DEP", "communication", "as", "a", "target", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/dep.py#L417-L460
241,212
nfcpy/nfcpy
src/nfc/ndef/message.py
Message.pretty
def pretty(self): """Returns a message representation that might be considered pretty-printable.""" lines = list() for index, record in enumerate(self._records): lines.append(("record {0}".format(index+1),)) lines.append((" type", repr(record.type))) ...
python
def pretty(self): lines = list() for index, record in enumerate(self._records): lines.append(("record {0}".format(index+1),)) lines.append((" type", repr(record.type))) lines.append((" name", repr(record.name))) lines.append((" data", repr(record.data))...
[ "def", "pretty", "(", "self", ")", ":", "lines", "=", "list", "(", ")", "for", "index", ",", "record", "in", "enumerate", "(", "self", ".", "_records", ")", ":", "lines", ".", "append", "(", "(", "\"record {0}\"", ".", "format", "(", "index", "+", ...
Returns a message representation that might be considered pretty-printable.
[ "Returns", "a", "message", "representation", "that", "might", "be", "considered", "pretty", "-", "printable", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/message.py#L161-L173
241,213
nfcpy/nfcpy
src/nfc/tag/tt1_broadcom.py
Topaz.format
def format(self, version=None, wipe=None): """Format a Topaz tag for NDEF use. The implementation of :meth:`nfc.tag.Tag.format` for a Topaz tag creates a capability container and an NDEF TLV with length zero. Data bytes of the NDEF data area are left untouched unless the wipe ar...
python
def format(self, version=None, wipe=None): return super(Topaz, self).format(version, wipe)
[ "def", "format", "(", "self", ",", "version", "=", "None", ",", "wipe", "=", "None", ")", ":", "return", "super", "(", "Topaz", ",", "self", ")", ".", "format", "(", "version", ",", "wipe", ")" ]
Format a Topaz tag for NDEF use. The implementation of :meth:`nfc.tag.Tag.format` for a Topaz tag creates a capability container and an NDEF TLV with length zero. Data bytes of the NDEF data area are left untouched unless the wipe argument is set.
[ "Format", "a", "Topaz", "tag", "for", "NDEF", "use", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt1_broadcom.py#L40-L49
241,214
nfcpy/nfcpy
src/nfc/tag/tt1_broadcom.py
Topaz512.format
def format(self, version=None, wipe=None): """Format a Topaz-512 tag for NDEF use. The implementation of :meth:`nfc.tag.Tag.format` for a Topaz-512 tag creates a capability container, a Lock Control and a Memory Control TLV, and an NDEF TLV with length zero. Data bytes of the ND...
python
def format(self, version=None, wipe=None): return super(Topaz512, self).format(version, wipe)
[ "def", "format", "(", "self", ",", "version", "=", "None", ",", "wipe", "=", "None", ")", ":", "return", "super", "(", "Topaz512", ",", "self", ")", ".", "format", "(", "version", ",", "wipe", ")" ]
Format a Topaz-512 tag for NDEF use. The implementation of :meth:`nfc.tag.Tag.format` for a Topaz-512 tag creates a capability container, a Lock Control and a Memory Control TLV, and an NDEF TLV with length zero. Data bytes of the NDEF data area are left untouched unless the wip...
[ "Format", "a", "Topaz", "-", "512", "tag", "for", "NDEF", "use", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt1_broadcom.py#L100-L110
241,215
nfcpy/nfcpy
src/nfc/tag/tt1.py
Type1Tag.read_all
def read_all(self): """Returns the 2 byte Header ROM and all 120 byte static memory. """ log.debug("read all static memory") cmd = "\x00\x00\x00" + self.uid return self.transceive(cmd)
python
def read_all(self): log.debug("read all static memory") cmd = "\x00\x00\x00" + self.uid return self.transceive(cmd)
[ "def", "read_all", "(", "self", ")", ":", "log", ".", "debug", "(", "\"read all static memory\"", ")", "cmd", "=", "\"\\x00\\x00\\x00\"", "+", "self", ".", "uid", "return", "self", ".", "transceive", "(", "cmd", ")" ]
Returns the 2 byte Header ROM and all 120 byte static memory.
[ "Returns", "the", "2", "byte", "Header", "ROM", "and", "all", "120", "byte", "static", "memory", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt1.py#L387-L392
241,216
nfcpy/nfcpy
src/nfc/clf/acr122.py
Device.listen_tta
def listen_tta(self, target, timeout): """Listen as Type A Target is not supported.""" info = "{device} does not support listen as Type A Target" raise nfc.clf.UnsupportedTargetError(info.format(device=self))
python
def listen_tta(self, target, timeout): info = "{device} does not support listen as Type A Target" raise nfc.clf.UnsupportedTargetError(info.format(device=self))
[ "def", "listen_tta", "(", "self", ",", "target", ",", "timeout", ")", ":", "info", "=", "\"{device} does not support listen as Type A Target\"", "raise", "nfc", ".", "clf", ".", "UnsupportedTargetError", "(", "info", ".", "format", "(", "device", "=", "self", ")...
Listen as Type A Target is not supported.
[ "Listen", "as", "Type", "A", "Target", "is", "not", "supported", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/acr122.py#L109-L112
241,217
nfcpy/nfcpy
src/nfc/clf/acr122.py
Chipset.command
def command(self, cmd_code, cmd_data, timeout): """Send a host command and return the chip response. """ log.log(logging.DEBUG-1, self.CMD[cmd_code]+" "+hexlify(cmd_data)) frame = bytearray([0xD4, cmd_code]) + bytearray(cmd_data) frame = bytearray([0xFF, 0x00, 0x00, 0x00, len(f...
python
def command(self, cmd_code, cmd_data, timeout): log.log(logging.DEBUG-1, self.CMD[cmd_code]+" "+hexlify(cmd_data)) frame = bytearray([0xD4, cmd_code]) + bytearray(cmd_data) frame = bytearray([0xFF, 0x00, 0x00, 0x00, len(frame)]) + frame frame = self.ccid_xfr_block(frame, timeout) ...
[ "def", "command", "(", "self", ",", "cmd_code", ",", "cmd_data", ",", "timeout", ")", ":", "log", ".", "log", "(", "logging", ".", "DEBUG", "-", "1", ",", "self", ".", "CMD", "[", "cmd_code", "]", "+", "\" \"", "+", "hexlify", "(", "cmd_data", ")",...
Send a host command and return the chip response.
[ "Send", "a", "host", "command", "and", "return", "the", "chip", "response", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/acr122.py#L223-L242
241,218
nfcpy/nfcpy
src/nfc/tag/tt4.py
Type4Tag.format
def format(self, version=None, wipe=None): """Erase the NDEF message on a Type 4 Tag. The :meth:`format` method writes the length of the NDEF message on a Type 4 Tag to zero, thus the tag will appear to be empty. If the *wipe* argument is set to some integer then :meth:`format` ...
python
def format(self, version=None, wipe=None): return super(Type4Tag, self).format(version, wipe)
[ "def", "format", "(", "self", ",", "version", "=", "None", ",", "wipe", "=", "None", ")", ":", "return", "super", "(", "Type4Tag", ",", "self", ")", ".", "format", "(", "version", ",", "wipe", ")" ]
Erase the NDEF message on a Type 4 Tag. The :meth:`format` method writes the length of the NDEF message on a Type 4 Tag to zero, thus the tag will appear to be empty. If the *wipe* argument is set to some integer then :meth:`format` will also overwrite all user data with that in...
[ "Erase", "the", "NDEF", "message", "on", "a", "Type", "4", "Tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt4.py#L395-L409
241,219
nfcpy/nfcpy
src/nfc/tag/tt4.py
Type4Tag.transceive
def transceive(self, data, timeout=None): """Transmit arbitrary data and receive the response. This is a low level method to send arbitrary data to the tag. While it should almost always be better to use :meth:`send_apdu` this is the only way to force a specific timeout value (w...
python
def transceive(self, data, timeout=None): log.debug(">> {0}".format(hexlify(data))) data = self._dep.exchange(data, timeout) log.debug("<< {0}".format(hexlify(data) if data else "None")) return data
[ "def", "transceive", "(", "self", ",", "data", ",", "timeout", "=", "None", ")", ":", "log", ".", "debug", "(", "\">> {0}\"", ".", "format", "(", "hexlify", "(", "data", ")", ")", ")", "data", "=", "self", ".", "_dep", ".", "exchange", "(", "data",...
Transmit arbitrary data and receive the response. This is a low level method to send arbitrary data to the tag. While it should almost always be better to use :meth:`send_apdu` this is the only way to force a specific timeout value (which is otherwise derived from the Tag's answ...
[ "Transmit", "arbitrary", "data", "and", "receive", "the", "response", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt4.py#L425-L439
241,220
nfcpy/nfcpy
src/nfc/tag/__init__.py
Tag.format
def format(self, version=None, wipe=None): """Format the tag to make it NDEF compatible or erase content. The :meth:`format` method is highly dependent on the tag type, product and present status, for example a tag that has been made read-only with lock bits can no longer be formatted o...
python
def format(self, version=None, wipe=None): if hasattr(self, "_format"): args = "version={0!r}, wipe={1!r}" args = args.format(version, wipe) log.debug("format({0})".format(args)) status = self._format(version, wipe) if status is True: s...
[ "def", "format", "(", "self", ",", "version", "=", "None", ",", "wipe", "=", "None", ")", ":", "if", "hasattr", "(", "self", ",", "\"_format\"", ")", ":", "args", "=", "\"version={0!r}, wipe={1!r}\"", "args", "=", "args", ".", "format", "(", "version", ...
Format the tag to make it NDEF compatible or erase content. The :meth:`format` method is highly dependent on the tag type, product and present status, for example a tag that has been made read-only with lock bits can no longer be formatted or erased. :meth:`format` creates the ...
[ "Format", "the", "tag", "to", "make", "it", "NDEF", "compatible", "or", "erase", "content", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/__init__.py#L302-L344
241,221
nfcpy/nfcpy
src/nfc/tag/__init__.py
Tag.protect
def protect(self, password=None, read_protect=False, protect_from=0): """Protect a tag against future write or read access. :meth:`protect` attempts to make a tag readonly for all readers if *password* is :const:`None`, writeable only after authentication if a *password* is provided, an...
python
def protect(self, password=None, read_protect=False, protect_from=0): if hasattr(self, "_protect"): args = "password={0!r}, read_protect={1!r}, protect_from={2!r}" args = args.format(password, read_protect, protect_from) log.debug("protect({0})".format(args)) stat...
[ "def", "protect", "(", "self", ",", "password", "=", "None", ",", "read_protect", "=", "False", ",", "protect_from", "=", "0", ")", ":", "if", "hasattr", "(", "self", ",", "\"_protect\"", ")", ":", "args", "=", "\"password={0!r}, read_protect={1!r}, protect_fr...
Protect a tag against future write or read access. :meth:`protect` attempts to make a tag readonly for all readers if *password* is :const:`None`, writeable only after authentication if a *password* is provided, and readable only after authentication if a *password* is provided and the ...
[ "Protect", "a", "tag", "against", "future", "write", "or", "read", "access", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/__init__.py#L346-L384
241,222
nfcpy/nfcpy
src/nfc/snep/client.py
SnepClient.get_records
def get_records(self, records=None, timeout=1.0): """Get NDEF message records from a SNEP Server. .. versionadded:: 0.13 The :class:`ndef.Record` list given by *records* is encoded as the request message octets input to :meth:`get_octets`. The return value is an :class:`ndef.Re...
python
def get_records(self, records=None, timeout=1.0): octets = b''.join(ndef.message_encoder(records)) if records else None octets = self.get_octets(octets, timeout) if octets and len(octets) >= 3: return list(ndef.message_decoder(octets))
[ "def", "get_records", "(", "self", ",", "records", "=", "None", ",", "timeout", "=", "1.0", ")", ":", "octets", "=", "b''", ".", "join", "(", "ndef", ".", "message_encoder", "(", "records", ")", ")", "if", "records", "else", "None", "octets", "=", "s...
Get NDEF message records from a SNEP Server. .. versionadded:: 0.13 The :class:`ndef.Record` list given by *records* is encoded as the request message octets input to :meth:`get_octets`. The return value is an :class:`ndef.Record` list decoded from the response message octets r...
[ "Get", "NDEF", "message", "records", "from", "a", "SNEP", "Server", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/snep/client.py#L156-L176
241,223
nfcpy/nfcpy
src/nfc/snep/client.py
SnepClient.get_octets
def get_octets(self, octets=None, timeout=1.0): """Get NDEF message octets from a SNEP Server. .. versionadded:: 0.13 If the client has not yet a data link connection with a SNEP Server, it temporarily connects to the default SNEP Server, sends the message octets, disconnects a...
python
def get_octets(self, octets=None, timeout=1.0): if octets is None: # Send NDEF Message with one empty Record. octets = b'\xd0\x00\x00' if not self.socket: try: self.connect('urn:nfc:sn:snep') except nfc.llcp.ConnectRefused: ...
[ "def", "get_octets", "(", "self", ",", "octets", "=", "None", ",", "timeout", "=", "1.0", ")", ":", "if", "octets", "is", "None", ":", "# Send NDEF Message with one empty Record.", "octets", "=", "b'\\xd0\\x00\\x00'", "if", "not", "self", ".", "socket", ":", ...
Get NDEF message octets from a SNEP Server. .. versionadded:: 0.13 If the client has not yet a data link connection with a SNEP Server, it temporarily connects to the default SNEP Server, sends the message octets, disconnects after the server response, and returns the received ...
[ "Get", "NDEF", "message", "octets", "from", "a", "SNEP", "Server", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/snep/client.py#L178-L221
241,224
nfcpy/nfcpy
src/nfc/snep/client.py
SnepClient.put
def put(self, ndef_message, timeout=1.0): """Send an NDEF message to the server. Temporarily connects to the default SNEP server if the client is not yet connected. .. deprecated:: 0.13 Use :meth:`put_records` or :meth:`put_octets`. """ if not self.socket: ...
python
def put(self, ndef_message, timeout=1.0): if not self.socket: try: self.connect('urn:nfc:sn:snep') except nfc.llcp.ConnectRefused: return False else: self.release_connection = True else: self.release_connecti...
[ "def", "put", "(", "self", ",", "ndef_message", ",", "timeout", "=", "1.0", ")", ":", "if", "not", "self", ".", "socket", ":", "try", ":", "self", ".", "connect", "(", "'urn:nfc:sn:snep'", ")", "except", "nfc", ".", "llcp", ".", "ConnectRefused", ":", ...
Send an NDEF message to the server. Temporarily connects to the default SNEP server if the client is not yet connected. .. deprecated:: 0.13 Use :meth:`put_records` or :meth:`put_octets`.
[ "Send", "an", "NDEF", "message", "to", "the", "server", ".", "Temporarily", "connects", "to", "the", "default", "SNEP", "server", "if", "the", "client", "is", "not", "yet", "connected", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/snep/client.py#L223-L252
241,225
nfcpy/nfcpy
src/nfc/snep/client.py
SnepClient.put_records
def put_records(self, records, timeout=1.0): """Send NDEF message records to a SNEP Server. .. versionadded:: 0.13 The :class:`ndef.Record` list given by *records* is encoded and then send via :meth:`put_octets`. Same as:: import ndef octets = ndef.message_enco...
python
def put_records(self, records, timeout=1.0): octets = b''.join(ndef.message_encoder(records)) return self.put_octets(octets, timeout)
[ "def", "put_records", "(", "self", ",", "records", ",", "timeout", "=", "1.0", ")", ":", "octets", "=", "b''", ".", "join", "(", "ndef", ".", "message_encoder", "(", "records", ")", ")", "return", "self", ".", "put_octets", "(", "octets", ",", "timeout...
Send NDEF message records to a SNEP Server. .. versionadded:: 0.13 The :class:`ndef.Record` list given by *records* is encoded and then send via :meth:`put_octets`. Same as:: import ndef octets = ndef.message_encoder(records) snep_client.put_octets(octets, ...
[ "Send", "NDEF", "message", "records", "to", "a", "SNEP", "Server", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/snep/client.py#L254-L268
241,226
nfcpy/nfcpy
src/nfc/clf/rcs380.py
Device.sense_ttb
def sense_ttb(self, target): """Sense for a Type B Target is supported for 106, 212 and 424 kbps. However, there may not be any target that understands the activation command in other than 106 kbps. """ log.debug("polling for NFC-B technology") if target.brty not in ("1...
python
def sense_ttb(self, target): log.debug("polling for NFC-B technology") if target.brty not in ("106B", "212B", "424B"): message = "unsupported bitrate {0}".format(target.brty) raise nfc.clf.UnsupportedTargetError(message) self.chipset.in_set_rf(target.brty) self....
[ "def", "sense_ttb", "(", "self", ",", "target", ")", ":", "log", ".", "debug", "(", "\"polling for NFC-B technology\"", ")", "if", "target", ".", "brty", "not", "in", "(", "\"106B\"", ",", "\"212B\"", ",", "\"424B\"", ")", ":", "message", "=", "\"unsupport...
Sense for a Type B Target is supported for 106, 212 and 424 kbps. However, there may not be any target that understands the activation command in other than 106 kbps.
[ "Sense", "for", "a", "Type", "B", "Target", "is", "supported", "for", "106", "212", "and", "424", "kbps", ".", "However", "there", "may", "not", "be", "any", "target", "that", "understands", "the", "activation", "command", "in", "other", "than", "106", "...
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/rcs380.py#L452-L482
241,227
nfcpy/nfcpy
src/nfc/clf/rcs380.py
Device.sense_ttf
def sense_ttf(self, target): """Sense for a Type F Target is supported for 212 and 424 kbps. """ log.debug("polling for NFC-F technology") if target.brty not in ("212F", "424F"): message = "unsupported bitrate {0}".format(target.brty) raise nfc.clf.UnsupportedTa...
python
def sense_ttf(self, target): log.debug("polling for NFC-F technology") if target.brty not in ("212F", "424F"): message = "unsupported bitrate {0}".format(target.brty) raise nfc.clf.UnsupportedTargetError(message) self.chipset.in_set_rf(target.brty) self.chipset....
[ "def", "sense_ttf", "(", "self", ",", "target", ")", ":", "log", ".", "debug", "(", "\"polling for NFC-F technology\"", ")", "if", "target", ".", "brty", "not", "in", "(", "\"212F\"", ",", "\"424F\"", ")", ":", "message", "=", "\"unsupported bitrate {0}\"", ...
Sense for a Type F Target is supported for 212 and 424 kbps.
[ "Sense", "for", "a", "Type", "F", "Target", "is", "supported", "for", "212", "and", "424", "kbps", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/rcs380.py#L484-L512
241,228
nfcpy/nfcpy
src/nfc/clf/rcs380.py
Device.listen_ttf
def listen_ttf(self, target, timeout): """Listen as Type F Target is supported for either 212 or 424 kbps.""" if target.brty not in ('212F', '424F'): info = "unsupported target bitrate: %r" % target.brty raise nfc.clf.UnsupportedTargetError(info) if target.sensf_res is N...
python
def listen_ttf(self, target, timeout): if target.brty not in ('212F', '424F'): info = "unsupported target bitrate: %r" % target.brty raise nfc.clf.UnsupportedTargetError(info) if target.sensf_res is None: raise ValueError("sensf_res is required") if len(targe...
[ "def", "listen_ttf", "(", "self", ",", "target", ",", "timeout", ")", ":", "if", "target", ".", "brty", "not", "in", "(", "'212F'", ",", "'424F'", ")", ":", "info", "=", "\"unsupported target bitrate: %r\"", "%", "target", ".", "brty", "raise", "nfc", "....
Listen as Type F Target is supported for either 212 or 424 kbps.
[ "Listen", "as", "Type", "F", "Target", "is", "supported", "for", "either", "212", "or", "424", "kbps", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/rcs380.py#L671-L726
241,229
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaStandard.request_response
def request_response(self): """Verify that a card is still present and get its operating mode. The Request Response command returns the current operating state of the card. The operating state changes with the authentication process, a card is in Mode 0 after power-up or a Polli...
python
def request_response(self): a, b, e = self.pmm[3] & 7, self.pmm[3] >> 3 & 7, self.pmm[3] >> 6 timeout = 302E-6 * (b + 1 + a + 1) * 4**e data = self.send_cmd_recv_rsp(0x04, '', timeout, check_status=False) if len(data) != 1: log.debug("insufficient data received from tag") ...
[ "def", "request_response", "(", "self", ")", ":", "a", ",", "b", ",", "e", "=", "self", ".", "pmm", "[", "3", "]", "&", "7", ",", "self", ".", "pmm", "[", "3", "]", ">>", "3", "&", "7", ",", "self", ".", "pmm", "[", "3", "]", ">>", "6", ...
Verify that a card is still present and get its operating mode. The Request Response command returns the current operating state of the card. The operating state changes with the authentication process, a card is in Mode 0 after power-up or a Polling command, transitions to Mode 1 with ...
[ "Verify", "that", "a", "card", "is", "still", "present", "and", "get", "its", "operating", "mode", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L258-L279
241,230
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaStandard.search_service_code
def search_service_code(self, service_index): """Search for a service code that corresponds to an index. The Search Service Code command provides access to the iterable list of services and areas within the activated system. The *service_index* argument may be any value from 0 t...
python
def search_service_code(self, service_index): log.debug("search service code index {0}".format(service_index)) # The maximum response time is given by the value of PMM[3]. # Some cards (like RC-S860 with IC RC-S915) encode a value # that is too short, thus we use at lest 2 ms. a,...
[ "def", "search_service_code", "(", "self", ",", "service_index", ")", ":", "log", ".", "debug", "(", "\"search service code index {0}\"", ".", "format", "(", "service_index", ")", ")", "# The maximum response time is given by the value of PMM[3].", "# Some cards (like RC-S860...
Search for a service code that corresponds to an index. The Search Service Code command provides access to the iterable list of services and areas within the activated system. The *service_index* argument may be any value from 0 to 0xffff. As long as there is a service or area found for...
[ "Search", "for", "a", "service", "code", "that", "corresponds", "to", "an", "index", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L281-L323
241,231
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaStandard.request_system_code
def request_system_code(self): """Return all system codes that are registered in the card. A card has one or more system codes that correspond to logical partitions (systems). Each system has a system code that could be used in a polling command to activate that system. The syst...
python
def request_system_code(self): log.debug("request system code list") a, e = self.pmm[3] & 7, self.pmm[3] >> 6 timeout = max(302E-6 * (a + 1) * 4**e, 0.002) data = self.send_cmd_recv_rsp(0x0C, '', timeout, check_status=False) if len(data) != 1 + data[0] * 2: log.debug(...
[ "def", "request_system_code", "(", "self", ")", ":", "log", ".", "debug", "(", "\"request system code list\"", ")", "a", ",", "e", "=", "self", ".", "pmm", "[", "3", "]", "&", "7", ",", "self", ".", "pmm", "[", "3", "]", ">>", "6", "timeout", "=", ...
Return all system codes that are registered in the card. A card has one or more system codes that correspond to logical partitions (systems). Each system has a system code that could be used in a polling command to activate that system. The system codes responded by the card are returne...
[ "Return", "all", "system", "codes", "that", "are", "registered", "in", "the", "card", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L325-L347
241,232
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLite.protect
def protect(self, password=None, read_protect=False, protect_from=0): """Protect a FeliCa Lite Tag. A FeliCa Lite Tag can be provisioned with a custom password (or the default manufacturer key if the password is an empty string or bytearray) to ensure that data retrieved by future ...
python
def protect(self, password=None, read_protect=False, protect_from=0): return super(FelicaLite, self).protect( password, read_protect, protect_from)
[ "def", "protect", "(", "self", ",", "password", "=", "None", ",", "read_protect", "=", "False", ",", "protect_from", "=", "0", ")", ":", "return", "super", "(", "FelicaLite", ",", "self", ")", ".", "protect", "(", "password", ",", "read_protect", ",", ...
Protect a FeliCa Lite Tag. A FeliCa Lite Tag can be provisioned with a custom password (or the default manufacturer key if the password is an empty string or bytearray) to ensure that data retrieved by future read operations, after authentication, is genuine. Read protection is ...
[ "Protect", "a", "FeliCa", "Lite", "Tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L492-L513
241,233
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLite.format
def format(self, version=0x10, wipe=None): """Format a FeliCa Lite Tag for NDEF. """ return super(FelicaLite, self).format(version, wipe)
python
def format(self, version=0x10, wipe=None): return super(FelicaLite, self).format(version, wipe)
[ "def", "format", "(", "self", ",", "version", "=", "0x10", ",", "wipe", "=", "None", ")", ":", "return", "super", "(", "FelicaLite", ",", "self", ")", ".", "format", "(", "version", ",", "wipe", ")" ]
Format a FeliCa Lite Tag for NDEF.
[ "Format", "a", "FeliCa", "Lite", "Tag", "for", "NDEF", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L626-L630
241,234
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLite.read_without_mac
def read_without_mac(self, *blocks): """Read a number of data blocks without integrity check. This method accepts a variable number of integer arguments as the block numbers to read. The blocks are read with service code 0x000B (NDEF). Tag command errors raise :exc:`~nfc.tag.Ta...
python
def read_without_mac(self, *blocks): log.debug("read {0} block(s) without mac".format(len(blocks))) service_list = [tt3.ServiceCode(0, 0b001011)] block_list = [tt3.BlockCode(n) for n in blocks] return self.read_without_encryption(service_list, block_list)
[ "def", "read_without_mac", "(", "self", ",", "*", "blocks", ")", ":", "log", ".", "debug", "(", "\"read {0} block(s) without mac\"", ".", "format", "(", "len", "(", "blocks", ")", ")", ")", "service_list", "=", "[", "tt3", ".", "ServiceCode", "(", "0", "...
Read a number of data blocks without integrity check. This method accepts a variable number of integer arguments as the block numbers to read. The blocks are read with service code 0x000B (NDEF). Tag command errors raise :exc:`~nfc.tag.TagCommandError`.
[ "Read", "a", "number", "of", "data", "blocks", "without", "integrity", "check", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L680-L693
241,235
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLite.read_with_mac
def read_with_mac(self, *blocks): """Read a number of data blocks with integrity check. This method accepts a variable number of integer arguments as the block numbers to read. The blocks are read with service code 0x000B (NDEF). Along with the requested block data the tag retur...
python
def read_with_mac(self, *blocks): log.debug("read {0} block(s) with mac".format(len(blocks))) if self._sk is None or self._iv is None: raise RuntimeError("authentication required") service_list = [tt3.ServiceCode(0, 0b001011)] block_list = [tt3.BlockCode(n) for n in blocks]...
[ "def", "read_with_mac", "(", "self", ",", "*", "blocks", ")", ":", "log", ".", "debug", "(", "\"read {0} block(s) with mac\"", ".", "format", "(", "len", "(", "blocks", ")", ")", ")", "if", "self", ".", "_sk", "is", "None", "or", "self", ".", "_iv", ...
Read a number of data blocks with integrity check. This method accepts a variable number of integer arguments as the block numbers to read. The blocks are read with service code 0x000B (NDEF). Along with the requested block data the tag returns a message authentication code that is veri...
[ "Read", "a", "number", "of", "data", "blocks", "with", "integrity", "check", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L695-L725
241,236
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLite.write_without_mac
def write_without_mac(self, data, block): """Write a data block without integrity check. This is the standard write method for a FeliCa Lite. The 16-byte string or bytearray *data* is written to the numbered *block* in service 0x0009 (NDEF write service). :: data = bytearra...
python
def write_without_mac(self, data, block): # Write a single data block without a mac. Write with mac is # only supported by FeliCa Lite-S. assert len(data) == 16 and type(block) is int log.debug("write 1 block without mac".format()) sc_list = [tt3.ServiceCode(0, 0b001001)] ...
[ "def", "write_without_mac", "(", "self", ",", "data", ",", "block", ")", ":", "# Write a single data block without a mac. Write with mac is", "# only supported by FeliCa Lite-S.", "assert", "len", "(", "data", ")", "==", "16", "and", "type", "(", "block", ")", "is", ...
Write a data block without integrity check. This is the standard write method for a FeliCa Lite. The 16-byte string or bytearray *data* is written to the numbered *block* in service 0x0009 (NDEF write service). :: data = bytearray(range(16)) # 0x00, 0x01, ... 0x0F try: ...
[ "Write", "a", "data", "block", "without", "integrity", "check", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L727-L748
241,237
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLiteS.authenticate
def authenticate(self, password): """Mutually authenticate with a FeliCa Lite-S Tag. FeliCa Lite-S supports enhanced security functions, one of them is the mutual authentication performed by this method. The first part of mutual authentication is to authenticate the tag with :me...
python
def authenticate(self, password): if super(FelicaLiteS, self).authenticate(password): # At this point we have achieved internal authentication, # i.e we know that the tag has the same card key as in # password. We now reset the authentication status and do # exter...
[ "def", "authenticate", "(", "self", ",", "password", ")", ":", "if", "super", "(", "FelicaLiteS", ",", "self", ")", ".", "authenticate", "(", "password", ")", ":", "# At this point we have achieved internal authentication,", "# i.e we know that the tag has the same card k...
Mutually authenticate with a FeliCa Lite-S Tag. FeliCa Lite-S supports enhanced security functions, one of them is the mutual authentication performed by this method. The first part of mutual authentication is to authenticate the tag with :meth:`FelicaLite.authenticate`. If succ...
[ "Mutually", "authenticate", "with", "a", "FeliCa", "Lite", "-", "S", "Tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L882-L926
241,238
nfcpy/nfcpy
src/nfc/tag/tt3_sony.py
FelicaLiteS.write_with_mac
def write_with_mac(self, data, block): """Write one data block with additional integrity check. If prior to calling this method the tag was not authenticated, a :exc:`RuntimeError` exception is raised. Command execution errors raise :exc:`~nfc.tag.TagCommandError`. """ ...
python
def write_with_mac(self, data, block): # Write a single data block protected with a mac. The card # will only accept the write if it computed the same mac. log.debug("write 1 block with mac") if len(data) != 16: raise ValueError("data must be 16 octets") if type(block...
[ "def", "write_with_mac", "(", "self", ",", "data", ",", "block", ")", ":", "# Write a single data block protected with a mac. The card", "# will only accept the write if it computed the same mac.", "log", ".", "debug", "(", "\"write 1 block with mac\"", ")", "if", "len", "(",...
Write one data block with additional integrity check. If prior to calling this method the tag was not authenticated, a :exc:`RuntimeError` exception is raised. Command execution errors raise :exc:`~nfc.tag.TagCommandError`.
[ "Write", "one", "data", "block", "with", "additional", "integrity", "check", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3_sony.py#L928-L966
241,239
nfcpy/nfcpy
src/nfc/ndef/record.py
Record._read
def _read(self, f): """Parse an NDEF record from a file-like object.""" try: self.header = ord(f.read(1)) except TypeError: log.debug("buffer underflow at offset {0}".format(f.tell())) raise LengthError("insufficient data to parse") m...
python
def _read(self, f): try: self.header = ord(f.read(1)) except TypeError: log.debug("buffer underflow at offset {0}".format(f.tell())) raise LengthError("insufficient data to parse") mbf = bool(self.header & 0x80) mef = bool(self.header & 0x40) ...
[ "def", "_read", "(", "self", ",", "f", ")", ":", "try", ":", "self", ".", "header", "=", "ord", "(", "f", ".", "read", "(", "1", ")", ")", "except", "TypeError", ":", "log", ".", "debug", "(", "\"buffer underflow at offset {0}\"", ".", "format", "(",...
Parse an NDEF record from a file-like object.
[ "Parse", "an", "NDEF", "record", "from", "a", "file", "-", "like", "object", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/record.py#L91-L146
241,240
nfcpy/nfcpy
src/nfc/ndef/record.py
Record._write
def _write(self, f): """Serialize an NDEF record to a file-like object.""" log.debug("writing ndef record at offset {0}".format(f.tell())) record_type = self.type record_name = self.name record_data = self.data if record_type == '': header_flags = 0;...
python
def _write(self, f): log.debug("writing ndef record at offset {0}".format(f.tell())) record_type = self.type record_name = self.name record_data = self.data if record_type == '': header_flags = 0; record_name = ''; record_data = '' elif record_type.s...
[ "def", "_write", "(", "self", ",", "f", ")", ":", "log", ".", "debug", "(", "\"writing ndef record at offset {0}\"", ".", "format", "(", "f", ".", "tell", "(", ")", ")", ")", "record_type", "=", "self", ".", "type", "record_name", "=", "self", ".", "na...
Serialize an NDEF record to a file-like object.
[ "Serialize", "an", "NDEF", "record", "to", "a", "file", "-", "like", "object", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/ndef/record.py#L148-L193
241,241
nfcpy/nfcpy
src/nfc/tag/tt3.py
ServiceCode.pack
def pack(self): """Pack the service code for transmission. Returns a 2 byte string.""" sn, sa = self.number, self.attribute return pack("<H", (sn & 0x3ff) << 6 | (sa & 0x3f))
python
def pack(self): sn, sa = self.number, self.attribute return pack("<H", (sn & 0x3ff) << 6 | (sa & 0x3f))
[ "def", "pack", "(", "self", ")", ":", "sn", ",", "sa", "=", "self", ".", "number", ",", "self", ".", "attribute", "return", "pack", "(", "\"<H\"", ",", "(", "sn", "&", "0x3ff", ")", "<<", "6", "|", "(", "sa", "&", "0x3f", ")", ")" ]
Pack the service code for transmission. Returns a 2 byte string.
[ "Pack", "the", "service", "code", "for", "transmission", ".", "Returns", "a", "2", "byte", "string", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L97-L100
241,242
nfcpy/nfcpy
src/nfc/tag/tt3.py
BlockCode.pack
def pack(self): """Pack the block code for transmission. Returns a 2-3 byte string.""" bn, am, sx = self.number, self.access, self.service return chr(bool(bn < 256) << 7 | (am & 0x7) << 4 | (sx & 0xf)) + \ (chr(bn) if bn < 256 else pack("<H", bn))
python
def pack(self): bn, am, sx = self.number, self.access, self.service return chr(bool(bn < 256) << 7 | (am & 0x7) << 4 | (sx & 0xf)) + \ (chr(bn) if bn < 256 else pack("<H", bn))
[ "def", "pack", "(", "self", ")", ":", "bn", ",", "am", ",", "sx", "=", "self", ".", "number", ",", "self", ".", "access", ",", "self", ".", "service", "return", "chr", "(", "bool", "(", "bn", "<", "256", ")", "<<", "7", "|", "(", "am", "&", ...
Pack the block code for transmission. Returns a 2-3 byte string.
[ "Pack", "the", "block", "code", "for", "transmission", ".", "Returns", "a", "2", "-", "3", "byte", "string", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L129-L133
241,243
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.dump_service
def dump_service(self, sc): """Read all data blocks of a given service. :meth:`dump_service` reads all data blocks from the service with service code *sc* and returns a list of strings suitable for printing. The number of strings returned does not necessarily reflect the number ...
python
def dump_service(self, sc): def lprint(fmt, data, index): ispchr = lambda x: x >= 32 and x <= 126 # noqa: E731 def print_bytes(octets): return ' '.join(['%02x' % x for x in octets]) def print_chars(octets): return ''.join([chr(x) if ispchr(x...
[ "def", "dump_service", "(", "self", ",", "sc", ")", ":", "def", "lprint", "(", "fmt", ",", "data", ",", "index", ")", ":", "ispchr", "=", "lambda", "x", ":", "x", ">=", "32", "and", "x", "<=", "126", "# noqa: E731", "def", "print_bytes", "(", "octe...
Read all data blocks of a given service. :meth:`dump_service` reads all data blocks from the service with service code *sc* and returns a list of strings suitable for printing. The number of strings returned does not necessarily reflect the number of data blocks because a range ...
[ "Read", "all", "data", "blocks", "of", "a", "given", "service", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L284-L335
241,244
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.format
def format(self, version=None, wipe=None): """Format and blank an NFC Forum Type 3 Tag. A generic NFC Forum Type 3 Tag can be (re)formatted if it is in either one of blank, initialized or readwrite state. By formatting, all contents of the attribute information block is overwrit...
python
def format(self, version=None, wipe=None): return super(Type3Tag, self).format(version, wipe)
[ "def", "format", "(", "self", ",", "version", "=", "None", ",", "wipe", "=", "None", ")", ":", "return", "super", "(", "Type3Tag", ",", "self", ")", ".", "format", "(", "version", ",", "wipe", ")" ]
Format and blank an NFC Forum Type 3 Tag. A generic NFC Forum Type 3 Tag can be (re)formatted if it is in either one of blank, initialized or readwrite state. By formatting, all contents of the attribute information block is overwritten with values determined. The number of user data ...
[ "Format", "and", "blank", "an", "NFC", "Forum", "Type", "3", "Tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L337-L359
241,245
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.polling
def polling(self, system_code=0xffff, request_code=0, time_slots=0): """Aquire and identify a card. The Polling command is used to detect the Type 3 Tags in the field. It is also used for initialization and anti-collision. The *system_code* identifies the card system to acquire. A ...
python
def polling(self, system_code=0xffff, request_code=0, time_slots=0): log.debug("polling for system 0x{0:04x}".format(system_code)) if time_slots not in (0, 1, 3, 7, 15): log.debug("invalid number of time slots: {0}".format(time_slots)) raise ValueError("invalid number of time slo...
[ "def", "polling", "(", "self", ",", "system_code", "=", "0xffff", ",", "request_code", "=", "0", ",", "time_slots", "=", "0", ")", ":", "log", ".", "debug", "(", "\"polling for system 0x{0:04x}\"", ".", "format", "(", "system_code", ")", ")", "if", "time_s...
Aquire and identify a card. The Polling command is used to detect the Type 3 Tags in the field. It is also used for initialization and anti-collision. The *system_code* identifies the card system to acquire. A card can have multiple systems. The first system that matches *syste...
[ "Aquire", "and", "identify", "a", "card", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L452-L513
241,246
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.read_from_ndef_service
def read_from_ndef_service(self, *blocks): """Read block data from an NDEF compatible tag. This is a convinience method to read block data from a tag that has system code 0x12FC (NDEF). For other tags this method simply returns :const:`None`. All arguments are block numbers to r...
python
def read_from_ndef_service(self, *blocks): if self.sys == 0x12FC: sc_list = [ServiceCode(0, 0b001011)] bc_list = [BlockCode(n) for n in blocks] return self.read_without_encryption(sc_list, bc_list)
[ "def", "read_from_ndef_service", "(", "self", ",", "*", "blocks", ")", ":", "if", "self", ".", "sys", "==", "0x12FC", ":", "sc_list", "=", "[", "ServiceCode", "(", "0", ",", "0b001011", ")", "]", "bc_list", "=", "[", "BlockCode", "(", "n", ")", "for"...
Read block data from an NDEF compatible tag. This is a convinience method to read block data from a tag that has system code 0x12FC (NDEF). For other tags this method simply returns :const:`None`. All arguments are block numbers to read. To actually pass a list of block numbers requires...
[ "Read", "block", "data", "from", "an", "NDEF", "compatible", "tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L568-L587
241,247
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.write_without_encryption
def write_without_encryption(self, service_list, block_list, data): """Write data blocks to unencrypted services. This method sends a Write Without Encryption command to the tag. The data blocks to overwrite are indicated by a sequence of :class:`~nfc.tag.tt3.BlockCode` objects in the p...
python
def write_without_encryption(self, service_list, block_list, data): a, b, e = self.pmm[6] & 7, self.pmm[6] >> 3 & 7, self.pmm[6] >> 6 timeout = 302.1E-6 * ((b + 1) * len(block_list) + a + 1) * 4**e data = (chr(len(service_list)) + ''.join([sc.pack() for sc in service_list]) ...
[ "def", "write_without_encryption", "(", "self", ",", "service_list", ",", "block_list", ",", "data", ")", ":", "a", ",", "b", ",", "e", "=", "self", ".", "pmm", "[", "6", "]", "&", "7", ",", "self", ".", "pmm", "[", "6", "]", ">>", "3", "&", "7...
Write data blocks to unencrypted services. This method sends a Write Without Encryption command to the tag. The data blocks to overwrite are indicated by a sequence of :class:`~nfc.tag.tt3.BlockCode` objects in the parameter *block_list*. Each block code must reference one of the ...
[ "Write", "data", "blocks", "to", "unencrypted", "services", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L589-L642
241,248
nfcpy/nfcpy
src/nfc/tag/tt3.py
Type3Tag.write_to_ndef_service
def write_to_ndef_service(self, data, *blocks): """Write block data to an NDEF compatible tag. This is a convinience method to write block data to a tag that has system code 0x12FC (NDEF). For other tags this method simply does nothing. The *data* to write must be a string or by...
python
def write_to_ndef_service(self, data, *blocks): if self.sys == 0x12FC: sc_list = [ServiceCode(0, 0b001001)] bc_list = [BlockCode(n) for n in blocks] self.write_without_encryption(sc_list, bc_list, data)
[ "def", "write_to_ndef_service", "(", "self", ",", "data", ",", "*", "blocks", ")", ":", "if", "self", ".", "sys", "==", "0x12FC", ":", "sc_list", "=", "[", "ServiceCode", "(", "0", ",", "0b001001", ")", "]", "bc_list", "=", "[", "BlockCode", "(", "n"...
Write block data to an NDEF compatible tag. This is a convinience method to write block data to a tag that has system code 0x12FC (NDEF). For other tags this method simply does nothing. The *data* to write must be a string or bytearray with length equal ``16 * len(blocks)``. All ...
[ "Write", "block", "data", "to", "an", "NDEF", "compatible", "tag", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/tag/tt3.py#L644-L665
241,249
nfcpy/nfcpy
src/nfc/clf/__init__.py
ContactlessFrontend.close
def close(self): """Close the contacless reader device.""" with self.lock: if self.device is not None: try: self.device.close() except IOError: pass self.device = None
python
def close(self): with self.lock: if self.device is not None: try: self.device.close() except IOError: pass self.device = None
[ "def", "close", "(", "self", ")", ":", "with", "self", ".", "lock", ":", "if", "self", ".", "device", "is", "not", "None", ":", "try", ":", "self", ".", "device", ".", "close", "(", ")", "except", "IOError", ":", "pass", "self", ".", "device", "=...
Close the contacless reader device.
[ "Close", "the", "contacless", "reader", "device", "." ]
6649146d1afdd5e82b2b6b1ea00aa58d50785117
https://github.com/nfcpy/nfcpy/blob/6649146d1afdd5e82b2b6b1ea00aa58d50785117/src/nfc/clf/__init__.py#L155-L163
241,250
cloudnativelabs/kube-shell
kubeshell/parser.py
Parser.build
def build(self, root, schema): """ Build the syntax tree for kubectl command line """ if schema.get("subcommands") and schema["subcommands"]: for subcmd, childSchema in schema["subcommands"].items(): child = CommandTree(node=subcmd) child = self.build(child, c...
python
def build(self, root, schema): if schema.get("subcommands") and schema["subcommands"]: for subcmd, childSchema in schema["subcommands"].items(): child = CommandTree(node=subcmd) child = self.build(child, childSchema) root.children.append(child) ...
[ "def", "build", "(", "self", ",", "root", ",", "schema", ")", ":", "if", "schema", ".", "get", "(", "\"subcommands\"", ")", "and", "schema", "[", "\"subcommands\"", "]", ":", "for", "subcmd", ",", "childSchema", "in", "schema", "[", "\"subcommands\"", "]...
Build the syntax tree for kubectl command line
[ "Build", "the", "syntax", "tree", "for", "kubectl", "command", "line" ]
adc801d165e87fe62f82b074ec49996954c3fbe8
https://github.com/cloudnativelabs/kube-shell/blob/adc801d165e87fe62f82b074ec49996954c3fbe8/kubeshell/parser.py#L45-L61
241,251
cloudnativelabs/kube-shell
kubeshell/parser.py
Parser.parse_tokens
def parse_tokens(self, tokens): """ Parse a sequence of tokens returns tuple of (parsed tokens, suggestions) """ if len(tokens) == 1: return list(), tokens, {"kubectl": self.ast.help} else: tokens.reverse() parsed, unparsed, suggestions = self.tre...
python
def parse_tokens(self, tokens): if len(tokens) == 1: return list(), tokens, {"kubectl": self.ast.help} else: tokens.reverse() parsed, unparsed, suggestions = self.treewalk(self.ast, parsed=list(), unparsed=tokens) if not suggestions and unparsed: # TOD...
[ "def", "parse_tokens", "(", "self", ",", "tokens", ")", ":", "if", "len", "(", "tokens", ")", "==", "1", ":", "return", "list", "(", ")", ",", "tokens", ",", "{", "\"kubectl\"", ":", "self", ".", "ast", ".", "help", "}", "else", ":", "tokens", "....
Parse a sequence of tokens returns tuple of (parsed tokens, suggestions)
[ "Parse", "a", "sequence", "of", "tokens" ]
adc801d165e87fe62f82b074ec49996954c3fbe8
https://github.com/cloudnativelabs/kube-shell/blob/adc801d165e87fe62f82b074ec49996954c3fbe8/kubeshell/parser.py#L69-L90
241,252
cloudnativelabs/kube-shell
kubeshell/parser.py
Parser.treewalk
def treewalk(self, root, parsed, unparsed): """ Recursively walks the syntax tree at root and returns the items parsed, unparsed and possible suggestions """ suggestions = dict() if not unparsed: logger.debug("no tokens left unparsed. returning %s, %s", parsed, suggestions) ...
python
def treewalk(self, root, parsed, unparsed): suggestions = dict() if not unparsed: logger.debug("no tokens left unparsed. returning %s, %s", parsed, suggestions) return parsed, unparsed, suggestions token = unparsed.pop().strip() logger.debug("begin parsing at %s ...
[ "def", "treewalk", "(", "self", ",", "root", ",", "parsed", ",", "unparsed", ")", ":", "suggestions", "=", "dict", "(", ")", "if", "not", "unparsed", ":", "logger", ".", "debug", "(", "\"no tokens left unparsed. returning %s, %s\"", ",", "parsed", ",", "sugg...
Recursively walks the syntax tree at root and returns the items parsed, unparsed and possible suggestions
[ "Recursively", "walks", "the", "syntax", "tree", "at", "root", "and", "returns", "the", "items", "parsed", "unparsed", "and", "possible", "suggestions" ]
adc801d165e87fe62f82b074ec49996954c3fbe8
https://github.com/cloudnativelabs/kube-shell/blob/adc801d165e87fe62f82b074ec49996954c3fbe8/kubeshell/parser.py#L92-L128
241,253
cloudnativelabs/kube-shell
kubeshell/parser.py
Parser.evalOptions
def evalOptions(self, root, parsed, unparsed): """ Evaluate only the options and return flags as suggestions """ logger.debug("parsing options at tree: %s with p:%s, u:%s", root.node, parsed, unparsed) suggestions = dict() token = unparsed.pop().strip() parts = token.partition('...
python
def evalOptions(self, root, parsed, unparsed): logger.debug("parsing options at tree: %s with p:%s, u:%s", root.node, parsed, unparsed) suggestions = dict() token = unparsed.pop().strip() parts = token.partition('=') if parts[-1] != '': # parsing for --option=value type input ...
[ "def", "evalOptions", "(", "self", ",", "root", ",", "parsed", ",", "unparsed", ")", ":", "logger", ".", "debug", "(", "\"parsing options at tree: %s with p:%s, u:%s\"", ",", "root", ".", "node", ",", "parsed", ",", "unparsed", ")", "suggestions", "=", "dict",...
Evaluate only the options and return flags as suggestions
[ "Evaluate", "only", "the", "options", "and", "return", "flags", "as", "suggestions" ]
adc801d165e87fe62f82b074ec49996954c3fbe8
https://github.com/cloudnativelabs/kube-shell/blob/adc801d165e87fe62f82b074ec49996954c3fbe8/kubeshell/parser.py#L136-L165
241,254
olofk/fusesoc
fusesoc/utils.py
setup_logging
def setup_logging(level, monchrome=False, log_file=None): ''' Utility function for setting up logging. ''' # Logging to file if log_file: logging.basicConfig(filename=log_file, filemode='w', level=logging.DEBUG) # Pretty color terminal logging ch = loggin...
python
def setup_logging(level, monchrome=False, log_file=None): ''' Utility function for setting up logging. ''' # Logging to file if log_file: logging.basicConfig(filename=log_file, filemode='w', level=logging.DEBUG) # Pretty color terminal logging ch = loggin...
[ "def", "setup_logging", "(", "level", ",", "monchrome", "=", "False", ",", "log_file", "=", "None", ")", ":", "# Logging to file", "if", "log_file", ":", "logging", ".", "basicConfig", "(", "filename", "=", "log_file", ",", "filemode", "=", "'w'", ",", "le...
Utility function for setting up logging.
[ "Utility", "function", "for", "setting", "up", "logging", "." ]
e30c6a30f6e4c2f4a568b3e8f53edce64b4481cd
https://github.com/olofk/fusesoc/blob/e30c6a30f6e4c2f4a568b3e8f53edce64b4481cd/fusesoc/utils.py#L84-L110
241,255
olofk/fusesoc
fusesoc/edalizer.py
Ttptttg.generate
def generate(self, cache_root): """Run a parametrized generator Args: cache_root (str): The directory where to store the generated cores Returns: list: Cores created by the generator """ generator_cwd = os.path.join(cache_root, 'generated', self.vlnv.san...
python
def generate(self, cache_root): generator_cwd = os.path.join(cache_root, 'generated', self.vlnv.sanitized_name) generator_input_file = os.path.join(generator_cwd, self.name+'_input.yml') logger.info('Generating ' + str(self.vlnv)) if not os.path.exists(generator_cwd): os.ma...
[ "def", "generate", "(", "self", ",", "cache_root", ")", ":", "generator_cwd", "=", "os", ".", "path", ".", "join", "(", "cache_root", ",", "'generated'", ",", "self", ".", "vlnv", ".", "sanitized_name", ")", "generator_input_file", "=", "os", ".", "path", ...
Run a parametrized generator Args: cache_root (str): The directory where to store the generated cores Returns: list: Cores created by the generator
[ "Run", "a", "parametrized", "generator" ]
e30c6a30f6e4c2f4a568b3e8f53edce64b4481cd
https://github.com/olofk/fusesoc/blob/e30c6a30f6e4c2f4a568b3e8f53edce64b4481cd/fusesoc/edalizer.py#L165-L203
241,256
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/fields.py
Field._range_check
def _range_check(self, value, min_value, max_value): ''' Utility method to check that the given value is between min_value and max_value. ''' if value < min_value or value > max_value: raise ValueError('%s out of range - %s is not between %s and %s' % (self.__class__.__name__...
python
def _range_check(self, value, min_value, max_value): ''' Utility method to check that the given value is between min_value and max_value. ''' if value < min_value or value > max_value: raise ValueError('%s out of range - %s is not between %s and %s' % (self.__class__.__name__...
[ "def", "_range_check", "(", "self", ",", "value", ",", "min_value", ",", "max_value", ")", ":", "if", "value", "<", "min_value", "or", "value", ">", "max_value", ":", "raise", "ValueError", "(", "'%s out of range - %s is not between %s and %s'", "%", "(", "self"...
Utility method to check that the given value is between min_value and max_value.
[ "Utility", "method", "to", "check", "that", "the", "given", "value", "is", "between", "min_value", "and", "max_value", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/fields.py#L52-L57
241,257
Infinidat/infi.clickhouse_orm
scripts/generate_ref.py
_get_default_arg
def _get_default_arg(args, defaults, arg_index): """ Method that determines if an argument has default value or not, and if yes what is the default value for the argument :param args: array of arguments, eg: ['first_arg', 'second_arg', 'third_arg'] :param defaults: array of default values, eg: (42, 'so...
python
def _get_default_arg(args, defaults, arg_index): if not defaults: return DefaultArgSpec(False, None) args_with_no_defaults = len(args) - len(defaults) if arg_index < args_with_no_defaults: return DefaultArgSpec(False, None) else: value = defaults[arg_index - args_with_no_defaul...
[ "def", "_get_default_arg", "(", "args", ",", "defaults", ",", "arg_index", ")", ":", "if", "not", "defaults", ":", "return", "DefaultArgSpec", "(", "False", ",", "None", ")", "args_with_no_defaults", "=", "len", "(", "args", ")", "-", "len", "(", "defaults...
Method that determines if an argument has default value or not, and if yes what is the default value for the argument :param args: array of arguments, eg: ['first_arg', 'second_arg', 'third_arg'] :param defaults: array of default values, eg: (42, 'something') :param arg_index: index of the argument in ...
[ "Method", "that", "determines", "if", "an", "argument", "has", "default", "value", "or", "not", "and", "if", "yes", "what", "is", "the", "default", "value", "for", "the", "argument" ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/scripts/generate_ref.py#L7-L30
241,258
Infinidat/infi.clickhouse_orm
scripts/generate_ref.py
get_method_sig
def get_method_sig(method): """ Given a function, it returns a string that pretty much looks how the function signature would be written in python. :param method: a python method :return: A string similar describing the pythong method signature. eg: "my_method(first_argArg, second_arg=42, third_arg...
python
def get_method_sig(method): # The return value of ArgSpec is a bit weird, as the list of arguments and # list of defaults are returned in separate array. # eg: ArgSpec(args=['first_arg', 'second_arg', 'third_arg'], # varargs=None, keywords=None, defaults=(42, 'something')) argspec = inspect.getargsp...
[ "def", "get_method_sig", "(", "method", ")", ":", "# The return value of ArgSpec is a bit weird, as the list of arguments and", "# list of defaults are returned in separate array.", "# eg: ArgSpec(args=['first_arg', 'second_arg', 'third_arg'],", "# varargs=None, keywords=None, defaults=(42, 'somet...
Given a function, it returns a string that pretty much looks how the function signature would be written in python. :param method: a python method :return: A string similar describing the pythong method signature. eg: "my_method(first_argArg, second_arg=42, third_arg='something')"
[ "Given", "a", "function", "it", "returns", "a", "string", "that", "pretty", "much", "looks", "how", "the", "function", "signature", "would", "be", "written", "in", "python", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/scripts/generate_ref.py#L32-L65
241,259
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/query.py
AggregateQuerySet.group_by
def group_by(self, *args): """ This method lets you specify the grouping fields explicitly. The `args` must be names of grouping fields or calculated fields that this queryset was created with. """ for name in args: assert name in self._fields or name in self....
python
def group_by(self, *args): for name in args: assert name in self._fields or name in self._calculated_fields, \ 'Cannot group by `%s` since it is not included in the query' % name qs = copy(self) qs._grouping_fields = args return qs
[ "def", "group_by", "(", "self", ",", "*", "args", ")", ":", "for", "name", "in", "args", ":", "assert", "name", "in", "self", ".", "_fields", "or", "name", "in", "self", ".", "_calculated_fields", ",", "'Cannot group by `%s` since it is not included in the query...
This method lets you specify the grouping fields explicitly. The `args` must be names of grouping fields or calculated fields that this queryset was created with.
[ "This", "method", "lets", "you", "specify", "the", "grouping", "fields", "explicitly", ".", "The", "args", "must", "be", "names", "of", "grouping", "fields", "or", "calculated", "fields", "that", "this", "queryset", "was", "created", "with", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/query.py#L554-L565
241,260
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/query.py
AggregateQuerySet.select_fields_as_sql
def select_fields_as_sql(self): """ Returns the selected fields or expressions as a SQL string. """ return comma_join(list(self._fields) + ['%s AS %s' % (v, k) for k, v in self._calculated_fields.items()])
python
def select_fields_as_sql(self): return comma_join(list(self._fields) + ['%s AS %s' % (v, k) for k, v in self._calculated_fields.items()])
[ "def", "select_fields_as_sql", "(", "self", ")", ":", "return", "comma_join", "(", "list", "(", "self", ".", "_fields", ")", "+", "[", "'%s AS %s'", "%", "(", "v", ",", "k", ")", "for", "k", ",", "v", "in", "self", ".", "_calculated_fields", ".", "it...
Returns the selected fields or expressions as a SQL string.
[ "Returns", "the", "selected", "fields", "or", "expressions", "as", "a", "SQL", "string", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/query.py#L579-L583
241,261
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/query.py
AggregateQuerySet.count
def count(self): """ Returns the number of rows after aggregation. """ sql = u'SELECT count() FROM (%s)' % self.as_sql() raw = self._database.raw(sql) return int(raw) if raw else 0
python
def count(self): sql = u'SELECT count() FROM (%s)' % self.as_sql() raw = self._database.raw(sql) return int(raw) if raw else 0
[ "def", "count", "(", "self", ")", ":", "sql", "=", "u'SELECT count() FROM (%s)'", "%", "self", ".", "as_sql", "(", ")", "raw", "=", "self", ".", "_database", ".", "raw", "(", "sql", ")", "return", "int", "(", "raw", ")", "if", "raw", "else", "0" ]
Returns the number of rows after aggregation.
[ "Returns", "the", "number", "of", "rows", "after", "aggregation", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/query.py#L588-L594
241,262
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/models.py
Model.set_database
def set_database(self, db): ''' Sets the `Database` that this model instance belongs to. This is done automatically when the instance is read from the database or written to it. ''' # This can not be imported globally due to circular import from .database import Database ...
python
def set_database(self, db): ''' Sets the `Database` that this model instance belongs to. This is done automatically when the instance is read from the database or written to it. ''' # This can not be imported globally due to circular import from .database import Database ...
[ "def", "set_database", "(", "self", ",", "db", ")", ":", "# This can not be imported globally due to circular import", "from", ".", "database", "import", "Database", "assert", "isinstance", "(", "db", ",", "Database", ")", ",", "\"database must be database.Database instan...
Sets the `Database` that this model instance belongs to. This is done automatically when the instance is read from the database or written to it.
[ "Sets", "the", "Database", "that", "this", "model", "instance", "belongs", "to", ".", "This", "is", "done", "automatically", "when", "the", "instance", "is", "read", "from", "the", "database", "or", "written", "to", "it", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/models.py#L153-L161
241,263
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/models.py
Model.from_tsv
def from_tsv(cls, line, field_names, timezone_in_use=pytz.utc, database=None): ''' Create a model instance from a tab-separated line. The line may or may not include a newline. The `field_names` list must match the fields defined in the model, but does not have to include all of them. -...
python
def from_tsv(cls, line, field_names, timezone_in_use=pytz.utc, database=None): ''' Create a model instance from a tab-separated line. The line may or may not include a newline. The `field_names` list must match the fields defined in the model, but does not have to include all of them. -...
[ "def", "from_tsv", "(", "cls", ",", "line", ",", "field_names", ",", "timezone_in_use", "=", "pytz", ".", "utc", ",", "database", "=", "None", ")", ":", "from", "six", "import", "next", "values", "=", "iter", "(", "parse_tsv", "(", "line", ")", ")", ...
Create a model instance from a tab-separated line. The line may or may not include a newline. The `field_names` list must match the fields defined in the model, but does not have to include all of them. - `line`: the TSV-formatted data. - `field_names`: names of the model fields in the data. ...
[ "Create", "a", "model", "instance", "from", "a", "tab", "-", "separated", "line", ".", "The", "line", "may", "or", "may", "not", "include", "a", "newline", ".", "The", "field_names", "list", "must", "match", "the", "fields", "defined", "in", "the", "mode...
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/models.py#L207-L228
241,264
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/models.py
Model.to_tsv
def to_tsv(self, include_readonly=True): ''' Returns the instance's column values as a tab-separated line. A newline is not included. - `include_readonly`: if false, returns only fields that can be inserted into database. ''' data = self.__dict__ fields = self.fields(wri...
python
def to_tsv(self, include_readonly=True): ''' Returns the instance's column values as a tab-separated line. A newline is not included. - `include_readonly`: if false, returns only fields that can be inserted into database. ''' data = self.__dict__ fields = self.fields(wri...
[ "def", "to_tsv", "(", "self", ",", "include_readonly", "=", "True", ")", ":", "data", "=", "self", ".", "__dict__", "fields", "=", "self", ".", "fields", "(", "writable", "=", "not", "include_readonly", ")", "return", "'\\t'", ".", "join", "(", "field", ...
Returns the instance's column values as a tab-separated line. A newline is not included. - `include_readonly`: if false, returns only fields that can be inserted into database.
[ "Returns", "the", "instance", "s", "column", "values", "as", "a", "tab", "-", "separated", "line", ".", "A", "newline", "is", "not", "included", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/models.py#L230-L238
241,265
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/models.py
Model.to_dict
def to_dict(self, include_readonly=True, field_names=None): ''' Returns the instance's column values as a dict. - `include_readonly`: if false, returns only fields that can be inserted into database. - `field_names`: an iterable of field names to return (optional) ''' fi...
python
def to_dict(self, include_readonly=True, field_names=None): ''' Returns the instance's column values as a dict. - `include_readonly`: if false, returns only fields that can be inserted into database. - `field_names`: an iterable of field names to return (optional) ''' fi...
[ "def", "to_dict", "(", "self", ",", "include_readonly", "=", "True", ",", "field_names", "=", "None", ")", ":", "fields", "=", "self", ".", "fields", "(", "writable", "=", "not", "include_readonly", ")", "if", "field_names", "is", "not", "None", ":", "fi...
Returns the instance's column values as a dict. - `include_readonly`: if false, returns only fields that can be inserted into database. - `field_names`: an iterable of field names to return (optional)
[ "Returns", "the", "instance", "s", "column", "values", "as", "a", "dict", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/models.py#L240-L253
241,266
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/utils.py
import_submodules
def import_submodules(package_name): """ Import all submodules of a module. """ import importlib, pkgutil package = importlib.import_module(package_name) return { name: importlib.import_module(package_name + '.' + name) for _, name, _ in pkgutil.iter_modules(package.__path__) ...
python
def import_submodules(package_name): import importlib, pkgutil package = importlib.import_module(package_name) return { name: importlib.import_module(package_name + '.' + name) for _, name, _ in pkgutil.iter_modules(package.__path__) }
[ "def", "import_submodules", "(", "package_name", ")", ":", "import", "importlib", ",", "pkgutil", "package", "=", "importlib", ".", "import_module", "(", "package_name", ")", "return", "{", "name", ":", "importlib", ".", "import_module", "(", "package_name", "+"...
Import all submodules of a module.
[ "Import", "all", "submodules", "of", "a", "module", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/utils.py#L84-L93
241,267
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
ServerError.get_error_code_msg
def get_error_code_msg(cls, full_error_message): """ Extract the code and message of the exception that clickhouse-server generated. See the list of error codes here: https://github.com/yandex/ClickHouse/blob/master/dbms/src/Common/ErrorCodes.cpp """ for pattern in cls.E...
python
def get_error_code_msg(cls, full_error_message): for pattern in cls.ERROR_PATTERNS: match = pattern.match(full_error_message) if match: # assert match.group('type1') == match.group('type2') return int(match.group('code')), match.group('msg').strip() ...
[ "def", "get_error_code_msg", "(", "cls", ",", "full_error_message", ")", ":", "for", "pattern", "in", "cls", ".", "ERROR_PATTERNS", ":", "match", "=", "pattern", ".", "match", "(", "full_error_message", ")", "if", "match", ":", "# assert match.group('type1') == ma...
Extract the code and message of the exception that clickhouse-server generated. See the list of error codes here: https://github.com/yandex/ClickHouse/blob/master/dbms/src/Common/ErrorCodes.cpp
[ "Extract", "the", "code", "and", "message", "of", "the", "exception", "that", "clickhouse", "-", "server", "generated", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L58-L71
241,268
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.create_table
def create_table(self, model_class): ''' Creates a table for the given model class, if it does not exist already. ''' if model_class.is_system_model(): raise DatabaseException("You can't create system table") if getattr(model_class, 'engine') is None: rais...
python
def create_table(self, model_class): ''' Creates a table for the given model class, if it does not exist already. ''' if model_class.is_system_model(): raise DatabaseException("You can't create system table") if getattr(model_class, 'engine') is None: rais...
[ "def", "create_table", "(", "self", ",", "model_class", ")", ":", "if", "model_class", ".", "is_system_model", "(", ")", ":", "raise", "DatabaseException", "(", "\"You can't create system table\"", ")", "if", "getattr", "(", "model_class", ",", "'engine'", ")", ...
Creates a table for the given model class, if it does not exist already.
[ "Creates", "a", "table", "for", "the", "given", "model", "class", "if", "it", "does", "not", "exist", "already", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L136-L144
241,269
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.drop_table
def drop_table(self, model_class): ''' Drops the database table of the given model class, if it exists. ''' if model_class.is_system_model(): raise DatabaseException("You can't drop system table") self._send(model_class.drop_table_sql(self))
python
def drop_table(self, model_class): ''' Drops the database table of the given model class, if it exists. ''' if model_class.is_system_model(): raise DatabaseException("You can't drop system table") self._send(model_class.drop_table_sql(self))
[ "def", "drop_table", "(", "self", ",", "model_class", ")", ":", "if", "model_class", ".", "is_system_model", "(", ")", ":", "raise", "DatabaseException", "(", "\"You can't drop system table\"", ")", "self", ".", "_send", "(", "model_class", ".", "drop_table_sql", ...
Drops the database table of the given model class, if it exists.
[ "Drops", "the", "database", "table", "of", "the", "given", "model", "class", "if", "it", "exists", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L146-L152
241,270
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.does_table_exist
def does_table_exist(self, model_class): ''' Checks whether a table for the given model class already exists. Note that this only checks for existence of a table with the expected name. ''' sql = "SELECT count() FROM system.tables WHERE database = '%s' AND name = '%s'" r ...
python
def does_table_exist(self, model_class): ''' Checks whether a table for the given model class already exists. Note that this only checks for existence of a table with the expected name. ''' sql = "SELECT count() FROM system.tables WHERE database = '%s' AND name = '%s'" r ...
[ "def", "does_table_exist", "(", "self", ",", "model_class", ")", ":", "sql", "=", "\"SELECT count() FROM system.tables WHERE database = '%s' AND name = '%s'\"", "r", "=", "self", ".", "_send", "(", "sql", "%", "(", "self", ".", "db_name", ",", "model_class", ".", ...
Checks whether a table for the given model class already exists. Note that this only checks for existence of a table with the expected name.
[ "Checks", "whether", "a", "table", "for", "the", "given", "model", "class", "already", "exists", ".", "Note", "that", "this", "only", "checks", "for", "existence", "of", "a", "table", "with", "the", "expected", "name", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L154-L161
241,271
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.insert
def insert(self, model_instances, batch_size=1000): ''' Insert records into the database. - `model_instances`: any iterable containing instances of a single model class. - `batch_size`: number of records to send per chunk (use a lower number if your records are very large). ''' ...
python
def insert(self, model_instances, batch_size=1000): ''' Insert records into the database. - `model_instances`: any iterable containing instances of a single model class. - `batch_size`: number of records to send per chunk (use a lower number if your records are very large). ''' ...
[ "def", "insert", "(", "self", ",", "model_instances", ",", "batch_size", "=", "1000", ")", ":", "from", "six", "import", "next", "from", "io", "import", "BytesIO", "i", "=", "iter", "(", "model_instances", ")", "try", ":", "first_instance", "=", "next", ...
Insert records into the database. - `model_instances`: any iterable containing instances of a single model class. - `batch_size`: number of records to send per chunk (use a lower number if your records are very large).
[ "Insert", "records", "into", "the", "database", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L177-L222
241,272
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.count
def count(self, model_class, conditions=None): ''' Counts the number of records in the model's table. - `model_class`: the model to count. - `conditions`: optional SQL conditions (contents of the WHERE clause). ''' query = 'SELECT count() FROM $table' if conditio...
python
def count(self, model_class, conditions=None): ''' Counts the number of records in the model's table. - `model_class`: the model to count. - `conditions`: optional SQL conditions (contents of the WHERE clause). ''' query = 'SELECT count() FROM $table' if conditio...
[ "def", "count", "(", "self", ",", "model_class", ",", "conditions", "=", "None", ")", ":", "query", "=", "'SELECT count() FROM $table'", "if", "conditions", ":", "query", "+=", "' WHERE '", "+", "conditions", "query", "=", "self", ".", "_substitute", "(", "q...
Counts the number of records in the model's table. - `model_class`: the model to count. - `conditions`: optional SQL conditions (contents of the WHERE clause).
[ "Counts", "the", "number", "of", "records", "in", "the", "model", "s", "table", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L224-L236
241,273
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.select
def select(self, query, model_class=None, settings=None): ''' Performs a query and returns a generator of model instances. - `query`: the SQL query to execute. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model....
python
def select(self, query, model_class=None, settings=None): ''' Performs a query and returns a generator of model instances. - `query`: the SQL query to execute. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model....
[ "def", "select", "(", "self", ",", "query", ",", "model_class", "=", "None", ",", "settings", "=", "None", ")", ":", "query", "+=", "' FORMAT TabSeparatedWithNamesAndTypes'", "query", "=", "self", ".", "_substitute", "(", "query", ",", "model_class", ")", "r...
Performs a query and returns a generator of model instances. - `query`: the SQL query to execute. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model. - `settings`: query settings to send as HTTP GET parameters
[ "Performs", "a", "query", "and", "returns", "a", "generator", "of", "model", "instances", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L238-L257
241,274
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.raw
def raw(self, query, settings=None, stream=False): ''' Performs a query and returns its output as text. - `query`: the SQL query to execute. - `settings`: query settings to send as HTTP GET parameters - `stream`: if true, the HTTP response from ClickHouse will be streamed. ...
python
def raw(self, query, settings=None, stream=False): ''' Performs a query and returns its output as text. - `query`: the SQL query to execute. - `settings`: query settings to send as HTTP GET parameters - `stream`: if true, the HTTP response from ClickHouse will be streamed. ...
[ "def", "raw", "(", "self", ",", "query", ",", "settings", "=", "None", ",", "stream", "=", "False", ")", ":", "query", "=", "self", ".", "_substitute", "(", "query", ",", "None", ")", "return", "self", ".", "_send", "(", "query", ",", "settings", "...
Performs a query and returns its output as text. - `query`: the SQL query to execute. - `settings`: query settings to send as HTTP GET parameters - `stream`: if true, the HTTP response from ClickHouse will be streamed.
[ "Performs", "a", "query", "and", "returns", "its", "output", "as", "text", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L259-L268
241,275
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.paginate
def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None): ''' Selects records and returns a single page of model instances. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model....
python
def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None): ''' Selects records and returns a single page of model instances. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model....
[ "def", "paginate", "(", "self", ",", "model_class", ",", "order_by", ",", "page_num", "=", "1", ",", "page_size", "=", "100", ",", "conditions", "=", "None", ",", "settings", "=", "None", ")", ":", "count", "=", "self", ".", "count", "(", "model_class"...
Selects records and returns a single page of model instances. - `model_class`: the model class matching the query's table, or `None` for getting back instances of an ad-hoc model. - `order_by`: columns to use for sorting the query (contents of the ORDER BY clause). - `page_num`: the p...
[ "Selects", "records", "and", "returns", "a", "single", "page", "of", "model", "instances", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L270-L304
241,276
Infinidat/infi.clickhouse_orm
src/infi/clickhouse_orm/database.py
Database.migrate
def migrate(self, migrations_package_name, up_to=9999): ''' Executes schema migrations. - `migrations_package_name` - fully qualified name of the Python package containing the migrations. - `up_to` - number of the last migration to apply. ''' from .migrations i...
python
def migrate(self, migrations_package_name, up_to=9999): ''' Executes schema migrations. - `migrations_package_name` - fully qualified name of the Python package containing the migrations. - `up_to` - number of the last migration to apply. ''' from .migrations i...
[ "def", "migrate", "(", "self", ",", "migrations_package_name", ",", "up_to", "=", "9999", ")", ":", "from", ".", "migrations", "import", "MigrationHistory", "logger", "=", "logging", ".", "getLogger", "(", "'migrations'", ")", "applied_migrations", "=", "self", ...
Executes schema migrations. - `migrations_package_name` - fully qualified name of the Python package containing the migrations. - `up_to` - number of the last migration to apply.
[ "Executes", "schema", "migrations", "." ]
595f2023e334e3925a5c3fbfdd6083a5992a7169
https://github.com/Infinidat/infi.clickhouse_orm/blob/595f2023e334e3925a5c3fbfdd6083a5992a7169/src/infi/clickhouse_orm/database.py#L306-L325
241,277
pyusb/pyusb
usb/core.py
_try_get_string
def _try_get_string(dev, index, langid = None, default_str_i0 = "", default_access_error = "Error Accessing String"): """ try to get a string, but return a string no matter what """ if index == 0 : string = default_str_i0 else: try: if langid is None: ...
python
def _try_get_string(dev, index, langid = None, default_str_i0 = "", default_access_error = "Error Accessing String"): if index == 0 : string = default_str_i0 else: try: if langid is None: string = util.get_string(dev, index) else: s...
[ "def", "_try_get_string", "(", "dev", ",", "index", ",", "langid", "=", "None", ",", "default_str_i0", "=", "\"\"", ",", "default_access_error", "=", "\"Error Accessing String\"", ")", ":", "if", "index", "==", "0", ":", "string", "=", "default_str_i0", "else"...
try to get a string, but return a string no matter what
[ "try", "to", "get", "a", "string", "but", "return", "a", "string", "no", "matter", "what" ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L52-L66
241,278
pyusb/pyusb
usb/core.py
_try_lookup
def _try_lookup(table, value, default = ""): """ try to get a string from the lookup table, return "" instead of key error """ try: string = table[ value ] except KeyError: string = default return string
python
def _try_lookup(table, value, default = ""): try: string = table[ value ] except KeyError: string = default return string
[ "def", "_try_lookup", "(", "table", ",", "value", ",", "default", "=", "\"\"", ")", ":", "try", ":", "string", "=", "table", "[", "value", "]", "except", "KeyError", ":", "string", "=", "default", "return", "string" ]
try to get a string from the lookup table, return "" instead of key error
[ "try", "to", "get", "a", "string", "from", "the", "lookup", "table", "return", "instead", "of", "key", "error" ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L68-L76
241,279
pyusb/pyusb
usb/core.py
find
def find(find_all=False, backend = None, custom_match = None, **args): r"""Find an USB device and return it. find() is the function used to discover USB devices. You can pass as arguments any combination of the USB Device Descriptor fields to match a device. For example: find(idVendor=0x3f4, idPr...
python
def find(find_all=False, backend = None, custom_match = None, **args): r"""Find an USB device and return it. find() is the function used to discover USB devices. You can pass as arguments any combination of the USB Device Descriptor fields to match a device. For example: find(idVendor=0x3f4, idPr...
[ "def", "find", "(", "find_all", "=", "False", ",", "backend", "=", "None", ",", "custom_match", "=", "None", ",", "*", "*", "args", ")", ":", "def", "device_iter", "(", "*", "*", "kwargs", ")", ":", "for", "dev", "in", "backend", ".", "enumerate_devi...
r"""Find an USB device and return it. find() is the function used to discover USB devices. You can pass as arguments any combination of the USB Device Descriptor fields to match a device. For example: find(idVendor=0x3f4, idProduct=0x2009) will return the Device object for the device with idVend...
[ "r", "Find", "an", "USB", "device", "and", "return", "it", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L1179-L1273
241,280
pyusb/pyusb
usb/core.py
show_devices
def show_devices(verbose=False, **kwargs): """Show information about connected devices. The verbose flag sets to verbose or not. **kwargs are passed directly to the find() function. """ kwargs["find_all"] = True devices = find(**kwargs) strings = "" for device in devices: if not...
python
def show_devices(verbose=False, **kwargs): kwargs["find_all"] = True devices = find(**kwargs) strings = "" for device in devices: if not verbose: strings += "%s, %s\n" % (device._str(), _try_lookup( _lu.device_classes, device.bDeviceClass)) else: ...
[ "def", "show_devices", "(", "verbose", "=", "False", ",", "*", "*", "kwargs", ")", ":", "kwargs", "[", "\"find_all\"", "]", "=", "True", "devices", "=", "find", "(", "*", "*", "kwargs", ")", "strings", "=", "\"\"", "for", "device", "in", "devices", "...
Show information about connected devices. The verbose flag sets to verbose or not. **kwargs are passed directly to the find() function.
[ "Show", "information", "about", "connected", "devices", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L1275-L1291
241,281
pyusb/pyusb
usb/core.py
Device.langids
def langids(self): """ Return the USB device's supported language ID codes. These are 16-bit codes familiar to Windows developers, where for example instead of en-US you say 0x0409. USB_LANGIDS.pdf on the usb.org developer site for more info. String requests using a LANGID not i...
python
def langids(self): if self._langids is None: try: self._langids = util.get_langids(self) except USBError: self._langids = () return self._langids
[ "def", "langids", "(", "self", ")", ":", "if", "self", ".", "_langids", "is", "None", ":", "try", ":", "self", ".", "_langids", "=", "util", ".", "get_langids", "(", "self", ")", "except", "USBError", ":", "self", ".", "_langids", "=", "(", ")", "r...
Return the USB device's supported language ID codes. These are 16-bit codes familiar to Windows developers, where for example instead of en-US you say 0x0409. USB_LANGIDS.pdf on the usb.org developer site for more info. String requests using a LANGID not in this array should not be sent...
[ "Return", "the", "USB", "device", "s", "supported", "language", "ID", "codes", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L794-L810
241,282
pyusb/pyusb
usb/core.py
Device.serial_number
def serial_number(self): """ Return the USB device's serial number string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._serial_number is None: self._serial_number = util....
python
def serial_number(self): if self._serial_number is None: self._serial_number = util.get_string(self, self.iSerialNumber) return self._serial_number
[ "def", "serial_number", "(", "self", ")", ":", "if", "self", ".", "_serial_number", "is", "None", ":", "self", ".", "_serial_number", "=", "util", ".", "get_string", "(", "self", ",", "self", ".", "iSerialNumber", ")", "return", "self", ".", "_serial_numbe...
Return the USB device's serial number string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use.
[ "Return", "the", "USB", "device", "s", "serial", "number", "string", "descriptor", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L813-L821
241,283
pyusb/pyusb
usb/core.py
Device.product
def product(self): """ Return the USB device's product string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._product is None: self._product = util.get_string(self, self.iP...
python
def product(self): if self._product is None: self._product = util.get_string(self, self.iProduct) return self._product
[ "def", "product", "(", "self", ")", ":", "if", "self", ".", "_product", "is", "None", ":", "self", ".", "_product", "=", "util", ".", "get_string", "(", "self", ",", "self", ".", "iProduct", ")", "return", "self", ".", "_product" ]
Return the USB device's product string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use.
[ "Return", "the", "USB", "device", "s", "product", "string", "descriptor", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L824-L832
241,284
pyusb/pyusb
usb/core.py
Device.parent
def parent(self): """ Return the parent device. """ if self._has_parent is None: _parent = self._ctx.backend.get_parent(self._ctx.dev) self._has_parent = _parent is not None if self._has_parent: self._parent = Device(_parent, self._ctx.backend) ...
python
def parent(self): if self._has_parent is None: _parent = self._ctx.backend.get_parent(self._ctx.dev) self._has_parent = _parent is not None if self._has_parent: self._parent = Device(_parent, self._ctx.backend) else: self._parent = ...
[ "def", "parent", "(", "self", ")", ":", "if", "self", ".", "_has_parent", "is", "None", ":", "_parent", "=", "self", ".", "_ctx", ".", "backend", ".", "get_parent", "(", "self", ".", "_ctx", ".", "dev", ")", "self", ".", "_has_parent", "=", "_parent"...
Return the parent device.
[ "Return", "the", "parent", "device", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L835-L844
241,285
pyusb/pyusb
usb/core.py
Device.manufacturer
def manufacturer(self): """ Return the USB device's manufacturer string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use. """ if self._manufacturer is None: self._manufacturer = util.get_...
python
def manufacturer(self): if self._manufacturer is None: self._manufacturer = util.get_string(self, self.iManufacturer) return self._manufacturer
[ "def", "manufacturer", "(", "self", ")", ":", "if", "self", ".", "_manufacturer", "is", "None", ":", "self", ".", "_manufacturer", "=", "util", ".", "get_string", "(", "self", ",", "self", ".", "iManufacturer", ")", "return", "self", ".", "_manufacturer" ]
Return the USB device's manufacturer string descriptor. This property will cause some USB traffic the first time it is accessed and cache the resulting value for future use.
[ "Return", "the", "USB", "device", "s", "manufacturer", "string", "descriptor", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L847-L855
241,286
pyusb/pyusb
usb/core.py
Device.set_interface_altsetting
def set_interface_altsetting(self, interface = None, alternate_setting = None): r"""Set the alternate setting for an interface. When you want to use an interface and it has more than one alternate setting, you should call this method to select the appropriate alternate setting. If you c...
python
def set_interface_altsetting(self, interface = None, alternate_setting = None): r"""Set the alternate setting for an interface. When you want to use an interface and it has more than one alternate setting, you should call this method to select the appropriate alternate setting. If you c...
[ "def", "set_interface_altsetting", "(", "self", ",", "interface", "=", "None", ",", "alternate_setting", "=", "None", ")", ":", "self", ".", "_ctx", ".", "managed_set_interface", "(", "self", ",", "interface", ",", "alternate_setting", ")" ]
r"""Set the alternate setting for an interface. When you want to use an interface and it has more than one alternate setting, you should call this method to select the appropriate alternate setting. If you call the method without one or the two parameters, it will be selected the first ...
[ "r", "Set", "the", "alternate", "setting", "for", "an", "interface", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L879-L904
241,287
pyusb/pyusb
usb/core.py
Device.reset
def reset(self): r"""Reset the device.""" self._ctx.managed_open() self._ctx.dispose(self, False) self._ctx.backend.reset_device(self._ctx.handle) self._ctx.dispose(self, True)
python
def reset(self): r"""Reset the device.""" self._ctx.managed_open() self._ctx.dispose(self, False) self._ctx.backend.reset_device(self._ctx.handle) self._ctx.dispose(self, True)
[ "def", "reset", "(", "self", ")", ":", "self", ".", "_ctx", ".", "managed_open", "(", ")", "self", ".", "_ctx", ".", "dispose", "(", "self", ",", "False", ")", "self", ".", "_ctx", ".", "backend", ".", "reset_device", "(", "self", ".", "_ctx", ".",...
r"""Reset the device.
[ "r", "Reset", "the", "device", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L913-L918
241,288
pyusb/pyusb
usb/core.py
Device.ctrl_transfer
def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength = None, timeout = None): r"""Do a control transfer on the endpoint 0. This method is used to issue a control transfer over the endpoint 0 (endpoint 0 is required to always be a control endpoint). ...
python
def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength = None, timeout = None): r"""Do a control transfer on the endpoint 0. This method is used to issue a control transfer over the endpoint 0 (endpoint 0 is required to always be a control endpoint). ...
[ "def", "ctrl_transfer", "(", "self", ",", "bmRequestType", ",", "bRequest", ",", "wValue", "=", "0", ",", "wIndex", "=", "0", ",", "data_or_wLength", "=", "None", ",", "timeout", "=", "None", ")", ":", "try", ":", "buff", "=", "util", ".", "create_buff...
r"""Do a control transfer on the endpoint 0. This method is used to issue a control transfer over the endpoint 0 (endpoint 0 is required to always be a control endpoint). The parameters bmRequestType, bRequest, wValue and wIndex are the same of the USB Standard Control Request format. ...
[ "r", "Do", "a", "control", "transfer", "on", "the", "endpoint", "0", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L999-L1053
241,289
pyusb/pyusb
usb/core.py
Device.is_kernel_driver_active
def is_kernel_driver_active(self, interface): r"""Determine if there is kernel driver associated with the interface. If a kernel driver is active, the object will be unable to perform I/O. The interface parameter is the device interface number to check. """ self._ctx.ma...
python
def is_kernel_driver_active(self, interface): r"""Determine if there is kernel driver associated with the interface. If a kernel driver is active, the object will be unable to perform I/O. The interface parameter is the device interface number to check. """ self._ctx.ma...
[ "def", "is_kernel_driver_active", "(", "self", ",", "interface", ")", ":", "self", ".", "_ctx", ".", "managed_open", "(", ")", "return", "self", ".", "_ctx", ".", "backend", ".", "is_kernel_driver_active", "(", "self", ".", "_ctx", ".", "handle", ",", "int...
r"""Determine if there is kernel driver associated with the interface. If a kernel driver is active, the object will be unable to perform I/O. The interface parameter is the device interface number to check.
[ "r", "Determine", "if", "there", "is", "kernel", "driver", "associated", "with", "the", "interface", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L1055-L1066
241,290
pyusb/pyusb
usb/core.py
Device.detach_kernel_driver
def detach_kernel_driver(self, interface): r"""Detach a kernel driver. If successful, you will then be able to perform I/O. The interface parameter is the device interface number to detach the driver from. """ self._ctx.managed_open() self._ctx.backend.detach_ke...
python
def detach_kernel_driver(self, interface): r"""Detach a kernel driver. If successful, you will then be able to perform I/O. The interface parameter is the device interface number to detach the driver from. """ self._ctx.managed_open() self._ctx.backend.detach_ke...
[ "def", "detach_kernel_driver", "(", "self", ",", "interface", ")", ":", "self", ".", "_ctx", ".", "managed_open", "(", ")", "self", ".", "_ctx", ".", "backend", ".", "detach_kernel_driver", "(", "self", ".", "_ctx", ".", "handle", ",", "interface", ")" ]
r"""Detach a kernel driver. If successful, you will then be able to perform I/O. The interface parameter is the device interface number to detach the driver from.
[ "r", "Detach", "a", "kernel", "driver", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/core.py#L1068-L1079
241,291
pyusb/pyusb
usb/libloader.py
load_library
def load_library(lib, name=None, lib_cls=None): """Loads a library. Catches and logs exceptions. Returns: the loaded library or None arguments: * lib -- path to/name of the library to be loaded * name -- the library's identifier (for logging) Defaults to None. ...
python
def load_library(lib, name=None, lib_cls=None): try: if lib_cls: return lib_cls(lib) else: return ctypes.CDLL(lib) except Exception: if name: lib_msg = '%s (%s)' % (name, lib) else: lib_msg = lib lib_msg += ' could not be l...
[ "def", "load_library", "(", "lib", ",", "name", "=", "None", ",", "lib_cls", "=", "None", ")", ":", "try", ":", "if", "lib_cls", ":", "return", "lib_cls", "(", "lib", ")", "else", ":", "return", "ctypes", ".", "CDLL", "(", "lib", ")", "except", "Ex...
Loads a library. Catches and logs exceptions. Returns: the loaded library or None arguments: * lib -- path to/name of the library to be loaded * name -- the library's identifier (for logging) Defaults to None. * lib_cls -- library class. Defaults to None (-> cty...
[ "Loads", "a", "library", ".", "Catches", "and", "logs", "exceptions", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/libloader.py#L88-L115
241,292
pyusb/pyusb
usb/libloader.py
load_locate_library
def load_locate_library(candidates, cygwin_lib, name, win_cls=None, cygwin_cls=None, others_cls=None, find_library=None, check_symbols=None): """Locates and loads a library. Returns: the loaded library arguments: * candidates -- candidates list for lo...
python
def load_locate_library(candidates, cygwin_lib, name, win_cls=None, cygwin_cls=None, others_cls=None, find_library=None, check_symbols=None): if sys.platform == 'cygwin': if cygwin_lib: loaded_lib = load_library(cygwin_lib, name, cygwin_cls) ...
[ "def", "load_locate_library", "(", "candidates", ",", "cygwin_lib", ",", "name", ",", "win_cls", "=", "None", ",", "cygwin_cls", "=", "None", ",", "others_cls", "=", "None", ",", "find_library", "=", "None", ",", "check_symbols", "=", "None", ")", ":", "if...
Locates and loads a library. Returns: the loaded library arguments: * candidates -- candidates list for locate_library() * cygwin_lib -- name of the cygwin library * name -- lib identifier (for logging). Defaults to None. * win_cls -- class that is used to instantiate the ...
[ "Locates", "and", "loads", "a", "library", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/libloader.py#L117-L177
241,293
pyusb/pyusb
usb/control.py
get_status
def get_status(dev, recipient = None): r"""Return the status for the specified recipient. dev is the Device object to which the request will be sent to. The recipient can be None (on which the status will be queried from the device), an Interface or Endpoint descriptors. The status value is r...
python
def get_status(dev, recipient = None): r"""Return the status for the specified recipient. dev is the Device object to which the request will be sent to. The recipient can be None (on which the status will be queried from the device), an Interface or Endpoint descriptors. The status value is r...
[ "def", "get_status", "(", "dev", ",", "recipient", "=", "None", ")", ":", "bmRequestType", ",", "wIndex", "=", "_parse_recipient", "(", "recipient", ",", "util", ".", "CTRL_IN", ")", "ret", "=", "dev", ".", "ctrl_transfer", "(", "bmRequestType", "=", "bmRe...
r"""Return the status for the specified recipient. dev is the Device object to which the request will be sent to. The recipient can be None (on which the status will be queried from the device), an Interface or Endpoint descriptors. The status value is returned as an integer with the lower wo...
[ "r", "Return", "the", "status", "for", "the", "specified", "recipient", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/control.py#L79-L96
241,294
pyusb/pyusb
usb/control.py
get_descriptor
def get_descriptor(dev, desc_size, desc_type, desc_index, wIndex = 0): r"""Return the specified descriptor. dev is the Device object to which the request will be sent to. desc_size is the descriptor size. desc_type and desc_index are the descriptor type and index, respectively. wIndex index i...
python
def get_descriptor(dev, desc_size, desc_type, desc_index, wIndex = 0): r"""Return the specified descriptor. dev is the Device object to which the request will be sent to. desc_size is the descriptor size. desc_type and desc_index are the descriptor type and index, respectively. wIndex index i...
[ "def", "get_descriptor", "(", "dev", ",", "desc_size", ",", "desc_type", ",", "desc_index", ",", "wIndex", "=", "0", ")", ":", "wValue", "=", "desc_index", "|", "(", "desc_type", "<<", "8", ")", "bmRequestType", "=", "util", ".", "build_request_type", "(",...
r"""Return the specified descriptor. dev is the Device object to which the request will be sent to. desc_size is the descriptor size. desc_type and desc_index are the descriptor type and index, respectively. wIndex index is used for string descriptors and represents the Language ID. For other...
[ "r", "Return", "the", "specified", "descriptor", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/control.py#L135-L160
241,295
pyusb/pyusb
usb/control.py
set_descriptor
def set_descriptor(dev, desc, desc_type, desc_index, wIndex = None): r"""Update an existing descriptor or add a new one. dev is the Device object to which the request will be sent to. The desc parameter is the descriptor to be sent to the device. desc_type and desc_index are the descriptor type an...
python
def set_descriptor(dev, desc, desc_type, desc_index, wIndex = None): r"""Update an existing descriptor or add a new one. dev is the Device object to which the request will be sent to. The desc parameter is the descriptor to be sent to the device. desc_type and desc_index are the descriptor type an...
[ "def", "set_descriptor", "(", "dev", ",", "desc", ",", "desc_type", ",", "desc_index", ",", "wIndex", "=", "None", ")", ":", "wValue", "=", "desc_index", "|", "(", "desc_type", "<<", "8", ")", "bmRequestType", "=", "util", ".", "build_request_type", "(", ...
r"""Update an existing descriptor or add a new one. dev is the Device object to which the request will be sent to. The desc parameter is the descriptor to be sent to the device. desc_type and desc_index are the descriptor type and index, respectively. wIndex index is used for string descriptors ...
[ "r", "Update", "an", "existing", "descriptor", "or", "add", "a", "new", "one", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/control.py#L162-L186
241,296
pyusb/pyusb
usb/control.py
get_configuration
def get_configuration(dev): r"""Get the current active configuration of the device. dev is the Device object to which the request will be sent to. This function differs from the Device.get_active_configuration method because the later may use cached data, while this function always does a devi...
python
def get_configuration(dev): r"""Get the current active configuration of the device. dev is the Device object to which the request will be sent to. This function differs from the Device.get_active_configuration method because the later may use cached data, while this function always does a devi...
[ "def", "get_configuration", "(", "dev", ")", ":", "bmRequestType", "=", "util", ".", "build_request_type", "(", "util", ".", "CTRL_IN", ",", "util", ".", "CTRL_TYPE_STANDARD", ",", "util", ".", "CTRL_RECIPIENT_DEVICE", ")", "return", "dev", ".", "ctrl_transfer",...
r"""Get the current active configuration of the device. dev is the Device object to which the request will be sent to. This function differs from the Device.get_active_configuration method because the later may use cached data, while this function always does a device request.
[ "r", "Get", "the", "current", "active", "configuration", "of", "the", "device", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/control.py#L188-L206
241,297
pyusb/pyusb
usb/control.py
get_interface
def get_interface(dev, bInterfaceNumber): r"""Get the current alternate setting of the interface. dev is the Device object to which the request will be sent to. """ bmRequestType = util.build_request_type( util.CTRL_IN, util.CTRL_TYPE_STANDARD...
python
def get_interface(dev, bInterfaceNumber): r"""Get the current alternate setting of the interface. dev is the Device object to which the request will be sent to. """ bmRequestType = util.build_request_type( util.CTRL_IN, util.CTRL_TYPE_STANDARD...
[ "def", "get_interface", "(", "dev", ",", "bInterfaceNumber", ")", ":", "bmRequestType", "=", "util", ".", "build_request_type", "(", "util", ".", "CTRL_IN", ",", "util", ".", "CTRL_TYPE_STANDARD", ",", "util", ".", "CTRL_RECIPIENT_INTERFACE", ")", "return", "dev...
r"""Get the current alternate setting of the interface. dev is the Device object to which the request will be sent to.
[ "r", "Get", "the", "current", "alternate", "setting", "of", "the", "interface", "." ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/usb/control.py#L216-L231
241,298
pyusb/pyusb
tools/vcp_terminal.py
configInputQueue
def configInputQueue(): """ configure a queue for accepting characters and return the queue """ def captureInput(iqueue): while True: c = getch() if c == '\x03' or c == '\x04': # end on ctrl+c / ctrl+d log.debug("Break received (\\x{0:02X})".format(ord(c)))...
python
def configInputQueue(): def captureInput(iqueue): while True: c = getch() if c == '\x03' or c == '\x04': # end on ctrl+c / ctrl+d log.debug("Break received (\\x{0:02X})".format(ord(c))) iqueue.put(c) break log.debug( ...
[ "def", "configInputQueue", "(", ")", ":", "def", "captureInput", "(", "iqueue", ")", ":", "while", "True", ":", "c", "=", "getch", "(", ")", "if", "c", "==", "'\\x03'", "or", "c", "==", "'\\x04'", ":", "# end on ctrl+c / ctrl+d", "log", ".", "debug", "...
configure a queue for accepting characters and return the queue
[ "configure", "a", "queue", "for", "accepting", "characters", "and", "return", "the", "queue" ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/tools/vcp_terminal.py#L518-L537
241,299
pyusb/pyusb
tools/vcp_terminal.py
fmt_text
def fmt_text(text): """ convert characters that aren't printable to hex format """ PRINTABLE_CHAR = set( list(range(ord(' '), ord('~') + 1)) + [ord('\r'), ord('\n')]) newtext = ("\\x{:02X}".format( c) if c not in PRINTABLE_CHAR else chr(c) for c in text) textlines = "\r\n".join(l.str...
python
def fmt_text(text): PRINTABLE_CHAR = set( list(range(ord(' '), ord('~') + 1)) + [ord('\r'), ord('\n')]) newtext = ("\\x{:02X}".format( c) if c not in PRINTABLE_CHAR else chr(c) for c in text) textlines = "\r\n".join(l.strip('\r') for l in "".join(newtext).split('\...
[ "def", "fmt_text", "(", "text", ")", ":", "PRINTABLE_CHAR", "=", "set", "(", "list", "(", "range", "(", "ord", "(", "' '", ")", ",", "ord", "(", "'~'", ")", "+", "1", ")", ")", "+", "[", "ord", "(", "'\\r'", ")", ",", "ord", "(", "'\\n'", ")"...
convert characters that aren't printable to hex format
[ "convert", "characters", "that", "aren", "t", "printable", "to", "hex", "format" ]
ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9
https://github.com/pyusb/pyusb/blob/ffe6faf42c6ad273880b0b464b9bbf44c1d4b2e9/tools/vcp_terminal.py#L540-L549