code: def validate_port(port):
      '''Validate port and return it as an integer.
  
      A string, or its representation as an integer, is accepted.'''
      if not isinstance(port, (str, int)):
          raise TypeError(f'port must be an integer or string: {port}')
      if isinstance(port, str) and port.isdigit():
          port = int(port)
      if isinstance(port, int) and 0 < port <= 65535:
          return port
      raise ValueError(f'invalid port: {port}'f validate_port(port):
      '''Validate port and return it as an integer.
  
      A string, or its representation as an integer, is accepted.'''
      if not isinstance(port, (str, int)):
          raise TypeError(f'port must be an integer or string: {port}')
      if isinstance(port, str) and port.isdigit():
          port = int(port)
      if isinstance(port, int) and 0 < port <= 65535:
          return port
      raise ValueError(f'invalid port: {port}')
docs: Validate port and return it as an integer.
  
      A string, or its representation as an integer, is accepted.