comparison mercurial/statichttprepo.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 9f70512ae2cf
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
47 def seek(self, pos): 47 def seek(self, pos):
48 self.pos = pos 48 self.pos = pos
49 49
50 def read(self, bytes=None): 50 def read(self, bytes=None):
51 req = urlreq.request(pycompat.strurl(self.url)) 51 req = urlreq.request(pycompat.strurl(self.url))
52 end = '' 52 end = b''
53 if bytes: 53 if bytes:
54 end = self.pos + bytes - 1 54 end = self.pos + bytes - 1
55 if self.pos or end: 55 if self.pos or end:
56 req.add_header(r'Range', r'bytes=%d-%s' % (self.pos, end)) 56 req.add_header(r'Range', r'bytes=%d-%s' % (self.pos, end))
57 57
110 r.msg = msg 110 r.msg = msg
111 return r 111 return r
112 112
113 def http_error_416(self, req, fp, code, msg, hdrs): 113 def http_error_416(self, req, fp, code, msg, hdrs):
114 # HTTP's Range Not Satisfiable error 114 # HTTP's Range Not Satisfiable error
115 raise _RangeError('Requested Range Not Satisfiable') 115 raise _RangeError(b'Requested Range Not Satisfiable')
116 116
117 117
118 def build_opener(ui, authinfo): 118 def build_opener(ui, authinfo):
119 # urllib cannot handle URLs with embedded user or passwd 119 # urllib cannot handle URLs with embedded user or passwd
120 urlopener = url.opener(ui, authinfo) 120 urlopener = url.opener(ui, authinfo)
123 class statichttpvfs(vfsmod.abstractvfs): 123 class statichttpvfs(vfsmod.abstractvfs):
124 def __init__(self, base): 124 def __init__(self, base):
125 self.base = base 125 self.base = base
126 self.options = {} 126 self.options = {}
127 127
128 def __call__(self, path, mode='r', *args, **kw): 128 def __call__(self, path, mode=b'r', *args, **kw):
129 if mode not in ('r', 'rb'): 129 if mode not in (b'r', b'rb'):
130 raise IOError('Permission denied') 130 raise IOError(b'Permission denied')
131 f = "/".join((self.base, urlreq.quote(path))) 131 f = b"/".join((self.base, urlreq.quote(path)))
132 return httprangereader(f, urlopener) 132 return httprangereader(f, urlopener)
133 133
134 def join(self, path): 134 def join(self, path):
135 if path: 135 if path:
136 return pathutil.join(self.base, path) 136 return pathutil.join(self.base, path)
156 def __init__(self, ui, path): 156 def __init__(self, ui, path):
157 self._url = path 157 self._url = path
158 self.ui = ui 158 self.ui = ui
159 159
160 self.root = path 160 self.root = path
161 u = util.url(path.rstrip('/') + "/.hg") 161 u = util.url(path.rstrip(b'/') + b"/.hg")
162 self.path, authinfo = u.authinfo() 162 self.path, authinfo = u.authinfo()
163 163
164 vfsclass = build_opener(ui, authinfo) 164 vfsclass = build_opener(ui, authinfo)
165 self.vfs = vfsclass(self.path) 165 self.vfs = vfsclass(self.path)
166 self.cachevfs = vfsclass(self.vfs.join('cache')) 166 self.cachevfs = vfsclass(self.vfs.join(b'cache'))
167 self._phasedefaults = [] 167 self._phasedefaults = []
168 168
169 self.names = namespaces.namespaces() 169 self.names = namespaces.namespaces()
170 self.filtername = None 170 self.filtername = None
171 self._extrafilterid = None 171 self._extrafilterid = None
177 raise 177 raise
178 requirements = set() 178 requirements = set()
179 179
180 # check if it is a non-empty old-style repository 180 # check if it is a non-empty old-style repository
181 try: 181 try:
182 fp = self.vfs("00changelog.i") 182 fp = self.vfs(b"00changelog.i")
183 fp.read(1) 183 fp.read(1)
184 fp.close() 184 fp.close()
185 except IOError as inst: 185 except IOError as inst:
186 if inst.errno != errno.ENOENT: 186 if inst.errno != errno.ENOENT:
187 raise 187 raise
188 # we do not care about empty old-style repositories here 188 # we do not care about empty old-style repositories here
189 msg = _("'%s' does not appear to be an hg repository") % path 189 msg = _(b"'%s' does not appear to be an hg repository") % path
190 raise error.RepoError(msg) 190 raise error.RepoError(msg)
191 191
192 supportedrequirements = localrepo.gathersupportedrequirements(ui) 192 supportedrequirements = localrepo.gathersupportedrequirements(ui)
193 localrepo.ensurerequirementsrecognized( 193 localrepo.ensurerequirementsrecognized(
194 requirements, supportedrequirements 194 requirements, supportedrequirements
216 self.decodepats = None 216 self.decodepats = None
217 self._transref = None 217 self._transref = None
218 218
219 def _restrictcapabilities(self, caps): 219 def _restrictcapabilities(self, caps):
220 caps = super(statichttprepository, self)._restrictcapabilities(caps) 220 caps = super(statichttprepository, self)._restrictcapabilities(caps)
221 return caps.difference(["pushkey"]) 221 return caps.difference([b"pushkey"])
222 222
223 def url(self): 223 def url(self):
224 return self._url 224 return self._url
225 225
226 def local(self): 226 def local(self):
230 return statichttppeer(self) 230 return statichttppeer(self)
231 231
232 def wlock(self, wait=True): 232 def wlock(self, wait=True):
233 raise error.LockUnavailable( 233 raise error.LockUnavailable(
234 0, 234 0,
235 _('lock not available'), 235 _(b'lock not available'),
236 'lock', 236 b'lock',
237 _('cannot lock static-http repository'), 237 _(b'cannot lock static-http repository'),
238 ) 238 )
239 239
240 def lock(self, wait=True): 240 def lock(self, wait=True):
241 raise error.Abort(_('cannot lock static-http repository')) 241 raise error.Abort(_(b'cannot lock static-http repository'))
242 242
243 def _writecaches(self): 243 def _writecaches(self):
244 pass # statichttprepository are read only 244 pass # statichttprepository are read only
245 245
246 246
247 def instance(ui, path, create, intents=None, createopts=None): 247 def instance(ui, path, create, intents=None, createopts=None):
248 if create: 248 if create:
249 raise error.Abort(_('cannot create new static-http repository')) 249 raise error.Abort(_(b'cannot create new static-http repository'))
250 return statichttprepository(ui, path[7:]) 250 return statichttprepository(ui, path[7:])