]>
Commit | Line | Data |
---|---|---|
af6f018f KK |
1 | |
2 | # HG changeset patch | |
3 | # User Vinay Sajip <vinay_sajip@yahoo.co.uk> | |
4 | # Date 1366621660 -3600 | |
5 | # Node ID d037847137866e850abc5b8e4136ca60404dcfcb | |
6 | # Parent 9df9931fae96ab5f1cd2e516f065dccb9c061c18 | |
7 | Issue #17795: Reverted backwards-incompatible change in SysLogHandler with Unix domain sockets. | |
8 | ||
9 | diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py | |
10 | --- a/Lib/logging/handlers.py | |
11 | +++ b/Lib/logging/handlers.py | |
12 | @@ -1,4 +1,4 @@ | |
13 | -# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved. | |
14 | +# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved. | |
15 | # | |
16 | # Permission to use, copy, modify, and distribute this software and its | |
17 | # documentation for any purpose and without fee is hereby granted, | |
18 | @@ -18,7 +18,7 @@ | |
19 | Additional handlers for the logging package for Python. The core package is | |
20 | based on PEP 282 and comments thereto in comp.lang.python. | |
21 | ||
22 | -Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved. | |
23 | +Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. | |
24 | ||
25 | To use, simply 'import logging.handlers' and log away! | |
26 | """ | |
27 | @@ -767,7 +767,7 @@ class SysLogHandler(logging.Handler): | |
28 | } | |
29 | ||
30 | def __init__(self, address=('localhost', SYSLOG_UDP_PORT), | |
31 | - facility=LOG_USER, socktype=socket.SOCK_DGRAM): | |
32 | + facility=LOG_USER, socktype=None): | |
33 | """ | |
34 | Initialize a handler. | |
35 | ||
36 | @@ -786,18 +786,37 @@ class SysLogHandler(logging.Handler): | |
37 | self._connect_unixsocket(address) | |
38 | else: | |
39 | self.unixsocket = False | |
40 | + if socktype is None: | |
41 | + socktype = socket.SOCK_DGRAM | |
42 | self.socket = socket.socket(socket.AF_INET, socktype) | |
43 | if socktype == socket.SOCK_STREAM: | |
44 | self.socket.connect(address) | |
45 | + self.socktype = socktype | |
46 | self.formatter = None | |
47 | ||
48 | def _connect_unixsocket(self, address): | |
49 | - self.socket = socket.socket(socket.AF_UNIX, self.socktype) | |
50 | + use_socktype = self.socktype | |
51 | + if use_socktype is None: | |
52 | + use_socktype = socket.SOCK_DGRAM | |
53 | + self.socket = socket.socket(socket.AF_UNIX, use_socktype) | |
54 | try: | |
55 | self.socket.connect(address) | |
56 | + # it worked, so set self.socktype to the used type | |
57 | + self.socktype = use_socktype | |
58 | except socket.error: | |
59 | self.socket.close() | |
60 | - raise | |
61 | + if self.socktype is not None: | |
62 | + # user didn't specify falling back, so fail | |
63 | + raise | |
64 | + use_socktype = socket.SOCK_STREAM | |
65 | + self.socket = socket.socket(socket.AF_UNIX, use_socktype) | |
66 | + try: | |
67 | + self.socket.connect(address) | |
68 | + # it worked, so set self.socktype to the used type | |
69 | + self.socktype = use_socktype | |
70 | + except socket.error: | |
71 | + self.socket.close() | |
72 | + raise | |
73 | ||
74 | def encodePriority(self, facility, priority): | |
75 | """ | |
76 | diff --git a/Misc/NEWS b/Misc/NEWS | |
77 | --- a/Misc/NEWS | |
78 | +++ b/Misc/NEWS | |
79 | @@ -15,6 +15,9 @@ | |
80 | Library | |
81 | ------- | |
82 | ||
83 | +- Issue #17795: Reverted backwards-incompatible change in SysLogHandler with | |
84 | + Unix domain sockets. | |
85 | + | |
86 | - Issue #17625: In IDLE, close the replace dialog after it is used. | |
87 | ||
88 |