MCPcopy Index your code
hub / github.com/RustPython/RustPython / createSocket

Method createSocket

Lib/logging/handlers.py:902–946  ·  view source on GitHub ↗

Try to create a socket and, if it's not a datagram socket, connect it to the other end. This method is called during handler initialization, but it's not regarded as an error if the other end isn't listening yet --- the method will be called again when emitting an ev

(self)

Source from the content-addressed store, hash-verified

900 raise
901
902 def createSocket(self):
903 """
904 Try to create a socket and, if it's not a datagram socket, connect it
905 to the other end. This method is called during handler initialization,
906 but it's not regarded as an error if the other end isn't listening yet
907 --- the method will be called again when emitting an event,
908 if there is no socket at that point.
909 """
910 address = self.address
911 socktype = self.socktype
912
913 if isinstance(address, str):
914 self.unixsocket = True
915 # Syslog server may be unavailable during handler initialisation.
916 # C's openlog() function also ignores connection errors.
917 # Moreover, we ignore these errors while logging, so it's not worse
918 # to ignore it also here.
919 try:
920 self._connect_unixsocket(address)
921 except OSError:
922 pass
923 else:
924 self.unixsocket = False
925 if socktype is None:
926 socktype = socket.SOCK_DGRAM
927 host, port = address
928 ress = socket.getaddrinfo(host, port, 0, socktype)
929 if not ress:
930 raise OSError("getaddrinfo returns an empty list")
931 for res in ress:
932 af, socktype, proto, _, sa = res
933 err = sock = None
934 try:
935 sock = socket.socket(af, socktype, proto)
936 if socktype == socket.SOCK_STREAM:
937 sock.connect(sa)
938 break
939 except OSError as exc:
940 err = exc
941 if sock is not None:
942 sock.close()
943 if err is not None:
944 raise err
945 self.socket = sock
946 self.socktype = socktype
947
948 def encodePriority(self, facility, priority):
949 """

Callers 2

__init__Method · 0.95
emitMethod · 0.95

Calls 6

_connect_unixsocketMethod · 0.95
isinstanceFunction · 0.85
socketMethod · 0.80
getaddrinfoMethod · 0.45
connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected