Mercurial > hg
comparison mercurial/hgweb/__init__.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 91104f10ff65 |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
15 from .. import ( | 15 from .. import ( |
16 error, | 16 error, |
17 pycompat, | 17 pycompat, |
18 ) | 18 ) |
19 | 19 |
20 from ..utils import ( | 20 from ..utils import procutil |
21 procutil, | |
22 ) | |
23 | 21 |
24 from . import ( | 22 from . import ( |
25 hgweb_mod, | 23 hgweb_mod, |
26 hgwebdir_mod, | 24 hgwebdir_mod, |
27 server, | 25 server, |
28 ) | 26 ) |
27 | |
29 | 28 |
30 def hgweb(config, name=None, baseui=None): | 29 def hgweb(config, name=None, baseui=None): |
31 '''create an hgweb wsgi object | 30 '''create an hgweb wsgi object |
32 | 31 |
33 config can be one of: | 32 config can be one of: |
38 - list of virtual:real tuples (multi-repo view) | 37 - list of virtual:real tuples (multi-repo view) |
39 ''' | 38 ''' |
40 | 39 |
41 if isinstance(config, pycompat.unicode): | 40 if isinstance(config, pycompat.unicode): |
42 raise error.ProgrammingError( | 41 raise error.ProgrammingError( |
43 'Mercurial only supports encoded strings: %r' % config) | 42 'Mercurial only supports encoded strings: %r' % config |
44 if ((isinstance(config, bytes) and not os.path.isdir(config)) or | 43 ) |
45 isinstance(config, dict) or isinstance(config, list)): | 44 if ( |
45 (isinstance(config, bytes) and not os.path.isdir(config)) | |
46 or isinstance(config, dict) | |
47 or isinstance(config, list) | |
48 ): | |
46 # create a multi-dir interface | 49 # create a multi-dir interface |
47 return hgwebdir_mod.hgwebdir(config, baseui=baseui) | 50 return hgwebdir_mod.hgwebdir(config, baseui=baseui) |
48 return hgweb_mod.hgweb(config, name=name, baseui=baseui) | 51 return hgweb_mod.hgweb(config, name=name, baseui=baseui) |
49 | 52 |
53 | |
50 def hgwebdir(config, baseui=None): | 54 def hgwebdir(config, baseui=None): |
51 return hgwebdir_mod.hgwebdir(config, baseui=baseui) | 55 return hgwebdir_mod.hgwebdir(config, baseui=baseui) |
56 | |
52 | 57 |
53 class httpservice(object): | 58 class httpservice(object): |
54 def __init__(self, ui, app, opts): | 59 def __init__(self, ui, app, opts): |
55 self.ui = ui | 60 self.ui = ui |
56 self.app = app | 61 self.app = app |
58 | 63 |
59 def init(self): | 64 def init(self): |
60 procutil.setsignalhandler() | 65 procutil.setsignalhandler() |
61 self.httpd = server.create_server(self.ui, self.app) | 66 self.httpd = server.create_server(self.ui, self.app) |
62 | 67 |
63 if (self.opts['port'] and | 68 if ( |
64 not self.ui.verbose and | 69 self.opts['port'] |
65 not self.opts['print_url']): | 70 and not self.ui.verbose |
71 and not self.opts['print_url'] | |
72 ): | |
66 return | 73 return |
67 | 74 |
68 if self.httpd.prefix: | 75 if self.httpd.prefix: |
69 prefix = self.httpd.prefix.strip('/') + '/' | 76 prefix = self.httpd.prefix.strip('/') + '/' |
70 else: | 77 else: |
75 port = r'' | 82 port = r'' |
76 | 83 |
77 bindaddr = self.httpd.addr | 84 bindaddr = self.httpd.addr |
78 if bindaddr == r'0.0.0.0': | 85 if bindaddr == r'0.0.0.0': |
79 bindaddr = r'*' | 86 bindaddr = r'*' |
80 elif r':' in bindaddr: # IPv6 | 87 elif r':' in bindaddr: # IPv6 |
81 bindaddr = r'[%s]' % bindaddr | 88 bindaddr = r'[%s]' % bindaddr |
82 | 89 |
83 fqaddr = self.httpd.fqaddr | 90 fqaddr = self.httpd.fqaddr |
84 if r':' in fqaddr: | 91 if r':' in fqaddr: |
85 fqaddr = r'[%s]' % fqaddr | 92 fqaddr = r'[%s]' % fqaddr |
86 | 93 |
87 url = 'http://%s%s/%s' % ( | 94 url = 'http://%s%s/%s' % ( |
88 pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix) | 95 pycompat.sysbytes(fqaddr), |
96 pycompat.sysbytes(port), | |
97 prefix, | |
98 ) | |
89 if self.opts['print_url']: | 99 if self.opts['print_url']: |
90 self.ui.write('%s\n' % url) | 100 self.ui.write('%s\n' % url) |
91 else: | 101 else: |
92 if self.opts['port']: | 102 if self.opts['port']: |
93 write = self.ui.status | 103 write = self.ui.status |
94 else: | 104 else: |
95 write = self.ui.write | 105 write = self.ui.write |
96 write(_('listening at %s (bound to %s:%d)\n') % | 106 write( |
97 (url, pycompat.sysbytes(bindaddr), self.httpd.port)) | 107 _('listening at %s (bound to %s:%d)\n') |
108 % (url, pycompat.sysbytes(bindaddr), self.httpd.port) | |
109 ) | |
98 self.ui.flush() # avoid buffering of status message | 110 self.ui.flush() # avoid buffering of status message |
99 | 111 |
100 def run(self): | 112 def run(self): |
101 self.httpd.serve_forever() | 113 self.httpd.serve_forever() |
114 | |
102 | 115 |
103 def createapp(baseui, repo, webconf): | 116 def createapp(baseui, repo, webconf): |
104 if webconf: | 117 if webconf: |
105 return hgwebdir_mod.hgwebdir(webconf, baseui=baseui) | 118 return hgwebdir_mod.hgwebdir(webconf, baseui=baseui) |
106 else: | 119 else: |
107 if not repo: | 120 if not repo: |
108 raise error.RepoError(_("there is no Mercurial repository" | 121 raise error.RepoError( |
109 " here (.hg not found)")) | 122 _("there is no Mercurial repository" " here (.hg not found)") |
123 ) | |
110 return hgweb_mod.hgweb(repo, baseui=baseui) | 124 return hgweb_mod.hgweb(repo, baseui=baseui) |