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
0c6774d9
Kaydet (Commit)
0c6774d9
authored
Ock 15, 2003
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #661719: Expose compilation errors as exceptions on request.
üst
d69663d3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
28 deletions
+92
-28
libpycompile.tex
Doc/lib/libpycompile.tex
+7
-2
compileall.py
Lib/compileall.py
+3
-8
py_compile.py
Lib/py_compile.py
+75
-17
zipfile.py
Lib/zipfile.py
+4
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libpycompile.tex
Dosyayı görüntüle @
0c6774d9
...
...
@@ -19,17 +19,22 @@ modules for shared use, especially if some of the users may not have
permission to write the byte-code cache files in the directory
containing the source code.
\begin{excdesc}
{
PyCompileError
}
Exception raised when an error occurs while attempting to compile the file.
\end{excdesc}
\begin{funcdesc}
{
compile
}{
file
\optional
{
, cfile
\optional
{
, dfile
}}}
\begin{funcdesc}
{
compile
}{
file
\optional
{
, cfile
\optional
{
, dfile
\optional
{
, doraise
}
}}}
Compile a source file to byte-code and write out the byte-code cache
file. The source code is loaded from the file name
\var
{
file
}
. The
byte-code is written to
\var
{
cfile
}
, which defaults to
\var
{
file
}
\code
{
+
}
\code
{
'c'
}
(
\code
{
'o'
}
if optimization is enabled in the
current interpreter). If
\var
{
dfile
}
is specified, it is used as
the name of the source file in error messages instead of
\var
{
file
}
.
If
\var
{
doraise
}
= True, a PyCompileError is raised when an error is
encountered while compiling
\var
{
file
}
. If
\var
{
doraise
}
= False (the default),
an error string is written to sys.stderr, but no exception is raised.
\end{funcdesc}
\begin{funcdesc}
{
main
}{
\optional
{
args
}}
Compile several source files. The files named in
\var
{
args
}
(or on
the command line, if
\var
{
args
}
is not specified) are compiled and
...
...
Lib/compileall.py
Dosyayı görüntüle @
0c6774d9
...
...
@@ -62,16 +62,11 @@ def compile_dir(dir, maxlevels=10, ddir=None,
if
not
quiet
:
print
'Compiling'
,
fullname
,
'...'
try
:
ok
=
py_compile
.
compile
(
fullname
,
None
,
dfile
)
ok
=
py_compile
.
compile
(
fullname
,
None
,
dfile
,
True
)
except
KeyboardInterrupt
:
raise
KeyboardInterrupt
except
:
# XXX py_compile catches SyntaxErrors
if
type
(
sys
.
exc_type
)
==
type
(
''
):
exc_type_name
=
sys
.
exc_type
else
:
exc_type_name
=
sys
.
exc_type
.
__name__
print
'Sorry:'
,
exc_type_name
+
':'
,
print
sys
.
exc_value
except
py_compile
.
PyCompileError
,
err
:
print
err
.
msg
success
=
0
else
:
if
ok
==
0
:
...
...
Lib/py_compile.py
Dosyayı görüntüle @
0c6774d9
...
...
@@ -12,7 +12,54 @@ import traceback
MAGIC
=
imp
.
get_magic
()
__all__
=
[
"compile"
,
"main"
]
__all__
=
[
"compile"
,
"main"
,
"PyCompileError"
]
class
PyCompileError
(
Exception
):
"""Exception raised when an error occurs while attempting to
compile the file.
To raise this exception, use
raise PyCompileError(exc_type,exc_value,file[,msg])
where
exc_type: exception type to be used in error message
type name can be accesses as class variable
'exc_type_name'
exc_value: exception value to be used in error message
can be accesses as class variable 'exc_value'
file: name of file being compiled to be used in error message
can be accesses as class variable 'file'
msg: string message to be written as error message
If no value is given, a default exception message will be given,
consistent with 'standard' py_compile output.
message (or default) can be accesses as class variable 'msg'
"""
def
__init__
(
self
,
exc_type
,
exc_value
,
file
,
msg
=
''
):
exc_type_name
=
exc_type
.
__name__
if
exc_type
is
SyntaxError
:
tbtext
=
''
.
join
(
traceback
.
format_exception_only
(
exc_type
,
exc_value
))
errmsg
=
tbtext
.
replace
(
'File "<string>"'
,
'File "
%
s"'
%
file
)
else
:
errmsg
=
"Sorry:
%
s:
%
s"
%
(
exc_type_name
,
exc_value
)
Exception
.
__init__
(
self
,
msg
or
errmsg
,
exc_type_name
,
exc_value
,
file
)
self
.
exc_type_name
=
exc_type_name
self
.
exc_value
=
exc_value
self
.
file
=
file
self
.
msg
=
msg
or
errmsg
def
__str__
(
self
):
return
self
.
msg
# Define an internal helper according to the platform
if
os
.
name
==
"mac"
:
...
...
@@ -30,17 +77,24 @@ def wr_long(f, x):
f
.
write
(
chr
((
x
>>
16
)
&
0xff
))
f
.
write
(
chr
((
x
>>
24
)
&
0xff
))
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
):
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
,
doraise
=
False
):
"""Byte-compile one Python source file to Python bytecode.
Arguments:
file: source filename
cfile: target filename; defaults to source with 'c' or 'o' appended
('c' normally, 'o' in optimizing mode, giving .pyc or .pyo)
dfile: purported filename; defaults to source (this is the filename
that will show up in error messages)
file: source filename
cfile: target filename; defaults to source with 'c' or 'o' appended
('c' normally, 'o' in optimizing mode, giving .pyc or .pyo)
dfile: purported filename; defaults to source (this is the filename
that will show up in error messages)
doraise: flag indicating whether or not an exception should be
raised when a compile error is found. If an exception
occurs and this flag is set to False, a string
indicating the nature of the exception will be printed,
and the function will return to the caller. If an
exception occurs and this flag is set to True, a
PyCompileError exception will be raised.
Note that it isn't necessary to byte-compile Python modules for
execution efficiency -- Python itself byte-compiles a module when
it is loaded, and if it can, writes out the bytecode to the
...
...
@@ -68,13 +122,14 @@ def compile(file, cfile=None, dfile=None):
if
codestring
and
codestring
[
-
1
]
!=
'
\n
'
:
codestring
=
codestring
+
'
\n
'
try
:
codeobject
=
__builtin__
.
compile
(
codestring
,
dfile
or
file
,
'exec'
)
except
SyntaxError
,
detail
:
lines
=
traceback
.
format_exception_only
(
SyntaxError
,
detail
)
for
line
in
lines
:
sys
.
stderr
.
write
(
line
.
replace
(
'File "<string>"'
,
'File "
%
s"'
%
(
dfile
or
file
)))
return
codeobject
=
__builtin__
.
compile
(
codestring
,
dfile
or
file
,
'exec'
)
except
Exception
,
err
:
py_exc
=
PyCompileError
(
err
.
__class__
,
err
.
args
,
dfile
or
file
)
if
doraise
:
raise
py_exc
else
:
sys
.
stderr
.
write
(
py_exc
.
msg
)
return
if
cfile
is
None
:
cfile
=
file
+
(
__debug__
and
'c'
or
'o'
)
fc
=
open
(
cfile
,
'wb'
)
...
...
@@ -100,7 +155,10 @@ def main(args=None):
if
args
is
None
:
args
=
sys
.
argv
[
1
:]
for
filename
in
args
:
compile
(
filename
)
try
:
compile
(
filename
,
doraise
=
True
)
except
PyCompileError
,
err
:
sys
.
stderr
.
write
(
err
.
msg
)
if
__name__
==
"__main__"
:
main
()
Lib/zipfile.py
Dosyayı görüntüle @
0c6774d9
...
...
@@ -604,7 +604,10 @@ class PyZipFile(ZipFile):
import
py_compile
if
self
.
debug
:
print
"Compiling"
,
file_py
py_compile
.
compile
(
file_py
,
file_pyc
)
try
:
py_compile
.
compile
(
file_py
,
file_pyc
,
None
,
True
)
except
py_compile
.
PyCompileError
,
err
:
print
err
.
msg
fname
=
file_pyc
else
:
fname
=
file_pyc
...
...
Misc/NEWS
Dosyayı görüntüle @
0c6774d9
...
...
@@ -78,6 +78,9 @@ Extension modules
Library
-------
- py_compile has a new '
doraise
' flag and a new PyCompileError
exception.
- SimpleXMLRPCServer now supports CGI through the CGIXMLRPCRequestHandler
class.
...
...
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