Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Side by Side Diff: Lib/logging/config.py

Issue 15452: Improve the security model for logging listener()
Patch Set: Created 7 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/ast.py ('k') | Lib/test/test_ast.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. 1 # Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
2 # 2 #
3 # Permission to use, copy, modify, and distribute this software and its 3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose and without fee is hereby granted, 4 # documentation for any purpose and without fee is hereby granted,
5 # provided that the above copyright notice appear in all copies and that 5 # provided that the above copyright notice appear in all copies and that
6 # both that copyright notice and this permission notice appear in 6 # both that copyright notice and this permission notice appear in
7 # supporting documentation, and that the name of Vinay Sajip 7 # supporting documentation, and that the name of Vinay Sajip
8 # not be used in advertising or publicity pertaining to distribution 8 # not be used in advertising or publicity pertaining to distribution
9 # of the software without specific, written prior permission. 9 # of the software without specific, written prior permission.
10 # VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 10 # VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
11 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 11 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
12 # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 12 # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
13 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 13 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
14 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 14 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
17 """ 17 """
18 Configuration functions for the logging package for Python. The core package 18 Configuration functions for the logging package for Python. The core package
19 is based on PEP 282 and comments thereto in comp.lang.python, and influenced 19 is based on PEP 282 and comments thereto in comp.lang.python, and influenced
20 by Apache's log4j system. 20 by Apache's log4j system.
21 21
22 Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. 22 Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
23 23
24 To use, simply 'import logging' and log away! 24 To use, simply 'import logging' and log away!
25 """ 25 """
26 26
27 from ast import lookup_eval
27 import sys, logging, logging.handlers, socket, struct, traceback, re 28 import sys, logging, logging.handlers, socket, struct, traceback, re
28 import io 29 import io
29 30
30 try: 31 try:
31 import _thread as thread 32 import _thread as thread
32 import threading 33 import threading
33 except ImportError: #pragma: no cover 34 except ImportError: #pragma: no cover
34 thread = None 35 thread = None
35 36
36 from socketserver import ThreadingTCPServer, StreamRequestHandler 37 from socketserver import ThreadingTCPServer, StreamRequestHandler
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if not len(hlist): 129 if not len(hlist):
129 return {} 130 return {}
130 hlist = hlist.split(",") 131 hlist = hlist.split(",")
131 hlist = _strip_spaces(hlist) 132 hlist = _strip_spaces(hlist)
132 handlers = {} 133 handlers = {}
133 fixups = [] #for inter-handler references 134 fixups = [] #for inter-handler references
134 for hand in hlist: 135 for hand in hlist:
135 section = cp["handler_%s" % hand] 136 section = cp["handler_%s" % hand]
136 klass = section["class"] 137 klass = section["class"]
137 fmt = section.get("formatter", "") 138 fmt = section.get("formatter", "")
139 context = dict(vars(logging))
140 context['handlers'] = logging.handlers
138 try: 141 try:
139 klass = eval(klass, vars(logging)) 142 klass = lookup_eval(klass, context, True)
140 except (AttributeError, NameError): 143 except ValueError:
141 klass = _resolve(klass) 144 klass = _resolve(klass)
142 args = section["args"] 145 args = section["args"]
143 args = eval(args, vars(logging)) 146 args = lookup_eval(args, context, True)
144 h = klass(*args) 147 h = klass(*args)
145 if "level" in section: 148 if "level" in section:
146 level = section["level"] 149 level = section["level"]
147 h.setLevel(logging._levelNames[level]) 150 h.setLevel(logging._levelNames[level])
148 if len(fmt): 151 if len(fmt):
149 h.setFormatter(formatters[fmt]) 152 h.setFormatter(formatters[fmt])
150 if issubclass(klass, logging.handlers.MemoryHandler): 153 if issubclass(klass, logging.handlers.MemoryHandler):
151 target = section.get("target", "") 154 target = section.get("target", "")
152 if len(target): #the target handler may not be loaded yet, so keep f or later... 155 if len(target): #the target handler may not be loaded yet, so keep f or later...
153 fixups.append((h, target)) 156 fixups.append((h, target))
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 Stop the listening server which was created with a call to listen(). 912 Stop the listening server which was created with a call to listen().
910 """ 913 """
911 global _listener 914 global _listener
912 logging._acquireLock() 915 logging._acquireLock()
913 try: 916 try:
914 if _listener: 917 if _listener:
915 _listener.abort = 1 918 _listener.abort = 1
916 _listener = None 919 _listener = None
917 finally: 920 finally:
918 logging._releaseLock() 921 logging._releaseLock()
OLDNEW
« no previous file with comments | « Lib/ast.py ('k') | Lib/test/test_ast.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+