def __init__(self, vs_uuid_base=None, uuid_type=None):
assert isinstance(vs_uuid_base, (list, NoneType)), 'Invalid argument type'
assert isinstance(uuid_type, (int, long, NoneType)), 'Invalid argument type'
if (vs_uuid_base is None) and uuid_type is None:
self.base = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB]
self.type = driver.BLE_UUID_TYPE_BLE
else:
self.base = vs_uuid_base
self.type = uuid_type
python类NoneType()的实例源码
def ble_gap_conn_param_update(self, conn_handle, conn_params):
assert isinstance(conn_params, (BLEGapConnParams, NoneType)), 'Invalid argument type'
if conn_params:
conn_params=conn_params.to_c()
return driver.sd_ble_gap_conn_param_update(self.rpc_adapter, conn_handle, conn_params)
def ble_gap_authenticate(self, conn_handle, sec_params):
assert isinstance(sec_params, (BLEGapSecParams, NoneType)), 'Invalid argument type'
return driver.sd_ble_gap_authenticate(self.rpc_adapter,
conn_handle,
sec_params.to_c() if sec_params else None)
def ble_gattc_prim_srvc_disc(self, conn_handle, srvc_uuid, start_handle):
assert isinstance(srvc_uuid, (BLEUUID, NoneType)), 'Invalid argument type'
return driver.sd_ble_gattc_primary_services_discover(self.rpc_adapter,
conn_handle,
start_handle,
srvc_uuid.to_c() if srvc_uuid else None)
def write_success(self, data=None, finish=True):
assert isinstance(data, (types.NoneType, dict)), 'data must be NoneType or dict'
self._async_write(dict((data or {}), **{'status': 'success'}), finish=finish)
def create(field, node, parent=None):
item = ASTAttrTreeItem(field, node, parent)
if isinstance(node, list):
for child in node:
item.children.append(ASTTreeItem.create(child, parent=item))
elif not isinstance(node, (str, int, float, types.NoneType)):
item.children.append(ASTTreeItem.create(node, parent=item))
return item
def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_unicode(strings_only=True).
"""
return isinstance(obj, (
six.integer_types +
(types.NoneType,
datetime.datetime, datetime.date, datetime.time,
float, Decimal))
)
def save_sqlite(track_info):
[track, trackInfoEchoNest, trackInfoLastFM] = track_info
convert_type_dict = {float:'REAL', unicode:'TEXT', int:'INTEGER', str:'TEXT'}
EN_key_list = trackInfoEchoNest.keys()
LF_key_list = trackInfoLastFM.keys()
table_columns = []
column_names = []
question_mark_sign = []
for key in EN_key_list:
if type(trackInfoEchoNest[key]) != types.NoneType:
column_names.append('EN_' + key)
table_columns1 = ' '.join(['EN_' + key, convert_type_dict[type(trackInfoEchoNest[key])]])
table_columns.append(table_columns1)
question_mark_sign.append('?')
else:
trackInfoEchoNest.pop(key)
for key in LF_key_list:
if type(trackInfoLastFM[key]) != types.NoneType:
column_names.append('LF_' + key)
table_columns1 = ' '.join(['LF_' + key, convert_type_dict[type(trackInfoLastFM[key])]])
table_columns.append(table_columns1)
question_mark_sign.append('?')
else:
trackInfoLastFM.pop(key)
con = lite.connect('musicdata.db')
with con:
cur = con.cursor()
#cur.execute("DROP TABLE IF EXISTS BoardEntries")
cur.execute("SELECT ROWID FROM TrackEntries WHERE EN_title = ? and EN_artist_name = ?", (trackInfoEchoNest['title'],trackInfoEchoNest['artist_name']))
existingEntry=cur.fetchone()
if existingEntry is None:
print('saving into database %s, %s'%(trackInfoEchoNest['title'], trackInfoEchoNest['artist_name']))
single_entry = tuple([str(time.strftime("%Y-%m-%d %H:%M:%S")), track['title'], track['artist']] + trackInfoEchoNest.values() + trackInfoLastFM.values())
cur.execute('INSERT OR IGNORE INTO TrackEntries(ID, EntryDate, SearchTitle, SearchArtist, ' + ', '.join(column_names) + ') VALUES (NULL, ?,?,?, ' + ', '.join(question_mark_sign)+')', single_entry)
else:
print('found in database %s, %s'%(trackInfoEchoNest['title'], trackInfoEchoNest['artist_name']))
con.close()
def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_unicode(strings_only=True).
"""
return isinstance(obj, (
six.integer_types +
(types.NoneType,
datetime.datetime, datetime.date, datetime.time,
float, Decimal))
)
def test_unsubclassable_types(self):
with self.assertRaises(TypeError):
class X(types.NoneType):
pass
with self.assertRaises(TypeError):
class X(object, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(types.NoneType, object):
pass
class O(object):
pass
with self.assertRaises(TypeError):
class X(O, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(types.NoneType, O):
pass
class X(object):
pass
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType,
with self.assertRaises(TypeError):
X.__bases__ = object, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType, object
with self.assertRaises(TypeError):
X.__bases__ = O, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType, O
def test_unsubclassable_types(self):
with self.assertRaises(TypeError):
class X(types.NoneType):
pass
with self.assertRaises(TypeError):
class X(object, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(types.NoneType, object):
pass
class O(object):
pass
with self.assertRaises(TypeError):
class X(O, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(types.NoneType, O):
pass
class X(object):
pass
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType,
with self.assertRaises(TypeError):
X.__bases__ = object, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType, object
with self.assertRaises(TypeError):
X.__bases__ = O, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = types.NoneType, O
def properties(self, tags, id=None):
"""Return list of property tuples (id, name, value) for the specified tag(s) """
if type(tags) not in (types.ListType, types.TupleType) and type(id) not in (types.NoneType, types.ListType, types.TupleType):
single = True
else:
single = False
props = self.iproperties(tags, id)
if single:
return list(props)[0]
else:
return list(props)
def coerce_cache_params(params):
rules = [
('data_dir', (str, types.NoneType), "data_dir must be a string "
"referring to a directory."),
('lock_dir', (str, types.NoneType), "lock_dir must be a string referring to a "
"directory."),
('type', (str,), "Cache type must be a string."),
('enabled', (bool, types.NoneType), "enabled must be true/false "
"if present."),
('expire', (int, types.NoneType), "expire must be an integer representing "
"how many seconds the cache is valid for"),
('regions', (list, tuple, types.NoneType), "Regions must be a "
"comma seperated list of valid regions")
]
return verify_rules(params, rules)
def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_unicode(strings_only=True).
"""
return isinstance(obj, (
six.integer_types +
(types.NoneType,
datetime.datetime, datetime.date, datetime.time,
float, Decimal))
)
def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_unicode(strings_only=True).
"""
return isinstance(obj, (
six.integer_types +
(types.NoneType,
datetime.datetime, datetime.date, datetime.time,
float, Decimal))
)
def _is_protected_type(obj):
"""
True if the object is a native data type that does not need to be serialized further.
"""
return isinstance(obj, six.string_types + six.integer_types + (
types.NoneType,
datetime.datetime, datetime.date, datetime.time,
float, Decimal,
))
def comment(self, comment=None):
"""Modify or return a string comment."""
assert isinstance(comment, (basestring, types.NoneType)), "A comment is a string"
if comment is not None:
self._comment = comment
return self._comment
def X(self, value):
"""sets the X coordinate"""
if isinstance(value, (int, float,
long, types.NoneType)):
self._x = value
#----------------------------------------------------------------------
def Y(self, value):
""" sets the Y coordinate """
if isinstance(value, (int, float,
long, types.NoneType)):
self._y = value
#----------------------------------------------------------------------
def Z(self, value):
""" sets the Z coordinate """
if isinstance(value, (int, float,
long, types.NoneType)):
self._z = value
#----------------------------------------------------------------------