本文整理汇总了Python中cyordereddict.OrderedDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.update方法的具体用法?Python OrderedDict.update怎么用?Python OrderedDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setstate__
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def __setstate__(self, state):
OLDEST_SUPPORTED_STATE = 1
version = state.pop(VERSION_LABEL)
if version < OLDEST_SUPPORTED_STATE:
raise BaseException("PerformancePeriod saved state is too old.")
processed_transactions = defaultdict(list)
processed_transactions.update(state.pop('processed_transactions'))
orders_by_id = OrderedDict()
orders_by_id.update(state.pop('orders_by_id'))
orders_by_modified = defaultdict(OrderedDict)
orders_by_modified.update(state.pop('orders_by_modified'))
positions = positiondict()
positions.update(state.pop('positions'))
_positions_store = zp.Positions()
_positions_store.update(state.pop('_positions_store'))
self.processed_transactions = processed_transactions
self.orders_by_id = orders_by_id
self.orders_by_modified = orders_by_modified
self.positions = positions
self._positions_store = _positions_store
self.__dict__.update(state)
self.initialize_position_calc_arrays()
示例2: __setstate__
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def __setstate__(self, state):
OLDEST_SUPPORTED_STATE = 1
version = state.pop(VERSION_LABEL)
if version < OLDEST_SUPPORTED_STATE:
raise BaseException("PerformancePeriod saved state is too old.")
processed_transactions = {}
processed_transactions.update(state.pop('processed_transactions'))
orders_by_id = OrderedDict()
orders_by_id.update(state.pop('orders_by_id'))
orders_by_modified = {}
orders_by_modified.update(state.pop('orders_by_modified'))
self.processed_transactions = processed_transactions
self.orders_by_id = orders_by_id
self.orders_by_modified = orders_by_modified
# pop positions to use for v1
positions = state.pop('positions', None)
self.__dict__.update(state)
if version == 1:
# version 1 had PositionTracker logic inside of Period
# we create the PositionTracker here.
# Note: that in V2 it is assumed that the position_tracker
# will be dependency injected and so is not reconstructed
assert positions is not None, "positions should exist in v1"
position_tracker = PositionTracker()
position_tracker.update_positions(positions)
self.position_tracker = position_tracker
示例3: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
update_test = OrderedDict()
update_test.update(od)
for label, dup in [
('od.copy()', od.copy()),
('copy.copy(od)', copy.copy(od)),
('copy.deepcopy(od)', copy.deepcopy(od)),
('pickle.loads(pickle.dumps(od, 0))',
pickle.loads(pickle.dumps(od, 0))),
('pickle.loads(pickle.dumps(od, 1))',
pickle.loads(pickle.dumps(od, 1))),
('pickle.loads(pickle.dumps(od, 2))',
pickle.loads(pickle.dumps(od, 2))),
('pickle.loads(pickle.dumps(od, 3))',
pickle.loads(pickle.dumps(od, 3))),
('pickle.loads(pickle.dumps(od, -1))',
pickle.loads(pickle.dumps(od, -1))),
('eval(repr(od))', eval(repr(od))),
('update_test', update_test),
('OrderedDict(od)', OrderedDict(od)),
]:
with self.subTest(label=label):
msg = "\ncopy: %s\nod: %s" % (dup, od)
self.assertIsNot(dup, od, msg)
self.assertEqual(dup, od)
示例4: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
def check(dup):
msg = "\ncopy: %s\nod: %s" % (dup, od)
self.assertIsNot(dup, od, msg)
self.assertEqual(dup, od)
check(od.copy())
check(copy.copy(od))
check(copy.deepcopy(od))
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
check(pickle.loads(pickle.dumps(od, proto)))
check(eval(repr(od)))
update_test = OrderedDict()
update_test.update(od)
check(update_test)
check(OrderedDict(od))
示例5: __setstate__
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def __setstate__(self, state):
OLDEST_SUPPORTED_STATE = 3
version = state.pop(VERSION_LABEL)
if version < OLDEST_SUPPORTED_STATE:
raise BaseException("PerformancePeriod saved state is too old.")
processed_transactions = {}
processed_transactions.update(state.pop('processed_transactions'))
orders_by_id = OrderedDict()
orders_by_id.update(state.pop('orders_by_id'))
orders_by_modified = {}
orders_by_modified.update(state.pop('orders_by_modified'))
self.processed_transactions = processed_transactions
self.orders_by_id = orders_by_id
self.orders_by_modified = orders_by_modified
self._execution_cash_flow_multipliers = {}
self.__dict__.update(state)
示例6: test_copying
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def test_copying(self):
# Check that ordered dicts are copyable, deepcopyable, picklable,
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
update_test = OrderedDict()
update_test.update(od)
for i, dup in enumerate([
od.copy(),
copy.copy(od),
copy.deepcopy(od),
pickle.loads(pickle.dumps(od, 0)),
pickle.loads(pickle.dumps(od, 1)),
pickle.loads(pickle.dumps(od, 2)),
pickle.loads(pickle.dumps(od, -1)),
eval(repr(od)),
update_test,
OrderedDict(od),
]):
self.assertTrue(dup is not od)
self.assertEqual(dup, od)
self.assertEqual(list(dup.items()), list(od.items()))
self.assertEqual(len(dup), len(od))
self.assertEqual(type(dup), type(od))
示例7: test_update
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def test_update(self):
with self.assertRaises(TypeError):
OrderedDict().update([('a', 1), ('b', 2)], None) # too many args
pairs = [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
od = OrderedDict()
od.update(dict(pairs))
self.assertEqual(sorted(od.items()), pairs) # dict input
od = OrderedDict()
od.update(**dict(pairs))
self.assertEqual(sorted(od.items()), pairs) # kwds input
od = OrderedDict()
od.update(pairs)
self.assertEqual(list(od.items()), pairs) # pairs input
od = OrderedDict()
od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
self.assertEqual(list(od.items()), pairs) # mixed input
# Issue 9137: Named argument called 'other' or 'self'
# shouldn't be treated specially.
od = OrderedDict()
od.update(self=23)
self.assertEqual(list(od.items()), [('self', 23)])
od = OrderedDict()
od.update(other={})
self.assertEqual(list(od.items()), [('other', {})])
od = OrderedDict()
od.update(red=5, blue=6, other=7, self=8)
self.assertEqual(sorted(list(od.items())),
[('blue', 6), ('other', 7), ('red', 5), ('self', 8)])
# Make sure that direct calls to update do not clear previous contents
# add that updates items are not moved to the end
d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
d.update([('e', 5), ('f', 6)], g=7, d=4)
self.assertEqual(list(d.items()),
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7)])
示例8: format_one_submission
# 需要导入模块: from cyordereddict import OrderedDict [as 别名]
# 或者: from cyordereddict.OrderedDict import update [as 别名]
def format_one_submission(self, submission, current_section):
# 'current_section' is the name of what will become sheets in xls.
# If you don't have repeat groups, there is only one section
# containing all the formatted data.
# If you have repeat groups, you will have one section per repeat
# group. Section are hierarchical, and can have a parent and one
# or more children. format_one_submission() is called recursivelly
# with each section to process them all.
# 'chunks' is a mapping of section names with associated formatted data
# for one submission. It's used to handle repeat groups.
# Without repeat groups, chunks has only one section mapping to a
# list of one row.
#
# However, if you have repeat groups, chunks will looks like this:
#
# {'first_section': [[A, B, C, index=i]],
# 'second_section': [
# [D, E, F, index=x, parent_index=i],
# [D, E, F, index=y, parent_index=i],
# [D, E, F, index=z, parent_index=i],
# 'third_section': [
# [G, H, parent_index=x],
# [G, H, parent_index=x],
# [G, H, parent_index=y],
# [G, H, parent_index=y],
# [G, H, parent_index=z],
# [G, H, parent_index=z],
# ]}
#
chunks = OrderedDict()
# Some local aliases to get better perfs
_section_name = current_section.name
_lang = self.lang
_empty_row = self._empty_row[_section_name]
_indexes = self._indexes
row = self._row_cache[_section_name]
_fields = tuple(current_section.fields.values())
# 'rows' will contain all the formatted entries for the current
# section. If you don't have repeat-group, there is only one section
# with a row of size one.
# But if you have repeat groups, then rows will contain one row for
# each entry the user submitted. Of course, for the first section,
# this will always contains only one row.
rows = chunks[_section_name] = []
# Deal with only one level of nesting of the submission, since
# this method is later called recursively for each repeat group.
# Each level correspond to one section, so eventually one sheet
# in an xls doc. Althougt the first level will have only one entries,
# when repeat groups are involved, deeper levels can have an
# arbitrary number of entries depending of the user input.
for entry in submission:
# Format one entry and add it to the rows for this section
# Create an empty canvas with column names and empty values
# This is done to handle mulitple form versions in parallel which
# may more or less columns than each others.
# We don't build a new dict everytime, instead, we reuse the
# previous one, but we reset it, to gain some perfs.
row.update(_empty_row)
for field in _fields:
# TODO: pass a context to fields so they can all format ?
if field.can_format:
try:
# get submission value for this field
val = entry[field.path]
# get a mapping of {"col_name": "val", ...}
cells = field.format(val, _lang)
except KeyError:
cells = field.empty_result
# fill in the canvas
row.update(cells)
# Link between the parent and its children in a sub-section.
# Indeed, with repeat groups, entries are nested. Since we flatten
# them out, we need a way to tell the end user which entries was
# previously part of a bigger entry. The index is like an auto-increment
# id that we generate on the fly on the parent, and add it to
# the children like a foreign key.
# TODO: remove that for HTML export
if '_index' in row:
row['_index'] = _indexes[_section_name]
if '_parent_table_name' in row:
row['_parent_table_name'] = current_section.parent.name
row['_parent_index'] = _indexes[row['_parent_table_name']]
rows.append(list(row.values()))
# Process all repeat groups of this level
#.........这里部分代码省略.........