desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
''
| def profit(self, contract=None):
| pass
|
''
| def day_profit(self, contract=None):
| pass
|
'åœæ ¹baræ¶éŽç»ç¹æ®ååçå¯çšèµéïŒçšäºæµè¯ã'
| def test_cash(self):
| self.process_trading_events(at_baropen=False)
return self.cash()
|
'åœæ ¹baræ¶éŽç»ç¹æ®ååçæçïŒçšäºæµè¯ã'
| def test_equity(self):
| self.process_trading_events(at_baropen=False)
return self.equity()
|
'Args:
pcontracts (list): list of pcontracts(string)
dt_start (datetime/str): start time of all pcontracts
dt_end (datetime/str): end time of all pcontracts
n (int): last n bars
spec_date (dict): time range for specific pcontracts'
| def __init__(self, pcontracts, dt_start='1980-1-1', dt_end='2100-1-1', n=None, spec_date={}):
| self.finished_data = []
pcontracts = list(map((lambda x: x.upper()), pcontracts))
self.pcontracts = pcontracts
self._combs = []
self._data_manager = DataManager()
if (settings['source'] == 'csv'):
self.pcontracts = self._parse_pcontracts(self.pcontracts)
self._default_pcontract = self.pcontracts[0]
(self._all_data, self._max_window) = self._load_data(self.pcontracts, dt_start, dt_end, n, spec_date)
self.context = context.Context(self._all_data, self._max_window)
|
'Args:
comb (list): äžäžªçç¥ç»å'
| def add_comb(self, comb, settings):
| self._combs.append(comb)
num_strategy = len(comb)
if ('capital' not in settings):
settings['capital'] = 1000000.0
logger.info('BackTesting with default capital 1000000.0.')
assert (settings['capital'] > 0)
if (num_strategy == 1):
settings['ratio'] = [1]
elif ((num_strategy > 1) and ('ratio' not in settings)):
settings['ratio'] = ([(1.0 / num_strategy)] * num_strategy)
assert ('ratio' in settings)
assert (len(settings['ratio']) == num_strategy)
assert ((sum(settings['ratio']) - 1.0) < 1e-06)
assert (num_strategy >= 1)
ctxs = []
for (i, s) in enumerate(comb):
iset = {}
if settings:
iset = {'capital': (settings['capital'] * settings['ratio'][i])}
ctxs.append(strategy_context.StrategyContext(s.name, iset))
self.context.add_strategy_context(ctxs)
return Profile(ctxs, self._all_data, self.pcontracts[0], (len(self._combs) - 1))
|
''
| @abstractmethod
def connect(self):
| pass
|
''
| @abstractmethod
def query_contract(self, contract, sync=False):
| pass
|
''
| @abstractmethod
def query_tick(self, contract, sync=False):
| pass
|
''
| @abstractmethod
def query_captital(self, sync=False):
| pass
|
''
| @abstractmethod
def query_position(self, sync=False):
| pass
|
':param Order order: å§æè®¢åã'
| @abstractmethod
def order(self, order, sync=False):
| pass
|
''
| @abstractmethod
def cancel_order(self, orderid, sync=False):
| pass
|
''
| def on_transaction(self, trans):
| pass
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
''
| def connect(self):
| pass
|
''
| def query_contract(self, contract):
| pass
|
''
| def query_tick(self, contract):
| pass
|
''
| def query_captital(self):
| pass
|
''
| def query_position(self):
| pass
|
''
| def order(self, order):
| pass
|
''
| def cancel_order(self, orderid):
| pass
|
''
| def on_transaction(self, trans):
| pass
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
''
| def connect(self):
| pass
|
''
| def query_contract(self, contract):
| pass
|
''
| def query_tick(self, contract):
| pass
|
''
| def query_captital(self):
| pass
|
''
| def query_position(self):
| pass
|
''
| def order(self, order):
| self._events.put(OrderEvent(order))
|
''
| def cancel_order(self, orderid):
| pass
|
''
| def on_transaction(self, trans):
| self._blotter.update_fill(trans)
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
'nameçšæ¥è·èžª'
| def __init__(self, data=[], name='series', indic=None, default=None):
| self.curbar = 0
self._window_size = len(data)
self._indic = indic
self._default = default
self._realtime = False
self.name = name
if (len(data) == 0):
self.data = np.array(([self._default] * self._window_size))
else:
self.data = data
|
'Args:
data (list|ndarray|pd.Series): æ°æ®ïŒç±»åäžºæ¯æçŽ¢åŒçæ°æ®ç»æ
wwsize (int): çªå£å€§å°'
| def reset_data(self, data, wsize):
| self._window_size = wsize
if (len(data) == 0):
self.data = np.array(([self._default] * self._window_size))
else:
self.data = data
|
'æŽæ°åœåBar玢åŒ'
| def update_curbar(self, curbar):
| self.curbar = curbar
|
''
| def update(self, v):
| if isinstance(v, SeriesBase):
self.data[self.curbar] = v[0]
else:
self.data[self.curbar] = v
|
''
| def duplicate_last_element(self):
| try:
pre_elem = self.data[((self.curbar - 1) % self._window_size)]
except KeyError:
return
else:
self.data[self.curbar] = pre_elem
|
''
| def make_market(self, bars, at_baropen):
| if (len(self._open_orders) == 0):
return
fill_orders = set()
for order in self._open_orders:
if (order.side == TradeSide.CANCEL):
fill_orders.add(order)
transact = Transaction(order)
self.events.put(FillEvent(transact))
continue
try:
bar = bars[order.contract]
except KeyError:
logger.error(('\xe6\x89\x80\xe4\xba\xa4\xe6\x98\x93\xe7\x9a\x84\xe5\x90\x88\xe7\xba\xa6[%s]\xe6\x95\xb0\xe6\x8d\xae\xe4\xb8\x8d\xe5\xad\x98\xe5\x9c\xa8' % order.contract))
continue
transact = Transaction(order)
if self._strict:
if at_baropen:
if (order.price_type == PriceType.LMT):
price = bar.open
if (((order.side == TradeSide.KAI) and (((order.direction == Direction.LONG) and (order.price >= price)) or ((order.direction == Direction.SHORT) and (order.price <= price)))) or ((order.side == TradeSide.PING) and (((order.direction == Direction.LONG) and (order.price <= price)) or ((order.direction == Direction.SHORT) and (order.price >= price))))):
transact.price = order.price
transact.datetime = bar.datetime
fill_orders.add(order)
self.events.put(FillEvent(transact))
elif (order.price_type == PriceType.MKT):
transact.price = bar.open
transact.datetime = bar.datetime
transact.compute_commission()
fill_orders.add(order)
self.events.put(FillEvent(transact))
elif (order.price_type == PriceType.LMT):
if (((order.side == TradeSide.KAI) and (((order.direction == Direction.LONG) and (order.price >= bar.low)) or ((order.direction == Direction.SHORT) and (order.price <= bar.high)))) or ((order.side == TradeSide.PING) and (((order.direction == Direction.LONG) and (order.price <= bar.high)) or ((order.direction == Direction.SHORT) and (order.price >= bar.low))))):
transact.price = order.price
transact.datetime = bar.datetime
fill_orders.add(order)
self.events.put(FillEvent(transact))
elif (order.price_type == PriceType.MKT):
if (order.side == TradeSide.KAI):
if (order.direction == Direction.LONG):
transact.price = bar.high
else:
transact.price = bar.low
elif (order.side == TradeSide.PING):
if (order.direction == Direction.LONG):
transact.price = bar.low
else:
transact.price = bar.high
transact.datetime = bar.datetime
transact.compute_commission()
fill_orders.add(order)
self.events.put(FillEvent(transact))
else:
transact.datetime = bar.datetime
fill_orders.add(order)
self.events.put(FillEvent(transact))
if fill_orders:
self._open_orders -= fill_orders
|
''
| def insert_order(self, event):
| if (event.order in self._open_orders):
self._open_orders.remove(event.order)
self._open_orders.add(event.order)
|
'check ep for data, add it to queue and sleep for interval'
| def _read(self):
| while self._rxactive:
try:
rv = self._ep_in.read(self._ep_in.wMaxPacketSize)
if self._isFTDI:
status = rv[:2]
if ((status[0] != 1) or (status[1] != 96)):
log.info(u'USB Status: 0x{0:02X} 0x{1:02X}'.format(*status))
rv = rv[2:]
for rvi in rv:
self._rxqueue.put(rvi)
except usb.USBError as e:
log.warn(u'USB Error on _read {}'.format(e))
return
time.sleep(self._rxinterval)
|
'reset the FTDI device'
| def _resetFTDI(self):
| if (not self._isFTDI):
return
txdir = 0
req_type = 2
recipient = 0
req_type = (((txdir << 7) + (req_type << 5)) + recipient)
self.device.ctrl_transfer(bmRequestType=req_type, bRequest=0, wValue=0, wIndex=1, data_or_wLength=0)
|
'flush rx / tx buffers for ftdi device'
| def _flushFTDI(self, rx=True, tx=True):
| if (not self._isFTDI):
return
txdir = 0
req_type = (2 if self._isFTDI else 1)
recipient = (0 if self._isFTDI else 1)
req_type = (((txdir << 7) + (req_type << 5)) + recipient)
if rx:
self.device.ctrl_transfer(bmRequestType=req_type, bRequest=0, wValue=1, wIndex=1, data_or_wLength=0)
if tx:
self.device.ctrl_transfer(bmRequestType=req_type, bRequest=0, wValue=2, wIndex=1, data_or_wLength=0)
|
'Initialize the object.
This initializes the USBError object. The strerror and errno are passed
to the parent object. The error_code parameter is attributed to the
backend_error_code member variable.'
| def __init__(self, strerror, error_code=None, errno=None):
| IOError.__init__(self, errno, strerror)
self.backend_error_code = error_code
|
'Initialize the Endpoint object.
The device parameter is the device object returned by the find()
function. endpoint is the endpoint logical index (not the endpoint
address). The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). The interface
parameter is the interface logical index (not the bInterfaceNumber
field) and alternate_setting is the alternate setting logical index
(not the bAlternateSetting value). An interface may have only one
alternate setting. In this case, the alternate_setting parameter
should be zero. By "logical index" we mean the relative order of the
configurations returned by the peripheral as a result of GET_DESCRIPTOR
request.'
| def __init__(self, device, endpoint, interface=0, alternate_setting=0, configuration=0):
| self.device = device
self.index = endpoint
backend = device._ctx.backend
desc = backend.get_endpoint_descriptor(device._ctx.dev, endpoint, interface, alternate_setting, configuration)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'bEndpointAddress', 'bmAttributes', 'wMaxPacketSize', 'bInterval', 'bRefresh', 'bSynchAddress', 'extra_descriptors'))
|
'Write data to the endpoint.
The parameter data contains the data to be sent to the endpoint and
timeout is the time limit of the operation. The transfer type and
endpoint address are automatically inferred.
The method returns the number of bytes written.
For details, see the Device.write() method.'
| def write(self, data, timeout=None):
| return self.device.write(self, data, timeout)
|
'Read data from the endpoint.
The parameter size_or_buffer is either the number of bytes to
read or an array object where the data will be put in and timeout is the
time limit of the operation. The transfer type and endpoint address
are automatically inferred.
The method returns either an array object or the number of bytes
actually read.
For details, see the Device.read() method.'
| def read(self, size_or_buffer, timeout=None):
| return self.device.read(self, size_or_buffer, timeout)
|
'Clear the halt/status condition of the endpoint.'
| def clear_halt(self):
| self.device.clear_halt(self.bEndpointAddress)
|
'Initialize the interface object.
The device parameter is the device object returned by the find()
function. The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). The interface
parameter is the interface logical index (not the bInterfaceNumber
field) and alternate_setting is the alternate setting logical index
(not the bAlternateSetting value). An interface may have only one
alternate setting. In this case, the alternate_setting parameter
should be zero. By "logical index" we mean the relative order of
the configurations returned by the peripheral as a result of
GET_DESCRIPTOR request.'
| def __init__(self, device, interface=0, alternate_setting=0, configuration=0):
| self.device = device
self.alternate_index = alternate_setting
self.index = interface
self.configuration = configuration
backend = device._ctx.backend
desc = backend.get_interface_descriptor(self.device._ctx.dev, interface, alternate_setting, configuration)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'bInterfaceNumber', 'bAlternateSetting', 'bNumEndpoints', 'bInterfaceClass', 'bInterfaceSubClass', 'bInterfaceProtocol', 'iInterface', 'extra_descriptors'))
|
'Show all information for the interface.'
| def __str__(self):
| string = self._get_full_descriptor_str()
for endpoint in self:
string += ('\n' + str(endpoint))
return string
|
'Return a tuple of the interface endpoints.'
| def endpoints(self):
| return tuple(self)
|
'Set the interface alternate setting.'
| def set_altsetting(self):
| self.device.set_interface_altsetting(self.bInterfaceNumber, self.bAlternateSetting)
|
'Iterate over all endpoints of the interface.'
| def __iter__(self):
| for i in range(self.bNumEndpoints):
(yield Endpoint(self.device, i, self.index, self.alternate_index, self.configuration))
|
'Return the Endpoint object in the given position.'
| def __getitem__(self, index):
| return Endpoint(self.device, index, self.index, self.alternate_index, self.configuration)
|
'Initialize the configuration object.
The device parameter is the device object returned by the find()
function. The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). By "logical index"
we mean the relative order of the configurations returned by the
peripheral as a result of GET_DESCRIPTOR request.'
| def __init__(self, device, configuration=0):
| self.device = device
self.index = configuration
backend = device._ctx.backend
desc = backend.get_configuration_descriptor(self.device._ctx.dev, configuration)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'wTotalLength', 'bNumInterfaces', 'bConfigurationValue', 'iConfiguration', 'bmAttributes', 'bMaxPower', 'extra_descriptors'))
|
'Return a tuple of the configuration interfaces.'
| def interfaces(self):
| return tuple(self)
|
'Set this configuration as the active one.'
| def set(self):
| self.device.set_configuration(self.bConfigurationValue)
|
'Iterate over all interfaces of the configuration.'
| def __iter__(self):
| for i in range(self.bNumInterfaces):
alt = 0
try:
while True:
(yield Interface(self.device, i, alt, self.index))
alt += 1
except (USBError, IndexError):
pass
|
'Return the Interface object in the given position.
index is a tuple of two values with interface index and
alternate setting index, respectivally. Example:
>>> interface = config[(0, 0)]'
| def __getitem__(self, index):
| return Interface(self.device, index[0], index[1], self.index)
|
'Return a tuple of the device configurations.'
| def configurations(self):
| return tuple(self)
|
'Initialize the Device object.
Library users should normally get a Device instance through
the find function. The dev parameter is the identification
of a device to the backend and its meaning is opaque outside
of it. The backend parameter is a instance of a backend
object.'
| def __init__(self, dev, backend):
| self._ctx = _ResourceManager(dev, backend)
self.__default_timeout = _DEFAULT_TIMEOUT
(self._serial_number, self._product, self._manufacturer) = (None, None, None)
self._langids = None
desc = backend.get_device_descriptor(dev)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'bcdUSB', 'bDeviceClass', 'bDeviceSubClass', 'bDeviceProtocol', 'bMaxPacketSize0', 'idVendor', 'idProduct', 'bcdDevice', 'iManufacturer', 'iProduct', 'iSerialNumber', 'bNumConfigurations', 'address', 'bus', 'port_number', 'port_numbers', 'speed'))
if (desc.bus is not None):
self.bus = int(desc.bus)
else:
self.bus = None
if (desc.address is not None):
self.address = int(desc.address)
else:
self.address = None
if (desc.port_number is not None):
self.port_number = int(desc.port_number)
else:
self.port_number = None
if (desc.speed is not None):
self.speed = int(desc.speed)
else:
self.speed = None
|
'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 to the device.
This property will cause some USB traffic the first time it is accessed
and cache the resulting value for future use.'
| @property
def langids(self):
| if (self._langids is None):
try:
self._langids = util.get_langids(self)
except USBError:
self._langids = ()
return self._langids
|
'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.'
| @property
def serial_number(self):
| if (self._serial_number is None):
self._serial_number = util.get_string(self, self.iSerialNumber)
return self._serial_number
|
'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.'
| @property
def product(self):
| if (self._product is None):
self._product = util.get_string(self, self.iProduct)
return self._product
|
'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.'
| @property
def manufacturer(self):
| if (self._manufacturer is None):
self._manufacturer = util.get_string(self, self.iManufacturer)
return self._manufacturer
|
'Return the backend being used by the device.'
| @property
def backend(self):
| return self._ctx.backend
|
'Set the active configuration.
The configuration parameter is the bConfigurationValue field of the
configuration you want to set as active. If you call this method
without parameter, it will use the first configuration found. As a
device hardly ever has more than one configuration, calling the method
without arguments is enough to get the device ready.'
| def set_configuration(self, configuration=None):
| self._ctx.managed_set_configuration(self, configuration)
|
'Return a Configuration object representing the current
configuration set.'
| def get_active_configuration(self):
| return self._ctx.get_active_configuration(self)
|
'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 one found in the Device in
the same way of the set_configuration method.
Commonly, an interface has only one alternate setting and this call is
not necessary. For most devices, either it has more than one
alternate setting or not, it is not harmful to make a call to this
method with no arguments, as devices will silently ignore the request
when there is only one alternate setting, though the USB Spec allows
devices with no additional alternate setting return an error to the
Host in response to a SET_INTERFACE request.
If you are in doubt, you may want to call it with no arguments wrapped
by a try/except clause:
>>> try:
>>> dev.set_interface_altsetting()
>>> except usb.core.USBError:
>>> pass'
| def set_interface_altsetting(self, interface=None, alternate_setting=None):
| self._ctx.managed_set_interface(self, interface, alternate_setting)
|
'Clear the halt/stall condition for the endpoint ep.'
| def clear_halt(self, ep):
| if isinstance(ep, Endpoint):
ep = ep.bEndpointAddress
self._ctx.managed_open()
self._ctx.backend.clear_halt(self._ctx.handle, ep)
|
'Reset the device.'
| def reset(self):
| self._ctx.managed_open()
self._ctx.dispose(self, False)
self._ctx.backend.reset_device(self._ctx.handle)
self._ctx.dispose(self, True)
|
'Write data to the endpoint.
This method is used to send data to the device. The endpoint parameter
corresponds to the bEndpointAddress member whose endpoint you want to
communicate with.
The data parameter should be a sequence like type convertible to
the array type (see array module).
The timeout is specified in miliseconds.
The method returns the number of bytes written.'
| def write(self, endpoint, data, timeout=None):
| backend = self._ctx.backend
fn_map = {util.ENDPOINT_TYPE_BULK: backend.bulk_write, util.ENDPOINT_TYPE_INTR: backend.intr_write, util.ENDPOINT_TYPE_ISO: backend.iso_write}
(intf, ep) = self._ctx.setup_request(self, endpoint)
fn = fn_map[util.endpoint_type(ep.bmAttributes)]
return fn(self._ctx.handle, ep.bEndpointAddress, intf.bInterfaceNumber, _interop.as_array(data), self.__get_timeout(timeout))
|
'Read data from the endpoint.
This method is used to receive data from the device. The endpoint
parameter corresponds to the bEndpointAddress member whose endpoint
you want to communicate with. The size_or_buffer parameter either
tells how many bytes you want to read or supplies the buffer to
receive the data (it *must* be an object of the type array).
The timeout is specified in miliseconds.
If the size_or_buffer parameter is the number of bytes to read, the
method returns an array object with the data read. If the
size_or_buffer parameter is an array object, it returns the number
of bytes actually read.'
| def read(self, endpoint, size_or_buffer, timeout=None):
| backend = self._ctx.backend
fn_map = {util.ENDPOINT_TYPE_BULK: backend.bulk_read, util.ENDPOINT_TYPE_INTR: backend.intr_read, util.ENDPOINT_TYPE_ISO: backend.iso_read}
(intf, ep) = self._ctx.setup_request(self, endpoint)
fn = fn_map[util.endpoint_type(ep.bmAttributes)]
if isinstance(size_or_buffer, array.array):
buff = size_or_buffer
else:
buff = util.create_buffer(size_or_buffer)
ret = fn(self._ctx.handle, ep.bEndpointAddress, intf.bInterfaceNumber, buff, self.__get_timeout(timeout))
if isinstance(size_or_buffer, array.array):
return ret
elif (ret != (len(buff) * buff.itemsize)):
return buff[:ret]
else:
return buff
|
'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.
Control requests may or may not have a data payload to write/read.
In cases which it has, the direction bit of the bmRequestType
field is used to infer the desired request direction. For
host to device requests (OUT), data_or_wLength parameter is
the data payload to send, and it must be a sequence type convertible
to an array object. In this case, the return value is the number
of bytes written in the data payload. For device to host requests
(IN), data_or_wLength is either the wLength parameter of the control
request specifying the number of bytes to read in data payload, and
the return value is an array object with data read, or an array
object which the data will be read to, and the return value is the
number of bytes read.'
| def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength=None, timeout=None):
| try:
buff = util.create_buffer(data_or_wLength)
except TypeError:
buff = _interop.as_array(data_or_wLength)
self._ctx.managed_open()
recipient = (bmRequestType & 3)
rqtype = (bmRequestType & (3 << 5))
if ((recipient == util.CTRL_RECIPIENT_INTERFACE) and (rqtype != util.CTRL_TYPE_VENDOR)):
interface_number = (wIndex & 255)
self._ctx.managed_claim_interface(self, interface_number)
ret = self._ctx.backend.ctrl_transfer(self._ctx.handle, bmRequestType, bRequest, wValue, wIndex, buff, self.__get_timeout(timeout))
if (isinstance(data_or_wLength, array.array) or (util.ctrl_direction(bmRequestType) == util.CTRL_OUT)):
return ret
elif (ret != (len(buff) * buff.itemsize)):
return buff[:ret]
else:
return buff
|
'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.'
| def is_kernel_driver_active(self, interface):
| self._ctx.managed_open()
return self._ctx.backend.is_kernel_driver_active(self._ctx.handle, interface)
|
'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.'
| def detach_kernel_driver(self, interface):
| self._ctx.managed_open()
self._ctx.backend.detach_kernel_driver(self._ctx.handle, interface)
|
'Re-attach an interface\'s kernel driver, which was previously
detached using detach_kernel_driver().
The interface parameter is the device interface number to attach the
driver to.'
| def attach_kernel_driver(self, interface):
| self._ctx.managed_open()
self._ctx.backend.attach_kernel_driver(self._ctx.handle, interface)
|
'Iterate over all configurations of the device.'
| def __iter__(self):
| for i in range(self.bNumConfigurations):
(yield Configuration(self, i))
|
'Return the Configuration object in the given position.'
| def __getitem__(self, index):
| return Configuration(self, index)
|
'Actually finalizes the object (frees allocated resources etc.).
Returns: None
Derived classes should implement this.'
| def _finalize_object(self):
| pass
|
'Creates a new object instance and adds the private finalizer
attributes to it.
Returns: new object instance
Arguments:
* *args, **kwargs -- ignored'
| def __new__(cls, *args, **kwargs):
| instance = super(_AutoFinalizedObjectBase, cls).__new__(cls)
instance._finalize_called = False
return instance
|
'Helper method that finalizes the object if not already done.
Returns: None'
| def _do_finalize_object(self):
| if (not self._finalize_called):
self._finalize_called = True
self._finalize_object()
|
'Finalizes the object if not already done.
Returns: None'
| def finalize(self):
| raise NotImplementedError('finalize() must be implemented by AutoFinalizedObject.')
|
'Perform a bulk write request to the endpoint specified.
Arguments:
endpoint: endpoint number.
buffer: sequence data buffer to write.
This parameter can be any sequence type.
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.'
| def bulkWrite(self, endpoint, buffer, timeout=100):
| return self.dev.write(endpoint, buffer, timeout)
|
'Performs a bulk read request to the endpoint specified.
Arguments:
endpoint: endpoint number.
size: number of bytes to read.
timeout: operation timeout in milliseconds. (default: 100)
Returns a tuple with the data read.'
| def bulkRead(self, endpoint, size, timeout=100):
| return self.dev.read(endpoint, size, timeout)
|
'Perform a interrupt write request to the endpoint specified.
Arguments:
endpoint: endpoint number.
buffer: sequence data buffer to write.
This parameter can be any sequence type.
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.'
| def interruptWrite(self, endpoint, buffer, timeout=100):
| return self.dev.write(endpoint, buffer, timeout)
|
'Performs a interrupt read request to the endpoint specified.
Arguments:
endpoint: endpoint number.
size: number of bytes to read.
timeout: operation timeout in milliseconds. (default: 100)
Returns a tuple with the data read.'
| def interruptRead(self, endpoint, size, timeout=100):
| return self.dev.read(endpoint, size, timeout)
|
'Perform a control request to the default control pipe on a device.
Arguments:
requestType: specifies the direction of data flow, the type
of request, and the recipient.
request: specifies the request.
buffer: if the transfer is a write transfer, buffer is a sequence
with the transfer data, otherwise, buffer is the number of
bytes to read.
value: specific information to pass to the device. (default: 0)
index: specific information to pass to the device. (default: 0)
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.'
| def controlMsg(self, requestType, request, buffer, value=0, index=0, timeout=100):
| return self.dev.ctrl_transfer(requestType, request, wValue=value, wIndex=index, data_or_wLength=buffer, timeout=timeout)
|
'Clears any halt status on the specified endpoint.
Arguments:
endpoint: endpoint number.'
| def clearHalt(self, endpoint):
| self.dev.clear_halt(endpoint)
|
'Claims the interface with the Operating System.
Arguments:
interface: interface number or an Interface object.'
| def claimInterface(self, interface):
| if isinstance(interface, Interface):
interface = interface.interfaceNumber
util.claim_interface(self.dev, interface)
self.__claimed_interface = interface
|
'Release an interface previously claimed with claimInterface.'
| def releaseInterface(self):
| util.release_interface(self.dev, self.__claimed_interface)
self.__claimed_interface = (-1)
|
'Reset the specified device by sending a RESET
down the port it is connected to.'
| def reset(self):
| self.dev.reset()
|
'Reset all states for the specified endpoint.
Arguments:
endpoint: endpoint number.'
| def resetEndpoint(self, endpoint):
| self.clearHalt(endpoint)
|
'Set the active configuration of a device.
Arguments:
configuration: a configuration value or a Configuration object.'
| def setConfiguration(self, configuration):
| if isinstance(configuration, Configuration):
configuration = configuration.value
self.dev.set_configuration(configuration)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.