SecurityOrigin

Added in version 2.16.

class SecurityOrigin(**kwargs)

A security boundary for websites.

SecurityOrigin is a representation of a security domain defined by websites. A security origin consists of a protocol, a hostname, and an optional port number.

Resources with the same security origin can generally access each other for client-side scripting or database access. When comparing origins, beware that if both protocol and host are None, the origins should not be treated as equal.

Constructors

class SecurityOrigin
classmethod new(protocol: str, host: str, port: int) SecurityOrigin

Create a new security origin from the provided protocol, host and port.

Added in version 2.16.

Parameters:
  • protocol – The protocol for the new origin

  • host – The host for the new origin

  • port – The port number for the new origin, or 0 to indicate the default port for protocol

classmethod new_for_uri(uri: str) SecurityOrigin

Create a new security origin from the provided.

Create a new security origin from the provided URI. Components of uri other than protocol, host, and port do not affect the created SecurityOrigin.

Added in version 2.16.

Parameters:

uri – The URI for the new origin

Methods

class SecurityOrigin
get_host() str | None

Gets the hostname of origin.

It is reasonable for this to be None if its protocol does not require a host component.

Added in version 2.16.

get_port() int

Gets the port of origin.

This function will always return 0 if the port is the default port for the given protocol. For example, http://example.com has the same security origin as http://example.com:80, and this function will return 0 for a SecurityOrigin constructed from either URI.

Added in version 2.16.

get_protocol() str | None

Gets the protocol of origin.

Added in version 2.16.

to_string() str | None

Gets a string representation of origin.

The string representation is a valid URI with only protocol, host, and port components, or None.

Added in version 2.16.