当前位置: 首页>>代码示例>>Python>>正文


Python types.DictType方法代码示例

本文整理汇总了Python中types.DictType方法的典型用法代码示例。如果您正苦于以下问题:Python types.DictType方法的具体用法?Python types.DictType怎么用?Python types.DictType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types的用法示例。


在下文中一共展示了types.DictType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def __init__(self, initfile):
        self.__initfile = initfile
        self.__colordb = None
        self.__optiondb = {}
        self.__views = []
        self.__red = 0
        self.__green = 0
        self.__blue = 0
        self.__canceled = 0
        # read the initialization file
        fp = None
        if initfile:
            try:
                try:
                    fp = open(initfile)
                    self.__optiondb = marshal.load(fp)
                    if not isinstance(self.__optiondb, DictType):
                        print >> sys.stderr, \
                              'Problem reading options from file:', initfile
                        self.__optiondb = {}
                except (IOError, EOFError, ValueError):
                    pass
            finally:
                if fp:
                    fp.close() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:27,代码来源:Switchboard.py

示例2: validBarterCastMsg

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def validBarterCastMsg(self, bartercast_data):
        if not type(bartercast_data) == DictType:
            raise RuntimeError, 'bartercast: received data is not a dictionary'
            return False
        if not bartercast_data.has_key('data'):
            raise RuntimeError, "bartercast: 'data' key doesn't exist"
            return False
        if not type(bartercast_data['data']) == DictType:
            raise RuntimeError, "bartercast: 'data' value is not dictionary"
            return False
        for permid in bartercast_data['data'].keys():
            if not bartercast_data['data'][permid].has_key('u') or not bartercast_data['data'][permid].has_key('d'):
                raise RuntimeError, "bartercast: datafield doesn't contain 'u' or 'd' keys"
                return False

        return True 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:18,代码来源:bartercast.py

示例3: check_ut_pex

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def check_ut_pex(d):
    if type(d) != DictType:
        raise ValueError('ut_pex: not a dict')
    same_apeers = []
    apeers = check_ut_pex_peerlist(d, 'added')
    dpeers = check_ut_pex_peerlist(d, 'dropped')
    if 'added.f' in d:
        addedf = d['added.f']
        if type(addedf) != StringType:
            raise ValueError('ut_pex: added.f: not string')
        if len(addedf) != len(apeers) and not len(addedf) == 0:
            raise ValueError('ut_pex: added.f: more flags than peers')
        addedf = map(ord, addedf)
        for i in range(min(len(apeers), len(addedf)) - 1, -1, -1):
            if addedf[i] & 4:
                same_apeers.append(apeers.pop(i))
                addedf.pop(i)

    if DEBUG:
        print >> sys.stderr, 'ut_pex: Got', apeers
    return (same_apeers, apeers, dpeers) 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:23,代码来源:ut_pex.py

示例4: _CheckSequence

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def _CheckSequence(self, newseq, oldseq, checklen=True):
        """ Scan sequence comparing new and old values of individual items
            return True when the first difference is found.
            Compare sequence lengths if checklen is True. It is False on first 
            call because self.__dict__ has _snapshot as an extra entry 
        """
        if checklen and len(newseq) <> len(oldseq):
            return True
        if type(newseq) is types.DictType:
            for key in newseq:
                if key == '_snapshot':
                    continue
                if key not in oldseq:
                    return True
                if self._CheckItem(newseq[key], oldseq[key]):
                    return True
        else:
            for k in range(len(newseq)):
                if self._CheckItem(newseq[k], oldseq[k]):
                    return True
        return 0 
开发者ID:ActiveState,项目名称:code,代码行数:23,代码来源:recipe-302742.py

示例5: append

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def append(self, dict_obj):
        """
            Appended in list object a dictionary that represents
            the body of the message that will be sent to queue.

            :param dict_obj: Dict object

        """

        try:

            if not isinstance(dict_obj, types.DictType):
                raise ValueError(
                    u'QueueManagerError - The type must be a instance of Dict')

            self._msgs.append(dict_obj)
            self.log.debug('dict_obj:%s', dict_obj)

        except Exception, e:
            self.log.error(
                u'QueueManagerError - Error on appending objects to queue.')
            self.log.error(e)
            raise Exception(
                'QueueManagerError - Error on appending objects to queue.') 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:26,代码来源:queue_manager.py

示例6: _get_table_type

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def _get_table_type(self, data):
        # 自动推断应该使用的table类型
        if self._table_type is not None:
            return self._table_type

        # 空列表
        if data is None or len(data) == 0:
            return ListTable

        # 默认取第一行进行推断
        row = data[0]
        if isinstance(row, SequenceCollectionType):
            return ListTable
        elif isinstance(row, types.DictType):
            return DictTable
        else:
            return ObjectTable 
开发者ID:chihongze,项目名称:girlfriend,代码行数:19,代码来源:table.py

示例7: __init__

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def __init__(self, msg):
        """
            :param msg 可以是一个字符串,也可以是一个key为locale的字典
        """
        if isinstance(msg, types.DictType):
            country_code, _ = locale.getlocale(locale.LC_ALL)
            msg = msg[country_code]

        if isinstance(msg, unicode):
            super(GirlFriendException, self).__init__(msg.encode("utf-8"))
            self.msg = msg
        elif isinstance(msg, str):
            super(GirlFriendException, self).__init__(msg)
            self.msg = msg.decode("utf-8")
        else:
            raise TypeError 
开发者ID:chihongze,项目名称:girlfriend,代码行数:18,代码来源:exception.py

