Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ActorState.set_trajectory_data | (self, data, traj_buffer_idx, rollout_step) |
Write a dictionary of data into a trajectory buffer at the specific location (rollout_step).
:param data: any sub-dictionary of the full per-step data, e.g. just observation, observation and action, etc.
:param traj_buffer_idx: index of the trajectory buffer we're currently using on this worke... |
Write a dictionary of data into a trajectory buffer at the specific location (rollout_step). | def set_trajectory_data(self, data, traj_buffer_idx, rollout_step):
"""
Write a dictionary of data into a trajectory buffer at the specific location (rollout_step).
:param data: any sub-dictionary of the full per-step data, e.g. just observation, observation and action, etc.
:param traj... | [
"def",
"set_trajectory_data",
"(",
"self",
",",
"data",
",",
"traj_buffer_idx",
",",
"rollout_step",
")",
":",
"index",
"=",
"(",
"traj_buffer_idx",
",",
"rollout_step",
")",
"self",
".",
"traj_tensors",
".",
"set_data",
"(",
"index",
",",
"data",
")"
] | [
125,
4
] | [
136,
47
] | python | en | ['en', 'error', 'th'] | False |
ActorState.curr_actions | (self) |
:return: the latest set of actions for this actor, calculated by the policy worker for the last observation
|
:return: the latest set of actions for this actor, calculated by the policy worker for the last observation
| def curr_actions(self):
"""
:return: the latest set of actions for this actor, calculated by the policy worker for the last observation
"""
if self.integer_actions:
actions = self.last_actions.type(torch.int32).numpy()
else:
actions = self.last_actions.num... | [
"def",
"curr_actions",
"(",
"self",
")",
":",
"if",
"self",
".",
"integer_actions",
":",
"actions",
"=",
"self",
".",
"last_actions",
".",
"type",
"(",
"torch",
".",
"int32",
")",
".",
"numpy",
"(",
")",
"else",
":",
"actions",
"=",
"self",
".",
"las... | [
141,
4
] | [
152,
22
] | python | en | ['en', 'error', 'th'] | False |
ActorState.record_env_step | (self, reward, done, info, traj_buffer_idx, rollout_step) |
Policy inputs (obs) and policy outputs (actions, values, ...) for the current rollout step
are already added to the trajectory buffer
the only job remaining is to add auxiliary data: rewards, done flags, etc.
:param reward: last reward from the env step
:param done: last value ... |
Policy inputs (obs) and policy outputs (actions, values, ...) for the current rollout step
are already added to the trajectory buffer
the only job remaining is to add auxiliary data: rewards, done flags, etc. | def record_env_step(self, reward, done, info, traj_buffer_idx, rollout_step):
"""
Policy inputs (obs) and policy outputs (actions, values, ...) for the current rollout step
are already added to the trajectory buffer
the only job remaining is to add auxiliary data: rewards, done flags, et... | [
"def",
"record_env_step",
"(",
"self",
",",
"reward",
",",
"done",
",",
"info",
",",
"traj_buffer_idx",
",",
"rollout_step",
")",
":",
"self",
".",
"traj_tensors",
"[",
"'rewards'",
"]",
"[",
"traj_buffer_idx",
",",
"rollout_step",
"]",
"[",
"0",
"]",
"=",... | [
154,
4
] | [
180,
114
] | python | en | ['en', 'error', 'th'] | False |
ActorState.finalize_trajectory | (self, rollout_step) |
Do some postprocessing after we finished the entire rollout.
The key thing to notice here: we never change the policy that generates the actions in the middle of the
rollout! The policy index (in PBT scenarios) is only changed between rollouts.
This means that a little bit of experience... |
Do some postprocessing after we finished the entire rollout.
The key thing to notice here: we never change the policy that generates the actions in the middle of the
rollout! The policy index (in PBT scenarios) is only changed between rollouts.
This means that a little bit of experience... | def finalize_trajectory(self, rollout_step):
"""
Do some postprocessing after we finished the entire rollout.
The key thing to notice here: we never change the policy that generates the actions in the middle of the
rollout! The policy index (in PBT scenarios) is only changed between roll... | [
"def",
"finalize_trajectory",
"(",
"self",
",",
"rollout_step",
")",
":",
"t_id",
"=",
"f'{self.curr_policy_id}_{self.worker_idx}_{self.split_idx}_{self.env_idx}_{self.agent_idx}_{self.num_trajectories}'",
"traj_dict",
"=",
"dict",
"(",
"t_id",
"=",
"t_id",
",",
"length",
"="... | [
182,
4
] | [
216,
24
] | python | en | ['en', 'error', 'th'] | False |
ActorState.update_rnn_state | (self, done) | If we encountered an episode boundary, reset rnn states to their default values. | If we encountered an episode boundary, reset rnn states to their default values. | def update_rnn_state(self, done):
"""If we encountered an episode boundary, reset rnn states to their default values."""
if done:
self._reset_rnn_state() | [
"def",
"update_rnn_state",
"(",
"self",
",",
"done",
")",
":",
"if",
"done",
":",
"self",
".",
"_reset_rnn_state",
"(",
")"
] | [
218,
4
] | [
221,
35
] | python | en | ['en', 'en', 'en'] | True |
VectorEnvRunner.__init__ | (self, cfg, num_envs, worker_idx, split_idx, num_agents, shared_buffers, pbt_reward_shaping) |
Ctor.
:param cfg: global system config (all CLI params)
:param num_envs: number of envs to run in this vector runner
:param worker_idx: idx of the parent worker
:param split_idx: index of the environment group in double-buffered sampling (either 0 or 1). Always 0 when
d... |
Ctor. | def __init__(self, cfg, num_envs, worker_idx, split_idx, num_agents, shared_buffers, pbt_reward_shaping):
"""
Ctor.
:param cfg: global system config (all CLI params)
:param num_envs: number of envs to run in this vector runner
:param worker_idx: idx of the parent worker
... | [
"def",
"__init__",
"(",
"self",
",",
"cfg",
",",
"num_envs",
",",
"worker_idx",
",",
"split_idx",
",",
"num_agents",
",",
"shared_buffers",
",",
"pbt_reward_shaping",
")",
":",
"self",
".",
"cfg",
"=",
"cfg",
"self",
".",
"num_envs",
"=",
"num_envs",
"self... | [
253,
4
] | [
291,
66
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner.init | (self) |
Actually instantiate the env instances.
Also creates ActorState objects that hold the state of individual actors in (potentially) multi-agent envs.
|
Actually instantiate the env instances.
Also creates ActorState objects that hold the state of individual actors in (potentially) multi-agent envs.
| def init(self):
"""
Actually instantiate the env instances.
Also creates ActorState objects that hold the state of individual actors in (potentially) multi-agent envs.
"""
for env_i in range(self.num_envs):
vector_idx = self.split_idx * self.num_envs + env_i
... | [
"def",
"init",
"(",
"self",
")",
":",
"for",
"env_i",
"in",
"range",
"(",
"self",
".",
"num_envs",
")",
":",
"vector_idx",
"=",
"self",
".",
"split_idx",
"*",
"self",
".",
"num_envs",
"+",
"env_i",
"# global env id within the entire system",
"env_id",
"=",
... | [
293,
4
] | [
328,
60
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._process_policy_outputs | (self, policy_id) |
Process the latest data from the policy worker (for policy = policy_id).
Policy outputs currently include new RNN states, actions, values, logprobs, etc. See shared_buffers.py
for the full list of outputs.
As a performance optimization, all these tensors are squished together into a si... |
Process the latest data from the policy worker (for policy = policy_id).
Policy outputs currently include new RNN states, actions, values, logprobs, etc. See shared_buffers.py
for the full list of outputs. | def _process_policy_outputs(self, policy_id):
"""
Process the latest data from the policy worker (for policy = policy_id).
Policy outputs currently include new RNN states, actions, values, logprobs, etc. See shared_buffers.py
for the full list of outputs.
As a performance optimi... | [
"def",
"_process_policy_outputs",
"(",
"self",
",",
"policy_id",
")",
":",
"all_actors_ready",
"=",
"True",
"for",
"env_i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"envs",
")",
")",
":",
"for",
"agent_i",
"in",
"range",
"(",
"self",
".",
"num_agents... | [
335,
4
] | [
386,
31
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._process_rewards | (self, rewards, env_i) |
Pretty self-explanatory, here we record the episode reward and apply the optional clipping and
scaling of rewards.
|
Pretty self-explanatory, here we record the episode reward and apply the optional clipping and
scaling of rewards.
| def _process_rewards(self, rewards, env_i):
"""
Pretty self-explanatory, here we record the episode reward and apply the optional clipping and
scaling of rewards.
"""
for agent_i, r in enumerate(rewards):
self.actor_states[env_i][agent_i].last_episode_reward += r
... | [
"def",
"_process_rewards",
"(",
"self",
",",
"rewards",
",",
"env_i",
")",
":",
"for",
"agent_i",
",",
"r",
"in",
"enumerate",
"(",
"rewards",
")",
":",
"self",
".",
"actor_states",
"[",
"env_i",
"]",
"[",
"agent_i",
"]",
".",
"last_episode_reward",
"+="... | [
388,
4
] | [
400,
22
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._process_env_step | (self, new_obs, rewards, dones, infos, env_i) |
Process step outputs from a single environment in the vector.
:param new_obs: latest observations from the env
:param env_i: index of the environment in the vector
:return: episodic stats, not empty only on the episode boundary
|
Process step outputs from a single environment in the vector. | def _process_env_step(self, new_obs, rewards, dones, infos, env_i):
"""
Process step outputs from a single environment in the vector.
:param new_obs: latest observations from the env
:param env_i: index of the environment in the vector
:return: episodic stats, not empty only on ... | [
"def",
"_process_env_step",
"(",
"self",
",",
"new_obs",
",",
"rewards",
",",
"dones",
",",
"infos",
",",
"env_i",
")",
":",
"episodic_stats",
"=",
"[",
"]",
"env_actor_states",
"=",
"self",
".",
"actor_states",
"[",
"env_i",
"]",
"rewards",
"=",
"self",
... | [
402,
4
] | [
430,
29
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._finalize_trajectories | (self) |
Do some postprocessing when we're done with the rollout.
Also see comments in actor_state.finalize_trajectory (IMPORTANT)
|
Do some postprocessing when we're done with the rollout.
Also see comments in actor_state.finalize_trajectory (IMPORTANT)
| def _finalize_trajectories(self):
"""
Do some postprocessing when we're done with the rollout.
Also see comments in actor_state.finalize_trajectory (IMPORTANT)
"""
rollouts = []
for env_i in range(self.num_envs):
for agent_i in range(self.num_agents):
... | [
"def",
"_finalize_trajectories",
"(",
"self",
")",
":",
"rollouts",
"=",
"[",
"]",
"for",
"env_i",
"in",
"range",
"(",
"self",
".",
"num_envs",
")",
":",
"for",
"agent_i",
"in",
"range",
"(",
"self",
".",
"num_agents",
")",
":",
"actor_state",
"=",
"se... | [
432,
4
] | [
447,
76
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._format_policy_request | (self) |
Format data that allows us to request new actions from policies that control the agents in all the envs.
Note how the data required is basically just indices of envs and agents, as well as location of the step
data in the shared rollout buffer. This is enough for the policy worker to find the s... |
Format data that allows us to request new actions from policies that control the agents in all the envs.
Note how the data required is basically just indices of envs and agents, as well as location of the step
data in the shared rollout buffer. This is enough for the policy worker to find the s... | def _format_policy_request(self):
"""
Format data that allows us to request new actions from policies that control the agents in all the envs.
Note how the data required is basically just indices of envs and agents, as well as location of the step
data in the shared rollout buffer. This ... | [
"def",
"_format_policy_request",
"(",
"self",
")",
":",
"policy_request",
"=",
"dict",
"(",
")",
"for",
"env_i",
"in",
"range",
"(",
"self",
".",
"num_envs",
")",
":",
"for",
"agent_i",
"in",
"range",
"(",
"self",
".",
"num_agents",
")",
":",
"actor_stat... | [
449,
4
] | [
473,
29
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner._prepare_next_step | (self) |
Write environment outputs to shared memory so policy workers can calculate actions for the next step.
Note how we temporarily hold obs and rnn_states in local variables before writing them into shared memory.
We could not do the memory write right away because for that we need the memory locati... |
Write environment outputs to shared memory so policy workers can calculate actions for the next step.
Note how we temporarily hold obs and rnn_states in local variables before writing them into shared memory.
We could not do the memory write right away because for that we need the memory locati... | def _prepare_next_step(self):
"""
Write environment outputs to shared memory so policy workers can calculate actions for the next step.
Note how we temporarily hold obs and rnn_states in local variables before writing them into shared memory.
We could not do the memory write right away b... | [
"def",
"_prepare_next_step",
"(",
"self",
")",
":",
"for",
"env_i",
"in",
"range",
"(",
"self",
".",
"num_envs",
")",
":",
"for",
"agent_i",
"in",
"range",
"(",
"self",
".",
"num_agents",
")",
":",
"actor_state",
"=",
"self",
".",
"actor_states",
"[",
... | [
475,
4
] | [
492,
103
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner.reset | (self, report_queue) |
Do the very first reset for all environments in a vector. Populate shared memory with initial obs.
Note that this is called only once, at the very beginning of training. After this the envs should auto-reset.
:param report_queue: we use report queue to monitor reset progress (see appo.py). Thi... |
Do the very first reset for all environments in a vector. Populate shared memory with initial obs.
Note that this is called only once, at the very beginning of training. After this the envs should auto-reset. | def reset(self, report_queue):
"""
Do the very first reset for all environments in a vector. Populate shared memory with initial obs.
Note that this is called only once, at the very beginning of training. After this the envs should auto-reset.
:param report_queue: we use report queue to... | [
"def",
"reset",
"(",
"self",
",",
"report_queue",
")",
":",
"for",
"env_i",
",",
"e",
"in",
"enumerate",
"(",
"self",
".",
"envs",
")",
":",
"observations",
"=",
"e",
".",
"reset",
"(",
")",
"if",
"self",
".",
"cfg",
".",
"decorrelate_envs_on_one_worke... | [
494,
4
] | [
528,
29
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner.advance_rollouts | (self, data, timing) |
Main function in VectorEnvRunner. Does one step of simulation (if all actions for all actors are available).
:param data: incoming data from policy workers (policy outputs), including new actions
:param timing: this is just for profiling
:return: same as reset(), return a set of reques... |
Main function in VectorEnvRunner. Does one step of simulation (if all actions for all actors are available). | def advance_rollouts(self, data, timing):
"""
Main function in VectorEnvRunner. Does one step of simulation (if all actions for all actors are available).
:param data: incoming data from policy workers (policy outputs), including new actions
:param timing: this is just for profiling
... | [
"def",
"advance_rollouts",
"(",
"self",
",",
"data",
",",
"timing",
")",
":",
"with",
"timing",
".",
"add_time",
"(",
"'save_policy_outputs'",
")",
":",
"policy_id",
"=",
"data",
"[",
"'policy_id'",
"]",
"all_actors_ready",
"=",
"self",
".",
"_process_policy_o... | [
530,
4
] | [
577,
64
] | python | en | ['en', 'error', 'th'] | False |
VectorEnvRunner.wait_for_traj_buffers | (self) |
In very rare cases the learner might not have freed the shared memory buffer by the time we need it.
Here we wait until the learner is done with it.
|
In very rare cases the learner might not have freed the shared memory buffer by the time we need it.
Here we wait until the learner is done with it.
| def wait_for_traj_buffers(self):
"""
In very rare cases the learner might not have freed the shared memory buffer by the time we need it.
Here we wait until the learner is done with it.
"""
print_warning = True
while self.traj_tensors_available[:, :, self.traj_buffer_idx... | [
"def",
"wait_for_traj_buffers",
"(",
"self",
")",
":",
"print_warning",
"=",
"True",
"while",
"self",
".",
"traj_tensors_available",
"[",
":",
",",
":",
",",
"self",
".",
"traj_buffer_idx",
"]",
".",
"min",
"(",
")",
"==",
"0",
":",
"if",
"print_warning",
... | [
579,
4
] | [
593,
29
] | python | en | ['en', 'error', 'th'] | False |
ActorWorker.__init__ | (
self, cfg, obs_space, action_space, num_agents, worker_idx, shared_buffers,
task_queue, policy_queues, report_queue, learner_queues,
) |
Ctor.
:param cfg: global config (all CLI params)
:param obs_space: observation space (spaces) of the environment
:param action_space: action space(s)
:param num_agents: number of agents per env (all env should have the same number of agents right now,
although it should... |
Ctor. | def __init__(
self, cfg, obs_space, action_space, num_agents, worker_idx, shared_buffers,
task_queue, policy_queues, report_queue, learner_queues,
):
"""
Ctor.
:param cfg: global config (all CLI params)
:param obs_space: observation space (spaces) of the environment
... | [
"def",
"__init__",
"(",
"self",
",",
"cfg",
",",
"obs_space",
",",
"action_space",
",",
"num_agents",
",",
"worker_idx",
",",
"shared_buffers",
",",
"task_queue",
",",
"policy_queues",
",",
"report_queue",
",",
"learner_queues",
",",
")",
":",
"self",
".",
"... | [
618,
4
] | [
669,
28
] | python | en | ['en', 'error', 'th'] | False |
ActorWorker._init | (self) |
Initialize env runners, that actually do all the work. Also we're doing some utility stuff here, e.g.
setting process affinity (this is a performance optimization).
|
Initialize env runners, that actually do all the work. Also we're doing some utility stuff here, e.g.
setting process affinity (this is a performance optimization).
| def _init(self):
"""
Initialize env runners, that actually do all the work. Also we're doing some utility stuff here, e.g.
setting process affinity (this is a performance optimization).
"""
log.info('Initializing envs for env runner %d...', self.worker_idx)
if self.cfg.... | [
"def",
"_init",
"(",
"self",
")",
":",
"log",
".",
"info",
"(",
"'Initializing envs for env runner %d...'",
",",
"self",
".",
"worker_idx",
")",
"if",
"self",
".",
"cfg",
".",
"force_envs_single_thread",
":",
"from",
"threadpoolctl",
"import",
"threadpool_limits",... | [
671,
4
] | [
694,
47
] | python | en | ['en', 'error', 'th'] | False |
ActorWorker._enqueue_policy_request | (self, split_idx, policy_inputs) | Distribute action requests to their corresponding queues. | Distribute action requests to their corresponding queues. | def _enqueue_policy_request(self, split_idx, policy_inputs):
"""Distribute action requests to their corresponding queues."""
for policy_id, requests in policy_inputs.items():
policy_request = (self.worker_idx, split_idx, requests)
self.policy_queues[policy_id].put(policy_request... | [
"def",
"_enqueue_policy_request",
"(",
"self",
",",
"split_idx",
",",
"policy_inputs",
")",
":",
"for",
"policy_id",
",",
"requests",
"in",
"policy_inputs",
".",
"items",
"(",
")",
":",
"policy_request",
"=",
"(",
"self",
".",
"worker_idx",
",",
"split_idx",
... | [
702,
4
] | [
707,
61
] | python | en | ['en', 'en', 'en'] | True |
ActorWorker._enqueue_complete_rollouts | (self, split_idx, complete_rollouts) | Send complete rollouts from VectorEnv to the learner. | Send complete rollouts from VectorEnv to the learner. | def _enqueue_complete_rollouts(self, split_idx, complete_rollouts):
"""Send complete rollouts from VectorEnv to the learner."""
if self.cfg.sampler_only:
return
rollouts = complete_rollouts['rollouts']
traj_buffer_idx = complete_rollouts['traj_buffer_idx']
# mark th... | [
"def",
"_enqueue_complete_rollouts",
"(",
"self",
",",
"split_idx",
",",
"complete_rollouts",
")",
":",
"if",
"self",
".",
"cfg",
".",
"sampler_only",
":",
"return",
"rollouts",
"=",
"complete_rollouts",
"[",
"'rollouts'",
"]",
"traj_buffer_idx",
"=",
"complete_ro... | [
709,
4
] | [
734,
74
] | python | en | ['en', 'en', 'en'] | True |
ActorWorker._handle_reset | (self) |
Reset all envs, one split at a time (double-buffering), and send requests to policy workers to get
actions for the very first env step.
|
Reset all envs, one split at a time (double-buffering), and send requests to policy workers to get
actions for the very first env step.
| def _handle_reset(self):
"""
Reset all envs, one split at a time (double-buffering), and send requests to policy workers to get
actions for the very first env step.
"""
for split_idx, env_runner in enumerate(self.env_runners):
policy_inputs = env_runner.reset(self.rep... | [
"def",
"_handle_reset",
"(",
"self",
")",
":",
"for",
"split_idx",
",",
"env_runner",
"in",
"enumerate",
"(",
"self",
".",
"env_runners",
")",
":",
"policy_inputs",
"=",
"env_runner",
".",
"reset",
"(",
"self",
".",
"report_queue",
")",
"self",
".",
"_enqu... | [
740,
4
] | [
750,
94
] | python | en | ['en', 'error', 'th'] | False |
ActorWorker._advance_rollouts | (self, data, timing) |
Process incoming request from policy worker. Use the data (policy outputs, actions) to advance the simulation
by one step on the corresponding VectorEnvRunner.
If we successfully managed to advance the simulation, send requests to policy workers to get actions for the
next step. If we ... |
Process incoming request from policy worker. Use the data (policy outputs, actions) to advance the simulation
by one step on the corresponding VectorEnvRunner. | def _advance_rollouts(self, data, timing):
"""
Process incoming request from policy worker. Use the data (policy outputs, actions) to advance the simulation
by one step on the corresponding VectorEnvRunner.
If we successfully managed to advance the simulation, send requests to policy wo... | [
"def",
"_advance_rollouts",
"(",
"self",
",",
"data",
",",
"timing",
")",
":",
"split_idx",
"=",
"data",
"[",
"'split_idx'",
"]",
"runner",
"=",
"self",
".",
"env_runners",
"[",
"split_idx",
"]",
"policy_request",
",",
"complete_rollouts",
",",
"episodic_stats... | [
752,
4
] | [
790,
46
] | python | en | ['en', 'error', 'th'] | False |
ActorWorker._process_pbt_task | (self, pbt_task) | Save the latest version of reward shaping from PBT, we later propagate this to envs. | Save the latest version of reward shaping from PBT, we later propagate this to envs. | def _process_pbt_task(self, pbt_task):
"""Save the latest version of reward shaping from PBT, we later propagate this to envs."""
task_type, data = pbt_task
if task_type == PbtTask.UPDATE_REWARD_SCHEME:
policy_id, new_reward_shaping_scheme = data
self.reward_shaping[poli... | [
"def",
"_process_pbt_task",
"(",
"self",
",",
"pbt_task",
")",
":",
"task_type",
",",
"data",
"=",
"pbt_task",
"if",
"task_type",
"==",
"PbtTask",
".",
"UPDATE_REWARD_SCHEME",
":",
"policy_id",
",",
"new_reward_shaping_scheme",
"=",
"data",
"self",
".",
"reward_... | [
792,
4
] | [
798,
70
] | python | en | ['en', 'en', 'en'] | True |
ActorWorker._run | (self) |
Main loop of the actor worker (rollout worker).
Process tasks (mainly ROLLOUT_STEP) until we get the termination signal, which usually means end of training.
Currently there is no mechanism to restart dead workers if something bad happens during training. We can only
retry on the initia... |
Main loop of the actor worker (rollout worker).
Process tasks (mainly ROLLOUT_STEP) until we get the termination signal, which usually means end of training.
Currently there is no mechanism to restart dead workers if something bad happens during training. We can only
retry on the initia... | def _run(self):
"""
Main loop of the actor worker (rollout worker).
Process tasks (mainly ROLLOUT_STEP) until we get the termination signal, which usually means end of training.
Currently there is no mechanism to restart dead workers if something bad happens during training. We can only
... | [
"def",
"_run",
"(",
"self",
")",
":",
"log",
".",
"info",
"(",
"'Initializing vector env runner %d...'",
",",
"self",
".",
"worker_idx",
")",
"# workers should ignore Ctrl+C because the termination is handled in the event loop by a special msg",
"signal",
".",
"signal",
"(",
... | [
800,
4
] | [
882,
13
] | python | en | ['en', 'error', 'th'] | False |
request | (method, url, **kwargs) | Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to se... | Constructs and sends a :class:`Request <Request>`. | def request(method, url, **kwargs):
"""Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
:param url: URL for the new :class:`Request` object.
:param params: (optional... | [
"def",
"request",
"(",
"method",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"# By using the 'with' statement we are sure the session is closed, thus we",
"# avoid leaving sockets open which can trigger a ResourceWarning in some",
"# cases, and look like a memory leak in others.",
"... | [
15,
0
] | [
60,
64
] | python | en | ['en', 'en', 'en'] | True |
get | (url, params=None, **kwargs) | r"""Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` o... | r"""Sends a GET request. | def get(url, params=None, **kwargs):
r"""Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
... | [
"def",
"get",
"(",
"url",
",",
"params",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'allow_redirects'",
",",
"True",
")",
"return",
"request",
"(",
"'get'",
",",
"url",
",",
"params",
"=",
"params",
",",
"*",
... | [
63,
0
] | [
75,
55
] | python | en | ['en', 'co', 'en'] | True |
options | (url, **kwargs) | r"""Sends an OPTIONS request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
| r"""Sends an OPTIONS request. | def options(url, **kwargs):
r"""Sends an OPTIONS request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
"""
kwargs.setdefault('allow_redirects', True)... | [
"def",
"options",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'allow_redirects'",
",",
"True",
")",
"return",
"request",
"(",
"'options'",
",",
"url",
",",
"*",
"*",
"kwargs",
")"
] | [
78,
0
] | [
88,
44
] | python | en | ['en', 'en', 'en'] | True |
head | (url, **kwargs) | r"""Sends a HEAD request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes. If
`allow_redirects` is not provided, it will be set to `False` (as
opposed to the default :meth:`request` behavior).
:return: :class:`Response <Respo... | r"""Sends a HEAD request. | def head(url, **kwargs):
r"""Sends a HEAD request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes. If
`allow_redirects` is not provided, it will be set to `False` (as
opposed to the default :meth:`request` behavior).
:re... | [
"def",
"head",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'allow_redirects'",
",",
"False",
")",
"return",
"request",
"(",
"'head'",
",",
"url",
",",
"*",
"*",
"kwargs",
")"
] | [
91,
0
] | [
103,
41
] | python | en | ['en', 'co', 'en'] | True |
post | (url, data=None, json=None, **kwargs) | r"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kw... | r"""Sends a POST request. | def post(url, data=None, json=None, **kwargs):
r"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in ... | [
"def",
"post",
"(",
"url",
",",
"data",
"=",
"None",
",",
"json",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"request",
"(",
"'post'",
",",
"url",
",",
"data",
"=",
"data",
",",
"json",
"=",
"json",
",",
"*",
"*",
"kwargs",
")"
] | [
106,
0
] | [
118,
63
] | python | en | ['en', 'en', 'en'] | True |
put | (url, data=None, **kwargs) | r"""Sends a PUT request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwa... | r"""Sends a PUT request. | def put(url, data=None, **kwargs):
r"""Sends a PUT request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of t... | [
"def",
"put",
"(",
"url",
",",
"data",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"request",
"(",
"'put'",
",",
"url",
",",
"data",
"=",
"data",
",",
"*",
"*",
"kwargs",
")"
] | [
121,
0
] | [
133,
51
] | python | en | ['en', 'co', 'en'] | True |
patch | (url, data=None, **kwargs) | r"""Sends a PATCH request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*k... | r"""Sends a PATCH request. | def patch(url, data=None, **kwargs):
r"""Sends a PATCH request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body ... | [
"def",
"patch",
"(",
"url",
",",
"data",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"request",
"(",
"'patch'",
",",
"url",
",",
"data",
"=",
"data",
",",
"*",
"*",
"kwargs",
")"
] | [
136,
0
] | [
148,
53
] | python | en | ['en', 'co', 'en'] | True |
delete | (url, **kwargs) | r"""Sends a DELETE request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
| r"""Sends a DELETE request. | def delete(url, **kwargs):
r"""Sends a DELETE request.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
"""
return request('delete', url, **kwargs) | [
"def",
"delete",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"request",
"(",
"'delete'",
",",
"url",
",",
"*",
"*",
"kwargs",
")"
] | [
151,
0
] | [
160,
43
] | python | en | ['en', 'it', 'en'] | True |
_find_vc2017 | () | Returns "15, path" based on the result of invoking vswhere.exe
If no install is found, returns "None, None"
The version is returned to avoid unnecessarily changing the function
result. It may be ignored when the path is not None.
If vswhere.exe is not available, by definition, VS 2017 is not
insta... | Returns "15, path" based on the result of invoking vswhere.exe
If no install is found, returns "None, None" | def _find_vc2017():
"""Returns "15, path" based on the result of invoking vswhere.exe
If no install is found, returns "None, None"
The version is returned to avoid unnecessarily changing the function
result. It may be ignored when the path is not None.
If vswhere.exe is not available, by definitio... | [
"def",
"_find_vc2017",
"(",
")",
":",
"root",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"ProgramFiles(x86)\"",
")",
"or",
"os",
".",
"environ",
".",
"get",
"(",
"\"ProgramFiles\"",
")",
"if",
"not",
"root",
":",
"return",
"None",
",",
"None",
"try"... | [
59,
0
] | [
89,
21
] | python | en | ['en', 'en', 'en'] | True |
_find_exe | (exe, paths=None) | Return path to an MSVC executable program.
Tries to find the program in several places: first, one of the
MSVC program search paths from the registry; next, the directories
in the PATH environment variable. If any of those work, return an
absolute path that is known to exist. If none of them work, ju... | Return path to an MSVC executable program. | def _find_exe(exe, paths=None):
"""Return path to an MSVC executable program.
Tries to find the program in several places: first, one of the
MSVC program search paths from the registry; next, the directories
in the PATH environment variable. If any of those work, return an
absolute path that is kn... | [
"def",
"_find_exe",
"(",
"exe",
",",
"paths",
"=",
"None",
")",
":",
"if",
"not",
"paths",
":",
"paths",
"=",
"os",
".",
"getenv",
"(",
"'path'",
")",
".",
"split",
"(",
"os",
".",
"pathsep",
")",
"for",
"p",
"in",
"paths",
":",
"fn",
"=",
"os"... | [
146,
0
] | [
161,
14
] | python | en | ['en', 'en', 'en'] | True |
MSVCCompiler._fallback_spawn | (self, cmd, env) |
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
so the 'env' kwarg causes a TypeError. Detect this condition and
restore the legacy, unsafe behavior.
|
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
so the 'env' kwarg causes a TypeError. Detect this condition and
restore the legacy, unsafe behavior.
| def _fallback_spawn(self, cmd, env):
"""
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
so the 'env' kwarg causes a TypeError. Detect this condition and
restore the legacy, unsafe behavior.
"""
bag = type('Bag', (), {})()
try:
yi... | [
"def",
"_fallback_spawn",
"(",
"self",
",",
"cmd",
",",
"env",
")",
":",
"bag",
"=",
"type",
"(",
"'Bag'",
",",
"(",
")",
",",
"{",
"}",
")",
"(",
")",
"try",
":",
"yield",
"bag",
"except",
"TypeError",
"as",
"exc",
":",
"if",
"\"unexpected keyword... | [
513,
4
] | [
530,
42
] | python | en | ['en', 'error', 'th'] | False |
CodeshipHookTests.test_codeship_build_in_testing_status_message | (self) |
Tests if codeship testing status is mapped correctly
|
Tests if codeship testing status is mapped correctly
| def test_codeship_build_in_testing_status_message(self) -> None:
"""
Tests if codeship testing status is mapped correctly
"""
expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch started."
self.check_webhook("t... | [
"def",
"test_codeship_build_in_testing_status_message",
"(",
"self",
")",
"->",
"None",
":",
"expected_message",
"=",
"\"[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch started.\"",
"self",
".",
"check_webhook",
"(",
"\"testing_bui... | [
9,
4
] | [
14,
73
] | python | en | ['en', 'error', 'th'] | False |
CodeshipHookTests.test_codeship_build_in_error_status_message | (self) |
Tests if codeship error status is mapped correctly
|
Tests if codeship error status is mapped correctly
| def test_codeship_build_in_error_status_message(self) -> None:
"""
Tests if codeship error status is mapped correctly
"""
expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch failed."
self.check_webhook("error_... | [
"def",
"test_codeship_build_in_error_status_message",
"(",
"self",
")",
"->",
"None",
":",
"expected_message",
"=",
"\"[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch failed.\"",
"self",
".",
"check_webhook",
"(",
"\"error_build\""... | [
16,
4
] | [
21,
71
] | python | en | ['en', 'error', 'th'] | False |
CodeshipHookTests.test_codeship_build_in_success_status_message | (self) |
Tests if codeship success status is mapped correctly
|
Tests if codeship success status is mapped correctly
| def test_codeship_build_in_success_status_message(self) -> None:
"""
Tests if codeship success status is mapped correctly
"""
expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch succeeded."
self.check_webhook(... | [
"def",
"test_codeship_build_in_success_status_message",
"(",
"self",
")",
"->",
"None",
":",
"expected_message",
"=",
"\"[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch succeeded.\"",
"self",
".",
"check_webhook",
"(",
"\"success_b... | [
23,
4
] | [
28,
73
] | python | en | ['en', 'error', 'th'] | False |
CodeshipHookTests.test_codeship_build_in_other_status_status_message | (self) |
Tests if codeship other status is mapped correctly
|
Tests if codeship other status is mapped correctly
| def test_codeship_build_in_other_status_status_message(self) -> None:
"""
Tests if codeship other status is mapped correctly
"""
expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch has some_other_status status."
... | [
"def",
"test_codeship_build_in_other_status_status_message",
"(",
"self",
")",
"->",
"None",
":",
"expected_message",
"=",
"\"[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch has some_other_status status.\"",
"self",
".",
"check_webhook... | [
30,
4
] | [
35,
78
] | python | en | ['en', 'error', 'th'] | False |
Typer.auto | (cls, node, value=None) |
Automatically set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. When I{value} is an unmapped class,
the default type (xs:any) is set.
@param node: An XML node
@type node: L{sax.element.Element}
@param value: An object th... |
Automatically set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. When I{value} is an unmapped class,
the default type (xs:any) is set.
| def auto(cls, node, value=None):
"""
Automatically set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. When I{value} is an unmapped class,
the default type (xs:any) is set.
@param node: An XML node
@type node: L{sax.element... | [
"def",
"auto",
"(",
"cls",
",",
"node",
",",
"value",
"=",
"None",
")",
":",
"if",
"value",
"is",
"None",
":",
"value",
"=",
"node",
".",
"getText",
"(",
")",
"if",
"isinstance",
"(",
"value",
",",
"Object",
")",
":",
"known",
"=",
"cls",
".",
... | [
47,
4
] | [
69,
19
] | python | en | ['en', 'error', 'th'] | False |
Typer.manual | (cls, node, tval, ns=None) |
Set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. Then adds the referenced
prefix(s) to the node's prefix mapping.
@param node: An XML node
@type node: L{sax.element.Element}
@param tval: The name of the schema type.
... |
Set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. Then adds the referenced
prefix(s) to the node's prefix mapping.
| def manual(cls, node, tval, ns=None):
"""
Set the node's xsi:type attribute based on either I{value}'s
class or the class of the node's text. Then adds the referenced
prefix(s) to the node's prefix mapping.
@param node: An XML node
@type node: L{sax.element.Element}
... | [
"def",
"manual",
"(",
"cls",
",",
"node",
",",
"tval",
",",
"ns",
"=",
"None",
")",
":",
"xta",
"=",
"':'",
".",
"join",
"(",
"(",
"NS",
".",
"xsins",
"[",
"0",
"]",
",",
"'type'",
")",
")",
"node",
".",
"addPrefix",
"(",
"NS",
".",
"xsins",
... | [
72,
4
] | [
95,
19
] | python | en | ['en', 'error', 'th'] | False |
Typer.genprefix | (cls, node, ns) |
Generate a prefix.
@param node: An XML node on which the prefix will be used.
@type node: L{sax.element.Element}
@param ns: A namespace needing an unique prefix.
@type ns: (prefix, uri)
@return: The I{ns} with a new prefix.
|
Generate a prefix.
| def genprefix(cls, node, ns):
"""
Generate a prefix.
@param node: An XML node on which the prefix will be used.
@type node: L{sax.element.Element}
@param ns: A namespace needing an unique prefix.
@type ns: (prefix, uri)
@return: The I{ns} with a new prefix.
... | [
"def",
"genprefix",
"(",
"cls",
",",
"node",
",",
"ns",
")",
":",
"for",
"n",
"in",
"range",
"(",
"1",
",",
"1024",
")",
":",
"p",
"=",
"'ns%d'",
"%",
"n",
"u",
"=",
"node",
".",
"resolvePrefix",
"(",
"p",
",",
"default",
"=",
"None",
")",
"i... | [
98,
4
] | [
112,
49
] | python | en | ['en', 'error', 'th'] | False |
FastFilesCompleter.__call__ | (self, prefix, **kwargs) | only called on non option completions | only called on non option completions | def __call__(self, prefix, **kwargs):
"""only called on non option completions"""
if os.path.sep in prefix[1:]:
prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
else:
prefix_dir = 0
completion = []
globbed = []
if '*' not in prefix and '?' n... | [
"def",
"__call__",
"(",
"self",
",",
"prefix",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"os",
".",
"path",
".",
"sep",
"in",
"prefix",
"[",
"1",
":",
"]",
":",
"prefix_dir",
"=",
"len",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"prefix",
")"... | [
68,
4
] | [
87,
25
] | python | en | ['en', 'en', 'en'] | True |
TestDefaults.test_update_compute_defaults | (self) | Tests the Update Default Compute Quotas functionality:
1) Login as Admin and go to Admin > System > Defaults
2) Updates default compute Quotas by adding a random
number between 1 and 10
3) Verifies that the updated values are present in the
Compute Quota Defaults table
... | Tests the Update Default Compute Quotas functionality: | def test_update_compute_defaults(self):
"""Tests the Update Default Compute Quotas functionality:
1) Login as Admin and go to Admin > System > Defaults
2) Updates default compute Quotas by adding a random
number between 1 and 10
3) Verifies that the updated values are present... | [
"def",
"test_update_compute_defaults",
"(",
"self",
")",
":",
"default_quota_values",
"=",
"self",
".",
"defaults_page",
".",
"compute_quota_values",
"self",
".",
"defaults_page",
".",
"update_compute_defaults",
"(",
"self",
".",
"add_up",
")",
"self",
".",
"assertT... | [
25,
4
] | [
49,
18
] | python | en | ['en', 'en', 'en'] | True |
TestDefaults.test_update_volume_defaults | (self) | Tests the Update Default Volume Quotas functionality:
1) Login as Admin and go to Admin > System > Defaults
2) Clicks on Volume Quotas tab
3) Updates default volume Quotas by adding a random
number between 1 and 10
4) Verifies that the updated values are present in the
... | Tests the Update Default Volume Quotas functionality: | def test_update_volume_defaults(self):
"""Tests the Update Default Volume Quotas functionality:
1) Login as Admin and go to Admin > System > Defaults
2) Clicks on Volume Quotas tab
3) Updates default volume Quotas by adding a random
number between 1 and 10
4) Verifies... | [
"def",
"test_update_volume_defaults",
"(",
"self",
")",
":",
"self",
".",
"defaults_page",
".",
"go_to_volume_quotas_tab",
"(",
")",
"default_quota_values",
"=",
"self",
".",
"defaults_page",
".",
"volume_quota_values",
"self",
".",
"defaults_page",
".",
"update_volum... | [
51,
4
] | [
78,
18
] | python | en | ['en', 'en', 'en'] | True |
CharSetProber.filter_international_words | (buf) |
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delimited
by markers. This function works to ... |
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF] | def filter_international_words(buf):
"""
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delim... | [
"def",
"filter_international_words",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"# This regex expression filters out only words that have at-least one",
"# international character. The word may include one marker character at",
"# the end.",
"words",
"=",
"re",
"... | [
66,
4
] | [
100,
23
] | python | en | ['en', 'error', 'th'] | False |
CharSetProber.filter_with_english_letters | (buf) |
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
This filter can be applied to all scripts which... |
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >. | def filter_with_english_letters(buf):
"""
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
... | [
"def",
"filter_with_english_letters",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"in_tag",
"=",
"False",
"prev",
"=",
"0",
"for",
"curr",
"in",
"range",
"(",
"len",
"(",
"buf",
")",
")",
":",
"# Slice here to get bytes instead of an int with... | [
103,
4
] | [
144,
23
] | python | en | ['en', 'error', 'th'] | False |
opener_for | (ca_bundle=None) | Get a urlopen() replacement that uses ca_bundle for verification | Get a urlopen() replacement that uses ca_bundle for verification | def opener_for(ca_bundle=None):
"""Get a urlopen() replacement that uses ca_bundle for verification"""
return urllib.request.build_opener(
VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
).open | [
"def",
"opener_for",
"(",
"ca_bundle",
"=",
"None",
")",
":",
"return",
"urllib",
".",
"request",
".",
"build_opener",
"(",
"VerifyingHTTPSHandler",
"(",
"ca_bundle",
"or",
"find_ca_bundle",
"(",
")",
")",
")",
".",
"open"
] | [
210,
0
] | [
214,
10
] | python | en | ['en', 'en', 'en'] | True |
find_ca_bundle | () | Return an existing CA bundle path, or None | Return an existing CA bundle path, or None | def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
extant_cert_paths = filter(os.path.isfile, cert_paths)
return (
get_win_certfile()
or next(extant_cert_paths, None)
or _certifi_where()
) | [
"def",
"find_ca_bundle",
"(",
")",
":",
"extant_cert_paths",
"=",
"filter",
"(",
"os",
".",
"path",
".",
"isfile",
",",
"cert_paths",
")",
"return",
"(",
"get_win_certfile",
"(",
")",
"or",
"next",
"(",
"extant_cert_paths",
",",
"None",
")",
"or",
"_certif... | [
251,
0
] | [
258,
5
] | python | en | ['en', 'en', 'en'] | True |
detect_narrowed_window | (
request: HttpRequest, user_profile: Optional[UserProfile]
) | This function implements Zulip's support for a mini Zulip window
that just handles messages from a single narrow | This function implements Zulip's support for a mini Zulip window
that just handles messages from a single narrow | def detect_narrowed_window(
request: HttpRequest, user_profile: Optional[UserProfile]
) -> Tuple[List[List[str]], Optional[Stream], Optional[str]]:
"""This function implements Zulip's support for a mini Zulip window
that just handles messages from a single narrow"""
if user_profile is None:
retu... | [
"def",
"detect_narrowed_window",
"(",
"request",
":",
"HttpRequest",
",",
"user_profile",
":",
"Optional",
"[",
"UserProfile",
"]",
")",
"->",
"Tuple",
"[",
"List",
"[",
"List",
"[",
"str",
"]",
"]",
",",
"Optional",
"[",
"Stream",
"]",
",",
"Optional",
... | [
69,
0
] | [
91,
46
] | python | en | ['en', 'en', 'en'] | True |
update_last_reminder | (user_profile: Optional[UserProfile]) | Reset our don't-spam-users-with-email counter since the
user has since logged in
| Reset our don't-spam-users-with-email counter since the
user has since logged in
| def update_last_reminder(user_profile: Optional[UserProfile]) -> None:
"""Reset our don't-spam-users-with-email counter since the
user has since logged in
"""
if user_profile is None:
return
if user_profile.last_reminder is not None: # nocoverage
# TODO: Look into the history of la... | [
"def",
"update_last_reminder",
"(",
"user_profile",
":",
"Optional",
"[",
"UserProfile",
"]",
")",
"->",
"None",
":",
"if",
"user_profile",
"is",
"None",
":",
"return",
"if",
"user_profile",
".",
"last_reminder",
"is",
"not",
"None",
":",
"# nocoverage",
"# TO... | [
94,
0
] | [
105,
58
] | python | en | ['en', 'en', 'en'] | True |
one_click_unsubscribe_link | (user_profile: UserProfile, email_type: str) |
Generate a unique link that a logged-out user can visit to unsubscribe from
Zulip e-mails without having to first log in.
|
Generate a unique link that a logged-out user can visit to unsubscribe from
Zulip e-mails without having to first log in.
| def one_click_unsubscribe_link(user_profile: UserProfile, email_type: str) -> str:
"""
Generate a unique link that a logged-out user can visit to unsubscribe from
Zulip e-mails without having to first log in.
"""
return create_confirmation_link(
user_profile, Confirmation.UNSUBSCRIBE, url_ar... | [
"def",
"one_click_unsubscribe_link",
"(",
"user_profile",
":",
"UserProfile",
",",
"email_type",
":",
"str",
")",
"->",
"str",
":",
"return",
"create_confirmation_link",
"(",
"user_profile",
",",
"Confirmation",
".",
"UNSUBSCRIBE",
",",
"url_args",
"=",
"{",
"\"em... | [
162,
0
] | [
169,
5
] | python | en | ['en', 'error', 'th'] | False |
validate_key | (creation_key: Optional[str]) | Get the record for this key, raising InvalidCreationKey if non-None but invalid. | Get the record for this key, raising InvalidCreationKey if non-None but invalid. | def validate_key(creation_key: Optional[str]) -> Optional["RealmCreationKey"]:
"""Get the record for this key, raising InvalidCreationKey if non-None but invalid."""
if creation_key is None:
return None
try:
key_record = RealmCreationKey.objects.get(creation_key=creation_key)
except Real... | [
"def",
"validate_key",
"(",
"creation_key",
":",
"Optional",
"[",
"str",
"]",
")",
"->",
"Optional",
"[",
"\"RealmCreationKey\"",
"]",
":",
"if",
"creation_key",
"is",
"None",
":",
"return",
"None",
"try",
":",
"key_record",
"=",
"RealmCreationKey",
".",
"ob... | [
181,
0
] | [
192,
21
] | python | en | ['en', 'en', 'en'] | True |
b64encode | (s, altchars=None) | Encode the bytes-like object s using Base64 and return a bytes object.
Optional altchars should be a byte string of length 2 which specifies an
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Base64 strings.
| Encode the bytes-like object s using Base64 and return a bytes object. | def b64encode(s, altchars=None):
"""Encode the bytes-like object s using Base64 and return a bytes object.
Optional altchars should be a byte string of length 2 which specifies an
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Ba... | [
"def",
"b64encode",
"(",
"s",
",",
"altchars",
"=",
"None",
")",
":",
"encoded",
"=",
"binascii",
".",
"b2a_base64",
"(",
"s",
",",
"newline",
"=",
"False",
")",
"if",
"altchars",
"is",
"not",
"None",
":",
"assert",
"len",
"(",
"altchars",
")",
"==",... | [
50,
0
] | [
61,
18
] | python | en | ['en', 'en', 'en'] | True |
b64decode | (s, altchars=None, validate=False) | Decode the Base64 encoded bytes-like object or ASCII string s.
Optional altchars must be a bytes-like object or ASCII string of length 2
which specifies the alternative alphabet used instead of the '+' and '/'
characters.
The result is returned as a bytes object. A binascii.Error is raised if
s i... | Decode the Base64 encoded bytes-like object or ASCII string s. | def b64decode(s, altchars=None, validate=False):
"""Decode the Base64 encoded bytes-like object or ASCII string s.
Optional altchars must be a bytes-like object or ASCII string of length 2
which specifies the alternative alphabet used instead of the '+' and '/'
characters.
The result is returned a... | [
"def",
"b64decode",
"(",
"s",
",",
"altchars",
"=",
"None",
",",
"validate",
"=",
"False",
")",
":",
"s",
"=",
"_bytes_from_decode_data",
"(",
"s",
")",
"if",
"altchars",
"is",
"not",
"None",
":",
"altchars",
"=",
"_bytes_from_decode_data",
"(",
"altchars"... | [
64,
0
] | [
86,
33
] | python | en | ['en', 'en', 'en'] | True |
standard_b64encode | (s) | Encode bytes-like object s using the standard Base64 alphabet.
The result is returned as a bytes object.
| Encode bytes-like object s using the standard Base64 alphabet. | def standard_b64encode(s):
"""Encode bytes-like object s using the standard Base64 alphabet.
The result is returned as a bytes object.
"""
return b64encode(s) | [
"def",
"standard_b64encode",
"(",
"s",
")",
":",
"return",
"b64encode",
"(",
"s",
")"
] | [
89,
0
] | [
94,
23
] | python | en | ['en', 'zu', 'en'] | True |
standard_b64decode | (s) | Decode bytes encoded with the standard Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
is incorrectly padded. Characters that are not in the standard alphabet
are discarded prior to the pa... | Decode bytes encoded with the standard Base64 alphabet. | def standard_b64decode(s):
"""Decode bytes encoded with the standard Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
is incorrectly padded. Characters that are not in the standard alphabet... | [
"def",
"standard_b64decode",
"(",
"s",
")",
":",
"return",
"b64decode",
"(",
"s",
")"
] | [
96,
0
] | [
104,
23
] | python | en | ['en', 'en', 'en'] | True |
urlsafe_b64encode | (s) | Encode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object to encode. The result is returned as a
bytes object. The alphabet uses '-' instead of '+' and '_' instead of
'/'.
| Encode bytes using the URL- and filesystem-safe Base64 alphabet. | def urlsafe_b64encode(s):
"""Encode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object to encode. The result is returned as a
bytes object. The alphabet uses '-' instead of '+' and '_' instead of
'/'.
"""
return b64encode(s).translate(_urlsafe_encode_t... | [
"def",
"urlsafe_b64encode",
"(",
"s",
")",
":",
"return",
"b64encode",
"(",
"s",
")",
".",
"translate",
"(",
"_urlsafe_encode_translation",
")"
] | [
110,
0
] | [
117,
62
] | python | en | ['en', 'zu', 'en'] | True |
urlsafe_b64decode | (s) | Decode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
is incorrectly padded. Characters that are not in the URL-safe base-64
alphabet, and are not... | Decode bytes using the URL- and filesystem-safe Base64 alphabet. | def urlsafe_b64decode(s):
"""Decode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
is incorrectly padded. Characters that are not in the URL-safe ... | [
"def",
"urlsafe_b64decode",
"(",
"s",
")",
":",
"s",
"=",
"_bytes_from_decode_data",
"(",
"s",
")",
"s",
"=",
"s",
".",
"translate",
"(",
"_urlsafe_decode_translation",
")",
"return",
"b64decode",
"(",
"s",
")"
] | [
119,
0
] | [
132,
23
] | python | en | ['en', 'zu', 'en'] | True |
b32encode | (s) | Encode the bytes-like object s using Base32 and return a bytes object.
| Encode the bytes-like object s using Base32 and return a bytes object.
| def b32encode(s):
"""Encode the bytes-like object s using Base32 and return a bytes object.
"""
global _b32tab2
# Delay the initialization of the table to not waste memory
# if the function is never called
if _b32tab2 is None:
b32tab = [bytes((i,)) for i in _b32alphabet]
_b32tab2... | [
"def",
"b32encode",
"(",
"s",
")",
":",
"global",
"_b32tab2",
"# Delay the initialization of the table to not waste memory",
"# if the function is never called",
"if",
"_b32tab2",
"is",
"None",
":",
"b32tab",
"=",
"[",
"bytes",
"(",
"(",
"i",
",",
")",
")",
"for",
... | [
141,
0
] | [
177,
25
] | python | en | ['en', 'en', 'en'] | True |
b32decode | (s, casefold=False, map01=None) | Decode the Base32 encoded bytes-like object or ASCII string s.
Optional casefold is a flag specifying whether a lowercase alphabet is
acceptable as input. For security purposes, the default is False.
RFC 3548 allows for optional mapping of the digit 0 (zero) to the
letter O (oh), and for optional map... | Decode the Base32 encoded bytes-like object or ASCII string s. | def b32decode(s, casefold=False, map01=None):
"""Decode the Base32 encoded bytes-like object or ASCII string s.
Optional casefold is a flag specifying whether a lowercase alphabet is
acceptable as input. For security purposes, the default is False.
RFC 3548 allows for optional mapping of the digit 0 ... | [
"def",
"b32decode",
"(",
"s",
",",
"casefold",
"=",
"False",
",",
"map01",
"=",
"None",
")",
":",
"global",
"_b32rev",
"# Delay the initialization of the table to not waste memory",
"# if the function is never called",
"if",
"_b32rev",
"is",
"None",
":",
"_b32rev",
"=... | [
179,
0
] | [
246,
25
] | python | en | ['en', 'en', 'en'] | True |
b16encode | (s) | Encode the bytes-like object s using Base16 and return a bytes object.
| Encode the bytes-like object s using Base16 and return a bytes object.
| def b16encode(s):
"""Encode the bytes-like object s using Base16 and return a bytes object.
"""
return binascii.hexlify(s).upper() | [
"def",
"b16encode",
"(",
"s",
")",
":",
"return",
"binascii",
".",
"hexlify",
"(",
"s",
")",
".",
"upper",
"(",
")"
] | [
253,
0
] | [
256,
38
] | python | en | ['en', 'en', 'en'] | True |
b16decode | (s, casefold=False) | Decode the Base16 encoded bytes-like object or ASCII string s.
Optional casefold is a flag specifying whether a lowercase alphabet is
acceptable as input. For security purposes, the default is False.
The result is returned as a bytes object. A binascii.Error is raised if
s is incorrectly padded or i... | Decode the Base16 encoded bytes-like object or ASCII string s. | def b16decode(s, casefold=False):
"""Decode the Base16 encoded bytes-like object or ASCII string s.
Optional casefold is a flag specifying whether a lowercase alphabet is
acceptable as input. For security purposes, the default is False.
The result is returned as a bytes object. A binascii.Error is r... | [
"def",
"b16decode",
"(",
"s",
",",
"casefold",
"=",
"False",
")",
":",
"s",
"=",
"_bytes_from_decode_data",
"(",
"s",
")",
"if",
"casefold",
":",
"s",
"=",
"s",
".",
"upper",
"(",
")",
"if",
"re",
".",
"search",
"(",
"b'[^0-9A-F]'",
",",
"s",
")",
... | [
259,
0
] | [
274,
32
] | python | en | ['en', 'en', 'en'] | True |
a85encode | (b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False) | Encode bytes-like object b using Ascii85 and return a bytes object.
foldspaces is an optional flag that uses the special short sequence 'y'
instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This
feature is not supported by the "standard" Adobe encoding.
wrapcol controls whether the ... | Encode bytes-like object b using Ascii85 and return a bytes object. | def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
"""Encode bytes-like object b using Ascii85 and return a bytes object.
foldspaces is an optional flag that uses the special short sequence 'y'
instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This
feature is n... | [
"def",
"a85encode",
"(",
"b",
",",
"*",
",",
"foldspaces",
"=",
"False",
",",
"wrapcol",
"=",
"0",
",",
"pad",
"=",
"False",
",",
"adobe",
"=",
"False",
")",
":",
"global",
"_a85chars",
",",
"_a85chars2",
"# Delay the initialization of tables to not waste memo... | [
309,
0
] | [
348,
17
] | python | en | ['en', 'haw', 'en'] | True |
a85decode | (b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v') | Decode the Ascii85 encoded bytes-like object or ASCII string b.
foldspaces is a flag that specifies whether the 'y' short sequence should be
accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is
not supported by the "standard" Adobe encoding.
adobe controls whether the input seq... | Decode the Ascii85 encoded bytes-like object or ASCII string b. | def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
"""Decode the Ascii85 encoded bytes-like object or ASCII string b.
foldspaces is a flag that specifies whether the 'y' short sequence should be
accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is
not ... | [
"def",
"a85decode",
"(",
"b",
",",
"*",
",",
"foldspaces",
"=",
"False",
",",
"adobe",
"=",
"False",
",",
"ignorechars",
"=",
"b' \\t\\n\\r\\v'",
")",
":",
"b",
"=",
"_bytes_from_decode_data",
"(",
"b",
")",
"if",
"adobe",
":",
"if",
"not",
"b",
".",
... | [
350,
0
] | [
418,
17
] | python | en | ['en', 'cy', 'en'] | True |
b85encode | (b, pad=False) | Encode bytes-like object b in base85 format and return a bytes object.
If pad is true, the input is padded with b'\\0' so its length is a multiple of
4 bytes before encoding.
| Encode bytes-like object b in base85 format and return a bytes object. | def b85encode(b, pad=False):
"""Encode bytes-like object b in base85 format and return a bytes object.
If pad is true, the input is padded with b'\\0' so its length is a multiple of
4 bytes before encoding.
"""
global _b85chars, _b85chars2
# Delay the initialization of tables to not waste memor... | [
"def",
"b85encode",
"(",
"b",
",",
"pad",
"=",
"False",
")",
":",
"global",
"_b85chars",
",",
"_b85chars2",
"# Delay the initialization of tables to not waste memory",
"# if the function is never called",
"if",
"_b85chars",
"is",
"None",
":",
"_b85chars",
"=",
"[",
"b... | [
428,
0
] | [
440,
51
] | python | en | ['en', 'en', 'en'] | True |
b85decode | (b) | Decode the base85-encoded bytes-like object or ASCII string b
The result is returned as a bytes object.
| Decode the base85-encoded bytes-like object or ASCII string b | def b85decode(b):
"""Decode the base85-encoded bytes-like object or ASCII string b
The result is returned as a bytes object.
"""
global _b85dec
# Delay the initialization of tables to not waste memory
# if the function is never called
if _b85dec is None:
_b85dec = [None] * 256
... | [
"def",
"b85decode",
"(",
"b",
")",
":",
"global",
"_b85dec",
"# Delay the initialization of tables to not waste memory",
"# if the function is never called",
"if",
"_b85dec",
"is",
"None",
":",
"_b85dec",
"=",
"[",
"None",
"]",
"*",
"256",
"for",
"i",
",",
"c",
"i... | [
442,
0
] | [
481,
17
] | python | en | ['en', 'zu', 'en'] | True |
encode | (input, output) | Encode a file; input and output are binary files. | Encode a file; input and output are binary files. | def encode(input, output):
"""Encode a file; input and output are binary files."""
while True:
s = input.read(MAXBINSIZE)
if not s:
break
while len(s) < MAXBINSIZE:
ns = input.read(MAXBINSIZE-len(s))
if not ns:
break
s += ns... | [
"def",
"encode",
"(",
"input",
",",
"output",
")",
":",
"while",
"True",
":",
"s",
"=",
"input",
".",
"read",
"(",
"MAXBINSIZE",
")",
"if",
"not",
"s",
":",
"break",
"while",
"len",
"(",
"s",
")",
"<",
"MAXBINSIZE",
":",
"ns",
"=",
"input",
".",
... | [
490,
0
] | [
502,
26
] | python | en | ['en', 'en', 'en'] | True |
decode | (input, output) | Decode a file; input and output are binary files. | Decode a file; input and output are binary files. | def decode(input, output):
"""Decode a file; input and output are binary files."""
while True:
line = input.readline()
if not line:
break
s = binascii.a2b_base64(line)
output.write(s) | [
"def",
"decode",
"(",
"input",
",",
"output",
")",
":",
"while",
"True",
":",
"line",
"=",
"input",
".",
"readline",
"(",
")",
"if",
"not",
"line",
":",
"break",
"s",
"=",
"binascii",
".",
"a2b_base64",
"(",
"line",
")",
"output",
".",
"write",
"("... | [
505,
0
] | [
512,
23
] | python | en | ['en', 'en', 'en'] | True |
encodebytes | (s) | Encode a bytestring into a bytes object containing multiple lines
of base-64 data. | Encode a bytestring into a bytes object containing multiple lines
of base-64 data. | def encodebytes(s):
"""Encode a bytestring into a bytes object containing multiple lines
of base-64 data."""
_input_type_check(s)
pieces = []
for i in range(0, len(s), MAXBINSIZE):
chunk = s[i : i + MAXBINSIZE]
pieces.append(binascii.b2a_base64(chunk))
return b"".join(pieces) | [
"def",
"encodebytes",
"(",
"s",
")",
":",
"_input_type_check",
"(",
"s",
")",
"pieces",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"s",
")",
",",
"MAXBINSIZE",
")",
":",
"chunk",
"=",
"s",
"[",
"i",
":",
"i",
"+",
"M... | [
530,
0
] | [
538,
27
] | python | en | ['en', 'en', 'en'] | True |
encodestring | (s) | Legacy alias of encodebytes(). | Legacy alias of encodebytes(). | def encodestring(s):
"""Legacy alias of encodebytes()."""
import warnings
warnings.warn("encodestring() is a deprecated alias since 3.1, "
"use encodebytes()",
DeprecationWarning, 2)
return encodebytes(s) | [
"def",
"encodestring",
"(",
"s",
")",
":",
"import",
"warnings",
"warnings",
".",
"warn",
"(",
"\"encodestring() is a deprecated alias since 3.1, \"",
"\"use encodebytes()\"",
",",
"DeprecationWarning",
",",
"2",
")",
"return",
"encodebytes",
"(",
"s",
")"
] | [
540,
0
] | [
546,
25
] | python | en | ['en', 'hmn', 'en'] | True |
decodebytes | (s) | Decode a bytestring of base-64 data into a bytes object. | Decode a bytestring of base-64 data into a bytes object. | def decodebytes(s):
"""Decode a bytestring of base-64 data into a bytes object."""
_input_type_check(s)
return binascii.a2b_base64(s) | [
"def",
"decodebytes",
"(",
"s",
")",
":",
"_input_type_check",
"(",
"s",
")",
"return",
"binascii",
".",
"a2b_base64",
"(",
"s",
")"
] | [
549,
0
] | [
552,
33
] | python | en | ['en', 'en', 'en'] | True |
decodestring | (s) | Legacy alias of decodebytes(). | Legacy alias of decodebytes(). | def decodestring(s):
"""Legacy alias of decodebytes()."""
import warnings
warnings.warn("decodestring() is a deprecated alias since Python 3.1, "
"use decodebytes()",
DeprecationWarning, 2)
return decodebytes(s) | [
"def",
"decodestring",
"(",
"s",
")",
":",
"import",
"warnings",
"warnings",
".",
"warn",
"(",
"\"decodestring() is a deprecated alias since Python 3.1, \"",
"\"use decodebytes()\"",
",",
"DeprecationWarning",
",",
"2",
")",
"return",
"decodebytes",
"(",
"s",
")"
] | [
554,
0
] | [
560,
25
] | python | en | ['en', 'lt', 'en'] | True |
main | () | Small main program | Small main program | def main():
"""Small main program"""
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], 'deut')
except getopt.error as msg:
sys.stdout = sys.stderr
print(msg)
print("""usage: %s [-d|-e|-u|-t] [file|-]
-d, -u: decode
-e: encode (default)
... | [
"def",
"main",
"(",
")",
":",
"import",
"sys",
",",
"getopt",
"try",
":",
"opts",
",",
"args",
"=",
"getopt",
".",
"getopt",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
",",
"'deut'",
")",
"except",
"getopt",
".",
"error",
"as",
"msg",
":",
"s... | [
564,
0
] | [
587,
49
] | python | en | ['en', 'mg', 'en'] | True |
User.is_token_expired | (self, margin=None) | Determine if the token is expired.
:returns:
``True`` if the token is expired, ``False`` if not, and
``None`` if there is no token set.
:param margin:
A security time margin in seconds before real expiration.
Will return ``True`` if the token expires in less t... | Determine if the token is expired. | def is_token_expired(self, margin=None):
"""Determine if the token is expired.
:returns:
``True`` if the token is expired, ``False`` if not, and
``None`` if there is no token set.
:param margin:
A security time margin in seconds before real expiration.
... | [
"def",
"is_token_expired",
"(",
"self",
",",
"margin",
"=",
"None",
")",
":",
"if",
"self",
".",
"token",
"is",
"None",
":",
"return",
"None",
"return",
"not",
"utils",
".",
"is_token_valid",
"(",
"self",
".",
"token",
",",
"margin",
")"
] | [
244,
4
] | [
261,
59
] | python | en | ['en', 'en', 'en'] | True |
User.is_authenticated | (self) | Checks for a valid authentication. | Checks for a valid authentication. | def is_authenticated(self):
"""Checks for a valid authentication."""
return self.token is not None and utils.is_token_valid(self.token) | [
"def",
"is_authenticated",
"(",
"self",
")",
":",
"return",
"self",
".",
"token",
"is",
"not",
"None",
"and",
"utils",
".",
"is_token_valid",
"(",
"self",
".",
"token",
")"
] | [
264,
4
] | [
266,
74
] | python | en | ['en', 'en', 'en'] | True |
User.is_anonymous | (self) | Return if the user is not authenticated.
:returns: ``True`` if not authenticated,``False`` otherwise.
| Return if the user is not authenticated. | def is_anonymous(self):
"""Return if the user is not authenticated.
:returns: ``True`` if not authenticated,``False`` otherwise.
"""
return not self.is_authenticated | [
"def",
"is_anonymous",
"(",
"self",
")",
":",
"return",
"not",
"self",
".",
"is_authenticated"
] | [
269,
4
] | [
274,
40
] | python | en | ['en', 'en', 'en'] | True |
User.is_superuser | (self) | Evaluates whether this user has admin privileges.
:returns: ``True`` or ``False``.
| Evaluates whether this user has admin privileges. | def is_superuser(self):
"""Evaluates whether this user has admin privileges.
:returns: ``True`` or ``False``.
"""
admin_roles = utils.get_admin_roles()
user_roles = {role['name'].lower() for role in self.roles}
return not admin_roles.isdisjoint(user_roles) | [
"def",
"is_superuser",
"(",
"self",
")",
":",
"admin_roles",
"=",
"utils",
".",
"get_admin_roles",
"(",
")",
"user_roles",
"=",
"{",
"role",
"[",
"'name'",
"]",
".",
"lower",
"(",
")",
"for",
"role",
"in",
"self",
".",
"roles",
"}",
"return",
"not",
... | [
281,
4
] | [
288,
53
] | python | en | ['en', 'en', 'en'] | True |
User.authorized_tenants | (self) | Returns a memoized list of tenants this user may access. | Returns a memoized list of tenants this user may access. | def authorized_tenants(self):
"""Returns a memoized list of tenants this user may access."""
if self.is_authenticated and self._authorized_tenants is None:
endpoint = self.endpoint
try:
self._authorized_tenants = utils.get_project_list(
user_id... | [
"def",
"authorized_tenants",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_authenticated",
"and",
"self",
".",
"_authorized_tenants",
"is",
"None",
":",
"endpoint",
"=",
"self",
".",
"endpoint",
"try",
":",
"self",
".",
"_authorized_tenants",
"=",
"utils",
"... | [
291,
4
] | [
304,
45
] | python | en | ['en', 'en', 'en'] | True |
User.available_services_regions | (self) | Returns list of unique region name values in service catalog. | Returns list of unique region name values in service catalog. | def available_services_regions(self):
"""Returns list of unique region name values in service catalog."""
regions = []
if self.service_catalog:
for service in self.service_catalog:
service_type = service.get('type')
if service_type is None or service_t... | [
"def",
"available_services_regions",
"(",
"self",
")",
":",
"regions",
"=",
"[",
"]",
"if",
"self",
".",
"service_catalog",
":",
"for",
"service",
"in",
"self",
".",
"service_catalog",
":",
"service_type",
"=",
"service",
".",
"get",
"(",
"'type'",
")",
"i... | [
319,
4
] | [
331,
22
] | python | en | ['en', 'la', 'en'] | True |
User.has_a_matching_perm | (self, perm_list, obj=None) | Returns True if the user has one of the specified permissions.
If object is passed, it checks if the user has any of the required
perms for this object.
| Returns True if the user has one of the specified permissions. | def has_a_matching_perm(self, perm_list, obj=None):
"""Returns True if the user has one of the specified permissions.
If object is passed, it checks if the user has any of the required
perms for this object.
"""
# If there are no permissions to check, just return true
if... | [
"def",
"has_a_matching_perm",
"(",
"self",
",",
"perm_list",
",",
"obj",
"=",
"None",
")",
":",
"# If there are no permissions to check, just return true",
"if",
"not",
"perm_list",
":",
"return",
"True",
"# Check that user has at least one of the required permissions.",
"for... | [
343,
4
] | [
356,
20
] | python | en | ['en', 'en', 'en'] | True |
User.has_perms | (self, perm_list, obj=None) | Returns True if the user has all of the specified permissions.
Tuples in the list will possess the required permissions if
the user has a permissions matching one of the elements of
that tuple
| Returns True if the user has all of the specified permissions. | def has_perms(self, perm_list, obj=None):
"""Returns True if the user has all of the specified permissions.
Tuples in the list will possess the required permissions if
the user has a permissions matching one of the elements of
that tuple
"""
# If there are no permissions... | [
"def",
"has_perms",
"(",
"self",
",",
"perm_list",
",",
"obj",
"=",
"None",
")",
":",
"# If there are no permissions to check, just return true",
"if",
"not",
"perm_list",
":",
"return",
"True",
"for",
"perm",
"in",
"perm_list",
":",
"if",
"isinstance",
"(",
"pe... | [
370,
4
] | [
389,
19
] | python | en | ['en', 'en', 'en'] | True |
User.time_until_expiration | (self) | Returns the number of remaining days until user's password expires.
Calculates the number days until the user must change their password,
once the password expires the user will not able to log in until an
admin changes its password.
| Returns the number of remaining days until user's password expires. | def time_until_expiration(self):
"""Returns the number of remaining days until user's password expires.
Calculates the number days until the user must change their password,
once the password expires the user will not able to log in until an
admin changes its password.
"""
... | [
"def",
"time_until_expiration",
"(",
"self",
")",
":",
"if",
"self",
".",
"password_expires_at",
"is",
"not",
"None",
":",
"expiration_date",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"self",
".",
"password_expires_at",
",",
"\"%Y-%m-%dT%H:%M:%S.%f\"... | [
391,
4
] | [
401,
60
] | python | en | ['en', 'en', 'en'] | True |
xor_hex_strings | (bytes_a: str, bytes_b: str) | Given two hex strings of equal length, return a hex string with
the bitwise xor of the two hex strings. | Given two hex strings of equal length, return a hex string with
the bitwise xor of the two hex strings. | def xor_hex_strings(bytes_a: str, bytes_b: str) -> str:
"""Given two hex strings of equal length, return a hex string with
the bitwise xor of the two hex strings."""
assert len(bytes_a) == len(bytes_b)
return "".join(f"{int(x, 16) ^ int(y, 16):x}" for x, y in zip(bytes_a, bytes_b)) | [
"def",
"xor_hex_strings",
"(",
"bytes_a",
":",
"str",
",",
"bytes_b",
":",
"str",
")",
"->",
"str",
":",
"assert",
"len",
"(",
"bytes_a",
")",
"==",
"len",
"(",
"bytes_b",
")",
"return",
"\"\"",
".",
"join",
"(",
"f\"{int(x, 16) ^ int(y, 16):x}\"",
"for",
... | [
13,
0
] | [
17,
84
] | python | en | ['en', 'en', 'en'] | True |
ascii_to_hex | (input_string: str) | Given an ascii string, encode it as a hex string | Given an ascii string, encode it as a hex string | def ascii_to_hex(input_string: str) -> str:
"""Given an ascii string, encode it as a hex string"""
return input_string.encode().hex() | [
"def",
"ascii_to_hex",
"(",
"input_string",
":",
"str",
")",
"->",
"str",
":",
"return",
"input_string",
".",
"encode",
"(",
")",
".",
"hex",
"(",
")"
] | [
20,
0
] | [
22,
38
] | python | en | ['en', 'en', 'en'] | True |
hex_to_ascii | (input_string: str) | Given a hex array, decode it back to a string | Given a hex array, decode it back to a string | def hex_to_ascii(input_string: str) -> str:
"""Given a hex array, decode it back to a string"""
return bytes.fromhex(input_string).decode() | [
"def",
"hex_to_ascii",
"(",
"input_string",
":",
"str",
")",
"->",
"str",
":",
"return",
"bytes",
".",
"fromhex",
"(",
"input_string",
")",
".",
"decode",
"(",
")"
] | [
25,
0
] | [
27,
47
] | python | en | ['en', 'en', 'en'] | True |
HttpAuthenticated.__init__ | (self, **kwargs) |
@param kwargs: Keyword arguments.
- B{proxy} - An http proxy to be specified on requests.
The proxy is defined as {protocol:proxy,}
- type: I{dict}
- default: {}
- B{timeout} - Set the url open timeout (seconds).
... | def __init__(self, **kwargs):
"""
@param kwargs: Keyword arguments.
- B{proxy} - An http proxy to be specified on requests.
The proxy is defined as {protocol:proxy,}
- type: I{dict}
- default: {}
- B{timeout} - Set the url ... | [
"def",
"__init__",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"HttpTransport",
".",
"__init__",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"pm",
"=",
"u2",
".",
"HTTPPasswordMgrWithDefaultRealm",
"(",
")"
] | [
37,
4
] | [
55,
54
] | python | en | ['en', 'error', 'th'] | False | |
raise_option_error | (parser, option, msg) |
Raise an option parsing error using parser.error().
Args:
parser: an OptionParser instance.
option: an Option instance.
msg: the error text.
|
Raise an option parsing error using parser.error(). | def raise_option_error(parser, option, msg):
# type: (OptionParser, Option, str) -> None
"""
Raise an option parsing error using parser.error().
Args:
parser: an OptionParser instance.
option: an Option instance.
msg: the error text.
"""
msg = '{} error: {}'.format(option, msg... | [
"def",
"raise_option_error",
"(",
"parser",
",",
"option",
",",
"msg",
")",
":",
"# type: (OptionParser, Option, str) -> None",
"msg",
"=",
"'{} error: {}'",
".",
"format",
"(",
"option",
",",
"msg",
")",
"msg",
"=",
"textwrap",
".",
"fill",
"(",
"' '",
".",
... | [
37,
0
] | [
49,
21
] | python | en | ['en', 'error', 'th'] | False |
make_option_group | (group, parser) |
Return an OptionGroup object
group -- assumed to be dict with 'name' and 'options' keys
parser -- an optparse Parser
|
Return an OptionGroup object
group -- assumed to be dict with 'name' and 'options' keys
parser -- an optparse Parser
| def make_option_group(group, parser):
# type: (Dict[str, Any], ConfigOptionParser) -> OptionGroup
"""
Return an OptionGroup object
group -- assumed to be dict with 'name' and 'options' keys
parser -- an optparse Parser
"""
option_group = OptionGroup(parser, group['name'])
for option in ... | [
"def",
"make_option_group",
"(",
"group",
",",
"parser",
")",
":",
"# type: (Dict[str, Any], ConfigOptionParser) -> OptionGroup",
"option_group",
"=",
"OptionGroup",
"(",
"parser",
",",
"group",
"[",
"'name'",
"]",
")",
"for",
"option",
"in",
"group",
"[",
"'options... | [
52,
0
] | [
62,
23
] | python | en | ['en', 'error', 'th'] | False |
check_install_build_global | (options, check_options=None) | Disable wheels if per-setup.py call options are set.
:param options: The OptionParser options to update.
:param check_options: The options to check, if not supplied defaults to
options.
| Disable wheels if per-setup.py call options are set. | def check_install_build_global(options, check_options=None):
# type: (Values, Optional[Values]) -> None
"""Disable wheels if per-setup.py call options are set.
:param options: The OptionParser options to update.
:param check_options: The options to check, if not supplied defaults to
options.
... | [
"def",
"check_install_build_global",
"(",
"options",
",",
"check_options",
"=",
"None",
")",
":",
"# type: (Values, Optional[Values]) -> None",
"if",
"check_options",
"is",
"None",
":",
"check_options",
"=",
"options",
"def",
"getname",
"(",
"n",
")",
":",
"# type: ... | [
65,
0
] | [
86,
9
] | python | en | ['en', 'en', 'en'] | True |
check_dist_restriction | (options, check_target=False) | Function for determining if custom platform options are allowed.
:param options: The OptionParser options.
:param check_target: Whether or not to check if --target is being used.
| Function for determining if custom platform options are allowed. | def check_dist_restriction(options, check_target=False):
# type: (Values, bool) -> None
"""Function for determining if custom platform options are allowed.
:param options: The OptionParser options.
:param check_target: Whether or not to check if --target is being used.
"""
dist_restriction_set ... | [
"def",
"check_dist_restriction",
"(",
"options",
",",
"check_target",
"=",
"False",
")",
":",
"# type: (Values, bool) -> None",
"dist_restriction_set",
"=",
"any",
"(",
"[",
"options",
".",
"python_version",
",",
"options",
".",
"platform",
",",
"options",
".",
"a... | [
89,
0
] | [
126,
13
] | python | en | ['en', 'en', 'en'] | True |
_get_format_control | (values, option) | Get a format_control object. | Get a format_control object. | def _get_format_control(values, option):
# type: (Values, Option) -> Any
"""Get a format_control object."""
return getattr(values, option.dest) | [
"def",
"_get_format_control",
"(",
"values",
",",
"option",
")",
":",
"# type: (Values, Option) -> Any",
"return",
"getattr",
"(",
"values",
",",
"option",
".",
"dest",
")"
] | [
437,
0
] | [
440,
39
] | python | en | ['en', 'en', 'en'] | True |
_convert_python_version | (value) |
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints.
:return: A 2-tuple (version_info, error_msg), where `error_msg` is
non-None if and only if there was a parsing error.
|
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints. | def _convert_python_version(value):
# type: (str) -> Tuple[Tuple[int, ...], Optional[str]]
"""
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints.
:return: A 2-tuple (version_info, error_msg), where `error_msg` is
non-None if and only if there was a parsing error.
"""
... | [
"def",
"_convert_python_version",
"(",
"value",
")",
":",
"# type: (str) -> Tuple[Tuple[int, ...], Optional[str]]",
"if",
"not",
"value",
":",
"# The empty string is the same as not providing a value.",
"return",
"(",
"None",
",",
"None",
")",
"parts",
"=",
"value",
".",
... | [
503,
0
] | [
530,
31
] | python | en | ['en', 'error', 'th'] | False |
_handle_python_version | (option, opt_str, value, parser) |
Handle a provided --python-version value.
|
Handle a provided --python-version value.
| def _handle_python_version(option, opt_str, value, parser):
# type: (Option, str, str, OptionParser) -> None
"""
Handle a provided --python-version value.
"""
version_info, error_msg = _convert_python_version(value)
if error_msg is not None:
msg = (
'invalid --python-version ... | [
"def",
"_handle_python_version",
"(",
"option",
",",
"opt_str",
",",
"value",
",",
"parser",
")",
":",
"# type: (Option, str, str, OptionParser) -> None",
"version_info",
",",
"error_msg",
"=",
"_convert_python_version",
"(",
"value",
")",
"if",
"error_msg",
"is",
"no... | [
533,
0
] | [
547,
47
] | python | en | ['en', 'error', 'th'] | False |
_handle_no_cache_dir | (option, opt, value, parser) |
Process a value provided for the --no-cache-dir option.
This is an optparse.Option callback for the --no-cache-dir option.
|
Process a value provided for the --no-cache-dir option. | def _handle_no_cache_dir(option, opt, value, parser):
# type: (Option, str, str, OptionParser) -> None
"""
Process a value provided for the --no-cache-dir option.
This is an optparse.Option callback for the --no-cache-dir option.
"""
# The value argument will be None if --no-cache-dir is passed... | [
"def",
"_handle_no_cache_dir",
"(",
"option",
",",
"opt",
",",
"value",
",",
"parser",
")",
":",
"# type: (Option, str, str, OptionParser) -> None",
"# The value argument will be None if --no-cache-dir is passed via the",
"# command-line, since the option doesn't accept arguments. Howev... | [
639,
0
] | [
664,
35
] | python | en | ['en', 'error', 'th'] | False |
_handle_no_use_pep517 | (option, opt, value, parser) |
Process a value provided for the --no-use-pep517 option.
This is an optparse.Option callback for the no_use_pep517 option.
|
Process a value provided for the --no-use-pep517 option. | def _handle_no_use_pep517(option, opt, value, parser):
# type: (Option, str, str, OptionParser) -> None
"""
Process a value provided for the --no-use-pep517 option.
This is an optparse.Option callback for the no_use_pep517 option.
"""
# Since --no-use-pep517 doesn't accept arguments, the value ... | [
"def",
"_handle_no_use_pep517",
"(",
"option",
",",
"opt",
",",
"value",
",",
"parser",
")",
":",
"# type: (Option, str, str, OptionParser) -> None",
"# Since --no-use-pep517 doesn't accept arguments, the value argument",
"# will be None if --no-use-pep517 is passed via the command-line.... | [
729,
0
] | [
750,
36
] | python | en | ['en', 'error', 'th'] | False |
_handle_merge_hash | (option, opt_str, value, parser) | Given a value spelled "algo:digest", append the digest to a list
pointed to in a dict by the algo name. | Given a value spelled "algo:digest", append the digest to a list
pointed to in a dict by the algo name. | def _handle_merge_hash(option, opt_str, value, parser):
# type: (Option, str, str, OptionParser) -> None
"""Given a value spelled "algo:digest", append the digest to a list
pointed to in a dict by the algo name."""
if not parser.values.hashes:
parser.values.hashes = {}
try:
algo, dig... | [
"def",
"_handle_merge_hash",
"(",
"option",
",",
"opt_str",
",",
"value",
",",
"parser",
")",
":",
"# type: (Option, str, str, OptionParser) -> None",
"if",
"not",
"parser",
".",
"values",
".",
"hashes",
":",
"parser",
".",
"values",
".",
"hashes",
"=",
"{",
"... | [
824,
0
] | [
839,
60
] | python | en | ['en', 'en', 'en'] | True |
Marker.evaluate | (self, environment=None) | Evaluate a marker.
Return the boolean from evaluating the given marker against the
environment. environment is an optional argument to override all or
part of the determined environment.
The environment is determined from the current Python process.
| Evaluate a marker. | def evaluate(self, environment=None):
# type: (Optional[Dict[str, str]]) -> bool
"""Evaluate a marker.
Return the boolean from evaluating the given marker against the
environment. environment is an optional argument to override all or
part of the determined environment.
... | [
"def",
"evaluate",
"(",
"self",
",",
"environment",
"=",
"None",
")",
":",
"# type: (Optional[Dict[str, str]]) -> bool",
"current_environment",
"=",
"default_environment",
"(",
")",
"if",
"environment",
"is",
"not",
"None",
":",
"current_environment",
".",
"update",
... | [
313,
4
] | [
327,
68
] | python | en | ['en', 'en', 'en'] | True |
RedisCache.clear | (self) | Helper for clearing all the keys in a database. Use with
caution! | Helper for clearing all the keys in a database. Use with
caution! | def clear(self):
"""Helper for clearing all the keys in a database. Use with
caution!"""
for key in self.conn.keys():
self.conn.delete(key) | [
"def",
"clear",
"(",
"self",
")",
":",
"for",
"key",
"in",
"self",
".",
"conn",
".",
"keys",
"(",
")",
":",
"self",
".",
"conn",
".",
"delete",
"(",
"key",
")"
] | [
24,
4
] | [
28,
33
] | python | en | ['en', 'en', 'en'] | True |
RedisCache.close | (self) | Redis uses connection pooling, no need to close the connection. | Redis uses connection pooling, no need to close the connection. | def close(self):
"""Redis uses connection pooling, no need to close the connection."""
pass | [
"def",
"close",
"(",
"self",
")",
":",
"pass"
] | [
30,
4
] | [
32,
12
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.