code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
m = Map(features=self._features, width=self._width, height=self._height, **self._attrs) m._folium_map = self._folium_map return m
def copy(self)
Copies the current Map into a new one and returns it.
7.53409
5.977267
1.260457
bounds = self._autobounds() attrs = {} midpoint = lambda a, b: (a + b)/2 attrs['location'] = ( midpoint(bounds['min_lat'], bounds['max_lat']), midpoint(bounds['min_lon'], bounds['max_lon']) ) # self._folium_map.fit_bounds( # ...
def _autozoom(self)
Calculate zoom and location.
4.076408
3.988733
1.021981
bounds = {} def check(prop, compare, extreme, val): opp = min if compare is max else max bounds.setdefault(prop, val) bounds[prop] = opp(compare(bounds[prop], val), extreme) def bound_check(lat_lon): lat, lon = lat_lon check(...
def _autobounds(self)
Simple calculation for bounds.
2.856877
2.773575
1.030034
attrs = self._attrs.copy() attrs.update({'width': self._width, 'height': self._height}) attrs.update(kwargs) return Map(self._features, **attrs)
def format(self, **kwargs)
Apply formatting.
4.971794
4.421539
1.124449
return { "type": "FeatureCollection", "features": [f.geojson(i) for i, f in self._features.items()] }
def geojson(self)
Render features as a FeatureCollection.
3.329526
2.749312
1.211039
# Set values and ids to both be simple sequences by inspecting values id_name, value_name = 'IDs', 'values' if isinstance(values, collections.abc.Mapping): assert not ids, 'IDs and a map cannot both be used together' if hasattr(values, 'columns') and len(values.c...
def color(self, values, ids=(), key_on='feature.id', palette='YlOrBr', **kwargs)
Color map features by binning values. values -- a sequence of values or a table of keys and values ids -- an ID for each value; if none are provided, indices are used key_on -- attribute of each feature to match to ids palette -- one of the following color brewer palettes: ...
4.638939
4.380137
1.059085
result = self.copy() if type(feature) == Table: # if table of features e.g. Table.from_records(taz_map.features) if 'feature' in feature: feature = feature['feature'] # if marker table e.g. table with columns: latitudes,longitudes,popup,color...
def overlay(self, feature, color='Blue', opacity=0.6)
Overlays ``feature`` on the map. Returns a new Map. Args: ``feature``: a ``Table`` of map features, a list of map features, a Map, a Region, or a circle marker map table. The features will be overlayed on the Map with specified ``color``. ``color`` (``st...
3.416663
3.084132
1.10782
assert path_or_json_or_string data = None if isinstance(path_or_json_or_string, (dict, list)): data = path_or_json_or_string try: data = json.loads(path_or_json_or_string) except ValueError: pass try: path = path_or...
def read_geojson(cls, path_or_json_or_string)
Read a geoJSON string, object, or file. Return a dict of features keyed by ID.
2.6692
2.508376
1.064115
if features is None: features = collections.OrderedDict() for i, feature in enumerate(data['features']): key = feature.get('id', prefix + str(i)) feature_type = feature['geometry']['type'] if feature_type == 'FeatureCollection': _r...
def _read_geojson_features(data, features=None, prefix="")
Return a dict of features keyed by ID.
2.896204
2.715335
1.066611
f = getattr(folium_map, self._map_method_name) f(**self._folium_kwargs)
def draw_on(self, folium_map)
Add feature to Folium map object.
5.850292
5.062441
1.155627
m = Map(features=[self], width=self._width, height=self._height) self._folium_map = m.draw()
def _set_folium_map(self)
A map containing only the feature.
6.931531
5.357558
1.293786
lat, lon = self.lat_lon return { 'type': 'Feature', 'id': feature_id, 'geometry': { 'type': 'Point', 'coordinates': (lon, lat), }, }
def geojson(self, feature_id)
GeoJSON representation of the marker as a point.
2.411968
2.17133
1.110825
attrs = self._attrs.copy() attrs.update(kwargs) lat, lon = self.lat_lon return type(self)(lat, lon, **attrs)
def format(self, **kwargs)
Apply formatting.
4.930475
4.59205
1.073698
lon, lat = feature['geometry']['coordinates'] popup = feature['properties'].get('name', '') return cls(lat, lon)
def _convert_point(cls, feature)
Convert a GeoJSON point to a Marker.
5.692873
4.14677
1.372845
assert len(latitudes) == len(longitudes) assert areas is None or hasattr(cls, '_has_radius'), "A " + cls.__name__ + " has no radius" inputs = [latitudes, longitudes] if labels is not None: assert len(labels) == len(latitudes) inputs.append(labels) ...
def map(cls, latitudes, longitudes, labels=None, colors=None, areas=None, **kwargs)
Return markers from columns of coordinates, labels, & colors. The areas column is not applicable to markers, but sets circle areas.
2.659317
2.623686
1.01358
if self.type == 'Polygon': polygons = [self._geojson['geometry']['coordinates']] elif self.type == 'MultiPolygon': polygons = self._geojson['geometry']['coordinates'] return [ [ [_lat_lons_from_geojson(s) for s in ring ] ...
def polygons(self)
Return a list of polygons describing the region. - Each polygon is a list of linear rings, where the first describes the exterior and the rest describe interior holes. - Each linear ring is a list of positions where the last is a repeat of the first. - Each position is a (la...
5.583274
5.133382
1.08764
if self._geojson.get('id', feature_id) == feature_id: return self._geojson else: geo = self._geojson.copy() geo['id'] = feature_id return geo
def geojson(self, feature_id)
Return GeoJSON with ID substituted.
3.099638
2.774537
1.117173
attrs = self._attrs.copy() attrs.update(kwargs) return Region(self._geojson, **attrs)
def format(self, **kwargs)
Apply formatting.
7.453293
6.627429
1.124613
return _combinable(lambda x: (y <= x < z) or _equal_or_float_equal(x, y))
def between(y, z)
Greater than or equal to y and less than z.
16.292664
15.244952
1.068725
return _combinable(lambda x: (y <= x <= z) or _equal_or_float_equal(x, y) or _equal_or_float_equal(x, z))
def between_or_equal_to(y, z)
Greater than or equal to y and less than or equal to z.
6.623032
6.232934
1.062586
if len(column) == 0: val_width = 0 else: val_width = max(len(self.format_value(v)) for v in column) val_width = min(val_width, self.max_width) width = max(val_width, len(str(label)), self.min_width, len(self.etc)) def pad(value, label=False): ...
def format_column(self, label, column)
Return a formatting function that pads & truncates values.
2.883749
2.64179
1.091589
if isinstance(value, (bool, np.bool_)): return str(value) elif isinstance(value, (int, np.integer)): return '{:n}'.format(value) elif isinstance(value, (float, np.floating)): return '{:g}'.format(value) else: return str(value)
def format_value(value)
Pretty-print an arbitrary value.
2.03102
1.922031
1.056705
return self.convert_value is not Formatter.convert_value or \ self.convert_column is not Formatter.convert_column
def converts_values(self)
Whether this Formatter also converts values.
9.866375
5.77763
1.707686
if isinstance(value, str): value = value.replace(self.separator, '') if self.decimal_point not in value: return int(value) else: return float(value.replace(self.decimal_point, '.')) elif self.int_to_float: return fl...
def convert_value(self, value)
Convert string 93,000.00 to float 93000.0.
2.7673
2.407076
1.149652
if isinstance(value, str): assert value.startswith(self.symbol), "Currency does not start with " + self.symbol value = value.lstrip(self.symbol) return super().convert_value(value)
def convert_value(self, value)
Convert value to float. If value is a string, ensure that the first character is the same as symbol ie. the value is in the currency this formatter is representing.
4.097363
3.013367
1.359729
assert all(values >= 0), 'Cannot normalize a column with negatives' total = sum(values) if total > 0: return values / total else: return values
def convert_column(self, values)
Normalize values.
4.661914
3.842098
1.213377
if value > MAX_VALUE: raise ValueError('value {!r} exceeds MAC address range'.format(value)) if value < 0: raise ValueError('value must not be negative') # todo: convert to the right byte order. the resulting # mac address is reversed on my machine compared to the # mac address displayed by the h...
def encode(value)
Encodes the number *value* to a MAC address ASCII string in binary form. Raises a #ValueError if *value* is a negative number or exceeds the MAC address range.
7.284379
6.505877
1.119661
bstr = bstr.replace(b':', b'') if len(bstr) != 12: raise ValueError('not a valid MAC address: {!r}'.format(bstr)) try: return int(bstr, 16) except ValueError: raise ValueError('not a valid MAC address: {!r}'.format(bstr))
def decode(bstr)
Decodes an ASCII encoded binary MAC address tring into a number.
2.655046
2.067373
1.284261
if sum(bool(x) for x in [lib_name, bin_path, sdk_path]) > 1: raise ValueError('expected zero or one arguments') if sdk_path: if sys.platform.startswith('win32'): bin_path = os.path.join(sdk_path, 'bin') elif sys.platform.startswith('darwin'): bin_path = os.path.join(sdk_path, 'myo.frame...
def init(lib_name=None, bin_path=None, sdk_path=None)
Initialize the Myo SDK by loading the libmyo shared library. With no arguments, libmyo must be on your `PATH` or `LD_LIBRARY_PATH`. You can specify the exact path to libmyo with *lib_name*. Alternatively, you can specify the binaries directory that contains libmyo with *bin_path*. Finally, you can also pass th...
2.67926
2.442482
1.096941
if not callable(handler): if hasattr(handler, 'on_event'): handler = handler.on_event else: raise TypeError('expected callable or DeviceListener') with self._lock: if self._running: raise RuntimeError('a handler is already running in the Hub') self._running...
def run(self, handler, duration_ms)
Runs the *handler* function for *duration_ms* milliseconds. The function must accept exactly one argument which is an #Event object. The handler must return either a #HandlerResult value, #False, #True or #None, whereas #False represents #HandlerResult.stop and #True and #None represent #HandlerResult.c...
3.487113
3.25565
1.071096
timer = TimeoutManager(timeout) with self._cond: # As long as there are no Myo's connected, wait until we # get notified about a change. while not timer.check(): # Check if we found a Myo that is connected. for device in self._devices.values(): if device.connect...
def wait_for_single_device(self, timeout=None, interval=0.5)
Waits until a Myo is was paired **and** connected with the Hub and returns it. If the *timeout* is exceeded, returns None. This function will not return a Myo that is only paired but not connected. # Parameters timeout: The maximum time to wait for a device. interval: The interval at which the func...
6.434569
6.318596
1.018354
if self.value is None: return True return (time.clock() - self.start) >= self.value
def check(self)
Returns #True if the time interval has passed.
8.866979
4.894676
1.811556
if value is None: value = time.clock() self.start = value if self.value_on_reset: self.value = self.value_on_reset
def reset(self, value=None)
Resets the start time of the interval to now or the specified value.
4.668906
4.144704
1.126475
if self.check(): self.reset(value) return True return False
def check_and_reset(self, value=None)
Combination of #check() and #reset().
10.064936
5.3499
1.881331
if self.value is None: return False return (time.clock() - self.start) >= self.value
def check(self)
Returns #True if the timeout is exceeded.
8.574418
4.686256
1.829695
if self.value is None: return max_value remainder = self.value - (time.clock() - self.start) if remainder < 0.0: return 0.0 elif max_value is not None and remainder > max_value: return max_value else: return remainder
def remainder(self, max_value=None)
Returns the time remaining for the timeout, or *max_value* if that remainder is larger.
2.998147
2.383884
1.257673
norm = self.magnitude() return Vector(self.x / norm, self.y / norm, self.z / norm)
def normalized(self)
Returns a normalized copy of this vector.
6.37509
3.481558
1.831102
return self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
def dot(self, rhs)
Return the dot product of this vector and *rhs*.
3.841932
2.233499
1.72014
return Vector( self.y * rhs.z - self.z * rhs.y, self.z * rhs.x - self.x * rhs.z, self.x * rhs.y - self.y * rhs.x)
def cross(self, rhs)
Return the cross product of this vector and *rhs*.
2.304274
1.954728
1.178821
return math.acos(self.dot(rhs) / (self.magnitude() * rhs.magnitude()))
def angle_to(self, rhs)
Return the angle between this vector and *rhs* in radians.
4.56813
2.661349
1.716472
return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2 + self.w ** 2)
def magnitude(self)
Returns the magnitude of the quaternion.
3.669509
1.965991
1.866493
magnitude = self.magnitude() return Quaternion( self.x / magnitude, self.y / magnitude, self.z / magnitude, self.w / magnitude)
def normalized(self)
Returns the unit quaternion corresponding to the same rotation as this one.
6.310114
3.587089
1.759118
qvec = self * Quaternion(vec.x, vec.y, vec.z, 0) * ~self return type(vec)(qvec.x, qvec.y, qvec.z)
def rotate(self, vec)
Returns *vec* rotated by this #Quaternion. :param vec: A vector object. :return: object of type of *vec*
5.578356
4.607411
1.210735
x, y, z, w = self.x, self.y, self.z, self.w return math.atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z)
def roll(self)
Calculates the Roll of the Quaternion.
2.58737
1.819817
1.421775
x, y, z, w = self.x, self.y, self.z, self.w return math.atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z)
def pitch(self)
Calculates the Pitch of the Quaternion.
2.691728
1.807141
1.489495
x, y, z, w = self.x, self.y, self.z, self.w return math.asin(2*x*y + 2*z*w)
def yaw(self)
Calculates the Yaw of the Quaternion.
4.305593
2.377416
1.811039
x, y, z, w = self.x, self.y, self.z, self.w roll = math.atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) pitch = math.atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) yaw = math.asin(2*x*y + 2*z*w) return (roll, pitch, yaw)
def rpy(self)
Calculates the Roll, Pitch and Yaw of the Quaternion.
1.630826
1.423018
1.146033
source = Vector(source.x, source.y, source.z) dest = Vector(dest.x, dest.y, dest.z) cross = source.cross(dest) cos_theta = source.dot(dest) # Return identity if the vectors are the same direction. if cos_theta >= 1.0: return Quaternion.identity() # Product of the square of the ...
def rotation_of(source, dest)
Returns a #Quaternion that represents a rotation from vector *source* to *dest*.
3.303803
3.276489
1.008336
sincomp = math.sin(angle / 2.0) return Quaternion( axis.x * sincomp, axis.y * sincomp, axis.z * sincomp, math.cos(angle / 2.0))
def from_axis_angle(axis, angle)
Returns a #Quaternion that represents the right-handed rotation of *angle* radians about the givne *axis*. :param axis: The unit vector representing the axis of rotation. :param angle: The angle of rotation, in radians.
3.204147
3.156461
1.015107
field_list = [] append = field_list.append for field in field_name_list: type_prefix = '' for char in field: if not char.islower(): break type_prefix += char append((field, _desc_type_dict[type_prefix])) result = type('some_descriptor'...
def newStruct(field_name_list)
Create a ctype structure class based on USB standard field naming (type-prefixed).
5.685439
5.488249
1.035929
transfer = transfer_p.contents offset = 0 result = [] append = result.append for iso_transfer in _get_iso_packet_list(transfer): length = iso_transfer.length append(_get_iso_packet_buffer(transfer, offset, length)) offset += length return result
def get_iso_packet_buffer_list(transfer_p)
Python-specific helper extracting a list of iso packet buffers.
3.469218
3.341553
1.038205
result = [] extra_length = descriptor.extra_length if extra_length: extra = buffer_at(descriptor.extra.value, extra_length) append = result.append while extra: length = _string_item_to_int(extra[0]) if not 0 < length <= len(extra): raise V...
def get_extra(descriptor)
Python-specific helper to access "extra" field of descriptors, because it's not as straight-forward as in C. Returns a list, where each entry is an individual extra descriptor.
4.496371
4.236236
1.061407
# As per ctypes.create_string_buffer, as of python 2.7.10 at least: # - int or long is a length # - str or unicode is an initialiser # Testing the latter confuses 2to3, so test the former. if isinstance(init_or_size, (int, long)): init_or_size = bytearray(init_or_size) return create...
def create_binary_buffer(init_or_size)
ctypes.create_string_buffer variant which does not add a trailing null when init_or_size is not a size.
6.959795
6.54132
1.063974
version = libusb1.libusb_get_version().contents return Version( version.major, version.minor, version.micro, version.nano, version.rc, version.describe, )
def getVersion()
Returns underlying libusb's version information as a 6-namedtuple (or 6-tuple if namedtuples are not avaiable): - major - minor - micro - nano - rc - describe Returns (0, 0, 0, 0, '', '') if libusb doesn't have required entry point.
4.75076
2.734876
1.737102
if self.__submitted: raise ValueError('Cannot close a submitted transfer') self.doom() self.__initialized = False # Break possible external reference cycles self.__callback = None self.__user_data = None # Break libusb_transfer reference cycle...
def close(self)
Break reference cycles to allow instance to be garbage-collected. Raises if called on a submitted transfer.
11.220655
9.815034
1.143211
self.__submitted = False self.__after_completion(self) callback = self.__callback if callback is not None: callback(self) if self.__doomed: self.close()
def __callbackWrapper(self, transfer_p)
Makes it possible for user-provided callback to alter transfer when fired (ie, mark transfer as not submitted upon call).
7.043765
6.305279
1.117122
if self.__submitted: raise ValueError('Cannot alter a submitted transfer') if self.__doomed: raise DoomedTransferError('Cannot reuse a doomed transfer') if isinstance(buffer_or_len, (int, long)): length = buffer_or_len # pylint: disable=un...
def setControl( self, request_type, request, value, index, buffer_or_len, callback=None, user_data=None, timeout=0)
Setup transfer for control use. request_type, request, value, index See USBDeviceHandle.controlWrite. request_type defines transfer direction (see ENDPOINT_OUT and ENDPOINT_IN)). buffer_or_len Either a string (when sending data), or expected data length (...
3.519901
3.519555
1.000098
if self.__submitted: raise ValueError('Cannot alter a submitted transfer') if self.__doomed: raise DoomedTransferError('Cannot reuse a doomed transfer') string_buffer, self.__transfer_py_buffer = create_binary_buffer( buffer_or_len ) s...
def setInterrupt( self, endpoint, buffer_or_len, callback=None, user_data=None, timeout=0)
Setup transfer for interrupt use. endpoint Endpoint to submit transfer to. Defines transfer direction (see ENDPOINT_OUT and ENDPOINT_IN)). buffer_or_len Either a string (when sending data), or expected data length (when receiving data) To avoi...
5.817943
5.972559
0.974112
if self.__submitted: raise ValueError('Cannot alter a submitted transfer') num_iso_packets = self.__num_iso_packets if num_iso_packets == 0: raise TypeError( 'This transfer canot be used for isochronous I/O. ' 'You must get another...
def setIsochronous( self, endpoint, buffer_or_len, callback=None, user_data=None, timeout=0, iso_transfer_length_list=None)
Setup transfer for isochronous use. endpoint Endpoint to submit transfer to. Defines transfer direction (see ENDPOINT_OUT and ENDPOINT_IN)). buffer_or_len Either a string (when sending data), or expected data length (when receiving data) To av...
3.12598
3.083035
1.01393
transfer_p = self.__transfer transfer = transfer_p.contents # pylint: disable=undefined-variable if transfer.type != TRANSFER_TYPE_ISOCHRONOUS: # pylint: enable=undefined-variable raise TypeError( 'This method cannot be called on non-iso t...
def getISOBufferList(self)
Get individual ISO transfer's buffer. Returns a list with one item per ISO transfer, with their individually-configured sizes. Returned list is consistent with getISOSetupList return value. Should not be called on a submitted transfer. See also iterISO.
6.609962
5.693063
1.161056
transfer_p = self.__transfer transfer = transfer_p.contents # pylint: disable=undefined-variable if transfer.type != TRANSFER_TYPE_ISOCHRONOUS: # pylint: enable=undefined-variable raise TypeError( 'This method cannot be called on non-iso t...
def getISOSetupList(self)
Get individual ISO transfer's setup. Returns a list of dicts, each containing an individual ISO transfer parameters: - length - actual_length - status (see libusb1's API documentation for their signification) Returned list is consistent with getISOBufferList retur...
5.544175
3.482172
1.59216
transfer_p = self.__transfer transfer = transfer_p.contents # pylint: disable=undefined-variable if transfer.type != TRANSFER_TYPE_ISOCHRONOUS: # pylint: enable=undefined-variable raise TypeError( 'This method cannot be called on non-iso t...
def iterISO(self)
Generator yielding (status, buffer) for each isochornous transfer. buffer is truncated to actual_length. This is more efficient than calling both getISOBufferList and getISOSetupList when receiving data. Should not be called on a submitted transfer.
5.929716
4.359985
1.360031
if self.__submitted: raise ValueError('Cannot alter a submitted transfer') transfer = self.__transfer.contents # pylint: disable=undefined-variable if transfer.type == TRANSFER_TYPE_CONTROL: # pylint: enable=undefined-variable raise ValueError...
def setBuffer(self, buffer_or_len)
Replace buffer with a new one. Allows resizing read buffer and replacing data sent. Note: resizing is not allowed for isochronous buffer (use setIsochronous). Note: disallowed on control transfers (use setControl).
3.510985
3.118184
1.125971
if self.__submitted: raise ValueError('Cannot submit a submitted transfer') if not self.__initialized: raise ValueError( 'Cannot submit a transfer until it has been initialized' ) if self.__doomed: raise DoomedTransferError...
def submit(self)
Submit transfer for asynchronous handling.
4.345715
3.945899
1.101324
if not self.__submitted: # XXX: Workaround for a bug reported on libusb 1.0.8: calling # libusb_cancel_transfer on a non-submitted transfer might # trigger a segfault. raise self.__USBErrorNotFound self.__mayRaiseUSBError(self.__libusb_cancel_tran...
def cancel(self)
Cancel transfer. Note: cancellation happens asynchronously, so you must wait for TRANSFER_CANCELLED.
10.055736
9.188505
1.094382
if event not in EVENT_CALLBACK_SET: raise ValueError('Unknown event %r.' % (event, )) self.__event_callback_dict[event] = callback
def setEventCallback(self, event, callback)
Set a function to call for a given event. event must be one of: TRANSFER_COMPLETED TRANSFER_ERROR TRANSFER_TIMED_OUT TRANSFER_CANCELLED TRANSFER_STALL TRANSFER_NO_DEVICE TRANSFER_OVERFLOW
4.92134
4.811788
1.022767
next_usb_timeout = self.__context.getNextTimeout() if timeout is None or timeout < 0: usb_timeout = next_usb_timeout elif next_usb_timeout: usb_timeout = min(next_usb_timeout, timeout) else: usb_timeout = timeout event_list = self.__po...
def poll(self, timeout=None)
Poll for events. timeout can be a float in seconds, or None for no timeout. Returns a list of (descriptor, event) pairs.
3.141578
2.967379
1.058705
if fd in self.__fd_set: raise ValueError( 'This fd is a special USB event fd, it cannot be polled.' ) self.__poller.register(fd, events)
def register(self, fd, events)
Register an USB-unrelated fd to poller. Convenience method.
9.353114
6.389382
1.463853
if fd in self.__fd_set: raise ValueError( 'This fd is a special USB event fd, it must stay registered.' ) self.__poller.unregister(fd)
def unregister(self, fd)
Unregister an USB-unrelated fd from poller. Convenience method.
14.606015
10.060315
1.451845
handle = self.__handle if handle is None: return # Build a strong set from weak self.__transfer_set so we can doom # and close all contained transfers. # Because of backward compatibility, self.__transfer_set might be a # wrapper around WeakKeyDiction...
def close(self)
Close this handle. If not called explicitely, will be called by destructor. This method cancels any in-flight transfer when it is called. As cancellation is not immediate, this method needs to let libusb handle events until transfers are actually cancelled. In multi-threaded pro...
6.459082
5.973833
1.081229
configuration = c_int() mayRaiseUSBError(libusb1.libusb_get_configuration( self.__handle, byref(configuration), )) return configuration.value
def getConfiguration(self)
Get the current configuration number for this device.
7.014629
5.166122
1.357813
mayRaiseUSBError( libusb1.libusb_claim_interface(self.__handle, interface), ) return _ReleaseInterface(self, interface)
def claimInterface(self, interface)
Claim (= get exclusive access to) given interface number. Required to receive/send data. Can be used as a context manager: with handle.claimInterface(0): # do stuff # handle.releaseInterface(0) gets automatically called
9.595828
10.122807
0.947941
mayRaiseUSBError(libusb1.libusb_set_interface_alt_setting( self.__handle, interface, alt_setting, ))
def setInterfaceAltSetting(self, interface, alt_setting)
Set interface's alternative setting (both parameters are integers).
8.353295
6.99028
1.194987
result = libusb1.libusb_kernel_driver_active(self.__handle, interface) if result == 0: return False elif result == 1: return True raiseUSBError(result)
def kernelDriverActive(self, interface)
Tell whether a kernel driver is active on given interface number.
3.281023
3.032872
1.08182
mayRaiseUSBError(libusb1.libusb_set_auto_detach_kernel_driver( self.__handle, bool(enable), ))
def setAutoDetachKernelDriver(self, enable)
Control automatic kernel driver detach. enable (bool) True to enable auto-detach, False to disable it.
7.644601
9.887437
0.773163
descriptor_string, _ = create_binary_buffer(STRING_LENGTH) result = libusb1.libusb_get_string_descriptor( self.__handle, 0, 0, descriptor_string, sizeof(descriptor_string), ) # pylint: disable=undefined-variable if result == ERROR_PIPE: # pylint: ...
def getSupportedLanguageList(self)
Return a list of USB language identifiers (as integers) supported by current device for its string descriptors. Note: language identifiers seem (I didn't check them all...) very similar to windows language identifiers, so you may want to use locales.windows_locale to get an rfc3066 repr...
5.994578
5.632467
1.06429
if descriptor == 0: return None descriptor_string = bytearray(STRING_LENGTH) try: received = mayRaiseUSBError(libusb1.libusb_get_string_descriptor( self.__handle, descriptor, lang_id, create_binary_buffer(descriptor_string)[0], ...
def getStringDescriptor(self, descriptor, lang_id, errors='strict')
Fetch description string for given descriptor and in given language. Use getSupportedLanguageList to know which languages are available. Return value is a unicode string. Return None if there is no such descriptor on device.
5.399126
5.44792
0.991043
if descriptor == 0: return None descriptor_string = bytearray(STRING_LENGTH) try: received = mayRaiseUSBError(libusb1.libusb_get_string_descriptor_ascii( self.__handle, descriptor, create_binary_buffer(descriptor_string)[0], ...
def getASCIIStringDescriptor(self, descriptor, errors='strict')
Fetch description string for given descriptor in first available language. Return value is a unicode string. Return None if there is no such descriptor on device.
5.845347
5.883859
0.993455
# pylint: disable=undefined-variable request_type = (request_type & ~ENDPOINT_DIR_MASK) | ENDPOINT_OUT # pylint: enable=undefined-variable data, _ = create_initialised_buffer(data) return self._controlTransfer(request_type, request, value, index, data, ...
def controlWrite( self, request_type, request, value, index, data, timeout=0)
Synchronous control write. request_type: request type bitmask (bmRequestType), see constants TYPE_* and RECIPIENT_*. request: request id (some values are standard). value, index, data: meaning is request-dependent. timeout: in milliseconds, how long to wait for device acknowled...
5.215849
5.134244
1.015894
# pylint: disable=undefined-variable request_type = (request_type & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) transferred = self._controlTransfer( request_type, request, value, index...
def controlRead( self, request_type, request, value, index, length, timeout=0)
Synchronous control read. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See controlWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" parameter. ...
4.42962
4.921632
0.900031
# pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_OUT # pylint: enable=undefined-variable data, _ = create_initialised_buffer(data) return self._bulkTransfer(endpoint, data, sizeof(data), timeout)
def bulkWrite(self, endpoint, data, timeout=0)
Synchronous bulk write. endpoint: endpoint to send data to. data: data to send. timeout: in milliseconds, how long to wait for device acknowledgement. Set to 0 to disable. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray)...
7.5772
6.656876
1.138252
# pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) try: transferred = self._bulkTransfer(endpoint, data, length, timeout) e...
def bulkRead(self, endpoint, length, timeout=0)
Synchronous bulk read. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See bulkWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" parameter. ...
4.853123
4.569557
1.062055
# pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_OUT # pylint: enable=undefined-variable data, _ = create_initialised_buffer(data) return self._interruptTransfer(endpoint, data, sizeof(data), timeout)
def interruptWrite(self, endpoint, data, timeout=0)
Synchronous interrupt write. endpoint: endpoint to send data to. data: data to send. timeout: in milliseconds, how long to wait for device acknowledgement. Set to 0 to disable. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytea...
6.193925
7.142055
0.867247
# pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) try: transferred = self._interruptTransfer( endpoint, ...
def interruptRead(self, endpoint, length, timeout=0)
Synchronous interrupt write. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. See interruptWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" paramete...
4.681789
4.650245
1.006783
result = USBTransfer( self.__handle, iso_packets, self.__inflight_add, self.__inflight_remove, ) self.__transfer_set.add(result) return result
def getTransfer(self, iso_packets=0)
Get an USBTransfer instance for asynchronous use. iso_packets: the number of isochronous transfer descriptors to allocate.
7.502648
6.675685
1.123877
port_list = (c_uint8 * PATH_MAX_DEPTH)() result = libusb1.libusb_get_port_numbers( self.device_p, port_list, len(port_list)) mayRaiseUSBError(result) return list(port_list[:result])
def getPortNumberList(self)
Get the port number of each hub toward device.
5.500513
5.180278
1.061818
result = libusb1.libusb_get_max_packet_size(self.device_p, endpoint) mayRaiseUSBError(result) return result
def getMaxPacketSize(self, endpoint)
Get device's max packet size for given endpoint. Warning: this function will not always give you the expected result. See https://libusb.org/ticket/77 . You should instead consult the endpoint descriptor of current configuration and alternate setting.
6.111666
5.706667
1.070969
result = libusb1.libusb_get_max_iso_packet_size(self.device_p, endpoint) mayRaiseUSBError(result) return result
def getMaxISOPacketSize(self, endpoint)
Get the maximum size for a single isochronous packet for given endpoint. Warning: this function will not always give you the expected result. See https://libusb.org/ticket/77 . You should instead consult the endpoint descriptor of current configuration and alternate setting.
5.8564
5.801775
1.009415
handle = libusb1.libusb_device_handle_p() mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle))) result = USBDeviceHandle(self.__context, handle, self) self.__close_set.add(result) return result
def open(self)
Open device. Returns an USBDeviceHandle instance.
5.883771
4.468984
1.316579
assert self.__context_refcount == 0 mayRaiseUSBError(libusb1.libusb_init(byref(self.__context_p))) return self
def open(self)
Finish context initialisation, as is normally done in __enter__ . This happens automatically on the first method call needing access to the uninitialised properties, but with a warning. Call this method ONLY if your usage pattern prevents you from using the with USBContext() as cont...
16.203451
11.489764
1.410251
self.__auto_open = False self.__context_cond.acquire() try: while self.__context_refcount and self.__context_p: self.__context_cond.wait() self._exit() finally: self.__context_cond.notifyAll() self.__context_cond.re...
def close(self)
Close (destroy) this USB context, and all related instances. When this method has been called, methods on its instance will become mosty no-ops, returning None until explicitly re-opened (by calling open() or __enter__()). Note: "exit" is a deprecated alias of "close".
4.920887
4.518615
1.089025
device_p_p = libusb1.libusb_device_p_p() libusb_device_p = libusb1.libusb_device_p device_list_len = libusb1.libusb_get_device_list(self.__context_p, byref(device_p_p)) mayRaiseUSBError(device_list_len) try: ...
def getDeviceIterator(self, skip_on_error=False)
Return an iterator over all USB devices currently plugged in, as USBDevice instances. skip_on_error (bool) If True, ignore devices which raise USBError.
5.053764
5.152528
0.980832
return list( self.getDeviceIterator( skip_on_error=skip_on_access_error or skip_on_error, ), )
def getDeviceList(self, skip_on_access_error=False, skip_on_error=False)
Return a list of all USB devices currently plugged in, as USBDevice instances. skip_on_error (bool) If True, ignore devices which raise USBError. skip_on_access_error (bool) DEPRECATED. Alias for skip_on_error.
4.963563
4.864328
1.020401
for device in self.getDeviceIterator( skip_on_error=skip_on_access_error or skip_on_error, ): if device.getVendorID() == vendor_id and \ device.getProductID() == product_id: return device
def getByVendorIDAndProductID( self, vendor_id, product_id, skip_on_access_error=False, skip_on_error=False)
Get the first USB device matching given vendor and product ids. Returns an USBDevice instance, or None if no present device match. skip_on_error (bool) (see getDeviceList) skip_on_access_error (bool) (see getDeviceList)
2.706419
2.537776
1.066453
result = self.getByVendorIDAndProductID( vendor_id, product_id, skip_on_access_error=skip_on_access_error, skip_on_error=skip_on_error) if result is not None: return result.open()
def openByVendorIDAndProductID( self, vendor_id, product_id, skip_on_access_error=False, skip_on_error=False)
Get the first USB device matching given vendor and product ids. Returns an USBDeviceHandle instance, or None if no present device match. skip_on_error (bool) (see getDeviceList) skip_on_access_error (bool) (see getDeviceList)
1.899483
2.026415
0.937361
pollfd_p_p = libusb1.libusb_get_pollfds(self.__context_p) if not pollfd_p_p: errno = get_errno() if errno: raise OSError(errno) else: # Assume not implemented raise NotImplementedError( 'Your...
def getPollFDList(self)
Return file descriptors to be used to poll USB events. You should not have to call this method, unless you are integrating this class with a polling mechanism.
3.260379
3.049298
1.069223
if tv is None: tv = 0 tv_s = int(tv) real_tv = libusb1.timeval(tv_s, int((tv - tv_s) * 1000000)) mayRaiseUSBError( libusb1.libusb_handle_events_timeout( self.__context_p, byref(real_tv), ), )
def handleEventsTimeout(self, tv=0)
Handle any pending event. If tv is 0, will return immediately after handling already-pending events. Otherwise, defines the maximum amount of time to wait for events, in seconds.
4.851507
4.494545
1.079421
if added_cb is None: added_cb = self.__null_pointer else: added_cb = libusb1.libusb_pollfd_added_cb_p(added_cb) if removed_cb is None: removed_cb = self.__null_pointer else: removed_cb = libusb1.libusb_pollfd_removed_cb_p(removed_c...
def setPollFDNotifiers( self, added_cb=None, removed_cb=None, user_data=None)
Give libusb1 methods to call when it should add/remove file descriptor for polling. You should not have to call this method, unless you are integrating this class with a polling mechanism.
1.902077
1.862452
1.021276
timeval = libusb1.timeval() result = libusb1.libusb_get_next_timeout( self.__context_p, byref(timeval)) if result == 0: return None elif result == 1: return timeval.tv_sec + (timeval.tv_usec * 0.000001) raiseUSBError(result)
def getNextTimeout(self)
Returns the next internal timeout that libusb needs to handle, in seconds, or None if no timeout is needed. You should not have to call this method, unless you are integrating this class with a polling mechanism.
2.986083
2.822882
1.057814
if tv is None: tv = 0 tv_s = int(tv) real_tv = libusb1.timeval(tv_s, int((tv - tv_s) * 1000000)) libusb1.libusb_wait_for_event(self.__context_p, byref(real_tv))
def waitForEvent(self, tv=0)
See libusb_wait_for_event doc.
3.880817
3.347007
1.159489