Commit 311df9f1 authored by Kirill Smelkov's avatar Kirill Smelkov

golang.pyx: Rename moved channel bits * -> py*

To denote that this function/classes work at Python level:

    - chan    -> pychan
    - select  -> pyselect
    - default -> pydefault
    - nilchan -> pynilchan
parent 83259a1b
...@@ -173,9 +173,9 @@ def defer(f): ...@@ -173,9 +173,9 @@ def defer(f):
from ._golang import \ from ._golang import \
pygo as go, \ pygo as go, \
chan, \ pychan as chan, \
select, \ pyselect as select, \
default, \ pydefault as default, \
nilchan, \ pynilchan as nilchan, \
_PanicError, \ _PanicError, \
pypanic as panic pypanic as panic
...@@ -252,8 +252,8 @@ def _dequeWaiter(queue): ...@@ -252,8 +252,8 @@ def _dequeWaiter(queue):
return None return None
# chan is a channel with Go semantic. # pychan is Python channel with Go semantic.
class chan(object): class pychan(object):
# ._cap channel capacity # ._cap channel capacity
# ._mu lock # ._mu lock
# ._dataq deque *: data buffer # ._dataq deque *: data buffer
...@@ -273,7 +273,7 @@ class chan(object): ...@@ -273,7 +273,7 @@ class chan(object):
# #
# .send(obj) # .send(obj)
def send(self, obj): def send(self, obj):
if self is nilchan: if self is pynilchan:
_blockforever() _blockforever()
self._mu.acquire() self._mu.acquire()
...@@ -300,7 +300,7 @@ class chan(object): ...@@ -300,7 +300,7 @@ class chan(object):
# #
# .recv_() -> (rx, ok) # .recv_() -> (rx, ok)
def recv_(self): def recv_(self):
if self is nilchan: if self is pynilchan:
_blockforever() _blockforever()
self._mu.acquire() self._mu.acquire()
...@@ -401,7 +401,7 @@ class chan(object): ...@@ -401,7 +401,7 @@ class chan(object):
# close closes sending side of the channel. # close closes sending side of the channel.
def close(self): def close(self):
if self is nilchan: if self is pynilchan:
pypanic("close of nil channel") pypanic("close of nil channel")
recvv = [] recvv = []
...@@ -437,32 +437,32 @@ class chan(object): ...@@ -437,32 +437,32 @@ class chan(object):
return len(self._dataq) return len(self._dataq)
def __repr__(self): def __repr__(self):
if self is nilchan: if self is pynilchan:
return "nilchan" return "nilchan"
else: else:
return super(chan, self).__repr__() return super(pychan, self).__repr__()
# nilchan is the nil channel. # pynilchan is the nil py channel.
# #
# On nil channel: send/recv block forever; close panics. # On nil channel: send/recv block forever; close panics.
nilchan = chan(None) # TODO -> <chan*>(NULL) after move to Cython pynilchan = pychan(None) # TODO -> <chan*>(NULL) after move to Cython
# default represents default case for select. # pydefault represents default case for pyselect.
default = object() pydefault = object()
# unbound chan.{send,recv,recv_} # unbound pychan.{send,recv,recv_}
_chan_send = chan.send _pychan_send = pychan.send
_chan_recv = chan.recv _pychan_recv = pychan.recv
_chan_recv_ = chan.recv_ _pychan_recv_ = pychan.recv_
if six.PY2: if six.PY2:
# on py3 class.func gets the func; on py2 - unbound_method(func) # on py3 class.func gets the func; on py2 - unbound_method(func)
_chan_send = _chan_send.__func__ _pychan_send = _pychan_send.__func__
_chan_recv = _chan_recv.__func__ _pychan_recv = _pychan_recv.__func__
_chan_recv_ = _chan_recv_.__func__ _pychan_recv_ = _pychan_recv_.__func__
# select executes one ready send or receive channel case. # pyselect executes one ready send or receive channel case.
# #
# if no case is ready and default case was provided, select chooses default. # if no case is ready and default case was provided, select chooses default.
# if no case is ready and default was not provided, select blocks until one case becomes ready. # if no case is ready and default was not provided, select blocks until one case becomes ready.
...@@ -489,7 +489,7 @@ if six.PY2: ...@@ -489,7 +489,7 @@ if six.PY2:
# if _ == 3: # if _ == 3:
# # default case # # default case
# ... # ...
def select(*casev): def pyselect(*casev):
# select promise: if multiple cases are ready - one will be selected randomly # select promise: if multiple cases are ready - one will be selected randomly
ncasev = list(enumerate(casev)) ncasev = list(enumerate(casev))
random.shuffle(ncasev) random.shuffle(ncasev)
...@@ -500,21 +500,21 @@ def select(*casev): ...@@ -500,21 +500,21 @@ def select(*casev):
ndefault = None ndefault = None
for (n, case) in ncasev: for (n, case) in ncasev:
# default: remember we have it # default: remember we have it
if case is default: if case is pydefault:
if ndefault is not None: if ndefault is not None:
pypanic("select: multiple default") pypanic("pyselect: multiple default")
ndefault = n ndefault = n
# send # send
elif isinstance(case, tuple): elif isinstance(case, tuple):
send, tx = case send, tx = case
if im_class(send) is not chan: if im_class(send) is not pychan:
pypanic("select: send on non-chan: %r" % (im_class(send),)) pypanic("pyselect: send on non-chan: %r" % (im_class(send),))
if send.__func__ is not _chan_send: if send.__func__ is not _pychan_send:
pypanic("select: send expected: %r" % (send,)) pypanic("pyselect: send expected: %r" % (send,))
ch = send.__self__ ch = send.__self__
if ch is not nilchan: # nil chan is never ready if ch is not pynilchan: # nil chan is never ready
ch._mu.acquire() ch._mu.acquire()
if 1: if 1:
ok = ch._trysend(tx) ok = ch._trysend(tx)
...@@ -527,17 +527,17 @@ def select(*casev): ...@@ -527,17 +527,17 @@ def select(*casev):
# recv # recv
else: else:
recv = case recv = case
if im_class(recv) is not chan: if im_class(recv) is not pychan:
pypanic("select: recv on non-chan: %r" % (im_class(recv),)) pypanic("pyselect: recv on non-chan: %r" % (im_class(recv),))
if recv.__func__ is _chan_recv: if recv.__func__ is _pychan_recv:
commaok = False commaok = False
elif recv.__func__ is _chan_recv_: elif recv.__func__ is _pychan_recv_:
commaok = True commaok = True
else: else:
pypanic("select: recv expected: %r" % (recv,)) pypanic("pyselect: recv expected: %r" % (recv,))
ch = recv.__self__ ch = recv.__self__
if ch is not nilchan: # nil chan is never ready if ch is not pynilchan: # nil chan is never ready
ch._mu.acquire() ch._mu.acquire()
if 1: if 1:
rx_, ok = ch._tryrecv() rx_, ok = ch._tryrecv()
......
...@@ -30,7 +30,7 @@ from six.moves import range as xrange ...@@ -30,7 +30,7 @@ from six.moves import range as xrange
import gc, weakref import gc, weakref
import golang import golang
from golang._golang import _chan_recv, _chan_send from golang._golang import _pychan_recv, _pychan_send
from golang._pycompat import im_class from golang._pycompat import im_class
# pyx/c/c++ tests -> test_pyx_* # pyx/c/c++ tests -> test_pyx_*
...@@ -70,9 +70,9 @@ def waitBlocked(chanop): ...@@ -70,9 +70,9 @@ def waitBlocked(chanop):
panic("wait blocked: %r is method of a non-chan: %r" % (chanop, im_class(chanop))) panic("wait blocked: %r is method of a non-chan: %r" % (chanop, im_class(chanop)))
ch = chanop.__self__ ch = chanop.__self__
recv = send = False recv = send = False
if chanop.__func__ is _chan_recv: if chanop.__func__ is _pychan_recv:
recv = True recv = True
elif chanop.__func__ is _chan_send: elif chanop.__func__ is _pychan_send:
send = True send = True
else: else:
panic("wait blocked: unexpected chan method: %r" % (chanop,)) panic("wait blocked: unexpected chan method: %r" % (chanop,))
......
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