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
061cfb52
Kaydet (Commit)
061cfb52
authored
Şub 28, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
üst
8d0f2572
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
12 deletions
+82
-12
socket.rst
Doc/library/socket.rst
+10
-0
test_socket.py
Lib/test/test_socket.py
+20
-0
NEWS
Misc/NEWS
+2
-0
socketmodule.c
Modules/socketmodule.c
+35
-0
configure
configure
+2
-2
configure.in
configure.in
+1
-1
pyconfig.h.in
pyconfig.h.in
+12
-9
No files found.
Doc/library/socket.rst
Dosyayı görüntüle @
061cfb52
...
@@ -521,6 +521,16 @@ The module :mod:`socket` exports the following constants and functions:
...
@@ -521,6 +521,16 @@ The module :mod:`socket` exports the following constants and functions:
meanings.
meanings.
.. function:: sethostname(name)
Set the machine's hostname to *name*. This will raise a
:exc:`socket.error` if you don't have enough rights.
Availability: Unix.
.. versionadded:: 3.3
.. data:: SocketType
.. data:: SocketType
This is a Python type object that represents the socket object type. It is the
This is a Python type object that represents the socket object type. It is the
...
...
Lib/test/test_socket.py
Dosyayı görüntüle @
061cfb52
...
@@ -325,6 +325,26 @@ class GeneralModuleTests(unittest.TestCase):
...
@@ -325,6 +325,26 @@ class GeneralModuleTests(unittest.TestCase):
if
not
fqhn
in
all_host_names
:
if
not
fqhn
in
all_host_names
:
self
.
fail
(
"Error testing host resolution mechanisms. (fqdn:
%
s, all:
%
s)"
%
(
fqhn
,
repr
(
all_host_names
)))
self
.
fail
(
"Error testing host resolution mechanisms. (fqdn:
%
s, all:
%
s)"
%
(
fqhn
,
repr
(
all_host_names
)))
@unittest.skipUnless
(
hasattr
(
socket
,
'sethostname'
),
"test needs socket.sethostname()"
)
@unittest.skipUnless
(
hasattr
(
socket
,
'gethostname'
),
"test needs socket.gethostname()"
)
def
test_sethostname
(
self
):
oldhn
=
socket
.
gethostname
()
try
:
socket
.
sethostname
(
'new'
)
except
socket
.
error
as
e
:
if
e
.
errno
==
errno
.
EPERM
:
self
.
skipTest
(
"test should be run as root"
)
else
:
raise
try
:
# running test as root!
self
.
assertEqual
(
socket
.
gethostname
(),
'new'
)
# Should work with bytes objects too
socket
.
sethostname
(
b
'bar'
)
self
.
assertEqual
(
socket
.
gethostname
(),
'bar'
)
finally
:
socket
.
sethostname
(
oldhn
)
def
testRefCountGetNameInfo
(
self
):
def
testRefCountGetNameInfo
(
self
):
# Testing reference count for getnameinfo
# Testing reference count for getnameinfo
if
hasattr
(
sys
,
"getrefcount"
):
if
hasattr
(
sys
,
"getrefcount"
):
...
...
Misc/NEWS
Dosyayı görüntüle @
061cfb52
...
@@ -35,6 +35,8 @@ Core and Builtins
...
@@ -35,6 +35,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
- Issue #11140: Lock.release() now raises a RuntimeError when attempting
- Issue #11140: Lock.release() now raises a RuntimeError when attempting
to release an unacquired lock, as claimed in the threading documentation.
to release an unacquired lock, as claimed in the threading documentation.
The _thread.error exception is now an alias of RuntimeError. Patch by
The _thread.error exception is now an alias of RuntimeError. Patch by
...
...
Modules/socketmodule.c
Dosyayı görüntüle @
061cfb52
...
@@ -3135,6 +3135,37 @@ PyDoc_STRVAR(gethostname_doc,
...
@@ -3135,6 +3135,37 @@ PyDoc_STRVAR(gethostname_doc,
\n
\
\n
\
Return the current host name."
);
Return the current host name."
);
#ifdef HAVE_SETHOSTNAME
PyDoc_STRVAR
(
sethostname_doc
,
"sethostname(name)
\n\n
\
Sets the hostname to name."
);
static
PyObject
*
socket_sethostname
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
hnobj
;
Py_buffer
buf
;
int
res
,
flag
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"S:sethostname"
,
&
hnobj
))
{
PyErr_Clear
();
if
(
!
PyArg_ParseTuple
(
args
,
"O&:sethostname"
,
PyUnicode_FSConverter
,
&
hnobj
))
return
NULL
;
flag
=
1
;
}
res
=
PyObject_GetBuffer
(
hnobj
,
&
buf
,
PyBUF_SIMPLE
);
if
(
!
res
)
{
res
=
sethostname
(
buf
.
buf
,
buf
.
len
);
PyBuffer_Release
(
&
buf
);
}
if
(
flag
)
Py_DECREF
(
hnobj
);
if
(
res
)
return
set_error
();
Py_RETURN_NONE
;
}
#endif
/* Python interface to gethostbyname(name). */
/* Python interface to gethostbyname(name). */
...
@@ -4233,6 +4264,10 @@ static PyMethodDef socket_methods[] = {
...
@@ -4233,6 +4264,10 @@ static PyMethodDef socket_methods[] = {
METH_VARARGS
,
gethostbyaddr_doc
},
METH_VARARGS
,
gethostbyaddr_doc
},
{
"gethostname"
,
socket_gethostname
,
{
"gethostname"
,
socket_gethostname
,
METH_NOARGS
,
gethostname_doc
},
METH_NOARGS
,
gethostname_doc
},
#ifdef HAVE_SETHOSTNAME
{
"sethostname"
,
socket_sethostname
,
METH_VARARGS
,
sethostname_doc
},
#endif
{
"getservbyname"
,
socket_getservbyname
,
{
"getservbyname"
,
socket_getservbyname
,
METH_VARARGS
,
getservbyname_doc
},
METH_VARARGS
,
getservbyname_doc
},
{
"getservbyport"
,
socket_getservbyport
,
{
"getservbyport"
,
socket_getservbyport
,
...
...
configure
Dosyayı görüntüle @
061cfb52
#! /bin/sh
#! /bin/sh
# From configure.in Revision: 8862
4
.
# From configure.in Revision: 8862
5
.
# Guess values for system-dependent variables and create Makefiles.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for python 3.3.
# Generated by GNU Autoconf 2.65 for python 3.3.
#
#
...
@@ -9319,7 +9319,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
...
@@ -9319,7 +9319,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
mkfifoat
mknod
mknodat mktime mremap
nice
openat pathconf pause plock poll
\
mkfifoat
mknod
mknodat mktime mremap
nice
openat pathconf pause plock poll
\
pthread_init putenv
readlink
readlinkat
realpath
renameat
\
pthread_init putenv
readlink
readlinkat
realpath
renameat
\
select
sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid
\
select
sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid
\
setgid
\
setgid
sethostname
\
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf
\
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf
\
sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat
\
sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat
\
sysconf tcgetpgrp tcsetpgrp tempnam timegm
times
tmpfile tmpnam tmpnam_r
\
sysconf tcgetpgrp tcsetpgrp tempnam timegm
times
tmpfile tmpnam tmpnam_r
\
...
...
configure.in
Dosyayı görüntüle @
061cfb52
...
@@ -2542,7 +2542,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
...
@@ -2542,7 +2542,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause plock poll \
pthread_init putenv readlink readlinkat realpath renameat \
pthread_init putenv readlink readlinkat realpath renameat \
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
setgid \
setgid
sethostname
\
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat \
sigaction siginterrupt sigrelse snprintf strftime strlcpy symlinkat \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
...
...
pyconfig.h.in
Dosyayı görüntüle @
061cfb52
...
@@ -443,6 +443,9 @@
...
@@ -443,6 +443,9 @@
/* Define to 1 if you have the `resolv' library (-lresolv). */
/* Define to 1 if you have the `resolv' library (-lresolv). */
#undef HAVE_LIBRESOLV
#undef HAVE_LIBRESOLV
/* Define to 1 if you have the `sendfile' library (-lsendfile). */
#undef HAVE_LIBSENDFILE
/* Define to 1 if you have the <libutil.h> header file. */
/* Define to 1 if you have the <libutil.h> header file. */
#undef HAVE_LIBUTIL_H
#undef HAVE_LIBUTIL_H
...
@@ -533,12 +536,6 @@
...
@@ -533,12 +536,6 @@
/* Define if the OS supports pipe2() */
/* Define if the OS supports pipe2() */
#undef HAVE_PIPE2
#undef HAVE_PIPE2
/* Define if the OS supports pipe2() */
#undef HAVE_PIPE2
/* Define if the OS supports pipe2() */
#undef HAVE_PIPE2
/* Define to 1 if you have the `plock' function. */
/* Define to 1 if you have the `plock' function. */
#undef HAVE_PLOCK
#undef HAVE_PLOCK
...
@@ -623,6 +620,9 @@
...
@@ -623,6 +620,9 @@
/* Define to 1 if you have the `sem_unlink' function. */
/* Define to 1 if you have the `sem_unlink' function. */
#undef HAVE_SEM_UNLINK
#undef HAVE_SEM_UNLINK
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
/* Define to 1 if you have the `setegid' function. */
/* Define to 1 if you have the `setegid' function. */
#undef HAVE_SETEGID
#undef HAVE_SETEGID
...
@@ -635,6 +635,9 @@
...
@@ -635,6 +635,9 @@
/* Define if you have the 'setgroups' function. */
/* Define if you have the 'setgroups' function. */
#undef HAVE_SETGROUPS
#undef HAVE_SETGROUPS
/* Define to 1 if you have the `sethostname' function. */
#undef HAVE_SETHOSTNAME
/* Define to 1 if you have the `setitimer' function. */
/* Define to 1 if you have the `setitimer' function. */
#undef HAVE_SETITIMER
#undef HAVE_SETITIMER
...
@@ -849,6 +852,9 @@
...
@@ -849,6 +852,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/uio.h> header file. */
#undef HAVE_SYS_UIO_H
/* Define to 1 if you have the <sys/un.h> header file. */
/* Define to 1 if you have the <sys/un.h> header file. */
#undef HAVE_SYS_UN_H
#undef HAVE_SYS_UN_H
...
@@ -1084,9 +1090,6 @@
...
@@ -1084,9 +1090,6 @@
/* The size of `size_t', as computed by sizeof. */
/* The size of `size_t', as computed by sizeof. */
#undef SIZEOF_SIZE_T
#undef SIZEOF_SIZE_T
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
/* The size of `time_t', as computed by sizeof. */
/* The size of `time_t', as computed by sizeof. */
#undef SIZEOF_TIME_T
#undef SIZEOF_TIME_T
...
...
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