partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
Ha.is_lagging
Returns if instance with an wal should consider itself unhealthy to be promoted due to replication lag. :param wal_position: Current wal position. :returns True when node is lagging
patroni/ha.py
def is_lagging(self, wal_position): """Returns if instance with an wal should consider itself unhealthy to be promoted due to replication lag. :param wal_position: Current wal position. :returns True when node is lagging """ lag = (self.cluster.last_leader_operation or 0) - wal_...
def is_lagging(self, wal_position): """Returns if instance with an wal should consider itself unhealthy to be promoted due to replication lag. :param wal_position: Current wal position. :returns True when node is lagging """ lag = (self.cluster.last_leader_operation or 0) - wal_...
[ "Returns", "if", "instance", "with", "an", "wal", "should", "consider", "itself", "unhealthy", "to", "be", "promoted", "due", "to", "replication", "lag", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L567-L574
[ "def", "is_lagging", "(", "self", ",", "wal_position", ")", ":", "lag", "=", "(", "self", ".", "cluster", ".", "last_leader_operation", "or", "0", ")", "-", "wal_position", "return", "lag", ">", "self", ".", "patroni", ".", "config", ".", "get", "(", "...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha._is_healthiest_node
This method tries to determine whether I am healthy enough to became a new leader candidate or not.
patroni/ha.py
def _is_healthiest_node(self, members, check_replication_lag=True): """This method tries to determine whether I am healthy enough to became a new leader candidate or not.""" _, my_wal_position = self.state_handler.timeline_wal_position() if check_replication_lag and self.is_lagging(my_wal_posit...
def _is_healthiest_node(self, members, check_replication_lag=True): """This method tries to determine whether I am healthy enough to became a new leader candidate or not.""" _, my_wal_position = self.state_handler.timeline_wal_position() if check_replication_lag and self.is_lagging(my_wal_posit...
[ "This", "method", "tries", "to", "determine", "whether", "I", "am", "healthy", "enough", "to", "became", "a", "new", "leader", "candidate", "or", "not", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L576-L603
[ "def", "_is_healthiest_node", "(", "self", ",", "members", ",", "check_replication_lag", "=", "True", ")", ":", "_", ",", "my_wal_position", "=", "self", ".", "state_handler", ".", "timeline_wal_position", "(", ")", "if", "check_replication_lag", "and", "self", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.demote
Demote PostgreSQL running as master. :param mode: One of offline, graceful or immediate. offline is used when connection to DCS is not available. graceful is used when failing over to another node due to user request. May only be called running async. immediate is used when ...
patroni/ha.py
def demote(self, mode): """Demote PostgreSQL running as master. :param mode: One of offline, graceful or immediate. offline is used when connection to DCS is not available. graceful is used when failing over to another node due to user request. May only be called running async. ...
def demote(self, mode): """Demote PostgreSQL running as master. :param mode: One of offline, graceful or immediate. offline is used when connection to DCS is not available. graceful is used when failing over to another node due to user request. May only be called running async. ...
[ "Demote", "PostgreSQL", "running", "as", "master", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L720-L765
[ "def", "demote", "(", "self", ",", "mode", ")", ":", "mode_control", "=", "{", "'offline'", ":", "dict", "(", "stop", "=", "'fast'", ",", "checkpoint", "=", "False", ",", "release", "=", "False", ",", "offline", "=", "True", ",", "async_req", "=", "F...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.process_manual_failover_from_leader
Checks if manual failover is requested and takes action if appropriate. Cleans up failover key if failover conditions are not matched. :returns: action message if demote was initiated, None if no action was taken
patroni/ha.py
def process_manual_failover_from_leader(self): """Checks if manual failover is requested and takes action if appropriate. Cleans up failover key if failover conditions are not matched. :returns: action message if demote was initiated, None if no action was taken""" failover = self.clus...
def process_manual_failover_from_leader(self): """Checks if manual failover is requested and takes action if appropriate. Cleans up failover key if failover conditions are not matched. :returns: action message if demote was initiated, None if no action was taken""" failover = self.clus...
[ "Checks", "if", "manual", "failover", "is", "requested", "and", "takes", "action", "if", "appropriate", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L801-L844
[ "def", "process_manual_failover_from_leader", "(", "self", ")", ":", "failover", "=", "self", ".", "cluster", ".", "failover", "if", "not", "failover", "or", "(", "self", ".", "is_paused", "(", ")", "and", "not", "self", ".", "state_handler", ".", "is_leader...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.process_unhealthy_cluster
Cluster has no leader key
patroni/ha.py
def process_unhealthy_cluster(self): """Cluster has no leader key""" if self.is_healthiest_node(): if self.acquire_lock(): failover = self.cluster.failover if failover: if self.is_paused() and failover.leader and failover.candidate: ...
def process_unhealthy_cluster(self): """Cluster has no leader key""" if self.is_healthiest_node(): if self.acquire_lock(): failover = self.cluster.failover if failover: if self.is_paused() and failover.leader and failover.candidate: ...
[ "Cluster", "has", "no", "leader", "key" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L846-L886
[ "def", "process_unhealthy_cluster", "(", "self", ")", ":", "if", "self", ".", "is_healthiest_node", "(", ")", ":", "if", "self", ".", "acquire_lock", "(", ")", ":", "failover", "=", "self", ".", "cluster", ".", "failover", "if", "failover", ":", "if", "s...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.restart
conditional and unconditional restart
patroni/ha.py
def restart(self, restart_data, run_async=False): """ conditional and unconditional restart """ assert isinstance(restart_data, dict) if (not self.restart_matches(restart_data.get('role'), restart_data.get('postgres_version'), ...
def restart(self, restart_data, run_async=False): """ conditional and unconditional restart """ assert isinstance(restart_data, dict) if (not self.restart_matches(restart_data.get('role'), restart_data.get('postgres_version'), ...
[ "conditional", "and", "unconditional", "restart" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L1009-L1048
[ "def", "restart", "(", "self", ",", "restart_data", ",", "run_async", "=", "False", ")", ":", "assert", "isinstance", "(", "restart_data", ",", "dict", ")", "if", "(", "not", "self", ".", "restart_matches", "(", "restart_data", ".", "get", "(", "'role'", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.handle_starting_instance
Starting up PostgreSQL may take a long time. In case we are the leader we may want to fail over to.
patroni/ha.py
def handle_starting_instance(self): """Starting up PostgreSQL may take a long time. In case we are the leader we may want to fail over to.""" # Check if we are in startup, when paused defer to main loop for manual failovers. if not self.state_handler.check_for_startup() or self.is_pause...
def handle_starting_instance(self): """Starting up PostgreSQL may take a long time. In case we are the leader we may want to fail over to.""" # Check if we are in startup, when paused defer to main loop for manual failovers. if not self.state_handler.check_for_startup() or self.is_pause...
[ "Starting", "up", "PostgreSQL", "may", "take", "a", "long", "time", ".", "In", "case", "we", "are", "the", "leader", "we", "may", "want", "to", "fail", "over", "to", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L1153-L1190
[ "def", "handle_starting_instance", "(", "self", ")", ":", "# Check if we are in startup, when paused defer to main loop for manual failovers.", "if", "not", "self", ".", "state_handler", ".", "check_for_startup", "(", ")", "or", "self", ".", "is_paused", "(", ")", ":", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Ha.get_remote_member
In case of standby cluster this will tel us from which remote master to stream. Config can be both patroni config or cluster.config.data
patroni/ha.py
def get_remote_member(self, member=None): """ In case of standby cluster this will tel us from which remote master to stream. Config can be both patroni config or cluster.config.data """ cluster_params = self.get_standby_cluster_config() if cluster_params: ...
def get_remote_member(self, member=None): """ In case of standby cluster this will tel us from which remote master to stream. Config can be both patroni config or cluster.config.data """ cluster_params = self.get_standby_cluster_config() if cluster_params: ...
[ "In", "case", "of", "standby", "cluster", "this", "will", "tel", "us", "from", "which", "remote", "master", "to", "stream", ".", "Config", "can", "be", "both", "patroni", "config", "or", "cluster", ".", "config", ".", "data" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/ha.py#L1363-L1380
[ "def", "get_remote_member", "(", "self", ",", "member", "=", "None", ")", ":", "cluster_params", "=", "self", ".", "get_standby_cluster_config", "(", ")", "if", "cluster_params", ":", "name", "=", "member", ".", "name", "if", "member", "else", "'remote_master:...
f6d29081c90af52064b981cdd877a07338d86038
train
Client.machines
Original `machines` method(property) of `etcd.Client` class raise exception when it failed to get list of etcd cluster members. This method is being called only when request failed on one of the etcd members during `api_execute` call. For us it's more important to execute original request rather...
patroni/dcs/etcd.py
def machines(self): """Original `machines` method(property) of `etcd.Client` class raise exception when it failed to get list of etcd cluster members. This method is being called only when request failed on one of the etcd members during `api_execute` call. For us it's more important to ...
def machines(self): """Original `machines` method(property) of `etcd.Client` class raise exception when it failed to get list of etcd cluster members. This method is being called only when request failed on one of the etcd members during `api_execute` call. For us it's more important to ...
[ "Original", "machines", "method", "(", "property", ")", "of", "etcd", ".", "Client", "class", "raise", "exception", "when", "it", "failed", "to", "get", "list", "of", "etcd", "cluster", "members", ".", "This", "method", "is", "being", "called", "only", "wh...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/etcd.py#L118-L157
[ "def", "machines", "(", "self", ")", ":", "kwargs", "=", "self", ".", "_build_request_parameters", "(", ")", "while", "True", ":", "try", ":", "response", "=", "self", ".", "http", ".", "request", "(", "self", ".", "_MGET", ",", "self", ".", "_base_uri...
f6d29081c90af52064b981cdd877a07338d86038
train
Client._get_machines_cache_from_srv
Fetch list of etcd-cluster member by resolving _etcd-server._tcp. SRV record. This record should contain list of host and peer ports which could be used to run 'GET http://{host}:{port}/members' request (peer protocol)
patroni/dcs/etcd.py
def _get_machines_cache_from_srv(self, srv): """Fetch list of etcd-cluster member by resolving _etcd-server._tcp. SRV record. This record should contain list of host and peer ports which could be used to run 'GET http://{host}:{port}/members' request (peer protocol)""" ret = [] ...
def _get_machines_cache_from_srv(self, srv): """Fetch list of etcd-cluster member by resolving _etcd-server._tcp. SRV record. This record should contain list of host and peer ports which could be used to run 'GET http://{host}:{port}/members' request (peer protocol)""" ret = [] ...
[ "Fetch", "list", "of", "etcd", "-", "cluster", "member", "by", "resolving", "_etcd", "-", "server", ".", "_tcp", ".", "SRV", "record", ".", "This", "record", "should", "contain", "list", "of", "host", "and", "peer", "ports", "which", "could", "be", "used...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/etcd.py#L231-L258
[ "def", "_get_machines_cache_from_srv", "(", "self", ",", "srv", ")", ":", "ret", "=", "[", "]", "for", "r", "in", "[", "'-client-ssl'", ",", "'-client'", ",", "'-ssl'", ",", "''", ",", "'-server-ssl'", ",", "'-server'", "]", ":", "protocol", "=", "'https...
f6d29081c90af52064b981cdd877a07338d86038
train
Client._get_machines_cache_from_dns
One host might be resolved into multiple ip addresses. We will make list out of it
patroni/dcs/etcd.py
def _get_machines_cache_from_dns(self, host, port): """One host might be resolved into multiple ip addresses. We will make list out of it""" if self.protocol == 'http': ret = [] for af, _, _, _, sa in self._dns_resolver.resolve(host, port): host, port = sa[:2] ...
def _get_machines_cache_from_dns(self, host, port): """One host might be resolved into multiple ip addresses. We will make list out of it""" if self.protocol == 'http': ret = [] for af, _, _, _, sa in self._dns_resolver.resolve(host, port): host, port = sa[:2] ...
[ "One", "host", "might", "be", "resolved", "into", "multiple", "ip", "addresses", ".", "We", "will", "make", "list", "out", "of", "it" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/etcd.py#L260-L271
[ "def", "_get_machines_cache_from_dns", "(", "self", ",", "host", ",", "port", ")", ":", "if", "self", ".", "protocol", "==", "'http'", ":", "ret", "=", "[", "]", "for", "af", ",", "_", ",", "_", ",", "_", ",", "sa", "in", "self", ".", "_dns_resolve...
f6d29081c90af52064b981cdd877a07338d86038
train
Client._load_machines_cache
This method should fill up `_machines_cache` from scratch. It could happen only in two cases: 1. During class initialization 2. When all etcd members failed
patroni/dcs/etcd.py
def _load_machines_cache(self): """This method should fill up `_machines_cache` from scratch. It could happen only in two cases: 1. During class initialization 2. When all etcd members failed""" self._update_machines_cache = True if 'srv' not in self._config and 'host' ...
def _load_machines_cache(self): """This method should fill up `_machines_cache` from scratch. It could happen only in two cases: 1. During class initialization 2. When all etcd members failed""" self._update_machines_cache = True if 'srv' not in self._config and 'host' ...
[ "This", "method", "should", "fill", "up", "_machines_cache", "from", "scratch", ".", "It", "could", "happen", "only", "in", "two", "cases", ":", "1", ".", "During", "class", "initialization", "2", ".", "When", "all", "etcd", "members", "failed" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/etcd.py#L288-L310
[ "def", "_load_machines_cache", "(", "self", ")", ":", "self", ".", "_update_machines_cache", "=", "True", "if", "'srv'", "not", "in", "self", ".", "_config", "and", "'host'", "not", "in", "self", ".", "_config", "and", "'hosts'", "not", "in", "self", ".", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.pg_ctl
Builds and executes pg_ctl command :returns: `!True` when return_code == 0, otherwise `!False`
patroni/postgresql.py
def pg_ctl(self, cmd, *args, **kwargs): """Builds and executes pg_ctl command :returns: `!True` when return_code == 0, otherwise `!False`""" pg_ctl = [self._pgcommand('pg_ctl'), cmd] return subprocess.call(pg_ctl + ['-D', self._data_dir] + list(args), **kwargs) == 0
def pg_ctl(self, cmd, *args, **kwargs): """Builds and executes pg_ctl command :returns: `!True` when return_code == 0, otherwise `!False`""" pg_ctl = [self._pgcommand('pg_ctl'), cmd] return subprocess.call(pg_ctl + ['-D', self._data_dir] + list(args), **kwargs) == 0
[ "Builds", "and", "executes", "pg_ctl", "command" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L278-L284
[ "def", "pg_ctl", "(", "self", ",", "cmd", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "pg_ctl", "=", "[", "self", ".", "_pgcommand", "(", "'pg_ctl'", ")", ",", "cmd", "]", "return", "subprocess", ".", "call", "(", "pg_ctl", "+", "[", "'-...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.pg_isready
Runs pg_isready to see if PostgreSQL is accepting connections. :returns: 'ok' if PostgreSQL is up, 'reject' if starting up, 'no_resopnse' if not up.
patroni/postgresql.py
def pg_isready(self): """Runs pg_isready to see if PostgreSQL is accepting connections. :returns: 'ok' if PostgreSQL is up, 'reject' if starting up, 'no_resopnse' if not up.""" cmd = [self._pgcommand('pg_isready'), '-p', self._local_address['port'], '-d', self._database] # Host is not...
def pg_isready(self): """Runs pg_isready to see if PostgreSQL is accepting connections. :returns: 'ok' if PostgreSQL is up, 'reject' if starting up, 'no_resopnse' if not up.""" cmd = [self._pgcommand('pg_isready'), '-p', self._local_address['port'], '-d', self._database] # Host is not...
[ "Runs", "pg_isready", "to", "see", "if", "PostgreSQL", "is", "accepting", "connections", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L286-L306
[ "def", "pg_isready", "(", "self", ")", ":", "cmd", "=", "[", "self", ".", "_pgcommand", "(", "'pg_isready'", ")", ",", "'-p'", ",", "self", ".", "_local_address", "[", "'port'", "]", ",", "'-d'", ",", "self", ".", "_database", "]", "# Host is not set if ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.can_rewind
check if pg_rewind executable is there and that pg_controldata indicates we have either wal_log_hints or checksums turned on
patroni/postgresql.py
def can_rewind(self): """ check if pg_rewind executable is there and that pg_controldata indicates we have either wal_log_hints or checksums turned on """ # low-hanging fruit: check if pg_rewind configuration is there if not self.config.get('use_pg_rewind'): retur...
def can_rewind(self): """ check if pg_rewind executable is there and that pg_controldata indicates we have either wal_log_hints or checksums turned on """ # low-hanging fruit: check if pg_rewind configuration is there if not self.config.get('use_pg_rewind'): retur...
[ "check", "if", "pg_rewind", "executable", "is", "there", "and", "that", "pg_controldata", "indicates", "we", "have", "either", "wal_log_hints", "or", "checksums", "turned", "on" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L408-L423
[ "def", "can_rewind", "(", "self", ")", ":", "# low-hanging fruit: check if pg_rewind configuration is there", "if", "not", "self", ".", "config", ".", "get", "(", "'use_pg_rewind'", ")", ":", "return", "False", "cmd", "=", "[", "self", ".", "_pgcommand", "(", "'...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql._query
We are always using the same cursor, therefore this method is not thread-safe!!! You can call it from different threads only if you are holding explicit `AsyncExecutor` lock, because the main thread is always holding this lock when running HA cycle.
patroni/postgresql.py
def _query(self, sql, *params): """We are always using the same cursor, therefore this method is not thread-safe!!! You can call it from different threads only if you are holding explicit `AsyncExecutor` lock, because the main thread is always holding this lock when running HA cycle.""" ...
def _query(self, sql, *params): """We are always using the same cursor, therefore this method is not thread-safe!!! You can call it from different threads only if you are holding explicit `AsyncExecutor` lock, because the main thread is always holding this lock when running HA cycle.""" ...
[ "We", "are", "always", "using", "the", "same", "cursor", "therefore", "this", "method", "is", "not", "thread", "-", "safe!!!", "You", "can", "call", "it", "from", "different", "threads", "only", "if", "you", "are", "holding", "explicit", "AsyncExecutor", "lo...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L493-L514
[ "def", "_query", "(", "self", ",", "sql", ",", "*", "params", ")", ":", "cursor", "=", "None", "try", ":", "cursor", "=", "self", ".", "_cursor", "(", ")", "cursor", ".", "execute", "(", "sql", ",", "params", ")", "return", "cursor", "except", "psy...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.run_bootstrap_post_init
runs a script after initdb or custom bootstrap script is called and waits until completion.
patroni/postgresql.py
def run_bootstrap_post_init(self, config): """ runs a script after initdb or custom bootstrap script is called and waits until completion. """ cmd = config.get('post_bootstrap') or config.get('post_init') if cmd: r = self._local_connect_kwargs if 'host' i...
def run_bootstrap_post_init(self, config): """ runs a script after initdb or custom bootstrap script is called and waits until completion. """ cmd = config.get('post_bootstrap') or config.get('post_init') if cmd: r = self._local_connect_kwargs if 'host' i...
[ "runs", "a", "script", "after", "initdb", "or", "custom", "bootstrap", "script", "is", "called", "and", "waits", "until", "completion", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L603-L641
[ "def", "run_bootstrap_post_init", "(", "self", ",", "config", ")", ":", "cmd", "=", "config", ".", "get", "(", "'post_bootstrap'", ")", "or", "config", ".", "get", "(", "'post_init'", ")", "if", "cmd", ":", "r", "=", "self", ".", "_local_connect_kwargs", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.can_create_replica_without_replication_connection
go through the replication methods to see if there are ones that does not require a working replication connection.
patroni/postgresql.py
def can_create_replica_without_replication_connection(self): """ go through the replication methods to see if there are ones that does not require a working replication connection. """ replica_methods = self._create_replica_methods return any(self.replica_method_can_work_with...
def can_create_replica_without_replication_connection(self): """ go through the replication methods to see if there are ones that does not require a working replication connection. """ replica_methods = self._create_replica_methods return any(self.replica_method_can_work_with...
[ "go", "through", "the", "replication", "methods", "to", "see", "if", "there", "are", "ones", "that", "does", "not", "require", "a", "working", "replication", "connection", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L663-L668
[ "def", "can_create_replica_without_replication_connection", "(", "self", ")", ":", "replica_methods", "=", "self", ".", "_create_replica_methods", "return", "any", "(", "self", ".", "replica_method_can_work_without_replication_connection", "(", "method", ")", "for", "method...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.create_replica
create the replica according to the replica_method defined by the user. this is a list, so we need to loop through all methods the user supplies
patroni/postgresql.py
def create_replica(self, clone_member): """ create the replica according to the replica_method defined by the user. this is a list, so we need to loop through all methods the user supplies """ self.set_state('creating replica') self._sysid = None ...
def create_replica(self, clone_member): """ create the replica according to the replica_method defined by the user. this is a list, so we need to loop through all methods the user supplies """ self.set_state('creating replica') self._sysid = None ...
[ "create", "the", "replica", "according", "to", "the", "replica_method", "defined", "by", "the", "user", ".", "this", "is", "a", "list", "so", "we", "need", "to", "loop", "through", "all", "methods", "the", "user", "supplies" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L670-L759
[ "def", "create_replica", "(", "self", ",", "clone_member", ")", ":", "self", ".", "set_state", "(", "'creating replica'", ")", "self", ".", "_sysid", "=", "None", "is_remote_master", "=", "isinstance", "(", "clone_member", ",", "RemoteMember", ")", "create_repli...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.is_running
Returns PostmasterProcess if one is running on the data directory or None. If most recently seen process is running updates the cached process based on pid file.
patroni/postgresql.py
def is_running(self): """Returns PostmasterProcess if one is running on the data directory or None. If most recently seen process is running updates the cached process based on pid file.""" if self._postmaster_proc: if self._postmaster_proc.is_running(): return self._...
def is_running(self): """Returns PostmasterProcess if one is running on the data directory or None. If most recently seen process is running updates the cached process based on pid file.""" if self._postmaster_proc: if self._postmaster_proc.is_running(): return self._...
[ "Returns", "PostmasterProcess", "if", "one", "is", "running", "on", "the", "data", "directory", "or", "None", ".", "If", "most", "recently", "seen", "process", "is", "running", "updates", "the", "cached", "process", "based", "on", "pid", "file", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L783-L795
[ "def", "is_running", "(", "self", ")", ":", "if", "self", ".", "_postmaster_proc", ":", "if", "self", ".", "_postmaster_proc", ".", "is_running", "(", ")", ":", "return", "self", ".", "_postmaster_proc", "self", ".", "_postmaster_proc", "=", "None", "# we no...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.call_nowait
pick a callback command and call it without waiting for it to finish
patroni/postgresql.py
def call_nowait(self, cb_name): """ pick a callback command and call it without waiting for it to finish """ if self.bootstrapping: return if cb_name in (ACTION_ON_START, ACTION_ON_STOP, ACTION_ON_RESTART, ACTION_ON_ROLE_CHANGE): self.__cb_called = True if self.c...
def call_nowait(self, cb_name): """ pick a callback command and call it without waiting for it to finish """ if self.bootstrapping: return if cb_name in (ACTION_ON_START, ACTION_ON_STOP, ACTION_ON_RESTART, ACTION_ON_ROLE_CHANGE): self.__cb_called = True if self.c...
[ "pick", "a", "callback", "command", "and", "call", "it", "without", "waiting", "for", "it", "to", "finish" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L801-L814
[ "def", "call_nowait", "(", "self", ",", "cb_name", ")", ":", "if", "self", ".", "bootstrapping", ":", "return", "if", "cb_name", "in", "(", "ACTION_ON_START", ",", "ACTION_ON_STOP", ",", "ACTION_ON_RESTART", ",", "ACTION_ON_ROLE_CHANGE", ")", ":", "self", ".",...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.wait_for_port_open
Waits until PostgreSQL opens ports.
patroni/postgresql.py
def wait_for_port_open(self, postmaster, timeout): """Waits until PostgreSQL opens ports.""" for _ in polling_loop(timeout): with self._cancellable_lock: if self._is_cancelled: return False if not postmaster.is_running(): logge...
def wait_for_port_open(self, postmaster, timeout): """Waits until PostgreSQL opens ports.""" for _ in polling_loop(timeout): with self._cancellable_lock: if self._is_cancelled: return False if not postmaster.is_running(): logge...
[ "Waits", "until", "PostgreSQL", "opens", "ports", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L841-L860
[ "def", "wait_for_port_open", "(", "self", ",", "postmaster", ",", "timeout", ")", ":", "for", "_", "in", "polling_loop", "(", "timeout", ")", ":", "with", "self", ".", "_cancellable_lock", ":", "if", "self", ".", "_is_cancelled", ":", "return", "False", "i...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql._build_effective_configuration
It might happen that the current value of one (or more) below parameters stored in the controldata is higher than the value stored in the global cluster configuration. Example: max_connections in global configuration is 100, but in controldata `Current max_connections setting: 200`. If we try t...
patroni/postgresql.py
def _build_effective_configuration(self): """It might happen that the current value of one (or more) below parameters stored in the controldata is higher than the value stored in the global cluster configuration. Example: max_connections in global configuration is 100, but in controldata ...
def _build_effective_configuration(self): """It might happen that the current value of one (or more) below parameters stored in the controldata is higher than the value stored in the global cluster configuration. Example: max_connections in global configuration is 100, but in controldata ...
[ "It", "might", "happen", "that", "the", "current", "value", "of", "one", "(", "or", "more", ")", "below", "parameters", "stored", "in", "the", "controldata", "is", "higher", "than", "the", "value", "stored", "in", "the", "global", "cluster", "configuration",...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L862-L890
[ "def", "_build_effective_configuration", "(", "self", ")", ":", "OPTIONS_MAPPING", "=", "{", "'max_connections'", ":", "'max_connections setting'", ",", "'max_prepared_transactions'", ":", "'max_prepared_xacts setting'", ",", "'max_locks_per_transaction'", ":", "'max_locks_per_...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.start
Start PostgreSQL Waits for postmaster to open ports or terminate so pg_isready can be used to check startup completion or failure. :returns: True if start was initiated and postmaster ports are open, False if start failed
patroni/postgresql.py
def start(self, timeout=None, task=None, block_callbacks=False, role=None): """Start PostgreSQL Waits for postmaster to open ports or terminate so pg_isready can be used to check startup completion or failure. :returns: True if start was initiated and postmaster ports are open, False i...
def start(self, timeout=None, task=None, block_callbacks=False, role=None): """Start PostgreSQL Waits for postmaster to open ports or terminate so pg_isready can be used to check startup completion or failure. :returns: True if start was initiated and postmaster ports are open, False i...
[ "Start", "PostgreSQL" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L892-L961
[ "def", "start", "(", "self", ",", "timeout", "=", "None", ",", "task", "=", "None", ",", "block_callbacks", "=", "False", ",", "role", "=", "None", ")", ":", "# make sure we close all connections established against", "# the former node, otherwise, we might get a stalle...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.stop
Stop PostgreSQL Supports a callback when a safepoint is reached. A safepoint is when no user backend can return a successful commit to users. Currently this means we wait for user backends to close. But in the future alternate mechanisms could be added. :param on_safepoint: This callba...
patroni/postgresql.py
def stop(self, mode='fast', block_callbacks=False, checkpoint=None, on_safepoint=None): """Stop PostgreSQL Supports a callback when a safepoint is reached. A safepoint is when no user backend can return a successful commit to users. Currently this means we wait for user backends to close. But i...
def stop(self, mode='fast', block_callbacks=False, checkpoint=None, on_safepoint=None): """Stop PostgreSQL Supports a callback when a safepoint is reached. A safepoint is when no user backend can return a successful commit to users. Currently this means we wait for user backends to close. But i...
[ "Stop", "PostgreSQL" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L980-L1003
[ "def", "stop", "(", "self", ",", "mode", "=", "'fast'", ",", "block_callbacks", "=", "False", ",", "checkpoint", "=", "None", ",", "on_safepoint", "=", "None", ")", ":", "if", "checkpoint", "is", "None", ":", "checkpoint", "=", "False", "if", "mode", "...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.check_startup_state_changed
Checks if PostgreSQL has completed starting up or failed or still starting. Should only be called when state == 'starting' :returns: True if state was changed from 'starting'
patroni/postgresql.py
def check_startup_state_changed(self): """Checks if PostgreSQL has completed starting up or failed or still starting. Should only be called when state == 'starting' :returns: True if state was changed from 'starting' """ ready = self.pg_isready() if ready == STATE_REJE...
def check_startup_state_changed(self): """Checks if PostgreSQL has completed starting up or failed or still starting. Should only be called when state == 'starting' :returns: True if state was changed from 'starting' """ ready = self.pg_isready() if ready == STATE_REJE...
[ "Checks", "if", "PostgreSQL", "has", "completed", "starting", "up", "or", "failed", "or", "still", "starting", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1062-L1095
[ "def", "check_startup_state_changed", "(", "self", ")", ":", "ready", "=", "self", ".", "pg_isready", "(", ")", "if", "ready", "==", "STATE_REJECT", ":", "return", "False", "elif", "ready", "==", "STATE_NO_RESPONSE", ":", "self", ".", "set_state", "(", "'sta...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.wait_for_startup
Waits for PostgreSQL startup to complete or fail. :returns: True if start was successful, False otherwise
patroni/postgresql.py
def wait_for_startup(self, timeout=None): """Waits for PostgreSQL startup to complete or fail. :returns: True if start was successful, False otherwise""" if not self.is_starting(): # Should not happen logger.warning("wait_for_startup() called when not in starting state")...
def wait_for_startup(self, timeout=None): """Waits for PostgreSQL startup to complete or fail. :returns: True if start was successful, False otherwise""" if not self.is_starting(): # Should not happen logger.warning("wait_for_startup() called when not in starting state")...
[ "Waits", "for", "PostgreSQL", "startup", "to", "complete", "or", "fail", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1097-L1113
[ "def", "wait_for_startup", "(", "self", ",", "timeout", "=", "None", ")", ":", "if", "not", "self", ".", "is_starting", "(", ")", ":", "# Should not happen", "logger", ".", "warning", "(", "\"wait_for_startup() called when not in starting state\"", ")", "while", "...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.restart
Restarts PostgreSQL. When timeout parameter is set the call will block either until PostgreSQL has started, failed to start or timeout arrives. :returns: True when restart was successful and timeout did not expire when waiting.
patroni/postgresql.py
def restart(self, timeout=None, task=None, block_callbacks=False, role=None): """Restarts PostgreSQL. When timeout parameter is set the call will block either until PostgreSQL has started, failed to start or timeout arrives. :returns: True when restart was successful and timeout did no...
def restart(self, timeout=None, task=None, block_callbacks=False, role=None): """Restarts PostgreSQL. When timeout parameter is set the call will block either until PostgreSQL has started, failed to start or timeout arrives. :returns: True when restart was successful and timeout did no...
[ "Restarts", "PostgreSQL", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1115-L1129
[ "def", "restart", "(", "self", ",", "timeout", "=", "None", ",", "task", "=", "None", ",", "block_callbacks", "=", "False", ",", "role", "=", "None", ")", ":", "self", ".", "set_state", "(", "'restarting'", ")", "if", "not", "block_callbacks", ":", "se...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql._replace_pg_hba
Replace pg_hba.conf content in the PGDATA if hba_file is not defined in the `postgresql.parameters` and pg_hba is defined in `postgresql` configuration section. :returns: True if pg_hba.conf was rewritten.
patroni/postgresql.py
def _replace_pg_hba(self): """ Replace pg_hba.conf content in the PGDATA if hba_file is not defined in the `postgresql.parameters` and pg_hba is defined in `postgresql` configuration section. :returns: True if pg_hba.conf was rewritten. """ # when we are doing custom bo...
def _replace_pg_hba(self): """ Replace pg_hba.conf content in the PGDATA if hba_file is not defined in the `postgresql.parameters` and pg_hba is defined in `postgresql` configuration section. :returns: True if pg_hba.conf was rewritten. """ # when we are doing custom bo...
[ "Replace", "pg_hba", ".", "conf", "content", "in", "the", "PGDATA", "if", "hba_file", "is", "not", "defined", "in", "the", "postgresql", ".", "parameters", "and", "pg_hba", "is", "defined", "in", "postgresql", "configuration", "section", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1163-L1192
[ "def", "_replace_pg_hba", "(", "self", ")", ":", "# when we are doing custom bootstrap we assume that we don't know superuser password", "# and in order to be able to change it, we are opening trust access from a certain address", "if", "self", ".", "_running_custom_bootstrap", ":", "addre...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql._replace_pg_ident
Replace pg_ident.conf content in the PGDATA if ident_file is not defined in the `postgresql.parameters` and pg_ident is defined in the `postgresql` section. :returns: True if pg_ident.conf was rewritten.
patroni/postgresql.py
def _replace_pg_ident(self): """ Replace pg_ident.conf content in the PGDATA if ident_file is not defined in the `postgresql.parameters` and pg_ident is defined in the `postgresql` section. :returns: True if pg_ident.conf was rewritten. """ if not self._server_parameter...
def _replace_pg_ident(self): """ Replace pg_ident.conf content in the PGDATA if ident_file is not defined in the `postgresql.parameters` and pg_ident is defined in the `postgresql` section. :returns: True if pg_ident.conf was rewritten. """ if not self._server_parameter...
[ "Replace", "pg_ident", ".", "conf", "content", "in", "the", "PGDATA", "if", "ident_file", "is", "not", "defined", "in", "the", "postgresql", ".", "parameters", "and", "pg_ident", "is", "defined", "in", "the", "postgresql", "section", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1194-L1207
[ "def", "_replace_pg_ident", "(", "self", ")", ":", "if", "not", "self", ".", "_server_parameters", ".", "get", "(", "'ident_file'", ")", "and", "self", ".", "config", ".", "get", "(", "'pg_ident'", ")", ":", "with", "open", "(", "self", ".", "_pg_ident_c...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.controldata
return the contents of pg_controldata, or non-True value if pg_controldata call failed
patroni/postgresql.py
def controldata(self): """ return the contents of pg_controldata, or non-True value if pg_controldata call failed """ result = {} # Don't try to call pg_controldata during backup restore if self._version_file_exists() and self.state != 'creating replica': try: ...
def controldata(self): """ return the contents of pg_controldata, or non-True value if pg_controldata call failed """ result = {} # Don't try to call pg_controldata during backup restore if self._version_file_exists() and self.state != 'creating replica': try: ...
[ "return", "the", "contents", "of", "pg_controldata", "or", "non", "-", "True", "value", "if", "pg_controldata", "call", "failed" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1256-L1273
[ "def", "controldata", "(", "self", ")", ":", "result", "=", "{", "}", "# Don't try to call pg_controldata during backup restore", "if", "self", ".", "_version_file_exists", "(", ")", "and", "self", ".", "state", "!=", "'creating replica'", ":", "try", ":", "env", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.save_configuration_files
copy postgresql.conf to postgresql.conf.backup to be able to retrive configuration files - originally stored as symlinks, those are normally skipped by pg_basebackup - in case of WAL-E basebackup (see http://comments.gmane.org/gmane.comp.db.postgresql.wal-e/239)
patroni/postgresql.py
def save_configuration_files(self): """ copy postgresql.conf to postgresql.conf.backup to be able to retrive configuration files - originally stored as symlinks, those are normally skipped by pg_basebackup - in case of WAL-E basebackup (see http://comments.gmane.org/gmane.com...
def save_configuration_files(self): """ copy postgresql.conf to postgresql.conf.backup to be able to retrive configuration files - originally stored as symlinks, those are normally skipped by pg_basebackup - in case of WAL-E basebackup (see http://comments.gmane.org/gmane.com...
[ "copy", "postgresql", ".", "conf", "to", "postgresql", ".", "conf", ".", "backup", "to", "be", "able", "to", "retrive", "configuration", "files", "-", "originally", "stored", "as", "symlinks", "those", "are", "normally", "skipped", "by", "pg_basebackup", "-", ...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1516-L1530
[ "def", "save_configuration_files", "(", "self", ")", ":", "try", ":", "for", "f", "in", "self", ".", "_configuration_to_save", ":", "config_file", "=", "os", ".", "path", ".", "join", "(", "self", ".", "_config_dir", ",", "f", ")", "backup_file", "=", "o...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.restore_configuration_files
restore a previously saved postgresql.conf
patroni/postgresql.py
def restore_configuration_files(self): """ restore a previously saved postgresql.conf """ try: for f in self._configuration_to_save: config_file = os.path.join(self._config_dir, f) backup_file = os.path.join(self._data_dir, f + '.backup') if no...
def restore_configuration_files(self): """ restore a previously saved postgresql.conf """ try: for f in self._configuration_to_save: config_file = os.path.join(self._config_dir, f) backup_file = os.path.join(self._data_dir, f + '.backup') if no...
[ "restore", "a", "previously", "saved", "postgresql", ".", "conf" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1532-L1545
[ "def", "restore_configuration_files", "(", "self", ")", ":", "try", ":", "for", "f", "in", "self", ".", "_configuration_to_save", ":", "config_file", "=", "os", ".", "path", ".", "join", "(", "self", ".", "_config_dir", ",", "f", ")", "backup_file", "=", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.clone
- initialize the replica from an existing member (master or replica) - initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup)
patroni/postgresql.py
def clone(self, clone_member): """ - initialize the replica from an existing member (master or replica) - initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup) ...
def clone(self, clone_member): """ - initialize the replica from an existing member (master or replica) - initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup) ...
[ "-", "initialize", "the", "replica", "from", "an", "existing", "member", "(", "master", "or", "replica", ")", "-", "initialize", "the", "replica", "using", "the", "replica", "creation", "method", "that", "works", "without", "the", "replication", "connection", ...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1699-L1712
[ "def", "clone", "(", "self", ",", "clone_member", ")", ":", "self", ".", "_rewind_state", "=", "REWIND_STATUS", ".", "INITIAL", "ret", "=", "self", ".", "create_replica", "(", "clone_member", ")", "==", "0", "if", "ret", ":", "self", ".", "_post_restore", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.bootstrap
Initialize a new node from scratch and start it.
patroni/postgresql.py
def bootstrap(self, config): """ Initialize a new node from scratch and start it. """ pg_hba = config.get('pg_hba', []) method = config.get('method') or 'initdb' self._running_custom_bootstrap = method != 'initdb' and method in config and 'command' in config[method] if self._runn...
def bootstrap(self, config): """ Initialize a new node from scratch and start it. """ pg_hba = config.get('pg_hba', []) method = config.get('method') or 'initdb' self._running_custom_bootstrap = method != 'initdb' and method in config and 'command' in config[method] if self._runn...
[ "Initialize", "a", "new", "node", "from", "scratch", "and", "start", "it", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1714-L1725
[ "def", "bootstrap", "(", "self", ",", "config", ")", ":", "pg_hba", "=", "config", ".", "get", "(", "'pg_hba'", ",", "[", "]", ")", "method", "=", "config", ".", "get", "(", "'method'", ")", "or", "'initdb'", "self", ".", "_running_custom_bootstrap", "...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.pick_synchronous_standby
Finds the best candidate to be the synchronous standby. Current synchronous standby is always preferred, unless it has disconnected or does not want to be a synchronous standby any longer. :returns tuple of candidate name or None, and bool showing if the member is the active synchronous standb...
patroni/postgresql.py
def pick_synchronous_standby(self, cluster): """Finds the best candidate to be the synchronous standby. Current synchronous standby is always preferred, unless it has disconnected or does not want to be a synchronous standby any longer. :returns tuple of candidate name or None, and boo...
def pick_synchronous_standby(self, cluster): """Finds the best candidate to be the synchronous standby. Current synchronous standby is always preferred, unless it has disconnected or does not want to be a synchronous standby any longer. :returns tuple of candidate name or None, and boo...
[ "Finds", "the", "best", "candidate", "to", "be", "the", "synchronous", "standby", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1839-L1870
[ "def", "pick_synchronous_standby", "(", "self", ",", "cluster", ")", ":", "current", "=", "cluster", ".", "sync", ".", "sync_standby", "current", "=", "current", ".", "lower", "(", ")", "if", "current", "else", "current", "members", "=", "{", "m", ".", "...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.set_synchronous_standby
Sets a node to be synchronous standby and if changed does a reload for PostgreSQL.
patroni/postgresql.py
def set_synchronous_standby(self, name): """Sets a node to be synchronous standby and if changed does a reload for PostgreSQL.""" if name and name != '*': name = quote_ident(name) if name != self._synchronous_standby_names: if name is None: self._server_pa...
def set_synchronous_standby(self, name): """Sets a node to be synchronous standby and if changed does a reload for PostgreSQL.""" if name and name != '*': name = quote_ident(name) if name != self._synchronous_standby_names: if name is None: self._server_pa...
[ "Sets", "a", "node", "to", "be", "synchronous", "standby", "and", "if", "changed", "does", "a", "reload", "for", "PostgreSQL", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1872-L1884
[ "def", "set_synchronous_standby", "(", "self", ",", "name", ")", ":", "if", "name", "and", "name", "!=", "'*'", ":", "name", "=", "quote_ident", "(", "name", ")", "if", "name", "!=", "self", ".", "_synchronous_standby_names", ":", "if", "name", "is", "No...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.postgres_version_to_int
Convert the server_version to integer >>> Postgresql.postgres_version_to_int('9.5.3') 90503 >>> Postgresql.postgres_version_to_int('9.3.13') 90313 >>> Postgresql.postgres_version_to_int('10.1') 100001 >>> Postgresql.postgres_version_to_int('10') # doctest: +IGNO...
patroni/postgresql.py
def postgres_version_to_int(pg_version): """Convert the server_version to integer >>> Postgresql.postgres_version_to_int('9.5.3') 90503 >>> Postgresql.postgres_version_to_int('9.3.13') 90313 >>> Postgresql.postgres_version_to_int('10.1') 100001 >>> Postgr...
def postgres_version_to_int(pg_version): """Convert the server_version to integer >>> Postgresql.postgres_version_to_int('9.5.3') 90503 >>> Postgresql.postgres_version_to_int('9.3.13') 90313 >>> Postgresql.postgres_version_to_int('10.1') 100001 >>> Postgr...
[ "Convert", "the", "server_version", "to", "integer" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1887-L1923
[ "def", "postgres_version_to_int", "(", "pg_version", ")", ":", "try", ":", "components", "=", "list", "(", "map", "(", "int", ",", "pg_version", ".", "split", "(", "'.'", ")", ")", ")", "except", "ValueError", ":", "raise", "PostgresException", "(", "'Inva...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.read_postmaster_opts
returns the list of option names/values from postgres.opts, Empty dict if read failed or no file
patroni/postgresql.py
def read_postmaster_opts(self): """returns the list of option names/values from postgres.opts, Empty dict if read failed or no file""" result = {} try: with open(os.path.join(self._data_dir, 'postmaster.opts')) as f: data = f.read() for opt in data.spl...
def read_postmaster_opts(self): """returns the list of option names/values from postgres.opts, Empty dict if read failed or no file""" result = {} try: with open(os.path.join(self._data_dir, 'postmaster.opts')) as f: data = f.read() for opt in data.spl...
[ "returns", "the", "list", "of", "option", "names", "/", "values", "from", "postgres", ".", "opts", "Empty", "dict", "if", "read", "failed", "or", "no", "file" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1935-L1947
[ "def", "read_postmaster_opts", "(", "self", ")", ":", "result", "=", "{", "}", "try", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(", "self", ".", "_data_dir", ",", "'postmaster.opts'", ")", ")", "as", "f", ":", "data", "=", "f", "."...
f6d29081c90af52064b981cdd877a07338d86038
train
Postgresql.single_user_mode
run a given command in a single-user mode. If the command is empty - then just start and stop
patroni/postgresql.py
def single_user_mode(self, command=None, options=None): """run a given command in a single-user mode. If the command is empty - then just start and stop""" cmd = [self._pgcommand('postgres'), '--single', '-D', self._data_dir] for opt, val in sorted((options or {}).items()): cmd.exten...
def single_user_mode(self, command=None, options=None): """run a given command in a single-user mode. If the command is empty - then just start and stop""" cmd = [self._pgcommand('postgres'), '--single', '-D', self._data_dir] for opt, val in sorted((options or {}).items()): cmd.exten...
[ "run", "a", "given", "command", "in", "a", "single", "-", "user", "mode", ".", "If", "the", "command", "is", "empty", "-", "then", "just", "start", "and", "stop" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1949-L1956
[ "def", "single_user_mode", "(", "self", ",", "command", "=", "None", ",", "options", "=", "None", ")", ":", "cmd", "=", "[", "self", ".", "_pgcommand", "(", "'postgres'", ")", ",", "'--single'", ",", "'-D'", ",", "self", ".", "_data_dir", "]", "for", ...
f6d29081c90af52064b981cdd877a07338d86038
train
deep_compare
>>> deep_compare({'1': None}, {}) False >>> deep_compare({'1': {}}, {'1': None}) False >>> deep_compare({'1': [1]}, {'1': [2]}) False >>> deep_compare({'1': 2}, {'1': '2'}) True >>> deep_compare({'1': {'2': [3, 4]}}, {'1': {'2': [3, 4]}}) True
patroni/utils.py
def deep_compare(obj1, obj2): """ >>> deep_compare({'1': None}, {}) False >>> deep_compare({'1': {}}, {'1': None}) False >>> deep_compare({'1': [1]}, {'1': [2]}) False >>> deep_compare({'1': 2}, {'1': '2'}) True >>> deep_compare({'1': {'2': [3, 4]}}, {'1': {'2': [3, 4]}}) Tru...
def deep_compare(obj1, obj2): """ >>> deep_compare({'1': None}, {}) False >>> deep_compare({'1': {}}, {'1': None}) False >>> deep_compare({'1': [1]}, {'1': [2]}) False >>> deep_compare({'1': 2}, {'1': '2'}) True >>> deep_compare({'1': {'2': [3, 4]}}, {'1': {'2': [3, 4]}}) Tru...
[ ">>>", "deep_compare", "(", "{", "1", ":", "None", "}", "{}", ")", "False", ">>>", "deep_compare", "(", "{", "1", ":", "{}", "}", "{", "1", ":", "None", "}", ")", "False", ">>>", "deep_compare", "(", "{", "1", ":", "[", "1", "]", "}", "{", "1...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L10-L33
[ "def", "deep_compare", "(", "obj1", ",", "obj2", ")", ":", "if", "set", "(", "list", "(", "obj1", ".", "keys", "(", ")", ")", ")", "!=", "set", "(", "list", "(", "obj2", ".", "keys", "(", ")", ")", ")", ":", "# Objects have different sets of keys", ...
f6d29081c90af52064b981cdd877a07338d86038
train
patch_config
recursively 'patch' `config` with `data` :returns: `!True` if the `config` was changed
patroni/utils.py
def patch_config(config, data): """recursively 'patch' `config` with `data` :returns: `!True` if the `config` was changed""" is_changed = False for name, value in data.items(): if value is None: if config.pop(name, None) is not None: is_changed = True elif nam...
def patch_config(config, data): """recursively 'patch' `config` with `data` :returns: `!True` if the `config` was changed""" is_changed = False for name, value in data.items(): if value is None: if config.pop(name, None) is not None: is_changed = True elif nam...
[ "recursively", "patch", "config", "with", "data", ":", "returns", ":", "!True", "if", "the", "config", "was", "changed" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L36-L58
[ "def", "patch_config", "(", "config", ",", "data", ")", ":", "is_changed", "=", "False", "for", "name", ",", "value", "in", "data", ".", "items", "(", ")", ":", "if", "value", "is", "None", ":", "if", "config", ".", "pop", "(", "name", ",", "None",...
f6d29081c90af52064b981cdd877a07338d86038
train
parse_bool
>>> parse_bool(1) True >>> parse_bool('off') False >>> parse_bool('foo')
patroni/utils.py
def parse_bool(value): """ >>> parse_bool(1) True >>> parse_bool('off') False >>> parse_bool('foo') """ value = str(value).lower() if value in ('on', 'true', 'yes', '1'): return True if value in ('off', 'false', 'no', '0'): return False
def parse_bool(value): """ >>> parse_bool(1) True >>> parse_bool('off') False >>> parse_bool('foo') """ value = str(value).lower() if value in ('on', 'true', 'yes', '1'): return True if value in ('off', 'false', 'no', '0'): return False
[ ">>>", "parse_bool", "(", "1", ")", "True", ">>>", "parse_bool", "(", "off", ")", "False", ">>>", "parse_bool", "(", "foo", ")" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L61-L73
[ "def", "parse_bool", "(", "value", ")", ":", "value", "=", "str", "(", "value", ")", ".", "lower", "(", ")", "if", "value", "in", "(", "'on'", ",", "'true'", ",", "'yes'", ",", "'1'", ")", ":", "return", "True", "if", "value", "in", "(", "'off'",...
f6d29081c90af52064b981cdd877a07338d86038
train
strtol
As most as possible close equivalent of strtol(3) function (with base=0), used by postgres to parse parameter values. >>> strtol(0) == (0, '') True >>> strtol(1) == (1, '') True >>> strtol(9) == (9, '') True >>> strtol(' +0x400MB') == (1024, 'MB') True >>> strtol(' -070d') == ...
patroni/utils.py
def strtol(value, strict=True): """As most as possible close equivalent of strtol(3) function (with base=0), used by postgres to parse parameter values. >>> strtol(0) == (0, '') True >>> strtol(1) == (1, '') True >>> strtol(9) == (9, '') True >>> strtol(' +0x400MB') == (1024, 'MB'...
def strtol(value, strict=True): """As most as possible close equivalent of strtol(3) function (with base=0), used by postgres to parse parameter values. >>> strtol(0) == (0, '') True >>> strtol(1) == (1, '') True >>> strtol(9) == (9, '') True >>> strtol(' +0x400MB') == (1024, 'MB'...
[ "As", "most", "as", "possible", "close", "equivalent", "of", "strtol", "(", "3", ")", "function", "(", "with", "base", "=", "0", ")", "used", "by", "postgres", "to", "parse", "parameter", "values", ".", ">>>", "strtol", "(", "0", ")", "==", "(", "0",...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L76-L126
[ "def", "strtol", "(", "value", ",", "strict", "=", "True", ")", ":", "value", "=", "str", "(", "value", ")", ".", "strip", "(", ")", "ln", "=", "len", "(", "value", ")", "i", "=", "0", "# skip sign:", "if", "i", "<", "ln", "and", "value", "[", ...
f6d29081c90af52064b981cdd877a07338d86038
train
parse_int
>>> parse_int('1') == 1 True >>> parse_int(' 0x400 MB ', '16384kB') == 64 True >>> parse_int('1MB', 'kB') == 1024 True >>> parse_int('1000 ms', 's') == 1 True >>> parse_int('1GB', 'MB') is None True >>> parse_int(0) == 0 True
patroni/utils.py
def parse_int(value, base_unit=None): """ >>> parse_int('1') == 1 True >>> parse_int(' 0x400 MB ', '16384kB') == 64 True >>> parse_int('1MB', 'kB') == 1024 True >>> parse_int('1000 ms', 's') == 1 True >>> parse_int('1GB', 'MB') is None True >>> parse_int(0) == 0 True ...
def parse_int(value, base_unit=None): """ >>> parse_int('1') == 1 True >>> parse_int(' 0x400 MB ', '16384kB') == 64 True >>> parse_int('1MB', 'kB') == 1024 True >>> parse_int('1000 ms', 's') == 1 True >>> parse_int('1GB', 'MB') is None True >>> parse_int(0) == 0 True ...
[ ">>>", "parse_int", "(", "1", ")", "==", "1", "True", ">>>", "parse_int", "(", "0x400", "MB", "16384kB", ")", "==", "64", "True", ">>>", "parse_int", "(", "1MB", "kB", ")", "==", "1024", "True", ">>>", "parse_int", "(", "1000", "ms", "s", ")", "=="...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L129-L167
[ "def", "parse_int", "(", "value", ",", "base_unit", "=", "None", ")", ":", "convert", "=", "{", "'kB'", ":", "{", "'kB'", ":", "1", ",", "'MB'", ":", "1024", ",", "'GB'", ":", "1024", "*", "1024", ",", "'TB'", ":", "1024", "*", "1024", "*", "10...
f6d29081c90af52064b981cdd877a07338d86038
train
compare_values
>>> compare_values('enum', None, 'remote_write', 'REMOTE_WRITE') True >>> compare_values('real', None, '1.23', 1.23) True
patroni/utils.py
def compare_values(vartype, unit, old_value, new_value): """ >>> compare_values('enum', None, 'remote_write', 'REMOTE_WRITE') True >>> compare_values('real', None, '1.23', 1.23) True """ # if the integer or bool new_value is not correct this function will return False if vartype == 'boo...
def compare_values(vartype, unit, old_value, new_value): """ >>> compare_values('enum', None, 'remote_write', 'REMOTE_WRITE') True >>> compare_values('real', None, '1.23', 1.23) True """ # if the integer or bool new_value is not correct this function will return False if vartype == 'boo...
[ ">>>", "compare_values", "(", "enum", "None", "remote_write", "REMOTE_WRITE", ")", "True", ">>>", "compare_values", "(", "real", "None", "1", ".", "23", "1", ".", "23", ")", "True" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L170-L189
[ "def", "compare_values", "(", "vartype", ",", "unit", ",", "old_value", ",", "new_value", ")", ":", "# if the integer or bool new_value is not correct this function will return False", "if", "vartype", "==", "'bool'", ":", "old_value", "=", "parse_bool", "(", "old_value",...
f6d29081c90af52064b981cdd877a07338d86038
train
polling_loop
Returns an iterator that returns values until timeout has passed. Timeout is measured from start of iteration.
patroni/utils.py
def polling_loop(timeout, interval=1): """Returns an iterator that returns values until timeout has passed. Timeout is measured from start of iteration.""" start_time = time.time() iteration = 0 end_time = start_time + timeout while time.time() < end_time: yield iteration iteration +...
def polling_loop(timeout, interval=1): """Returns an iterator that returns values until timeout has passed. Timeout is measured from start of iteration.""" start_time = time.time() iteration = 0 end_time = start_time + timeout while time.time() < end_time: yield iteration iteration +...
[ "Returns", "an", "iterator", "that", "returns", "values", "until", "timeout", "has", "passed", ".", "Timeout", "is", "measured", "from", "start", "of", "iteration", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L269-L277
[ "def", "polling_loop", "(", "timeout", ",", "interval", "=", "1", ")", ":", "start_time", "=", "time", ".", "time", "(", ")", "iteration", "=", "0", "end_time", "=", "start_time", "+", "timeout", "while", "time", ".", "time", "(", ")", "<", "end_time",...
f6d29081c90af52064b981cdd877a07338d86038
train
Retry.reset
Reset the attempt counter
patroni/utils.py
def reset(self): """Reset the attempt counter""" self._attempts = 0 self._cur_delay = self.delay self._cur_stoptime = None
def reset(self): """Reset the attempt counter""" self._attempts = 0 self._cur_delay = self.delay self._cur_stoptime = None
[ "Reset", "the", "attempt", "counter" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L228-L232
[ "def", "reset", "(", "self", ")", ":", "self", ".", "_attempts", "=", "0", "self", ".", "_cur_delay", "=", "self", ".", "delay", "self", ".", "_cur_stoptime", "=", "None" ]
f6d29081c90af52064b981cdd877a07338d86038
train
Retry.copy
Return a clone of this retry manager
patroni/utils.py
def copy(self): """Return a clone of this retry manager""" return Retry(max_tries=self.max_tries, delay=self.delay, backoff=self.backoff, max_jitter=self.max_jitter / 100.0, max_delay=self.max_delay, sleep_func=self.sleep_func, deadline=self.deadline, retry_exce...
def copy(self): """Return a clone of this retry manager""" return Retry(max_tries=self.max_tries, delay=self.delay, backoff=self.backoff, max_jitter=self.max_jitter / 100.0, max_delay=self.max_delay, sleep_func=self.sleep_func, deadline=self.deadline, retry_exce...
[ "Return", "a", "clone", "of", "this", "retry", "manager" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/utils.py#L234-L238
[ "def", "copy", "(", "self", ")", ":", "return", "Retry", "(", "max_tries", "=", "self", ".", "max_tries", ",", "delay", "=", "self", ".", "delay", ",", "backoff", "=", "self", ".", "backoff", ",", "max_jitter", "=", "self", ".", "max_jitter", "/", "1...
f6d29081c90af52064b981cdd877a07338d86038
train
check_auth
Decorator function to check authorization header. Usage example: @check_auth def do_PUT_foo(): pass
patroni/api.py
def check_auth(func): """Decorator function to check authorization header. Usage example: @check_auth def do_PUT_foo(): pass """ def wrapper(handler, *args, **kwargs): if handler.check_auth_header(): return func(handler, *args, **kwargs) return wrapper
def check_auth(func): """Decorator function to check authorization header. Usage example: @check_auth def do_PUT_foo(): pass """ def wrapper(handler, *args, **kwargs): if handler.check_auth_header(): return func(handler, *args, **kwargs) return wrapper
[ "Decorator", "function", "to", "check", "authorization", "header", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/api.py#L21-L32
[ "def", "check_auth", "(", "func", ")", ":", "def", "wrapper", "(", "handler", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "handler", ".", "check_auth_header", "(", ")", ":", "return", "func", "(", "handler", ",", "*", "args", ",", "*...
f6d29081c90af52064b981cdd877a07338d86038
train
RestApiHandler.do_GET
Default method for processing all GET requests which can not be routed to other methods
patroni/api.py
def do_GET(self, write_status_code_only=False): """Default method for processing all GET requests which can not be routed to other methods""" path = '/master' if self.path == '/' else self.path response = self.get_postgresql_status() patroni = self.server.patroni cluster = patr...
def do_GET(self, write_status_code_only=False): """Default method for processing all GET requests which can not be routed to other methods""" path = '/master' if self.path == '/' else self.path response = self.get_postgresql_status() patroni = self.server.patroni cluster = patr...
[ "Default", "method", "for", "processing", "all", "GET", "requests", "which", "can", "not", "be", "routed", "to", "other", "methods" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/api.py#L79-L116
[ "def", "do_GET", "(", "self", ",", "write_status_code_only", "=", "False", ")", ":", "path", "=", "'/master'", "if", "self", ".", "path", "==", "'/'", "else", "self", ".", "path", "response", "=", "self", ".", "get_postgresql_status", "(", ")", "patroni", ...
f6d29081c90af52064b981cdd877a07338d86038
train
RestApiHandler.parse_schedule
parses the given schedule and validates at
patroni/api.py
def parse_schedule(schedule, action): """ parses the given schedule and validates at """ error = None scheduled_at = None try: scheduled_at = dateutil.parser.parse(schedule) if scheduled_at.tzinfo is None: error = 'Timezone information is mandatory...
def parse_schedule(schedule, action): """ parses the given schedule and validates at """ error = None scheduled_at = None try: scheduled_at = dateutil.parser.parse(schedule) if scheduled_at.tzinfo is None: error = 'Timezone information is mandatory...
[ "parses", "the", "given", "schedule", "and", "validates", "at" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/api.py#L186-L204
[ "def", "parse_schedule", "(", "schedule", ",", "action", ")", ":", "error", "=", "None", "scheduled_at", "=", "None", "try", ":", "scheduled_at", "=", "dateutil", ".", "parser", ".", "parse", "(", "schedule", ")", "if", "scheduled_at", ".", "tzinfo", "is",...
f6d29081c90af52064b981cdd877a07338d86038
train
RestApiHandler.parse_request
Override parse_request method to enrich basic functionality of `BaseHTTPRequestHandler` class Original class can only invoke do_GET, do_POST, do_PUT, etc method implementations if they are defined. But we would like to have at least some simple routing mechanism, i.e.: GET /uri1/part2 request s...
patroni/api.py
def parse_request(self): """Override parse_request method to enrich basic functionality of `BaseHTTPRequestHandler` class Original class can only invoke do_GET, do_POST, do_PUT, etc method implementations if they are defined. But we would like to have at least some simple routing mechanism, i.e...
def parse_request(self): """Override parse_request method to enrich basic functionality of `BaseHTTPRequestHandler` class Original class can only invoke do_GET, do_POST, do_PUT, etc method implementations if they are defined. But we would like to have at least some simple routing mechanism, i.e...
[ "Override", "parse_request", "method", "to", "enrich", "basic", "functionality", "of", "BaseHTTPRequestHandler", "class" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/api.py#L387-L403
[ "def", "parse_request", "(", "self", ")", ":", "ret", "=", "BaseHTTPRequestHandler", ".", "parse_request", "(", "self", ")", "if", "ret", ":", "mname", "=", "self", ".", "path", ".", "lstrip", "(", "'/'", ")", ".", "split", "(", "'/'", ")", "[", "0",...
f6d29081c90af52064b981cdd877a07338d86038
train
Config._load_config_file
Loads config.yaml from filesystem and applies some values which were set via ENV
patroni/config.py
def _load_config_file(self): """Loads config.yaml from filesystem and applies some values which were set via ENV""" with open(self._config_file) as f: config = yaml.safe_load(f) patch_config(config, self.__environment_configuration) return config
def _load_config_file(self): """Loads config.yaml from filesystem and applies some values which were set via ENV""" with open(self._config_file) as f: config = yaml.safe_load(f) patch_config(config, self.__environment_configuration) return config
[ "Loads", "config", ".", "yaml", "from", "filesystem", "and", "applies", "some", "values", "which", "were", "set", "via", "ENV" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/config.py#L105-L110
[ "def", "_load_config_file", "(", "self", ")", ":", "with", "open", "(", "self", ".", "_config_file", ")", "as", "f", ":", "config", "=", "yaml", ".", "safe_load", "(", "f", ")", "patch_config", "(", "config", ",", "self", ".", "__environment_configuration"...
f6d29081c90af52064b981cdd877a07338d86038
train
slot_name_from_member_name
Translate member name to valid PostgreSQL slot name. PostgreSQL replication slot names must be valid PostgreSQL names. This function maps the wider space of member names to valid PostgreSQL names. Names are lowercased, dashes and periods common in hostnames are replaced with underscores, other characters a...
patroni/dcs/__init__.py
def slot_name_from_member_name(member_name): """Translate member name to valid PostgreSQL slot name. PostgreSQL replication slot names must be valid PostgreSQL names. This function maps the wider space of member names to valid PostgreSQL names. Names are lowercased, dashes and periods common in hostnames ...
def slot_name_from_member_name(member_name): """Translate member name to valid PostgreSQL slot name. PostgreSQL replication slot names must be valid PostgreSQL names. This function maps the wider space of member names to valid PostgreSQL names. Names are lowercased, dashes and periods common in hostnames ...
[ "Translate", "member", "name", "to", "valid", "PostgreSQL", "slot", "name", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L26-L39
[ "def", "slot_name_from_member_name", "(", "member_name", ")", ":", "def", "replace_char", "(", "match", ")", ":", "c", "=", "match", ".", "group", "(", "0", ")", "return", "'_'", "if", "c", "in", "'-.'", "else", "\"u{:04d}\"", ".", "format", "(", "ord", ...
f6d29081c90af52064b981cdd877a07338d86038
train
parse_connection_string
Original Governor stores connection strings for each cluster members if a following format: postgres://{username}:{password}@{connect_address}/postgres Since each of our patroni instances provides own REST API endpoint it's good to store this information in DCS among with postgresql connection string. I...
patroni/dcs/__init__.py
def parse_connection_string(value): """Original Governor stores connection strings for each cluster members if a following format: postgres://{username}:{password}@{connect_address}/postgres Since each of our patroni instances provides own REST API endpoint it's good to store this information in DCS...
def parse_connection_string(value): """Original Governor stores connection strings for each cluster members if a following format: postgres://{username}:{password}@{connect_address}/postgres Since each of our patroni instances provides own REST API endpoint it's good to store this information in DCS...
[ "Original", "Governor", "stores", "connection", "strings", "for", "each", "cluster", "members", "if", "a", "following", "format", ":", "postgres", ":", "//", "{", "username", "}", ":", "{", "password", "}", "@", "{", "connect_address", "}", "/", "postgres", ...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L42-L56
[ "def", "parse_connection_string", "(", "value", ")", ":", "scheme", ",", "netloc", ",", "path", ",", "params", ",", "query", ",", "fragment", "=", "urlparse", "(", "value", ")", "conn_url", "=", "urlunparse", "(", "(", "scheme", ",", "netloc", ",", "path...
f6d29081c90af52064b981cdd877a07338d86038
train
dcs_modules
Get names of DCS modules, depending on execution environment. If being packaged with PyInstaller, modules aren't discoverable dynamically by scanning source directory because `FrozenImporter` doesn't implement `iter_modules` method. But it is still possible to find all potential DCS modules by iterating thr...
patroni/dcs/__init__.py
def dcs_modules(): """Get names of DCS modules, depending on execution environment. If being packaged with PyInstaller, modules aren't discoverable dynamically by scanning source directory because `FrozenImporter` doesn't implement `iter_modules` method. But it is still possible to find all potential DCS mo...
def dcs_modules(): """Get names of DCS modules, depending on execution environment. If being packaged with PyInstaller, modules aren't discoverable dynamically by scanning source directory because `FrozenImporter` doesn't implement `iter_modules` method. But it is still possible to find all potential DCS mo...
[ "Get", "names", "of", "DCS", "modules", "depending", "on", "execution", "environment", ".", "If", "being", "packaged", "with", "PyInstaller", "modules", "aren", "t", "discoverable", "dynamically", "by", "scanning", "source", "directory", "because", "FrozenImporter",...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L59-L72
[ "def", "dcs_modules", "(", ")", ":", "dcs_dirname", "=", "os", ".", "path", ".", "dirname", "(", "__file__", ")", "module_prefix", "=", "__package__", "+", "'.'", "if", "getattr", "(", "sys", ",", "'frozen'", ",", "False", ")", ":", "importer", "=", "p...
f6d29081c90af52064b981cdd877a07338d86038
train
Member.from_node
>>> Member.from_node(-1, '', '', '{"conn_url": "postgres://foo@bar/postgres"}') is not None True >>> Member.from_node(-1, '', '', '{') Member(index=-1, name='', session='', data={})
patroni/dcs/__init__.py
def from_node(index, name, session, data): """ >>> Member.from_node(-1, '', '', '{"conn_url": "postgres://foo@bar/postgres"}') is not None True >>> Member.from_node(-1, '', '', '{') Member(index=-1, name='', session='', data={}) """ if data.startswith('postgres'):...
def from_node(index, name, session, data): """ >>> Member.from_node(-1, '', '', '{"conn_url": "postgres://foo@bar/postgres"}') is not None True >>> Member.from_node(-1, '', '', '{') Member(index=-1, name='', session='', data={}) """ if data.startswith('postgres'):...
[ ">>>", "Member", ".", "from_node", "(", "-", "1", "{", "conn_url", ":", "postgres", ":", "//", "foo" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L112-L127
[ "def", "from_node", "(", "index", ",", "name", ",", "session", ",", "data", ")", ":", "if", "data", ".", "startswith", "(", "'postgres'", ")", ":", "conn_url", ",", "api_url", "=", "parse_connection_string", "(", "data", ")", "data", "=", "{", "'conn_url...
f6d29081c90af52064b981cdd877a07338d86038
train
ClusterConfig.from_node
>>> ClusterConfig.from_node(1, '{') is None False
patroni/dcs/__init__.py
def from_node(index, data, modify_index=None): """ >>> ClusterConfig.from_node(1, '{') is None False """ try: data = json.loads(data) except (TypeError, ValueError): data = None modify_index = 0 if not isinstance(data, dict): ...
def from_node(index, data, modify_index=None): """ >>> ClusterConfig.from_node(1, '{') is None False """ try: data = json.loads(data) except (TypeError, ValueError): data = None modify_index = 0 if not isinstance(data, dict): ...
[ ">>>", "ClusterConfig", ".", "from_node", "(", "1", "{", ")", "is", "None", "False" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L293-L306
[ "def", "from_node", "(", "index", ",", "data", ",", "modify_index", "=", "None", ")", ":", "try", ":", "data", "=", "json", ".", "loads", "(", "data", ")", "except", "(", "TypeError", ",", "ValueError", ")", ":", "data", "=", "None", "modify_index", ...
f6d29081c90af52064b981cdd877a07338d86038
train
SyncState.from_node
>>> SyncState.from_node(1, None).leader is None True >>> SyncState.from_node(1, '{}').leader is None True >>> SyncState.from_node(1, '{').leader is None True >>> SyncState.from_node(1, '[]').leader is None True >>> SyncState.from_node(1, '{"leader": "leade...
patroni/dcs/__init__.py
def from_node(index, value): """ >>> SyncState.from_node(1, None).leader is None True >>> SyncState.from_node(1, '{}').leader is None True >>> SyncState.from_node(1, '{').leader is None True >>> SyncState.from_node(1, '[]').leader is None True ...
def from_node(index, value): """ >>> SyncState.from_node(1, None).leader is None True >>> SyncState.from_node(1, '{}').leader is None True >>> SyncState.from_node(1, '{').leader is None True >>> SyncState.from_node(1, '[]').leader is None True ...
[ ">>>", "SyncState", ".", "from_node", "(", "1", "None", ")", ".", "leader", "is", "None", "True", ">>>", "SyncState", ".", "from_node", "(", "1", "{}", ")", ".", "leader", "is", "None", "True", ">>>", "SyncState", ".", "from_node", "(", "1", "{", ")"...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L325-L351
[ "def", "from_node", "(", "index", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "dict", ")", ":", "data", "=", "value", "elif", "value", ":", "try", ":", "data", "=", "json", ".", "loads", "(", "value", ")", "if", "not", "isinstanc...
f6d29081c90af52064b981cdd877a07338d86038
train
TimelineHistory.from_node
>>> h = TimelineHistory.from_node(1, 2) >>> h.lines []
patroni/dcs/__init__.py
def from_node(index, value): """ >>> h = TimelineHistory.from_node(1, 2) >>> h.lines [] """ try: lines = json.loads(value) except (TypeError, ValueError): lines = None if not isinstance(lines, list): lines = [] r...
def from_node(index, value): """ >>> h = TimelineHistory.from_node(1, 2) >>> h.lines [] """ try: lines = json.loads(value) except (TypeError, ValueError): lines = None if not isinstance(lines, list): lines = [] r...
[ ">>>", "h", "=", "TimelineHistory", ".", "from_node", "(", "1", "2", ")", ">>>", "h", ".", "lines", "[]" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L376-L388
[ "def", "from_node", "(", "index", ",", "value", ")", ":", "try", ":", "lines", "=", "json", ".", "loads", "(", "value", ")", "except", "(", "TypeError", ",", "ValueError", ")", ":", "lines", "=", "None", "if", "not", "isinstance", "(", "lines", ",", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Cluster.timeline
>>> Cluster(0, 0, 0, 0, 0, 0, 0, 0).timeline 0 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[]')).timeline 1 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[["a"]]')).timeline 0
patroni/dcs/__init__.py
def timeline(self): """ >>> Cluster(0, 0, 0, 0, 0, 0, 0, 0).timeline 0 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[]')).timeline 1 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[["a"]]')).timeline 0 """ if self....
def timeline(self): """ >>> Cluster(0, 0, 0, 0, 0, 0, 0, 0).timeline 0 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[]')).timeline 1 >>> Cluster(0, 0, 0, 0, 0, 0, 0, TimelineHistory.from_node(1, '[["a"]]')).timeline 0 """ if self....
[ ">>>", "Cluster", "(", "0", "0", "0", "0", "0", "0", "0", "0", ")", ".", "timeline", "0", ">>>", "Cluster", "(", "0", "0", "0", "0", "0", "0", "0", "TimelineHistory", ".", "from_node", "(", "1", "[]", "))", ".", "timeline", "1", ">>>", "Cluster...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/__init__.py#L489-L506
[ "def", "timeline", "(", "self", ")", ":", "if", "self", ".", "history", ":", "if", "self", ".", "history", ".", "lines", ":", "try", ":", "return", "int", "(", "self", ".", "history", ".", "lines", "[", "-", "1", "]", "[", "0", "]", ")", "+", ...
f6d29081c90af52064b981cdd877a07338d86038
train
Kubernetes.subsets_changed
>>> Kubernetes.subsets_changed([], []) False >>> Kubernetes.subsets_changed([], [k8s_client.V1EndpointSubset()]) True >>> s1 = [k8s_client.V1EndpointSubset(addresses=[k8s_client.V1EndpointAddress(ip='1.2.3.4')])] >>> s2 = [k8s_client.V1EndpointSubset(addresses=[k8s_client.V1Endpo...
patroni/dcs/kubernetes.py
def subsets_changed(last_observed_subsets, subsets): """ >>> Kubernetes.subsets_changed([], []) False >>> Kubernetes.subsets_changed([], [k8s_client.V1EndpointSubset()]) True >>> s1 = [k8s_client.V1EndpointSubset(addresses=[k8s_client.V1EndpointAddress(ip='1.2.3.4')])] ...
def subsets_changed(last_observed_subsets, subsets): """ >>> Kubernetes.subsets_changed([], []) False >>> Kubernetes.subsets_changed([], [k8s_client.V1EndpointSubset()]) True >>> s1 = [k8s_client.V1EndpointSubset(addresses=[k8s_client.V1EndpointAddress(ip='1.2.3.4')])] ...
[ ">>>", "Kubernetes", ".", "subsets_changed", "(", "[]", "[]", ")", "False", ">>>", "Kubernetes", ".", "subsets_changed", "(", "[]", "[", "k8s_client", ".", "V1EndpointSubset", "()", "]", ")", "True", ">>>", "s1", "=", "[", "k8s_client", ".", "V1EndpointSubse...
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/dcs/kubernetes.py#L220-L260
[ "def", "subsets_changed", "(", "last_observed_subsets", ",", "subsets", ")", ":", "if", "len", "(", "last_observed_subsets", ")", "!=", "len", "(", "subsets", ")", ":", "return", "True", "if", "subsets", "==", "[", "]", ":", "return", "False", "if", "len",...
f6d29081c90af52064b981cdd877a07338d86038
train
after_feature
stop all Patronis, remove their data directory and cleanup the keys in etcd
features/environment.py
def after_feature(context, feature): """ stop all Patronis, remove their data directory and cleanup the keys in etcd """ context.pctl.stop_all() shutil.rmtree(os.path.join(context.pctl.patroni_path, 'data')) context.dcs_ctl.cleanup_service_tree() if feature.status == 'failed': shutil.copytre...
def after_feature(context, feature): """ stop all Patronis, remove their data directory and cleanup the keys in etcd """ context.pctl.stop_all() shutil.rmtree(os.path.join(context.pctl.patroni_path, 'data')) context.dcs_ctl.cleanup_service_tree() if feature.status == 'failed': shutil.copytre...
[ "stop", "all", "Patronis", "remove", "their", "data", "directory", "and", "cleanup", "the", "keys", "in", "etcd" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/features/environment.py#L823-L829
[ "def", "after_feature", "(", "context", ",", "feature", ")", ":", "context", ".", "pctl", ".", "stop_all", "(", ")", "shutil", ".", "rmtree", "(", "os", ".", "path", ".", "join", "(", "context", ".", "pctl", ".", "patroni_path", ",", "'data'", ")", "...
f6d29081c90af52064b981cdd877a07338d86038
train
AbstractDcsController.stop
terminate process and wipe out the temp work directory, but only if we actually started it
features/environment.py
def stop(self, kill=False, timeout=15): """ terminate process and wipe out the temp work directory, but only if we actually started it""" super(AbstractDcsController, self).stop(kill=kill, timeout=timeout) if self._work_directory: shutil.rmtree(self._work_directory)
def stop(self, kill=False, timeout=15): """ terminate process and wipe out the temp work directory, but only if we actually started it""" super(AbstractDcsController, self).stop(kill=kill, timeout=timeout) if self._work_directory: shutil.rmtree(self._work_directory)
[ "terminate", "process", "and", "wipe", "out", "the", "temp", "work", "directory", "but", "only", "if", "we", "actually", "started", "it" ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/features/environment.py#L343-L347
[ "def", "stop", "(", "self", ",", "kill", "=", "False", ",", "timeout", "=", "15", ")", ":", "super", "(", "AbstractDcsController", ",", "self", ")", ".", "stop", "(", "kill", "=", "kill", ",", "timeout", "=", "timeout", ")", "if", "self", ".", "_wo...
f6d29081c90af52064b981cdd877a07338d86038
train
LinuxWatchdogDevice._ioctl
Runs the specified ioctl on the underlying fd. Raises WatchdogError if the device is closed. Raises OSError or IOError (Python 2) when the ioctl fails.
patroni/watchdog/linux.py
def _ioctl(self, func, arg): """Runs the specified ioctl on the underlying fd. Raises WatchdogError if the device is closed. Raises OSError or IOError (Python 2) when the ioctl fails.""" if self._fd is None: raise WatchdogError("Watchdog device is closed") if os.name...
def _ioctl(self, func, arg): """Runs the specified ioctl on the underlying fd. Raises WatchdogError if the device is closed. Raises OSError or IOError (Python 2) when the ioctl fails.""" if self._fd is None: raise WatchdogError("Watchdog device is closed") if os.name...
[ "Runs", "the", "specified", "ioctl", "on", "the", "underlying", "fd", "." ]
zalando/patroni
python
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/watchdog/linux.py#L157-L166
[ "def", "_ioctl", "(", "self", ",", "func", ",", "arg", ")", ":", "if", "self", ".", "_fd", "is", "None", ":", "raise", "WatchdogError", "(", "\"Watchdog device is closed\"", ")", "if", "os", ".", "name", "!=", "'nt'", ":", "import", "fcntl", "fcntl", "...
f6d29081c90af52064b981cdd877a07338d86038
train
json_safe
Returns JSON-safe version of `string`. If `string` is a Unicode string or a valid UTF-8, it is returned unmodified, as it can safely be encoded to JSON string. If `string` contains raw/binary data, it is Base64-encoded, formatted and returned according to "data" URL scheme (RFC2397). Since JSON is not...
httpbin/helpers.py
def json_safe(string, content_type='application/octet-stream'): """Returns JSON-safe version of `string`. If `string` is a Unicode string or a valid UTF-8, it is returned unmodified, as it can safely be encoded to JSON string. If `string` contains raw/binary data, it is Base64-encoded, formatted and ...
def json_safe(string, content_type='application/octet-stream'): """Returns JSON-safe version of `string`. If `string` is a Unicode string or a valid UTF-8, it is returned unmodified, as it can safely be encoded to JSON string. If `string` contains raw/binary data, it is Base64-encoded, formatted and ...
[ "Returns", "JSON", "-", "safe", "version", "of", "string", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L85-L106
[ "def", "json_safe", "(", "string", ",", "content_type", "=", "'application/octet-stream'", ")", ":", "try", ":", "string", "=", "string", ".", "decode", "(", "'utf-8'", ")", "json", ".", "dumps", "(", "string", ")", "return", "string", "except", "(", "Valu...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
get_files
Returns files dict from request context.
httpbin/helpers.py
def get_files(): """Returns files dict from request context.""" files = dict() for k, v in request.files.items(): content_type = request.files[k].content_type or 'application/octet-stream' val = json_safe(v.read(), content_type) if files.get(k): if not isinstance(files[...
def get_files(): """Returns files dict from request context.""" files = dict() for k, v in request.files.items(): content_type = request.files[k].content_type or 'application/octet-stream' val = json_safe(v.read(), content_type) if files.get(k): if not isinstance(files[...
[ "Returns", "files", "dict", "from", "request", "context", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L109-L124
[ "def", "get_files", "(", ")", ":", "files", "=", "dict", "(", ")", "for", "k", ",", "v", "in", "request", ".", "files", ".", "items", "(", ")", ":", "content_type", "=", "request", ".", "files", "[", "k", "]", ".", "content_type", "or", "'applicati...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
get_headers
Returns headers dict from request context.
httpbin/helpers.py
def get_headers(hide_env=True): """Returns headers dict from request context.""" headers = dict(request.headers.items()) if hide_env and ('show_env' not in request.args): for key in ENV_HEADERS: try: del headers[key] except KeyError: pass ...
def get_headers(hide_env=True): """Returns headers dict from request context.""" headers = dict(request.headers.items()) if hide_env and ('show_env' not in request.args): for key in ENV_HEADERS: try: del headers[key] except KeyError: pass ...
[ "Returns", "headers", "dict", "from", "request", "context", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L127-L139
[ "def", "get_headers", "(", "hide_env", "=", "True", ")", ":", "headers", "=", "dict", "(", "request", ".", "headers", ".", "items", "(", ")", ")", "if", "hide_env", "and", "(", "'show_env'", "not", "in", "request", ".", "args", ")", ":", "for", "key"...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
semiflatten
Convert a MutiDict into a regular dict. If there are more than one value for a key, the result will have a list of values for the key. Otherwise it will have the plain value.
httpbin/helpers.py
def semiflatten(multi): """Convert a MutiDict into a regular dict. If there are more than one value for a key, the result will have a list of values for the key. Otherwise it will have the plain value.""" if multi: result = multi.to_dict(flat=False) for k, v in result.items(): ...
def semiflatten(multi): """Convert a MutiDict into a regular dict. If there are more than one value for a key, the result will have a list of values for the key. Otherwise it will have the plain value.""" if multi: result = multi.to_dict(flat=False) for k, v in result.items(): ...
[ "Convert", "a", "MutiDict", "into", "a", "regular", "dict", ".", "If", "there", "are", "more", "than", "one", "value", "for", "a", "key", "the", "result", "will", "have", "a", "list", "of", "values", "for", "the", "key", ".", "Otherwise", "it", "will",...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L142-L153
[ "def", "semiflatten", "(", "multi", ")", ":", "if", "multi", ":", "result", "=", "multi", ".", "to_dict", "(", "flat", "=", "False", ")", "for", "k", ",", "v", "in", "result", ".", "items", "(", ")", ":", "if", "len", "(", "v", ")", "==", "1", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
get_url
Since we might be hosted behind a proxy, we need to check the X-Forwarded-Proto, X-Forwarded-Protocol, or X-Forwarded-SSL headers to find out what protocol was used to access us.
httpbin/helpers.py
def get_url(request): """ Since we might be hosted behind a proxy, we need to check the X-Forwarded-Proto, X-Forwarded-Protocol, or X-Forwarded-SSL headers to find out what protocol was used to access us. """ protocol = request.headers.get('X-Forwarded-Proto') or request.headers.get('X-Forwarded...
def get_url(request): """ Since we might be hosted behind a proxy, we need to check the X-Forwarded-Proto, X-Forwarded-Protocol, or X-Forwarded-SSL headers to find out what protocol was used to access us. """ protocol = request.headers.get('X-Forwarded-Proto') or request.headers.get('X-Forwarded...
[ "Since", "we", "might", "be", "hosted", "behind", "a", "proxy", "we", "need", "to", "check", "the", "X", "-", "Forwarded", "-", "Proto", "X", "-", "Forwarded", "-", "Protocol", "or", "X", "-", "Forwarded", "-", "SSL", "headers", "to", "find", "out", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L155-L168
[ "def", "get_url", "(", "request", ")", ":", "protocol", "=", "request", ".", "headers", ".", "get", "(", "'X-Forwarded-Proto'", ")", "or", "request", ".", "headers", ".", "get", "(", "'X-Forwarded-Protocol'", ")", "if", "protocol", "is", "None", "and", "re...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
get_dict
Returns request dict of given keys.
httpbin/helpers.py
def get_dict(*keys, **extras): """Returns request dict of given keys.""" _keys = ('url', 'args', 'form', 'data', 'origin', 'headers', 'files', 'json', 'method') assert all(map(_keys.__contains__, keys)) data = request.data form = semiflatten(request.form) try: _json = json.loads(data....
def get_dict(*keys, **extras): """Returns request dict of given keys.""" _keys = ('url', 'args', 'form', 'data', 'origin', 'headers', 'files', 'json', 'method') assert all(map(_keys.__contains__, keys)) data = request.data form = semiflatten(request.form) try: _json = json.loads(data....
[ "Returns", "request", "dict", "of", "given", "keys", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L171-L204
[ "def", "get_dict", "(", "*", "keys", ",", "*", "*", "extras", ")", ":", "_keys", "=", "(", "'url'", ",", "'args'", ",", "'form'", ",", "'data'", ",", "'origin'", ",", "'headers'", ",", "'files'", ",", "'json'", ",", "'method'", ")", "assert", "all", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
status_code
Returns response object of given status code.
httpbin/helpers.py
def status_code(code): """Returns response object of given status code.""" redirect = dict(headers=dict(location=REDIRECT_LOCATION)) code_map = { 301: redirect, 302: redirect, 303: redirect, 304: dict(data=''), 305: redirect, 307: redirect, 401: dict...
def status_code(code): """Returns response object of given status code.""" redirect = dict(headers=dict(location=REDIRECT_LOCATION)) code_map = { 301: redirect, 302: redirect, 303: redirect, 304: dict(data=''), 305: redirect, 307: redirect, 401: dict...
[ "Returns", "response", "object", "of", "given", "status", "code", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L207-L255
[ "def", "status_code", "(", "code", ")", ":", "redirect", "=", "dict", "(", "headers", "=", "dict", "(", "location", "=", "REDIRECT_LOCATION", ")", ")", "code_map", "=", "{", "301", ":", "redirect", ",", "302", ":", "redirect", ",", "303", ":", "redirec...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
check_basic_auth
Checks user authentication using HTTP Basic Auth.
httpbin/helpers.py
def check_basic_auth(user, passwd): """Checks user authentication using HTTP Basic Auth.""" auth = request.authorization return auth and auth.username == user and auth.password == passwd
def check_basic_auth(user, passwd): """Checks user authentication using HTTP Basic Auth.""" auth = request.authorization return auth and auth.username == user and auth.password == passwd
[ "Checks", "user", "authentication", "using", "HTTP", "Basic", "Auth", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L258-L262
[ "def", "check_basic_auth", "(", "user", ",", "passwd", ")", ":", "auth", "=", "request", ".", "authorization", "return", "auth", "and", "auth", ".", "username", "==", "user", "and", "auth", ".", "password", "==", "passwd" ]
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
HA1
Create HA1 hash by realm, username, password HA1 = md5(A1) = MD5(username:realm:password)
httpbin/helpers.py
def HA1(realm, username, password, algorithm): """Create HA1 hash by realm, username, password HA1 = md5(A1) = MD5(username:realm:password) """ if not realm: realm = u'' return H(b":".join([username.encode('utf-8'), realm.encode('utf-8'), ...
def HA1(realm, username, password, algorithm): """Create HA1 hash by realm, username, password HA1 = md5(A1) = MD5(username:realm:password) """ if not realm: realm = u'' return H(b":".join([username.encode('utf-8'), realm.encode('utf-8'), ...
[ "Create", "HA1", "hash", "by", "realm", "username", "password" ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L278-L287
[ "def", "HA1", "(", "realm", ",", "username", ",", "password", ",", "algorithm", ")", ":", "if", "not", "realm", ":", "realm", "=", "u''", "return", "H", "(", "b\":\"", ".", "join", "(", "[", "username", ".", "encode", "(", "'utf-8'", ")", ",", "rea...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
HA2
Create HA2 md5 hash If the qop directive's value is "auth" or is unspecified, then HA2: HA2 = md5(A2) = MD5(method:digestURI) If the qop directive's value is "auth-int" , then HA2 is HA2 = md5(A2) = MD5(method:digestURI:MD5(entityBody))
httpbin/helpers.py
def HA2(credentials, request, algorithm): """Create HA2 md5 hash If the qop directive's value is "auth" or is unspecified, then HA2: HA2 = md5(A2) = MD5(method:digestURI) If the qop directive's value is "auth-int" , then HA2 is HA2 = md5(A2) = MD5(method:digestURI:MD5(entityBody)) """ ...
def HA2(credentials, request, algorithm): """Create HA2 md5 hash If the qop directive's value is "auth" or is unspecified, then HA2: HA2 = md5(A2) = MD5(method:digestURI) If the qop directive's value is "auth-int" , then HA2 is HA2 = md5(A2) = MD5(method:digestURI:MD5(entityBody)) """ ...
[ "Create", "HA2", "md5", "hash" ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L290-L308
[ "def", "HA2", "(", "credentials", ",", "request", ",", "algorithm", ")", ":", "if", "credentials", ".", "get", "(", "\"qop\"", ")", "==", "\"auth\"", "or", "credentials", ".", "get", "(", "'qop'", ")", "is", "None", ":", "return", "H", "(", "b\":\"", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
response
Compile digest auth response If the qop directive's value is "auth" or "auth-int" , then compute the response as follows: RESPONSE = MD5(HA1:nonce:nonceCount:clienNonce:qop:HA2) Else if the qop directive is unspecified, then compute the response as follows: RESPONSE = MD5(HA1:nonce:HA2) Argu...
httpbin/helpers.py
def response(credentials, password, request): """Compile digest auth response If the qop directive's value is "auth" or "auth-int" , then compute the response as follows: RESPONSE = MD5(HA1:nonce:nonceCount:clienNonce:qop:HA2) Else if the qop directive is unspecified, then compute the response as fo...
def response(credentials, password, request): """Compile digest auth response If the qop directive's value is "auth" or "auth-int" , then compute the response as follows: RESPONSE = MD5(HA1:nonce:nonceCount:clienNonce:qop:HA2) Else if the qop directive is unspecified, then compute the response as fo...
[ "Compile", "digest", "auth", "response" ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L311-L352
[ "def", "response", "(", "credentials", ",", "password", ",", "request", ")", ":", "response", "=", "None", "algorithm", "=", "credentials", ".", "get", "(", "'algorithm'", ")", "HA1_value", "=", "HA1", "(", "credentials", ".", "get", "(", "'realm'", ")", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
check_digest_auth
Check user authentication using HTTP Digest auth
httpbin/helpers.py
def check_digest_auth(user, passwd): """Check user authentication using HTTP Digest auth""" if request.headers.get('Authorization'): credentials = parse_authorization_header(request.headers.get('Authorization')) if not credentials: return request_uri = request.script_root + ...
def check_digest_auth(user, passwd): """Check user authentication using HTTP Digest auth""" if request.headers.get('Authorization'): credentials = parse_authorization_header(request.headers.get('Authorization')) if not credentials: return request_uri = request.script_root + ...
[ "Check", "user", "authentication", "using", "HTTP", "Digest", "auth" ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L355-L370
[ "def", "check_digest_auth", "(", "user", ",", "passwd", ")", ":", "if", "request", ".", "headers", ".", "get", "(", "'Authorization'", ")", ":", "credentials", "=", "parse_authorization_header", "(", "request", ".", "headers", ".", "get", "(", "'Authorization'...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
__parse_request_range
Return a tuple describing the byte range requested in a GET request If the range is open ended on the left or right side, then a value of None will be set. RFC7233: http://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7233.html#header.range Examples: Range : bytes=1024- Range : bytes=10-20 ...
httpbin/helpers.py
def __parse_request_range(range_header_text): """ Return a tuple describing the byte range requested in a GET request If the range is open ended on the left or right side, then a value of None will be set. RFC7233: http://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7233.html#header.range Examples: ...
def __parse_request_range(range_header_text): """ Return a tuple describing the byte range requested in a GET request If the range is open ended on the left or right side, then a value of None will be set. RFC7233: http://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7233.html#header.range Examples: ...
[ "Return", "a", "tuple", "describing", "the", "byte", "range", "requested", "in", "a", "GET", "request", "If", "the", "range", "is", "open", "ended", "on", "the", "left", "or", "right", "side", "then", "a", "value", "of", "None", "will", "be", "set", "....
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L376-L413
[ "def", "__parse_request_range", "(", "range_header_text", ")", ":", "left", "=", "None", "right", "=", "None", "if", "not", "range_header_text", ":", "return", "left", ",", "right", "range_header_text", "=", "range_header_text", ".", "strip", "(", ")", "if", "...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
parse_multi_value_header
Break apart an HTTP header string that is potentially a quoted, comma separated list as used in entity headers in RFC2616.
httpbin/helpers.py
def parse_multi_value_header(header_str): """Break apart an HTTP header string that is potentially a quoted, comma separated list as used in entity headers in RFC2616.""" parsed_parts = [] if header_str: parts = header_str.split(',') for part in parts: match = re.search('\s*(W/)?...
def parse_multi_value_header(header_str): """Break apart an HTTP header string that is potentially a quoted, comma separated list as used in entity headers in RFC2616.""" parsed_parts = [] if header_str: parts = header_str.split(',') for part in parts: match = re.search('\s*(W/)?...
[ "Break", "apart", "an", "HTTP", "header", "string", "that", "is", "potentially", "a", "quoted", "comma", "separated", "list", "as", "used", "in", "entity", "headers", "in", "RFC2616", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/helpers.py#L432-L441
[ "def", "parse_multi_value_header", "(", "header_str", ")", ":", "parsed_parts", "=", "[", "]", "if", "header_str", ":", "parts", "=", "header_str", ".", "split", "(", "','", ")", "for", "part", "in", "parts", ":", "match", "=", "re", ".", "search", "(", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
redirect_n_times
302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection.
httpbin/core.py
def redirect_n_times(n): """302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 absolute = request.args.get("absolute"...
def redirect_n_times(n): """302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 absolute = request.args.get("absolute"...
[ "302", "Redirects", "n", "times", ".", "---", "tags", ":", "-", "Redirects", "parameters", ":", "-", "in", ":", "path", "name", ":", "n", "type", ":", "int", "produces", ":", "-", "text", "/", "html", "responses", ":", "302", ":", "description", ":",...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L538-L563
[ "def", "redirect_n_times", "(", "n", ")", ":", "assert", "n", ">", "0", "absolute", "=", "request", ".", "args", ".", "get", "(", "\"absolute\"", ",", "\"false\"", ")", ".", "lower", "(", ")", "==", "\"true\"", "if", "n", "==", "1", ":", "return", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
redirect_to
302/3XX Redirects to the given URL. --- tags: - Redirects produces: - text/html get: parameters: - in: query name: url type: string required: true - in: query name: status_code type: int post: consumes: ...
httpbin/core.py
def redirect_to(): """302/3XX Redirects to the given URL. --- tags: - Redirects produces: - text/html get: parameters: - in: query name: url type: string required: true - in: query name: status_code type: int pos...
def redirect_to(): """302/3XX Redirects to the given URL. --- tags: - Redirects produces: - text/html get: parameters: - in: query name: url type: string required: true - in: query name: status_code type: int pos...
[ "302", "/", "3XX", "Redirects", "to", "the", "given", "URL", ".", "---", "tags", ":", "-", "Redirects", "produces", ":", "-", "text", "/", "html", "get", ":", "parameters", ":", "-", "in", ":", "query", "name", ":", "url", "type", ":", "string", "r...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L573-L644
[ "def", "redirect_to", "(", ")", ":", "args_dict", "=", "request", ".", "args", ".", "items", "(", ")", "args", "=", "CaseInsensitiveDict", "(", "args_dict", ")", "# We need to build the response manually and convert to UTF-8 to prevent", "# werkzeug from \"fixing\" the URL....
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
relative_redirect_n_times
Relatively 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection.
httpbin/core.py
def relative_redirect_n_times(n): """Relatively 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 response = app.ma...
def relative_redirect_n_times(n): """Relatively 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 response = app.ma...
[ "Relatively", "302", "Redirects", "n", "times", ".", "---", "tags", ":", "-", "Redirects", "parameters", ":", "-", "in", ":", "path", "name", ":", "n", "type", ":", "int", "produces", ":", "-", "text", "/", "html", "responses", ":", "302", ":", "desc...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L648-L674
[ "def", "relative_redirect_n_times", "(", "n", ")", ":", "assert", "n", ">", "0", "response", "=", "app", ".", "make_response", "(", "\"\"", ")", "response", ".", "status_code", "=", "302", "if", "n", "==", "1", ":", "response", ".", "headers", "[", "\"...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
absolute_redirect_n_times
Absolutely 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection.
httpbin/core.py
def absolute_redirect_n_times(n): """Absolutely 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 if n == 1: ...
def absolute_redirect_n_times(n): """Absolutely 302 Redirects n times. --- tags: - Redirects parameters: - in: path name: n type: int produces: - text/html responses: 302: description: A redirection. """ assert n > 0 if n == 1: ...
[ "Absolutely", "302", "Redirects", "n", "times", ".", "---", "tags", ":", "-", "Redirects", "parameters", ":", "-", "in", ":", "path", "name", ":", "n", "type", ":", "int", "produces", ":", "-", "text", "/", "html", "responses", ":", "302", ":", "desc...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L678-L699
[ "def", "absolute_redirect_n_times", "(", "n", ")", ":", "assert", "n", ">", "0", "if", "n", "==", "1", ":", "return", "redirect", "(", "url_for", "(", "\"view_get\"", ",", "_external", "=", "True", ")", ")", "return", "_redirect", "(", "\"absolute\"", ",...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
stream_n_messages
Stream n JSON responses --- tags: - Dynamic data parameters: - in: path name: n type: int produces: - application/json responses: 200: description: Streamed JSON responses.
httpbin/core.py
def stream_n_messages(n): """Stream n JSON responses --- tags: - Dynamic data parameters: - in: path name: n type: int produces: - application/json responses: 200: description: Streamed JSON responses. """ response = get_dict("url", "args",...
def stream_n_messages(n): """Stream n JSON responses --- tags: - Dynamic data parameters: - in: path name: n type: int produces: - application/json responses: 200: description: Streamed JSON responses. """ response = get_dict("url", "args",...
[ "Stream", "n", "JSON", "responses", "---", "tags", ":", "-", "Dynamic", "data", "parameters", ":", "-", "in", ":", "path", "name", ":", "n", "type", ":", "int", "produces", ":", "-", "application", "/", "json", "responses", ":", "200", ":", "descriptio...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L703-L726
[ "def", "stream_n_messages", "(", "n", ")", ":", "response", "=", "get_dict", "(", "\"url\"", ",", "\"args\"", ",", "\"headers\"", ",", "\"origin\"", ")", "n", "=", "min", "(", "n", ",", "100", ")", "def", "generate_stream", "(", ")", ":", "for", "i", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
view_status_code
Return status code or random status code if more than one are given --- tags: - Status codes parameters: - in: path name: codes produces: - text/plain responses: 100: description: Informational responses 200: description: Success 300: ...
httpbin/core.py
def view_status_code(codes): """Return status code or random status code if more than one are given --- tags: - Status codes parameters: - in: path name: codes produces: - text/plain responses: 100: description: Informational responses 200: d...
def view_status_code(codes): """Return status code or random status code if more than one are given --- tags: - Status codes parameters: - in: path name: codes produces: - text/plain responses: 100: description: Informational responses 200: d...
[ "Return", "status", "code", "or", "random", "status", "code", "if", "more", "than", "one", "are", "given", "---", "tags", ":", "-", "Status", "codes", "parameters", ":", "-", "in", ":", "path", "name", ":", "codes", "produces", ":", "-", "text", "/", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L732-L777
[ "def", "view_status_code", "(", "codes", ")", ":", "if", "\",\"", "not", "in", "codes", ":", "try", ":", "code", "=", "int", "(", "codes", ")", "except", "ValueError", ":", "return", "Response", "(", "\"Invalid status code\"", ",", "status", "=", "400", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
response_headers
Returns a set of response headers from the query string. --- tags: - Response inspection parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: type: string styl...
httpbin/core.py
def response_headers(): """Returns a set of response headers from the query string. --- tags: - Response inspection parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: ...
def response_headers(): """Returns a set of response headers from the query string. --- tags: - Response inspection parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: ...
[ "Returns", "a", "set", "of", "response", "headers", "from", "the", "query", "string", ".", "---", "tags", ":", "-", "Response", "inspection", "parameters", ":", "-", "in", ":", "query", "name", ":", "freeform", "explode", ":", "true", "allowEmptyValue", ":...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L781-L821
[ "def", "response_headers", "(", ")", ":", "# Pending swaggerUI update", "# https://github.com/swagger-api/swagger-ui/issues/3850", "headers", "=", "MultiDict", "(", "request", ".", "args", ".", "items", "(", "multi", "=", "True", ")", ")", "response", "=", "jsonify", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
view_cookies
Returns cookie data. --- tags: - Cookies produces: - application/json responses: 200: description: Set cookies.
httpbin/core.py
def view_cookies(hide_env=True): """Returns cookie data. --- tags: - Cookies produces: - application/json responses: 200: description: Set cookies. """ cookies = dict(request.cookies.items()) if hide_env and ("show_env" not in request.args): for key in...
def view_cookies(hide_env=True): """Returns cookie data. --- tags: - Cookies produces: - application/json responses: 200: description: Set cookies. """ cookies = dict(request.cookies.items()) if hide_env and ("show_env" not in request.args): for key in...
[ "Returns", "cookie", "data", ".", "---", "tags", ":", "-", "Cookies", "produces", ":", "-", "application", "/", "json", "responses", ":", "200", ":", "description", ":", "Set", "cookies", "." ]
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L825-L846
[ "def", "view_cookies", "(", "hide_env", "=", "True", ")", ":", "cookies", "=", "dict", "(", "request", ".", "cookies", ".", "items", "(", ")", ")", "if", "hide_env", "and", "(", "\"show_env\"", "not", "in", "request", ".", "args", ")", ":", "for", "k...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
set_cookie
Sets a cookie and redirects to cookie list. --- tags: - Cookies parameters: - in: path name: name type: string - in: path name: value type: string produces: - text/plain responses: 200: description: Set cookies and redirects to co...
httpbin/core.py
def set_cookie(name, value): """Sets a cookie and redirects to cookie list. --- tags: - Cookies parameters: - in: path name: name type: string - in: path name: value type: string produces: - text/plain responses: 200: descript...
def set_cookie(name, value): """Sets a cookie and redirects to cookie list. --- tags: - Cookies parameters: - in: path name: name type: string - in: path name: value type: string produces: - text/plain responses: 200: descript...
[ "Sets", "a", "cookie", "and", "redirects", "to", "cookie", "list", ".", "---", "tags", ":", "-", "Cookies", "parameters", ":", "-", "in", ":", "path", "name", ":", "name", "type", ":", "string", "-", "in", ":", "path", "name", ":", "value", "type", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L857-L879
[ "def", "set_cookie", "(", "name", ",", "value", ")", ":", "r", "=", "app", ".", "make_response", "(", "redirect", "(", "url_for", "(", "\"view_cookies\"", ")", ")", ")", "r", ".", "set_cookie", "(", "key", "=", "name", ",", "value", "=", "value", ","...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
set_cookies
Sets cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: type: string ...
httpbin/core.py
def set_cookies(): """Sets cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: ...
def set_cookies(): """Sets cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: ...
[ "Sets", "cookie", "(", "s", ")", "as", "provided", "by", "the", "query", "string", "and", "redirects", "to", "cookie", "list", ".", "---", "tags", ":", "-", "Cookies", "parameters", ":", "-", "in", ":", "query", "name", ":", "freeform", "explode", ":",...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L883-L910
[ "def", "set_cookies", "(", ")", ":", "cookies", "=", "dict", "(", "request", ".", "args", ".", "items", "(", ")", ")", "r", "=", "app", ".", "make_response", "(", "redirect", "(", "url_for", "(", "\"view_cookies\"", ")", ")", ")", "for", "key", ",", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
delete_cookies
Deletes cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalProperties: type: string ...
httpbin/core.py
def delete_cookies(): """Deletes cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalPropertie...
def delete_cookies(): """Deletes cookie(s) as provided by the query string and redirects to cookie list. --- tags: - Cookies parameters: - in: query name: freeform explode: true allowEmptyValue: true schema: type: object additionalPropertie...
[ "Deletes", "cookie", "(", "s", ")", "as", "provided", "by", "the", "query", "string", "and", "redirects", "to", "cookie", "list", ".", "---", "tags", ":", "-", "Cookies", "parameters", ":", "-", "in", ":", "query", "name", ":", "freeform", "explode", "...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L914-L941
[ "def", "delete_cookies", "(", ")", ":", "cookies", "=", "dict", "(", "request", ".", "args", ".", "items", "(", ")", ")", "r", "=", "app", ".", "make_response", "(", "redirect", "(", "url_for", "(", "\"view_cookies\"", ")", ")", ")", "for", "key", ",...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
basic_auth
Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json responses: 200: description: Sucessful aut...
httpbin/core.py
def basic_auth(user="user", passwd="passwd"): """Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json res...
def basic_auth(user="user", passwd="passwd"): """Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json res...
[ "Prompts", "the", "user", "for", "authorization", "using", "HTTP", "Basic", "Auth", ".", "---", "tags", ":", "-", "Auth", "parameters", ":", "-", "in", ":", "path", "name", ":", "user", "type", ":", "string", "-", "in", ":", "path", "name", ":", "pas...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L945-L969
[ "def", "basic_auth", "(", "user", "=", "\"user\"", ",", "passwd", "=", "\"passwd\"", ")", ":", "if", "not", "check_basic_auth", "(", "user", ",", "passwd", ")", ":", "return", "status_code", "(", "401", ")", "return", "jsonify", "(", "authenticated", "=", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
hidden_basic_auth
Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json responses: 200: description: Sucessful aut...
httpbin/core.py
def hidden_basic_auth(user="user", passwd="passwd"): """Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json ...
def hidden_basic_auth(user="user", passwd="passwd"): """Prompts the user for authorization using HTTP Basic Auth. --- tags: - Auth parameters: - in: path name: user type: string - in: path name: passwd type: string produces: - application/json ...
[ "Prompts", "the", "user", "for", "authorization", "using", "HTTP", "Basic", "Auth", ".", "---", "tags", ":", "-", "Auth", "parameters", ":", "-", "in", ":", "path", "name", ":", "user", "type", ":", "string", "-", "in", ":", "path", "name", ":", "pas...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L973-L996
[ "def", "hidden_basic_auth", "(", "user", "=", "\"user\"", ",", "passwd", "=", "\"passwd\"", ")", ":", "if", "not", "check_basic_auth", "(", "user", ",", "passwd", ")", ":", "return", "status_code", "(", "404", ")", "return", "jsonify", "(", "authenticated", ...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
bearer_auth
Prompts the user for authorization using bearer authentication. --- tags: - Auth parameters: - in: header name: Authorization schema: type: string produces: - application/json responses: 200: description: Sucessful authentication. 401: ...
httpbin/core.py
def bearer_auth(): """Prompts the user for authorization using bearer authentication. --- tags: - Auth parameters: - in: header name: Authorization schema: type: string produces: - application/json responses: 200: description: Sucessful a...
def bearer_auth(): """Prompts the user for authorization using bearer authentication. --- tags: - Auth parameters: - in: header name: Authorization schema: type: string produces: - application/json responses: 200: description: Sucessful a...
[ "Prompts", "the", "user", "for", "authorization", "using", "bearer", "authentication", ".", "---", "tags", ":", "-", "Auth", "parameters", ":", "-", "in", ":", "header", "name", ":", "Authorization", "schema", ":", "type", ":", "string", "produces", ":", "...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1000-L1027
[ "def", "bearer_auth", "(", ")", ":", "authorization", "=", "request", ".", "headers", ".", "get", "(", "\"Authorization\"", ")", "if", "not", "(", "authorization", "and", "authorization", ".", "startswith", "(", "\"Bearer \"", ")", ")", ":", "response", "=",...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
digest_auth_nostale
Prompts the user for authorization using Digest Auth + Algorithm. --- tags: - Auth parameters: - in: path name: qop type: string description: auth or auth-int - in: path name: user type: string - in: path name: passwd type: stri...
httpbin/core.py
def digest_auth_nostale(qop=None, user="user", passwd="passwd", algorithm="MD5"): """Prompts the user for authorization using Digest Auth + Algorithm. --- tags: - Auth parameters: - in: path name: qop type: string description: auth or auth-int - in: path ...
def digest_auth_nostale(qop=None, user="user", passwd="passwd", algorithm="MD5"): """Prompts the user for authorization using Digest Auth + Algorithm. --- tags: - Auth parameters: - in: path name: qop type: string description: auth or auth-int - in: path ...
[ "Prompts", "the", "user", "for", "authorization", "using", "Digest", "Auth", "+", "Algorithm", ".", "---", "tags", ":", "-", "Auth", "parameters", ":", "-", "in", ":", "path", "name", ":", "qop", "type", ":", "string", "description", ":", "auth", "or", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1059-L1088
[ "def", "digest_auth_nostale", "(", "qop", "=", "None", ",", "user", "=", "\"user\"", ",", "passwd", "=", "\"passwd\"", ",", "algorithm", "=", "\"MD5\"", ")", ":", "return", "digest_auth", "(", "qop", ",", "user", ",", "passwd", ",", "algorithm", ",", "\"...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
digest_auth
Prompts the user for authorization using Digest Auth + Algorithm. allow settings the stale_after argument. --- tags: - Auth parameters: - in: path name: qop type: string description: auth or auth-int - in: path name: user type: string - in:...
httpbin/core.py
def digest_auth( qop=None, user="user", passwd="passwd", algorithm="MD5", stale_after="never" ): """Prompts the user for authorization using Digest Auth + Algorithm. allow settings the stale_after argument. --- tags: - Auth parameters: - in: path name: qop type: strin...
def digest_auth( qop=None, user="user", passwd="passwd", algorithm="MD5", stale_after="never" ): """Prompts the user for authorization using Digest Auth + Algorithm. allow settings the stale_after argument. --- tags: - Auth parameters: - in: path name: qop type: strin...
[ "Prompts", "the", "user", "for", "authorization", "using", "Digest", "Auth", "+", "Algorithm", ".", "allow", "settings", "the", "stale_after", "argument", ".", "---", "tags", ":", "-", "Auth", "parameters", ":", "-", "in", ":", "path", "name", ":", "qop", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1092-L1192
[ "def", "digest_auth", "(", "qop", "=", "None", ",", "user", "=", "\"user\"", ",", "passwd", "=", "\"passwd\"", ",", "algorithm", "=", "\"MD5\"", ",", "stale_after", "=", "\"never\"", ")", ":", "require_cookie_handling", "=", "request", ".", "args", ".", "g...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
delay_response
Returns a delayed response (max of 10 seconds). --- tags: - Dynamic data parameters: - in: path name: delay type: int produces: - application/json responses: 200: description: A delayed response.
httpbin/core.py
def delay_response(delay): """Returns a delayed response (max of 10 seconds). --- tags: - Dynamic data parameters: - in: path name: delay type: int produces: - application/json responses: 200: description: A delayed response. """ delay = mi...
def delay_response(delay): """Returns a delayed response (max of 10 seconds). --- tags: - Dynamic data parameters: - in: path name: delay type: int produces: - application/json responses: 200: description: A delayed response. """ delay = mi...
[ "Returns", "a", "delayed", "response", "(", "max", "of", "10", "seconds", ")", ".", "---", "tags", ":", "-", "Dynamic", "data", "parameters", ":", "-", "in", ":", "path", "name", ":", "delay", "type", ":", "int", "produces", ":", "-", "application", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1196-L1217
[ "def", "delay_response", "(", "delay", ")", ":", "delay", "=", "min", "(", "float", "(", "delay", ")", ",", "10", ")", "time", ".", "sleep", "(", "delay", ")", "return", "jsonify", "(", "get_dict", "(", "\"url\"", ",", "\"args\"", ",", "\"form\"", ",...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
drip
Drips data over a duration after an optional initial delay. --- tags: - Dynamic data parameters: - in: query name: duration type: number description: The amount of time (in seconds) over which to drip each byte default: 2 required: false - in: query ...
httpbin/core.py
def drip(): """Drips data over a duration after an optional initial delay. --- tags: - Dynamic data parameters: - in: query name: duration type: number description: The amount of time (in seconds) over which to drip each byte default: 2 required: false...
def drip(): """Drips data over a duration after an optional initial delay. --- tags: - Dynamic data parameters: - in: query name: duration type: number description: The amount of time (in seconds) over which to drip each byte default: 2 required: false...
[ "Drips", "data", "over", "a", "duration", "after", "an", "optional", "initial", "delay", ".", "---", "tags", ":", "-", "Dynamic", "data", "parameters", ":", "-", "in", ":", "query", "name", ":", "duration", "type", ":", "number", "description", ":", "The...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1221-L1287
[ "def", "drip", "(", ")", ":", "args", "=", "CaseInsensitiveDict", "(", "request", ".", "args", ".", "items", "(", ")", ")", "duration", "=", "float", "(", "args", ".", "get", "(", "\"duration\"", ",", "2", ")", ")", "numbytes", "=", "min", "(", "in...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
cache
Returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a GET otherwise. --- tags: - Response inspection parameters: - in: header name: If-Modified-Since - in: header name: If-None-Match produces: - application/json respon...
httpbin/core.py
def cache(): """Returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a GET otherwise. --- tags: - Response inspection parameters: - in: header name: If-Modified-Since - in: header name: If-None-Match produces: - applica...
def cache(): """Returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a GET otherwise. --- tags: - Response inspection parameters: - in: header name: If-Modified-Since - in: header name: If-None-Match produces: - applica...
[ "Returns", "a", "304", "if", "an", "If", "-", "Modified", "-", "Since", "header", "or", "If", "-", "None", "-", "Match", "is", "present", ".", "Returns", "the", "same", "as", "a", "GET", "otherwise", ".", "---", "tags", ":", "-", "Response", "inspect...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1315-L1344
[ "def", "cache", "(", ")", ":", "is_conditional", "=", "request", ".", "headers", ".", "get", "(", "\"If-Modified-Since\"", ")", "or", "request", ".", "headers", ".", "get", "(", "\"If-None-Match\"", ")", "if", "is_conditional", "is", "None", ":", "response",...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83
train
etag
Assumes the resource has the given etag and responds to If-None-Match and If-Match headers appropriately. --- tags: - Response inspection parameters: - in: header name: If-None-Match - in: header name: If-Match produces: - application/json responses: 200...
httpbin/core.py
def etag(etag): """Assumes the resource has the given etag and responds to If-None-Match and If-Match headers appropriately. --- tags: - Response inspection parameters: - in: header name: If-None-Match - in: header name: If-Match produces: - application/json ...
def etag(etag): """Assumes the resource has the given etag and responds to If-None-Match and If-Match headers appropriately. --- tags: - Response inspection parameters: - in: header name: If-None-Match - in: header name: If-Match produces: - application/json ...
[ "Assumes", "the", "resource", "has", "the", "given", "etag", "and", "responds", "to", "If", "-", "None", "-", "Match", "and", "If", "-", "Match", "headers", "appropriately", ".", "---", "tags", ":", "-", "Response", "inspection", "parameters", ":", "-", ...
postmanlabs/httpbin
python
https://github.com/postmanlabs/httpbin/blob/f8ec666b4d1b654e4ff6aedd356f510dcac09f83/httpbin/core.py#L1348-L1382
[ "def", "etag", "(", "etag", ")", ":", "if_none_match", "=", "parse_multi_value_header", "(", "request", ".", "headers", ".", "get", "(", "\"If-None-Match\"", ")", ")", "if_match", "=", "parse_multi_value_header", "(", "request", ".", "headers", ".", "get", "("...
f8ec666b4d1b654e4ff6aedd356f510dcac09f83