##// END OF EJS Templates
wireprotov2: implement commands as a generator of objects...
wireprotov2: implement commands as a generator of objects Previously, wire protocol version 2 inherited version 1's model of having separate types to represent the results of different wire protocol commands. As I implemented more powerful commands in future commits, I found I was using a common pattern of returning a special type to hold a generator. This meant the command function required a closure to do most of the work. That made logic flow more difficult to follow. I also noticed that many commands were effectively a sequence of objects to be CBOR encoded. I think it makes sense to define version 2 commands as generators. This way, commands can simply emit the data structures they wish to send to the client. This eliminates the need for a closure in command functions and removes encoding from the bodies of commands. As part of this commit, the handling of response objects has been moved into the serverreactor class. This puts the reactor in the driver's seat with regards to CBOR encoding and error handling. Having error handling in the function that emits frames is particularly important because exceptions in that function can lead to things getting in a bad state: I'm fairly certain that uncaught exceptions in the frame generator were causing deadlocks. I also introduced a dedicated error type for explicit error reporting in command handlers. This will be used in subsequent commits. There's still a bit of work to be done here, especially around formalizing the error handling "protocol." I've added yet another TODO to track this so we don't forget. Test output changed because we're using generators and no longer know we are at the end of the data until we hit the end of the generator. This means we can't emit the end-of-stream flag until we've exhausted the generator. Hence the introduction of 0-sized end-of-stream frames. Differential Revision: https://phab.mercurial-scm.org/D4472

File last commit:

r37961:32bc3815 default
r39595:07b58266 default
Show More
test-ui-color.py
40 lines | 1023 B | text/x-python | PythonLexer
Pulkit Goyal
tests: make test-ui-color use absolute_import
r28915 from __future__ import absolute_import, print_function
Simon Heimberg
cleanup: remove unused imports...
r19322 import os
Pulkit Goyal
tests: make test-ui-color use absolute_import
r28915 from mercurial import (
dispatch,
ui as uimod,
)
Augie Fackler
tests: port test-ui-color.py to Python 3...
r37944 from mercurial.utils import (
stringutil,
)
Brodie Rao
color: call correct superclass method in write_err...
r11732
# ensure errors aren't buffered
Pierre-Yves David
color: drop the 'colorui' class...
r31095 testui = uimod.ui()
Brodie Rao
color: call correct superclass method in write_err...
r11732 testui.pushbuffer()
Pulkit Goyal
py3: add b'' to test-ui-color.py...
r36354 testui.write((b'buffered\n'))
testui.warn((b'warning\n'))
testui.write_err(b'error\n')
Yuya Nishihara
stringutil: flip the default of pprint() to bprefix=False...
r37961 print(stringutil.pprint(testui.popbuffer(), bprefix=True).decode('ascii'))
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516
# test dispatch.dispatch with the same ui object
Pulkit Goyal
py3: make sure we open file in bytes mode...
r36355 hgrc = open(os.environ["HGRCPATH"], 'wb')
Pulkit Goyal
py3: add b'' to test-ui-color.py...
r36354 hgrc.write(b'[extensions]\n')
hgrc.write(b'color=\n')
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516 hgrc.close()
Yuya Nishihara
ui: factor out ui.load() to create a ui without loading configs (API)...
r30559 ui_ = uimod.ui.load()
Pulkit Goyal
py3: add b'' to test-ui-color.py...
r36354 ui_.setconfig(b'ui', b'formatted', b'True')
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516
Idan Kamara
ui: use I/O descriptors internally...
r14614 # we're not interested in the output, so write that to devnull
Pulkit Goyal
py3: make sure we open file in bytes mode...
r36355 ui_.fout = open(os.devnull, 'wb')
Idan Kamara
ui: use I/O descriptors internally...
r14614
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516 # call some arbitrary command just so we go through
# color's wrapped _runcommand twice.
def runcmd():
Pulkit Goyal
py3: add b'' to test-ui-color.py...
r36354 dispatch.dispatch(dispatch.request([b'version', b'-q'], ui_))
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516
runcmd()
Pierre-Yves David
color: drop the 'colorui' class...
r31095 print("colored? %s" % (ui_._colormode is not None))
Idan Kamara
color: check if ui is already a subclass of colorui before wrapping it...
r14516 runcmd()
Pierre-Yves David
color: drop the 'colorui' class...
r31095 print("colored? %s" % (ui_._colormode is not None))