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


Python types.DictionaryType方法代码示例

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


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

示例1: __init__

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def __init__(self, **kwargs):
        """
        Ctypes.Structure with integrated default values.
        https://stackoverflow.com/questions/7946519/default-values-in-a-ctypes-structure/25892189#25892189

        :param kwargs: values different to defaults
        :type kwargs: dict
        """

        # sanity checks
        defaults = type(self)._defaults_
        assert type(defaults) is types.DictionaryType

        # use defaults, but override with keyword arguments, if any
        values = defaults.copy()
        for (key, val) in kwargs.items():
            values[key] = val

        # appropriately initialize ctypes.Structure
        #super().__init__(**values)                     # Python 3 syntax
        return Structure.__init__(self, **values)       # Python 2 syntax

    # http://stackoverflow.com/questions/1825715/how-to-pack-and-unpack-using-ctypes-structure-str/1827666#1827666
    # https://wiki.python.org/moin/ctypes 
开发者ID:daq-tools,项目名称:kotori,代码行数:26,代码来源:backend_ctypes.py

示例2: process_message

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def process_message(self, topic, payload, *args):

        log.debug('Bus receive: topic={topic}, payload={payload}', topic=topic, payload=payload)

        # TODO: filter by realm/topic

        # decode message
        if type(payload) is types.DictionaryType:
            message = payload.copy()
        elif type(payload) is types.ListType:
            message = OrderedDict(payload)
        else:
            raise TypeError('Unable to handle data type "{}" from bus'.format(type(payload)))

        # compute storage location from topic and message
        storage_location = self.storage_location(message)
        log.debug('Storage location: {storage_location}', storage_location=dict(storage_location))

        # store data
        self.store_message(storage_location, message) 
开发者ID:daq-tools,项目名称:kotori,代码行数:22,代码来源:influx.py

示例3: _dump

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def _dump(obj):
    if _is_primitive_types(obj): return simplejson.dumps(obj, ensure_ascii=True)
    
    ret = {}
    items = obj.iteritems() if isinstance(obj, types.DictionaryType) else obj.__dict__.iteritems()
    #items = inspect.getmembers(obj)
    for key, val in items:
        if key.startswith('_'): continue
        
        if _is_unsupported_type(obj):
            raise NoneSupportedTypeError('cannot dump %s, type:%s, object dict: %s' % (val, type(val), obj.__dict__))
        
        if _is_primitive_types(val):
            ret[key] = val
        elif isinstance(val, types.DictType):
            ret[key] = val
        elif isinstance(val, types.ListType):
            nlst = _dump_list(val)
            ret[key] = nlst
        elif isinstance(val, types.NoneType):
            pass
        else:
            nmap = _dump(val)
            ret[key] = nmap
    return ret 
开发者ID:zstackio,项目名称:zstack-utility,代码行数:27,代码来源:jsonobject.py

示例4: _get_skip_key

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def _get_skip_key(self, *args):
        key_parts = []
        for arg in args:
            if isinstance(arg, types.StringTypes):
                key_parts.append(arg)
            elif isinstance(arg, types.DictionaryType):
                key_parts.append(','.join(arg.keys()))
        skip_key = '-'.join(key_parts)
        return skip_key 
开发者ID:daq-tools,项目名称:kotori,代码行数:11,代码来源:common.py

示例5: flatten

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def flatten(l):
    """
    Munge InfluxDB results.

    See also: https://stackoverflow.com/questions/21461140/flatten-an-irregular-list-of-lists-in-python-respecting-pandas-dataframes
    """
    import pandas
    for el in l:
        if isinstance(el, collections.Iterable) and not isinstance(el, (basestring, pandas.DataFrame, types.DictionaryType)):
            for sub in flatten(el):
                yield sub
        else:
            yield el 
开发者ID:daq-tools,项目名称:kotori,代码行数:15,代码来源:influx.py

示例6: unique_sequence

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def unique_sequence(seq):
    # https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order/480227#480227
    seen = set()
    seen_add = seen.add
    unhashable_types = (types.ListType, types.DictionaryType)
    return [x for x in seq if type(x) in unhashable_types or not (x in seen or seen_add(x))] 
开发者ID:ip-tools,项目名称:patzilla,代码行数:8,代码来源:container.py

