本文整理汇总了Python中ordereddict.OrderedDict方法的典型用法代码示例。如果您正苦于以下问题:Python ordereddict.OrderedDict方法的具体用法?Python ordereddict.OrderedDict怎么用?Python ordereddict.OrderedDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ordereddict
的用法示例。
在下文中一共展示了ordereddict.OrderedDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_referenceSourceExistsNonWriteable
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def test_referenceSourceExistsNonWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
# Reference sources exists but cannot be written
# The reference repo is set nevertheless but not updated
mock_path.exists.side_effect = lambda x: True
mock_is_writeable.side_effect = lambda x: False
mock_os.path.join.side_effect = join
mock_getstatusoutput.side_effect = allow_directory_creation
mock_git_clone = MagicMock(return_value=None)
mock_git_fetch = MagicMock(return_value=None)
mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
referenceSources = "sw/MIRROR"
reference = abspath(referenceSources) + "/aliroot"
mock_os.makedirs.reset_mock()
mock_git_clone.reset_mock()
mock_git_fetch.reset_mock()
updateReferenceRepoSpec(referenceSources=referenceSources, p="AliRoot", spec=spec, fetch=True)
mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
self.assertEqual(mock_git_fetch.call_count, 0, "Expected no calls to git fetch (called %d times instead)" % mock_git_fetch.call_count)
self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count)
self.assertEqual(spec.get("reference"), reference)
self.assertEqual(True, call('Updating references.') in mock_debug.mock_calls)
示例2: test_referenceSourceExistsWriteable
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def test_referenceSourceExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
# Reference sources exists and can be written
# The reference repo is set nevertheless but not updated
mock_path.exists.side_effect = lambda x: True
mock_is_writeable.side_effect = lambda x: True
mock_os.path.join.side_effect = join
mock_getstatusoutput.side_effect = allow_directory_creation
mock_git_clone = MagicMock(return_value=None)
mock_git_fetch = MagicMock(return_value=None)
mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
referenceSources = "sw/MIRROR"
reference = abspath(referenceSources) + "/aliroot"
mock_os.makedirs.reset_mock()
mock_git_clone.reset_mock()
mock_git_fetch.reset_mock()
updateReferenceRepoSpec(referenceSources=referenceSources, p="AliRoot", spec=spec, fetch=True)
mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
self.assertEqual(mock_git_fetch.call_count, 1, "Expected one call to git fetch (called %d times instead)" % mock_git_fetch.call_count)
self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count)
self.assertEqual(spec.get("reference"), reference)
self.assertEqual(True, call('Updating references.') in mock_debug.mock_calls)
示例3: test_referenceBasedirExistsWriteable
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def test_referenceBasedirExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
"""
The referenceSources directory exists and it's writeable
Reference sources are already there
"""
mock_path.exists.side_effect = lambda x: True
mock_is_writeable.side_effect = lambda x: True
mock_os.path.join.side_effect = join
mock_getstatusoutput.side_effect = allow_directory_creation
mock_git_clone = MagicMock(return_value=None)
mock_git_fetch = MagicMock(return_value=None)
mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
referenceSources = "sw/MIRROR"
reference = abspath(referenceSources) + "/aliroot"
mock_os.makedirs.reset_mock()
mock_git_clone.reset_mock()
mock_git_fetch.reset_mock()
updateReferenceRepo(referenceSources=referenceSources, p="AliRoot", spec=spec)
mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
self.assertEqual(mock_git_fetch.call_count, 1, "Expected one call to git fetch (called %d times instead)" % mock_git_fetch.call_count)
示例4: test_referenceBasedirNotExistsWriteable
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def test_referenceBasedirNotExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
"""
The referenceSources directory exists and it's writeable
Reference sources are not already there
"""
mock_path.exists.side_effect = reference_sources_do_not_exists
mock_is_writeable.side_effect = lambda x: False # not writeable
mock_os.path.join.side_effect = join
mock_os.makedirs.side_effect = lambda x: True
mock_getstatusoutput.side_effect = allow_directory_creation
mock_git_clone = MagicMock(return_value=None)
mock_git_fetch = MagicMock(return_value=None)
mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
referenceSources = "sw/MIRROR"
reference = abspath(referenceSources) + "/aliroot"
mock_os.makedirs.reset_mock()
mock_git_clone.reset_mock()
mock_git_fetch.reset_mock()
updateReferenceRepo(referenceSources=referenceSources, p="AliRoot", spec=spec)
mock_path.exists.assert_called_with('%s/sw/MIRROR/aliroot' % getcwd())
mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count)
示例5: parseDefaults
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def parseDefaults(disable, defaultsGetter, log):
defaultsMeta, defaultsBody = defaultsGetter()
# Defaults are actually special packages. They can override metadata
# of any other package and they can disable other packages. For
# example they could decide to switch from ROOT 5 to ROOT 6 and they
# could disable alien for O2. For this reason we need to parse their
# metadata early and extract the override and disable data.
defaultsDisable = asList(defaultsMeta.get("disable", []))
for x in defaultsDisable:
log("Package %s has been disabled by current default." % x)
disable.extend(defaultsDisable)
if type(defaultsMeta.get("overrides", OrderedDict())) != OrderedDict:
return ("overrides should be a dictionary", None, None)
overrides, taps = OrderedDict(), {}
commonEnv = {"env": defaultsMeta["env"]} if "env" in defaultsMeta else {}
overrides["defaults-release"] = commonEnv
for k, v in defaultsMeta.get("overrides", {}).items():
f = k.split("@", 1)[0].lower()
if "@" in k:
taps[f] = "dist:"+k
overrides[f] = dict(**(v or {}))
return (None, overrides, taps)
示例6: startElement
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def startElement(self, full_name, attrs):
name = self._build_name(full_name)
attrs = self._attrs_to_dict(attrs)
if attrs and self.namespace_declarations:
attrs['xmlns'] = self.namespace_declarations
self.namespace_declarations = OrderedDict()
self.path.append((name, attrs or None))
if len(self.path) > self.item_depth:
self.stack.append((self.item, self.data))
if self.xml_attribs:
attr_entries = []
for key, value in attrs.items():
key = self.attr_prefix+self._build_name(key)
if self.postprocessor:
entry = self.postprocessor(self.path, key, value)
else:
entry = (key, value)
if entry:
attr_entries.append(entry)
attrs = self.dict_constructor(attr_entries)
else:
attrs = None
self.item = attrs or None
self.data = []
示例7: construct_mapping
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
msg = 'expected a mapping node, but found %s' % node.id
raise yaml.constructor.ConstructError(None,
None,
msg,
node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as err:
raise yaml.constructor.ConstructError(
'while constructing a mapping', node.start_mark,
'found unacceptable key (%s)' % err, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例8: __addItem
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def __addItem(self, entry):
dataDefinitionHeader = ESENT_DATA_DEFINITION_HEADER(entry['EntryData'])
catalogEntry = ESENT_CATALOG_DATA_DEFINITION_ENTRY(entry['EntryData'][len(dataDefinitionHeader):])
itemName = self.__parseItemName(entry)
if catalogEntry['Type'] == CATALOG_TYPE_TABLE:
self.__tables[itemName] = OrderedDict()
self.__tables[itemName]['TableEntry'] = entry
self.__tables[itemName]['Columns'] = OrderedDict()
self.__tables[itemName]['Indexes'] = OrderedDict()
self.__tables[itemName]['LongValues'] = OrderedDict()
self.__currentTable = itemName
elif catalogEntry['Type'] == CATALOG_TYPE_COLUMN:
self.__tables[self.__currentTable]['Columns'][itemName] = entry
self.__tables[self.__currentTable]['Columns'][itemName]['Header'] = dataDefinitionHeader
self.__tables[self.__currentTable]['Columns'][itemName]['Record'] = catalogEntry
elif catalogEntry['Type'] == CATALOG_TYPE_INDEX:
self.__tables[self.__currentTable]['Indexes'][itemName] = entry
elif catalogEntry['Type'] == CATALOG_TYPE_LONG_VALUE:
self.__addLongValue(entry)
else:
LOG.error('Unknown type 0x%x' % catalogEntry['Type'])
raise
示例9: describe
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def describe(self):
"""Describes all available objects
"""
url = self.base_url + "sobjects"
result = self._call_salesforce('GET', url)
if result.status_code != 200:
raise SalesforceGeneralError(url,
'describe',
result.status_code,
result.content)
json_result = result.json(object_pairs_hook=OrderedDict)
if len(json_result) == 0:
return None
else:
return json_result
# SObject Handler
示例10: restful
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def restful(self, path, params, method='GET'):
"""Allows you to make a direct REST call if you know the path
Arguments:
* path: The path of the request
Example: sobjects/User/ABC123/password'
* params: dict of parameters to pass to the path
* method: HTTP request method, default GET
"""
url = self.base_url + path
result = self._call_salesforce(method, url, params=params)
if result.status_code != 200:
raise SalesforceGeneralError(url,
path,
result.status_code,
result.content)
json_result = result.json(object_pairs_hook=OrderedDict)
if len(json_result) == 0:
return None
else:
return json_result
# Search Functions
示例11: query
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def query(self, query, **kwargs):
"""Return the result of a Salesforce SOQL query as a dict decoded from
the Salesforce response JSON payload.
Arguments:
* query -- the SOQL query to send to Salesforce, e.g.
`SELECT Id FROM Lead WHERE Email = "waldo@somewhere.com"`
"""
url = self.base_url + 'query/'
params = {'q': query}
# `requests` will correctly encode the query string passed as `params`
result = self._call_salesforce('GET', url, params=params, **kwargs)
if result.status_code != 200:
_exception_handler(result)
return result.json(object_pairs_hook=OrderedDict)
示例12: describe_layout
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def describe_layout(self, record_id, headers=None):
"""Returns the layout of the object
Returns the result of a GET to
`.../{object_name}/describe/layouts/<recordid>` as a dict decoded from
the JSON payload returned by Salesforce.
Arguments:
* record_id -- the Id of the SObject to get
* headers -- a dict with additional request headers.
"""
custom_url_part = 'describe/layouts/{record_id}'.format(
record_id=record_id
)
result = self._call_salesforce(
method='GET',
url=urljoin(self.base_url, custom_url_part),
headers=headers
)
return result.json(object_pairs_hook=OrderedDict)
示例13: get_by_custom_id
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def get_by_custom_id(self, custom_id_field, custom_id, headers=None):
"""Return an ``SFType`` by custom ID
Returns the result of a GET to
`.../{object_name}/{custom_id_field}/{custom_id}` as a dict decoded
from the JSON payload returned by Salesforce.
Arguments:
* custom_id_field -- the API name of a custom field that was defined
as an External ID
* custom_id - the External ID value of the SObject to get
* headers -- a dict with additional request headers.
"""
custom_url = urljoin(
self.base_url, '{custom_id_field}/{custom_id}'.format(
custom_id_field=custom_id_field, custom_id=custom_id
)
)
result = self._call_salesforce(
method='GET', url=custom_url, headers=headers
)
return result.json(object_pairs_hook=OrderedDict)
示例14: create
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def create(self, data, headers=None):
"""Creates a new SObject using a POST to `.../{object_name}/`.
Returns a dict decoded from the JSON payload returned by Salesforce.
Arguments:
* data -- a dict of the data to create the SObject from. It will be
JSON-encoded before being transmitted.
* headers -- a dict with additional request headers.
"""
result = self._call_salesforce(
method='POST', url=self.base_url,
data=json.dumps(data), headers=headers
)
return result.json(object_pairs_hook=OrderedDict)
示例15: deleted
# 需要导入模块: import ordereddict [as 别名]
# 或者: from ordereddict import OrderedDict [as 别名]
def deleted(self, start, end, headers=None):
# pylint: disable=line-too-long
"""Gets a list of deleted records
Use the SObject Get Deleted resource to get a list of deleted records
for the specified object.
.../deleted/?start=2013-05-05T00:00:00+00:00&end=2013-05-10T00:00:00+00:00
* start -- start datetime object
* end -- end datetime object
* headers -- a dict with additional request headers.
"""
url = urljoin(
self.base_url, 'deleted/?start={start}&end={end}'.format(
start=date_to_iso8601(start), end=date_to_iso8601(end)
)
)
result = self._call_salesforce(method='GET', url=url, headers=headers)
return result.json(object_pairs_hook=OrderedDict)