##// END OF EJS Templates
hgweb: always return iterable from @webcommand functions (API)...
Gregory Szorc -
r36896:67fb0dca default
parent child Browse files
Show More
@@ -88,7 +88,7 b' def generate_css(web, req, tmpl):'
88 '/* pygments_style = %s */\n\n' % pg_style,
88 '/* pygments_style = %s */\n\n' % pg_style,
89 fmter.get_style_defs(''),
89 fmter.get_style_defs(''),
90 ]))
90 ]))
91 return web.res
91 return web.res.sendresponse()
92
92
93 def extsetup():
93 def extsetup():
94 # monkeypatch in the new version
94 # monkeypatch in the new version
@@ -621,13 +621,7 b' def kwweb_skip(orig, web, req, tmpl):'
621 origmatch = kwt.match
621 origmatch = kwt.match
622 kwt.match = util.never
622 kwt.match = util.never
623 try:
623 try:
624 res = orig(web, req, tmpl)
624 for chunk in orig(web, req, tmpl):
625 if res is web.res:
626 res = res.sendresponse()
627 elif res is True:
628 return
629
630 for chunk in res:
631 yield chunk
625 yield chunk
632 finally:
626 finally:
633 if kwt:
627 if kwt:
@@ -14,7 +14,6 b' import os'
14 from .common import (
14 from .common import (
15 ErrorResponse,
15 ErrorResponse,
16 HTTP_BAD_REQUEST,
16 HTTP_BAD_REQUEST,
17 HTTP_OK,
18 cspvalues,
17 cspvalues,
19 permhooks,
18 permhooks,
20 statusmessage,
19 statusmessage,
@@ -405,15 +404,7 b' class hgweb(object):'
405 # override easily enough.
404 # override easily enough.
406 res.status = '200 Script output follows'
405 res.status = '200 Script output follows'
407 res.headers['Content-Type'] = ctype
406 res.headers['Content-Type'] = ctype
408 content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl)
407 return getattr(webcommands, cmd)(rctx, wsgireq, tmpl)
409
410 if content is res:
411 return res.sendresponse()
412 elif content is True:
413 return []
414 else:
415 wsgireq.respond(HTTP_OK, ctype)
416 return content
417
408
418 except (error.LookupError, error.RepoLookupError) as err:
409 except (error.LookupError, error.RepoLookupError) as err:
419 msg = pycompat.bytestr(err)
410 msg = pycompat.bytestr(err)
@@ -57,12 +57,9 b' class webcommand(object):'
57 The functions should populate the ``rctx.res`` object with details
57 The functions should populate the ``rctx.res`` object with details
58 about the HTTP response.
58 about the HTTP response.
59
59
60 The function can return the ``requestcontext.res`` instance to signal
60 The function returns a generator to be consumed by the WSGI application.
61 that it wants to use this object to generate the response. If an iterable
61 For most commands, this should be the result from
62 is returned, the ``wsgirequest`` instance will be used and the returned
62 ``web.res.sendresponse()``.
63 content will constitute the response body. ``True`` can be returned to
64 indicate that the function already sent output and the caller doesn't
65 need to do anything more to send the response.
66
63
67 Usage:
64 Usage:
68
65
@@ -135,7 +132,7 b' def rawfile(web, req, tmpl):'
135 .replace('\\', '\\\\').replace('"', '\\"'))
132 .replace('\\', '\\\\').replace('"', '\\"'))
136 web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
133 web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
137 web.res.setbodybytes(text)
134 web.res.setbodybytes(text)
138 return web.res
135 return web.res.sendresponse()
139
136
140 def _filerevision(web, req, tmpl, fctx):
137 def _filerevision(web, req, tmpl, fctx):
141 f = fctx.path()
138 f = fctx.path()
@@ -165,7 +162,7 b' def _filerevision(web, req, tmpl, fctx):'
165 ishead=int(ishead),
162 ishead=int(ishead),
166 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
163 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
167
164
168 return web.res
165 return web.res.sendresponse()
169
166
170 @webcommand('file')
167 @webcommand('file')
171 def file(web, req, tmpl):
168 def file(web, req, tmpl):
@@ -355,7 +352,7 b' def _search(web, req, tmpl):'
355 showforcekw=showforcekw,
352 showforcekw=showforcekw,
356 showunforcekw=showunforcekw))
353 showunforcekw=showunforcekw))
357
354
358 return web.res
355 return web.res.sendresponse()
359
356
360 @webcommand('changelog')
357 @webcommand('changelog')
361 def changelog(web, req, tmpl, shortlog=False):
358 def changelog(web, req, tmpl, shortlog=False):
@@ -455,7 +452,7 b' def changelog(web, req, tmpl, shortlog=F'
455 lessvars=lessvars,
452 lessvars=lessvars,
456 query=query))
453 query=query))
457
454
458 return web.res
455 return web.res.sendresponse()
459
456
460 @webcommand('shortlog')
457 @webcommand('shortlog')
461 def shortlog(web, req, tmpl):
458 def shortlog(web, req, tmpl):
@@ -490,7 +487,7 b' def changeset(web, req, tmpl):'
490 ctx = webutil.changectx(web.repo, req)
487 ctx = webutil.changectx(web.repo, req)
491 web.res.setbodygen(tmpl('changeset',
488 web.res.setbodygen(tmpl('changeset',
492 **webutil.changesetentry(web, req, tmpl, ctx)))
489 **webutil.changesetentry(web, req, tmpl, ctx)))
493 return web.res
490 return web.res.sendresponse()
494
491
495 rev = webcommand('rev')(changeset)
492 rev = webcommand('rev')(changeset)
496
493
@@ -602,7 +599,7 b' def manifest(web, req, tmpl):'
602 archives=web.archivelist(hex(node)),
599 archives=web.archivelist(hex(node)),
603 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
600 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
604
601
605 return web.res
602 return web.res.sendresponse()
606
603
607 @webcommand('tags')
604 @webcommand('tags')
608 def tags(web, req, tmpl):
605 def tags(web, req, tmpl):
@@ -638,7 +635,7 b' def tags(web, req, tmpl):'
638 entriesnotip=lambda **x: entries(True, False, **x),
635 entriesnotip=lambda **x: entries(True, False, **x),
639 latestentry=lambda **x: entries(True, True, **x)))
636 latestentry=lambda **x: entries(True, True, **x)))
640
637
641 return web.res
638 return web.res.sendresponse()
642
639
643 @webcommand('bookmarks')
640 @webcommand('bookmarks')
644 def bookmarks(web, req, tmpl):
641 def bookmarks(web, req, tmpl):
@@ -679,7 +676,7 b' def bookmarks(web, req, tmpl):'
679 entries=lambda **x: entries(latestonly=False, **x),
676 entries=lambda **x: entries(latestonly=False, **x),
680 latestentry=lambda **x: entries(latestonly=True, **x)))
677 latestentry=lambda **x: entries(latestonly=True, **x)))
681
678
682 return web.res
679 return web.res.sendresponse()
683
680
684 @webcommand('branches')
681 @webcommand('branches')
685 def branches(web, req, tmpl):
682 def branches(web, req, tmpl):
@@ -704,7 +701,7 b' def branches(web, req, tmpl):'
704 entries=entries,
701 entries=entries,
705 latestentry=latestentry))
702 latestentry=latestentry))
706
703
707 return web.res
704 return web.res.sendresponse()
708
705
709 @webcommand('summary')
706 @webcommand('summary')
710 def summary(web, req, tmpl):
707 def summary(web, req, tmpl):
@@ -789,7 +786,7 b' def summary(web, req, tmpl):'
789 archives=web.archivelist('tip'),
786 archives=web.archivelist('tip'),
790 labels=web.configlist('web', 'labels')))
787 labels=web.configlist('web', 'labels')))
791
788
792 return web.res
789 return web.res.sendresponse()
793
790
794 @webcommand('filediff')
791 @webcommand('filediff')
795 def filediff(web, req, tmpl):
792 def filediff(web, req, tmpl):
@@ -838,7 +835,7 b' def filediff(web, req, tmpl):'
838 diff=diffs,
835 diff=diffs,
839 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
836 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
840
837
841 return web.res
838 return web.res.sendresponse()
842
839
843 diff = webcommand('diff')(filediff)
840 diff = webcommand('diff')(filediff)
844
841
@@ -917,7 +914,7 b' def comparison(web, req, tmpl):'
917 comparison=comparison,
914 comparison=comparison,
918 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
915 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
919
916
920 return web.res
917 return web.res.sendresponse()
921
918
922 @webcommand('annotate')
919 @webcommand('annotate')
923 def annotate(web, req, tmpl):
920 def annotate(web, req, tmpl):
@@ -1011,7 +1008,7 b' def annotate(web, req, tmpl):'
1011 diffopts=diffopts,
1008 diffopts=diffopts,
1012 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
1009 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
1013
1010
1014 return web.res
1011 return web.res.sendresponse()
1015
1012
1016 @webcommand('filelog')
1013 @webcommand('filelog')
1017 def filelog(web, req, tmpl):
1014 def filelog(web, req, tmpl):
@@ -1151,7 +1148,7 b' def filelog(web, req, tmpl):'
1151 lessvars=lessvars,
1148 lessvars=lessvars,
1152 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
1149 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
1153
1150
1154 return web.res
1151 return web.res.sendresponse()
1155
1152
1156 @webcommand('archive')
1153 @webcommand('archive')
1157 def archive(web, req, tmpl):
1154 def archive(web, req, tmpl):
@@ -1225,7 +1222,7 b' def archive(web, req, tmpl):'
1225 matchfn=match,
1222 matchfn=match,
1226 subrepos=web.configbool("web", "archivesubrepos"))
1223 subrepos=web.configbool("web", "archivesubrepos"))
1227
1224
1228 return True
1225 return []
1229
1226
1230 @webcommand('static')
1227 @webcommand('static')
1231 def static(web, req, tmpl):
1228 def static(web, req, tmpl):
@@ -1240,7 +1237,7 b' def static(web, req, tmpl):'
1240 static = [os.path.join(p, 'static') for p in tp]
1237 static = [os.path.join(p, 'static') for p in tp]
1241
1238
1242 staticfile(static, fname, web.res)
1239 staticfile(static, fname, web.res)
1243 return web.res
1240 return web.res.sendresponse()
1244
1241
1245 @webcommand('graph')
1242 @webcommand('graph')
1246 def graph(web, req, tmpl):
1243 def graph(web, req, tmpl):
@@ -1401,7 +1398,7 b' def graph(web, req, tmpl):'
1401 node=ctx.hex(),
1398 node=ctx.hex(),
1402 changenav=changenav))
1399 changenav=changenav))
1403
1400
1404 return web.res
1401 return web.res.sendresponse()
1405
1402
1406 def _getdoc(e):
1403 def _getdoc(e):
1407 doc = e[0].__doc__
1404 doc = e[0].__doc__
@@ -1463,7 +1460,7 b' def help(web, req, tmpl):'
1463 earlycommands=earlycommands,
1460 earlycommands=earlycommands,
1464 othercommands=othercommands,
1461 othercommands=othercommands,
1465 title='Index'))
1462 title='Index'))
1466 return web.res
1463 return web.res.sendresponse()
1467
1464
1468 # Render an index of sub-topics.
1465 # Render an index of sub-topics.
1469 if topicname in helpmod.subtopics:
1466 if topicname in helpmod.subtopics:
@@ -1480,7 +1477,7 b' def help(web, req, tmpl):'
1480 topics=topics,
1477 topics=topics,
1481 title=topicname,
1478 title=topicname,
1482 subindex=True))
1479 subindex=True))
1483 return web.res
1480 return web.res.sendresponse()
1484
1481
1485 u = webutil.wsgiui.load()
1482 u = webutil.wsgiui.load()
1486 u.verbose = True
1483 u.verbose = True
@@ -1506,7 +1503,7 b' def help(web, req, tmpl):'
1506 topic=topicname,
1503 topic=topicname,
1507 doc=doc))
1504 doc=doc))
1508
1505
1509 return web.res
1506 return web.res.sendresponse()
1510
1507
1511 # tell hggettext to extract docstrings from these functions:
1508 # tell hggettext to extract docstrings from these functions:
1512 i18nfunctions = commands.values()
1509 i18nfunctions = commands.values()
General Comments 0
You need to be logged in to leave comments. Login now