示例7: normalize_patent

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def normalize_patent(number, as_dict=False, as_string=False, fix_kindcode=False, for_ops=True, provider=None):

    if provider is None and for_ops is True:
        provider = 'ops'

    # 1. handle patent dicts or convert (split) from string
    if isinstance(number, types.DictionaryType):
        patent = number
    else:
        patent = split_patent_number(number)

    # 2.a. normalize patent dict
    patent_normalized = patch_patent(patent, provider=provider)

    # 2.b. apply fixes
    if fix_kindcode:
        fix_patent_kindcode_ops(patent_normalized)

    # 3. result handling

    # 3.a) default mechanism: return what we've got
    if isinstance(number, types.DictionaryType):
        result = patent_normalized
    else:
        result = join_patent(patent_normalized)

    # 3.b) extended mechanism: return what we are requested for
    if as_dict:
        result = patent_normalized
    elif as_string:
        result = join_patent(patent_normalized)

    return result 
开发者ID:ip-tools,项目名称:patzilla,代码行数:35,代码来源:normalize.py

示例8: decode_patent_number

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def decode_patent_number(patent):
    if isinstance(patent, types.StringTypes):
        decoded = split_patent_number(patent)
    elif isinstance(patent, types.DictionaryType):
        decoded = patent
    else:
        raise TypeError(u'Document number "{patent}" of type "{type}" could not be decoded'.format(patent=patent, type=type(patent)))
    return decoded 
开发者ID:ip-tools,项目名称:patzilla,代码行数:10,代码来源:common.py

示例9: write_numberlist_sheets

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def write_numberlist_sheets(self):
        sheets = OrderedDict()
        sheets['rated']     = self.data.get('collections', {}).get('rated')
        sheets['dismissed'] = self.data.get('collections', {}).get('dismissed')
        sheets['seen']      = self.data.get('collections', {}).get('seen')
        for sheet_name, entries in sheets.iteritems():

            #print 'entries:'; pprint(entries)

            if entries:
                first = entries[0]
            else:
                first = {}

            # Create pandas DataFrame
            if type(first) in types.StringTypes:
                df = pandas.DataFrame(entries, columns=['PN'])

            elif isinstance(first, (types.DictionaryType, Bunch)):
                df = pandas.DataFrame(entries, columns=['number', 'score', 'timestamp', 'url'])
                df.rename(columns={'number': 'document', 'url': 'display'}, inplace=True)

            # Export DataFrame to Excel
            df.to_excel(self.writer, sheet_name=sheet_name, index=False)

            # Set column widths
            wks = self.worksheet_set_column_widths(sheet_name, 25, 15, 30, 25, cell_format=self.format_wrap_top)
            wks.set_landscape()
            #wks.set_column('C:C', width=19, cell_format=self.format_small_font)
            self.set_header_footer(wks) 
开发者ID:ip-tools,项目名称:patzilla,代码行数:32,代码来源:export.py

示例10: getAlbumJson

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def getAlbumJson(self, album_id, checkMasterAlbum=False):
        json_obj = self.fetch('album', '%s' % album_id)
        #if isinstance(json_obj, DictionaryType):
        #    json_obj.update({'_cached': True, '_mqa': False if not checkMasterAlbum else self.isMasterAlbum(album_id)})
        return json_obj 
开发者ID:arnesongit,项目名称:plugin.audio.tidal2,代码行数:7,代码来源:metacache.py

示例11: unpack_item

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def unpack_item(item):
	tp = type(item.value)
	if tp == types.DictionaryType:
		newitem = {}
		for key, value in item.value.items():
			newitem[key] = unpack_item(value)
	elif tp == types.ListType:
		newitem = [None] * len(item.value)
		for i in range(len(item.value)):
			newitem[i] = unpack_item(item.value[i])
		if item.type == 'proceduretype':
			newitem = tuple(newitem)
	else:
		newitem = item.value
	return newitem 
开发者ID:gltn,项目名称:stdm,代码行数:17,代码来源:psLib.py

示例12: _validate_response

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def _validate_response(self, response):
        """
        Validate the response that came back from the API, return True if it's good, False if bad

        :param response: API response, Dictionary expected
        :return: True if response if valid, False if not
        """
        # Check for unexpected response - all should be JSON dicts that have
        # already been deserialised
        if not isinstance(response, types.DictionaryType):
            self.message(
                "\t\t[!] ERROR - Unexpected value returned from the API: '%s'" %
                (response))
            return False

        # Check for valid errors
        if "error" in response and "msg" in response:
            self.message(
                "\t\t[!] ERROR - %s (%s)" %
                (response["msg"], response["timestamp"]))
            return False

        # Is this a valid response message
        if "msg" in response:
            return True

        # Catch all...dictionary returned but does not contain expected keys?
        # Who know's what's going on here?!
        else:
            self.message(
                "\t\t[!] ERROR - Unexpected dictionary response returned from the API: '%s'" %
                (response))
            return False 
开发者ID:duo-labs,项目名称:EFIgy,代码行数:35,代码来源:EFIgyLite_cli.py

