Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
80b0fa0d
Kaydet (Commit)
80b0fa0d
authored
Haz 26, 1996
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
socket wrapper module around _socket for all Window platforms
üst
ca318ec1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
272 additions
and
0 deletions
+272
-0
socket.py
Lib/plat-win/socket.py
+136
-0
socket.py
Lib/win/socket.py
+136
-0
No files found.
Lib/plat-win/socket.py
0 → 100755
Dosyayı görüntüle @
80b0fa0d
"Socket wrapper for Windows, which does not support dup()."
print
"new socket.py loading"
# (And hence, fromfd() and makefile() are unimplemented in C....)
# XXX Living dangerously here -- close() is implemented by deleting a
# reference. Thus we rely on the real _socket module to close on
# deallocation, and also hope that nobody keeps a reference to our _sock
# member.
try
:
from
_socket
import
*
except
ImportError
:
from
socket
import
*
_realsocketcall
=
socket
def
socket
(
family
,
type
,
proto
=
0
):
return
_socketobject
(
_realsocketcall
(
family
,
type
,
proto
))
class
_socketobject
:
def
__init__
(
self
,
sock
):
print
"creating _socketobject"
,
sock
self
.
_sock
=
sock
def
close
(
self
):
self
.
_sock
=
None
def
__del__
(
self
):
self
.
close
()
def
accept
(
self
):
sock
,
addr
=
self
.
_sock
.
accept
()
return
_socketobject
(
sock
),
addr
def
dup
(
self
):
return
_socketobject
(
self
.
_sock
)
def
makefile
(
self
,
mode
=
'r'
,
bufsize
=-
1
):
return
_fileobject
(
self
.
_sock
,
mode
,
bufsize
)
_s
=
"def
%
s(self, *args): return apply(self._sock.
%
s, args)
\n\n
"
for
_m
in
(
'bind'
,
'connect'
,
'fileno'
,
'listen'
,
'getpeername'
,
'getsockname'
,
'getsockopt'
,
'setsockopt'
,
'recv'
,
'recvfrom'
,
'send'
,
'sendto'
,
'setblocking'
,
'shutdown'
):
exec
_s
%
(
_m
,
_m
)
class
_fileobject
:
def
__init__
(
self
,
sock
,
mode
,
bufsize
):
self
.
_sock
=
sock
self
.
_mode
=
mode
if
bufsize
<
0
:
bufsize
=
512
self
.
_rbufsize
=
max
(
1
,
bufsize
)
self
.
_wbufsize
=
bufsize
self
.
_wbuf
=
self
.
_rbuf
=
""
def
close
(
self
):
try
:
if
self
.
_sock
:
self
.
flush
()
finally
:
self
.
_sock
=
None
def
__del__
(
self
):
self
.
close
()
def
flush
(
self
):
if
self
.
_wbuf
:
self
.
_sock
.
send
(
self
.
_wbuf
)
self
.
_wbuf
=
""
def
fileno
(
self
):
return
self
.
_sock
.
fileno
()
def
write
(
self
,
data
):
self
.
_wbuf
=
self
.
_wbuf
+
data
if
self
.
_wbufsize
==
1
:
if
'
\n
'
in
data
:
self
.
flush
()
else
:
if
len
(
self
.
_wbuf
)
>=
self
.
_wbufsize
:
self
.
flush
()
def
writelines
(
self
,
list
):
filter
(
self
.
_sock
.
send
,
list
)
self
.
flush
()
def
read
(
self
,
n
=-
1
):
if
n
>=
0
:
while
len
(
self
.
_rbuf
)
<
n
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
self
.
_rbuf
=
self
.
_rbuf
+
new
data
,
self
.
_rbuf
=
self
.
_rbuf
[:
n
],
self
.
_rbuf
[
n
:]
return
data
while
1
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
self
.
_rbuf
=
self
.
_rbuf
+
new
data
,
self
.
_rbuf
=
self
.
_rbuf
,
""
return
data
def
readline
(
self
):
import
string
data
=
""
i
=
string
.
find
(
self
.
_rbuf
,
'
\n
'
)
while
i
<
0
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
i
=
string
.
find
(
new
,
'
\n
'
)
if
i
>=
0
:
i
=
i
+
len
(
self
.
_rbuf
)
self
.
_rbuf
=
self
.
_rbuf
+
new
if
i
<
0
:
i
=
len
(
self
.
_rbuf
)
else
:
i
=
i
+
1
data
,
self
.
_rbuf
=
self
.
_rbuf
[:
i
],
self
.
_rbuf
[
i
:]
return
data
def
readlines
(
self
):
list
=
[]
while
1
:
line
=
self
.
readline
()
if
not
line
:
break
list
.
append
(
line
)
return
list
Lib/win/socket.py
0 → 100755
Dosyayı görüntüle @
80b0fa0d
"Socket wrapper for Windows, which does not support dup()."
print
"new socket.py loading"
# (And hence, fromfd() and makefile() are unimplemented in C....)
# XXX Living dangerously here -- close() is implemented by deleting a
# reference. Thus we rely on the real _socket module to close on
# deallocation, and also hope that nobody keeps a reference to our _sock
# member.
try
:
from
_socket
import
*
except
ImportError
:
from
socket
import
*
_realsocketcall
=
socket
def
socket
(
family
,
type
,
proto
=
0
):
return
_socketobject
(
_realsocketcall
(
family
,
type
,
proto
))
class
_socketobject
:
def
__init__
(
self
,
sock
):
print
"creating _socketobject"
,
sock
self
.
_sock
=
sock
def
close
(
self
):
self
.
_sock
=
None
def
__del__
(
self
):
self
.
close
()
def
accept
(
self
):
sock
,
addr
=
self
.
_sock
.
accept
()
return
_socketobject
(
sock
),
addr
def
dup
(
self
):
return
_socketobject
(
self
.
_sock
)
def
makefile
(
self
,
mode
=
'r'
,
bufsize
=-
1
):
return
_fileobject
(
self
.
_sock
,
mode
,
bufsize
)
_s
=
"def
%
s(self, *args): return apply(self._sock.
%
s, args)
\n\n
"
for
_m
in
(
'bind'
,
'connect'
,
'fileno'
,
'listen'
,
'getpeername'
,
'getsockname'
,
'getsockopt'
,
'setsockopt'
,
'recv'
,
'recvfrom'
,
'send'
,
'sendto'
,
'setblocking'
,
'shutdown'
):
exec
_s
%
(
_m
,
_m
)
class
_fileobject
:
def
__init__
(
self
,
sock
,
mode
,
bufsize
):
self
.
_sock
=
sock
self
.
_mode
=
mode
if
bufsize
<
0
:
bufsize
=
512
self
.
_rbufsize
=
max
(
1
,
bufsize
)
self
.
_wbufsize
=
bufsize
self
.
_wbuf
=
self
.
_rbuf
=
""
def
close
(
self
):
try
:
if
self
.
_sock
:
self
.
flush
()
finally
:
self
.
_sock
=
None
def
__del__
(
self
):
self
.
close
()
def
flush
(
self
):
if
self
.
_wbuf
:
self
.
_sock
.
send
(
self
.
_wbuf
)
self
.
_wbuf
=
""
def
fileno
(
self
):
return
self
.
_sock
.
fileno
()
def
write
(
self
,
data
):
self
.
_wbuf
=
self
.
_wbuf
+
data
if
self
.
_wbufsize
==
1
:
if
'
\n
'
in
data
:
self
.
flush
()
else
:
if
len
(
self
.
_wbuf
)
>=
self
.
_wbufsize
:
self
.
flush
()
def
writelines
(
self
,
list
):
filter
(
self
.
_sock
.
send
,
list
)
self
.
flush
()
def
read
(
self
,
n
=-
1
):
if
n
>=
0
:
while
len
(
self
.
_rbuf
)
<
n
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
self
.
_rbuf
=
self
.
_rbuf
+
new
data
,
self
.
_rbuf
=
self
.
_rbuf
[:
n
],
self
.
_rbuf
[
n
:]
return
data
while
1
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
self
.
_rbuf
=
self
.
_rbuf
+
new
data
,
self
.
_rbuf
=
self
.
_rbuf
,
""
return
data
def
readline
(
self
):
import
string
data
=
""
i
=
string
.
find
(
self
.
_rbuf
,
'
\n
'
)
while
i
<
0
:
new
=
self
.
_sock
.
recv
(
self
.
_rbufsize
)
if
not
new
:
break
i
=
string
.
find
(
new
,
'
\n
'
)
if
i
>=
0
:
i
=
i
+
len
(
self
.
_rbuf
)
self
.
_rbuf
=
self
.
_rbuf
+
new
if
i
<
0
:
i
=
len
(
self
.
_rbuf
)
else
:
i
=
i
+
1
data
,
self
.
_rbuf
=
self
.
_rbuf
[:
i
],
self
.
_rbuf
[
i
:]
return
data
def
readlines
(
self
):
list
=
[]
while
1
:
line
=
self
.
readline
()
if
not
line
:
break
list
.
append
(
line
)
return
list
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