parameters: (self, bind_addr)
return_statement: return sock
docstring: Create (or recreate) a UNIX socket object.
docstring_summary: Create (or recreate) a UNIX socket object.
docstring_tokens: Create ( or recreate ) a UNIX socket object .
function: def bind_unix_socket(self, bind_addr):
          """Create (or recreate) a UNIX socket object."""
          if IS_WINDOWS:
              """
              Trying to access socket.AF_UNIX under Windows
              causes an AttributeError.
              """
              raise ValueError(  # or RuntimeError?
                  'AF_UNIX sockets are not supported under Windows.',
              )
  
          fs_permissions = 0o777  # TODO: allow changing mode
  
          try:
              # Make possible reusing the socket...
              os.unlink(self.bind_addr)
          except OSError:
              """
              File does not exist, which is the primary goal anyway.
              """
          except TypeError as typ_err:
              err_msg = str(typ_err)
              if (
                      'remove() argument 1 must be encoded '
                      'string without null bytes, not unicode'
                      not in err_msg
                      and 'embedded NUL character' not in err_msg  # py34
                      and 'argument must be a '
                      'string without NUL characters' not in err_msg  # pypy2
              ):
                  raise
          except ValueError as val_err:
              err_msg = str(val_err)
              if (
                      'unlink: embedded null '
                      'character in path' not in err_msg
                      and 'embedded null byte' not in err_msg
                      and 'argument must be a '
                      'string without NUL characters' not in err_msg  # pypy3
              ):
                  raise
  
          sock = self.prepare_socket(
              bind_addr=bind_addr,
              family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0,
              nodelay=self.nodelay, ssl_adapter=self.ssl_adapter,
          )
  
          try:
              """Linux way of pre-populating fs mode permissions."""
              # Allow everyone access the socket...
              os.fchmod(sock.fileno(), fs_permissions)
              FS_PERMS_SET = True
          except OSError:
              FS_PERMS_SET = False
  
          try:
              sock = self.bind_socket(sock, bind_addr)
          except socket.error:
              sock.close()
              raise
  
          bind_addr = self.resolve_real_bind_addr(sock)
  
          try:
              """FreeBSD/macOS pre-populating fs mode permissions."""
              if not FS_PERMS_SET:
                  try:
                      os.lchmod(bind_addr, fs_permissions)
                  except AttributeError:
                      os.chmod(bind_addr, fs_permissions, follow_symlinks=False)
                  FS_PERMS_SET = True
          except OSError:
              pass
  
          if not FS_PERMS_SET:
              self.error_log(
                  'Failed to set socket fs mode permissions',
                  level=logging.WARNING,
              )
  
          self.bind_addr = bind_addr
          self.socket = sock
          return sock
function_tokens: def bind_unix_socket ( self , bind_addr ) : if IS_WINDOWS : """
              Trying to access socket.AF_UNIX under Windows
              causes an AttributeError.
              """ raise ValueError ( # or RuntimeError? 'AF_UNIX sockets are not supported under Windows.' , ) fs_permissions = 0o777 # TODO: allow changing mode try : # Make possible reusing the socket... os . unlink ( self . bind_addr ) except OSError : """
              File does not exist, which is the primary goal anyway.
              """ except TypeError as typ_err : err_msg = str ( typ_err ) if ( 'remove() argument 1 must be encoded ' 'string without null bytes, not unicode' not in err_msg and 'embedded NUL character' not in err_msg # py34 and 'argument must be a ' 'string without NUL characters' not in err_msg # pypy2 ) : raise except ValueError as val_err : err_msg = str ( val_err ) if ( 'unlink: embedded null ' 'character in path' not in err_msg and 'embedded null byte' not in err_msg and 'argument must be a ' 'string without NUL characters' not in err_msg # pypy3 ) : raise sock = self . prepare_socket ( bind_addr = bind_addr , family = socket . AF_UNIX , type = socket . SOCK_STREAM , proto = 0 , nodelay = self . nodelay , ssl_adapter = self . ssl_adapter , ) try : """Linux way of pre-populating fs mode permissions.""" # Allow everyone access the socket... os . fchmod ( sock . fileno ( ) , fs_permissions ) FS_PERMS_SET = True except OSError : FS_PERMS_SET = False try : sock = self . bind_socket ( sock , bind_addr ) except socket . error : sock . close ( ) raise bind_addr = self . resolve_real_bind_addr ( sock ) try : """FreeBSD/macOS pre-populating fs mode permissions.""" if not FS_PERMS_SET : try : os . lchmod ( bind_addr , fs_permissions ) except AttributeError : os . chmod ( bind_addr , fs_permissions , follow_symlinks = False ) FS_PERMS_SET = True except OSError : pass if not FS_PERMS_SET : self . error_log ( 'Failed to set socket fs mode permissions' , level = logging . WARNING , ) self . bind_addr = bind_addr self . socket = sock return sock