Commit 48d24cb4 authored by Kirill Smelkov's avatar Kirill Smelkov

xnet/lonet.py: @method -> @func

Pygolang, starting from 0.0.0.dev8, deprecates @method(cls) in favour of @func(cls):

	pygolang@942ee900
parent 7ee2de42
...@@ -33,7 +33,7 @@ import functools ...@@ -33,7 +33,7 @@ import functools
import threading import threading
import logging as log import logging as log
from golang import method, go, chan, select, default, panic, gimport from golang import func, go, chan, select, default, panic, gimport
from golang.gcompat import qq from golang.gcompat import qq
xerr = gimport('lab.nexedi.com/kirr/go123/xerr') xerr = gimport('lab.nexedi.com/kirr/go123/xerr')
...@@ -220,7 +220,7 @@ class Accept(object): ...@@ -220,7 +220,7 @@ class Accept(object):
# ---------------------------------------- # ----------------------------------------
# _shutdown is worker for close and _vnet_down. # _shutdown is worker for close and _vnet_down.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def _shutdown(n, exc): def _shutdown(n, exc):
if not set_once(n._down_once): if not set_once(n._down_once):
return return
...@@ -239,13 +239,13 @@ def _shutdown(n, exc): ...@@ -239,13 +239,13 @@ def _shutdown(n, exc):
# close shutdowns subnetwork. # close shutdowns subnetwork.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def close(n): def close(n):
with errctx("virtnet %s: close" % qq(n._network)): with errctx("virtnet %s: close" % qq(n._network)):
n._shutdown(None) n._shutdown(None)
# _vnet_down shutdowns subnetwork upon engine error. # _vnet_down shutdowns subnetwork upon engine error.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def _vnet_down(n, exc): def _vnet_down(n, exc):
# XXX py: errctx here (go does not have) because we do not reraise .downErr in close # XXX py: errctx here (go does not have) because we do not reraise .downErr in close
with errctx("virtnet %s: shutdown" % qq(n._network)): with errctx("virtnet %s: shutdown" % qq(n._network)):
...@@ -253,7 +253,7 @@ def _vnet_down(n, exc): ...@@ -253,7 +253,7 @@ def _vnet_down(n, exc):
# new_host creates new Host with given name. # new_host creates new Host with given name.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def new_host(n, name): def new_host(n, name):
with errctx("virtnet %s: new host %s" % (qq(n._network), qq(name))): with errctx("virtnet %s: new host %s" % (qq(n._network), qq(name))):
n._vnet_newhost(name, n._registry) n._vnet_newhost(name, n._registry)
...@@ -269,14 +269,14 @@ def new_host(n, name): ...@@ -269,14 +269,14 @@ def new_host(n, name):
# host returns host on the subnetwork by name. # host returns host on the subnetwork by name.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def host(n, name): def host(n, name):
with n._hostmu: with n._hostmu:
return n._hostmap.get(name) return n._hostmap.get(name)
# _shutdown is underlying worker for close. # _shutdown is underlying worker for close.
@method(Host) @func(Host)
def _shutdown(h): def _shutdown(h):
if not set_once(h._down_once): if not set_once(h._down_once):
return return
...@@ -293,14 +293,14 @@ def _shutdown(h): ...@@ -293,14 +293,14 @@ def _shutdown(h):
sk._listener._shutdown() sk._listener._shutdown()
# close shutdowns host. # close shutdowns host.
@method(Host) @func(Host)
def close(h): def close(h):
with errctx("virtnet %s: host %s: close" % (qq(h._subnet._network), qq(h._name))): with errctx("virtnet %s: host %s: close" % (qq(h._subnet._network), qq(h._name))):
h._shutdown() h._shutdown()
# listen starts new listener on the host. # listen starts new listener on the host.
@method(Host) @func(Host)
def listen(h, laddr): def listen(h, laddr):
if laddr == "": if laddr == "":
laddr = ":0" laddr = ":0"
...@@ -335,13 +335,13 @@ def listen(h, laddr): ...@@ -335,13 +335,13 @@ def listen(h, laddr):
# _shutdown shutdowns the listener. # _shutdown shutdowns the listener.
@method(listener) @func(listener)
def _shutdown(l): def _shutdown(l):
if set_once(l._down_once): if set_once(l._down_once):
l._down.close() l._down.close()
# close closes the listener. # close closes the listener.
@method(listener) @func(listener)
def close(l): def close(l):
l._shutdown() l._shutdown()
if not set_once(l._close_once): if not set_once(l._close_once):
...@@ -357,7 +357,7 @@ def close(l): ...@@ -357,7 +357,7 @@ def close(l):
# accept tries to connect to dial called with addr corresponding to our listener. # accept tries to connect to dial called with addr corresponding to our listener.
@method(listener) @func(listener)
def accept(l): def accept(l):
h = l._socket._host h = l._socket._host
...@@ -412,7 +412,7 @@ def accept(l): ...@@ -412,7 +412,7 @@ def accept(l):
# _vnet_accept accepts or rejects incoming connection. # _vnet_accept accepts or rejects incoming connection.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def _vnet_accept(n, src, dst, netconn): def _vnet_accept(n, src, dst, netconn):
with n._hostmu: with n._hostmu:
host = n._hostmap.get(dst.host) host = n._hostmap.get(dst.host)
...@@ -447,7 +447,7 @@ def _vnet_accept(n, src, dst, netconn): ...@@ -447,7 +447,7 @@ def _vnet_accept(n, src, dst, netconn):
# dial dials address on the network. # dial dials address on the network.
@method(Host) @func(Host)
def dial(h, addr): def dial(h, addr):
with h._sockmu: with h._sockmu:
sk = h._allocFreeSocket() sk = h._allocFreeSocket()
...@@ -483,7 +483,7 @@ def dial(h, addr): ...@@ -483,7 +483,7 @@ def dial(h, addr):
# ---- conn ---- # ---- conn ----
# _shutdown closes underlying network connection. # _shutdown closes underlying network connection.
@method(conn) @func(conn)
def _shutdown(c): def _shutdown(c):
if not set_once(c._down_once): if not set_once(c._down_once):
return return
...@@ -494,7 +494,7 @@ def _shutdown(c): ...@@ -494,7 +494,7 @@ def _shutdown(c):
# close closes network endpoint and unregisters conn from Host. # close closes network endpoint and unregisters conn from Host.
@method(conn) @func(conn)
def close(c): def close(c):
c._shutdown() c._shutdown()
if set_once(c._close_once): if set_once(c._close_once):
...@@ -512,29 +512,29 @@ def close(c): ...@@ -512,29 +512,29 @@ def close(c):
# XXX py: don't bother to override send (Write) # XXX py: don't bother to override send (Write)
# local_addr returns virtnet address of local end of connection. # local_addr returns virtnet address of local end of connection.
@method(conn) @func(conn)
def local_addr(c): def local_addr(c):
return c._socket.addr() return c._socket.addr()
# getsockname returns virtnet address of local end of connection as net.AF_INET (host, port) pair. # getsockname returns virtnet address of local end of connection as net.AF_INET (host, port) pair.
@method(conn) @func(conn)
def getsockname(c): def getsockname(c):
return c.local_addr().netaddr() return c.local_addr().netaddr()
# remote_addr returns virtnet address of remote end of connection. # remote_addr returns virtnet address of remote end of connection.
@method(conn) @func(conn)
def remote_addr(c): def remote_addr(c):
return c._peerAddr return c._peerAddr
# getpeername returns virtnet address of remote end of connection as net.AF_INET (host, port) pair. # getpeername returns virtnet address of remote end of connection as net.AF_INET (host, port) pair.
@method(conn) @func(conn)
def getpeername(c): def getpeername(c):
return c.remote_addr().netaddr() return c.remote_addr().netaddr()
# ---------------------------------------- # ----------------------------------------
# _allocFreeSocket finds first free port and allocates socket entry for it. # _allocFreeSocket finds first free port and allocates socket entry for it.
@method(Host) @func(Host)
def _allocFreeSocket(h): def _allocFreeSocket(h):
port = 1 port = 1
while port < len(h._socketv): while port < len(h._socketv):
...@@ -551,18 +551,18 @@ def _allocFreeSocket(h): ...@@ -551,18 +551,18 @@ def _allocFreeSocket(h):
# empty checks whether socket's both conn and listener are all nil. # empty checks whether socket's both conn and listener are all nil.
@method(socket) @func(socket)
def _empty(sk): def _empty(sk):
return (sk._conn is None and sk._listener is None) return (sk._conn is None and sk._listener is None)
# addr returns address corresponding to socket. # addr returns address corresponding to socket.
@method(socket) @func(socket)
def addr(sk): def addr(sk):
h = sk._host h = sk._host
return Addr(h.network(), h.name(), sk._port) return Addr(h.network(), h.name(), sk._port)
# Addr.parse parses addr into virtnet address for named network. # Addr.parse parses addr into virtnet address for named network.
@method(Addr) @func(Addr)
@staticmethod @staticmethod
def parse(net, addr): def parse(net, addr):
try: try:
...@@ -574,7 +574,7 @@ def parse(net, addr): ...@@ -574,7 +574,7 @@ def parse(net, addr):
raise ValueError('%s is not valid virtnet address' % addr) raise ValueError('%s is not valid virtnet address' % addr)
# _parseAddr parses addr into virtnet address from host point of view. # _parseAddr parses addr into virtnet address from host point of view.
@method(Host) @func(Host)
def _parseAddr(h, addr): def _parseAddr(h, addr):
a = Addr.parse(h.network(), addr) a = Addr.parse(h.network(), addr)
if a.host == "": if a.host == "":
...@@ -582,30 +582,30 @@ def _parseAddr(h, addr): ...@@ -582,30 +582,30 @@ def _parseAddr(h, addr):
return a return a
# addr returns address where listener is accepting incoming connections. # addr returns address where listener is accepting incoming connections.
@method(listener) @func(listener)
def addr(l): def addr(l):
return l._socket.addr() return l._socket.addr()
# network returns full network name this subnetwork is part of. # network returns full network name this subnetwork is part of.
@method(VirtSubNetwork) @func(VirtSubNetwork)
def network(n): def network(n):
return n._network return n._network
# network returns full network name of underlying network. # network returns full network name of underlying network.
@method(Host) @func(Host)
def network(h): def network(h):
return h._subnet.network() return h._subnet.network()
# name returns host name. # name returns host name.
@method(Host) @func(Host)
def name(h): def name(h):
return h._name return h._name
# ---------------------------------------- # ----------------------------------------
# _excDown raises appropriate exception cause when h.down is found ready. # _excDown raises appropriate exception cause when h.down is found ready.
@method(Host) @func(Host)
def _excDown(h): def _excDown(h):
if ready(h._subnet._down): if ready(h._subnet._down):
raise ErrNetDown raise ErrNetDown
...@@ -613,7 +613,7 @@ def _excDown(h): ...@@ -613,7 +613,7 @@ def _excDown(h):
raise ErrHostDown raise ErrHostDown
# _excDown raises appropriate exception cause when l.down is found ready. # _excDown raises appropriate exception cause when l.down is found ready.
@method(listener) @func(listener)
def _excDown(l): def _excDown(l):
h = l._socket._host h = l._socket._host
n = h._subnet n = h._subnet
...@@ -888,7 +888,7 @@ class _SubNetwork(VirtSubNetwork): ...@@ -888,7 +888,7 @@ class _SubNetwork(VirtSubNetwork):
registry.announce(hostname, '%s:%d' % n._oslistener.getsockname()) registry.announce(hostname, '%s:%d' % n._oslistener.getsockname())
@method(protocolError) @func(protocolError)
def __str__(e): def __str__(e):
return "protocol error: %s" % e.args return "protocol error: %s" % e.args
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment