repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps.create_bucket | def create_bucket(self):
"""Create or update bucket based on app name."""
bucket_exists = self._bucket_exists()
if self.s3props.get('shared_bucket_target'):
if bucket_exists:
LOG.info('App uses shared bucket - %s ', self.bucket)
else:
LOG.e... | python | def create_bucket(self):
"""Create or update bucket based on app name."""
bucket_exists = self._bucket_exists()
if self.s3props.get('shared_bucket_target'):
if bucket_exists:
LOG.info('App uses shared bucket - %s ', self.bucket)
else:
LOG.e... | [
"def",
"create_bucket",
"(",
"self",
")",
":",
"bucket_exists",
"=",
"self",
".",
"_bucket_exists",
"(",
")",
"if",
"self",
".",
"s3props",
".",
"get",
"(",
"'shared_bucket_target'",
")",
":",
"if",
"bucket_exists",
":",
"LOG",
".",
"info",
"(",
"'App uses... | Create or update bucket based on app name. | [
"Create",
"or",
"update",
"bucket",
"based",
"on",
"app",
"name",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L65-L92 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._bucket_exists | def _bucket_exists(self):
"""Check if the bucket exists."""
try:
self.s3client.get_bucket_location(Bucket=self.bucket)
return True
except ClientError as error:
LOG.error(error)
return False | python | def _bucket_exists(self):
"""Check if the bucket exists."""
try:
self.s3client.get_bucket_location(Bucket=self.bucket)
return True
except ClientError as error:
LOG.error(error)
return False | [
"def",
"_bucket_exists",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"s3client",
".",
"get_bucket_location",
"(",
"Bucket",
"=",
"self",
".",
"bucket",
")",
"return",
"True",
"except",
"ClientError",
"as",
"error",
":",
"LOG",
".",
"error",
"(",
"err... | Check if the bucket exists. | [
"Check",
"if",
"the",
"bucket",
"exists",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L94-L101 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_policy | def _put_bucket_policy(self):
"""Attach a bucket policy to app bucket."""
if self.s3props['bucket_policy']:
policy_str = json.dumps(self.s3props['bucket_policy'])
_response = self.s3client.put_bucket_policy(Bucket=self.bucket, Policy=policy_str)
else:
_respons... | python | def _put_bucket_policy(self):
"""Attach a bucket policy to app bucket."""
if self.s3props['bucket_policy']:
policy_str = json.dumps(self.s3props['bucket_policy'])
_response = self.s3client.put_bucket_policy(Bucket=self.bucket, Policy=policy_str)
else:
_respons... | [
"def",
"_put_bucket_policy",
"(",
"self",
")",
":",
"if",
"self",
".",
"s3props",
"[",
"'bucket_policy'",
"]",
":",
"policy_str",
"=",
"json",
".",
"dumps",
"(",
"self",
".",
"s3props",
"[",
"'bucket_policy'",
"]",
")",
"_response",
"=",
"self",
".",
"s3... | Attach a bucket policy to app bucket. | [
"Attach",
"a",
"bucket",
"policy",
"to",
"app",
"bucket",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L103-L111 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_website | def _put_bucket_website(self):
"""Configure static website on S3 bucket."""
if self.s3props['website']['enabled']:
website_config = {
'ErrorDocument': {
'Key': self.s3props['website']['error_document']
},
'IndexDocument': {
... | python | def _put_bucket_website(self):
"""Configure static website on S3 bucket."""
if self.s3props['website']['enabled']:
website_config = {
'ErrorDocument': {
'Key': self.s3props['website']['error_document']
},
'IndexDocument': {
... | [
"def",
"_put_bucket_website",
"(",
"self",
")",
":",
"if",
"self",
".",
"s3props",
"[",
"'website'",
"]",
"[",
"'enabled'",
"]",
":",
"website_config",
"=",
"{",
"'ErrorDocument'",
":",
"{",
"'Key'",
":",
"self",
".",
"s3props",
"[",
"'website'",
"]",
"[... | Configure static website on S3 bucket. | [
"Configure",
"static",
"website",
"on",
"S3",
"bucket",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L113-L131 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._set_bucket_dns | def _set_bucket_dns(self):
"""Create CNAME for S3 endpoint."""
# Different regions have different s3 endpoint formats
dotformat_regions = ["eu-west-2", "eu-central-1", "ap-northeast-2", "ap-south-1", "ca-central-1", "us-east-2"]
if self.region in dotformat_regions:
s3_endpoin... | python | def _set_bucket_dns(self):
"""Create CNAME for S3 endpoint."""
# Different regions have different s3 endpoint formats
dotformat_regions = ["eu-west-2", "eu-central-1", "ap-northeast-2", "ap-south-1", "ca-central-1", "us-east-2"]
if self.region in dotformat_regions:
s3_endpoin... | [
"def",
"_set_bucket_dns",
"(",
"self",
")",
":",
"# Different regions have different s3 endpoint formats",
"dotformat_regions",
"=",
"[",
"\"eu-west-2\"",
",",
"\"eu-central-1\"",
",",
"\"ap-northeast-2\"",
",",
"\"ap-south-1\"",
",",
"\"ca-central-1\"",
",",
"\"us-east-2\"",... | Create CNAME for S3 endpoint. | [
"Create",
"CNAME",
"for",
"S3",
"endpoint",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L133-L152 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_cors | def _put_bucket_cors(self):
"""Adds bucket cors configuration."""
if self.s3props['cors']['enabled'] and self.s3props['website']['enabled']:
cors_config = {}
cors_rules = []
for each_rule in self.s3props['cors']['cors_rules']:
cors_rules.append({
... | python | def _put_bucket_cors(self):
"""Adds bucket cors configuration."""
if self.s3props['cors']['enabled'] and self.s3props['website']['enabled']:
cors_config = {}
cors_rules = []
for each_rule in self.s3props['cors']['cors_rules']:
cors_rules.append({
... | [
"def",
"_put_bucket_cors",
"(",
"self",
")",
":",
"if",
"self",
".",
"s3props",
"[",
"'cors'",
"]",
"[",
"'enabled'",
"]",
"and",
"self",
".",
"s3props",
"[",
"'website'",
"]",
"[",
"'enabled'",
"]",
":",
"cors_config",
"=",
"{",
"}",
"cors_rules",
"="... | Adds bucket cors configuration. | [
"Adds",
"bucket",
"cors",
"configuration",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L154-L175 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_encryption | def _put_bucket_encryption(self):
"""Adds bucket encryption configuration."""
if self.s3props['encryption']['enabled']:
encryption_config = {'Rules': [{}]}
encryption_config = {
'Rules': self.s3props['encryption']['encryption_rules']
}
LOG.... | python | def _put_bucket_encryption(self):
"""Adds bucket encryption configuration."""
if self.s3props['encryption']['enabled']:
encryption_config = {'Rules': [{}]}
encryption_config = {
'Rules': self.s3props['encryption']['encryption_rules']
}
LOG.... | [
"def",
"_put_bucket_encryption",
"(",
"self",
")",
":",
"if",
"self",
".",
"s3props",
"[",
"'encryption'",
"]",
"[",
"'enabled'",
"]",
":",
"encryption_config",
"=",
"{",
"'Rules'",
":",
"[",
"{",
"}",
"]",
"}",
"encryption_config",
"=",
"{",
"'Rules'",
... | Adds bucket encryption configuration. | [
"Adds",
"bucket",
"encryption",
"configuration",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L177-L190 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_lifecycle | def _put_bucket_lifecycle(self):
"""Adds bucket lifecycle configuration."""
status = 'deleted'
if self.s3props['lifecycle']['enabled']:
lifecycle_config = {
'Rules': self.s3props['lifecycle']['lifecycle_rules']
}
LOG.debug('Lifecycle Config: %s... | python | def _put_bucket_lifecycle(self):
"""Adds bucket lifecycle configuration."""
status = 'deleted'
if self.s3props['lifecycle']['enabled']:
lifecycle_config = {
'Rules': self.s3props['lifecycle']['lifecycle_rules']
}
LOG.debug('Lifecycle Config: %s... | [
"def",
"_put_bucket_lifecycle",
"(",
"self",
")",
":",
"status",
"=",
"'deleted'",
"if",
"self",
".",
"s3props",
"[",
"'lifecycle'",
"]",
"[",
"'enabled'",
"]",
":",
"lifecycle_config",
"=",
"{",
"'Rules'",
":",
"self",
".",
"s3props",
"[",
"'lifecycle'",
... | Adds bucket lifecycle configuration. | [
"Adds",
"bucket",
"lifecycle",
"configuration",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L192-L206 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_logging | def _put_bucket_logging(self):
"""Adds bucket logging policy to bucket for s3 access requests"""
logging_config = {}
if self.s3props['logging']['enabled']:
logging_config = {
'LoggingEnabled': {
'TargetBucket': self.s3props['logging']['logging_buck... | python | def _put_bucket_logging(self):
"""Adds bucket logging policy to bucket for s3 access requests"""
logging_config = {}
if self.s3props['logging']['enabled']:
logging_config = {
'LoggingEnabled': {
'TargetBucket': self.s3props['logging']['logging_buck... | [
"def",
"_put_bucket_logging",
"(",
"self",
")",
":",
"logging_config",
"=",
"{",
"}",
"if",
"self",
".",
"s3props",
"[",
"'logging'",
"]",
"[",
"'enabled'",
"]",
":",
"logging_config",
"=",
"{",
"'LoggingEnabled'",
":",
"{",
"'TargetBucket'",
":",
"self",
... | Adds bucket logging policy to bucket for s3 access requests | [
"Adds",
"bucket",
"logging",
"policy",
"to",
"bucket",
"for",
"s3",
"access",
"requests"
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L208-L221 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_tagging | def _put_bucket_tagging(self):
"""Add bucket tags to bucket."""
all_tags = self.s3props['tagging']['tags']
all_tags.update({'app_group': self.group, 'app_name': self.app_name})
tag_set = generate_s3_tags.generated_tag_data(all_tags)
tagging_config = {'TagSet': tag_set}
... | python | def _put_bucket_tagging(self):
"""Add bucket tags to bucket."""
all_tags = self.s3props['tagging']['tags']
all_tags.update({'app_group': self.group, 'app_name': self.app_name})
tag_set = generate_s3_tags.generated_tag_data(all_tags)
tagging_config = {'TagSet': tag_set}
... | [
"def",
"_put_bucket_tagging",
"(",
"self",
")",
":",
"all_tags",
"=",
"self",
".",
"s3props",
"[",
"'tagging'",
"]",
"[",
"'tags'",
"]",
"all_tags",
".",
"update",
"(",
"{",
"'app_group'",
":",
"self",
".",
"group",
",",
"'app_name'",
":",
"self",
".",
... | Add bucket tags to bucket. | [
"Add",
"bucket",
"tags",
"to",
"bucket",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L223-L232 |
foremast/foremast | src/foremast/s3/s3apps.py | S3Apps._put_bucket_versioning | def _put_bucket_versioning(self):
"""Adds bucket versioning policy to bucket"""
status = 'Suspended'
if self.s3props['versioning']['enabled']:
status = 'Enabled'
versioning_config = {
'MFADelete': self.s3props['versioning']['mfa_delete'],
'Status': st... | python | def _put_bucket_versioning(self):
"""Adds bucket versioning policy to bucket"""
status = 'Suspended'
if self.s3props['versioning']['enabled']:
status = 'Enabled'
versioning_config = {
'MFADelete': self.s3props['versioning']['mfa_delete'],
'Status': st... | [
"def",
"_put_bucket_versioning",
"(",
"self",
")",
":",
"status",
"=",
"'Suspended'",
"if",
"self",
".",
"s3props",
"[",
"'versioning'",
"]",
"[",
"'enabled'",
"]",
":",
"status",
"=",
"'Enabled'",
"versioning_config",
"=",
"{",
"'MFADelete'",
":",
"self",
"... | Adds bucket versioning policy to bucket | [
"Adds",
"bucket",
"versioning",
"policy",
"to",
"bucket"
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/s3/s3apps.py#L234-L247 |
foremast/foremast | src/foremast/configs/prepare_configs.py | process_git_configs | def process_git_configs(git_short=''):
"""Retrieve _application.json_ files from GitLab.
Args:
git_short (str): Short Git representation of repository, e.g.
forrest/core.
Returns:
collections.defaultdict: Configurations stored for each environment
found.
"""
LOG... | python | def process_git_configs(git_short=''):
"""Retrieve _application.json_ files from GitLab.
Args:
git_short (str): Short Git representation of repository, e.g.
forrest/core.
Returns:
collections.defaultdict: Configurations stored for each environment
found.
"""
LOG... | [
"def",
"process_git_configs",
"(",
"git_short",
"=",
"''",
")",
":",
"LOG",
".",
"info",
"(",
"'Processing application.json files from GitLab \"%s\".'",
",",
"git_short",
")",
"file_lookup",
"=",
"FileLookup",
"(",
"git_short",
"=",
"git_short",
")",
"app_configs",
... | Retrieve _application.json_ files from GitLab.
Args:
git_short (str): Short Git representation of repository, e.g.
forrest/core.
Returns:
collections.defaultdict: Configurations stored for each environment
found. | [
"Retrieve",
"_application",
".",
"json_",
"files",
"from",
"GitLab",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/configs/prepare_configs.py#L26-L46 |
foremast/foremast | src/foremast/configs/prepare_configs.py | process_runway_configs | def process_runway_configs(runway_dir=''):
"""Read the _application.json_ files.
Args:
runway_dir (str): Name of runway directory with app.json files.
Returns:
collections.defaultdict: Configurations stored for each environment
found.
"""
LOG.info('Processing application.js... | python | def process_runway_configs(runway_dir=''):
"""Read the _application.json_ files.
Args:
runway_dir (str): Name of runway directory with app.json files.
Returns:
collections.defaultdict: Configurations stored for each environment
found.
"""
LOG.info('Processing application.js... | [
"def",
"process_runway_configs",
"(",
"runway_dir",
"=",
"''",
")",
":",
"LOG",
".",
"info",
"(",
"'Processing application.json files from local directory \"%s\".'",
",",
"runway_dir",
")",
"file_lookup",
"=",
"FileLookup",
"(",
"runway_dir",
"=",
"runway_dir",
")",
"... | Read the _application.json_ files.
Args:
runway_dir (str): Name of runway directory with app.json files.
Returns:
collections.defaultdict: Configurations stored for each environment
found. | [
"Read",
"the",
"_application",
".",
"json_",
"files",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/configs/prepare_configs.py#L49-L62 |
foremast/foremast | src/foremast/configs/prepare_configs.py | process_configs | def process_configs(file_lookup, app_config_format, pipeline_config):
"""Processes the configs from lookup sources.
Args:
file_lookup (FileLookup): Source to look for file/config
app_config_format (str): The format for application config files.
pipeline_config (str): Name/path of the pi... | python | def process_configs(file_lookup, app_config_format, pipeline_config):
"""Processes the configs from lookup sources.
Args:
file_lookup (FileLookup): Source to look for file/config
app_config_format (str): The format for application config files.
pipeline_config (str): Name/path of the pi... | [
"def",
"process_configs",
"(",
"file_lookup",
",",
"app_config_format",
",",
"pipeline_config",
")",
":",
"app_configs",
"=",
"collections",
".",
"defaultdict",
"(",
"dict",
")",
"for",
"env",
"in",
"ENVS",
":",
"file_json",
"=",
"app_config_format",
".",
"forma... | Processes the configs from lookup sources.
Args:
file_lookup (FileLookup): Source to look for file/config
app_config_format (str): The format for application config files.
pipeline_config (str): Name/path of the pipeline config
Returns:
dict: Retreived application config | [
"Processes",
"the",
"configs",
"from",
"lookup",
"sources",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/configs/prepare_configs.py#L65-L93 |
foremast/foremast | src/foremast/configs/prepare_configs.py | apply_region_configs | def apply_region_configs(env_config):
"""Override default env configs with region specific configs and nest
all values under a region
Args:
env_config (dict): The environment specific config.
Return:
dict: Newly updated dictionary with region overrides applied.
"""
new_config =... | python | def apply_region_configs(env_config):
"""Override default env configs with region specific configs and nest
all values under a region
Args:
env_config (dict): The environment specific config.
Return:
dict: Newly updated dictionary with region overrides applied.
"""
new_config =... | [
"def",
"apply_region_configs",
"(",
"env_config",
")",
":",
"new_config",
"=",
"env_config",
".",
"copy",
"(",
")",
"for",
"region",
"in",
"env_config",
".",
"get",
"(",
"'regions'",
",",
"REGIONS",
")",
":",
"if",
"isinstance",
"(",
"env_config",
".",
"ge... | Override default env configs with region specific configs and nest
all values under a region
Args:
env_config (dict): The environment specific config.
Return:
dict: Newly updated dictionary with region overrides applied. | [
"Override",
"default",
"env",
"configs",
"with",
"region",
"specific",
"configs",
"and",
"nest",
"all",
"values",
"under",
"a",
"region"
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/configs/prepare_configs.py#L96-L114 |
foremast/foremast | src/foremast/iam/create_iam.py | create_iam_resources | def create_iam_resources(env='dev', app='', **_):
"""Create the IAM Resources for the application.
Args:
env (str): Deployment environment/account, i.e. dev, stage, prod.
app (str): Spinnaker Application name.
Returns:
True upon successful completion.
"""
session = boto3.se... | python | def create_iam_resources(env='dev', app='', **_):
"""Create the IAM Resources for the application.
Args:
env (str): Deployment environment/account, i.e. dev, stage, prod.
app (str): Spinnaker Application name.
Returns:
True upon successful completion.
"""
session = boto3.se... | [
"def",
"create_iam_resources",
"(",
"env",
"=",
"'dev'",
",",
"app",
"=",
"''",
",",
"*",
"*",
"_",
")",
":",
"session",
"=",
"boto3",
".",
"session",
".",
"Session",
"(",
"profile_name",
"=",
"env",
")",
"client",
"=",
"session",
".",
"client",
"(",... | Create the IAM Resources for the application.
Args:
env (str): Deployment environment/account, i.e. dev, stage, prod.
app (str): Spinnaker Application name.
Returns:
True upon successful completion. | [
"Create",
"the",
"IAM",
"Resources",
"for",
"the",
"application",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/iam/create_iam.py#L29-L87 |
foremast/foremast | src/foremast/iam/create_iam.py | attach_profile_to_role | def attach_profile_to_role(client, role_name='forrest_unicorn_role', profile_name='forrest_unicorn_profile'):
"""Attach an IAM Instance Profile _profile_name_ to Role _role_name_.
Args:
role_name (str): Name of Role.
profile_name (str): Name of Instance Profile.
Returns:
True upon ... | python | def attach_profile_to_role(client, role_name='forrest_unicorn_role', profile_name='forrest_unicorn_profile'):
"""Attach an IAM Instance Profile _profile_name_ to Role _role_name_.
Args:
role_name (str): Name of Role.
profile_name (str): Name of Instance Profile.
Returns:
True upon ... | [
"def",
"attach_profile_to_role",
"(",
"client",
",",
"role_name",
"=",
"'forrest_unicorn_role'",
",",
"profile_name",
"=",
"'forrest_unicorn_profile'",
")",
":",
"current_instance_profiles",
"=",
"resource_action",
"(",
"client",
",",
"action",
"=",
"'list_instance_profil... | Attach an IAM Instance Profile _profile_name_ to Role _role_name_.
Args:
role_name (str): Name of Role.
profile_name (str): Name of Instance Profile.
Returns:
True upon successful completion. | [
"Attach",
"an",
"IAM",
"Instance",
"Profile",
"_profile_name_",
"to",
"Role",
"_role_name_",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/iam/create_iam.py#L90-L128 |
foremast/foremast | src/foremast/utils/elb.py | find_elb | def find_elb(name='', env='', region=''):
"""Get an application's AWS elb dns name.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS record
"""
LOG.info('Find %s ELB in %s [%s].', name, env, region)
... | python | def find_elb(name='', env='', region=''):
"""Get an application's AWS elb dns name.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS record
"""
LOG.info('Find %s ELB in %s [%s].', name, env, region)
... | [
"def",
"find_elb",
"(",
"name",
"=",
"''",
",",
"env",
"=",
"''",
",",
"region",
"=",
"''",
")",
":",
"LOG",
".",
"info",
"(",
"'Find %s ELB in %s [%s].'",
",",
"name",
",",
"env",
",",
"region",
")",
"url",
"=",
"'{0}/applications/{1}/loadBalancers'",
"... | Get an application's AWS elb dns name.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS record | [
"Get",
"an",
"application",
"s",
"AWS",
"elb",
"dns",
"name",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/utils/elb.py#L30-L58 |
foremast/foremast | src/foremast/utils/elb.py | find_elb_dns_zone_id | def find_elb_dns_zone_id(name='', env='dev', region='us-east-1'):
"""Get an application's AWS elb dns zone id.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS zone ID
"""
LOG.info('Find %s ELB DNS Zone... | python | def find_elb_dns_zone_id(name='', env='dev', region='us-east-1'):
"""Get an application's AWS elb dns zone id.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS zone ID
"""
LOG.info('Find %s ELB DNS Zone... | [
"def",
"find_elb_dns_zone_id",
"(",
"name",
"=",
"''",
",",
"env",
"=",
"'dev'",
",",
"region",
"=",
"'us-east-1'",
")",
":",
"LOG",
".",
"info",
"(",
"'Find %s ELB DNS Zone ID in %s [%s].'",
",",
"name",
",",
"env",
",",
"region",
")",
"client",
"=",
"bot... | Get an application's AWS elb dns zone id.
Args:
name (str): ELB name
env (str): Environment/account of ELB
region (str): AWS Region
Returns:
str: elb DNS zone ID | [
"Get",
"an",
"application",
"s",
"AWS",
"elb",
"dns",
"zone",
"id",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/utils/elb.py#L61-L76 |
foremast/foremast | src/foremast/version.py | get_version | def get_version():
"""Retrieve package version."""
version = 'Not installed.'
try:
version = pkg_resources.get_distribution(__package__).version
except pkg_resources.DistributionNotFound:
pass
return version | python | def get_version():
"""Retrieve package version."""
version = 'Not installed.'
try:
version = pkg_resources.get_distribution(__package__).version
except pkg_resources.DistributionNotFound:
pass
return version | [
"def",
"get_version",
"(",
")",
":",
"version",
"=",
"'Not installed.'",
"try",
":",
"version",
"=",
"pkg_resources",
".",
"get_distribution",
"(",
"__package__",
")",
".",
"version",
"except",
"pkg_resources",
".",
"DistributionNotFound",
":",
"pass",
"return",
... | Retrieve package version. | [
"Retrieve",
"package",
"version",
"."
] | train | https://github.com/foremast/foremast/blob/fb70f29b8ce532f061685a17d120486e47b215ba/src/foremast/version.py#L5-L14 |
szastupov/aiotg | aiotg/reloader.py | reload | def reload():
""" Reload process """
try:
# Reload and replace current process
os.execv(sys.executable, [sys.executable] + sys.argv)
except OSError:
# Ugh, that failed
# Try spawning a new process and exitj
os.spawnv(os.P_NOWAIT, sys.executable, [sys.executable] + sy... | python | def reload():
""" Reload process """
try:
# Reload and replace current process
os.execv(sys.executable, [sys.executable] + sys.argv)
except OSError:
# Ugh, that failed
# Try spawning a new process and exitj
os.spawnv(os.P_NOWAIT, sys.executable, [sys.executable] + sy... | [
"def",
"reload",
"(",
")",
":",
"try",
":",
"# Reload and replace current process",
"os",
".",
"execv",
"(",
"sys",
".",
"executable",
",",
"[",
"sys",
".",
"executable",
"]",
"+",
"sys",
".",
"argv",
")",
"except",
"OSError",
":",
"# Ugh, that failed",
"#... | Reload process | [
"Reload",
"process"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/reloader.py#L46-L56 |
szastupov/aiotg | aiotg/reloader.py | run_with_reloader | async def run_with_reloader(loop, coroutine, cleanup=None, *args, **kwargs):
""" Run coroutine with reloader """
clear_screen()
print("🤖 Running in debug mode with live reloading")
print(" (don't forget to disable it for production)")
# Create watcher
handler = Handler(loop)
watcher =... | python | async def run_with_reloader(loop, coroutine, cleanup=None, *args, **kwargs):
""" Run coroutine with reloader """
clear_screen()
print("🤖 Running in debug mode with live reloading")
print(" (don't forget to disable it for production)")
# Create watcher
handler = Handler(loop)
watcher =... | [
"async",
"def",
"run_with_reloader",
"(",
"loop",
",",
"coroutine",
",",
"cleanup",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"clear_screen",
"(",
")",
"print",
"(",
"\"🤖 Running in debug mode with live reloading\")",
"",
"print",
"("... | Run coroutine with reloader | [
"Run",
"coroutine",
"with",
"reloader"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/reloader.py#L59-L90 |
szastupov/aiotg | aiotg/bot.py | Bot.loop | async def loop(self):
"""
Return bot's main loop as coroutine. Use with asyncio.
:Example:
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(bot.loop())
or
>>> loop = asyncio.get_event_loop()
>>> loop.create_task(bot.loop())
"""
... | python | async def loop(self):
"""
Return bot's main loop as coroutine. Use with asyncio.
:Example:
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(bot.loop())
or
>>> loop = asyncio.get_event_loop()
>>> loop.create_task(bot.loop())
"""
... | [
"async",
"def",
"loop",
"(",
"self",
")",
":",
"self",
".",
"_running",
"=",
"True",
"while",
"self",
".",
"_running",
":",
"updates",
"=",
"await",
"self",
".",
"api_call",
"(",
"\"getUpdates\"",
",",
"offset",
"=",
"self",
".",
"_offset",
"+",
"1",
... | Return bot's main loop as coroutine. Use with asyncio.
:Example:
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(bot.loop())
or
>>> loop = asyncio.get_event_loop()
>>> loop.create_task(bot.loop()) | [
"Return",
"bot",
"s",
"main",
"loop",
"as",
"coroutine",
".",
"Use",
"with",
"asyncio",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L134-L153 |
szastupov/aiotg | aiotg/bot.py | Bot.run | def run(self, debug=False, reload=None):
"""
Convenience method for running bots in getUpdates mode
:param bool debug: Enable debug logging and automatic reloading
:param bool reload: Automatically reload bot on code change
:Example:
>>> if __name__ == '__main__':
... | python | def run(self, debug=False, reload=None):
"""
Convenience method for running bots in getUpdates mode
:param bool debug: Enable debug logging and automatic reloading
:param bool reload: Automatically reload bot on code change
:Example:
>>> if __name__ == '__main__':
... | [
"def",
"run",
"(",
"self",
",",
"debug",
"=",
"False",
",",
"reload",
"=",
"None",
")",
":",
"loop",
"=",
"asyncio",
".",
"get_event_loop",
"(",
")",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
"if",
"debug",
"else",
"l... | Convenience method for running bots in getUpdates mode
:param bool debug: Enable debug logging and automatic reloading
:param bool reload: Automatically reload bot on code change
:Example:
>>> if __name__ == '__main__':
>>> bot.run() | [
"Convenience",
"method",
"for",
"running",
"bots",
"in",
"getUpdates",
"mode"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L155-L196 |
szastupov/aiotg | aiotg/bot.py | Bot.run_webhook | def run_webhook(self, webhook_url, **options):
"""
Convenience method for running bots in webhook mode
:Example:
>>> if __name__ == '__main__':
>>> bot.run_webhook(webhook_url="https://yourserver.com/webhooktoken")
Additional documentation on https://core.telegram.... | python | def run_webhook(self, webhook_url, **options):
"""
Convenience method for running bots in webhook mode
:Example:
>>> if __name__ == '__main__':
>>> bot.run_webhook(webhook_url="https://yourserver.com/webhooktoken")
Additional documentation on https://core.telegram.... | [
"def",
"run_webhook",
"(",
"self",
",",
"webhook_url",
",",
"*",
"*",
"options",
")",
":",
"loop",
"=",
"asyncio",
".",
"get_event_loop",
"(",
")",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"set_webhook",
"(",
"webhook_url",
",",
"*",
"*",
"op... | Convenience method for running bots in webhook mode
:Example:
>>> if __name__ == '__main__':
>>> bot.run_webhook(webhook_url="https://yourserver.com/webhooktoken")
Additional documentation on https://core.telegram.org/bots/api#setwebhook | [
"Convenience",
"method",
"for",
"running",
"bots",
"in",
"webhook",
"mode"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L198-L222 |
szastupov/aiotg | aiotg/bot.py | Bot.command | def command(self, regexp):
"""
Register a new command
:param str regexp: Regular expression matching the command to register
:Example:
>>> @bot.command(r"/echo (.+)")
>>> def echo(chat, match):
>>> return chat.reply(match.group(1))
"""
def ... | python | def command(self, regexp):
"""
Register a new command
:param str regexp: Regular expression matching the command to register
:Example:
>>> @bot.command(r"/echo (.+)")
>>> def echo(chat, match):
>>> return chat.reply(match.group(1))
"""
def ... | [
"def",
"command",
"(",
"self",
",",
"regexp",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"self",
".",
"add_command",
"(",
"regexp",
",",
"fn",
")",
"return",
"fn",
"return",
"decorator"
] | Register a new command
:param str regexp: Regular expression matching the command to register
:Example:
>>> @bot.command(r"/echo (.+)")
>>> def echo(chat, match):
>>> return chat.reply(match.group(1)) | [
"Register",
"a",
"new",
"command"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L236-L253 |
szastupov/aiotg | aiotg/bot.py | Bot.inline | def inline(self, callback):
"""
Set callback for inline queries
:Example:
>>> @bot.inline
>>> def echo(iq):
>>> return iq.answer([
>>> {"type": "text", "title": "test", "id": "0"}
>>> ])
>>> @bot.inline(r"myinline-(.+)")
... | python | def inline(self, callback):
"""
Set callback for inline queries
:Example:
>>> @bot.inline
>>> def echo(iq):
>>> return iq.answer([
>>> {"type": "text", "title": "test", "id": "0"}
>>> ])
>>> @bot.inline(r"myinline-(.+)")
... | [
"def",
"inline",
"(",
"self",
",",
"callback",
")",
":",
"if",
"callable",
"(",
"callback",
")",
":",
"self",
".",
"_default_inline",
"=",
"callback",
"return",
"callback",
"elif",
"isinstance",
"(",
"callback",
",",
"str",
")",
":",
"def",
"decorator",
... | Set callback for inline queries
:Example:
>>> @bot.inline
>>> def echo(iq):
>>> return iq.answer([
>>> {"type": "text", "title": "test", "id": "0"}
>>> ])
>>> @bot.inline(r"myinline-(.+)")
>>> def echo(chat, iq, match):
>>> r... | [
"Set",
"callback",
"for",
"inline",
"queries"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L276-L305 |
szastupov/aiotg | aiotg/bot.py | Bot.callback | def callback(self, callback):
"""
Set callback for callback queries
:Example:
>>> @bot.callback
>>> def echo(chat, cq):
>>> return cq.answer()
>>> @bot.callback(r"buttonclick-(.+)")
>>> def echo(chat, cq, match):
>>> return chat.reply(ma... | python | def callback(self, callback):
"""
Set callback for callback queries
:Example:
>>> @bot.callback
>>> def echo(chat, cq):
>>> return cq.answer()
>>> @bot.callback(r"buttonclick-(.+)")
>>> def echo(chat, cq, match):
>>> return chat.reply(ma... | [
"def",
"callback",
"(",
"self",
",",
"callback",
")",
":",
"if",
"callable",
"(",
"callback",
")",
":",
"self",
".",
"_default_callback",
"=",
"callback",
"return",
"callback",
"elif",
"isinstance",
"(",
"callback",
",",
"str",
")",
":",
"def",
"decorator"... | Set callback for callback queries
:Example:
>>> @bot.callback
>>> def echo(chat, cq):
>>> return cq.answer()
>>> @bot.callback(r"buttonclick-(.+)")
>>> def echo(chat, cq, match):
>>> return chat.reply(match.group(1)) | [
"Set",
"callback",
"for",
"callback",
"queries"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L313-L338 |
szastupov/aiotg | aiotg/bot.py | Bot.handle | def handle(self, msg_type):
"""
Set handler for specific message type
:Example:
>>> @bot.handle("audio")
>>> def handle(chat, audio):
>>> pass
"""
def wrap(callback):
self._handlers[msg_type] = callback
return callback
... | python | def handle(self, msg_type):
"""
Set handler for specific message type
:Example:
>>> @bot.handle("audio")
>>> def handle(chat, audio):
>>> pass
"""
def wrap(callback):
self._handlers[msg_type] = callback
return callback
... | [
"def",
"handle",
"(",
"self",
",",
"msg_type",
")",
":",
"def",
"wrap",
"(",
"callback",
")",
":",
"self",
".",
"_handlers",
"[",
"msg_type",
"]",
"=",
"callback",
"return",
"callback",
"return",
"wrap"
] | Set handler for specific message type
:Example:
>>> @bot.handle("audio")
>>> def handle(chat, audio):
>>> pass | [
"Set",
"handler",
"for",
"specific",
"message",
"type"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L359-L374 |
szastupov/aiotg | aiotg/bot.py | Bot.api_call | def api_call(self, method, **params):
"""
Call Telegram API.
See https://core.telegram.org/bots/api for reference.
:param str method: Telegram API method
:param params: Arguments for the method call
"""
coro = self._api_call(method, **params)
# Explicitl... | python | def api_call(self, method, **params):
"""
Call Telegram API.
See https://core.telegram.org/bots/api for reference.
:param str method: Telegram API method
:param params: Arguments for the method call
"""
coro = self._api_call(method, **params)
# Explicitl... | [
"def",
"api_call",
"(",
"self",
",",
"method",
",",
"*",
"*",
"params",
")",
":",
"coro",
"=",
"self",
".",
"_api_call",
"(",
"method",
",",
"*",
"*",
"params",
")",
"# Explicitly ensure that API call is executed",
"return",
"asyncio",
".",
"ensure_future",
... | Call Telegram API.
See https://core.telegram.org/bots/api for reference.
:param str method: Telegram API method
:param params: Arguments for the method call | [
"Call",
"Telegram",
"API",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L400-L411 |
szastupov/aiotg | aiotg/bot.py | Bot.send_message | def send_message(self, chat_id, text, **options):
"""
Send a text message to chat
:param int chat_id: ID of the chat to send the message to
:param str text: Text to send
:param options: Additional sendMessage options
(see https://core.telegram.org/bots/api#sendmessag... | python | def send_message(self, chat_id, text, **options):
"""
Send a text message to chat
:param int chat_id: ID of the chat to send the message to
:param str text: Text to send
:param options: Additional sendMessage options
(see https://core.telegram.org/bots/api#sendmessag... | [
"def",
"send_message",
"(",
"self",
",",
"chat_id",
",",
"text",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"api_call",
"(",
"\"sendMessage\"",
",",
"chat_id",
"=",
"chat_id",
",",
"text",
"=",
"text",
",",
"*",
"*",
"options",
")"
] | Send a text message to chat
:param int chat_id: ID of the chat to send the message to
:param str text: Text to send
:param options: Additional sendMessage options
(see https://core.telegram.org/bots/api#sendmessage) | [
"Send",
"a",
"text",
"message",
"to",
"chat"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L461-L470 |
szastupov/aiotg | aiotg/bot.py | Bot.edit_message_text | def edit_message_text(self, chat_id, message_id, text, **options):
"""
Edit a text message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param options:... | python | def edit_message_text(self, chat_id, message_id, text, **options):
"""
Edit a text message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param options:... | [
"def",
"edit_message_text",
"(",
"self",
",",
"chat_id",
",",
"message_id",
",",
"text",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"api_call",
"(",
"\"editMessageText\"",
",",
"chat_id",
"=",
"chat_id",
",",
"message_id",
"=",
"message_id",
... | Edit a text message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param options: Additional API options | [
"Edit",
"a",
"text",
"message",
"in",
"a",
"chat"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L472-L487 |
szastupov/aiotg | aiotg/bot.py | Bot.edit_message_reply_markup | def edit_message_reply_markup(self, chat_id, message_id, reply_markup, **options):
"""
Edit a reply markup of message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str reply_markup: New inline keybo... | python | def edit_message_reply_markup(self, chat_id, message_id, reply_markup, **options):
"""
Edit a reply markup of message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str reply_markup: New inline keybo... | [
"def",
"edit_message_reply_markup",
"(",
"self",
",",
"chat_id",
",",
"message_id",
",",
"reply_markup",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"api_call",
"(",
"\"editMessageReplyMarkup\"",
",",
"chat_id",
"=",
"chat_id",
",",
"message_id",
... | Edit a reply markup of message in a chat
:param int chat_id: ID of the chat the message to edit is in
:param int message_id: ID of the message to edit
:param str reply_markup: New inline keyboard markup for the message
:param options: Additional API options | [
"Edit",
"a",
"reply",
"markup",
"of",
"message",
"in",
"a",
"chat"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L489-L504 |
szastupov/aiotg | aiotg/bot.py | Bot.download_file | def download_file(self, file_path, range=None):
"""
Download a file from Telegram servers
"""
headers = {"range": range} if range else None
url = "{0}/file/bot{1}/{2}".format(API_URL, self.api_token, file_path)
return self.session.get(
url, headers=headers, pr... | python | def download_file(self, file_path, range=None):
"""
Download a file from Telegram servers
"""
headers = {"range": range} if range else None
url = "{0}/file/bot{1}/{2}".format(API_URL, self.api_token, file_path)
return self.session.get(
url, headers=headers, pr... | [
"def",
"download_file",
"(",
"self",
",",
"file_path",
",",
"range",
"=",
"None",
")",
":",
"headers",
"=",
"{",
"\"range\"",
":",
"range",
"}",
"if",
"range",
"else",
"None",
"url",
"=",
"\"{0}/file/bot{1}/{2}\"",
".",
"format",
"(",
"API_URL",
",",
"se... | Download a file from Telegram servers | [
"Download",
"a",
"file",
"from",
"Telegram",
"servers"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L516-L524 |
szastupov/aiotg | aiotg/bot.py | Bot.get_user_profile_photos | def get_user_profile_photos(self, user_id, **options):
"""
Get a list of profile pictures for a user
:param int user_id: Unique identifier of the target user
:param options: Additional getUserProfilePhotos options (see
https://core.telegram.org/bots/api#getuserprofilephotos)... | python | def get_user_profile_photos(self, user_id, **options):
"""
Get a list of profile pictures for a user
:param int user_id: Unique identifier of the target user
:param options: Additional getUserProfilePhotos options (see
https://core.telegram.org/bots/api#getuserprofilephotos)... | [
"def",
"get_user_profile_photos",
"(",
"self",
",",
"user_id",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"api_call",
"(",
"\"getUserProfilePhotos\"",
",",
"user_id",
"=",
"str",
"(",
"user_id",
")",
",",
"*",
"*",
"options",
")"
] | Get a list of profile pictures for a user
:param int user_id: Unique identifier of the target user
:param options: Additional getUserProfilePhotos options (see
https://core.telegram.org/bots/api#getuserprofilephotos) | [
"Get",
"a",
"list",
"of",
"profile",
"pictures",
"for",
"a",
"user"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L526-L534 |
szastupov/aiotg | aiotg/bot.py | Bot.track | def track(self, message, name="Message"):
"""
Track message using http://chatbase.com
Set chatbase_token to make it work
"""
if self.chatbase_token:
asyncio.ensure_future(self._track(message, name)) | python | def track(self, message, name="Message"):
"""
Track message using http://chatbase.com
Set chatbase_token to make it work
"""
if self.chatbase_token:
asyncio.ensure_future(self._track(message, name)) | [
"def",
"track",
"(",
"self",
",",
"message",
",",
"name",
"=",
"\"Message\"",
")",
":",
"if",
"self",
".",
"chatbase_token",
":",
"asyncio",
".",
"ensure_future",
"(",
"self",
".",
"_track",
"(",
"message",
",",
"name",
")",
")"
] | Track message using http://chatbase.com
Set chatbase_token to make it work | [
"Track",
"message",
"using",
"http",
":",
"//",
"chatbase",
".",
"com",
"Set",
"chatbase_token",
"to",
"make",
"it",
"work"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L536-L542 |
szastupov/aiotg | aiotg/bot.py | Bot.webhook_handle | async def webhook_handle(self, request):
"""
aiohttp.web handle for processing web hooks
:Example:
>>> from aiohttp import web
>>> app = web.Application()
>>> app.router.add_route('/webhook')
"""
update = await request.json(loads=self.json_deserialize)
... | python | async def webhook_handle(self, request):
"""
aiohttp.web handle for processing web hooks
:Example:
>>> from aiohttp import web
>>> app = web.Application()
>>> app.router.add_route('/webhook')
"""
update = await request.json(loads=self.json_deserialize)
... | [
"async",
"def",
"webhook_handle",
"(",
"self",
",",
"request",
")",
":",
"update",
"=",
"await",
"request",
".",
"json",
"(",
"loads",
"=",
"self",
".",
"json_deserialize",
")",
"self",
".",
"_process_update",
"(",
"update",
")",
"return",
"web",
".",
"R... | aiohttp.web handle for processing web hooks
:Example:
>>> from aiohttp import web
>>> app = web.Application()
>>> app.router.add_route('/webhook') | [
"aiohttp",
".",
"web",
"handle",
"for",
"processing",
"web",
"hooks"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L547-L559 |
szastupov/aiotg | aiotg/bot.py | Bot.create_webhook_app | def create_webhook_app(self, path, loop=None):
"""
Shorthand for creating aiohttp.web.Application with registered webhook hanlde
"""
app = web.Application(loop=loop)
app.router.add_route("POST", path, self.webhook_handle)
return app | python | def create_webhook_app(self, path, loop=None):
"""
Shorthand for creating aiohttp.web.Application with registered webhook hanlde
"""
app = web.Application(loop=loop)
app.router.add_route("POST", path, self.webhook_handle)
return app | [
"def",
"create_webhook_app",
"(",
"self",
",",
"path",
",",
"loop",
"=",
"None",
")",
":",
"app",
"=",
"web",
".",
"Application",
"(",
"loop",
"=",
"loop",
")",
"app",
".",
"router",
".",
"add_route",
"(",
"\"POST\"",
",",
"path",
",",
"self",
".",
... | Shorthand for creating aiohttp.web.Application with registered webhook hanlde | [
"Shorthand",
"for",
"creating",
"aiohttp",
".",
"web",
".",
"Application",
"with",
"registered",
"webhook",
"hanlde"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/bot.py#L561-L567 |
szastupov/aiotg | aiotg/chat.py | Chat.send_text | def send_text(self, text, **options):
"""
Send a text message to the chat.
:param str text: Text of the message to send
:param options: Additional sendMessage options (see
https://core.telegram.org/bots/api#sendmessage
"""
return self.bot.send_message(self.id... | python | def send_text(self, text, **options):
"""
Send a text message to the chat.
:param str text: Text of the message to send
:param options: Additional sendMessage options (see
https://core.telegram.org/bots/api#sendmessage
"""
return self.bot.send_message(self.id... | [
"def",
"send_text",
"(",
"self",
",",
"text",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"send_message",
"(",
"self",
".",
"id",
",",
"text",
",",
"*",
"*",
"options",
")"
] | Send a text message to the chat.
:param str text: Text of the message to send
:param options: Additional sendMessage options (see
https://core.telegram.org/bots/api#sendmessage | [
"Send",
"a",
"text",
"message",
"to",
"the",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L11-L19 |
szastupov/aiotg | aiotg/chat.py | Chat.reply | def reply(self, text, markup=None, parse_mode=None):
"""
Reply to the message this `Chat` object is based on.
:param str text: Text of the message to send
:param dict markup: Markup options
:param str parse_mode: Text parsing mode (``"Markdown"``, ``"HTML"`` or
``Non... | python | def reply(self, text, markup=None, parse_mode=None):
"""
Reply to the message this `Chat` object is based on.
:param str text: Text of the message to send
:param dict markup: Markup options
:param str parse_mode: Text parsing mode (``"Markdown"``, ``"HTML"`` or
``Non... | [
"def",
"reply",
"(",
"self",
",",
"text",
",",
"markup",
"=",
"None",
",",
"parse_mode",
"=",
"None",
")",
":",
"if",
"markup",
"is",
"None",
":",
"markup",
"=",
"{",
"}",
"return",
"self",
".",
"send_text",
"(",
"text",
",",
"reply_to_message_id",
"... | Reply to the message this `Chat` object is based on.
:param str text: Text of the message to send
:param dict markup: Markup options
:param str parse_mode: Text parsing mode (``"Markdown"``, ``"HTML"`` or
``None``) | [
"Reply",
"to",
"the",
"message",
"this",
"Chat",
"object",
"is",
"based",
"on",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L21-L39 |
szastupov/aiotg | aiotg/chat.py | Chat.edit_text | def edit_text(self, message_id, text, markup=None, parse_mode=None):
"""
Edit the message in this chat.
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param dict markup: Markup options
:param str parse_mode: Text parsing mo... | python | def edit_text(self, message_id, text, markup=None, parse_mode=None):
"""
Edit the message in this chat.
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param dict markup: Markup options
:param str parse_mode: Text parsing mo... | [
"def",
"edit_text",
"(",
"self",
",",
"message_id",
",",
"text",
",",
"markup",
"=",
"None",
",",
"parse_mode",
"=",
"None",
")",
":",
"if",
"markup",
"is",
"None",
":",
"markup",
"=",
"{",
"}",
"return",
"self",
".",
"bot",
".",
"edit_message_text",
... | Edit the message in this chat.
:param int message_id: ID of the message to edit
:param str text: Text to edit the message to
:param dict markup: Markup options
:param str parse_mode: Text parsing mode (``"Markdown"``, ``"HTML"`` or
``None``) | [
"Edit",
"the",
"message",
"in",
"this",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L41-L60 |
szastupov/aiotg | aiotg/chat.py | Chat.edit_reply_markup | def edit_reply_markup(self, message_id, markup):
"""
Edit only reply markup of the message in this chat.
:param int message_id: ID of the message to edit
:param dict markup: Markup options
"""
return self.bot.edit_message_reply_markup(
self.id, message_id, re... | python | def edit_reply_markup(self, message_id, markup):
"""
Edit only reply markup of the message in this chat.
:param int message_id: ID of the message to edit
:param dict markup: Markup options
"""
return self.bot.edit_message_reply_markup(
self.id, message_id, re... | [
"def",
"edit_reply_markup",
"(",
"self",
",",
"message_id",
",",
"markup",
")",
":",
"return",
"self",
".",
"bot",
".",
"edit_message_reply_markup",
"(",
"self",
".",
"id",
",",
"message_id",
",",
"reply_markup",
"=",
"self",
".",
"bot",
".",
"json_serialize... | Edit only reply markup of the message in this chat.
:param int message_id: ID of the message to edit
:param dict markup: Markup options | [
"Edit",
"only",
"reply",
"markup",
"of",
"the",
"message",
"in",
"this",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L62-L71 |
szastupov/aiotg | aiotg/chat.py | Chat.get_chat_member | def get_chat_member(self, user_id):
"""
Get information about a member of a chat.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call(
"getChatMember", chat_id=str(self.id), user_id=str(user_id)
) | python | def get_chat_member(self, user_id):
"""
Get information about a member of a chat.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call(
"getChatMember", chat_id=str(self.id), user_id=str(user_id)
) | [
"def",
"get_chat_member",
"(",
"self",
",",
"user_id",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"getChatMember\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"user_id",
"=",
"str",
"(",
"user_id",
")",
")"
] | Get information about a member of a chat.
:param int user_id: Unique identifier of the target user | [
"Get",
"information",
"about",
"a",
"member",
"of",
"a",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L91-L99 |
szastupov/aiotg | aiotg/chat.py | Chat.send_sticker | def send_sticker(self, sticker, **options):
"""
Send a sticker to the chat.
:param sticker: Sticker to send (file or string)
:param options: Additional sendSticker options (see
https://core.telegram.org/bots/api#sendsticker)
"""
return self.bot.api_call(
... | python | def send_sticker(self, sticker, **options):
"""
Send a sticker to the chat.
:param sticker: Sticker to send (file or string)
:param options: Additional sendSticker options (see
https://core.telegram.org/bots/api#sendsticker)
"""
return self.bot.api_call(
... | [
"def",
"send_sticker",
"(",
"self",
",",
"sticker",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendSticker\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"sticker",
"=",
"sticker",
",... | Send a sticker to the chat.
:param sticker: Sticker to send (file or string)
:param options: Additional sendSticker options (see
https://core.telegram.org/bots/api#sendsticker) | [
"Send",
"a",
"sticker",
"to",
"the",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L101-L111 |
szastupov/aiotg | aiotg/chat.py | Chat.send_audio | def send_audio(self, audio, **options):
"""
Send an mp3 audio file to the chat.
:param audio: Object containing the audio data
:param options: Additional sendAudio options (see
https://core.telegram.org/bots/api#sendaudio)
:Example:
>>> with open("foo.mp3",... | python | def send_audio(self, audio, **options):
"""
Send an mp3 audio file to the chat.
:param audio: Object containing the audio data
:param options: Additional sendAudio options (see
https://core.telegram.org/bots/api#sendaudio)
:Example:
>>> with open("foo.mp3",... | [
"def",
"send_audio",
"(",
"self",
",",
"audio",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendAudio\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"audio",
"=",
"audio",
",",
"*",
... | Send an mp3 audio file to the chat.
:param audio: Object containing the audio data
:param options: Additional sendAudio options (see
https://core.telegram.org/bots/api#sendaudio)
:Example:
>>> with open("foo.mp3", "rb") as f:
>>> await chat.send_audio(f, perfor... | [
"Send",
"an",
"mp3",
"audio",
"file",
"to",
"the",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L113-L128 |
szastupov/aiotg | aiotg/chat.py | Chat.send_photo | def send_photo(self, photo, caption="", **options):
"""
Send a photo to the chat.
:param photo: Object containing the photo data
:param str caption: Photo caption (optional)
:param options: Additional sendPhoto options (see
https://core.telegram.org/bots/api#sendphot... | python | def send_photo(self, photo, caption="", **options):
"""
Send a photo to the chat.
:param photo: Object containing the photo data
:param str caption: Photo caption (optional)
:param options: Additional sendPhoto options (see
https://core.telegram.org/bots/api#sendphot... | [
"def",
"send_photo",
"(",
"self",
",",
"photo",
",",
"caption",
"=",
"\"\"",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendPhoto\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"pho... | Send a photo to the chat.
:param photo: Object containing the photo data
:param str caption: Photo caption (optional)
:param options: Additional sendPhoto options (see
https://core.telegram.org/bots/api#sendphoto)
:Example:
>>> with open("foo.png", "rb") as f:
... | [
"Send",
"a",
"photo",
"to",
"the",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L130-L146 |
szastupov/aiotg | aiotg/chat.py | Chat.send_video | def send_video(self, video, caption="", **options):
"""
Send an mp4 video file to the chat.
:param video: Object containing the video data
:param str caption: Video caption (optional)
:param options: Additional sendVideo options (see
https://core.telegram.org/bots/ap... | python | def send_video(self, video, caption="", **options):
"""
Send an mp4 video file to the chat.
:param video: Object containing the video data
:param str caption: Video caption (optional)
:param options: Additional sendVideo options (see
https://core.telegram.org/bots/ap... | [
"def",
"send_video",
"(",
"self",
",",
"video",
",",
"caption",
"=",
"\"\"",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendVideo\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"vid... | Send an mp4 video file to the chat.
:param video: Object containing the video data
:param str caption: Video caption (optional)
:param options: Additional sendVideo options (see
https://core.telegram.org/bots/api#sendvideo)
:Example:
>>> with open("foo.mp4", "rb") ... | [
"Send",
"an",
"mp4",
"video",
"file",
"to",
"the",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L148-L164 |
szastupov/aiotg | aiotg/chat.py | Chat.send_document | def send_document(self, document, caption="", **options):
"""
Send a general file.
:param document: Object containing the document data
:param str caption: Document caption (optional)
:param options: Additional sendDocument options (see
https://core.telegram.org/bots... | python | def send_document(self, document, caption="", **options):
"""
Send a general file.
:param document: Object containing the document data
:param str caption: Document caption (optional)
:param options: Additional sendDocument options (see
https://core.telegram.org/bots... | [
"def",
"send_document",
"(",
"self",
",",
"document",
",",
"caption",
"=",
"\"\"",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendDocument\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",... | Send a general file.
:param document: Object containing the document data
:param str caption: Document caption (optional)
:param options: Additional sendDocument options (see
https://core.telegram.org/bots/api#senddocument)
:Example:
>>> with open("file.doc", "rb")... | [
"Send",
"a",
"general",
"file",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L166-L186 |
szastupov/aiotg | aiotg/chat.py | Chat.send_voice | def send_voice(self, voice, **options):
"""
Send an OPUS-encoded .ogg audio file.
:param voice: Object containing the audio data
:param options: Additional sendVoice options (see
https://core.telegram.org/bots/api#sendvoice)
:Example:
>>> with open("voice.o... | python | def send_voice(self, voice, **options):
"""
Send an OPUS-encoded .ogg audio file.
:param voice: Object containing the audio data
:param options: Additional sendVoice options (see
https://core.telegram.org/bots/api#sendvoice)
:Example:
>>> with open("voice.o... | [
"def",
"send_voice",
"(",
"self",
",",
"voice",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendVoice\"",
",",
"chat_id",
"=",
"str",
"(",
"self",
".",
"id",
")",
",",
"voice",
"=",
"voice",
",",
"*",
... | Send an OPUS-encoded .ogg audio file.
:param voice: Object containing the audio data
:param options: Additional sendVoice options (see
https://core.telegram.org/bots/api#sendvoice)
:Example:
>>> with open("voice.ogg", "rb") as f:
>>> await chat.send_voice(f) | [
"Send",
"an",
"OPUS",
"-",
"encoded",
".",
"ogg",
"audio",
"file",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L188-L203 |
szastupov/aiotg | aiotg/chat.py | Chat.send_location | def send_location(self, latitude, longitude, **options):
"""
Send a point on the map.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param options: Additional sendLocation options (see
https://core.telegram.org/bots... | python | def send_location(self, latitude, longitude, **options):
"""
Send a point on the map.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param options: Additional sendLocation options (see
https://core.telegram.org/bots... | [
"def",
"send_location",
"(",
"self",
",",
"latitude",
",",
"longitude",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendLocation\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"latitude",
"=",
"latitude",
... | Send a point on the map.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param options: Additional sendLocation options (see
https://core.telegram.org/bots/api#sendlocation) | [
"Send",
"a",
"point",
"on",
"the",
"map",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L205-L220 |
szastupov/aiotg | aiotg/chat.py | Chat.send_venue | def send_venue(self, latitude, longitude, title, address, **options):
"""
Send information about a venue.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param str title: Name of the venue
:param str address: Address of ... | python | def send_venue(self, latitude, longitude, title, address, **options):
"""
Send information about a venue.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param str title: Name of the venue
:param str address: Address of ... | [
"def",
"send_venue",
"(",
"self",
",",
"latitude",
",",
"longitude",
",",
"title",
",",
"address",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendVenue\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"... | Send information about a venue.
:param float latitude: Latitude of the location
:param float longitude: Longitude of the location
:param str title: Name of the venue
:param str address: Address of the venue
:param options: Additional sendVenue options (see
https://co... | [
"Send",
"information",
"about",
"a",
"venue",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L222-L241 |
szastupov/aiotg | aiotg/chat.py | Chat.send_contact | def send_contact(self, phone_number, first_name, **options):
"""
Send phone contacts.
:param str phone_number: Contact's phone number
:param str first_name: Contact's first name
:param options: Additional sendContact options (see
https://core.telegram.org/bots/api#se... | python | def send_contact(self, phone_number, first_name, **options):
"""
Send phone contacts.
:param str phone_number: Contact's phone number
:param str first_name: Contact's first name
:param options: Additional sendContact options (see
https://core.telegram.org/bots/api#se... | [
"def",
"send_contact",
"(",
"self",
",",
"phone_number",
",",
"first_name",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendContact\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"phone_number",
"=",
"phon... | Send phone contacts.
:param str phone_number: Contact's phone number
:param str first_name: Contact's first name
:param options: Additional sendContact options (see
https://core.telegram.org/bots/api#sendcontact) | [
"Send",
"phone",
"contacts",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L243-L258 |
szastupov/aiotg | aiotg/chat.py | Chat.send_chat_action | def send_chat_action(self, action):
"""
Send a chat action, to tell the user that something is happening on the
bot's side.
Available actions:
* `typing` for text messages
* `upload_photo` for photos
* `record_video` and `upload_video` for videos
* `... | python | def send_chat_action(self, action):
"""
Send a chat action, to tell the user that something is happening on the
bot's side.
Available actions:
* `typing` for text messages
* `upload_photo` for photos
* `record_video` and `upload_video` for videos
* `... | [
"def",
"send_chat_action",
"(",
"self",
",",
"action",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"sendChatAction\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"action",
"=",
"action",
")"
] | Send a chat action, to tell the user that something is happening on the
bot's side.
Available actions:
* `typing` for text messages
* `upload_photo` for photos
* `record_video` and `upload_video` for videos
* `record_audio` and `upload_audio` for audio files
... | [
"Send",
"a",
"chat",
"action",
"to",
"tell",
"the",
"user",
"that",
"something",
"is",
"happening",
"on",
"the",
"bot",
"s",
"side",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L260-L276 |
szastupov/aiotg | aiotg/chat.py | Chat.send_media_group | def send_media_group(
self,
media: str,
disable_notification: bool = False,
reply_to_message_id: int = None,
**options
):
"""
Send a group of photos or videos as an album
:param media: A JSON-serialized array describing photos and videos
to be... | python | def send_media_group(
self,
media: str,
disable_notification: bool = False,
reply_to_message_id: int = None,
**options
):
"""
Send a group of photos or videos as an album
:param media: A JSON-serialized array describing photos and videos
to be... | [
"def",
"send_media_group",
"(",
"self",
",",
"media",
":",
"str",
",",
"disable_notification",
":",
"bool",
"=",
"False",
",",
"reply_to_message_id",
":",
"int",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_cal... | Send a group of photos or videos as an album
:param media: A JSON-serialized array describing photos and videos
to be sent, must include 2–10 items
:param disable_notification: Sends the messages silently. Users will
receive a notification with no sound.
:param reply_to_message_... | [
"Send",
"a",
"group",
"of",
"photos",
"or",
"videos",
"as",
"an",
"album"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L278-L322 |
szastupov/aiotg | aiotg/chat.py | Chat.forward_message | def forward_message(self, from_chat_id, message_id):
"""
Forward a message from another chat to this chat.
:param int from_chat_id: ID of the chat to forward the message from
:param int message_id: ID of the message to forward
"""
return self.bot.api_call(
"f... | python | def forward_message(self, from_chat_id, message_id):
"""
Forward a message from another chat to this chat.
:param int from_chat_id: ID of the chat to forward the message from
:param int message_id: ID of the message to forward
"""
return self.bot.api_call(
"f... | [
"def",
"forward_message",
"(",
"self",
",",
"from_chat_id",
",",
"message_id",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"forwardMessage\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"from_chat_id",
"=",
"from_chat_id",
",",
"message... | Forward a message from another chat to this chat.
:param int from_chat_id: ID of the chat to forward the message from
:param int message_id: ID of the message to forward | [
"Forward",
"a",
"message",
"from",
"another",
"chat",
"to",
"this",
"chat",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L324-L336 |
szastupov/aiotg | aiotg/chat.py | Chat.kick_chat_member | def kick_chat_member(self, user_id):
"""
Use this method to kick a user from a group or a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call("kickChatMember", c... | python | def kick_chat_member(self, user_id):
"""
Use this method to kick a user from a group or a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call("kickChatMember", c... | [
"def",
"kick_chat_member",
"(",
"self",
",",
"user_id",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"kickChatMember\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"user_id",
"=",
"user_id",
")"
] | Use this method to kick a user from a group or a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user | [
"Use",
"this",
"method",
"to",
"kick",
"a",
"user",
"from",
"a",
"group",
"or",
"a",
"supergroup",
".",
"The",
"bot",
"must",
"be",
"an",
"administrator",
"in",
"the",
"group",
"for",
"this",
"to",
"work",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L338-L345 |
szastupov/aiotg | aiotg/chat.py | Chat.unban_chat_member | def unban_chat_member(self, user_id):
"""
Use this method to unban a previously kicked user in a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call("unbanChatMe... | python | def unban_chat_member(self, user_id):
"""
Use this method to unban a previously kicked user in a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user
"""
return self.bot.api_call("unbanChatMe... | [
"def",
"unban_chat_member",
"(",
"self",
",",
"user_id",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"unbanChatMember\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"user_id",
"=",
"user_id",
")"
] | Use this method to unban a previously kicked user in a supergroup.
The bot must be an administrator in the group for this to work.
:param int user_id: Unique identifier of the target user | [
"Use",
"this",
"method",
"to",
"unban",
"a",
"previously",
"kicked",
"user",
"in",
"a",
"supergroup",
".",
"The",
"bot",
"must",
"be",
"an",
"administrator",
"in",
"the",
"group",
"for",
"this",
"to",
"work",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L347-L354 |
szastupov/aiotg | aiotg/chat.py | Chat.delete_message | def delete_message(self, message_id):
"""
Delete message from this chat
:param int message_id: ID of the message
"""
return self.bot.api_call(
"deleteMessage", chat_id=self.id, message_id=message_id
) | python | def delete_message(self, message_id):
"""
Delete message from this chat
:param int message_id: ID of the message
"""
return self.bot.api_call(
"deleteMessage", chat_id=self.id, message_id=message_id
) | [
"def",
"delete_message",
"(",
"self",
",",
"message_id",
")",
":",
"return",
"self",
".",
"bot",
".",
"api_call",
"(",
"\"deleteMessage\"",
",",
"chat_id",
"=",
"self",
".",
"id",
",",
"message_id",
"=",
"message_id",
")"
] | Delete message from this chat
:param int message_id: ID of the message | [
"Delete",
"message",
"from",
"this",
"chat"
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L356-L364 |
szastupov/aiotg | aiotg/chat.py | Chat.from_message | def from_message(bot, message):
"""
Create a ``Chat`` object from a message.
:param Bot bot: ``Bot`` object the message and chat belong to
:param dict message: Message to base the object on
:return: A chat object based on the message
"""
chat = message["chat"]
... | python | def from_message(bot, message):
"""
Create a ``Chat`` object from a message.
:param Bot bot: ``Bot`` object the message and chat belong to
:param dict message: Message to base the object on
:return: A chat object based on the message
"""
chat = message["chat"]
... | [
"def",
"from_message",
"(",
"bot",
",",
"message",
")",
":",
"chat",
"=",
"message",
"[",
"\"chat\"",
"]",
"return",
"Chat",
"(",
"bot",
",",
"chat",
"[",
"\"id\"",
"]",
",",
"chat",
"[",
"\"type\"",
"]",
",",
"message",
")"
] | Create a ``Chat`` object from a message.
:param Bot bot: ``Bot`` object the message and chat belong to
:param dict message: Message to base the object on
:return: A chat object based on the message | [
"Create",
"a",
"Chat",
"object",
"from",
"a",
"message",
"."
] | train | https://github.com/szastupov/aiotg/blob/eed81a6a728c02120f1d730a6e8b8fe50263c010/aiotg/chat.py#L386-L395 |
mnubo/kubernetes-py | kubernetes_py/K8sCronJob.py | K8sCronJob.run | def run(self, timeout=POD_RUN_WAIT_TIMEOUT_SECONDS):
"""
Forces a K8sCronJob to run immediately.
- Fail if the K8sCronJob is currently running on-schedule.
- Suspend the K8sCronJob.
- Spawn a K8sPod.
- Unsuspend a K8sCronJob.
:param timeout: The timeout, in seco... | python | def run(self, timeout=POD_RUN_WAIT_TIMEOUT_SECONDS):
"""
Forces a K8sCronJob to run immediately.
- Fail if the K8sCronJob is currently running on-schedule.
- Suspend the K8sCronJob.
- Spawn a K8sPod.
- Unsuspend a K8sCronJob.
:param timeout: The timeout, in seco... | [
"def",
"run",
"(",
"self",
",",
"timeout",
"=",
"POD_RUN_WAIT_TIMEOUT_SECONDS",
")",
":",
"if",
"not",
"isinstance",
"(",
"timeout",
",",
"int",
")",
":",
"raise",
"SyntaxError",
"(",
"\"K8sCronJob.run() timeout: [ {} ] is invalid.\"",
")",
"if",
"len",
"(",
"se... | Forces a K8sCronJob to run immediately.
- Fail if the K8sCronJob is currently running on-schedule.
- Suspend the K8sCronJob.
- Spawn a K8sPod.
- Unsuspend a K8sCronJob.
:param timeout: The timeout, in seconds, after which to kill the K8sPod.
:return: None. | [
"Forces",
"a",
"K8sCronJob",
"to",
"run",
"immediately",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sCronJob.py#L319-L362 |
mnubo/kubernetes-py | kubernetes_py/K8sReplicationController.py | K8sReplicationController.scale | def scale(config=None, name=None, replicas=None):
"""
Scales the number of pods in the specified K8sReplicationController to the desired replica count.
:param config: an instance of K8sConfig
:param name: the name of the ReplicationController we want to scale.
:param replicas:... | python | def scale(config=None, name=None, replicas=None):
"""
Scales the number of pods in the specified K8sReplicationController to the desired replica count.
:param config: an instance of K8sConfig
:param name: the name of the ReplicationController we want to scale.
:param replicas:... | [
"def",
"scale",
"(",
"config",
"=",
"None",
",",
"name",
"=",
"None",
",",
"replicas",
"=",
"None",
")",
":",
"rc",
"=",
"K8sReplicationController",
"(",
"config",
"=",
"config",
",",
"name",
"=",
"name",
")",
".",
"get",
"(",
")",
"rc",
".",
"desi... | Scales the number of pods in the specified K8sReplicationController to the desired replica count.
:param config: an instance of K8sConfig
:param name: the name of the ReplicationController we want to scale.
:param replicas: the desired number of replicas.
:return: An instance of K8sR... | [
"Scales",
"the",
"number",
"of",
"pods",
"in",
"the",
"specified",
"K8sReplicationController",
"to",
"the",
"desired",
"replica",
"count",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sReplicationController.py#L517-L534 |
mnubo/kubernetes-py | kubernetes_py/K8sReplicationController.py | K8sReplicationController.rolling_update | def rolling_update(config=None, name=None, image=None, container_name=None, rc_new=None):
"""
Performs a simple rolling update of a ReplicationController.
See https://github.com/kubernetes/kubernetes/blob/master/docs/design/simple-rolling-update.md
for algorithm details. We have modifie... | python | def rolling_update(config=None, name=None, image=None, container_name=None, rc_new=None):
"""
Performs a simple rolling update of a ReplicationController.
See https://github.com/kubernetes/kubernetes/blob/master/docs/design/simple-rolling-update.md
for algorithm details. We have modifie... | [
"def",
"rolling_update",
"(",
"config",
"=",
"None",
",",
"name",
"=",
"None",
",",
"image",
"=",
"None",
",",
"container_name",
"=",
"None",
",",
"rc_new",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"raise",
"SyntaxError",
"(",
"'K8sRepli... | Performs a simple rolling update of a ReplicationController.
See https://github.com/kubernetes/kubernetes/blob/master/docs/design/simple-rolling-update.md
for algorithm details. We have modified it slightly to allow for keeping the same RC name
between updates, which is not supported by default... | [
"Performs",
"a",
"simple",
"rolling",
"update",
"of",
"a",
"ReplicationController",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sReplicationController.py#L539-L577 |
mnubo/kubernetes-py | kubernetes_py/K8sReplicationController.py | K8sReplicationController.restart | def restart(self):
"""
Restart will force a rolling update of the current ReplicationController to the current revision.
This essentially spawns a fresh copy of the RC and its pods. Useful when something is misbehaving.
"""
rc_new = copy.deepcopy(self)
return K8sReplicat... | python | def restart(self):
"""
Restart will force a rolling update of the current ReplicationController to the current revision.
This essentially spawns a fresh copy of the RC and its pods. Useful when something is misbehaving.
"""
rc_new = copy.deepcopy(self)
return K8sReplicat... | [
"def",
"restart",
"(",
"self",
")",
":",
"rc_new",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
")",
"return",
"K8sReplicationController",
".",
"rolling_update",
"(",
"config",
"=",
"self",
".",
"config",
",",
"name",
"=",
"self",
".",
"name",
",",
"rc_new... | Restart will force a rolling update of the current ReplicationController to the current revision.
This essentially spawns a fresh copy of the RC and its pods. Useful when something is misbehaving. | [
"Restart",
"will",
"force",
"a",
"rolling",
"update",
"of",
"the",
"current",
"ReplicationController",
"to",
"the",
"current",
"revision",
".",
"This",
"essentially",
"spawns",
"a",
"fresh",
"copy",
"of",
"the",
"RC",
"and",
"its",
"pods",
".",
"Useful",
"wh... | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sReplicationController.py#L711-L721 |
mnubo/kubernetes-py | kubernetes_py/K8sNode.py | K8sNode.drain | def drain(self, ignore_daemonsets=False, delete_local_storage=False, force=False):
"""
Removes all K8sPods from this K8sNode,
and prevents additional K8sPods from being scheduled.
:param ignore_daemonsets: a boolean.
If false, will fail if a K8sDaemonSet-manage... | python | def drain(self, ignore_daemonsets=False, delete_local_storage=False, force=False):
"""
Removes all K8sPods from this K8sNode,
and prevents additional K8sPods from being scheduled.
:param ignore_daemonsets: a boolean.
If false, will fail if a K8sDaemonSet-manage... | [
"def",
"drain",
"(",
"self",
",",
"ignore_daemonsets",
"=",
"False",
",",
"delete_local_storage",
"=",
"False",
",",
"force",
"=",
"False",
")",
":",
"# inventory of K8sPods found on this node.",
"daemonset_pods",
"=",
"[",
"]",
"pods",
"=",
"self",
".",
"_pod_i... | Removes all K8sPods from this K8sNode,
and prevents additional K8sPods from being scheduled.
:param ignore_daemonsets: a boolean.
If false, will fail if a K8sDaemonSet-managed K8sPod is present.
If true, will continue even if a K8sDaemonSet-managed K8sPod is pr... | [
"Removes",
"all",
"K8sPods",
"from",
"this",
"K8sNode",
"and",
"prevents",
"additional",
"K8sPods",
"from",
"being",
"scheduled",
".",
":",
"param",
"ignore_daemonsets",
":",
"a",
"boolean",
".",
"If",
"false",
"will",
"fail",
"if",
"a",
"K8sDaemonSet",
"-",
... | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sNode.py#L189-L234 |
mnubo/kubernetes-py | kubernetes_py/K8sNode.py | K8sNode._pod_inventory | def _pod_inventory(self):
"""
Returns the list of all K8sPods found on this K8sNode.
:return: A list of K8sPods.
"""
pods = []
namespaces = K8sNamespace(config=self.config, name="yo").list()
for ns in namespaces:
cfg = self.config
... | python | def _pod_inventory(self):
"""
Returns the list of all K8sPods found on this K8sNode.
:return: A list of K8sPods.
"""
pods = []
namespaces = K8sNamespace(config=self.config, name="yo").list()
for ns in namespaces:
cfg = self.config
... | [
"def",
"_pod_inventory",
"(",
"self",
")",
":",
"pods",
"=",
"[",
"]",
"namespaces",
"=",
"K8sNamespace",
"(",
"config",
"=",
"self",
".",
"config",
",",
"name",
"=",
"\"yo\"",
")",
".",
"list",
"(",
")",
"for",
"ns",
"in",
"namespaces",
":",
"cfg",
... | Returns the list of all K8sPods found on this K8sNode.
:return: A list of K8sPods. | [
"Returns",
"the",
"list",
"of",
"all",
"K8sPods",
"found",
"on",
"this",
"K8sNode",
".",
":",
"return",
":",
"A",
"list",
"of",
"K8sPods",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sNode.py#L236-L251 |
mnubo/kubernetes-py | kubernetes_py/K8sNode.py | K8sNode._is_daemonset | def _is_daemonset(self, pod=None):
"""
Determines if a K8sPod is part of a K8sDaemonSet.
:param pod: The K8sPod we're interested in.
:return: a boolean.
"""
if 'kubernetes.io/created-by' in pod.annotations:
parent = json.loads(pod.annotations['kuber... | python | def _is_daemonset(self, pod=None):
"""
Determines if a K8sPod is part of a K8sDaemonSet.
:param pod: The K8sPod we're interested in.
:return: a boolean.
"""
if 'kubernetes.io/created-by' in pod.annotations:
parent = json.loads(pod.annotations['kuber... | [
"def",
"_is_daemonset",
"(",
"self",
",",
"pod",
"=",
"None",
")",
":",
"if",
"'kubernetes.io/created-by'",
"in",
"pod",
".",
"annotations",
":",
"parent",
"=",
"json",
".",
"loads",
"(",
"pod",
".",
"annotations",
"[",
"'kubernetes.io/created-by'",
"]",
")"... | Determines if a K8sPod is part of a K8sDaemonSet.
:param pod: The K8sPod we're interested in.
:return: a boolean. | [
"Determines",
"if",
"a",
"K8sPod",
"is",
"part",
"of",
"a",
"K8sDaemonSet",
".",
":",
"param",
"pod",
":",
"The",
"K8sPod",
"we",
"re",
"interested",
"in",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sNode.py#L253-L266 |
mnubo/kubernetes-py | kubernetes_py/K8sNode.py | K8sNode._has_local_storage | def _has_local_storage(self, pod=None):
"""
Determines if a K8sPod has any local storage susceptible to be lost.
:param pod: The K8sPod we're interested in.
:return: a boolean.
"""
for vol in pod.volumes:
if vol.emptyDir is not None:
return ... | python | def _has_local_storage(self, pod=None):
"""
Determines if a K8sPod has any local storage susceptible to be lost.
:param pod: The K8sPod we're interested in.
:return: a boolean.
"""
for vol in pod.volumes:
if vol.emptyDir is not None:
return ... | [
"def",
"_has_local_storage",
"(",
"self",
",",
"pod",
"=",
"None",
")",
":",
"for",
"vol",
"in",
"pod",
".",
"volumes",
":",
"if",
"vol",
".",
"emptyDir",
"is",
"not",
"None",
":",
"return",
"True",
"return",
"False"
] | Determines if a K8sPod has any local storage susceptible to be lost.
:param pod: The K8sPod we're interested in.
:return: a boolean. | [
"Determines",
"if",
"a",
"K8sPod",
"has",
"any",
"local",
"storage",
"susceptible",
"to",
"be",
"lost",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sNode.py#L268-L280 |
mnubo/kubernetes-py | kubernetes_py/K8sNode.py | K8sNode._wait_for_pod_deletion | def _wait_for_pod_deletion(self, daemonset_pods=None):
"""
Wait until this K8sNode has evicted all its K8sPods.
:param daemonset_pods: A list of K8sPods on this K8sNode that are managed by a K8sDaemonSet.
:return: None
"""
pods = self._pod_inventory()
... | python | def _wait_for_pod_deletion(self, daemonset_pods=None):
"""
Wait until this K8sNode has evicted all its K8sPods.
:param daemonset_pods: A list of K8sPods on this K8sNode that are managed by a K8sDaemonSet.
:return: None
"""
pods = self._pod_inventory()
... | [
"def",
"_wait_for_pod_deletion",
"(",
"self",
",",
"daemonset_pods",
"=",
"None",
")",
":",
"pods",
"=",
"self",
".",
"_pod_inventory",
"(",
")",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"while",
"len",
"(",
"pods",
")",
">",
"0",
":",
"if",
... | Wait until this K8sNode has evicted all its K8sPods.
:param daemonset_pods: A list of K8sPods on this K8sNode that are managed by a K8sDaemonSet.
:return: None | [
"Wait",
"until",
"this",
"K8sNode",
"has",
"evicted",
"all",
"its",
"K8sPods",
".",
":",
"param",
"daemonset_pods",
":",
"A",
"list",
"of",
"K8sPods",
"on",
"this",
"K8sNode",
"that",
"are",
"managed",
"by",
"a",
"K8sDaemonSet",
".",
":",
"return",
":",
... | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sNode.py#L295-L312 |
mnubo/kubernetes-py | kubernetes_py/K8sDeployment.py | K8sDeployment.get_by_name | def get_by_name(config=None, name=None, name_label='name'):
"""
Fetches a K8sDeployment by name.
:param config: A K8sConfig object.
:param name: The name we want.
:param name_label: The label key to use for name.
:return: A list of K8sDeployment objects.
... | python | def get_by_name(config=None, name=None, name_label='name'):
"""
Fetches a K8sDeployment by name.
:param config: A K8sConfig object.
:param name: The name we want.
:param name_label: The label key to use for name.
:return: A list of K8sDeployment objects.
... | [
"def",
"get_by_name",
"(",
"config",
"=",
"None",
",",
"name",
"=",
"None",
",",
"name_label",
"=",
"'name'",
")",
":",
"if",
"name",
"is",
"None",
":",
"raise",
"SyntaxError",
"(",
"'Deployment: name: [ {0} ] cannot be None.'",
".",
"format",
"(",
"name",
"... | Fetches a K8sDeployment by name.
:param config: A K8sConfig object.
:param name: The name we want.
:param name_label: The label key to use for name.
:return: A list of K8sDeployment objects. | [
"Fetches",
"a",
"K8sDeployment",
"by",
"name",
".",
":",
"param",
"config",
":",
"A",
"K8sConfig",
"object",
".",
":",
"param",
"name",
":",
"The",
"name",
"we",
"want",
".",
":",
"param",
"name_label",
":",
"The",
"label",
"key",
"to",
"use",
"for",
... | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sDeployment.py#L334-L359 |
mnubo/kubernetes-py | kubernetes_py/K8sDeployment.py | K8sDeployment.rollback | def rollback(self, revision=None, annotations=None):
"""
Performs a rollback of the Deployment.
If the 'revision' parameter is omitted, we fetch the Deployment's system-generated
annotation containing the current revision, and revert to the version immediately
preceding the curr... | python | def rollback(self, revision=None, annotations=None):
"""
Performs a rollback of the Deployment.
If the 'revision' parameter is omitted, we fetch the Deployment's system-generated
annotation containing the current revision, and revert to the version immediately
preceding the curr... | [
"def",
"rollback",
"(",
"self",
",",
"revision",
"=",
"None",
",",
"annotations",
"=",
"None",
")",
":",
"rollback",
"=",
"DeploymentRollback",
"(",
")",
"rollback",
".",
"name",
"=",
"self",
".",
"name",
"rollback_config",
"=",
"RollbackConfig",
"(",
")",... | Performs a rollback of the Deployment.
If the 'revision' parameter is omitted, we fetch the Deployment's system-generated
annotation containing the current revision, and revert to the version immediately
preceding the current version.
:param revision: The revision to rollback to.
... | [
"Performs",
"a",
"rollback",
"of",
"the",
"Deployment",
"."
] | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sDeployment.py#L363-L411 |
mnubo/kubernetes-py | kubernetes_py/K8sDeployment.py | K8sDeployment.purge_replica_sets | def purge_replica_sets(self, keep=3):
"""
Builds a list of ReplicaSets, sorted from newest to oldest.
Slices the array, keeping the most X most recent ReplicaSets.
:param keep: The number of ReplicaSets to keep.
:return: None
"""
rsets = K8sReplicaSet(
... | python | def purge_replica_sets(self, keep=3):
"""
Builds a list of ReplicaSets, sorted from newest to oldest.
Slices the array, keeping the most X most recent ReplicaSets.
:param keep: The number of ReplicaSets to keep.
:return: None
"""
rsets = K8sReplicaSet(
... | [
"def",
"purge_replica_sets",
"(",
"self",
",",
"keep",
"=",
"3",
")",
":",
"rsets",
"=",
"K8sReplicaSet",
"(",
"config",
"=",
"self",
".",
"config",
",",
"name",
"=",
"\"yo\"",
")",
".",
"list",
"(",
"pattern",
"=",
"self",
".",
"name",
",",
"reverse... | Builds a list of ReplicaSets, sorted from newest to oldest.
Slices the array, keeping the most X most recent ReplicaSets.
:param keep: The number of ReplicaSets to keep.
:return: None | [
"Builds",
"a",
"list",
"of",
"ReplicaSets",
"sorted",
"from",
"newest",
"to",
"oldest",
".",
"Slices",
"the",
"array",
"keeping",
"the",
"most",
"X",
"most",
"recent",
"ReplicaSets",
".",
":",
"param",
"keep",
":",
"The",
"number",
"of",
"ReplicaSets",
"to... | train | https://github.com/mnubo/kubernetes-py/blob/e417946837f7cb06b6ea9f7c20d8c19853fbd1bf/kubernetes_py/K8sDeployment.py#L429-L445 |
area4lib/area4 | extras/sum_roll_dice.py | roll_dice | def roll_dice():
"""
Roll a die.
:return: None
"""
sums = 0 # will return the sum of the roll calls.
while True:
roll = random.randint(1, 6)
sums += roll
if(input("Enter y or n to continue: ").upper()) == 'N':
print(sums) # prints the sum of the roll calls
... | python | def roll_dice():
"""
Roll a die.
:return: None
"""
sums = 0 # will return the sum of the roll calls.
while True:
roll = random.randint(1, 6)
sums += roll
if(input("Enter y or n to continue: ").upper()) == 'N':
print(sums) # prints the sum of the roll calls
... | [
"def",
"roll_dice",
"(",
")",
":",
"sums",
"=",
"0",
"# will return the sum of the roll calls.",
"while",
"True",
":",
"roll",
"=",
"random",
".",
"randint",
"(",
"1",
",",
"6",
")",
"sums",
"+=",
"roll",
"if",
"(",
"input",
"(",
"\"Enter y or n to continue:... | Roll a die.
:return: None | [
"Roll",
"a",
"die",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/extras/sum_roll_dice.py#L6-L18 |
area4lib/area4 | area4/util.py | get_raw_file | def get_raw_file():
"""
Get the raw divider file in a string array.
:return: the array
:rtype: str
"""
with open("{0}/dividers.txt".format(
os.path.abspath(
os.path.dirname(__file__)
)
), mode="r") as file_handler:
lines = file_handler.readlines()
... | python | def get_raw_file():
"""
Get the raw divider file in a string array.
:return: the array
:rtype: str
"""
with open("{0}/dividers.txt".format(
os.path.abspath(
os.path.dirname(__file__)
)
), mode="r") as file_handler:
lines = file_handler.readlines()
... | [
"def",
"get_raw_file",
"(",
")",
":",
"with",
"open",
"(",
"\"{0}/dividers.txt\"",
".",
"format",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
")",
",",
"mode",
"=",
"\"r\"",
")",
"as",
... | Get the raw divider file in a string array.
:return: the array
:rtype: str | [
"Get",
"the",
"raw",
"divider",
"file",
"in",
"a",
"string",
"array",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/area4/util.py#L13-L29 |
area4lib/area4 | area4/util.py | reduce_to_unit | def reduce_to_unit(divider):
"""
Reduce a repeating divider to the smallest repeating unit possible.
Note: this function is used by make-div
:param divider: the divider
:return: smallest repeating unit possible
:rtype: str
:Example:
'XxXxXxX' -> 'Xx'
"""
for unit_size in range(... | python | def reduce_to_unit(divider):
"""
Reduce a repeating divider to the smallest repeating unit possible.
Note: this function is used by make-div
:param divider: the divider
:return: smallest repeating unit possible
:rtype: str
:Example:
'XxXxXxX' -> 'Xx'
"""
for unit_size in range(... | [
"def",
"reduce_to_unit",
"(",
"divider",
")",
":",
"for",
"unit_size",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"divider",
")",
"//",
"2",
"+",
"1",
")",
":",
"length",
"=",
"len",
"(",
"divider",
")",
"unit",
"=",
"divider",
"[",
":",
"unit_size"... | Reduce a repeating divider to the smallest repeating unit possible.
Note: this function is used by make-div
:param divider: the divider
:return: smallest repeating unit possible
:rtype: str
:Example:
'XxXxXxX' -> 'Xx' | [
"Reduce",
"a",
"repeating",
"divider",
"to",
"the",
"smallest",
"repeating",
"unit",
"possible",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/area4/util.py#L42-L62 |
area4lib/area4 | area4/__init__.py | splitter | def splitter(div, *args):
"""
Split text with dividers easily.
:return: newly made value
:rtype: str
:param div: the divider
"""
retstr = ""
if type(div) is int:
div = theArray()[div]
if len(args) == 1:
return args[0]
for s in args:
retstr += s
re... | python | def splitter(div, *args):
"""
Split text with dividers easily.
:return: newly made value
:rtype: str
:param div: the divider
"""
retstr = ""
if type(div) is int:
div = theArray()[div]
if len(args) == 1:
return args[0]
for s in args:
retstr += s
re... | [
"def",
"splitter",
"(",
"div",
",",
"*",
"args",
")",
":",
"retstr",
"=",
"\"\"",
"if",
"type",
"(",
"div",
")",
"is",
"int",
":",
"div",
"=",
"theArray",
"(",
")",
"[",
"div",
"]",
"if",
"len",
"(",
"args",
")",
"==",
"1",
":",
"return",
"ar... | Split text with dividers easily.
:return: newly made value
:rtype: str
:param div: the divider | [
"Split",
"text",
"with",
"dividers",
"easily",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/area4/__init__.py#L54-L72 |
area4lib/area4 | area4/__init__.py | area4info | def area4info():
"""
Get some info about the package.
:return: Package info
:rtype: str
"""
# Info variables:
name = "area4"
author = "https://github.com/RDIL"
author_email = rdillib.get_email()
description = "Dividers in Python, the easy way!"
return "{0}: {1}\n{2}: {3}\n{4... | python | def area4info():
"""
Get some info about the package.
:return: Package info
:rtype: str
"""
# Info variables:
name = "area4"
author = "https://github.com/RDIL"
author_email = rdillib.get_email()
description = "Dividers in Python, the easy way!"
return "{0}: {1}\n{2}: {3}\n{4... | [
"def",
"area4info",
"(",
")",
":",
"# Info variables:",
"name",
"=",
"\"area4\"",
"author",
"=",
"\"https://github.com/RDIL\"",
"author_email",
"=",
"rdillib",
".",
"get_email",
"(",
")",
"description",
"=",
"\"Dividers in Python, the easy way!\"",
"return",
"\"{0}: {1}... | Get some info about the package.
:return: Package info
:rtype: str | [
"Get",
"some",
"info",
"about",
"the",
"package",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/area4/__init__.py#L75-L92 |
area4lib/area4 | area4/__init__.py | make_div | def make_div(unit, length=24,
start='', end='',
literal_unit=False):
"""
Generate and return a custom divider.
:param unit: str containing a repeating unit
:param length: The maximum length (won't be exceeded) (default: 24)
:param start: optional starting string
:param... | python | def make_div(unit, length=24,
start='', end='',
literal_unit=False):
"""
Generate and return a custom divider.
:param unit: str containing a repeating unit
:param length: The maximum length (won't be exceeded) (default: 24)
:param start: optional starting string
:param... | [
"def",
"make_div",
"(",
"unit",
",",
"length",
"=",
"24",
",",
"start",
"=",
"''",
",",
"end",
"=",
"''",
",",
"literal_unit",
"=",
"False",
")",
":",
"# Reduce the size if possible to extend closer to full length:",
"if",
"not",
"literal_unit",
":",
"unit",
"... | Generate and return a custom divider.
:param unit: str containing a repeating unit
:param length: The maximum length (won't be exceeded) (default: 24)
:param start: optional starting string
:param end: optional ending string
:param literal_unit: if True will not try to break
unit down into smal... | [
"Generate",
"and",
"return",
"a",
"custom",
"divider",
"."
] | train | https://github.com/area4lib/area4/blob/7f71b58d6b44b1a61284a8a01f26afd3138b9b17/area4/__init__.py#L95-L127 |
capnproto/pycapnp | buildutils/bundle.py | localpath | def localpath(*args):
"""construct an absolute path from a list relative to the root pycapnp directory"""
plist = [ROOT] + list(args)
return os.path.abspath(pjoin(*plist)) | python | def localpath(*args):
"""construct an absolute path from a list relative to the root pycapnp directory"""
plist = [ROOT] + list(args)
return os.path.abspath(pjoin(*plist)) | [
"def",
"localpath",
"(",
"*",
"args",
")",
":",
"plist",
"=",
"[",
"ROOT",
"]",
"+",
"list",
"(",
"args",
")",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"pjoin",
"(",
"*",
"plist",
")",
")"
] | construct an absolute path from a list relative to the root pycapnp directory | [
"construct",
"an",
"absolute",
"path",
"from",
"a",
"list",
"relative",
"to",
"the",
"root",
"pycapnp",
"directory"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/bundle.py#L53-L56 |
capnproto/pycapnp | buildutils/bundle.py | fetch_archive | def fetch_archive(savedir, url, fname, force=False):
"""download an archive to a specific location"""
dest = pjoin(savedir, fname)
if os.path.exists(dest) and not force:
info("already have %s" % fname)
return dest
info("fetching %s into %s" % (url, savedir))
if not os.path.exists(sav... | python | def fetch_archive(savedir, url, fname, force=False):
"""download an archive to a specific location"""
dest = pjoin(savedir, fname)
if os.path.exists(dest) and not force:
info("already have %s" % fname)
return dest
info("fetching %s into %s" % (url, savedir))
if not os.path.exists(sav... | [
"def",
"fetch_archive",
"(",
"savedir",
",",
"url",
",",
"fname",
",",
"force",
"=",
"False",
")",
":",
"dest",
"=",
"pjoin",
"(",
"savedir",
",",
"fname",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"dest",
")",
"and",
"not",
"force",
":",
... | download an archive to a specific location | [
"download",
"an",
"archive",
"to",
"a",
"specific",
"location"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/bundle.py#L58-L70 |
capnproto/pycapnp | buildutils/bundle.py | fetch_libcapnp | def fetch_libcapnp(savedir, url=None):
"""download and extract libcapnp"""
is_preconfigured = False
if url is None:
url = libcapnp_url
is_preconfigured = True
dest = pjoin(savedir, 'capnproto-c++')
if os.path.exists(dest):
info("already have %s" % dest)
return
fna... | python | def fetch_libcapnp(savedir, url=None):
"""download and extract libcapnp"""
is_preconfigured = False
if url is None:
url = libcapnp_url
is_preconfigured = True
dest = pjoin(savedir, 'capnproto-c++')
if os.path.exists(dest):
info("already have %s" % dest)
return
fna... | [
"def",
"fetch_libcapnp",
"(",
"savedir",
",",
"url",
"=",
"None",
")",
":",
"is_preconfigured",
"=",
"False",
"if",
"url",
"is",
"None",
":",
"url",
"=",
"libcapnp_url",
"is_preconfigured",
"=",
"True",
"dest",
"=",
"pjoin",
"(",
"savedir",
",",
"'capnprot... | download and extract libcapnp | [
"download",
"and",
"extract",
"libcapnp"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/bundle.py#L76-L100 |
capnproto/pycapnp | buildutils/bundle.py | stage_platform_hpp | def stage_platform_hpp(capnproot):
"""stage platform.hpp into libcapnp sources
Tries ./configure first (except on Windows),
then falls back on included platform.hpp previously generated.
"""
platform_hpp = pjoin(capnproot, 'src', 'platform.hpp')
if os.path.exists(platform_hpp):
info("a... | python | def stage_platform_hpp(capnproot):
"""stage platform.hpp into libcapnp sources
Tries ./configure first (except on Windows),
then falls back on included platform.hpp previously generated.
"""
platform_hpp = pjoin(capnproot, 'src', 'platform.hpp')
if os.path.exists(platform_hpp):
info("a... | [
"def",
"stage_platform_hpp",
"(",
"capnproot",
")",
":",
"platform_hpp",
"=",
"pjoin",
"(",
"capnproot",
",",
"'src'",
",",
"'platform.hpp'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"platform_hpp",
")",
":",
"info",
"(",
"\"already have platform.hpp\... | stage platform.hpp into libcapnp sources
Tries ./configure first (except on Windows),
then falls back on included platform.hpp previously generated. | [
"stage",
"platform",
".",
"hpp",
"into",
"libcapnp",
"sources"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/bundle.py#L103-L138 |
capnproto/pycapnp | buildutils/patch.py | _find_library | def _find_library(lib, path):
"""Find a library"""
for d in path[::-1]:
real_lib = os.path.join(d, lib)
if os.path.exists(real_lib):
return real_lib | python | def _find_library(lib, path):
"""Find a library"""
for d in path[::-1]:
real_lib = os.path.join(d, lib)
if os.path.exists(real_lib):
return real_lib | [
"def",
"_find_library",
"(",
"lib",
",",
"path",
")",
":",
"for",
"d",
"in",
"path",
"[",
":",
":",
"-",
"1",
"]",
":",
"real_lib",
"=",
"os",
".",
"path",
".",
"join",
"(",
"d",
",",
"lib",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
... | Find a library | [
"Find",
"a",
"library"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/patch.py#L30-L35 |
capnproto/pycapnp | buildutils/patch.py | patch_lib_paths | def patch_lib_paths(fname, library_dirs):
"""Load any weakly-defined libraries from their real location
(only on OS X)
- Find libraries with `otool -L`
- Update with `install_name_tool -change`
"""
if sys.platform != 'darwin':
return
libs = _get_libs(fname)
for lib... | python | def patch_lib_paths(fname, library_dirs):
"""Load any weakly-defined libraries from their real location
(only on OS X)
- Find libraries with `otool -L`
- Update with `install_name_tool -change`
"""
if sys.platform != 'darwin':
return
libs = _get_libs(fname)
for lib... | [
"def",
"patch_lib_paths",
"(",
"fname",
",",
"library_dirs",
")",
":",
"if",
"sys",
".",
"platform",
"!=",
"'darwin'",
":",
"return",
"libs",
"=",
"_get_libs",
"(",
"fname",
")",
"for",
"lib",
"in",
"libs",
":",
"if",
"not",
"lib",
".",
"startswith",
"... | Load any weakly-defined libraries from their real location
(only on OS X)
- Find libraries with `otool -L`
- Update with `install_name_tool -change` | [
"Load",
"any",
"weakly",
"-",
"defined",
"libraries",
"from",
"their",
"real",
"location",
"(",
"only",
"on",
"OS",
"X",
")",
"-",
"Find",
"libraries",
"with",
"otool",
"-",
"L",
"-",
"Update",
"with",
"install_name_tool",
"-",
"change"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/patch.py#L42-L58 |
capnproto/pycapnp | examples/calculator_client.py | main | def main(host):
client = capnp.TwoPartyClient(host)
# Pass "calculator" to ez_restore (there's also a `restore` function that
# takes a struct or AnyPointer as an argument), and then cast the returned
# capability to it's proper type. This casting is due to capabilities not
# having a reference to ... | python | def main(host):
client = capnp.TwoPartyClient(host)
# Pass "calculator" to ez_restore (there's also a `restore` function that
# takes a struct or AnyPointer as an argument), and then cast the returned
# capability to it's proper type. This casting is due to capabilities not
# having a reference to ... | [
"def",
"main",
"(",
"host",
")",
":",
"client",
"=",
"capnp",
".",
"TwoPartyClient",
"(",
"host",
")",
"# Pass \"calculator\" to ez_restore (there's also a `restore` function that",
"# takes a struct or AnyPointer as an argument), and then cast the returned",
"# capability to it's pr... | Make a request that just evaluates the literal value 123.
What's interesting here is that evaluate() returns a "Value", which is
another interface and therefore points back to an object living on the
server. We then have to call read() on that object to read it.
However, even though we are making two ... | [
"Make",
"a",
"request",
"that",
"just",
"evaluates",
"the",
"literal",
"value",
"123",
"."
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/examples/calculator_client.py#L35-L303 |
capnproto/pycapnp | buildutils/misc.py | get_output_error | def get_output_error(cmd):
"""Return the exit status, stdout, stderr of a command"""
if not isinstance(cmd, list):
cmd = [cmd]
logging.debug("Running: %s", ' '.join(map(quote, cmd)))
try:
result = Popen(cmd, stdout=PIPE, stderr=PIPE)
except IOError as e:
return -1, u(''), u('... | python | def get_output_error(cmd):
"""Return the exit status, stdout, stderr of a command"""
if not isinstance(cmd, list):
cmd = [cmd]
logging.debug("Running: %s", ' '.join(map(quote, cmd)))
try:
result = Popen(cmd, stdout=PIPE, stderr=PIPE)
except IOError as e:
return -1, u(''), u('... | [
"def",
"get_output_error",
"(",
"cmd",
")",
":",
"if",
"not",
"isinstance",
"(",
"cmd",
",",
"list",
")",
":",
"cmd",
"=",
"[",
"cmd",
"]",
"logging",
".",
"debug",
"(",
"\"Running: %s\"",
",",
"' '",
".",
"join",
"(",
"map",
"(",
"quote",
",",
"cm... | Return the exit status, stdout, stderr of a command | [
"Return",
"the",
"exit",
"status",
"stdout",
"stderr",
"of",
"a",
"command"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/misc.py#L50-L64 |
capnproto/pycapnp | buildutils/config.py | load_config | def load_config(name, base='conf'):
"""Load config dict from JSON"""
fname = pjoin(base, name + '.json')
if not os.path.exists(fname):
return {}
try:
with open(fname) as f:
cfg = json.load(f)
except Exception as e:
warn("Couldn't load %s: %s" % (fname, e))
... | python | def load_config(name, base='conf'):
"""Load config dict from JSON"""
fname = pjoin(base, name + '.json')
if not os.path.exists(fname):
return {}
try:
with open(fname) as f:
cfg = json.load(f)
except Exception as e:
warn("Couldn't load %s: %s" % (fname, e))
... | [
"def",
"load_config",
"(",
"name",
",",
"base",
"=",
"'conf'",
")",
":",
"fname",
"=",
"pjoin",
"(",
"base",
",",
"name",
"+",
"'.json'",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"fname",
")",
":",
"return",
"{",
"}",
"try",
":",
... | Load config dict from JSON | [
"Load",
"config",
"dict",
"from",
"JSON"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L31-L42 |
capnproto/pycapnp | buildutils/config.py | save_config | def save_config(name, data, base='conf'):
"""Save config dict to JSON"""
if not os.path.exists(base):
os.mkdir(base)
fname = pjoin(base, name+'.json')
with open(fname, 'w') as f:
json.dump(data, f, indent=2) | python | def save_config(name, data, base='conf'):
"""Save config dict to JSON"""
if not os.path.exists(base):
os.mkdir(base)
fname = pjoin(base, name+'.json')
with open(fname, 'w') as f:
json.dump(data, f, indent=2) | [
"def",
"save_config",
"(",
"name",
",",
"data",
",",
"base",
"=",
"'conf'",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"base",
")",
":",
"os",
".",
"mkdir",
"(",
"base",
")",
"fname",
"=",
"pjoin",
"(",
"base",
",",
"name",
"... | Save config dict to JSON | [
"Save",
"config",
"dict",
"to",
"JSON"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L45-L51 |
capnproto/pycapnp | buildutils/config.py | get_eargs | def get_eargs():
""" Look for options in environment vars """
settings = {}
zmq = os.environ.get("ZMQ_PREFIX", None)
if zmq is not None:
debug("Found environ var ZMQ_PREFIX=%s" % zmq)
settings['zmq_prefix'] = zmq
return settings | python | def get_eargs():
""" Look for options in environment vars """
settings = {}
zmq = os.environ.get("ZMQ_PREFIX", None)
if zmq is not None:
debug("Found environ var ZMQ_PREFIX=%s" % zmq)
settings['zmq_prefix'] = zmq
return settings | [
"def",
"get_eargs",
"(",
")",
":",
"settings",
"=",
"{",
"}",
"zmq",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"ZMQ_PREFIX\"",
",",
"None",
")",
"if",
"zmq",
"is",
"not",
"None",
":",
"debug",
"(",
"\"Found environ var ZMQ_PREFIX=%s\"",
"%",
"zmq",
... | Look for options in environment vars | [
"Look",
"for",
"options",
"in",
"environment",
"vars"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L58-L68 |
capnproto/pycapnp | buildutils/config.py | cfg2dict | def cfg2dict(cfg):
"""turn a ConfigParser into a nested dict
because ConfigParser objects are dumb.
"""
d = {}
for section in cfg.sections():
d[section] = dict(cfg.items(section))
return d | python | def cfg2dict(cfg):
"""turn a ConfigParser into a nested dict
because ConfigParser objects are dumb.
"""
d = {}
for section in cfg.sections():
d[section] = dict(cfg.items(section))
return d | [
"def",
"cfg2dict",
"(",
"cfg",
")",
":",
"d",
"=",
"{",
"}",
"for",
"section",
"in",
"cfg",
".",
"sections",
"(",
")",
":",
"d",
"[",
"section",
"]",
"=",
"dict",
"(",
"cfg",
".",
"items",
"(",
"section",
")",
")",
"return",
"d"
] | turn a ConfigParser into a nested dict
because ConfigParser objects are dumb. | [
"turn",
"a",
"ConfigParser",
"into",
"a",
"nested",
"dict",
"because",
"ConfigParser",
"objects",
"are",
"dumb",
"."
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L70-L78 |
capnproto/pycapnp | buildutils/config.py | get_cfg_args | def get_cfg_args():
""" Look for options in setup.cfg """
if not os.path.exists('setup.cfg'):
return {}
cfg = ConfigParser()
cfg.read('setup.cfg')
cfg = cfg2dict(cfg)
g = cfg.setdefault('global', {})
# boolean keys:
for key in ['libzmq_extension',
'bundle_libzmq... | python | def get_cfg_args():
""" Look for options in setup.cfg """
if not os.path.exists('setup.cfg'):
return {}
cfg = ConfigParser()
cfg.read('setup.cfg')
cfg = cfg2dict(cfg)
g = cfg.setdefault('global', {})
# boolean keys:
for key in ['libzmq_extension',
'bundle_libzmq... | [
"def",
"get_cfg_args",
"(",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"'setup.cfg'",
")",
":",
"return",
"{",
"}",
"cfg",
"=",
"ConfigParser",
"(",
")",
"cfg",
".",
"read",
"(",
"'setup.cfg'",
")",
"cfg",
"=",
"cfg2dict",
"(",
"... | Look for options in setup.cfg | [
"Look",
"for",
"options",
"in",
"setup",
".",
"cfg"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L80-L102 |
capnproto/pycapnp | buildutils/config.py | config_from_prefix | def config_from_prefix(prefix):
"""Get config from zmq prefix"""
settings = {}
if prefix.lower() in ('default', 'auto', ''):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = False
settings['no_libzmq_extension'] = False
elif prefix.lower() in ('bundled', 'extension'):
... | python | def config_from_prefix(prefix):
"""Get config from zmq prefix"""
settings = {}
if prefix.lower() in ('default', 'auto', ''):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = False
settings['no_libzmq_extension'] = False
elif prefix.lower() in ('bundled', 'extension'):
... | [
"def",
"config_from_prefix",
"(",
"prefix",
")",
":",
"settings",
"=",
"{",
"}",
"if",
"prefix",
".",
"lower",
"(",
")",
"in",
"(",
"'default'",
",",
"'auto'",
",",
"''",
")",
":",
"settings",
"[",
"'zmq_prefix'",
"]",
"=",
"''",
"settings",
"[",
"'l... | Get config from zmq prefix | [
"Get",
"config",
"from",
"zmq",
"prefix"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L104-L119 |
capnproto/pycapnp | buildutils/config.py | merge | def merge(into, d):
"""merge two containers
into is updated, d has priority
"""
if isinstance(into, dict):
for key in d.keys():
if key not in into:
into[key] = d[key]
else:
into[key] = merge(into[key], d[key])
return into
e... | python | def merge(into, d):
"""merge two containers
into is updated, d has priority
"""
if isinstance(into, dict):
for key in d.keys():
if key not in into:
into[key] = d[key]
else:
into[key] = merge(into[key], d[key])
return into
e... | [
"def",
"merge",
"(",
"into",
",",
"d",
")",
":",
"if",
"isinstance",
"(",
"into",
",",
"dict",
")",
":",
"for",
"key",
"in",
"d",
".",
"keys",
"(",
")",
":",
"if",
"key",
"not",
"in",
"into",
":",
"into",
"[",
"key",
"]",
"=",
"d",
"[",
"ke... | merge two containers
into is updated, d has priority | [
"merge",
"two",
"containers",
"into",
"is",
"updated",
"d",
"has",
"priority"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L121-L136 |
capnproto/pycapnp | buildutils/config.py | discover_settings | def discover_settings(conf_base=None):
""" Discover custom settings for ZMQ path"""
settings = {
'zmq_prefix': '',
'libzmq_extension': False,
'no_libzmq_extension': False,
'skip_check_zmq': False,
'build_ext': {},
'bdist_egg': {},
}
if sys.platform.startsw... | python | def discover_settings(conf_base=None):
""" Discover custom settings for ZMQ path"""
settings = {
'zmq_prefix': '',
'libzmq_extension': False,
'no_libzmq_extension': False,
'skip_check_zmq': False,
'build_ext': {},
'bdist_egg': {},
}
if sys.platform.startsw... | [
"def",
"discover_settings",
"(",
"conf_base",
"=",
"None",
")",
":",
"settings",
"=",
"{",
"'zmq_prefix'",
":",
"''",
",",
"'libzmq_extension'",
":",
"False",
",",
"'no_libzmq_extension'",
":",
"False",
",",
"'skip_check_zmq'",
":",
"False",
",",
"'build_ext'",
... | Discover custom settings for ZMQ path | [
"Discover",
"custom",
"settings",
"for",
"ZMQ",
"path"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/config.py#L138-L157 |
capnproto/pycapnp | examples/calculator_server.py | evaluate_impl | def evaluate_impl(expression, params=None):
'''Implementation of CalculatorImpl::evaluate(), also shared by
FunctionImpl::call(). In the latter case, `params` are the parameter
values passed to the function; in the former case, `params` is just an
empty list.'''
which = expression.which()
if ... | python | def evaluate_impl(expression, params=None):
'''Implementation of CalculatorImpl::evaluate(), also shared by
FunctionImpl::call(). In the latter case, `params` are the parameter
values passed to the function; in the former case, `params` is just an
empty list.'''
which = expression.which()
if ... | [
"def",
"evaluate_impl",
"(",
"expression",
",",
"params",
"=",
"None",
")",
":",
"which",
"=",
"expression",
".",
"which",
"(",
")",
"if",
"which",
"==",
"'literal'",
":",
"return",
"capnp",
".",
"Promise",
"(",
"expression",
".",
"literal",
")",
"elif",... | Implementation of CalculatorImpl::evaluate(), also shared by
FunctionImpl::call(). In the latter case, `params` are the parameter
values passed to the function; in the former case, `params` is just an
empty list. | [
"Implementation",
"of",
"CalculatorImpl",
"::",
"evaluate",
"()",
"also",
"shared",
"by",
"FunctionImpl",
"::",
"call",
"()",
".",
"In",
"the",
"latter",
"case",
"params",
"are",
"the",
"parameter",
"values",
"passed",
"to",
"the",
"function",
";",
"in",
"th... | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/examples/calculator_server.py#L20-L50 |
capnproto/pycapnp | examples/calculator_server.py | FunctionImpl.call | def call(self, params, _context, **kwargs):
'''Note that we're returning a Promise object here, and bypassing the
helper functionality that normally sets the results struct from the
returned object. Instead, we set _context.results directly inside of
another promise'''
assert le... | python | def call(self, params, _context, **kwargs):
'''Note that we're returning a Promise object here, and bypassing the
helper functionality that normally sets the results struct from the
returned object. Instead, we set _context.results directly inside of
another promise'''
assert le... | [
"def",
"call",
"(",
"self",
",",
"params",
",",
"_context",
",",
"*",
"*",
"kwargs",
")",
":",
"assert",
"len",
"(",
"params",
")",
"==",
"self",
".",
"paramCount",
"# using setattr because '=' is not allowed inside of lambdas",
"return",
"evaluate_impl",
"(",
"... | Note that we're returning a Promise object here, and bypassing the
helper functionality that normally sets the results struct from the
returned object. Instead, we set _context.results directly inside of
another promise | [
"Note",
"that",
"we",
"re",
"returning",
"a",
"Promise",
"object",
"here",
"and",
"bypassing",
"the",
"helper",
"functionality",
"that",
"normally",
"sets",
"the",
"results",
"struct",
"from",
"the",
"returned",
"object",
".",
"Instead",
"we",
"set",
"_context... | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/examples/calculator_server.py#L73-L81 |
capnproto/pycapnp | buildutils/detect.py | detect_version | def detect_version(basedir, compiler=None, **compiler_attrs):
"""Compile, link & execute a test program, in empty directory `basedir`.
The C compiler will be updated with any keywords given via setattr.
Parameters
----------
basedir : path
The location where the test program will be compi... | python | def detect_version(basedir, compiler=None, **compiler_attrs):
"""Compile, link & execute a test program, in empty directory `basedir`.
The C compiler will be updated with any keywords given via setattr.
Parameters
----------
basedir : path
The location where the test program will be compi... | [
"def",
"detect_version",
"(",
"basedir",
",",
"compiler",
"=",
"None",
",",
"*",
"*",
"compiler_attrs",
")",
":",
"if",
"compiler",
"is",
"None",
":",
"compiler",
"=",
"get_default_compiler",
"(",
")",
"cfile",
"=",
"pjoin",
"(",
"basedir",
",",
"'vers.cpp... | Compile, link & execute a test program, in empty directory `basedir`.
The C compiler will be updated with any keywords given via setattr.
Parameters
----------
basedir : path
The location where the test program will be compiled and run
compiler : str
The distutils compiler key (e.... | [
"Compile",
"link",
"&",
"execute",
"a",
"test",
"program",
"in",
"empty",
"directory",
"basedir",
"."
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/detect.py#L87-L144 |
capnproto/pycapnp | buildutils/constants.py | cython_enums | def cython_enums():
"""generate `enum: ZMQ_CONST` block for constant_enums.pxi"""
lines = []
for name in all_names:
if no_prefix(name):
lines.append('enum: ZMQ_{0} "{0}"'.format(name))
else:
lines.append('enum: ZMQ_{0}'.format(name))
return dict(ZMQ_E... | python | def cython_enums():
"""generate `enum: ZMQ_CONST` block for constant_enums.pxi"""
lines = []
for name in all_names:
if no_prefix(name):
lines.append('enum: ZMQ_{0} "{0}"'.format(name))
else:
lines.append('enum: ZMQ_{0}'.format(name))
return dict(ZMQ_E... | [
"def",
"cython_enums",
"(",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"name",
"in",
"all_names",
":",
"if",
"no_prefix",
"(",
"name",
")",
":",
"lines",
".",
"append",
"(",
"'enum: ZMQ_{0} \"{0}\"'",
".",
"format",
"(",
"name",
")",
")",
"else",
":",
... | generate `enum: ZMQ_CONST` block for constant_enums.pxi | [
"generate",
"enum",
":",
"ZMQ_CONST",
"block",
"for",
"constant_enums",
".",
"pxi"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/constants.py#L33-L42 |
capnproto/pycapnp | buildutils/constants.py | ifndefs | def ifndefs():
"""generate `#ifndef ZMQ_CONST` block for zmq_constants.h"""
lines = ['#define _PYZMQ_UNDEFINED (-9999)']
for name in all_names:
if not no_prefix(name):
name = 'ZMQ_%s' % name
lines.append(ifndef_t.format(name))
return dict(ZMQ_IFNDEFS='\n'.join(lines)) | python | def ifndefs():
"""generate `#ifndef ZMQ_CONST` block for zmq_constants.h"""
lines = ['#define _PYZMQ_UNDEFINED (-9999)']
for name in all_names:
if not no_prefix(name):
name = 'ZMQ_%s' % name
lines.append(ifndef_t.format(name))
return dict(ZMQ_IFNDEFS='\n'.join(lines)) | [
"def",
"ifndefs",
"(",
")",
":",
"lines",
"=",
"[",
"'#define _PYZMQ_UNDEFINED (-9999)'",
"]",
"for",
"name",
"in",
"all_names",
":",
"if",
"not",
"no_prefix",
"(",
"name",
")",
":",
"name",
"=",
"'ZMQ_%s'",
"%",
"name",
"lines",
".",
"append",
"(",
"ifn... | generate `#ifndef ZMQ_CONST` block for zmq_constants.h | [
"generate",
"#ifndef",
"ZMQ_CONST",
"block",
"for",
"zmq_constants",
".",
"h"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/constants.py#L44-L51 |
capnproto/pycapnp | buildutils/constants.py | constants_pyx | def constants_pyx():
"""generate CONST = ZMQ_CONST and __all__ for constants.pxi"""
all_lines = []
assign_lines = []
for name in all_names:
if name == "NULL":
# avoid conflict with NULL in Cython
assign_lines.append("globals()['NULL'] = ZMQ_NULL")
else:
... | python | def constants_pyx():
"""generate CONST = ZMQ_CONST and __all__ for constants.pxi"""
all_lines = []
assign_lines = []
for name in all_names:
if name == "NULL":
# avoid conflict with NULL in Cython
assign_lines.append("globals()['NULL'] = ZMQ_NULL")
else:
... | [
"def",
"constants_pyx",
"(",
")",
":",
"all_lines",
"=",
"[",
"]",
"assign_lines",
"=",
"[",
"]",
"for",
"name",
"in",
"all_names",
":",
"if",
"name",
"==",
"\"NULL\"",
":",
"# avoid conflict with NULL in Cython",
"assign_lines",
".",
"append",
"(",
"\"globals... | generate CONST = ZMQ_CONST and __all__ for constants.pxi | [
"generate",
"CONST",
"=",
"ZMQ_CONST",
"and",
"__all__",
"for",
"constants",
".",
"pxi"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/constants.py#L53-L64 |
capnproto/pycapnp | buildutils/constants.py | generate_file | def generate_file(fname, ns_func, dest_dir="."):
"""generate a constants file from its template"""
with open(pjoin(root, 'buildutils', 'templates', '%s' % fname), 'r') as f:
tpl = f.read()
out = tpl.format(**ns_func())
dest = pjoin(dest_dir, fname)
info("generating %s from template" % dest)
... | python | def generate_file(fname, ns_func, dest_dir="."):
"""generate a constants file from its template"""
with open(pjoin(root, 'buildutils', 'templates', '%s' % fname), 'r') as f:
tpl = f.read()
out = tpl.format(**ns_func())
dest = pjoin(dest_dir, fname)
info("generating %s from template" % dest)
... | [
"def",
"generate_file",
"(",
"fname",
",",
"ns_func",
",",
"dest_dir",
"=",
"\".\"",
")",
":",
"with",
"open",
"(",
"pjoin",
"(",
"root",
",",
"'buildutils'",
",",
"'templates'",
",",
"'%s'",
"%",
"fname",
")",
",",
"'r'",
")",
"as",
"f",
":",
"tpl",... | generate a constants file from its template | [
"generate",
"a",
"constants",
"file",
"from",
"its",
"template"
] | train | https://github.com/capnproto/pycapnp/blob/cb3f190b955bdb1bfb6e0ac0b2f9306a5c79f7b5/buildutils/constants.py#L66-L74 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.