parameters: (self, protocol_factory,
                                         local_addr=None, remote_addr=None, *,
                                         family=0, proto=0, flags=0,
                                         reuse_address=_unset, reuse_port=None,
                                         allow_broadcast=None, sock=None)
return_statement: return transport, protocol
docstring: Create datagram connection.
docstring_summary: Create datagram connection.
docstring_tokens: Create datagram connection .
function: async def create_datagram_endpoint(self, protocol_factory,
                                         local_addr=None, remote_addr=None, *,
                                         family=0, proto=0, flags=0,
                                         reuse_address=_unset, reuse_port=None,
                                         allow_broadcast=None, sock=None):
          """Create datagram connection."""
          if sock is not None:
              if sock.type != socket.SOCK_DGRAM:
                  raise ValueError(
                      f'A UDP Socket was expected, got {sock!r}')
              if (local_addr or remote_addr or
                      family or proto or flags or
                      reuse_port or allow_broadcast):
                  # show the problematic kwargs in exception msg
                  opts = dict(local_addr=local_addr, remote_addr=remote_addr,
                              family=family, proto=proto, flags=flags,
                              reuse_address=reuse_address, reuse_port=reuse_port,
                              allow_broadcast=allow_broadcast)
                  problems = ', '.join(f'{k}={v}' for k, v in opts.items() if v)
                  raise ValueError(
                      f'socket modifier keyword arguments can not be used '
                      f'when sock is specified. ({problems})')
              sock.setblocking(False)
              r_addr = None
          else:
              if not (local_addr or remote_addr):
                  if family == 0:
                      raise ValueError('unexpected address family')
                  addr_pairs_info = (((family, proto), (None, None)),)
              elif hasattr(socket, 'AF_UNIX') and family == socket.AF_UNIX:
                  for addr in (local_addr, remote_addr):
                      if addr is not None and not isinstance(addr, str):
                          raise TypeError('string is expected')
                  addr_pairs_info = (((family, proto),
                                      (local_addr, remote_addr)), )
              else:
                  # join address by (family, protocol)
                  addr_infos = collections.OrderedDict()
                  for idx, addr in ((0, local_addr), (1, remote_addr)):
                      if addr is not None:
                          assert isinstance(addr, tuple) and len(addr) == 2, (
                              '2-tuple is expected')
  
                          infos = await self._ensure_resolved(
                              addr, family=family, type=socket.SOCK_DGRAM,
                              proto=proto, flags=flags, loop=self)
                          if not infos:
                              raise OSError('getaddrinfo() returned empty list')
  
                          for fam, _, pro, _, address in infos:
                              key = (fam, pro)
                              if key not in addr_infos:
                                  addr_infos[key] = [None, None]
                              addr_infos[key][idx] = address
  
                  # each addr has to have info for each (family, proto) pair
                  addr_pairs_info = [
                      (key, addr_pair) for key, addr_pair in addr_infos.items()
                      if not ((local_addr and addr_pair[0] is None) or
                              (remote_addr and addr_pair[1] is None))]
  
                  if not addr_pairs_info:
                      raise ValueError('can not get address information')
  
              exceptions = []
  
              # bpo-37228
              if reuse_address is not _unset:
                  if reuse_address:
                      raise ValueError("Passing `reuse_address=True` is no "
                                       "longer supported, as the usage of "
                                       "SO_REUSEPORT in UDP poses a significant "
                                       "security concern.")
                  else:
                      warnings.warn("The *reuse_address* parameter has been "
                                    "deprecated as of 3.7.6 and is scheduled "
                                    "for removal in 3.11.", DeprecationWarning,
                                    stacklevel=2)
  
              for ((family, proto),
                   (local_address, remote_address)) in addr_pairs_info:
                  sock = None
                  r_addr = None
                  try:
                      sock = socket.socket(
                          family=family, type=socket.SOCK_DGRAM, proto=proto)
                      if reuse_port:
                          _set_reuseport(sock)
                      if allow_broadcast:
                          sock.setsockopt(
                              socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                      sock.setblocking(False)
  
                      if local_addr:
                          sock.bind(local_address)
                      if remote_addr:
                          if not allow_broadcast:
                              await self.sock_connect(sock, remote_address)
                          r_addr = remote_address
                  except OSError as exc:
                      if sock is not None:
                          sock.close()
                      exceptions.append(exc)
                  except:
                      if sock is not None:
                          sock.close()
                      raise
                  else:
                      break
              else:
                  raise exceptions[0]
  
          protocol = protocol_factory()
          waiter = self.create_future()
          transport = self._make_datagram_transport(
              sock, protocol, r_addr, waiter)
          if self._debug:
              if local_addr:
                  logger.info("Datagram endpoint local_addr=%r remote_addr=%r "
                              "created: (%r, %r)",
                              local_addr, remote_addr, transport, protocol)
              else:
                  logger.debug("Datagram endpoint remote_addr=%r created: "
                               "(%r, %r)",
                               remote_addr, transport, protocol)
  
          try:
              await waiter
          except:
              transport.close()
              raise
  
          return transport, protocol
function_tokens: async def create_datagram_endpoint ( self , protocol_factory , local_addr = None , remote_addr = None , * , family = 0 , proto = 0 , flags = 0 , reuse_address = _unset , reuse_port = None , allow_broadcast = None , sock = None ) : if sock is not None : if sock . type != socket . SOCK_DGRAM : raise ValueError ( f'A UDP Socket was expected, got {sock!r}' ) if ( local_addr or remote_addr or family or proto or flags or reuse_port or allow_broadcast ) : # show the problematic kwargs in exception msg opts = dict ( local_addr = local_addr , remote_addr = remote_addr , family = family , proto = proto , flags = flags , reuse_address = reuse_address , reuse_port = reuse_port , allow_broadcast = allow_broadcast ) problems = ', ' . join ( f'{k}={v}' for k , v in opts . items ( ) if v ) raise ValueError ( f'socket modifier keyword arguments can not be used ' f'when sock is specified. ({problems})' ) sock . setblocking ( False ) r_addr = None else : if not ( local_addr or remote_addr ) : if family == 0 : raise ValueError ( 'unexpected address family' ) addr_pairs_info = ( ( ( family , proto ) , ( None , None ) ) , ) elif hasattr ( socket , 'AF_UNIX' ) and family == socket . AF_UNIX : for addr in ( local_addr , remote_addr ) : if addr is not None and not isinstance ( addr , str ) : raise TypeError ( 'string is expected' ) addr_pairs_info = ( ( ( family , proto ) , ( local_addr , remote_addr ) ) , ) else : # join address by (family, protocol) addr_infos = collections . OrderedDict ( ) for idx , addr in ( ( 0 , local_addr ) , ( 1 , remote_addr ) ) : if addr is not None : assert isinstance ( addr , tuple ) and len ( addr ) == 2 , ( '2-tuple is expected' ) infos = await self . _ensure_resolved ( addr , family = family , type = socket . SOCK_DGRAM , proto = proto , flags = flags , loop = self ) if not infos : raise OSError ( 'getaddrinfo() returned empty list' ) for fam , _ , pro , _ , address in infos : key = ( fam , pro ) if key not in addr_infos : addr_infos [ key ] = [ None , None ] addr_infos [ key ] [ idx ] = address # each addr has to have info for each (family, proto) pair addr_pairs_info = [ ( key , addr_pair ) for key , addr_pair in addr_infos . items ( ) if not ( ( local_addr and addr_pair [ 0 ] is None ) or ( remote_addr and addr_pair [ 1 ] is None ) ) ] if not addr_pairs_info : raise ValueError ( 'can not get address information' ) exceptions = [ ] # bpo-37228 if reuse_address is not _unset : if reuse_address : raise ValueError ( "Passing `reuse_address=True` is no " "longer supported, as the usage of " "SO_REUSEPORT in UDP poses a significant " "security concern." ) else : warnings . warn ( "The *reuse_address* parameter has been " "deprecated as of 3.7.6 and is scheduled " "for removal in 3.11." , DeprecationWarning , stacklevel = 2 ) for ( ( family , proto ) , ( local_address , remote_address ) ) in addr_pairs_info : sock = None r_addr = None try : sock = socket . socket ( family = family , type = socket . SOCK_DGRAM , proto = proto ) if reuse_port : _set_reuseport ( sock ) if allow_broadcast : sock . setsockopt ( socket . SOL_SOCKET , socket . SO_BROADCAST , 1 ) sock . setblocking ( False ) if local_addr : sock . bind ( local_address ) if remote_addr : if not allow_broadcast : await self . sock_connect ( sock , remote_address ) r_addr = remote_address except OSError as exc : if sock is not None : sock . close ( ) exceptions . append ( exc ) except : if sock is not None : sock . close ( ) raise else : break else : raise exceptions [ 0 ] protocol = protocol_factory ( ) waiter = self . create_future ( ) transport = self . _make_datagram_transport ( sock , protocol , r_addr , waiter ) if self . _debug : if local_addr : logger . info ( "Datagram endpoint local_addr=%r remote_addr=%r " "created: (%r, %r)" , local_addr , remote_addr , transport , protocol ) else : logger . debug ( "Datagram endpoint remote_addr=%r created: " "(%r, %r)" , remote_addr , transport , protocol ) try : await waiter except : transport . close ( ) raise return transport , protocol