示例8: table_output

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def table_output(data):
    '''Get a table representation of a dictionary.'''
    if type(data) == DictType:
        data = data.items()
    headings = [ item[0] for item in data ]
    rows = [ item[1] for item in data ]
    columns = zip(*rows)
    if len(columns):
        widths = [ max([ len(str(y)) for y in row ]) for row in rows ]
    else:
        widths = [ 0 for c in headings ]
    for c, heading in enumerate(headings):
        widths[c] = max(widths[c], len(heading))
    column_count = range(len(rows))
    table = [ ' '.join([ headings[c].ljust(widths[c]) for c in column_count ]) ]
    table.append(' '.join([ '=' * widths[c] for c in column_count ]))
    for column in columns:
        table.append(' '.join([ str(column[c]).ljust(widths[c]) for c in column_count ]))
    return '\n'.join(table) 
开发者ID:chriso,项目名称:timeseries,代码行数:21,代码来源:utilities.py

示例9: unpack

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def unpack(format, data, object=None):
	if object is None:
		object = {}
	formatstring, names, fixes = getformat(format)
	if type(object) is types.DictType:
		dict = object
	else:
		dict = object.__dict__
	elements = struct.unpack(formatstring, data)
	for i in range(len(names)):
		name = names[i]
		value = elements[i]
		if fixes.has_key(name):
			# fixed point conversion
			value = value / fixes[name]
		dict[name] = value
	return object 
开发者ID:gltn,项目名称:stdm,代码行数:19,代码来源:sstruct.py

示例10: restore

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def restore(self):
        global c
        c = {}
        self.cexecuted = {}
        if not os.path.exists(self.cache):
            return
        try:
            cache = open(self.cache, 'rb')
            import marshal
            cexecuted = marshal.load(cache)
            cache.close()
            if isinstance(cexecuted, types.DictType):
                self.cexecuted = cexecuted
        except:
            pass

    # canonical_filename(filename).  Return a canonical filename for the
    # file (that is, an absolute path with no redundant components and
    # normalized case).  See [GDR 2001-12-04b, 3.3]. 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:coverage.py

示例11: success

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def success(self, result):
        assert isinstance(result, types.DictType)
        self.status = OUTPUT_STATUS.SUCCESS
        self.result = result 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:6,代码来源:poc.py

示例12: _check_callback

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def _check_callback(self):
        if self.action == "callback":
            if not hasattr(self.callback, '__call__'):
                raise OptionError(
                    "callback not callable: %r" % self.callback, self)
            if (self.callback_args is not None and
                type(self.callback_args) is not types.TupleType):
                raise OptionError(
                    "callback_args, if supplied, must be a tuple: not %r"
                    % self.callback_args, self)
            if (self.callback_kwargs is not None and
                type(self.callback_kwargs) is not types.DictType):
                raise OptionError(
                    "callback_kwargs, if supplied, must be a dict: not %r"
                    % self.callback_kwargs, self)
        else:
            if self.callback is not None:
                raise OptionError(
                    "callback supplied (%r) for non-callback option"
                    % self.callback, self)
            if self.callback_args is not None:
                raise OptionError(
                    "callback_args supplied for non-callback option", self)
            if self.callback_kwargs is not None:
                raise OptionError(
                    "callback_kwargs supplied for non-callback option", self) 
开发者ID:glmcdona,项目名称:meddle,代码行数:28,代码来源:optparse.py

示例13: __cmp__

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def __cmp__(self, other):
        if isinstance(other, Values):
            return cmp(self.__dict__, other.__dict__)
        elif isinstance(other, types.DictType):
            return cmp(self.__dict__, other)
        else:
            return -1 
开发者ID:glmcdona,项目名称:meddle,代码行数:9,代码来源:optparse.py

示例14: schedule

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def schedule(scheduler, runbook, target, config, dbc, logger):
    ''' Setup schedule for new runbooks and targets '''
    # Default schedule (every minute)
    task_schedule = {
        'second' : 0,
        'minute' : '*',
        'hour' : '*',
        'day' : '*',
        'month' : '*',
        'day_of_week' : '*'
    }
    # If schedule is present override default
    if 'schedule' in target['runbooks'][runbook].keys():
        if type(target['runbooks'][runbook]['schedule']) == types.DictType:
            for key in target['runbooks'][runbook]['schedule'].keys():
                task_schedule[key] = target['runbooks'][runbook]['schedule'][key]
        elif type(target['runbooks'][runbook]['schedule']) == types.StringType:
            breakdown = target['runbooks'][runbook]['schedule'].split(" ")
            task_schedule = {
                'second' : 0,
                'minute' : breakdown[0],
                'hour' : breakdown[1],
                'day' : breakdown[2],
                'month' :  breakdown[3],
                'day_of_week' : breakdown[4]
            }
    cron = CronTrigger(
        second=task_schedule['second'],
        minute=task_schedule['minute'],
        hour=task_schedule['hour'],
        day=task_schedule['day'],
        month=task_schedule['month'],
        day_of_week=task_schedule['day_of_week'],
    )
    return scheduler.add_job(
        monitor,
        trigger=cron,
        args=[runbook, target, config, dbc, logger]
    ) 
开发者ID:madflojo,项目名称:automatron,代码行数:41,代码来源:monitoring.py

示例15: init_info

# 需要导入模块: import types [as 别名]
# 或者: from types import DictType [as 别名]
def init_info(self):
        scxx_converter.init_info(self)
        self.type_name = 'dict'
        self.check_func = 'PyDict_Check'
        self.c_type = 'py::dict'
        self.return_type = 'py::dict'
        self.to_c_return = 'py::dict(py_obj)'
        self.matching_types = [types.DictType]
        # ref counting handled by py::dict
        self.use_ref_count = 0

#----------------------------------------------------------------------------
# Instance Converter
#---------------------------------------------------------------------------- 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:c_spec.py


注:本文中的types.DictType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。