Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go123
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go123
Commits
78c29936
Commit
78c29936
authored
Jun 20, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golang: Move it to ->
https://lab.nexedi.com/kirr/pygolang
parent
5f16012d
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
10 additions
and
932 deletions
+10
-932
golang/__init__.py
golang/__init__.py
+0
-505
golang/gcompat.py
golang/gcompat.py
+0
-44
golang/gcompat_test.py
golang/gcompat_test.py
+0
-39
golang/golang_test.py
golang/golang_test.py
+0
-325
xnet/lonet/__init__.py
xnet/lonet/__init__.py
+4
-13
xnet/lonet/lonet.go
xnet/lonet/lonet.go
+1
-1
xnet/lonet/lonet_test.go
xnet/lonet/lonet_test.go
+2
-2
xnet/lonet/lonet_test.py
xnet/lonet/lonet_test.py
+3
-3
No files found.
golang/__init__.py
deleted
100644 → 0
View file @
5f16012d
This diff is collapsed.
Click to expand it.
golang/gcompat.py
deleted
100644 → 0
View file @
5f16012d
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Package gcompat provides Go-compatibility layer for Python"""
# qq is substitute for %q, which is missing in python.
#
# (python's automatic escape uses smartquotes quoting with either ' or ").
def
qq
(
obj
):
# go: like %s, %q automatically converts to string
if
not
isinstance
(
obj
,
basestring
):
obj
=
str
(
obj
)
return
_quote
(
obj
)
# _quote quotes string into valid "..." string always quoted with ".
def
_quote
(
s
):
# TODO also accept unicode as input.
# TODO output printable UTF-8 characters as-is, but escape non-printable UTF-8 and invalid UTF-8 bytes.
outv
=
[]
# we don't want ' to be escaped
for
_
in
s
.
split
(
"'"
):
# this escape almost everything except " character
# NOTE string_escape does not do smartquotes and always uses ' for quoting
# (repr(str) is the same except it does smartquoting picking ' or " automatically)
q
=
_
.
encode
(
"string_escape"
)
q
=
q
.
replace
(
'"'
,
r'\"'
)
outv
.
append
(
q
)
return
'"'
+
"'"
.
join
(
outv
)
+
'"'
golang/gcompat_test.py
deleted
100644 → 0
View file @
5f16012d
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
gopath
gcompat
=
gopath
.
gimport
(
'lab.nexedi.com/kirr/go123/golang/gcompat'
)
qq
=
gcompat
.
qq
def
test_qq
():
testv
=
(
# in want without leading/trailing "
(
''
,
r""
),
(
'
\
'
'
,
r"'"
),
(
'"'
,
r"\""
),
(
'abc
\
n
def'
,
r"abc\ndef"
),
(
'a
\
'
c
\
n
def'
,
r"a'c\ndef"
),
(
'a
\
"
c
\
n
def'
,
r"a\"c\ndef"
),
# ('привет', r"привет"), TODO
)
for
tin
,
twant
in
testv
:
twant
=
'"'
+
twant
+
'"'
# add lead/trail "
assert
qq
(
tin
)
==
twant
golang/golang_test.py
deleted
100644 → 0
View file @
5f16012d
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
gopath
golang
=
gopath
.
gimport
(
'lab.nexedi.com/kirr/go123/golang'
)
go
=
golang
.
go
chan
=
golang
.
chan
select
=
golang
.
select
default
=
golang
.
default
_PanicError
=
golang
.
_PanicError
from
pytest
import
raises
import
time
,
threading
# tdelay delays a bit.
#
# XXX needed in situations when we need to start with known ordering but do not
# have a way to wait properly for ordering event.
def
tdelay
():
time
.
sleep
(
1E-3
)
# 1ms
def
test_chan
():
# sync: pre-close vs send/recv
ch
=
chan
()
ch
.
close
()
assert
ch
.
recv
()
==
None
assert
ch
.
recv_
()
==
(
None
,
False
)
assert
ch
.
recv_
()
==
(
None
,
False
)
raises
(
_PanicError
,
"ch.send(0)"
)
raises
(
_PanicError
,
"ch.close()"
)
# sync: send vs recv
ch
=
chan
()
def
_
():
ch
.
send
(
1
)
assert
ch
.
recv
()
==
2
ch
.
close
()
go
(
_
)
assert
ch
.
recv
()
==
1
ch
.
send
(
2
)
assert
ch
.
recv_
()
==
(
None
,
False
)
assert
ch
.
recv_
()
==
(
None
,
False
)
# sync: close vs send
ch
=
chan
()
def
_
():
tdelay
()
ch
.
close
()
go
(
_
)
raises
(
_PanicError
,
"ch.send(0)"
)
# close vs recv
ch
=
chan
()
def
_
():
tdelay
()
ch
.
close
()
go
(
_
)
assert
ch
.
recv_
()
==
(
None
,
False
)
# sync: close vs multiple recv
ch
=
chan
()
done
=
chan
()
mu
=
threading
.
Lock
()
s
=
set
()
def
_
():
assert
ch
.
recv_
()
==
(
None
,
False
)
with
mu
:
x
=
len
(
s
)
s
.
add
(
x
)
done
.
send
(
x
)
for
i
in
range
(
3
):
go
(
_
)
ch
.
close
()
for
i
in
range
(
3
):
done
.
recv
()
assert
s
==
{
0
,
1
,
2
}
# buffered
ch
=
chan
(
3
)
done
=
chan
()
for
_
in
range
(
2
):
for
i
in
range
(
3
):
assert
len
(
ch
)
==
i
ch
.
send
(
i
)
assert
len
(
ch
)
==
i
+
1
for
i
in
range
(
3
):
assert
ch
.
recv_
()
==
(
i
,
True
)
assert
len
(
ch
)
==
0
for
i
in
range
(
3
):
ch
.
send
(
i
)
assert
len
(
ch
)
==
3
def
_
():
tdelay
()
assert
ch
.
recv_
()
==
(
0
,
True
)
done
.
send
(
'a'
)
for
i
in
range
(
1
,
4
):
assert
ch
.
recv_
()
==
(
i
,
True
)
assert
ch
.
recv_
()
==
(
None
,
False
)
done
.
send
(
'b'
)
go
(
_
)
ch
.
send
(
3
)
# will block without receiver
assert
done
.
recv
()
==
'a'
ch
.
close
()
assert
done
.
recv
()
==
'b'
def
test_select
():
# non-blocking try send: not ok
ch
=
chan
()
_
,
_rx
=
select
(
(
ch
.
send
,
0
),
default
,
)
assert
(
_
,
_rx
)
==
(
1
,
None
)
# non-blocking try recv: not ok
_
,
_rx
=
select
(
ch
.
recv
,
default
,
)
assert
(
_
,
_rx
)
==
(
1
,
None
)
_
,
_rx
=
select
(
ch
.
recv_
,
default
,
)
assert
(
_
,
_rx
)
==
(
1
,
None
)
# non-blocking try send: ok
ch
=
chan
()
done
=
chan
()
def
_
():
i
=
0
while
1
:
x
=
ch
.
recv
()
if
x
==
'stop'
:
break
assert
x
==
i
i
+=
1
done
.
close
()
go
(
_
)
for
i
in
range
(
10
):
tdelay
()
_
,
_rx
=
select
(
(
ch
.
send
,
i
),
default
,
)
assert
(
_
,
_rx
)
==
(
0
,
None
)
ch
.
send
(
'stop'
)
done
.
recv
()
# non-blocking try recv: ok
ch
=
chan
()
done
=
chan
()
def
_
():
for
i
in
range
(
10
):
ch
.
send
(
i
)
done
.
close
()
go
(
_
)
for
i
in
range
(
10
):
tdelay
()
if
i
%
2
:
_
,
_rx
=
select
(
ch
.
recv
,
default
,
)
assert
(
_
,
_rx
)
==
(
0
,
i
)
else
:
_
,
_rx
=
select
(
ch
.
recv_
,
default
,
)
assert
(
_
,
_rx
)
==
(
0
,
(
i
,
True
))
done
.
recv
()
# blocking 2·send
ch1
=
chan
()
ch2
=
chan
()
done
=
chan
()
def
_
():
tdelay
()
assert
ch1
.
recv
()
==
'a'
done
.
close
()
go
(
_
)
_
,
_rx
=
select
(
(
ch1
.
send
,
'a'
),
(
ch2
.
send
,
'b'
),
)
assert
(
_
,
_rx
)
==
(
0
,
None
)
done
.
recv
()
assert
len
(
ch1
.
_sendq
)
==
len
(
ch1
.
_recvq
)
==
0
assert
len
(
ch2
.
_sendq
)
==
len
(
ch2
.
_recvq
)
==
0
# blocking 2·recv
ch1
=
chan
()
ch2
=
chan
()
done
=
chan
()
def
_
():
tdelay
()
ch1
.
send
(
'a'
)
done
.
close
()
go
(
_
)
_
,
_rx
=
select
(
ch1
.
recv
,
ch2
.
recv
,
)
assert
(
_
,
_rx
)
==
(
0
,
'a'
)
done
.
recv
()
assert
len
(
ch1
.
_sendq
)
==
len
(
ch1
.
_recvq
)
==
0
assert
len
(
ch2
.
_sendq
)
==
len
(
ch2
.
_recvq
)
==
0
# blocking send/recv
ch1
=
chan
()
ch2
=
chan
()
done
=
chan
()
def
_
():
tdelay
()
assert
ch1
.
recv
()
==
'a'
done
.
close
()
go
(
_
)
_
,
_rx
=
select
(
(
ch1
.
send
,
'a'
),
ch2
.
recv
,
)
assert
(
_
,
_rx
)
==
(
0
,
None
)
done
.
recv
()
assert
len
(
ch1
.
_sendq
)
==
len
(
ch1
.
_recvq
)
==
0
assert
len
(
ch2
.
_sendq
)
==
len
(
ch2
.
_recvq
)
==
0
# blocking recv/send
ch1
=
chan
()
ch2
=
chan
()
done
=
chan
()
def
_
():
tdelay
()
ch1
.
send
(
'a'
)
done
.
close
()
go
(
_
)
_
,
_rx
=
select
(
ch1
.
recv
,
(
ch2
.
send
,
'b'
),
)
assert
(
_
,
_rx
)
==
(
0
,
'a'
)
done
.
recv
()
assert
len
(
ch1
.
_sendq
)
==
len
(
ch1
.
_recvq
)
==
0
assert
len
(
ch2
.
_sendq
)
==
len
(
ch2
.
_recvq
)
==
0
# buffered ping-pong
ch
=
chan
(
1
)
for
i
in
range
(
10
):
_
,
_rx
=
select
(
(
ch
.
send
,
i
),
ch
.
recv
,
)
assert
_
==
(
i
%
2
)
assert
_rx
==
(
i
-
1
if
i
%
2
else
None
)
# select vs select
for
i
in
range
(
10
):
ch1
=
chan
()
ch2
=
chan
()
done
=
chan
()
def
_
():
_
,
_rx
=
select
(
(
ch1
.
send
,
'a'
),
(
ch2
.
send
,
'xxx2'
),
)
assert
(
_
,
_rx
)
==
(
0
,
None
)
_
,
_rx
=
select
(
(
ch1
.
send
,
'yyy2'
),
ch2
.
recv
,
)
assert
(
_
,
_rx
)
==
(
1
,
'b'
)
done
.
close
()
go
(
_
)
_
,
_rx
=
select
(
ch1
.
recv
,
(
ch2
.
send
,
'xxx1'
),
)
assert
(
_
,
_rx
)
==
(
0
,
'a'
)
_
,
_rx
=
select
(
(
ch1
.
send
,
'yyy1'
),
(
ch2
.
send
,
'b'
),
)
assert
(
_
,
_rx
)
==
(
1
,
None
)
done
.
recv
()
assert
len
(
ch1
.
_sendq
)
==
len
(
ch1
.
_recvq
)
==
0
assert
len
(
ch2
.
_sendq
)
==
len
(
ch2
.
_recvq
)
==
0
xnet/lonet/__init__.py
View file @
78c29936
...
...
@@ -33,19 +33,10 @@ import functools
import
threading
import
logging
as
log
import
gopath
golang
=
gopath
.
gimport
(
'lab.nexedi.com/kirr/go123/golang'
)
method
=
golang
.
method
go
=
golang
.
go
chan
=
golang
.
chan
select
=
golang
.
select
default
=
golang
.
default
panic
=
golang
.
panic
gcompat
=
gopath
.
gimport
(
'lab.nexedi.com/kirr/go123/golang/gcompat'
)
qq
=
gcompat
.
qq
xerr
=
gopath
.
gimport
(
'lab.nexedi.com/kirr/go123/xerr'
)
from
golang
import
method
,
go
,
chan
,
select
,
default
,
panic
,
gimport
from
golang.gcompat
import
qq
xerr
=
gimport
(
'lab.nexedi.com/kirr/go123/xerr'
)
Error
=
xerr
.
Error
errctx
=
xerr
.
context
errcause
=
xerr
.
cause
...
...
xnet/lonet/lonet.go
View file @
78c29936
...
...
@@ -63,7 +63,7 @@
//
// --------
//
// (*) use https://pypi.org/project/pygo
path
to import.
// (*) use https://pypi.org/project/pygo
lang
to import.
package
lonet
// Lonet organization
...
...
xnet/lonet/lonet_test.go
View file @
78c29936
...
...
@@ -121,12 +121,12 @@ func needPy(t *testing.T) {
if
havePy
{
return
}
t
.
Skipf
(
"skipping: python/pygo
path
/pytest are not available"
)
t
.
Skipf
(
"skipping: python/pygo
lang
/pytest are not available"
)
}
func
TestMain
(
m
*
testing
.
M
)
{
// check whether we have python + infrastructure for tests
cmd
:=
exec
.
Command
(
"python"
,
"-c"
,
"import go
path
, pytest"
)
cmd
:=
exec
.
Command
(
"python"
,
"-c"
,
"import go
lang
, pytest"
)
err
:=
cmd
.
Run
()
if
err
==
nil
{
havePy
=
true
...
...
xnet/lonet/lonet_test.py
View file @
78c29936
...
...
@@ -18,9 +18,9 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
gopath
xerr
=
g
opath
.
g
import
(
'lab.nexedi.com/kirr/go123/xerr'
)
lonet
=
g
opath
.
g
import
(
'lab.nexedi.com/kirr/go123/xnet/lonet'
)
from
golang
import
gimport
xerr
=
gimport
(
'lab.nexedi.com/kirr/go123/xerr'
)
lonet
=
gimport
(
'lab.nexedi.com/kirr/go123/xnet/lonet'
)
from
threading
import
Thread
from
cStringIO
import
StringIO
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment