Merge pull request #490 from exarkun/pending-deprecations
Avoid pending Twisted deprecations
This commit is contained in:
commit
5bbf0abe9d
|
@ -2,6 +2,10 @@ import re, time
|
||||||
from twisted.application import service, strports, internet
|
from twisted.application import service, strports, internet
|
||||||
from twisted.web import http, static
|
from twisted.web import http, static
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
from twisted.internet.address import (
|
||||||
|
IPv4Address,
|
||||||
|
IPv6Address,
|
||||||
|
)
|
||||||
from nevow import appserver, inevow
|
from nevow import appserver, inevow
|
||||||
from allmydata.util import log, fileutil
|
from allmydata.util import log, fileutil
|
||||||
|
|
||||||
|
@ -114,16 +118,32 @@ class MyRequest(appserver.NevowRequest):
|
||||||
if self._tahoe_request_had_error:
|
if self._tahoe_request_had_error:
|
||||||
error = " [ERROR]"
|
error = " [ERROR]"
|
||||||
|
|
||||||
log.msg(format="web: %(clientip)s %(method)s %(uri)s %(code)s %(length)s%(error)s",
|
log.msg(
|
||||||
clientip=self.getClientIP(),
|
format=(
|
||||||
method=self.method,
|
"web: %(clientip)s %(method)s %(uri)s %(code)s "
|
||||||
uri=uri,
|
"%(length)s%(error)s"
|
||||||
code=self.code,
|
),
|
||||||
length=(self.sentLength or "-"),
|
clientip=_get_client_ip(self),
|
||||||
error=error,
|
method=self.method,
|
||||||
facility="tahoe.webish",
|
uri=uri,
|
||||||
level=log.OPERATIONAL,
|
code=self.code,
|
||||||
)
|
length=(self.sentLength or "-"),
|
||||||
|
error=error,
|
||||||
|
facility="tahoe.webish",
|
||||||
|
level=log.OPERATIONAL,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_client_ip(request):
|
||||||
|
try:
|
||||||
|
get = request.getClientAddress
|
||||||
|
except AttributeError:
|
||||||
|
return request.getClientIP()
|
||||||
|
else:
|
||||||
|
client_addr = get()
|
||||||
|
if isinstance(client_addr, (IPv4Address, IPv6Address)):
|
||||||
|
return client_addr.host
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class WebishServer(service.MultiService):
|
class WebishServer(service.MultiService):
|
||||||
|
@ -218,4 +238,3 @@ class IntroducerWebishServer(WebishServer):
|
||||||
service.MultiService.__init__(self)
|
service.MultiService.__init__(self)
|
||||||
self.root = introweb.IntroducerRoot(introducer)
|
self.root = introweb.IntroducerRoot(introducer)
|
||||||
self.buildServer(webport, nodeurl_path, staticdir)
|
self.buildServer(webport, nodeurl_path, staticdir)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue