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
7184bac5
Kaydet (Commit)
7184bac5
authored
Eki 15, 2014
tarafından
Ethan Furman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue20386: SocketType is again socket.socket; the IntEnum SOCK constants are SocketKind
üst
00bdce3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
7 deletions
+21
-7
socket.rst
Doc/library/socket.rst
+5
-0
socket.py
Lib/socket.py
+7
-5
test_socket.py
Lib/test/test_socket.py
+9
-2
No files found.
Doc/library/socket.rst
Dosyayı görüntüle @
7184bac5
...
@@ -192,6 +192,11 @@ Exceptions
...
@@ -192,6 +192,11 @@ Exceptions
Constants
Constants
^^^^^^^^^
^^^^^^^^^
The AF_* and SOCK_* constants are now :class:`AddressFamily` and
:class:`SocketKind` :class:`.IntEnum` collections.
.. versionadded:: 3.4
.. data:: AF_UNIX
.. data:: AF_UNIX
AF_INET
AF_INET
AF_INET6
AF_INET6
...
...
Lib/socket.py
Dosyayı görüntüle @
7184bac5
...
@@ -35,11 +35,13 @@ SocketType -- type object for socket objects
...
@@ -35,11 +35,13 @@ SocketType -- type object for socket objects
error -- exception raised for I/O errors
error -- exception raised for I/O errors
has_ipv6 -- boolean value indicating if IPv6 is supported
has_ipv6 -- boolean value indicating if IPv6 is supported
Int
eger
constants:
Int
Enum
constants:
AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
Integer constants:
Many other constants may be defined; these may be used in calls to
Many other constants may be defined; these may be used in calls to
the setsockopt() and getsockopt() methods.
the setsockopt() and getsockopt() methods.
"""
"""
...
@@ -71,10 +73,10 @@ AddressFamily = IntEnum('AddressFamily',
...
@@ -71,10 +73,10 @@ AddressFamily = IntEnum('AddressFamily',
if
name
.
isupper
()
and
name
.
startswith
(
'AF_'
)})
if
name
.
isupper
()
and
name
.
startswith
(
'AF_'
)})
globals
()
.
update
(
AddressFamily
.
__members__
)
globals
()
.
update
(
AddressFamily
.
__members__
)
Socket
Type
=
IntEnum
(
'SocketType
'
,
Socket
Kind
=
IntEnum
(
'SocketKind
'
,
{
name
:
value
for
name
,
value
in
globals
()
.
items
()
{
name
:
value
for
name
,
value
in
globals
()
.
items
()
if
name
.
isupper
()
and
name
.
startswith
(
'SOCK_'
)})
if
name
.
isupper
()
and
name
.
startswith
(
'SOCK_'
)})
globals
()
.
update
(
Socket
Type
.
__members__
)
globals
()
.
update
(
Socket
Kind
.
__members__
)
def
_intenum_converter
(
value
,
enum_klass
):
def
_intenum_converter
(
value
,
enum_klass
):
"""Convert a numeric family value to an IntEnum member.
"""Convert a numeric family value to an IntEnum member.
...
@@ -269,7 +271,7 @@ class socket(_socket.socket):
...
@@ -269,7 +271,7 @@ class socket(_socket.socket):
def
type
(
self
):
def
type
(
self
):
"""Read-only access to the socket type.
"""Read-only access to the socket type.
"""
"""
return
_intenum_converter
(
super
()
.
type
,
Socket
Type
)
return
_intenum_converter
(
super
()
.
type
,
Socket
Kind
)
if
os
.
name
==
'nt'
:
if
os
.
name
==
'nt'
:
def
get_inheritable
(
self
):
def
get_inheritable
(
self
):
...
@@ -530,6 +532,6 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
...
@@ -530,6 +532,6 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
for
res
in
_socket
.
getaddrinfo
(
host
,
port
,
family
,
type
,
proto
,
flags
):
for
res
in
_socket
.
getaddrinfo
(
host
,
port
,
family
,
type
,
proto
,
flags
):
af
,
socktype
,
proto
,
canonname
,
sa
=
res
af
,
socktype
,
proto
,
canonname
,
sa
=
res
addrlist
.
append
((
_intenum_converter
(
af
,
AddressFamily
),
addrlist
.
append
((
_intenum_converter
(
af
,
AddressFamily
),
_intenum_converter
(
socktype
,
Socket
Type
),
_intenum_converter
(
socktype
,
Socket
Kind
),
proto
,
canonname
,
sa
))
proto
,
canonname
,
sa
))
return
addrlist
return
addrlist
Lib/test/test_socket.py
Dosyayı görüntüle @
7184bac5
...
@@ -649,6 +649,13 @@ def requireSocket(*args):
...
@@ -649,6 +649,13 @@ def requireSocket(*args):
class
GeneralModuleTests
(
unittest
.
TestCase
):
class
GeneralModuleTests
(
unittest
.
TestCase
):
def
test_SocketType_is_socketobject
(
self
):
import
_socket
self
.
assertTrue
(
socket
.
SocketType
is
_socket
.
socket
)
s
=
socket
.
socket
()
self
.
assertIsInstance
(
s
,
socket
.
SocketType
)
s
.
close
()
def
test_repr
(
self
):
def
test_repr
(
self
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
with
s
:
with
s
:
...
@@ -1224,7 +1231,7 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -1224,7 +1231,7 @@ class GeneralModuleTests(unittest.TestCase):
self
.
assertEqual
(
family
,
socket
.
AF_INET
)
self
.
assertEqual
(
family
,
socket
.
AF_INET
)
self
.
assertEqual
(
str
(
family
),
'AddressFamily.AF_INET'
)
self
.
assertEqual
(
str
(
family
),
'AddressFamily.AF_INET'
)
self
.
assertEqual
(
type
,
socket
.
SOCK_STREAM
)
self
.
assertEqual
(
type
,
socket
.
SOCK_STREAM
)
self
.
assertEqual
(
str
(
type
),
'Socket
Type
.SOCK_STREAM'
)
self
.
assertEqual
(
str
(
type
),
'Socket
Kind
.SOCK_STREAM'
)
infos
=
socket
.
getaddrinfo
(
HOST
,
None
,
0
,
socket
.
SOCK_STREAM
)
infos
=
socket
.
getaddrinfo
(
HOST
,
None
,
0
,
socket
.
SOCK_STREAM
)
for
_
,
socktype
,
_
,
_
,
_
in
infos
:
for
_
,
socktype
,
_
,
_
,
_
in
infos
:
self
.
assertEqual
(
socktype
,
socket
.
SOCK_STREAM
)
self
.
assertEqual
(
socktype
,
socket
.
SOCK_STREAM
)
...
@@ -1396,7 +1403,7 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -1396,7 +1403,7 @@ class GeneralModuleTests(unittest.TestCase):
# reprs.
# reprs.
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s
:
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s
:
self
.
assertEqual
(
str
(
s
.
family
),
'AddressFamily.AF_INET'
)
self
.
assertEqual
(
str
(
s
.
family
),
'AddressFamily.AF_INET'
)
self
.
assertEqual
(
str
(
s
.
type
),
'Socket
Type
.SOCK_STREAM'
)
self
.
assertEqual
(
str
(
s
.
type
),
'Socket
Kind
.SOCK_STREAM'
)
@unittest.skipIf
(
os
.
name
==
'nt'
,
'Will not work on Windows'
)
@unittest.skipIf
(
os
.
name
==
'nt'
,
'Will not work on Windows'
)
def
test_uknown_socket_family_repr
(
self
):
def
test_uknown_socket_family_repr
(
self
):
...
...
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