##// END OF EJS Templates
bundle2.bundlepart: make mandatory part flag explicit in API...
Eric Sumner -
r23590:4440c7cc default
parent child Browse files
Show More
@@ -350,7 +350,8 b' def _processpart(op, part):'
350 350 if output is not None:
351 351 output = op.ui.popbuffer()
352 352 if output:
353 outpart = op.reply.newpart('b2x:output', data=output)
353 outpart = op.reply.newpart('b2x:output', data=output,
354 mandatory=False)
354 355 outpart.addparam('in-reply-to', str(part.id), mandatory=False)
355 356 finally:
356 357 # consume the part content to not corrupt the stream.
@@ -588,7 +589,7 b' class bundlepart(object):'
588 589 """
589 590
590 591 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
591 data=''):
592 data='', mandatory=True):
592 593 self.id = None
593 594 self.type = parttype
594 595 self._data = data
@@ -605,6 +606,7 b' class bundlepart(object):'
605 606 # - False: currently generated,
606 607 # - True: generation done.
607 608 self._generated = None
609 self.mandatory = mandatory
608 610
609 611 # methods used to defines the part content
610 612 def __setdata(self, data):
@@ -642,9 +644,13 b' class bundlepart(object):'
642 644 raise RuntimeError('part can only be consumed once')
643 645 self._generated = False
644 646 #### header
647 if self.mandatory:
648 parttype = self.type.upper()
649 else:
650 parttype = self.type.lower()
645 651 ## parttype
646 header = [_pack(_fparttypesize, len(self.type)),
647 self.type, _pack(_fpartid, self.id),
652 header = [_pack(_fparttypesize, len(parttype)),
653 parttype, _pack(_fpartid, self.id),
648 654 ]
649 655 ## parameters
650 656 # count
@@ -681,7 +687,8 b' class bundlepart(object):'
681 687 # backup exception data for later
682 688 exc_info = sys.exc_info()
683 689 msg = 'unexpected error: %s' % exc
684 interpart = bundlepart('b2x:error:abort', [('message', msg)])
690 interpart = bundlepart('b2x:error:abort', [('message', msg)],
691 mandatory=False)
685 692 interpart.id = 0
686 693 yield _pack(_fpayloadsize, -1)
687 694 for chunk in interpart.getchunks():
@@ -930,7 +937,7 b' def handlechangegroup(op, inpart):'
930 937 if op.reply is not None:
931 938 # This is definitely not the final form of this
932 939 # return. But one need to start somewhere.
933 part = op.reply.newpart('b2x:reply:changegroup')
940 part = op.reply.newpart('b2x:reply:changegroup', mandatory=False)
934 941 part.addparam('in-reply-to', str(inpart.id), mandatory=False)
935 942 part.addparam('return', '%i' % ret, mandatory=False)
936 943 assert not inpart.read()
@@ -55,7 +55,8 b' Create an extension to test bundle2 API'
55 55 > op.ui.write('received ping request (id %i)\n' % part.id)
56 56 > if op.reply is not None and 'ping-pong' in op.reply.capabilities:
57 57 > op.ui.write_err('replying to ping request (id %i)\n' % part.id)
58 > op.reply.newpart('test:pong', [('in-reply-to', str(part.id))])
58 > op.reply.newpart('test:pong', [('in-reply-to', str(part.id))],
59 > mandatory=False)
59 60 >
60 61 > @bundle2.parthandler('test:debugreply')
61 62 > def debugreply(op, part):
@@ -108,32 +109,34 b' Create an extension to test bundle2 API'
108 109 > headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)]
109 110 > outgoing = discovery.outgoing(repo.changelog, headcommon, headmissing)
110 111 > cg = changegroup.getlocalchangegroup(repo, 'test:bundle2', outgoing, None)
111 > bundler.newpart('b2x:changegroup', data=cg.getchunks())
112 > bundler.newpart('b2x:changegroup', data=cg.getchunks(),
113 > mandatory=False)
112 114 >
113 115 > if opts['parts']:
114 > bundler.newpart('test:empty')
116 > bundler.newpart('test:empty', mandatory=False)
115 117 > # add a second one to make sure we handle multiple parts
116 > bundler.newpart('test:empty')
117 > bundler.newpart('test:song', data=ELEPHANTSSONG)
118 > bundler.newpart('test:debugreply')
118 > bundler.newpart('test:empty', mandatory=False)
119 > bundler.newpart('test:song', data=ELEPHANTSSONG, mandatory=False)
120 > bundler.newpart('test:debugreply', mandatory=False)
119 121 > mathpart = bundler.newpart('test:math')
120 122 > mathpart.addparam('pi', '3.14')
121 123 > mathpart.addparam('e', '2.72')
122 124 > mathpart.addparam('cooking', 'raw', mandatory=False)
123 125 > mathpart.data = '42'
126 > mathpart.mandatory = False
124 127 > # advisory known part with unknown mandatory param
125 > bundler.newpart('test:song', [('randomparam','')])
128 > bundler.newpart('test:song', [('randomparam','')], mandatory=False)
126 129 > if opts['unknown']:
127 130 > bundler.newpart('test:UNKNOWN', data='some random content')
128 131 > if opts['unknownparams']:
129 132 > bundler.newpart('test:SONG', [('randomparams', '')])
130 133 > if opts['parts']:
131 > bundler.newpart('test:ping')
134 > bundler.newpart('test:ping', mandatory=False)
132 135 > if opts['genraise']:
133 136 > def genraise():
134 137 > yield 'first line\n'
135 138 > raise RuntimeError('Someone set up us the bomb!')
136 > bundler.newpart('b2x:output', data=genraise())
139 > bundler.newpart('b2x:output', data=genraise(), mandatory=False)
137 140 >
138 141 > if path is None:
139 142 > file = sys.stdout
General Comments 0
You need to be logged in to leave comments. Login now