All Samples(276492) | Call(276492) | Derive(0) | Import(0)
isinstance(object, class-or-type-or-tuple) -> bool Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object's type. The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for isinstance(x, A) or isinstance(x, B) or ... (etc.).
src/w/r/writing_games_tutorial-HEAD/examples/example2/server.py writing_games_tutorial(Download)
def Notify(self, event): if isinstance( event, TickEvent ): return print 'TEXTLOG <', if isinstance( event, CharactorPlaceEvent ): print event.name, " at ", event.charactor.sector elif isinstance( event, CharactorMoveEvent ):
def Notify(self, event): if isinstance( event, ClientConnectEvent ): self.clients.append( event.client ) ev = event #don't broadcast events that aren't Copyable if not isinstance( ev, pb.Copyable ):
src/n/o/notmm-0.4.1/examples/lib/satchmo_admin/validation.py notmm(Download)
else:
# getattr(model, field) could be an X_RelatedObjectsDescriptor
f = fetch_attr(cls, model, opts, "list_display[%d]" % idx, field)
if isinstance(f, models.ManyToManyField):
raise ImproperlyConfigured("'%s.list_display[%d]', '%s' is a ManyToManyField which is not supported."
% (cls.__name__, idx, field))
get_field(cls, model, opts, 'list_filter[%d]' % idx, field)
# list_per_page = 100
if hasattr(cls, 'list_per_page') and not isinstance(cls.list_per_page, int):
raise ImproperlyConfigured("'%s.list_per_page' should be a integer."
% cls.__name__)
# date_hierarchy = None
if cls.date_hierarchy:
f = get_field(cls, model, opts, 'date_hierarchy', cls.date_hierarchy)
if not isinstance(f, (models.DateField, models.DateTimeField)):
raise ImproperlyConfigured("'%s.date_hierarchy is "
"neither an instance of DateField nor DateTimeField."
% cls.__name__)
# save_as = False
# save_on_top = False
for attr in ('list_select_related', 'save_as', 'save_on_top'):
if not isinstance(getattr(cls, attr), bool):
raise ImproperlyConfigured("'%s.%s' should be a boolean."
% (cls.__name__, attr))
def validate_inline(cls, parent, parent_model):
# model is already verified to exist and be a Model
if cls.fk_name: # default value is None
f = get_field(cls, cls.model, cls.model._meta, 'fk_name', cls.fk_name)
if not isinstance(f, models.ForeignKey):
raise ImproperlyConfigured("'%s.fk_name is not an instance of "
# extra = 3
# max_num = 0
for attr in ('extra', 'max_num'):
if not isinstance(getattr(cls, attr), int):
raise ImproperlyConfigured("'%s.%s' should be a integer."
% (cls.__name__, attr))
check_isseq(cls, 'raw_id_fields', cls.raw_id_fields)
for idx, field in enumerate(cls.raw_id_fields):
f = get_field(cls, model, opts, 'raw_id_fields', field)
if not isinstance(f, (models.ForeignKey, models.ManyToManyField)):
raise ImproperlyConfigured("'%s.raw_id_fields[%d]', '%s' must "
"be either a ForeignKey or ManyToManyField."
% (cls.__name__, idx, field))
# If we can't find a field on the model that matches,
# it could be an extra field on the form.
continue
if isinstance(f, models.ManyToManyField) and not f.rel.through._meta.auto_created:
raise ImproperlyConfigured("'%s.fields' can't include the ManyToManyField "
"field '%s' because '%s' manually specifies "
"a 'through' model." % (cls.__name__, field, field))
check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
try:
f = opts.get_field(field)
if isinstance(f, models.ManyToManyField) and not f.rel.through._meta.auto_created:
raise ImproperlyConfigured("'%s.fieldsets[%d][1]['fields']' "
"can't include the ManyToManyField field '%s' because "
"'%s' manually specifies a 'through' model." % (
check_isseq(cls, 'filter_vertical', cls.filter_vertical)
for idx, field in enumerate(cls.filter_vertical):
f = get_field(cls, model, opts, 'filter_vertical', field)
if not isinstance(f, models.ManyToManyField):
raise ImproperlyConfigured("'%s.filter_vertical[%d]' must be "
"a ManyToManyField." % (cls.__name__, idx))
# filter_horizontal
if hasattr(cls, 'filter_horizontal'):
check_isseq(cls, 'filter_horizontal', cls.filter_horizontal)
for idx, field in enumerate(cls.filter_horizontal):
f = get_field(cls, model, opts, 'filter_horizontal', field)
if not isinstance(f, models.ManyToManyField):
check_isdict(cls, 'radio_fields', cls.radio_fields)
for field, val in cls.radio_fields.items():
f = get_field(cls, model, opts, 'radio_fields', field)
if not (isinstance(f, models.ForeignKey) or f.choices):
raise ImproperlyConfigured("'%s.radio_fields['%s']' "
"is neither an instance of ForeignKey nor does "
"have choices set." % (cls.__name__, field))
check_isdict(cls, 'prepopulated_fields', cls.prepopulated_fields)
for field, val in cls.prepopulated_fields.items():
f = get_field(cls, model, opts, 'prepopulated_fields', field)
if isinstance(f, (models.DateTimeField, models.ForeignKey,
models.ManyToManyField)):
raise ImproperlyConfigured("'%s.prepopulated_fields['%s']' "
"is either a DateTimeField, ForeignKey or "
def check_isseq(cls, label, obj):
if not isinstance(obj, (list, tuple)):
raise ImproperlyConfigured("'%s.%s' must be a list or tuple." % (cls.__name__, label))
def check_isdict(cls, label, obj):
if not isinstance(obj, dict):
raise ImproperlyConfigured("'%s.%s' must be a dictionary." % (cls.__name__, label))
src/f/u/funcparserlib-0.3.4/examples/dot/dot.py funcparserlib(Download)
def kids(x):
'object -> list(object)'
if isinstance(x, (Graph, SubGraph)):
return [p('stmts', x.stmts)]
elif isinstance(x, (Node, DefAttrs)):
return [p('attrs', x.attrs)]
elif isinstance(x, Edge):
return [p('nodes', x.nodes), p('attrs', x.attrs)]
elif isinstance (x, Pair):
def show(x):
'object -> str'
if isinstance(x, Pair):
return x.first
elif isinstance(x, Graph):
return 'Graph [id=%s, strict=%r, type=%s]' % (
x.id, x.strict is not None, x.type)
elif isinstance(x, SubGraph):
return 'SubGraph [id=%s]' % x.id
elif isinstance(x, Edge):
return 'Edge'
elif isinstance(x, Attr):
return 'Attr [name=%s, value=%s]' % (x.name, x.value)
elif isinstance(x, DefAttrs):
return 'Attr [name=%s, value=%s]' % (x.name, x.value)
elif isinstance(x, DefAttrs):
return 'DefAttrs [object=%s]' % x.object
elif isinstance(x, Node):
return 'Node [id=%s]' % x.id
else:
return unicode(x)
src/k/a/Kamaelia-0.6.0/Examples/SoC2006/RJL/P2PStreamPeer/p2pstreampeer.py Kamaelia(Download)
while self.dataReady("inbox"):
msg = self.recv("inbox")
if isinstance(msg, TIPCNewTorrentCreated):
torrents.append([msg.torrentid, msg.savefolder]) # add the new torrent to the list of known torrents
elif isinstance(msg, TIPCTorrentStatusUpdate):
while self.dataReady("control"):
msg = self.recv("control")
if isinstance(msg, shutdown) or isinstance(msg, producerFinished):
# if we are being told to shutdown then do so
self.send(producerFinished(self), "signal")
return
while self.dataReady("control"):
msg = self.recv("control")
if isinstance(msg, shutdown) or isinstance(msg, producerFinished):
self.send(producerFinished(self), "signal")
return
src/p/y/python-tumblr-HEAD/samples/pygooglechart.py python-tumblr(Download)
def __init__(self, width, height, title=None, legend=None, colours=None,
auto_scale=True, x_range=None, y_range=None):
assert(type(self) != Chart) # This is an abstract class
assert(isinstance(width, int))
assert(isinstance(height, int))
self.width = width
self.height = height
def set_legend(self, legend):
"""legend needs to be a list, tuple or None"""
assert(isinstance(legend, list) or isinstance(legend, tuple) or
legend is None)
if legend:
self.legend = [urllib.quote(a) for a in legend]
else:
def set_colours(self, colours):
# colours needs to be a list, tuple or None
assert(isinstance(colours, list) or isinstance(colours, tuple) or
colours is None)
# make sure the colours are in the right format
if colours:
for col in colours:
def _check_fill_linear(self, angle, *args):
assert(isinstance(args, list) or isinstance(args, tuple))
assert(angle >= 0 and angle <= 90)
assert(len(args) % 2 == 0)
args = list(args) # args is probably a tuple and we need to mutate
for a in xrange(len(args) / 2):
col = args[a * 2]
def data_class_detection(self, data):
"""Determines the appropriate data encoding type to give satisfactory
resolution (http://code.google.com/apis/chart/#chart_data).
"""
assert(isinstance(data, list) or isinstance(data, tuple))
if not isinstance(self, (LineChart, BarChart, ScatterChart)):
# From the link above:
index = -1
for axis in self.axis:
available_axis.append(axis.axis_type)
if isinstance(axis, RangeAxis):
range_axis.append(repr(axis))
if isinstance(axis, LabelAxis):
label_axis.append(repr(axis))
src/k/a/kamaelia-HEAD/trunk/Code/Python/Kamaelia/Examples/SoC2006/RJL/TorrentSeeder/torrentseeder.py kamaelia(Download)
while self.dataReady("control"):
msg = self.recv("control")
if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
self.send(producerFinished(self), "signal")
return
src/r/e/reporter-lib-HEAD/packages/pyparsing/examples/pythonGrammarParser.py reporter-lib(Download)
def __str__(self):
return "%s(%s)" % (self.label,
" ".join([isinstance(c,basestring) and c or str(c) for c in self.contents]) )
class OrList(SemanticGroup):
label = "OR"
pass
def __init__(self,contents):
if len(contents) > 1:
self.rep = contents[1]
else:
self.rep = ""
if isinstance(contents,basestring):
self.contents = contents
src/b/a/badger-lib-HEAD/packages/pyparsing/examples/pythonGrammarParser.py badger-lib(Download)
def __str__(self):
return "%s(%s)" % (self.label,
" ".join([isinstance(c,basestring) and c or str(c) for c in self.contents]) )
class OrList(SemanticGroup):
label = "OR"
pass
def __init__(self,contents):
if len(contents) > 1:
self.rep = contents[1]
else:
self.rep = ""
if isinstance(contents,basestring):
self.contents = contents
src/g/d/gdata-python-HEAD/samples/spreadsheets/spreadsheetExample.py gdata-python(Download)
def _CellsUpdateAction(self, row, col, inputValue):
entry = self.gd_client.UpdateCell(row=row, col=col, inputValue=inputValue,
key=self.curr_key, wksht_id=self.curr_wksht_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsCell):
print 'Updated!'
def _ListGetAction(self):
def _ListInsertAction(self, row_data):
entry = self.gd_client.InsertRow(self._StringToDictionary(row_data),
self.curr_key, self.curr_wksht_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
print 'Inserted!'
def _ListUpdateAction(self, index, row_data):
self.list_feed = self.gd_client.GetListFeed(self.curr_key, self.curr_wksht_id)
entry = self.gd_client.UpdateRow(
self.list_feed.entry[string.atoi(index)],
self._StringToDictionary(row_data))
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
def _PrintFeed(self, feed):
for i, entry in enumerate(feed.entry):
if isinstance(feed, gdata.spreadsheet.SpreadsheetsCellsFeed):
print '%s %s\n' % (entry.title.text, entry.content.text)
elif isinstance(feed, gdata.spreadsheet.SpreadsheetsListFeed):
#print '%s %s %s\n' % (i, entry.title.text.encode('UTF-8'), entry.content.text.encode('UTF-8'))
print '%s %s %s\n' % (i, entry.title.text, entry.content.text)
src/b/o/boodler-HEAD/core/branch/rel_2_0_2/src/boodle/sample.py boodler(Download)
"""
# If the argument is a Sample in the first place, return it.
if (isinstance(sname, Sample)):
return sname
# If we've seen it before, it's in the cache.
samp = cache.get(sname)
if (not (samp is None)):
return samp
suffix = None
if (isinstance(sname, boopak.pinfo.MemFile)):
if (isinstance(sname, boopak.pinfo.MemFile)):
filename = sname
suffix = sname.suffix
elif (isinstance(sname, boopak.pinfo.File)):
filename = sname
if (not os.access(sname.pathname, os.R_OK)):
raise SampleError('file not readable: ' + sname.pathname)
def raw_load(self, filename, csamp):
if (isinstance(filename, boopak.pinfo.File)):
afl = filename.open(True)
else:
afl = open(filename, 'rb')
try:
fl = aifc.open(afl)
def raw_load(self, filename, csamp):
if (isinstance(filename, boopak.pinfo.File)):
afl = filename.open(True)
else:
afl = open(filename, 'rb')
try:
fl = wave.open(afl)
def raw_load(self, filename, csamp):
if (isinstance(filename, boopak.pinfo.File)):
afl = filename.open(True)
else:
afl = open(filename, 'rb')
try:
fl = sunau.open(afl, 'r')
def load(self, filename, suffix):
dirname = None
modname = None
if (isinstance(filename, boopak.pinfo.File)):
afl = filename.open(True)
modname = filename.package.encoded_name
Previous 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 Next