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
fe93faf9
Kaydet (Commit)
fe93faf9
authored
Mar 14, 2011
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #3080: Add PyImport_ImportModuleLevelObject() function
Use it for the builtin __import__ function.
üst
98dbba5d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
18 deletions
+41
-18
import.rst
Doc/c-api/import.rst
+8
-1
import.h
Include/import.h
+7
-0
bltinmodule.c
Python/bltinmodule.c
+4
-7
import.c
Python/import.c
+22
-10
No files found.
Doc/c-api/import.rst
Dosyayı görüntüle @
fe93faf9
...
@@ -57,7 +57,7 @@ Importing Modules
...
@@ -57,7 +57,7 @@ Importing Modules
:c:func:`PyImport_ImportModule`.
:c:func:`PyImport_ImportModule`.
.. c:function:: PyObject* PyImport_ImportModuleLevel
(char
*name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
.. c:function:: PyObject* PyImport_ImportModuleLevel
Object(PyObject
*name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
Import a module. This is best described by referring to the built-in Python
Import a module. This is best described by referring to the built-in Python
function :func:`__import__`, as the standard :func:`__import__` function calls
function :func:`__import__`, as the standard :func:`__import__` function calls
...
@@ -68,6 +68,13 @@ Importing Modules
...
@@ -68,6 +68,13 @@ Importing Modules
the return value when a submodule of a package was requested is normally the
the return value when a submodule of a package was requested is normally the
top-level package, unless a non-empty *fromlist* was given.
top-level package, unless a non-empty *fromlist* was given.
.. versionadded:: 3.3
.. c:function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is an
UTF-8 encoded string instead of a Unicode object.
.. c:function:: PyObject* PyImport_Import(PyObject *name)
.. c:function:: PyObject* PyImport_Import(PyObject *name)
...
...
Include/import.h
Dosyayı görüntüle @
fe93faf9
...
@@ -50,6 +50,13 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
...
@@ -50,6 +50,13 @@ PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
PyObject
*
fromlist
,
PyObject
*
fromlist
,
int
level
int
level
);
);
PyAPI_FUNC
(
PyObject
*
)
PyImport_ImportModuleLevelObject
(
PyObject
*
name
,
PyObject
*
globals
,
PyObject
*
locals
,
PyObject
*
fromlist
,
int
level
);
#define PyImport_ImportModuleEx(n, g, l, f) \
#define PyImport_ImportModuleEx(n, g, l, f) \
PyImport_ImportModuleLevel(n, g, l, f, -1)
PyImport_ImportModuleLevel(n, g, l, f, -1)
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
fe93faf9
...
@@ -155,17 +155,14 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
...
@@ -155,17 +155,14 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
{
{
static
char
*
kwlist
[]
=
{
"name"
,
"globals"
,
"locals"
,
"fromlist"
,
static
char
*
kwlist
[]
=
{
"name"
,
"globals"
,
"locals"
,
"fromlist"
,
"level"
,
0
};
"level"
,
0
};
char
*
name
;
PyObject
*
name
,
*
globals
=
NULL
,
*
locals
=
NULL
,
*
fromlist
=
NULL
;
PyObject
*
globals
=
NULL
;
PyObject
*
locals
=
NULL
;
PyObject
*
fromlist
=
NULL
;
int
level
=
-
1
;
int
level
=
-
1
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"
s
|OOOi:__import__"
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"
U
|OOOi:__import__"
,
kwlist
,
&
name
,
&
globals
,
&
locals
,
&
fromlist
,
&
level
))
kwlist
,
&
name
,
&
globals
,
&
locals
,
&
fromlist
,
&
level
))
return
NULL
;
return
NULL
;
return
PyImport_ImportModuleLevel
(
name
,
globals
,
locals
,
return
PyImport_ImportModuleLevel
Object
(
name
,
globals
,
locals
,
fromlist
,
level
);
fromlist
,
level
);
}
}
PyDoc_STRVAR
(
import_doc
,
PyDoc_STRVAR
(
import_doc
,
...
...
Python/import.c
Dosyayı görüntüle @
fe93faf9
...
@@ -2753,25 +2753,37 @@ import_module_level(PyObject *name, PyObject *globals, PyObject *locals,
...
@@ -2753,25 +2753,37 @@ import_module_level(PyObject *name, PyObject *globals, PyObject *locals,
}
}
PyObject
*
PyObject
*
PyImport_ImportModuleLevel
(
char
*
name
,
PyObject
*
globals
,
PyObject
*
locals
,
PyImport_ImportModuleLevelObject
(
PyObject
*
name
,
PyObject
*
globals
,
PyObject
*
fromlist
,
int
level
)
PyObject
*
locals
,
PyObject
*
fromlist
,
int
level
)
{
{
PyObject
*
nameobj
,
*
result
;
PyObject
*
mod
;
nameobj
=
PyUnicode_FromString
(
name
);
if
(
nameobj
==
NULL
)
return
NULL
;
_PyImport_AcquireLock
();
_PyImport_AcquireLock
();
result
=
import_module_level
(
nameobj
,
globals
,
locals
,
fromlist
,
level
);
mod
=
import_module_level
(
name
,
globals
,
locals
,
fromlist
,
level
);
Py_DECREF
(
nameobj
);
if
(
_PyImport_ReleaseLock
()
<
0
)
{
if
(
_PyImport_ReleaseLock
()
<
0
)
{
Py_XDECREF
(
result
);
Py_XDECREF
(
mod
);
PyErr_SetString
(
PyExc_RuntimeError
,
PyErr_SetString
(
PyExc_RuntimeError
,
"not holding the import lock"
);
"not holding the import lock"
);
return
NULL
;
return
NULL
;
}
}
return
result
;
return
mod
;
}
PyObject
*
PyImport_ImportModuleLevel
(
char
*
name
,
PyObject
*
globals
,
PyObject
*
locals
,
PyObject
*
fromlist
,
int
level
)
{
PyObject
*
nameobj
,
*
mod
;
nameobj
=
PyUnicode_FromString
(
name
);
if
(
nameobj
==
NULL
)
return
NULL
;
mod
=
PyImport_ImportModuleLevelObject
(
nameobj
,
globals
,
locals
,
fromlist
,
level
);
Py_DECREF
(
nameobj
);
return
mod
;
}
}
/* Return the package that an import is being performed in. If globals comes
/* Return the package that an import is being performed in. If globals comes
from the module foo.bar.bat (not itself a package), this returns the
from the module foo.bar.bat (not itself a package), this returns the
sys.modules entry for foo.bar. If globals is from a package's __init__.py,
sys.modules entry for foo.bar. If globals is from a package's __init__.py,
...
...
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