summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2011-11-07 18:43:05 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2011-11-07 18:43:05 (GMT)
commit5252f9faee97573f5b8ff37d7c22225e5df6cc0b (patch)
tree780ab582475f423f45005bb673623e3e007e7716 /Lib/logging
parent1cdbf57c7cabaa0451cfcf04583f31c9a7eab38d (diff)
downloadcpython-5252f9faee97573f5b8ff37d7c22225e5df6cc0b.zip
cpython-5252f9faee97573f5b8ff37d7c22225e5df6cc0b.tar.gz
cpython-5252f9faee97573f5b8ff37d7c22225e5df6cc0b.tar.bz2
logging: replace codecs.open with builtins.open, remove '_encoded' sort, add some tests.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py13
-rw-r--r--Lib/logging/config.py12
-rw-r--r--Lib/logging/handlers.py12
3 files changed, 7 insertions, 30 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 988cbed..25acb3f 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -36,11 +36,6 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'getLogRecordFactory', 'setLogRecordFactory', 'lastResort']
try:
- import codecs
-except ImportError: #pragma: no cover
- codecs = None
-
-try:
import threading
except ImportError: #pragma: no cover
threading = None
@@ -954,8 +949,6 @@ class FileHandler(StreamHandler):
"""
#keep the absolute path, otherwise derived classes which use this
#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.mode = mode
self.encoding = encoding
@@ -983,11 +976,7 @@ class FileHandler(StreamHandler):
Open the current base file with the (original) mode and encoding.
Return the resulting stream.
"""
- if self.encoding is None:
- stream = open(self.baseFilename, self.mode)
- else:
- stream = codecs.open(self.baseFilename, self.mode, self.encoding)
- return stream
+ return open(self.baseFilename, self.mode, encoding=self.encoding)
def emit(self, record):
"""
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index e183e74..5ef5c91 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -24,8 +24,8 @@ Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
-import sys, logging, logging.handlers, socket, struct, os, traceback, re
-import types, io
+import sys, logging, logging.handlers, socket, struct, traceback, re
+import io
try:
import _thread as thread
@@ -98,9 +98,6 @@ def _resolve(name):
def _strip_spaces(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):
"""Create and return formatters"""
flist = cp["formatters"]["keys"]
@@ -215,7 +212,7 @@ def _install_loggers(cp, handlers, disable_existing):
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#to find the child loggers.
- existing.sort(key=_encoded)
+ existing.sort()
#We'll keep the list of existing loggers
#which are children of named loggers here...
child_loggers = []
@@ -588,7 +585,7 @@ class DictConfigurator(BaseConfigurator):
#avoid disabling child loggers of explicitly
#named loggers. With a sorted list it is easier
#to find the child loggers.
- existing.sort(key=_encoded)
+ existing.sort()
#We'll keep the list of existing loggers
#which are children of named loggers here...
child_loggers = []
@@ -804,7 +801,6 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
struct.pack(">L", n), followed by the config file.
Uses fileConfig() to do the grunt work.
"""
- import tempfile
try:
conn = self.connection
chunk = conn.recv(4)
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index ef17081..52e18e5 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -25,6 +25,7 @@ To use, simply 'import logging.handlers' and log away!
"""
import logging, socket, os, pickle, struct, time, re
+from codecs import BOM_UTF8
from stat import ST_DEV, ST_INO, ST_MTIME
import queue
try:
@@ -32,11 +33,6 @@ try:
except ImportError: #pragma: no cover
threading = None
-try:
- import codecs
-except ImportError: #pragma: no cover
- codecs = None
-
#
# Some constants...
#
@@ -60,8 +56,6 @@ class BaseRotatingHandler(logging.FileHandler):
"""
Use the specified filename for streamed logging
"""
- if codecs is None: #pragma: no cover
- encoding = None
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
self.mode = mode
self.encoding = encoding
@@ -793,9 +787,7 @@ class SysLogHandler(logging.Handler):
prio = prio.encode('utf-8')
# Message is a string. Convert to bytes as required by RFC 5424
msg = msg.encode('utf-8')
- if codecs:
- msg = codecs.BOM_UTF8 + msg
- msg = prio + msg
+ msg = prio + BOM_UTF8 + msg
try:
if self.unixsocket:
try: