Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
54584234
Commit
54584234
authored
Nov 07, 2011
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging: replace codecs.open with builtins.open, remove '_encoded' sort, add some tests.
parent
0c1b7496
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
35 deletions
+25
-35
Lib/logging/__init__.py
Lib/logging/__init__.py
+1
-12
Lib/logging/config.py
Lib/logging/config.py
+4
-8
Lib/logging/handlers.py
Lib/logging/handlers.py
+2
-10
Lib/test/test_logging.py
Lib/test/test_logging.py
+18
-5
No files found.
Lib/logging/__init__.py
View file @
54584234
...
@@ -35,11 +35,6 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
...
@@ -35,11 +35,6 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'info'
,
'log'
,
'makeLogRecord'
,
'setLoggerClass'
,
'warn'
,
'warning'
,
'info'
,
'log'
,
'makeLogRecord'
,
'setLoggerClass'
,
'warn'
,
'warning'
,
'getLogRecordFactory'
,
'setLogRecordFactory'
,
'lastResort'
]
'getLogRecordFactory'
,
'setLogRecordFactory'
,
'lastResort'
]
try
:
import
codecs
except
ImportError
:
#pragma: no cover
codecs
=
None
try
:
try
:
import
threading
import
threading
except
ImportError
:
#pragma: no cover
except
ImportError
:
#pragma: no cover
...
@@ -954,8 +949,6 @@ class FileHandler(StreamHandler):
...
@@ -954,8 +949,6 @@ class FileHandler(StreamHandler):
"""
"""
#keep the absolute path, otherwise derived classes which use this
#keep the absolute path, otherwise derived classes which use this
#may come a cropper when the current directory changes
#may come a cropper when the current directory changes
if
codecs
is
None
:
#pragma: no cover
encoding
=
None
self
.
baseFilename
=
os
.
path
.
abspath
(
filename
)
self
.
baseFilename
=
os
.
path
.
abspath
(
filename
)
self
.
mode
=
mode
self
.
mode
=
mode
self
.
encoding
=
encoding
self
.
encoding
=
encoding
...
@@ -983,11 +976,7 @@ class FileHandler(StreamHandler):
...
@@ -983,11 +976,7 @@ class FileHandler(StreamHandler):
Open the current base file with the (original) mode and encoding.
Open the current base file with the (original) mode and encoding.
Return the resulting stream.
Return the resulting stream.
"""
"""
if
self
.
encoding
is
None
:
return
open
(
self
.
baseFilename
,
self
.
mode
,
encoding
=
self
.
encoding
)
stream
=
open
(
self
.
baseFilename
,
self
.
mode
)
else
:
stream
=
codecs
.
open
(
self
.
baseFilename
,
self
.
mode
,
self
.
encoding
)
return
stream
def
emit
(
self
,
record
):
def
emit
(
self
,
record
):
"""
"""
...
...
Lib/logging/config.py
View file @
54584234
...
@@ -24,8 +24,8 @@ Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
...
@@ -24,8 +24,8 @@ Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
To use, simply 'import logging' and log away!
"""
"""
import
sys
,
logging
,
logging
.
handlers
,
socket
,
struct
,
os
,
traceback
,
re
import
sys
,
logging
,
logging
.
handlers
,
socket
,
struct
,
traceback
,
re
import
types
,
io
import
io
try
:
try
:
import
_thread
as
thread
import
_thread
as
thread
...
@@ -98,9 +98,6 @@ def _resolve(name):
...
@@ -98,9 +98,6 @@ def _resolve(name):
def
_strip_spaces
(
alist
):
def
_strip_spaces
(
alist
):
return
map
(
lambda
x
:
x
.
strip
(),
alist
)
return
map
(
lambda
x
:
x
.
strip
(),
alist
)
def
_encoded
(
s
):
return
s
if
isinstance
(
s
,
str
)
else
s
.
encode
(
'utf-8'
)
def
_create_formatters
(
cp
):
def
_create_formatters
(
cp
):
"""Create and return formatters"""
"""Create and return formatters"""
flist
=
cp
[
"formatters"
][
"keys"
]
flist
=
cp
[
"formatters"
][
"keys"
]
...
@@ -215,7 +212,7 @@ def _install_loggers(cp, handlers, disable_existing):
...
@@ -215,7 +212,7 @@ def _install_loggers(cp, handlers, disable_existing):
#avoid disabling child loggers of explicitly
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#named loggers. With a sorted list it is easier
#to find the child loggers.
#to find the child loggers.
existing
.
sort
(
key
=
_encoded
)
existing
.
sort
()
#We'll keep the list of existing loggers
#We'll keep the list of existing loggers
#which are children of named loggers here...
#which are children of named loggers here...
child_loggers
=
[]
child_loggers
=
[]
...
@@ -588,7 +585,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -588,7 +585,7 @@ class DictConfigurator(BaseConfigurator):
#avoid disabling child loggers of explicitly
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#named loggers. With a sorted list it is easier
#to find the child loggers.
#to find the child loggers.
existing.sort(
key=_encoded
)
existing.sort()
#We'll keep the list of existing loggers
#We'll keep the list of existing loggers
#which are children of named loggers here...
#which are children of named loggers here...
child_loggers = []
child_loggers = []
...
@@ -804,7 +801,6 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
...
@@ -804,7 +801,6 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
struct.pack("
>
L
", n), followed by the config file.
struct.pack("
>
L
", n), followed by the config file.
Uses fileConfig() to do the grunt work.
Uses fileConfig() to do the grunt work.
"""
"""
import tempfile
try:
try:
conn = self.connection
conn = self.connection
chunk = conn.recv(4)
chunk = conn.recv(4)
...
...
Lib/logging/handlers.py
View file @
54584234
...
@@ -25,6 +25,7 @@ To use, simply 'import logging.handlers' and log away!
...
@@ -25,6 +25,7 @@ To use, simply 'import logging.handlers' and log away!
"""
"""
import
logging
,
socket
,
os
,
pickle
,
struct
,
time
,
re
import
logging
,
socket
,
os
,
pickle
,
struct
,
time
,
re
from
codecs
import
BOM_UTF8
from
stat
import
ST_DEV
,
ST_INO
,
ST_MTIME
from
stat
import
ST_DEV
,
ST_INO
,
ST_MTIME
import
queue
import
queue
try
:
try
:
...
@@ -32,11 +33,6 @@ try:
...
@@ -32,11 +33,6 @@ try:
except
ImportError
:
#pragma: no cover
except
ImportError
:
#pragma: no cover
threading
=
None
threading
=
None
try
:
import
codecs
except
ImportError
:
#pragma: no cover
codecs
=
None
#
#
# Some constants...
# Some constants...
#
#
...
@@ -60,8 +56,6 @@ class BaseRotatingHandler(logging.FileHandler):
...
@@ -60,8 +56,6 @@ class BaseRotatingHandler(logging.FileHandler):
"""
"""
Use the specified filename for streamed logging
Use the specified filename for streamed logging
"""
"""
if
codecs
is
None
:
#pragma: no cover
encoding
=
None
logging
.
FileHandler
.
__init__
(
self
,
filename
,
mode
,
encoding
,
delay
)
logging
.
FileHandler
.
__init__
(
self
,
filename
,
mode
,
encoding
,
delay
)
self
.
mode
=
mode
self
.
mode
=
mode
self
.
encoding
=
encoding
self
.
encoding
=
encoding
...
@@ -793,9 +787,7 @@ class SysLogHandler(logging.Handler):
...
@@ -793,9 +787,7 @@ class SysLogHandler(logging.Handler):
prio
=
prio
.
encode
(
'utf-8'
)
prio
=
prio
.
encode
(
'utf-8'
)
# Message is a string. Convert to bytes as required by RFC 5424
# Message is a string. Convert to bytes as required by RFC 5424
msg
=
msg
.
encode
(
'utf-8'
)
msg
=
msg
.
encode
(
'utf-8'
)
if
codecs
:
msg
=
prio
+
BOM_UTF8
+
msg
msg
=
codecs
.
BOM_UTF8
+
msg
msg
=
prio
+
msg
try
:
try
:
if
self
.
unixsocket
:
if
self
.
unixsocket
:
try
:
try
:
...
...
Lib/test/test_logging.py
View file @
54584234
...
@@ -49,6 +49,7 @@ import weakref
...
@@ -49,6 +49,7 @@ import weakref
try
:
try
:
import
threading
import
threading
# The following imports are needed only for tests which
# The following imports are needed only for tests which
# require threading
import
asynchat
import
asynchat
import
asyncore
import
asyncore
import
errno
import
errno
...
@@ -95,9 +96,7 @@ class BaseTest(unittest.TestCase):
...
@@ -95,9 +96,7 @@ class BaseTest(unittest.TestCase):
finally:
finally:
logging._releaseLock()
logging._releaseLock()
# Set two unused loggers: one non-ASCII and one Unicode.
# Set two unused loggers
# This is to test correct operation when sorting existing
# loggers in the configuration code. See issue 8201.
self.logger1 = logging.getLogger("
\
xab
\
xd7
\
xbb
")
self.logger1 = logging.getLogger("
\
xab
\
xd7
\
xbb
")
self.logger2 = logging.getLogger("
\
u013f
\
u00d6
\
u0047
")
self.logger2 = logging.getLogger("
\
u013f
\
u00d6
\
u0047
")
...
@@ -310,8 +309,6 @@ class BuiltinLevelsTest(BaseTest):
...
@@ -310,8 +309,6 @@ class BuiltinLevelsTest(BaseTest):
('INF.BADPARENT', 'INFO', '4'),
('INF.BADPARENT', 'INFO', '4'),
])
])
def test_invalid_name(self):
self.assertRaises(TypeError, logging.getLogger, any)
class BasicFilterTest(BaseTest):
class BasicFilterTest(BaseTest):
...
@@ -3514,6 +3511,22 @@ class LoggerTest(BaseTest):
...
@@ -3514,6 +3511,22 @@ class LoggerTest(BaseTest):
self.addCleanup(setattr, self.logger.manager, 'disable', old_disable)
self.addCleanup(setattr, self.logger.manager, 'disable', old_disable)
self.assertFalse(self.logger.isEnabledFor(22))
self.assertFalse(self.logger.isEnabledFor(22))
def test_root_logger_aliases(self):
root = logging.getLogger()
self.assertIs(root, logging.root)
self.assertIs(root, logging.getLogger(None))
self.assertIs(root, logging.getLogger(''))
self.assertIs(root, logging.getLogger('foo').root)
self.assertIs(root, logging.getLogger('foo.bar').root)
self.assertIs(root, logging.getLogger('foo').parent)
self.assertIsNot(root, logging.getLogger('
\
0
'))
self.assertIsNot(root, logging.getLogger('foo.bar').parent)
def test_invalid_names(self):
self.assertRaises(TypeError, logging.getLogger, any)
self.assertRaises(TypeError, logging.getLogger, b'foo')
class BaseFileTest(BaseTest):
class BaseFileTest(BaseTest):
"
Base
class
for
handler
tests
that
write
log
files
"
"
Base
class
for
handler
tests
that
write
log
files
"
...
...
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