summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterworldmap.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2017-10-09 16:28:35 -0400
committerNat Goodspeed <nat@lindenlab.com>2017-10-09 16:28:35 -0400
commitd9d6df313cbced45c9fd57212e51ac417fc896d6 (patch)
treeedf68961e120a23f668c63d64c24638fb2b19034 /indra/newview/llfloaterworldmap.cpp
parentaa62145e1f27b66050ac52719ff655962d7d9e71 (diff)
MAINT-7831: Allow LLManifest.prefix() to be a context manager.
LLManifest.prefix() dates back to before Python had a 'with' statement or the notion of a context manager. That's why every prefix() call requires a corresponding end_prefix() call. Existing usage is of the form: if self.prefix(...some args...): self.path(...) ... self.end_prefix() The use of an 'if' statement is solely to allow the coder to indent the statements between the self.prefix() call and the corresponding call to self.end_prefix() -- there is no intention to make that code conditional. self.prefix() unconditionally returned True to facilitate that usage. But now that we have the 'with' statement, this all feels a little silly. Make prefix() return an instance of a context-manager class so that it's reasonable to say instead: with self.prefix(...some args...): self.path(...) ... and have the Right Things happen simply by leaving the 'with' block. The only tricky part is code to preserve compatibility with old-style usage: * The context manager has a __nonzero__() method so that if it's tested in an 'if' statement, it can unconditionally return True. * On leaving the 'with' block, rather than simply popping the top of each prefix stack, the context manager restores its length to the same length it had before that prefix() call. This allows for (erroneous but hardly unlikely) usage of the form: with self.prefix(...some args...): self.path(...) ... self.end_prefix() Restoring the previous length makes the context manager insensitive to whether or not end_prefix() has popped the most recent prefix() entries.
Diffstat (limited to 'indra/newview/llfloaterworldmap.cpp')
0 files changed, 0 insertions, 0 deletions