示例13: objgrep

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None):
    '''An insanely CPU-intensive process for finding stuff.
    '''
    if paths is None:
        paths = []
    if seen is None:
        seen = {}
    if eq(start, goal):
        paths.append(path)
    if id(start) in seen:
        if seen[id(start)] is start:
            return
    if maxDepth is not None:
        if maxDepth == 0:
            return
        maxDepth -= 1
    seen[id(start)] = start
    if isinstance(start, types.DictionaryType):
        for k, v in start.items():
            objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth)
            objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, (list, tuple, deque)):
        for idx in xrange(len(start)):
            objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.MethodType):
        objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth)
    elif hasattr(start, '__dict__'):
        for k, v in start.__dict__.items():
            objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth)
        if isinstance(start, types.InstanceType):
            objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, weakref.ReferenceType):
        objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth)
    elif (isinstance(start, types.StringTypes+
                    (types.IntType, types.FunctionType,
                     types.BuiltinMethodType, RegexType, types.FloatType,
                     types.NoneType, types.FileType)) or
          type(start).__name__ in ('wrapper_descriptor', 'method_descriptor',
                                   'member_descriptor', 'getset_descriptor')):
        pass
    elif showUnknowns:
        print 'unknown type', type(start), start
    return paths 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:47,代码来源:reflect.py

示例14: add_contact

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def add_contact(self, new_contact, insert_uri=None, auth_token=None,
                  billing_information=None, birthday=None, calendar_link=None, **kwargs):
    """Adds an new contact to Google Contacts.

    Args:
      new_contact: atom.Entry or subclass A new contact which is to be added to
                Google Contacts.
      insert_uri: the URL to post new contacts to the feed
      url_params: dict (optional) Additional URL parameters to be included
                  in the insertion request.
      escape_params: boolean (optional) If true, the url_parameters will be
                     escaped before they are included in the request.

    Returns:
      On successful insert,  an entry containing the contact created
      On failure, a RequestError is raised of the form:
        {'status': HTTP status code from server,
         'reason': HTTP reason from the server,
         'body': HTTP body of the server's response}
    """

    contact = gdata.contacts.data.ContactEntry()

    if billing_information is not None:
      if not isinstance(billing_information, gdata.contacts.data.BillingInformation):
        billing_information = gdata.contacts.data.BillingInformation(text=billing_information)

      contact.billing_information = billing_information

    if birthday is not None:
      if not isinstance(birthday, gdata.contacts.data.Birthday):
        birthday = gdata.contacts.data.Birthday(when=birthday)

      contact.birthday = birthday

    if calendar_link is not None:
      if type(calendar_link) is not ListType:
        calendar_link = [calendar_link]

      for link in calendar_link:
        if not isinstance(link, gdata.contacts.data.CalendarLink):
          if type(link) is not DictionaryType:
            raise TypeError("calendar_link Requires dictionary not %s" % type(link))

          link = gdata.contacts.data.CalendarLink(
                                                  rel=link.get("rel", None),
                                                  label=link.get("label", None),
                                                  primary=link.get("primary", None),
                                                  href=link.get("href", None),
                                                  )

        contact.calendar_link.append(link)

    insert_uri = insert_uri or self.GetFeedUri()
    return self.Post(contact, insert_uri,
                     auth_token=auth_token,  **kwargs) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:58,代码来源:client.py

示例15: objgrep

# 需要导入模块: import types [as 别名]
# 或者: from types import DictionaryType [as 别名]
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None):
    '''An insanely CPU-intensive process for finding stuff.
    '''
    if paths is None:
        paths = []
    if seen is None:
        seen = {}
    if eq(start, goal):
        paths.append(path)
    if seen.has_key(id(start)):
        if seen[id(start)] is start:
            return
    if maxDepth is not None:
        if maxDepth == 0:
            return
        maxDepth -= 1
    seen[id(start)] = start
    if isinstance(start, types.DictionaryType):
        r = []
        for k, v in start.items():
            objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth)
            objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.ListType) or isinstance(start, types.TupleType):
        for idx in xrange(len(start)):
            objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.MethodType):
        objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth)
    elif hasattr(start, '__dict__'):
        for k, v in start.__dict__.items():
            objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth)
        if isinstance(start, types.InstanceType):
            objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, weakref.ReferenceType):
        objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth)
    elif (isinstance(start, types.StringTypes+
                    (types.IntType, types.FunctionType,
                     types.BuiltinMethodType, RegexType, types.FloatType,
                     types.NoneType, types.FileType)) or
          type(start).__name__ in ('wrapper_descriptor', 'method_descriptor',
                                   'member_descriptor', 'getset_descriptor')):
        pass
    elif showUnknowns:
        print 'unknown type', type(start), start
    return paths 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:48,代码来源:reflect.py


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