id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
23,300 | awslabs/serverless-application-model | samtranslator/intrinsics/actions.py | Action._parse_resource_reference | def _parse_resource_reference(cls, ref_value):
"""
Splits a resource reference of structure "LogicalId.Property" and returns the "LogicalId" and "Property"
separately.
:param string ref_value: Input reference value which *may* contain the structure "LogicalId.Property"
:return s... | python | def _parse_resource_reference(cls, ref_value):
"""
Splits a resource reference of structure "LogicalId.Property" and returns the "LogicalId" and "Property"
separately.
:param string ref_value: Input reference value which *may* contain the structure "LogicalId.Property"
:return s... | [
"def",
"_parse_resource_reference",
"(",
"cls",
",",
"ref_value",
")",
":",
"no_result",
"=",
"(",
"None",
",",
"None",
")",
"if",
"not",
"isinstance",
"(",
"ref_value",
",",
"string_types",
")",
":",
"return",
"no_result",
"splits",
"=",
"ref_value",
".",
... | Splits a resource reference of structure "LogicalId.Property" and returns the "LogicalId" and "Property"
separately.
:param string ref_value: Input reference value which *may* contain the structure "LogicalId.Property"
:return string, string: Returns two values - logical_id, property. If the in... | [
"Splits",
"a",
"resource",
"reference",
"of",
"structure",
"LogicalId",
".",
"Property",
"and",
"returns",
"the",
"LogicalId",
"and",
"Property",
"separately",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/actions.py#L55-L76 |
23,301 | awslabs/serverless-application-model | samtranslator/intrinsics/actions.py | RefAction.resolve_parameter_refs | def resolve_parameter_refs(self, input_dict, parameters):
"""
Resolves references that are present in the parameters and returns the value. If it is not in parameters,
this method simply returns the input unchanged.
:param input_dict: Dictionary representing the Ref function. Must conta... | python | def resolve_parameter_refs(self, input_dict, parameters):
"""
Resolves references that are present in the parameters and returns the value. If it is not in parameters,
this method simply returns the input unchanged.
:param input_dict: Dictionary representing the Ref function. Must conta... | [
"def",
"resolve_parameter_refs",
"(",
"self",
",",
"input_dict",
",",
"parameters",
")",
":",
"if",
"not",
"self",
".",
"can_handle",
"(",
"input_dict",
")",
":",
"return",
"input_dict",
"param_name",
"=",
"input_dict",
"[",
"self",
".",
"intrinsic_name",
"]",... | Resolves references that are present in the parameters and returns the value. If it is not in parameters,
this method simply returns the input unchanged.
:param input_dict: Dictionary representing the Ref function. Must contain only one key and it should be "Ref".
Ex: {Ref: "foo"}
... | [
"Resolves",
"references",
"that",
"are",
"present",
"in",
"the",
"parameters",
"and",
"returns",
"the",
"value",
".",
"If",
"it",
"is",
"not",
"in",
"parameters",
"this",
"method",
"simply",
"returns",
"the",
"input",
"unchanged",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/actions.py#L82-L104 |
23,302 | awslabs/serverless-application-model | samtranslator/intrinsics/actions.py | RefAction.resolve_resource_refs | def resolve_resource_refs(self, input_dict, supported_resource_refs):
"""
Resolves references to some property of a resource. These are runtime properties which can't be converted
to a value here. Instead we output another reference that will more actually resolve to the value when
execu... | python | def resolve_resource_refs(self, input_dict, supported_resource_refs):
"""
Resolves references to some property of a resource. These are runtime properties which can't be converted
to a value here. Instead we output another reference that will more actually resolve to the value when
execu... | [
"def",
"resolve_resource_refs",
"(",
"self",
",",
"input_dict",
",",
"supported_resource_refs",
")",
":",
"if",
"not",
"self",
".",
"can_handle",
"(",
"input_dict",
")",
":",
"return",
"input_dict",
"ref_value",
"=",
"input_dict",
"[",
"self",
".",
"intrinsic_na... | Resolves references to some property of a resource. These are runtime properties which can't be converted
to a value here. Instead we output another reference that will more actually resolve to the value when
executed via CloudFormation
Example:
{"Ref": "LogicalId.Property"} => {"Re... | [
"Resolves",
"references",
"to",
"some",
"property",
"of",
"a",
"resource",
".",
"These",
"are",
"runtime",
"properties",
"which",
"can",
"t",
"be",
"converted",
"to",
"a",
"value",
"here",
".",
"Instead",
"we",
"output",
"another",
"reference",
"that",
"will... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/actions.py#L106-L137 |
23,303 | awslabs/serverless-application-model | samtranslator/intrinsics/actions.py | SubAction._handle_sub_action | def _handle_sub_action(self, input_dict, handler):
"""
Handles resolving replacements in the Sub action based on the handler that is passed as an input.
:param input_dict: Dictionary to be resolved
:param supported_values: One of several different objects that contain the supported valu... | python | def _handle_sub_action(self, input_dict, handler):
"""
Handles resolving replacements in the Sub action based on the handler that is passed as an input.
:param input_dict: Dictionary to be resolved
:param supported_values: One of several different objects that contain the supported valu... | [
"def",
"_handle_sub_action",
"(",
"self",
",",
"input_dict",
",",
"handler",
")",
":",
"if",
"not",
"self",
".",
"can_handle",
"(",
"input_dict",
")",
":",
"return",
"input_dict",
"key",
"=",
"self",
".",
"intrinsic_name",
"sub_value",
"=",
"input_dict",
"["... | Handles resolving replacements in the Sub action based on the handler that is passed as an input.
:param input_dict: Dictionary to be resolved
:param supported_values: One of several different objects that contain the supported values that
need to be changed. See each method above for speci... | [
"Handles",
"resolving",
"replacements",
"in",
"the",
"Sub",
"action",
"based",
"on",
"the",
"handler",
"that",
"is",
"passed",
"as",
"an",
"input",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/actions.py#L311-L329 |
23,304 | awslabs/serverless-application-model | samtranslator/intrinsics/actions.py | GetAttAction._get_resolved_dictionary | def _get_resolved_dictionary(self, input_dict, key, resolved_value, remaining):
"""
Resolves the function and returns the updated dictionary
:param input_dict: Dictionary to be resolved
:param key: Name of this intrinsic.
:param resolved_value: Resolved or updated value for this... | python | def _get_resolved_dictionary(self, input_dict, key, resolved_value, remaining):
"""
Resolves the function and returns the updated dictionary
:param input_dict: Dictionary to be resolved
:param key: Name of this intrinsic.
:param resolved_value: Resolved or updated value for this... | [
"def",
"_get_resolved_dictionary",
"(",
"self",
",",
"input_dict",
",",
"key",
",",
"resolved_value",
",",
"remaining",
")",
":",
"if",
"resolved_value",
":",
"# We resolved to a new resource logicalId. Use this as the first element and keep remaining elements intact",
"# This is... | Resolves the function and returns the updated dictionary
:param input_dict: Dictionary to be resolved
:param key: Name of this intrinsic.
:param resolved_value: Resolved or updated value for this action.
:param remaining: Remaining sections for the GetAtt action. | [
"Resolves",
"the",
"function",
"and",
"returns",
"the",
"updated",
"dictionary"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/actions.py#L497-L511 |
23,305 | awslabs/serverless-application-model | examples/apps/datadog-process-rds-metrics/lambda_function.py | lambda_handler | def lambda_handler(event, context):
''' Process a RDS enhenced monitoring DATA_MESSAGE,
coming from CLOUDWATCH LOGS
'''
# event is a dict containing a base64 string gzipped
event = json.loads(gzip.GzipFile(fileobj=StringIO(event['awslogs']['data'].decode('base64'))).read())
account = event[... | python | def lambda_handler(event, context):
''' Process a RDS enhenced monitoring DATA_MESSAGE,
coming from CLOUDWATCH LOGS
'''
# event is a dict containing a base64 string gzipped
event = json.loads(gzip.GzipFile(fileobj=StringIO(event['awslogs']['data'].decode('base64'))).read())
account = event[... | [
"def",
"lambda_handler",
"(",
"event",
",",
"context",
")",
":",
"# event is a dict containing a base64 string gzipped",
"event",
"=",
"json",
".",
"loads",
"(",
"gzip",
".",
"GzipFile",
"(",
"fileobj",
"=",
"StringIO",
"(",
"event",
"[",
"'awslogs'",
"]",
"[",
... | Process a RDS enhenced monitoring DATA_MESSAGE,
coming from CLOUDWATCH LOGS | [
"Process",
"a",
"RDS",
"enhenced",
"monitoring",
"DATA_MESSAGE",
"coming",
"from",
"CLOUDWATCH",
"LOGS"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/examples/apps/datadog-process-rds-metrics/lambda_function.py#L104-L122 |
23,306 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._construct_rest_api | def _construct_rest_api(self):
"""Constructs and returns the ApiGateway RestApi.
:returns: the RestApi to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayRestApi
"""
rest_api = ApiGatewayRestApi(self.logical_id, depends_on=self.depends_on, attributes=self.resou... | python | def _construct_rest_api(self):
"""Constructs and returns the ApiGateway RestApi.
:returns: the RestApi to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayRestApi
"""
rest_api = ApiGatewayRestApi(self.logical_id, depends_on=self.depends_on, attributes=self.resou... | [
"def",
"_construct_rest_api",
"(",
"self",
")",
":",
"rest_api",
"=",
"ApiGatewayRestApi",
"(",
"self",
".",
"logical_id",
",",
"depends_on",
"=",
"self",
".",
"depends_on",
",",
"attributes",
"=",
"self",
".",
"resource_attributes",
")",
"rest_api",
".",
"Bin... | Constructs and returns the ApiGateway RestApi.
:returns: the RestApi to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayRestApi | [
"Constructs",
"and",
"returns",
"the",
"ApiGateway",
"RestApi",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L74-L108 |
23,307 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._construct_body_s3_dict | def _construct_body_s3_dict(self):
"""Constructs the RestApi's `BodyS3Location property`_, from the SAM Api's DefinitionUri property.
:returns: a BodyS3Location dict, containing the S3 Bucket, Key, and Version of the Swagger definition
:rtype: dict
"""
if isinstance(self.definit... | python | def _construct_body_s3_dict(self):
"""Constructs the RestApi's `BodyS3Location property`_, from the SAM Api's DefinitionUri property.
:returns: a BodyS3Location dict, containing the S3 Bucket, Key, and Version of the Swagger definition
:rtype: dict
"""
if isinstance(self.definit... | [
"def",
"_construct_body_s3_dict",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"definition_uri",
",",
"dict",
")",
":",
"if",
"not",
"self",
".",
"definition_uri",
".",
"get",
"(",
"\"Bucket\"",
",",
"None",
")",
"or",
"not",
"self",
".",... | Constructs the RestApi's `BodyS3Location property`_, from the SAM Api's DefinitionUri property.
:returns: a BodyS3Location dict, containing the S3 Bucket, Key, and Version of the Swagger definition
:rtype: dict | [
"Constructs",
"the",
"RestApi",
"s",
"BodyS3Location",
"property",
"_",
"from",
"the",
"SAM",
"Api",
"s",
"DefinitionUri",
"property",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L110-L138 |
23,308 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._construct_deployment | def _construct_deployment(self, rest_api):
"""Constructs and returns the ApiGateway Deployment.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi for this Deployment
:returns: the Deployment to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayDeployment
... | python | def _construct_deployment(self, rest_api):
"""Constructs and returns the ApiGateway Deployment.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi for this Deployment
:returns: the Deployment to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayDeployment
... | [
"def",
"_construct_deployment",
"(",
"self",
",",
"rest_api",
")",
":",
"deployment",
"=",
"ApiGatewayDeployment",
"(",
"self",
".",
"logical_id",
"+",
"'Deployment'",
",",
"attributes",
"=",
"self",
".",
"passthrough_resource_attributes",
")",
"deployment",
".",
... | Constructs and returns the ApiGateway Deployment.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi for this Deployment
:returns: the Deployment to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayDeployment | [
"Constructs",
"and",
"returns",
"the",
"ApiGateway",
"Deployment",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L140-L152 |
23,309 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._construct_stage | def _construct_stage(self, deployment, swagger):
"""Constructs and returns the ApiGateway Stage.
:param model.apigateway.ApiGatewayDeployment deployment: the Deployment for this Stage
:returns: the Stage to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayStage
... | python | def _construct_stage(self, deployment, swagger):
"""Constructs and returns the ApiGateway Stage.
:param model.apigateway.ApiGatewayDeployment deployment: the Deployment for this Stage
:returns: the Stage to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayStage
... | [
"def",
"_construct_stage",
"(",
"self",
",",
"deployment",
",",
"swagger",
")",
":",
"# If StageName is some intrinsic function, then don't prefix the Stage's logical ID",
"# This will NOT create duplicates because we allow only ONE stage per API resource",
"stage_name_prefix",
"=",
"sel... | Constructs and returns the ApiGateway Stage.
:param model.apigateway.ApiGatewayDeployment deployment: the Deployment for this Stage
:returns: the Stage to which this SAM Api corresponds
:rtype: model.apigateway.ApiGatewayStage | [
"Constructs",
"and",
"returns",
"the",
"ApiGateway",
"Stage",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L154-L182 |
23,310 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator.to_cloudformation | def to_cloudformation(self):
"""Generates CloudFormation resources from a SAM API resource
:returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api.
:rtype: tuple
"""
rest_api = self._construct_rest_api()
deployment = self._construct_deployment(r... | python | def to_cloudformation(self):
"""Generates CloudFormation resources from a SAM API resource
:returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api.
:rtype: tuple
"""
rest_api = self._construct_rest_api()
deployment = self._construct_deployment(r... | [
"def",
"to_cloudformation",
"(",
"self",
")",
":",
"rest_api",
"=",
"self",
".",
"_construct_rest_api",
"(",
")",
"deployment",
"=",
"self",
".",
"_construct_deployment",
"(",
"rest_api",
")",
"swagger",
"=",
"None",
"if",
"rest_api",
".",
"Body",
"is",
"not... | Generates CloudFormation resources from a SAM API resource
:returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api.
:rtype: tuple | [
"Generates",
"CloudFormation",
"resources",
"from",
"a",
"SAM",
"API",
"resource"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L184-L203 |
23,311 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._add_cors | def _add_cors(self):
"""
Add CORS configuration to the Swagger file, if necessary
"""
INVALID_ERROR = "Invalid value for 'Cors' property"
if not self.cors:
return
if self.cors and not self.definition_body:
raise InvalidResourceException(self.log... | python | def _add_cors(self):
"""
Add CORS configuration to the Swagger file, if necessary
"""
INVALID_ERROR = "Invalid value for 'Cors' property"
if not self.cors:
return
if self.cors and not self.definition_body:
raise InvalidResourceException(self.log... | [
"def",
"_add_cors",
"(",
"self",
")",
":",
"INVALID_ERROR",
"=",
"\"Invalid value for 'Cors' property\"",
"if",
"not",
"self",
".",
"cors",
":",
"return",
"if",
"self",
".",
"cors",
"and",
"not",
"self",
".",
"definition_body",
":",
"raise",
"InvalidResourceExce... | Add CORS configuration to the Swagger file, if necessary | [
"Add",
"CORS",
"configuration",
"to",
"the",
"Swagger",
"file",
"if",
"necessary"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L205-L249 |
23,312 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._add_auth | def _add_auth(self):
"""
Add Auth configuration to the Swagger file, if necessary
"""
if not self.auth:
return
if self.auth and not self.definition_body:
raise InvalidResourceException(self.logical_id,
"Auth wor... | python | def _add_auth(self):
"""
Add Auth configuration to the Swagger file, if necessary
"""
if not self.auth:
return
if self.auth and not self.definition_body:
raise InvalidResourceException(self.logical_id,
"Auth wor... | [
"def",
"_add_auth",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"auth",
":",
"return",
"if",
"self",
".",
"auth",
"and",
"not",
"self",
".",
"definition_body",
":",
"raise",
"InvalidResourceException",
"(",
"self",
".",
"logical_id",
",",
"\"Auth work... | Add Auth configuration to the Swagger file, if necessary | [
"Add",
"Auth",
"configuration",
"to",
"the",
"Swagger",
"file",
"if",
"necessary"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L251-L281 |
23,313 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._add_gateway_responses | def _add_gateway_responses(self):
"""
Add Gateway Response configuration to the Swagger file, if necessary
"""
if not self.gateway_responses:
return
if self.gateway_responses and not self.definition_body:
raise InvalidResourceException(
s... | python | def _add_gateway_responses(self):
"""
Add Gateway Response configuration to the Swagger file, if necessary
"""
if not self.gateway_responses:
return
if self.gateway_responses and not self.definition_body:
raise InvalidResourceException(
s... | [
"def",
"_add_gateway_responses",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"gateway_responses",
":",
"return",
"if",
"self",
".",
"gateway_responses",
"and",
"not",
"self",
".",
"definition_body",
":",
"raise",
"InvalidResourceException",
"(",
"self",
"."... | Add Gateway Response configuration to the Swagger file, if necessary | [
"Add",
"Gateway",
"Response",
"configuration",
"to",
"the",
"Swagger",
"file",
"if",
"necessary"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L283-L324 |
23,314 | awslabs/serverless-application-model | samtranslator/model/api/api_generator.py | ApiGenerator._get_permission | def _get_permission(self, authorizer_name, authorizer_lambda_function_arn):
"""Constructs and returns the Lambda Permission resource allowing the Authorizer to invoke the function.
:returns: the permission resource
:rtype: model.lambda_.LambdaPermission
"""
rest_api = ApiGateway... | python | def _get_permission(self, authorizer_name, authorizer_lambda_function_arn):
"""Constructs and returns the Lambda Permission resource allowing the Authorizer to invoke the function.
:returns: the permission resource
:rtype: model.lambda_.LambdaPermission
"""
rest_api = ApiGateway... | [
"def",
"_get_permission",
"(",
"self",
",",
"authorizer_name",
",",
"authorizer_lambda_function_arn",
")",
":",
"rest_api",
"=",
"ApiGatewayRestApi",
"(",
"self",
".",
"logical_id",
",",
"depends_on",
"=",
"self",
".",
"depends_on",
",",
"attributes",
"=",
"self",... | Constructs and returns the Lambda Permission resource allowing the Authorizer to invoke the function.
:returns: the permission resource
:rtype: model.lambda_.LambdaPermission | [
"Constructs",
"and",
"returns",
"the",
"Lambda",
"Permission",
"resource",
"allowing",
"the",
"Authorizer",
"to",
"invoke",
"the",
"function",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/api/api_generator.py#L360-L381 |
23,315 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of v... | python | def to_cloudformation(self, **kwargs):
"""Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of v... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"resources",
"=",
"[",
"]",
"intrinsics_resolver",
"=",
"kwargs",
"[",
"\"intrinsics_resolver\"",
"]",
"if",
"self",
".",
"DeadLetterQueue",
":",
"self",
".",
"_validate_dlq",
"(",
"... | Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanilla CloudFormation Resources, to which this Fun... | [
"Returns",
"the",
"Lambda",
"function",
"role",
"and",
"event",
"resources",
"to",
"which",
"this",
"SAM",
"Function",
"corresponds",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L80-L126 |
23,316 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | _construct_role | def _construct_role(self, managed_policy_map):
"""Constructs a Lambda execution role based on this SAM function's Policies property.
:returns: the generated IAM Role
:rtype: model.iam.IAMRole
"""
execution_role = IAMRole(self.logical_id + 'Role', attributes=self.get_passthrough_... | python | def _construct_role(self, managed_policy_map):
"""Constructs a Lambda execution role based on this SAM function's Policies property.
:returns: the generated IAM Role
:rtype: model.iam.IAMRole
"""
execution_role = IAMRole(self.logical_id + 'Role', attributes=self.get_passthrough_... | [
"def",
"_construct_role",
"(",
"self",
",",
"managed_policy_map",
")",
":",
"execution_role",
"=",
"IAMRole",
"(",
"self",
".",
"logical_id",
"+",
"'Role'",
",",
"attributes",
"=",
"self",
".",
"get_passthrough_resource_attributes",
"(",
")",
")",
"execution_role"... | Constructs a Lambda execution role based on this SAM function's Policies property.
:returns: the generated IAM Role
:rtype: model.iam.IAMRole | [
"Constructs",
"a",
"Lambda",
"execution",
"role",
"based",
"on",
"this",
"SAM",
"function",
"s",
"Policies",
"property",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L186-L246 |
23,317 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | _generate_event_resources | def _generate_event_resources(self, lambda_function, execution_role, event_resources, lambda_alias=None):
"""Generates and returns the resources associated with this function's events.
:param model.lambda_.LambdaFunction lambda_function: generated Lambda function
:param iam.IAMRole execution_ro... | python | def _generate_event_resources(self, lambda_function, execution_role, event_resources, lambda_alias=None):
"""Generates and returns the resources associated with this function's events.
:param model.lambda_.LambdaFunction lambda_function: generated Lambda function
:param iam.IAMRole execution_ro... | [
"def",
"_generate_event_resources",
"(",
"self",
",",
"lambda_function",
",",
"execution_role",
",",
"event_resources",
",",
"lambda_alias",
"=",
"None",
")",
":",
"resources",
"=",
"[",
"]",
"if",
"self",
".",
"Events",
":",
"for",
"logical_id",
",",
"event_d... | Generates and returns the resources associated with this function's events.
:param model.lambda_.LambdaFunction lambda_function: generated Lambda function
:param iam.IAMRole execution_role: generated Lambda execution role
:param implicit_api: Global Implicit API resource where the implicit APIs... | [
"Generates",
"and",
"returns",
"the",
"resources",
"associated",
"with",
"this",
"function",
"s",
"events",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L276-L309 |
23,318 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | _construct_version | def _construct_version(self, function, intrinsics_resolver):
"""Constructs a Lambda Version resource that will be auto-published when CodeUri of the function changes.
Old versions will not be deleted without a direct reference from the CloudFormation template.
:param model.lambda_.LambdaFunctio... | python | def _construct_version(self, function, intrinsics_resolver):
"""Constructs a Lambda Version resource that will be auto-published when CodeUri of the function changes.
Old versions will not be deleted without a direct reference from the CloudFormation template.
:param model.lambda_.LambdaFunctio... | [
"def",
"_construct_version",
"(",
"self",
",",
"function",
",",
"intrinsics_resolver",
")",
":",
"code_dict",
"=",
"function",
".",
"Code",
"if",
"not",
"code_dict",
":",
"raise",
"ValueError",
"(",
"\"Lambda function code must be a valid non-empty dictionary\"",
")",
... | Constructs a Lambda Version resource that will be auto-published when CodeUri of the function changes.
Old versions will not be deleted without a direct reference from the CloudFormation template.
:param model.lambda_.LambdaFunction function: Lambda function object that is being connected to a version
... | [
"Constructs",
"a",
"Lambda",
"Version",
"resource",
"that",
"will",
"be",
"auto",
"-",
"published",
"when",
"CodeUri",
"of",
"the",
"function",
"changes",
".",
"Old",
"versions",
"will",
"not",
"be",
"deleted",
"without",
"a",
"direct",
"reference",
"from",
... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L321-L371 |
23,319 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | _construct_alias | def _construct_alias(self, name, function, version):
"""Constructs a Lambda Alias for the given function and pointing to the given version
:param string name: Name of the alias
:param model.lambda_.LambdaFunction function: Lambda function object to associate the alias with
:param model.... | python | def _construct_alias(self, name, function, version):
"""Constructs a Lambda Alias for the given function and pointing to the given version
:param string name: Name of the alias
:param model.lambda_.LambdaFunction function: Lambda function object to associate the alias with
:param model.... | [
"def",
"_construct_alias",
"(",
"self",
",",
"name",
",",
"function",
",",
"version",
")",
":",
"if",
"not",
"name",
":",
"raise",
"InvalidResourceException",
"(",
"self",
".",
"logical_id",
",",
"\"Alias name is required to create an alias\"",
")",
"logical_id",
... | Constructs a Lambda Alias for the given function and pointing to the given version
:param string name: Name of the alias
:param model.lambda_.LambdaFunction function: Lambda function object to associate the alias with
:param model.lambda_.LambdaVersion version: Lambda version object to associat... | [
"Constructs",
"a",
"Lambda",
"Alias",
"for",
"the",
"given",
"function",
"and",
"pointing",
"to",
"the",
"given",
"version"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L373-L392 |
23,320 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | SamApi.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the API Gateway RestApi, Deployment, and Stage to which this SAM Api corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanill... | python | def to_cloudformation(self, **kwargs):
"""Returns the API Gateway RestApi, Deployment, and Stage to which this SAM Api corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanill... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"resources",
"=",
"[",
"]",
"api_generator",
"=",
"ApiGenerator",
"(",
"self",
".",
"logical_id",
",",
"self",
".",
"CacheClusterEnabled",
",",
"self",
".",
"CacheClusterSize",
",",
... | Returns the API Gateway RestApi, Deployment, and Stage to which this SAM Api corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanilla CloudFormation Resources, to which this Function... | [
"Returns",
"the",
"API",
"Gateway",
"RestApi",
"Deployment",
"and",
"Stage",
"to",
"which",
"this",
"SAM",
"Api",
"corresponds",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L456-L493 |
23,321 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | SamApplication._get_application_tags | def _get_application_tags(self):
"""Adds tags to the stack if this resource is using the serverless app repo
"""
application_tags = {}
if isinstance(self.Location, dict):
if (self.APPLICATION_ID_KEY in self.Location.keys() and
self.Location[self.APPLICATIO... | python | def _get_application_tags(self):
"""Adds tags to the stack if this resource is using the serverless app repo
"""
application_tags = {}
if isinstance(self.Location, dict):
if (self.APPLICATION_ID_KEY in self.Location.keys() and
self.Location[self.APPLICATIO... | [
"def",
"_get_application_tags",
"(",
"self",
")",
":",
"application_tags",
"=",
"{",
"}",
"if",
"isinstance",
"(",
"self",
".",
"Location",
",",
"dict",
")",
":",
"if",
"(",
"self",
".",
"APPLICATION_ID_KEY",
"in",
"self",
".",
"Location",
".",
"keys",
"... | Adds tags to the stack if this resource is using the serverless app repo | [
"Adds",
"tags",
"to",
"the",
"stack",
"if",
"this",
"resource",
"is",
"using",
"the",
"serverless",
"app",
"repo"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L597-L608 |
23,322 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | SamLayerVersion.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the Lambda layer to which this SAM Layer corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanilla CloudFormation Resources, ... | python | def to_cloudformation(self, **kwargs):
"""Returns the Lambda layer to which this SAM Layer corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanilla CloudFormation Resources, ... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"resources",
"=",
"[",
"]",
"# Append any CFN resources:",
"intrinsics_resolver",
"=",
"kwargs",
"[",
"\"intrinsics_resolver\"",
"]",
"resources",
".",
"append",
"(",
"self",
".",
"_cons... | Returns the Lambda layer to which this SAM Layer corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
macro to pure CloudFormation
:returns: a list of vanilla CloudFormation Resources, to which this Function expands
:rtype: lis... | [
"Returns",
"the",
"Lambda",
"layer",
"to",
"which",
"this",
"SAM",
"Layer",
"corresponds",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L628-L642 |
23,323 | awslabs/serverless-application-model | samtranslator/model/sam_resources.py | SamLayerVersion._get_retention_policy_value | def _get_retention_policy_value(self):
"""
Sets the deletion policy on this resource. The default is 'Retain'.
:return: value for the DeletionPolicy attribute.
"""
if self.RetentionPolicy is None or self.RetentionPolicy.lower() == self.RETAIN.lower():
return self.RE... | python | def _get_retention_policy_value(self):
"""
Sets the deletion policy on this resource. The default is 'Retain'.
:return: value for the DeletionPolicy attribute.
"""
if self.RetentionPolicy is None or self.RetentionPolicy.lower() == self.RETAIN.lower():
return self.RE... | [
"def",
"_get_retention_policy_value",
"(",
"self",
")",
":",
"if",
"self",
".",
"RetentionPolicy",
"is",
"None",
"or",
"self",
".",
"RetentionPolicy",
".",
"lower",
"(",
")",
"==",
"self",
".",
"RETAIN",
".",
"lower",
"(",
")",
":",
"return",
"self",
"."... | Sets the deletion policy on this resource. The default is 'Retain'.
:return: value for the DeletionPolicy attribute. | [
"Sets",
"the",
"deletion",
"policy",
"on",
"this",
"resource",
".",
"The",
"default",
"is",
"Retain",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/sam_resources.py#L690-L704 |
23,324 | awslabs/serverless-application-model | examples/apps/lex-order-flowers-python/lambda_function.py | order_flowers | def order_flowers(intent_request):
"""
Performs dialog management and fulfillment for ordering flowers.
Beyond fulfillment, the implementation of this intent demonstrates the use of the elicitSlot dialog action
in slot validation and re-prompting.
"""
flower_type = get_slots(intent_request)["Fl... | python | def order_flowers(intent_request):
"""
Performs dialog management and fulfillment for ordering flowers.
Beyond fulfillment, the implementation of this intent demonstrates the use of the elicitSlot dialog action
in slot validation and re-prompting.
"""
flower_type = get_slots(intent_request)["Fl... | [
"def",
"order_flowers",
"(",
"intent_request",
")",
":",
"flower_type",
"=",
"get_slots",
"(",
"intent_request",
")",
"[",
"\"FlowerType\"",
"]",
"date",
"=",
"get_slots",
"(",
"intent_request",
")",
"[",
"\"PickupDate\"",
"]",
"time",
"=",
"get_slots",
"(",
"... | Performs dialog management and fulfillment for ordering flowers.
Beyond fulfillment, the implementation of this intent demonstrates the use of the elicitSlot dialog action
in slot validation and re-prompting. | [
"Performs",
"dialog",
"management",
"and",
"fulfillment",
"for",
"ordering",
"flowers",
".",
"Beyond",
"fulfillment",
"the",
"implementation",
"of",
"this",
"intent",
"demonstrates",
"the",
"use",
"of",
"the",
"elicitSlot",
"dialog",
"action",
"in",
"slot",
"valid... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/examples/apps/lex-order-flowers-python/lambda_function.py#L119-L158 |
23,325 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | PushEventSource._construct_permission | def _construct_permission(self, function, source_arn=None, source_account=None, suffix="", event_source_token=None):
"""Constructs the Lambda Permission resource allowing the source service to invoke the function this event
source triggers.
:returns: the permission resource
:rtype: mode... | python | def _construct_permission(self, function, source_arn=None, source_account=None, suffix="", event_source_token=None):
"""Constructs the Lambda Permission resource allowing the source service to invoke the function this event
source triggers.
:returns: the permission resource
:rtype: mode... | [
"def",
"_construct_permission",
"(",
"self",
",",
"function",
",",
"source_arn",
"=",
"None",
",",
"source_account",
"=",
"None",
",",
"suffix",
"=",
"\"\"",
",",
"event_source_token",
"=",
"None",
")",
":",
"lambda_permission",
"=",
"LambdaPermission",
"(",
"... | Constructs the Lambda Permission resource allowing the source service to invoke the function this event
source triggers.
:returns: the permission resource
:rtype: model.lambda_.LambdaPermission | [
"Constructs",
"the",
"Lambda",
"Permission",
"resource",
"allowing",
"the",
"source",
"service",
"to",
"invoke",
"the",
"function",
"this",
"event",
"source",
"triggers",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L43-L66 |
23,326 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | Schedule.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the CloudWatch Events Rule and Lambda Permission to which this Schedule event source corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this pull event expand... | python | def to_cloudformation(self, **kwargs):
"""Returns the CloudWatch Events Rule and Lambda Permission to which this Schedule event source corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this pull event expand... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"function",
"=",
"kwargs",
".",
"get",
"(",
"'function'",
")",
"if",
"not",
"function",
":",
"raise",
"TypeError",
"(",
"\"Missing required keyword argument: function\"",
")",
"resources... | Returns the CloudWatch Events Rule and Lambda Permission to which this Schedule event source corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this pull event expands
:rtype: list | [
"Returns",
"the",
"CloudWatch",
"Events",
"Rule",
"and",
"Lambda",
"Permission",
"to",
"which",
"this",
"Schedule",
"event",
"source",
"corresponds",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L78-L103 |
23,327 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | CloudWatchEvent._construct_target | def _construct_target(self, function):
"""Constructs the Target property for the CloudWatch Events Rule.
:returns: the Target property
:rtype: dict
"""
target = {
'Arn': function.get_runtime_attr("arn"),
'Id': self.logical_id + 'LambdaTarget'
... | python | def _construct_target(self, function):
"""Constructs the Target property for the CloudWatch Events Rule.
:returns: the Target property
:rtype: dict
"""
target = {
'Arn': function.get_runtime_attr("arn"),
'Id': self.logical_id + 'LambdaTarget'
... | [
"def",
"_construct_target",
"(",
"self",
",",
"function",
")",
":",
"target",
"=",
"{",
"'Arn'",
":",
"function",
".",
"get_runtime_attr",
"(",
"\"arn\"",
")",
",",
"'Id'",
":",
"self",
".",
"logical_id",
"+",
"'LambdaTarget'",
"}",
"if",
"self",
".",
"I... | Constructs the Target property for the CloudWatch Events Rule.
:returns: the Target property
:rtype: dict | [
"Constructs",
"the",
"Target",
"property",
"for",
"the",
"CloudWatch",
"Events",
"Rule",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L159-L174 |
23,328 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | S3.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the Lambda Permission resource allowing S3 to invoke the function this event source triggers.
:param dict kwargs: S3 bucket resource
:returns: a list of vanilla CloudFormation Resources, to which this S3 event expands
:rtype: list
... | python | def to_cloudformation(self, **kwargs):
"""Returns the Lambda Permission resource allowing S3 to invoke the function this event source triggers.
:param dict kwargs: S3 bucket resource
:returns: a list of vanilla CloudFormation Resources, to which this S3 event expands
:rtype: list
... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"function",
"=",
"kwargs",
".",
"get",
"(",
"'function'",
")",
"if",
"not",
"function",
":",
"raise",
"TypeError",
"(",
"\"Missing required keyword argument: function\"",
")",
"if",
"'... | Returns the Lambda Permission resource allowing S3 to invoke the function this event source triggers.
:param dict kwargs: S3 bucket resource
:returns: a list of vanilla CloudFormation Resources, to which this S3 event expands
:rtype: list | [
"Returns",
"the",
"Lambda",
"Permission",
"resource",
"allowing",
"S3",
"to",
"invoke",
"the",
"function",
"this",
"event",
"source",
"triggers",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L197-L241 |
23,329 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | S3._depend_on_lambda_permissions_using_tag | def _depend_on_lambda_permissions_using_tag(self, bucket, permission):
"""
Since conditional DependsOn is not supported this undocumented way of
implicitely making dependency through tags is used.
See https://stackoverflow.com/questions/34607476/cloudformation-apply-condition-on-depend... | python | def _depend_on_lambda_permissions_using_tag(self, bucket, permission):
"""
Since conditional DependsOn is not supported this undocumented way of
implicitely making dependency through tags is used.
See https://stackoverflow.com/questions/34607476/cloudformation-apply-condition-on-depend... | [
"def",
"_depend_on_lambda_permissions_using_tag",
"(",
"self",
",",
"bucket",
",",
"permission",
")",
":",
"properties",
"=",
"bucket",
".",
"get",
"(",
"'Properties'",
",",
"None",
")",
"if",
"properties",
"is",
"None",
":",
"properties",
"=",
"{",
"}",
"bu... | Since conditional DependsOn is not supported this undocumented way of
implicitely making dependency through tags is used.
See https://stackoverflow.com/questions/34607476/cloudformation-apply-condition-on-dependson
It is done by using Ref wrapped in a conditional Fn::If. Using Ref implies a
... | [
"Since",
"conditional",
"DependsOn",
"is",
"not",
"supported",
"this",
"undocumented",
"way",
"of",
"implicitely",
"making",
"dependency",
"through",
"tags",
"is",
"used",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L268-L297 |
23,330 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | SNS.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the Lambda Permission resource allowing SNS to invoke the function this event source triggers.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this SNS event expands
... | python | def to_cloudformation(self, **kwargs):
"""Returns the Lambda Permission resource allowing SNS to invoke the function this event source triggers.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this SNS event expands
... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"function",
"=",
"kwargs",
".",
"get",
"(",
"'function'",
")",
"if",
"not",
"function",
":",
"raise",
"TypeError",
"(",
"\"Missing required keyword argument: function\"",
")",
"return",
... | Returns the Lambda Permission resource allowing SNS to invoke the function this event source triggers.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this SNS event expands
:rtype: list | [
"Returns",
"the",
"Lambda",
"Permission",
"resource",
"allowing",
"SNS",
"to",
"invoke",
"the",
"function",
"this",
"event",
"source",
"triggers",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L350-L363 |
23,331 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | Api.resources_to_link | def resources_to_link(self, resources):
"""
If this API Event Source refers to an explicit API resource, resolve the reference and grab
necessary data from the explicit API
"""
rest_api_id = self.RestApiId
if isinstance(rest_api_id, dict) and "Ref" in rest_api_id:
... | python | def resources_to_link(self, resources):
"""
If this API Event Source refers to an explicit API resource, resolve the reference and grab
necessary data from the explicit API
"""
rest_api_id = self.RestApiId
if isinstance(rest_api_id, dict) and "Ref" in rest_api_id:
... | [
"def",
"resources_to_link",
"(",
"self",
",",
"resources",
")",
":",
"rest_api_id",
"=",
"self",
".",
"RestApiId",
"if",
"isinstance",
"(",
"rest_api_id",
",",
"dict",
")",
"and",
"\"Ref\"",
"in",
"rest_api_id",
":",
"rest_api_id",
"=",
"rest_api_id",
"[",
"... | If this API Event Source refers to an explicit API resource, resolve the reference and grab
necessary data from the explicit API | [
"If",
"this",
"API",
"Event",
"Source",
"refers",
"to",
"an",
"explicit",
"API",
"resource",
"resolve",
"the",
"reference",
"and",
"grab",
"necessary",
"data",
"from",
"the",
"explicit",
"API"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L392-L439 |
23,332 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | Api.to_cloudformation | def to_cloudformation(self, **kwargs):
"""If the Api event source has a RestApi property, then simply return the Lambda Permission resource allowing
API Gateway to call the function. If no RestApi is provided, then additionally inject the path, method, and the
x-amazon-apigateway-integration int... | python | def to_cloudformation(self, **kwargs):
"""If the Api event source has a RestApi property, then simply return the Lambda Permission resource allowing
API Gateway to call the function. If no RestApi is provided, then additionally inject the path, method, and the
x-amazon-apigateway-integration int... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"resources",
"=",
"[",
"]",
"function",
"=",
"kwargs",
".",
"get",
"(",
"'function'",
")",
"if",
"not",
"function",
":",
"raise",
"TypeError",
"(",
"\"Missing required keyword argume... | If the Api event source has a RestApi property, then simply return the Lambda Permission resource allowing
API Gateway to call the function. If no RestApi is provided, then additionally inject the path, method, and the
x-amazon-apigateway-integration into the Swagger body for a provided implicit API.
... | [
"If",
"the",
"Api",
"event",
"source",
"has",
"a",
"RestApi",
"property",
"then",
"simply",
"return",
"the",
"Lambda",
"Permission",
"resource",
"allowing",
"API",
"Gateway",
"to",
"call",
"the",
"function",
".",
"If",
"no",
"RestApi",
"is",
"provided",
"the... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L441-L468 |
23,333 | awslabs/serverless-application-model | samtranslator/model/eventsources/push.py | Api._add_swagger_integration | def _add_swagger_integration(self, api, function):
"""Adds the path and method for this Api event source to the Swagger body for the provided RestApi.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi to which the path and method should be added.
"""
swagger_body = api.get... | python | def _add_swagger_integration(self, api, function):
"""Adds the path and method for this Api event source to the Swagger body for the provided RestApi.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi to which the path and method should be added.
"""
swagger_body = api.get... | [
"def",
"_add_swagger_integration",
"(",
"self",
",",
"api",
",",
"function",
")",
":",
"swagger_body",
"=",
"api",
".",
"get",
"(",
"\"DefinitionBody\"",
")",
"if",
"swagger_body",
"is",
"None",
":",
"return",
"function_arn",
"=",
"function",
".",
"get_runtime... | Adds the path and method for this Api event source to the Swagger body for the provided RestApi.
:param model.apigateway.ApiGatewayRestApi rest_api: the RestApi to which the path and method should be added. | [
"Adds",
"the",
"path",
"and",
"method",
"for",
"this",
"Api",
"event",
"source",
"to",
"the",
"Swagger",
"body",
"for",
"the",
"provided",
"RestApi",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/push.py#L507-L567 |
23,334 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver.resolve_parameter_refs | def resolve_parameter_refs(self, input):
"""
Resolves references to parameters within the given dictionary recursively. Other intrinsic functions such as
!GetAtt, !Sub or !Ref to non-parameters will be left untouched.
Result is a dictionary where parameter values are inlined. Don't pass... | python | def resolve_parameter_refs(self, input):
"""
Resolves references to parameters within the given dictionary recursively. Other intrinsic functions such as
!GetAtt, !Sub or !Ref to non-parameters will be left untouched.
Result is a dictionary where parameter values are inlined. Don't pass... | [
"def",
"resolve_parameter_refs",
"(",
"self",
",",
"input",
")",
":",
"return",
"self",
".",
"_traverse",
"(",
"input",
",",
"self",
".",
"parameters",
",",
"self",
".",
"_try_resolve_parameter_refs",
")"
] | Resolves references to parameters within the given dictionary recursively. Other intrinsic functions such as
!GetAtt, !Sub or !Ref to non-parameters will be left untouched.
Result is a dictionary where parameter values are inlined. Don't pass this dictionary directly into
transform's output bec... | [
"Resolves",
"references",
"to",
"parameters",
"within",
"the",
"given",
"dictionary",
"recursively",
".",
"Other",
"intrinsic",
"functions",
"such",
"as",
"!GetAtt",
"!Sub",
"or",
"!Ref",
"to",
"non",
"-",
"parameters",
"will",
"be",
"left",
"untouched",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L30-L41 |
23,335 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver.resolve_sam_resource_refs | def resolve_sam_resource_refs(self, input, supported_resource_refs):
"""
Customers can provide a reference to a "derived" SAM resource such as Alias of a Function or Stage of an API
resource. This method recursively walks the tree, converting all derived references to the real resource name,
... | python | def resolve_sam_resource_refs(self, input, supported_resource_refs):
"""
Customers can provide a reference to a "derived" SAM resource such as Alias of a Function or Stage of an API
resource. This method recursively walks the tree, converting all derived references to the real resource name,
... | [
"def",
"resolve_sam_resource_refs",
"(",
"self",
",",
"input",
",",
"supported_resource_refs",
")",
":",
"return",
"self",
".",
"_traverse",
"(",
"input",
",",
"supported_resource_refs",
",",
"self",
".",
"_try_resolve_sam_resource_refs",
")"
] | Customers can provide a reference to a "derived" SAM resource such as Alias of a Function or Stage of an API
resource. This method recursively walks the tree, converting all derived references to the real resource name,
if it is present.
Example:
{"Ref": "MyFunction.Alias"} -> {"Ref... | [
"Customers",
"can",
"provide",
"a",
"reference",
"to",
"a",
"derived",
"SAM",
"resource",
"such",
"as",
"Alias",
"of",
"a",
"Function",
"or",
"Stage",
"of",
"an",
"API",
"resource",
".",
"This",
"method",
"recursively",
"walks",
"the",
"tree",
"converting",
... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L43-L65 |
23,336 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver.resolve_sam_resource_id_refs | def resolve_sam_resource_id_refs(self, input, supported_resource_id_refs):
"""
Some SAM resources have their logical ids mutated from the original id that the customer writes in the
template. This method recursively walks the tree and updates these logical ids from the old value
to the n... | python | def resolve_sam_resource_id_refs(self, input, supported_resource_id_refs):
"""
Some SAM resources have their logical ids mutated from the original id that the customer writes in the
template. This method recursively walks the tree and updates these logical ids from the old value
to the n... | [
"def",
"resolve_sam_resource_id_refs",
"(",
"self",
",",
"input",
",",
"supported_resource_id_refs",
")",
":",
"return",
"self",
".",
"_traverse",
"(",
"input",
",",
"supported_resource_id_refs",
",",
"self",
".",
"_try_resolve_sam_resource_id_refs",
")"
] | Some SAM resources have their logical ids mutated from the original id that the customer writes in the
template. This method recursively walks the tree and updates these logical ids from the old value
to the new value that is generated by SAM.
Example:
{"Ref": "MyLayer"} -> {"Ref": ... | [
"Some",
"SAM",
"resources",
"have",
"their",
"logical",
"ids",
"mutated",
"from",
"the",
"original",
"id",
"that",
"the",
"customer",
"writes",
"in",
"the",
"template",
".",
"This",
"method",
"recursively",
"walks",
"the",
"tree",
"and",
"updates",
"these",
... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L67-L88 |
23,337 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._traverse | def _traverse(self, input, resolution_data, resolver_method):
"""
Driver method that performs the actual traversal of input and calls the appropriate `resolver_method` when
to perform the resolution.
:param input: Any primitive type (dict, array, string etc) whose value might contain a... | python | def _traverse(self, input, resolution_data, resolver_method):
"""
Driver method that performs the actual traversal of input and calls the appropriate `resolver_method` when
to perform the resolution.
:param input: Any primitive type (dict, array, string etc) whose value might contain a... | [
"def",
"_traverse",
"(",
"self",
",",
"input",
",",
"resolution_data",
",",
"resolver_method",
")",
":",
"# There is data to help with resolution. Skip the traversal altogether",
"if",
"len",
"(",
"resolution_data",
")",
"==",
"0",
":",
"return",
"input",
"#",
"# Trav... | Driver method that performs the actual traversal of input and calls the appropriate `resolver_method` when
to perform the resolution.
:param input: Any primitive type (dict, array, string etc) whose value might contain an intrinsic function
:param resolution_data: Data that will help with reso... | [
"Driver",
"method",
"that",
"performs",
"the",
"actual",
"traversal",
"of",
"input",
"and",
"calls",
"the",
"appropriate",
"resolver_method",
"when",
"to",
"perform",
"the",
"resolution",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L90-L132 |
23,338 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._traverse_dict | def _traverse_dict(self, input_dict, resolution_data, resolver_method):
"""
Traverse a dictionary to resolve intrinsic functions on every value
:param input_dict: Input dictionary to traverse
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolve... | python | def _traverse_dict(self, input_dict, resolution_data, resolver_method):
"""
Traverse a dictionary to resolve intrinsic functions on every value
:param input_dict: Input dictionary to traverse
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolve... | [
"def",
"_traverse_dict",
"(",
"self",
",",
"input_dict",
",",
"resolution_data",
",",
"resolver_method",
")",
":",
"for",
"key",
",",
"value",
"in",
"input_dict",
".",
"items",
"(",
")",
":",
"input_dict",
"[",
"key",
"]",
"=",
"self",
".",
"_traverse",
... | Traverse a dictionary to resolve intrinsic functions on every value
:param input_dict: Input dictionary to traverse
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolver_method: Method that can actually resolve an intrinsic function, if it detects one
... | [
"Traverse",
"a",
"dictionary",
"to",
"resolve",
"intrinsic",
"functions",
"on",
"every",
"value"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L134-L146 |
23,339 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._traverse_list | def _traverse_list(self, input_list, resolution_data, resolver_method):
"""
Traverse a list to resolve intrinsic functions on every element
:param input_list: List of input
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolver_method: Method th... | python | def _traverse_list(self, input_list, resolution_data, resolver_method):
"""
Traverse a list to resolve intrinsic functions on every element
:param input_list: List of input
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolver_method: Method th... | [
"def",
"_traverse_list",
"(",
"self",
",",
"input_list",
",",
"resolution_data",
",",
"resolver_method",
")",
":",
"for",
"index",
",",
"value",
"in",
"enumerate",
"(",
"input_list",
")",
":",
"input_list",
"[",
"index",
"]",
"=",
"self",
".",
"_traverse",
... | Traverse a list to resolve intrinsic functions on every element
:param input_list: List of input
:param resolution_data: Data that the `resolver_method` needs to operate
:param resolver_method: Method that can actually resolve an intrinsic function, if it detects one
:return: Modified l... | [
"Traverse",
"a",
"list",
"to",
"resolve",
"intrinsic",
"functions",
"on",
"every",
"element"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L148-L160 |
23,340 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._try_resolve_sam_resource_refs | def _try_resolve_sam_resource_refs(self, input, supported_resource_refs):
"""
Try to resolve SAM resource references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original input
... | python | def _try_resolve_sam_resource_refs(self, input, supported_resource_refs):
"""
Try to resolve SAM resource references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original input
... | [
"def",
"_try_resolve_sam_resource_refs",
"(",
"self",
",",
"input",
",",
"supported_resource_refs",
")",
":",
"if",
"not",
"self",
".",
"_is_intrinsic_dict",
"(",
"input",
")",
":",
"return",
"input",
"function_type",
"=",
"list",
"(",
"input",
".",
"keys",
"(... | Try to resolve SAM resource references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original input
unmodified.
:param dict input: Dictionary that may represent an intrinsic funct... | [
"Try",
"to",
"resolve",
"SAM",
"resource",
"references",
"on",
"the",
"given",
"template",
".",
"If",
"the",
"given",
"object",
"looks",
"like",
"one",
"of",
"the",
"supported",
"intrinsics",
"it",
"calls",
"the",
"appropriate",
"resolution",
"on",
"it",
"."... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L179-L194 |
23,341 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._try_resolve_sam_resource_id_refs | def _try_resolve_sam_resource_id_refs(self, input, supported_resource_id_refs):
"""
Try to resolve SAM resource id references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original... | python | def _try_resolve_sam_resource_id_refs(self, input, supported_resource_id_refs):
"""
Try to resolve SAM resource id references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original... | [
"def",
"_try_resolve_sam_resource_id_refs",
"(",
"self",
",",
"input",
",",
"supported_resource_id_refs",
")",
":",
"if",
"not",
"self",
".",
"_is_intrinsic_dict",
"(",
"input",
")",
":",
"return",
"input",
"function_type",
"=",
"list",
"(",
"input",
".",
"keys"... | Try to resolve SAM resource id references on the given template. If the given object looks like one of the
supported intrinsics, it calls the appropriate resolution on it. If not, this method returns the original input
unmodified.
:param dict input: Dictionary that may represent an intrinsic fu... | [
"Try",
"to",
"resolve",
"SAM",
"resource",
"id",
"references",
"on",
"the",
"given",
"template",
".",
"If",
"the",
"given",
"object",
"looks",
"like",
"one",
"of",
"the",
"supported",
"intrinsics",
"it",
"calls",
"the",
"appropriate",
"resolution",
"on",
"it... | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L196-L210 |
23,342 | awslabs/serverless-application-model | samtranslator/intrinsics/resolver.py | IntrinsicsResolver._is_intrinsic_dict | def _is_intrinsic_dict(self, input):
"""
Can the input represent an intrinsic function in it?
:param input: Object to be checked
:return: True, if the input contains a supported intrinsic function. False otherwise
"""
# All intrinsic functions are dictionaries with just... | python | def _is_intrinsic_dict(self, input):
"""
Can the input represent an intrinsic function in it?
:param input: Object to be checked
:return: True, if the input contains a supported intrinsic function. False otherwise
"""
# All intrinsic functions are dictionaries with just... | [
"def",
"_is_intrinsic_dict",
"(",
"self",
",",
"input",
")",
":",
"# All intrinsic functions are dictionaries with just one key",
"return",
"isinstance",
"(",
"input",
",",
"dict",
")",
"and",
"len",
"(",
"input",
")",
"==",
"1",
"and",
"list",
"(",
"input",
"."... | Can the input represent an intrinsic function in it?
:param input: Object to be checked
:return: True, if the input contains a supported intrinsic function. False otherwise | [
"Can",
"the",
"input",
"represent",
"an",
"intrinsic",
"function",
"in",
"it?"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/intrinsics/resolver.py#L212-L222 |
23,343 | awslabs/serverless-application-model | samtranslator/model/eventsources/cloudwatchlogs.py | CloudWatchLogs.to_cloudformation | def to_cloudformation(self, **kwargs):
"""Returns the CloudWatch Logs Subscription Filter and Lambda Permission to which this CloudWatch Logs event source
corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to ... | python | def to_cloudformation(self, **kwargs):
"""Returns the CloudWatch Logs Subscription Filter and Lambda Permission to which this CloudWatch Logs event source
corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to ... | [
"def",
"to_cloudformation",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"function",
"=",
"kwargs",
".",
"get",
"(",
"'function'",
")",
"if",
"not",
"function",
":",
"raise",
"TypeError",
"(",
"\"Missing required keyword argument: function\"",
")",
"source_ar... | Returns the CloudWatch Logs Subscription Filter and Lambda Permission to which this CloudWatch Logs event source
corresponds.
:param dict kwargs: no existing resources need to be modified
:returns: a list of vanilla CloudFormation Resources, to which this push event expands
:rtype: list | [
"Returns",
"the",
"CloudWatch",
"Logs",
"Subscription",
"Filter",
"and",
"Lambda",
"Permission",
"to",
"which",
"this",
"CloudWatch",
"Logs",
"event",
"source",
"corresponds",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/model/eventsources/cloudwatchlogs.py#L18-L36 |
23,344 | awslabs/serverless-application-model | samtranslator/policy_template_processor/processor.py | PolicyTemplatesProcessor.convert | def convert(self, template_name, parameter_values):
"""
Converts the given template to IAM-ready policy statement by substituting template parameters with the given
values.
:param template_name: Name of the template
:param parameter_values: Values for all parameters of the templ... | python | def convert(self, template_name, parameter_values):
"""
Converts the given template to IAM-ready policy statement by substituting template parameters with the given
values.
:param template_name: Name of the template
:param parameter_values: Values for all parameters of the templ... | [
"def",
"convert",
"(",
"self",
",",
"template_name",
",",
"parameter_values",
")",
":",
"if",
"not",
"self",
".",
"has",
"(",
"template_name",
")",
":",
"raise",
"TemplateNotFoundException",
"(",
"template_name",
")",
"template",
"=",
"self",
".",
"get",
"("... | Converts the given template to IAM-ready policy statement by substituting template parameters with the given
values.
:param template_name: Name of the template
:param parameter_values: Values for all parameters of the template
:return dict: Dictionary containing policy statement
... | [
"Converts",
"the",
"given",
"template",
"to",
"IAM",
"-",
"ready",
"policy",
"statement",
"by",
"substituting",
"template",
"parameters",
"with",
"the",
"given",
"values",
"."
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/policy_template_processor/processor.py#L84-L100 |
23,345 | awslabs/serverless-application-model | samtranslator/policy_template_processor/processor.py | PolicyTemplatesProcessor._is_valid_templates_dict | def _is_valid_templates_dict(policy_templates_dict, schema=None):
"""
Is this a valid policy template dictionary
:param dict policy_templates_dict: Data to be validated
:param dict schema: Optional, dictionary containing JSON Schema representing policy template
:return: True, if... | python | def _is_valid_templates_dict(policy_templates_dict, schema=None):
"""
Is this a valid policy template dictionary
:param dict policy_templates_dict: Data to be validated
:param dict schema: Optional, dictionary containing JSON Schema representing policy template
:return: True, if... | [
"def",
"_is_valid_templates_dict",
"(",
"policy_templates_dict",
",",
"schema",
"=",
"None",
")",
":",
"if",
"not",
"schema",
":",
"schema",
"=",
"PolicyTemplatesProcessor",
".",
"_read_schema",
"(",
")",
"try",
":",
"jsonschema",
".",
"validate",
"(",
"policy_t... | Is this a valid policy template dictionary
:param dict policy_templates_dict: Data to be validated
:param dict schema: Optional, dictionary containing JSON Schema representing policy template
:return: True, if it is valid.
:raises ValueError: If the template dictionary doesn't match up ... | [
"Is",
"this",
"a",
"valid",
"policy",
"template",
"dictionary"
] | cccb0c96b5c91e53355ebc07e542467303a5eedd | https://github.com/awslabs/serverless-application-model/blob/cccb0c96b5c91e53355ebc07e542467303a5eedd/samtranslator/policy_template_processor/processor.py#L103-L122 |
23,346 | pyecharts/pyecharts | pyecharts/render/engine.py | RenderEngine.render_chart_to_file | def render_chart_to_file(self, template_name: str, chart: Any, path: str):
"""
Render a chart or page to local html files.
:param chart: A Chart or Page object
:param path: The destination file which the html code write to
:param template_name: The name of template file.
... | python | def render_chart_to_file(self, template_name: str, chart: Any, path: str):
"""
Render a chart or page to local html files.
:param chart: A Chart or Page object
:param path: The destination file which the html code write to
:param template_name: The name of template file.
... | [
"def",
"render_chart_to_file",
"(",
"self",
",",
"template_name",
":",
"str",
",",
"chart",
":",
"Any",
",",
"path",
":",
"str",
")",
":",
"tpl",
"=",
"self",
".",
"env",
".",
"get_template",
"(",
"template_name",
")",
"html",
"=",
"tpl",
".",
"render"... | Render a chart or page to local html files.
:param chart: A Chart or Page object
:param path: The destination file which the html code write to
:param template_name: The name of template file. | [
"Render",
"a",
"chart",
"or",
"page",
"to",
"local",
"html",
"files",
"."
] | 02050acb0e94bb9453b88a25028de7a0ce23f125 | https://github.com/pyecharts/pyecharts/blob/02050acb0e94bb9453b88a25028de7a0ce23f125/pyecharts/render/engine.py#L36-L46 |
23,347 | pyecharts/pyecharts | pyecharts/render/snapshot.py | decode_base64 | def decode_base64(data: str) -> bytes:
"""Decode base64, padding being optional.
:param data: Base64 data as an ASCII byte string
:returns: The decoded byte string.
"""
missing_padding = len(data) % 4
if missing_padding != 0:
data += "=" * (4 - missing_padding)
return base64.decodeb... | python | def decode_base64(data: str) -> bytes:
"""Decode base64, padding being optional.
:param data: Base64 data as an ASCII byte string
:returns: The decoded byte string.
"""
missing_padding = len(data) % 4
if missing_padding != 0:
data += "=" * (4 - missing_padding)
return base64.decodeb... | [
"def",
"decode_base64",
"(",
"data",
":",
"str",
")",
"->",
"bytes",
":",
"missing_padding",
"=",
"len",
"(",
"data",
")",
"%",
"4",
"if",
"missing_padding",
"!=",
"0",
":",
"data",
"+=",
"\"=\"",
"*",
"(",
"4",
"-",
"missing_padding",
")",
"return",
... | Decode base64, padding being optional.
:param data: Base64 data as an ASCII byte string
:returns: The decoded byte string. | [
"Decode",
"base64",
"padding",
"being",
"optional",
"."
] | 02050acb0e94bb9453b88a25028de7a0ce23f125 | https://github.com/pyecharts/pyecharts/blob/02050acb0e94bb9453b88a25028de7a0ce23f125/pyecharts/render/snapshot.py#L58-L67 |
23,348 | micropython/micropython | ports/nrf/boards/make-pins.py | parse_pin | def parse_pin(name_str):
"""Parses a string and returns a pin-num."""
if len(name_str) < 1:
raise ValueError("Expecting pin name to be at least 4 charcters.")
if name_str[0] != 'P':
raise ValueError("Expecting pin name to start with P")
pin_str = name_str[1:].split('/')[0]
if not pin... | python | def parse_pin(name_str):
"""Parses a string and returns a pin-num."""
if len(name_str) < 1:
raise ValueError("Expecting pin name to be at least 4 charcters.")
if name_str[0] != 'P':
raise ValueError("Expecting pin name to start with P")
pin_str = name_str[1:].split('/')[0]
if not pin... | [
"def",
"parse_pin",
"(",
"name_str",
")",
":",
"if",
"len",
"(",
"name_str",
")",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"Expecting pin name to be at least 4 charcters.\"",
")",
"if",
"name_str",
"[",
"0",
"]",
"!=",
"'P'",
":",
"raise",
"ValueError",
... | Parses a string and returns a pin-num. | [
"Parses",
"a",
"string",
"and",
"returns",
"a",
"pin",
"-",
"num",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/ports/nrf/boards/make-pins.py#L14-L23 |
23,349 | micropython/micropython | examples/switch.py | run_loop | def run_loop(leds=all_leds):
"""
Start the loop.
:param `leds`: Which LEDs to light up upon switch press.
:type `leds`: sequence of LED objects
"""
print('Loop started.\nPress Ctrl+C to break out of the loop.')
while 1:
try:
if switch():
[led.on() for led... | python | def run_loop(leds=all_leds):
"""
Start the loop.
:param `leds`: Which LEDs to light up upon switch press.
:type `leds`: sequence of LED objects
"""
print('Loop started.\nPress Ctrl+C to break out of the loop.')
while 1:
try:
if switch():
[led.on() for led... | [
"def",
"run_loop",
"(",
"leds",
"=",
"all_leds",
")",
":",
"print",
"(",
"'Loop started.\\nPress Ctrl+C to break out of the loop.'",
")",
"while",
"1",
":",
"try",
":",
"if",
"switch",
"(",
")",
":",
"[",
"led",
".",
"on",
"(",
")",
"for",
"led",
"in",
"... | Start the loop.
:param `leds`: Which LEDs to light up upon switch press.
:type `leds`: sequence of LED objects | [
"Start",
"the",
"loop",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/examples/switch.py#L27-L42 |
23,350 | micropython/micropython | py/makemoduledefs.py | find_c_file | def find_c_file(obj_file, vpath):
""" Search vpaths for the c file that matches the provided object_file.
:param str obj_file: object file to find the matching c file for
:param List[str] vpath: List of base paths, similar to gcc vpath
:return: str path to c file or None
"""
c_file = None
r... | python | def find_c_file(obj_file, vpath):
""" Search vpaths for the c file that matches the provided object_file.
:param str obj_file: object file to find the matching c file for
:param List[str] vpath: List of base paths, similar to gcc vpath
:return: str path to c file or None
"""
c_file = None
r... | [
"def",
"find_c_file",
"(",
"obj_file",
",",
"vpath",
")",
":",
"c_file",
"=",
"None",
"relative_c_file",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"obj_file",
")",
"[",
"0",
"]",
"+",
"\".c\"",
"relative_c_file",
"=",
"relative_c_file",
".",
"lstrip",
... | Search vpaths for the c file that matches the provided object_file.
:param str obj_file: object file to find the matching c file for
:param List[str] vpath: List of base paths, similar to gcc vpath
:return: str path to c file or None | [
"Search",
"vpaths",
"for",
"the",
"c",
"file",
"that",
"matches",
"the",
"provided",
"object_file",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/py/makemoduledefs.py#L22-L38 |
23,351 | micropython/micropython | py/makemoduledefs.py | find_module_registrations | def find_module_registrations(c_file):
""" Find any MP_REGISTER_MODULE definitions in the provided c file.
:param str c_file: path to c file to check
:return: List[(module_name, obj_module, enabled_define)]
"""
global pattern
if c_file is None:
# No c file to match the object file, ski... | python | def find_module_registrations(c_file):
""" Find any MP_REGISTER_MODULE definitions in the provided c file.
:param str c_file: path to c file to check
:return: List[(module_name, obj_module, enabled_define)]
"""
global pattern
if c_file is None:
# No c file to match the object file, ski... | [
"def",
"find_module_registrations",
"(",
"c_file",
")",
":",
"global",
"pattern",
"if",
"c_file",
"is",
"None",
":",
"# No c file to match the object file, skip",
"return",
"set",
"(",
")",
"with",
"io",
".",
"open",
"(",
"c_file",
",",
"encoding",
"=",
"'utf-8'... | Find any MP_REGISTER_MODULE definitions in the provided c file.
:param str c_file: path to c file to check
:return: List[(module_name, obj_module, enabled_define)] | [
"Find",
"any",
"MP_REGISTER_MODULE",
"definitions",
"in",
"the",
"provided",
"c",
"file",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/py/makemoduledefs.py#L41-L54 |
23,352 | micropython/micropython | py/makemoduledefs.py | generate_module_table_header | def generate_module_table_header(modules):
""" Generate header with module table entries for builtin modules.
:param List[(module_name, obj_module, enabled_define)] modules: module defs
:return: None
"""
# Print header file for all external modules.
mod_defs = []
print("// Automatically ge... | python | def generate_module_table_header(modules):
""" Generate header with module table entries for builtin modules.
:param List[(module_name, obj_module, enabled_define)] modules: module defs
:return: None
"""
# Print header file for all external modules.
mod_defs = []
print("// Automatically ge... | [
"def",
"generate_module_table_header",
"(",
"modules",
")",
":",
"# Print header file for all external modules.",
"mod_defs",
"=",
"[",
"]",
"print",
"(",
"\"// Automatically generated by makemoduledefs.py.\\n\"",
")",
"for",
"module_name",
",",
"obj_module",
",",
"enabled_de... | Generate header with module table entries for builtin modules.
:param List[(module_name, obj_module, enabled_define)] modules: module defs
:return: None | [
"Generate",
"header",
"with",
"module",
"table",
"entries",
"for",
"builtin",
"modules",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/py/makemoduledefs.py#L57-L86 |
23,353 | micropython/micropython | tools/gen-cpydiff.py | readfiles | def readfiles():
""" Reads test files """
tests = list(filter(lambda x: x.endswith('.py'), os.listdir(TESTPATH)))
tests.sort()
files = []
for test in tests:
text = open(TESTPATH + test, 'r').read()
try:
class_, desc, cause, workaround, code = [x.rstrip() for x in \
... | python | def readfiles():
""" Reads test files """
tests = list(filter(lambda x: x.endswith('.py'), os.listdir(TESTPATH)))
tests.sort()
files = []
for test in tests:
text = open(TESTPATH + test, 'r').read()
try:
class_, desc, cause, workaround, code = [x.rstrip() for x in \
... | [
"def",
"readfiles",
"(",
")",
":",
"tests",
"=",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"x",
".",
"endswith",
"(",
"'.py'",
")",
",",
"os",
".",
"listdir",
"(",
"TESTPATH",
")",
")",
")",
"tests",
".",
"sort",
"(",
")",
"files",
"=",
"... | Reads test files | [
"Reads",
"test",
"files"
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/gen-cpydiff.py#L63-L80 |
23,354 | micropython/micropython | tools/gen-cpydiff.py | uimports | def uimports(code):
""" converts CPython module names into MicroPython equivalents """
for uimport in UIMPORTLIST:
uimport = bytes(uimport, 'utf8')
code = code.replace(uimport, b'u' + uimport)
return code | python | def uimports(code):
""" converts CPython module names into MicroPython equivalents """
for uimport in UIMPORTLIST:
uimport = bytes(uimport, 'utf8')
code = code.replace(uimport, b'u' + uimport)
return code | [
"def",
"uimports",
"(",
"code",
")",
":",
"for",
"uimport",
"in",
"UIMPORTLIST",
":",
"uimport",
"=",
"bytes",
"(",
"uimport",
",",
"'utf8'",
")",
"code",
"=",
"code",
".",
"replace",
"(",
"uimport",
",",
"b'u'",
"+",
"uimport",
")",
"return",
"code"
] | converts CPython module names into MicroPython equivalents | [
"converts",
"CPython",
"module",
"names",
"into",
"MicroPython",
"equivalents"
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/gen-cpydiff.py#L82-L87 |
23,355 | micropython/micropython | tools/gen-cpydiff.py | indent | def indent(block, spaces):
""" indents paragraphs of text for rst formatting """
new_block = ''
for line in block.split('\n'):
new_block += spaces + line + '\n'
return new_block | python | def indent(block, spaces):
""" indents paragraphs of text for rst formatting """
new_block = ''
for line in block.split('\n'):
new_block += spaces + line + '\n'
return new_block | [
"def",
"indent",
"(",
"block",
",",
"spaces",
")",
":",
"new_block",
"=",
"''",
"for",
"line",
"in",
"block",
".",
"split",
"(",
"'\\n'",
")",
":",
"new_block",
"+=",
"spaces",
"+",
"line",
"+",
"'\\n'",
"return",
"new_block"
] | indents paragraphs of text for rst formatting | [
"indents",
"paragraphs",
"of",
"text",
"for",
"rst",
"formatting"
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/gen-cpydiff.py#L116-L121 |
23,356 | micropython/micropython | tools/gen-cpydiff.py | gen_table | def gen_table(contents):
""" creates a table given any set of columns """
xlengths = []
ylengths = []
for column in contents:
col_len = 0
for entry in column:
lines = entry.split('\n')
for line in lines:
col_len = max(len(line) + 2, col_len)
... | python | def gen_table(contents):
""" creates a table given any set of columns """
xlengths = []
ylengths = []
for column in contents:
col_len = 0
for entry in column:
lines = entry.split('\n')
for line in lines:
col_len = max(len(line) + 2, col_len)
... | [
"def",
"gen_table",
"(",
"contents",
")",
":",
"xlengths",
"=",
"[",
"]",
"ylengths",
"=",
"[",
"]",
"for",
"column",
"in",
"contents",
":",
"col_len",
"=",
"0",
"for",
"entry",
"in",
"column",
":",
"lines",
"=",
"entry",
".",
"split",
"(",
"'\\n'",
... | creates a table given any set of columns | [
"creates",
"a",
"table",
"given",
"any",
"set",
"of",
"columns"
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/gen-cpydiff.py#L123-L154 |
23,357 | micropython/micropython | tools/pydfu.py | init | def init():
"""Initializes the found DFU device so that we can program it."""
global __dev, __cfg_descr
devices = get_dfu_devices(idVendor=__VID, idProduct=__PID)
if not devices:
raise ValueError('No DFU device found')
if len(devices) > 1:
raise ValueError("Multiple DFU devices found... | python | def init():
"""Initializes the found DFU device so that we can program it."""
global __dev, __cfg_descr
devices = get_dfu_devices(idVendor=__VID, idProduct=__PID)
if not devices:
raise ValueError('No DFU device found')
if len(devices) > 1:
raise ValueError("Multiple DFU devices found... | [
"def",
"init",
"(",
")",
":",
"global",
"__dev",
",",
"__cfg_descr",
"devices",
"=",
"get_dfu_devices",
"(",
"idVendor",
"=",
"__VID",
",",
"idProduct",
"=",
"__PID",
")",
"if",
"not",
"devices",
":",
"raise",
"ValueError",
"(",
"'No DFU device found'",
")",... | Initializes the found DFU device so that we can program it. | [
"Initializes",
"the",
"found",
"DFU",
"device",
"so",
"that",
"we",
"can",
"program",
"it",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L92-L126 |
23,358 | micropython/micropython | tools/pydfu.py | mass_erase | def mass_erase():
"""Performs a MASS erase (i.e. erases the entire device."""
# Send DNLOAD with first byte=0x41
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE,
"\x41", __TIMEOUT)
# Execute last command
if get_status() != __DFU_STATE_DFU_DOWNLOAD_BUSY:
ra... | python | def mass_erase():
"""Performs a MASS erase (i.e. erases the entire device."""
# Send DNLOAD with first byte=0x41
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE,
"\x41", __TIMEOUT)
# Execute last command
if get_status() != __DFU_STATE_DFU_DOWNLOAD_BUSY:
ra... | [
"def",
"mass_erase",
"(",
")",
":",
"# Send DNLOAD with first byte=0x41",
"__dev",
".",
"ctrl_transfer",
"(",
"0x21",
",",
"__DFU_DNLOAD",
",",
"0",
",",
"__DFU_INTERFACE",
",",
"\"\\x41\"",
",",
"__TIMEOUT",
")",
"# Execute last command",
"if",
"get_status",
"(",
... | Performs a MASS erase (i.e. erases the entire device. | [
"Performs",
"a",
"MASS",
"erase",
"(",
"i",
".",
"e",
".",
"erases",
"the",
"entire",
"device",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L148-L160 |
23,359 | micropython/micropython | tools/pydfu.py | page_erase | def page_erase(addr):
"""Erases a single page."""
if __verbose:
print("Erasing page: 0x%x..." % (addr))
# Send DNLOAD with first byte=0x41 and page address
buf = struct.pack("<BI", 0x41, addr)
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE, buf, __TIMEOUT)
# Execute last co... | python | def page_erase(addr):
"""Erases a single page."""
if __verbose:
print("Erasing page: 0x%x..." % (addr))
# Send DNLOAD with first byte=0x41 and page address
buf = struct.pack("<BI", 0x41, addr)
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE, buf, __TIMEOUT)
# Execute last co... | [
"def",
"page_erase",
"(",
"addr",
")",
":",
"if",
"__verbose",
":",
"print",
"(",
"\"Erasing page: 0x%x...\"",
"%",
"(",
"addr",
")",
")",
"# Send DNLOAD with first byte=0x41 and page address",
"buf",
"=",
"struct",
".",
"pack",
"(",
"\"<BI\"",
",",
"0x41",
",",... | Erases a single page. | [
"Erases",
"a",
"single",
"page",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L163-L179 |
23,360 | micropython/micropython | tools/pydfu.py | set_address | def set_address(addr):
"""Sets the address for the next operation."""
# Send DNLOAD with first byte=0x21 and page address
buf = struct.pack("<BI", 0x21, addr)
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE, buf, __TIMEOUT)
# Execute last command
if get_status() != __DFU_STATE_DFU_DO... | python | def set_address(addr):
"""Sets the address for the next operation."""
# Send DNLOAD with first byte=0x21 and page address
buf = struct.pack("<BI", 0x21, addr)
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE, buf, __TIMEOUT)
# Execute last command
if get_status() != __DFU_STATE_DFU_DO... | [
"def",
"set_address",
"(",
"addr",
")",
":",
"# Send DNLOAD with first byte=0x21 and page address",
"buf",
"=",
"struct",
".",
"pack",
"(",
"\"<BI\"",
",",
"0x21",
",",
"addr",
")",
"__dev",
".",
"ctrl_transfer",
"(",
"0x21",
",",
"__DFU_DNLOAD",
",",
"0",
","... | Sets the address for the next operation. | [
"Sets",
"the",
"address",
"for",
"the",
"next",
"operation",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L182-L194 |
23,361 | micropython/micropython | tools/pydfu.py | write_memory | def write_memory(addr, buf, progress=None, progress_addr=0, progress_size=0):
"""Writes a buffer into memory. This routine assumes that memory has
already been erased.
"""
xfer_count = 0
xfer_bytes = 0
xfer_total = len(buf)
xfer_base = addr
while xfer_bytes < xfer_total:
if __v... | python | def write_memory(addr, buf, progress=None, progress_addr=0, progress_size=0):
"""Writes a buffer into memory. This routine assumes that memory has
already been erased.
"""
xfer_count = 0
xfer_bytes = 0
xfer_total = len(buf)
xfer_base = addr
while xfer_bytes < xfer_total:
if __v... | [
"def",
"write_memory",
"(",
"addr",
",",
"buf",
",",
"progress",
"=",
"None",
",",
"progress_addr",
"=",
"0",
",",
"progress_size",
"=",
"0",
")",
":",
"xfer_count",
"=",
"0",
"xfer_bytes",
"=",
"0",
"xfer_total",
"=",
"len",
"(",
"buf",
")",
"xfer_bas... | Writes a buffer into memory. This routine assumes that memory has
already been erased. | [
"Writes",
"a",
"buffer",
"into",
"memory",
".",
"This",
"routine",
"assumes",
"that",
"memory",
"has",
"already",
"been",
"erased",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L197-L233 |
23,362 | micropython/micropython | tools/pydfu.py | write_page | def write_page(buf, xfer_offset):
"""Writes a single page. This routine assumes that memory has already
been erased.
"""
xfer_base = 0x08000000
# Set mem write address
set_address(xfer_base+xfer_offset)
# Send DNLOAD with fw data
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 2, __DFU_INTERF... | python | def write_page(buf, xfer_offset):
"""Writes a single page. This routine assumes that memory has already
been erased.
"""
xfer_base = 0x08000000
# Set mem write address
set_address(xfer_base+xfer_offset)
# Send DNLOAD with fw data
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 2, __DFU_INTERF... | [
"def",
"write_page",
"(",
"buf",
",",
"xfer_offset",
")",
":",
"xfer_base",
"=",
"0x08000000",
"# Set mem write address",
"set_address",
"(",
"xfer_base",
"+",
"xfer_offset",
")",
"# Send DNLOAD with fw data",
"__dev",
".",
"ctrl_transfer",
"(",
"0x21",
",",
"__DFU_... | Writes a single page. This routine assumes that memory has already
been erased. | [
"Writes",
"a",
"single",
"page",
".",
"This",
"routine",
"assumes",
"that",
"memory",
"has",
"already",
"been",
"erased",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L236-L258 |
23,363 | micropython/micropython | tools/pydfu.py | exit_dfu | def exit_dfu():
"""Exit DFU mode, and start running the program."""
# set jump address
set_address(0x08000000)
# Send DNLOAD with 0 length to exit DFU
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE,
None, __TIMEOUT)
try:
# Execute last command
... | python | def exit_dfu():
"""Exit DFU mode, and start running the program."""
# set jump address
set_address(0x08000000)
# Send DNLOAD with 0 length to exit DFU
__dev.ctrl_transfer(0x21, __DFU_DNLOAD, 0, __DFU_INTERFACE,
None, __TIMEOUT)
try:
# Execute last command
... | [
"def",
"exit_dfu",
"(",
")",
":",
"# set jump address",
"set_address",
"(",
"0x08000000",
")",
"# Send DNLOAD with 0 length to exit DFU",
"__dev",
".",
"ctrl_transfer",
"(",
"0x21",
",",
"__DFU_DNLOAD",
",",
"0",
",",
"__DFU_INTERFACE",
",",
"None",
",",
"__TIMEOUT"... | Exit DFU mode, and start running the program. | [
"Exit",
"DFU",
"mode",
"and",
"start",
"running",
"the",
"program",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L261-L279 |
23,364 | micropython/micropython | tools/pydfu.py | consume | def consume(fmt, data, names):
"""Parses the struct defined by `fmt` from `data`, stores the parsed fields
into a named tuple using `names`. Returns the named tuple, and the data
with the struct stripped off."""
size = struct.calcsize(fmt)
return named(struct.unpack(fmt, data[:size]), names), data[s... | python | def consume(fmt, data, names):
"""Parses the struct defined by `fmt` from `data`, stores the parsed fields
into a named tuple using `names`. Returns the named tuple, and the data
with the struct stripped off."""
size = struct.calcsize(fmt)
return named(struct.unpack(fmt, data[:size]), names), data[s... | [
"def",
"consume",
"(",
"fmt",
",",
"data",
",",
"names",
")",
":",
"size",
"=",
"struct",
".",
"calcsize",
"(",
"fmt",
")",
"return",
"named",
"(",
"struct",
".",
"unpack",
"(",
"fmt",
",",
"data",
"[",
":",
"size",
"]",
")",
",",
"names",
")",
... | Parses the struct defined by `fmt` from `data`, stores the parsed fields
into a named tuple using `names`. Returns the named tuple, and the data
with the struct stripped off. | [
"Parses",
"the",
"struct",
"defined",
"by",
"fmt",
"from",
"data",
"stores",
"the",
"parsed",
"fields",
"into",
"a",
"named",
"tuple",
"using",
"names",
".",
"Returns",
"the",
"named",
"tuple",
"and",
"the",
"data",
"with",
"the",
"struct",
"stripped",
"of... | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L287-L292 |
23,365 | micropython/micropython | tools/pydfu.py | list_dfu_devices | def list_dfu_devices(*args, **kwargs):
"""Prints a lits of devices detected in DFU mode."""
devices = get_dfu_devices(*args, **kwargs)
if not devices:
print("No DFU capable devices found")
return
for device in devices:
print("Bus {} Device {:03d}: ID {:04x}:{:04x}"
... | python | def list_dfu_devices(*args, **kwargs):
"""Prints a lits of devices detected in DFU mode."""
devices = get_dfu_devices(*args, **kwargs)
if not devices:
print("No DFU capable devices found")
return
for device in devices:
print("Bus {} Device {:03d}: ID {:04x}:{:04x}"
... | [
"def",
"list_dfu_devices",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"devices",
"=",
"get_dfu_devices",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"not",
"devices",
":",
"print",
"(",
"\"No DFU capable devices found\"",
")",
"return",... | Prints a lits of devices detected in DFU mode. | [
"Prints",
"a",
"lits",
"of",
"devices",
"detected",
"in",
"DFU",
"mode",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L458-L473 |
23,366 | micropython/micropython | tools/pydfu.py | write_elements | def write_elements(elements, mass_erase_used, progress=None):
"""Writes the indicated elements into the target memory,
erasing as needed.
"""
mem_layout = get_memory_layout(__dev)
for elem in elements:
addr = elem['addr']
size = elem['size']
data = elem['data']
elem_... | python | def write_elements(elements, mass_erase_used, progress=None):
"""Writes the indicated elements into the target memory,
erasing as needed.
"""
mem_layout = get_memory_layout(__dev)
for elem in elements:
addr = elem['addr']
size = elem['size']
data = elem['data']
elem_... | [
"def",
"write_elements",
"(",
"elements",
",",
"mass_erase_used",
",",
"progress",
"=",
"None",
")",
":",
"mem_layout",
"=",
"get_memory_layout",
"(",
"__dev",
")",
"for",
"elem",
"in",
"elements",
":",
"addr",
"=",
"elem",
"[",
"'addr'",
"]",
"size",
"=",... | Writes the indicated elements into the target memory,
erasing as needed. | [
"Writes",
"the",
"indicated",
"elements",
"into",
"the",
"target",
"memory",
"erasing",
"as",
"needed",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L476-L510 |
23,367 | micropython/micropython | tools/pydfu.py | cli_progress | def cli_progress(addr, offset, size):
"""Prints a progress report suitable for use on the command line."""
width = 25
done = offset * width // size
print("\r0x{:08x} {:7d} [{}{}] {:3d}% "
.format(addr, size, '=' * done, ' ' * (width - done),
offset * 100 // size), end="")
... | python | def cli_progress(addr, offset, size):
"""Prints a progress report suitable for use on the command line."""
width = 25
done = offset * width // size
print("\r0x{:08x} {:7d} [{}{}] {:3d}% "
.format(addr, size, '=' * done, ' ' * (width - done),
offset * 100 // size), end="")
... | [
"def",
"cli_progress",
"(",
"addr",
",",
"offset",
",",
"size",
")",
":",
"width",
"=",
"25",
"done",
"=",
"offset",
"*",
"width",
"//",
"size",
"print",
"(",
"\"\\r0x{:08x} {:7d} [{}{}] {:3d}% \"",
".",
"format",
"(",
"addr",
",",
"size",
",",
"'='",
"*... | Prints a progress report suitable for use on the command line. | [
"Prints",
"a",
"progress",
"report",
"suitable",
"for",
"use",
"on",
"the",
"command",
"line",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L513-L525 |
23,368 | micropython/micropython | tools/pydfu.py | main | def main():
"""Test program for verifying this files functionality."""
global __verbose
# Parse CMD args
parser = argparse.ArgumentParser(description='DFU Python Util')
#parser.add_argument("path", help="file path")
parser.add_argument(
"-l", "--list",
help="list available DFU de... | python | def main():
"""Test program for verifying this files functionality."""
global __verbose
# Parse CMD args
parser = argparse.ArgumentParser(description='DFU Python Util')
#parser.add_argument("path", help="file path")
parser.add_argument(
"-l", "--list",
help="list available DFU de... | [
"def",
"main",
"(",
")",
":",
"global",
"__verbose",
"# Parse CMD args",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'DFU Python Util'",
")",
"#parser.add_argument(\"path\", help=\"file path\")",
"parser",
".",
"add_argument",
"(",
"\"-l\... | Test program for verifying this files functionality. | [
"Test",
"program",
"for",
"verifying",
"this",
"files",
"functionality",
"."
] | 8031b7a25c21fb864fe9dd1fa40740030be66c11 | https://github.com/micropython/micropython/blob/8031b7a25c21fb864fe9dd1fa40740030be66c11/tools/pydfu.py#L528-L583 |
23,369 | onnx/onnx | onnx/external_data_helper.py | load_external_data_for_tensor | def load_external_data_for_tensor(tensor, base_dir): # type: (TensorProto, Text) -> None
"""
Load data from an external file for tensor.
@params
tensor: a TensorProto object.
base_dir: directory that contains the external data.
"""
if tensor.HasField("raw_data"): # already loaded
... | python | def load_external_data_for_tensor(tensor, base_dir): # type: (TensorProto, Text) -> None
"""
Load data from an external file for tensor.
@params
tensor: a TensorProto object.
base_dir: directory that contains the external data.
"""
if tensor.HasField("raw_data"): # already loaded
... | [
"def",
"load_external_data_for_tensor",
"(",
"tensor",
",",
"base_dir",
")",
":",
"# type: (TensorProto, Text) -> None",
"if",
"tensor",
".",
"HasField",
"(",
"\"raw_data\"",
")",
":",
"# already loaded",
"return",
"info",
"=",
"ExternalDataInfo",
"(",
"tensor",
")",
... | Load data from an external file for tensor.
@params
tensor: a TensorProto object.
base_dir: directory that contains the external data. | [
"Load",
"data",
"from",
"an",
"external",
"file",
"for",
"tensor",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L32-L54 |
23,370 | onnx/onnx | onnx/external_data_helper.py | load_external_data_for_model | def load_external_data_for_model(model, base_dir): # type: (ModelProto, Text) -> None
"""
Loads external tensors into model
@params
model: ModelProto to load external data to
base_dir: directory that contains external data
"""
for tensor in _get_all_tensors(model):
if uses_external... | python | def load_external_data_for_model(model, base_dir): # type: (ModelProto, Text) -> None
"""
Loads external tensors into model
@params
model: ModelProto to load external data to
base_dir: directory that contains external data
"""
for tensor in _get_all_tensors(model):
if uses_external... | [
"def",
"load_external_data_for_model",
"(",
"model",
",",
"base_dir",
")",
":",
"# type: (ModelProto, Text) -> None",
"for",
"tensor",
"in",
"_get_all_tensors",
"(",
"model",
")",
":",
"if",
"uses_external_data",
"(",
"tensor",
")",
":",
"load_external_data_for_tensor",... | Loads external tensors into model
@params
model: ModelProto to load external data to
base_dir: directory that contains external data | [
"Loads",
"external",
"tensors",
"into",
"model"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L57-L67 |
23,371 | onnx/onnx | onnx/external_data_helper.py | convert_model_to_external_data | def convert_model_to_external_data(model, all_tensors_to_one_file=True, location=None):
# type: (ModelProto, bool, Optional[Text]) -> None
"""
call to set all tensors as external data. save_model saves all the tensors data as external data after calling this function.
@params
model: ModelProto to be... | python | def convert_model_to_external_data(model, all_tensors_to_one_file=True, location=None):
# type: (ModelProto, bool, Optional[Text]) -> None
"""
call to set all tensors as external data. save_model saves all the tensors data as external data after calling this function.
@params
model: ModelProto to be... | [
"def",
"convert_model_to_external_data",
"(",
"model",
",",
"all_tensors_to_one_file",
"=",
"True",
",",
"location",
"=",
"None",
")",
":",
"# type: (ModelProto, bool, Optional[Text]) -> None",
"if",
"all_tensors_to_one_file",
":",
"file_name",
"=",
"Text",
"(",
"uuid",
... | call to set all tensors as external data. save_model saves all the tensors data as external data after calling this function.
@params
model: ModelProto to be converted.
all_tensors_to_one_file: If true, save all tensors to one external file specified by location.
If false, save ... | [
"call",
"to",
"set",
"all",
"tensors",
"as",
"external",
"data",
".",
"save_model",
"saves",
"all",
"the",
"tensors",
"data",
"as",
"external",
"data",
"after",
"calling",
"this",
"function",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L92-L111 |
23,372 | onnx/onnx | onnx/external_data_helper.py | convert_model_from_external_data | def convert_model_from_external_data(model): # type: (ModelProto) -> None
"""
call to set all tensors data as embedded data. save_model saves all the tensors data as embedded data after calling this function.
@params
model: ModelProto to be converted.
"""
for tensor in _get_all_tensors(model):
... | python | def convert_model_from_external_data(model): # type: (ModelProto) -> None
"""
call to set all tensors data as embedded data. save_model saves all the tensors data as embedded data after calling this function.
@params
model: ModelProto to be converted.
"""
for tensor in _get_all_tensors(model):
... | [
"def",
"convert_model_from_external_data",
"(",
"model",
")",
":",
"# type: (ModelProto) -> None",
"for",
"tensor",
"in",
"_get_all_tensors",
"(",
"model",
")",
":",
"if",
"uses_external_data",
"(",
"tensor",
")",
":",
"if",
"not",
"tensor",
".",
"HasField",
"(",
... | call to set all tensors data as embedded data. save_model saves all the tensors data as embedded data after calling this function.
@params
model: ModelProto to be converted. | [
"call",
"to",
"set",
"all",
"tensors",
"data",
"as",
"embedded",
"data",
".",
"save_model",
"saves",
"all",
"the",
"tensors",
"data",
"as",
"embedded",
"data",
"after",
"calling",
"this",
"function",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L114-L125 |
23,373 | onnx/onnx | onnx/external_data_helper.py | save_external_data | def save_external_data(tensor, base_path): # type: (TensorProto, Text) -> None
"""
Write tensor data to an external file according to information in the `external_data` field.
@params
tensor: Tensor object to be serialized
base_path: System path of a folder where tensor data is to be stored
""... | python | def save_external_data(tensor, base_path): # type: (TensorProto, Text) -> None
"""
Write tensor data to an external file according to information in the `external_data` field.
@params
tensor: Tensor object to be serialized
base_path: System path of a folder where tensor data is to be stored
""... | [
"def",
"save_external_data",
"(",
"tensor",
",",
"base_path",
")",
":",
"# type: (TensorProto, Text) -> None",
"info",
"=",
"ExternalDataInfo",
"(",
"tensor",
")",
"external_data_file_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base_path",
",",
"info",
".",
... | Write tensor data to an external file according to information in the `external_data` field.
@params
tensor: Tensor object to be serialized
base_path: System path of a folder where tensor data is to be stored | [
"Write",
"tensor",
"data",
"to",
"an",
"external",
"file",
"according",
"to",
"information",
"in",
"the",
"external_data",
"field",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L128-L159 |
23,374 | onnx/onnx | onnx/external_data_helper.py | _get_attribute_tensors | def _get_attribute_tensors(onnx_model_proto): # type: (ModelProto) -> Iterable[TensorProto]
"""Create an iterator of tensors from node attributes of an ONNX model."""
for node in onnx_model_proto.graph.node:
for attribute in node.attribute:
if attribute.HasField("t"):
yield ... | python | def _get_attribute_tensors(onnx_model_proto): # type: (ModelProto) -> Iterable[TensorProto]
"""Create an iterator of tensors from node attributes of an ONNX model."""
for node in onnx_model_proto.graph.node:
for attribute in node.attribute:
if attribute.HasField("t"):
yield ... | [
"def",
"_get_attribute_tensors",
"(",
"onnx_model_proto",
")",
":",
"# type: (ModelProto) -> Iterable[TensorProto]",
"for",
"node",
"in",
"onnx_model_proto",
".",
"graph",
".",
"node",
":",
"for",
"attribute",
"in",
"node",
".",
"attribute",
":",
"if",
"attribute",
... | Create an iterator of tensors from node attributes of an ONNX model. | [
"Create",
"an",
"iterator",
"of",
"tensors",
"from",
"node",
"attributes",
"of",
"an",
"ONNX",
"model",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L174-L181 |
23,375 | onnx/onnx | onnx/external_data_helper.py | remove_external_data_field | def remove_external_data_field(tensor, field_key): # type: (TensorProto, Text) -> None
"""
Remove a field from a Tensor's external_data key-value store.
Modifies tensor object in place.
@params
tensor: Tensor object from which value will be removed
field_key: The key of the field to be remove... | python | def remove_external_data_field(tensor, field_key): # type: (TensorProto, Text) -> None
"""
Remove a field from a Tensor's external_data key-value store.
Modifies tensor object in place.
@params
tensor: Tensor object from which value will be removed
field_key: The key of the field to be remove... | [
"def",
"remove_external_data_field",
"(",
"tensor",
",",
"field_key",
")",
":",
"# type: (TensorProto, Text) -> None",
"for",
"(",
"i",
",",
"field",
")",
"in",
"enumerate",
"(",
"tensor",
".",
"external_data",
")",
":",
"if",
"field",
".",
"key",
"==",
"field... | Remove a field from a Tensor's external_data key-value store.
Modifies tensor object in place.
@params
tensor: Tensor object from which value will be removed
field_key: The key of the field to be removed | [
"Remove",
"a",
"field",
"from",
"a",
"Tensor",
"s",
"external_data",
"key",
"-",
"value",
"store",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L197-L209 |
23,376 | onnx/onnx | onnx/external_data_helper.py | write_external_data_tensors | def write_external_data_tensors(model, filepath): # type: (ModelProto, Text) -> ModelProto
"""
Write external data of all tensors to files on disk.
Note: This function also strips basepath information from all tensors' external_data fields.
@params
model: Model object which is the source of tenso... | python | def write_external_data_tensors(model, filepath): # type: (ModelProto, Text) -> ModelProto
"""
Write external data of all tensors to files on disk.
Note: This function also strips basepath information from all tensors' external_data fields.
@params
model: Model object which is the source of tenso... | [
"def",
"write_external_data_tensors",
"(",
"model",
",",
"filepath",
")",
":",
"# type: (ModelProto, Text) -> ModelProto",
"for",
"tensor",
"in",
"_get_all_tensors",
"(",
"model",
")",
":",
"if",
"uses_external_data",
"(",
"tensor",
")",
":",
"save_external_data",
"("... | Write external data of all tensors to files on disk.
Note: This function also strips basepath information from all tensors' external_data fields.
@params
model: Model object which is the source of tensors to serialize.
filepath: System path to the directory which should be treated as base path for ext... | [
"Write",
"external",
"data",
"of",
"all",
"tensors",
"to",
"files",
"on",
"disk",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/external_data_helper.py#L212-L230 |
23,377 | onnx/onnx | tools/protoc-gen-mypy.py | PkgWriter._import_message | def _import_message(self, type_name):
# type: (d.FieldDescriptorProto) -> Text
"""Import a referenced message and return a handle"""
name = cast(Text, type_name)
if name[0] == '.' and name[1].isupper() and name[2].islower():
# Message defined in this file
return ... | python | def _import_message(self, type_name):
# type: (d.FieldDescriptorProto) -> Text
"""Import a referenced message and return a handle"""
name = cast(Text, type_name)
if name[0] == '.' and name[1].isupper() and name[2].islower():
# Message defined in this file
return ... | [
"def",
"_import_message",
"(",
"self",
",",
"type_name",
")",
":",
"# type: (d.FieldDescriptorProto) -> Text",
"name",
"=",
"cast",
"(",
"Text",
",",
"type_name",
")",
"if",
"name",
"[",
"0",
"]",
"==",
"'.'",
"and",
"name",
"[",
"1",
"]",
".",
"isupper",
... | Import a referenced message and return a handle | [
"Import",
"a",
"referenced",
"message",
"and",
"return",
"a",
"handle"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/tools/protoc-gen-mypy.py#L83-L112 |
23,378 | onnx/onnx | onnx/helper.py | make_node | def make_node(
op_type, # type: Text
inputs, # type: Sequence[Text]
outputs, # type: Sequence[Text]
name=None, # type: Optional[Text]
doc_string=None, # type: Optional[Text]
domain=None, # type: Optional[Text]
**kwargs # type: Any
): # type: (...) -> NodeP... | python | def make_node(
op_type, # type: Text
inputs, # type: Sequence[Text]
outputs, # type: Sequence[Text]
name=None, # type: Optional[Text]
doc_string=None, # type: Optional[Text]
domain=None, # type: Optional[Text]
**kwargs # type: Any
): # type: (...) -> NodeP... | [
"def",
"make_node",
"(",
"op_type",
",",
"# type: Text",
"inputs",
",",
"# type: Sequence[Text]",
"outputs",
",",
"# type: Sequence[Text]",
"name",
"=",
"None",
",",
"# type: Optional[Text]",
"doc_string",
"=",
"None",
",",
"# type: Optional[Text]",
"domain",
"=",
"No... | Construct a NodeProto.
Arguments:
op_type (string): The name of the operator to construct
inputs (list of string): list of input names
outputs (list of string): list of output names
name (string, default None): optional unique identifier for NodeProto
doc_string (string, def... | [
"Construct",
"a",
"NodeProto",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L20-L57 |
23,379 | onnx/onnx | onnx/helper.py | make_operatorsetid | def make_operatorsetid(
domain, # type: Text
version, # type: int
): # type: (...) -> OperatorSetIdProto
"""Construct an OperatorSetIdProto.
Arguments:
domain (string): The domain of the operator set id
version (integer): Version of operator set id
"""
operatorsetid =... | python | def make_operatorsetid(
domain, # type: Text
version, # type: int
): # type: (...) -> OperatorSetIdProto
"""Construct an OperatorSetIdProto.
Arguments:
domain (string): The domain of the operator set id
version (integer): Version of operator set id
"""
operatorsetid =... | [
"def",
"make_operatorsetid",
"(",
"domain",
",",
"# type: Text",
"version",
",",
"# type: int",
")",
":",
"# type: (...) -> OperatorSetIdProto",
"operatorsetid",
"=",
"OperatorSetIdProto",
"(",
")",
"operatorsetid",
".",
"domain",
"=",
"domain",
"operatorsetid",
".",
... | Construct an OperatorSetIdProto.
Arguments:
domain (string): The domain of the operator set id
version (integer): Version of operator set id | [
"Construct",
"an",
"OperatorSetIdProto",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L60-L73 |
23,380 | onnx/onnx | onnx/helper.py | _to_bytes_or_false | def _to_bytes_or_false(val): # type: (Union[Text, bytes]) -> Union[bytes, bool]
"""An internal graph to convert the input to a bytes or to False.
The criteria for conversion is as follows and should be python 2 and 3
compatible:
- If val is py2 str or py3 bytes: return bytes
- If val is py2 unicod... | python | def _to_bytes_or_false(val): # type: (Union[Text, bytes]) -> Union[bytes, bool]
"""An internal graph to convert the input to a bytes or to False.
The criteria for conversion is as follows and should be python 2 and 3
compatible:
- If val is py2 str or py3 bytes: return bytes
- If val is py2 unicod... | [
"def",
"_to_bytes_or_false",
"(",
"val",
")",
":",
"# type: (Union[Text, bytes]) -> Union[bytes, bool]",
"if",
"isinstance",
"(",
"val",
",",
"bytes",
")",
":",
"return",
"val",
"else",
":",
"try",
":",
"return",
"val",
".",
"encode",
"(",
"'utf-8'",
")",
"exc... | An internal graph to convert the input to a bytes or to False.
The criteria for conversion is as follows and should be python 2 and 3
compatible:
- If val is py2 str or py3 bytes: return bytes
- If val is py2 unicode or py3 str: return val.decode('utf-8')
- Otherwise, return False | [
"An",
"internal",
"graph",
"to",
"convert",
"the",
"input",
"to",
"a",
"bytes",
"or",
"to",
"False",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L179-L194 |
23,381 | onnx/onnx | onnx/helper.py | make_attribute | def make_attribute(
key, # type: Text
value, # type: Any
doc_string=None # type: Optional[Text]
): # type: (...) -> AttributeProto
"""Makes an AttributeProto based on the value type."""
attr = AttributeProto()
attr.name = key
if doc_string:
attr.doc_string = doc_strin... | python | def make_attribute(
key, # type: Text
value, # type: Any
doc_string=None # type: Optional[Text]
): # type: (...) -> AttributeProto
"""Makes an AttributeProto based on the value type."""
attr = AttributeProto()
attr.name = key
if doc_string:
attr.doc_string = doc_strin... | [
"def",
"make_attribute",
"(",
"key",
",",
"# type: Text",
"value",
",",
"# type: Any",
"doc_string",
"=",
"None",
"# type: Optional[Text]",
")",
":",
"# type: (...) -> AttributeProto",
"attr",
"=",
"AttributeProto",
"(",
")",
"attr",
".",
"name",
"=",
"key",
"if",... | Makes an AttributeProto based on the value type. | [
"Makes",
"an",
"AttributeProto",
"based",
"on",
"the",
"value",
"type",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L197-L256 |
23,382 | onnx/onnx | onnx/helper.py | make_tensor_value_info | def make_tensor_value_info(
name, # type: Text
elem_type, # type: int
shape, # type: Optional[Sequence[Union[Text, int]]]
doc_string="", # type: Text
shape_denotation=None, # type: Optional[List[Text]]
): # type: (...) -> ValueInfoProto
"""Makes a ValueInfoProto based o... | python | def make_tensor_value_info(
name, # type: Text
elem_type, # type: int
shape, # type: Optional[Sequence[Union[Text, int]]]
doc_string="", # type: Text
shape_denotation=None, # type: Optional[List[Text]]
): # type: (...) -> ValueInfoProto
"""Makes a ValueInfoProto based o... | [
"def",
"make_tensor_value_info",
"(",
"name",
",",
"# type: Text",
"elem_type",
",",
"# type: int",
"shape",
",",
"# type: Optional[Sequence[Union[Text, int]]]",
"doc_string",
"=",
"\"\"",
",",
"# type: Text",
"shape_denotation",
"=",
"None",
",",
"# type: Optional[List[Tex... | Makes a ValueInfoProto based on the data type and shape. | [
"Makes",
"a",
"ValueInfoProto",
"based",
"on",
"the",
"data",
"type",
"and",
"shape",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L290-L340 |
23,383 | onnx/onnx | onnx/helper.py | strip_doc_string | def strip_doc_string(proto): # type: (google.protobuf.message.Message) -> None
"""
Empties `doc_string` field on any nested protobuf messages
"""
assert isinstance(proto, google.protobuf.message.Message)
for descriptor in proto.DESCRIPTOR.fields:
if descriptor.name == 'doc_string':
... | python | def strip_doc_string(proto): # type: (google.protobuf.message.Message) -> None
"""
Empties `doc_string` field on any nested protobuf messages
"""
assert isinstance(proto, google.protobuf.message.Message)
for descriptor in proto.DESCRIPTOR.fields:
if descriptor.name == 'doc_string':
... | [
"def",
"strip_doc_string",
"(",
"proto",
")",
":",
"# type: (google.protobuf.message.Message) -> None",
"assert",
"isinstance",
"(",
"proto",
",",
"google",
".",
"protobuf",
".",
"message",
".",
"Message",
")",
"for",
"descriptor",
"in",
"proto",
".",
"DESCRIPTOR",
... | Empties `doc_string` field on any nested protobuf messages | [
"Empties",
"doc_string",
"field",
"on",
"any",
"nested",
"protobuf",
"messages"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/helper.py#L538-L551 |
23,384 | onnx/onnx | onnx/numpy_helper.py | to_array | def to_array(tensor): # type: (TensorProto) -> np.ndarray[Any]
"""Converts a tensor def object to a numpy array.
Inputs:
tensor: a TensorProto object.
Returns:
arr: the converted array.
"""
if tensor.HasField("segment"):
raise ValueError(
"Currently not supporti... | python | def to_array(tensor): # type: (TensorProto) -> np.ndarray[Any]
"""Converts a tensor def object to a numpy array.
Inputs:
tensor: a TensorProto object.
Returns:
arr: the converted array.
"""
if tensor.HasField("segment"):
raise ValueError(
"Currently not supporti... | [
"def",
"to_array",
"(",
"tensor",
")",
":",
"# type: (TensorProto) -> np.ndarray[Any]",
"if",
"tensor",
".",
"HasField",
"(",
"\"segment\"",
")",
":",
"raise",
"ValueError",
"(",
"\"Currently not supporting loading segments.\"",
")",
"if",
"tensor",
".",
"data_type",
... | Converts a tensor def object to a numpy array.
Inputs:
tensor: a TensorProto object.
Returns:
arr: the converted array. | [
"Converts",
"a",
"tensor",
"def",
"object",
"to",
"a",
"numpy",
"array",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/numpy_helper.py#L24-L66 |
23,385 | onnx/onnx | onnx/numpy_helper.py | from_array | def from_array(arr, name=None): # type: (np.ndarray[Any], Optional[Text]) -> TensorProto
"""Converts a numpy array to a tensor def.
Inputs:
arr: a numpy array.
name: (optional) the name of the tensor.
Returns:
tensor_def: the converted tensor def.
"""
tensor = TensorProto()... | python | def from_array(arr, name=None): # type: (np.ndarray[Any], Optional[Text]) -> TensorProto
"""Converts a numpy array to a tensor def.
Inputs:
arr: a numpy array.
name: (optional) the name of the tensor.
Returns:
tensor_def: the converted tensor def.
"""
tensor = TensorProto()... | [
"def",
"from_array",
"(",
"arr",
",",
"name",
"=",
"None",
")",
":",
"# type: (np.ndarray[Any], Optional[Text]) -> TensorProto",
"tensor",
"=",
"TensorProto",
"(",
")",
"tensor",
".",
"dims",
".",
"extend",
"(",
"arr",
".",
"shape",
")",
"if",
"name",
":",
"... | Converts a numpy array to a tensor def.
Inputs:
arr: a numpy array.
name: (optional) the name of the tensor.
Returns:
tensor_def: the converted tensor def. | [
"Converts",
"a",
"numpy",
"array",
"to",
"a",
"tensor",
"def",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/numpy_helper.py#L69-L117 |
23,386 | onnx/onnx | onnx/__init__.py | _serialize | def _serialize(proto): # type: (Union[bytes, google.protobuf.message.Message]) -> bytes
'''
Serialize a in-memory proto to bytes
@params
proto is a in-memory proto, such as a ModelProto, TensorProto, etc
@return
Serialized proto in bytes
'''
if isinstance(proto, bytes):
return... | python | def _serialize(proto): # type: (Union[bytes, google.protobuf.message.Message]) -> bytes
'''
Serialize a in-memory proto to bytes
@params
proto is a in-memory proto, such as a ModelProto, TensorProto, etc
@return
Serialized proto in bytes
'''
if isinstance(proto, bytes):
return... | [
"def",
"_serialize",
"(",
"proto",
")",
":",
"# type: (Union[bytes, google.protobuf.message.Message]) -> bytes",
"if",
"isinstance",
"(",
"proto",
",",
"bytes",
")",
":",
"return",
"proto",
"elif",
"hasattr",
"(",
"proto",
",",
"'SerializeToString'",
")",
"and",
"ca... | Serialize a in-memory proto to bytes
@params
proto is a in-memory proto, such as a ModelProto, TensorProto, etc
@return
Serialized proto in bytes | [
"Serialize",
"a",
"in",
"-",
"memory",
"proto",
"to",
"bytes"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/__init__.py#L53-L70 |
23,387 | onnx/onnx | onnx/__init__.py | _deserialize | def _deserialize(s, proto): # type: (bytes, _Proto) -> _Proto
'''
Parse bytes into a in-memory proto
@params
s is bytes containing serialized proto
proto is a in-memory proto object
@return
The proto instance filled in by s
'''
if not isinstance(s, bytes):
raise ValueError... | python | def _deserialize(s, proto): # type: (bytes, _Proto) -> _Proto
'''
Parse bytes into a in-memory proto
@params
s is bytes containing serialized proto
proto is a in-memory proto object
@return
The proto instance filled in by s
'''
if not isinstance(s, bytes):
raise ValueError... | [
"def",
"_deserialize",
"(",
"s",
",",
"proto",
")",
":",
"# type: (bytes, _Proto) -> _Proto",
"if",
"not",
"isinstance",
"(",
"s",
",",
"bytes",
")",
":",
"raise",
"ValueError",
"(",
"'Parameter s must be bytes, but got type: {}'",
".",
"format",
"(",
"type",
"(",... | Parse bytes into a in-memory proto
@params
s is bytes containing serialized proto
proto is a in-memory proto object
@return
The proto instance filled in by s | [
"Parse",
"bytes",
"into",
"a",
"in",
"-",
"memory",
"proto"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/__init__.py#L76-L99 |
23,388 | onnx/onnx | onnx/__init__.py | load_model | def load_model(f, format=None, load_external_data=True): # type: (Union[IO[bytes], Text], Optional[Any], bool) -> ModelProto
'''
Loads a serialized ModelProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@ret... | python | def load_model(f, format=None, load_external_data=True): # type: (Union[IO[bytes], Text], Optional[Any], bool) -> ModelProto
'''
Loads a serialized ModelProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@ret... | [
"def",
"load_model",
"(",
"f",
",",
"format",
"=",
"None",
",",
"load_external_data",
"=",
"True",
")",
":",
"# type: (Union[IO[bytes], Text], Optional[Any], bool) -> ModelProto",
"s",
"=",
"_load_bytes",
"(",
"f",
")",
"model",
"=",
"load_model_from_string",
"(",
"... | Loads a serialized ModelProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@return
Loaded in-memory ModelProto | [
"Loads",
"a",
"serialized",
"ModelProto",
"into",
"memory"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/__init__.py#L102-L122 |
23,389 | onnx/onnx | onnx/__init__.py | load_tensor | def load_tensor(f, format=None): # type: (Union[IO[bytes], Text], Optional[Any]) -> TensorProto
'''
Loads a serialized TensorProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@return
Loaded in-memory Ten... | python | def load_tensor(f, format=None): # type: (Union[IO[bytes], Text], Optional[Any]) -> TensorProto
'''
Loads a serialized TensorProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@return
Loaded in-memory Ten... | [
"def",
"load_tensor",
"(",
"f",
",",
"format",
"=",
"None",
")",
":",
"# type: (Union[IO[bytes], Text], Optional[Any]) -> TensorProto",
"s",
"=",
"_load_bytes",
"(",
"f",
")",
"return",
"load_tensor_from_string",
"(",
"s",
",",
"format",
"=",
"format",
")"
] | Loads a serialized TensorProto into memory
@params
f can be a file-like object (has "read" function) or a string containing a file name
format is for future use
@return
Loaded in-memory TensorProto | [
"Loads",
"a",
"serialized",
"TensorProto",
"into",
"memory"
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/__init__.py#L125-L137 |
23,390 | onnx/onnx | onnx/__init__.py | save_model | def save_model(proto, f, format=None): # type: (Union[ModelProto, bytes], Union[IO[bytes], Text], Optional[Any]) -> None
'''
Saves the ModelProto to the specified path.
@params
proto should be a in-memory ModelProto
f can be a file-like object (has "write" function) or a string containing a file n... | python | def save_model(proto, f, format=None): # type: (Union[ModelProto, bytes], Union[IO[bytes], Text], Optional[Any]) -> None
'''
Saves the ModelProto to the specified path.
@params
proto should be a in-memory ModelProto
f can be a file-like object (has "write" function) or a string containing a file n... | [
"def",
"save_model",
"(",
"proto",
",",
"f",
",",
"format",
"=",
"None",
")",
":",
"# type: (Union[ModelProto, bytes], Union[IO[bytes], Text], Optional[Any]) -> None",
"if",
"isinstance",
"(",
"proto",
",",
"bytes",
")",
":",
"proto",
"=",
"_deserialize",
"(",
"prot... | Saves the ModelProto to the specified path.
@params
proto should be a in-memory ModelProto
f can be a file-like object (has "write" function) or a string containing a file name
format is for future use | [
"Saves",
"the",
"ModelProto",
"to",
"the",
"specified",
"path",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/__init__.py#L168-L186 |
23,391 | onnx/onnx | onnx/utils.py | polish_model | def polish_model(model): # type: (ModelProto) -> ModelProto
'''
This function combines several useful utility functions together.
'''
onnx.checker.check_model(model)
onnx.helper.strip_doc_string(model)
model = onnx.shape_inference.infer_shapes(model)
model = onnx.optimizer.optimize(mode... | python | def polish_model(model): # type: (ModelProto) -> ModelProto
'''
This function combines several useful utility functions together.
'''
onnx.checker.check_model(model)
onnx.helper.strip_doc_string(model)
model = onnx.shape_inference.infer_shapes(model)
model = onnx.optimizer.optimize(mode... | [
"def",
"polish_model",
"(",
"model",
")",
":",
"# type: (ModelProto) -> ModelProto",
"onnx",
".",
"checker",
".",
"check_model",
"(",
"model",
")",
"onnx",
".",
"helper",
".",
"strip_doc_string",
"(",
"model",
")",
"model",
"=",
"onnx",
".",
"shape_inference",
... | This function combines several useful utility functions together. | [
"This",
"function",
"combines",
"several",
"useful",
"utility",
"functions",
"together",
"."
] | 2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4 | https://github.com/onnx/onnx/blob/2f7dc10f03a072526d94b6820cedbf2a1ec5a2c4/onnx/utils.py#L14-L23 |
23,392 | apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py | get_input_shape | def get_input_shape(sym, proto_obj):
"""Helper function to obtain the shape of an array"""
arg_params = proto_obj.arg_dict
aux_params = proto_obj.aux_dict
model_input_shape = [data[1] for data in proto_obj.model_metadata.get('input_tensor_data')]
data_names = [data[0] for data in proto_obj.model_... | python | def get_input_shape(sym, proto_obj):
"""Helper function to obtain the shape of an array"""
arg_params = proto_obj.arg_dict
aux_params = proto_obj.aux_dict
model_input_shape = [data[1] for data in proto_obj.model_metadata.get('input_tensor_data')]
data_names = [data[0] for data in proto_obj.model_... | [
"def",
"get_input_shape",
"(",
"sym",
",",
"proto_obj",
")",
":",
"arg_params",
"=",
"proto_obj",
".",
"arg_dict",
"aux_params",
"=",
"proto_obj",
".",
"aux_dict",
"model_input_shape",
"=",
"[",
"data",
"[",
"1",
"]",
"for",
"data",
"in",
"proto_obj",
".",
... | Helper function to obtain the shape of an array | [
"Helper",
"function",
"to",
"obtain",
"the",
"shape",
"of",
"an",
"array"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/_translation_utils.py#L216-L247 |
23,393 | apache/incubator-mxnet | python/mxnet/image/image.py | imresize | def imresize(src, w, h, *args, **kwargs):
r"""Resize image with OpenCV.
.. note:: `imresize` uses OpenCV (not the CV2 Python library). MXNet must have been built
with USE_OPENCV=1 for `imresize` to work.
Parameters
----------
src : NDArray
source image
w : int, required
... | python | def imresize(src, w, h, *args, **kwargs):
r"""Resize image with OpenCV.
.. note:: `imresize` uses OpenCV (not the CV2 Python library). MXNet must have been built
with USE_OPENCV=1 for `imresize` to work.
Parameters
----------
src : NDArray
source image
w : int, required
... | [
"def",
"imresize",
"(",
"src",
",",
"w",
",",
"h",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_internal",
".",
"_cvimresize",
"(",
"src",
",",
"w",
",",
"h",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | r"""Resize image with OpenCV.
.. note:: `imresize` uses OpenCV (not the CV2 Python library). MXNet must have been built
with USE_OPENCV=1 for `imresize` to work.
Parameters
----------
src : NDArray
source image
w : int, required
Width of resized image.
h : int, required
... | [
"r",
"Resize",
"image",
"with",
"OpenCV",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L86-L140 |
23,394 | apache/incubator-mxnet | python/mxnet/image/image.py | imdecode | def imdecode(buf, *args, **kwargs):
"""Decode an image to an NDArray.
.. note:: `imdecode` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.
Parameters
----------
buf : str/bytes/bytearray or numpy.ndarray
Binary image dat... | python | def imdecode(buf, *args, **kwargs):
"""Decode an image to an NDArray.
.. note:: `imdecode` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.
Parameters
----------
buf : str/bytes/bytearray or numpy.ndarray
Binary image dat... | [
"def",
"imdecode",
"(",
"buf",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"isinstance",
"(",
"buf",
",",
"nd",
".",
"NDArray",
")",
":",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"==",
"3",
"and",
"not",
"isinstance"... | Decode an image to an NDArray.
.. note:: `imdecode` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.
Parameters
----------
buf : str/bytes/bytearray or numpy.ndarray
Binary image data as string or numpy ndarray.
flag : in... | [
"Decode",
"an",
"image",
"to",
"an",
"NDArray",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L143-L198 |
23,395 | apache/incubator-mxnet | python/mxnet/image/image.py | scale_down | def scale_down(src_size, size):
"""Scales down crop size if it's larger than image size.
If width/height of the crop is larger than the width/height of the image,
sets the width/height to the width/height of the image.
Parameters
----------
src_size : tuple of int
Size of the image in ... | python | def scale_down(src_size, size):
"""Scales down crop size if it's larger than image size.
If width/height of the crop is larger than the width/height of the image,
sets the width/height to the width/height of the image.
Parameters
----------
src_size : tuple of int
Size of the image in ... | [
"def",
"scale_down",
"(",
"src_size",
",",
"size",
")",
":",
"w",
",",
"h",
"=",
"size",
"sw",
",",
"sh",
"=",
"src_size",
"if",
"sh",
"<",
"h",
":",
"w",
",",
"h",
"=",
"float",
"(",
"w",
"*",
"sh",
")",
"/",
"h",
",",
"sh",
"if",
"sw",
... | Scales down crop size if it's larger than image size.
If width/height of the crop is larger than the width/height of the image,
sets the width/height to the width/height of the image.
Parameters
----------
src_size : tuple of int
Size of the image in (width, height) format.
size : tupl... | [
"Scales",
"down",
"crop",
"size",
"if",
"it",
"s",
"larger",
"than",
"image",
"size",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L201-L233 |
23,396 | apache/incubator-mxnet | python/mxnet/image/image.py | copyMakeBorder | def copyMakeBorder(src, top, bot, left, right, *args, **kwargs):
"""Pad image border with OpenCV.
Parameters
----------
src : NDArray
source image
top : int, required
Top margin.
bot : int, required
Bottom margin.
left : int, required
Left margin.
right :... | python | def copyMakeBorder(src, top, bot, left, right, *args, **kwargs):
"""Pad image border with OpenCV.
Parameters
----------
src : NDArray
source image
top : int, required
Top margin.
bot : int, required
Bottom margin.
left : int, required
Left margin.
right :... | [
"def",
"copyMakeBorder",
"(",
"src",
",",
"top",
",",
"bot",
",",
"left",
",",
"right",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_internal",
".",
"_cvcopyMakeBorder",
"(",
"src",
",",
"top",
",",
"bot",
",",
"left",
",",
"rig... | Pad image border with OpenCV.
Parameters
----------
src : NDArray
source image
top : int, required
Top margin.
bot : int, required
Bottom margin.
left : int, required
Left margin.
right : int, required
Right margin.
type : int, optional, default='... | [
"Pad",
"image",
"border",
"with",
"OpenCV",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L236-L286 |
23,397 | apache/incubator-mxnet | python/mxnet/image/image.py | _get_interp_method | def _get_interp_method(interp, sizes=()):
"""Get the interpolation method for resize functions.
The major purpose of this function is to wrap a random interp method selection
and a auto-estimation method.
Parameters
----------
interp : int
interpolation method for all resizing operation... | python | def _get_interp_method(interp, sizes=()):
"""Get the interpolation method for resize functions.
The major purpose of this function is to wrap a random interp method selection
and a auto-estimation method.
Parameters
----------
interp : int
interpolation method for all resizing operation... | [
"def",
"_get_interp_method",
"(",
"interp",
",",
"sizes",
"=",
"(",
")",
")",
":",
"if",
"interp",
"==",
"9",
":",
"if",
"sizes",
":",
"assert",
"len",
"(",
"sizes",
")",
"==",
"4",
"oh",
",",
"ow",
",",
"nh",
",",
"nw",
"=",
"sizes",
"if",
"nh... | Get the interpolation method for resize functions.
The major purpose of this function is to wrap a random interp method selection
and a auto-estimation method.
Parameters
----------
interp : int
interpolation method for all resizing operations
Possible values:
0: Nearest Ne... | [
"Get",
"the",
"interpolation",
"method",
"for",
"resize",
"functions",
".",
"The",
"major",
"purpose",
"of",
"this",
"function",
"is",
"to",
"wrap",
"a",
"random",
"interp",
"method",
"selection",
"and",
"a",
"auto",
"-",
"estimation",
"method",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L289-L341 |
23,398 | apache/incubator-mxnet | python/mxnet/image/image.py | resize_short | def resize_short(src, size, interp=2):
"""Resizes shorter edge to size.
.. note:: `resize_short` uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for `resize_short` to work.
Resizes the original image by setting the shorter edge to size
and setting the longer edg... | python | def resize_short(src, size, interp=2):
"""Resizes shorter edge to size.
.. note:: `resize_short` uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for `resize_short` to work.
Resizes the original image by setting the shorter edge to size
and setting the longer edg... | [
"def",
"resize_short",
"(",
"src",
",",
"size",
",",
"interp",
"=",
"2",
")",
":",
"h",
",",
"w",
",",
"_",
"=",
"src",
".",
"shape",
"if",
"h",
">",
"w",
":",
"new_h",
",",
"new_w",
"=",
"size",
"*",
"h",
"//",
"w",
",",
"size",
"else",
":... | Resizes shorter edge to size.
.. note:: `resize_short` uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for `resize_short` to work.
Resizes the original image by setting the shorter edge to size
and setting the longer edge accordingly.
Resizing function is called... | [
"Resizes",
"shorter",
"edge",
"to",
"size",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L344-L403 |
23,399 | apache/incubator-mxnet | python/mxnet/image/image.py | center_crop | def center_crop(src, size, interp=2):
"""Crops the image `src` to the given `size` by trimming on all four
sides and preserving the center of the image. Upsamples if `src` is smaller
than `size`.
.. note:: This requires MXNet to be compiled with USE_OPENCV.
Parameters
----------
src : NDAr... | python | def center_crop(src, size, interp=2):
"""Crops the image `src` to the given `size` by trimming on all four
sides and preserving the center of the image. Upsamples if `src` is smaller
than `size`.
.. note:: This requires MXNet to be compiled with USE_OPENCV.
Parameters
----------
src : NDAr... | [
"def",
"center_crop",
"(",
"src",
",",
"size",
",",
"interp",
"=",
"2",
")",
":",
"h",
",",
"w",
",",
"_",
"=",
"src",
".",
"shape",
"new_w",
",",
"new_h",
"=",
"scale_down",
"(",
"(",
"w",
",",
"h",
")",
",",
"size",
")",
"x0",
"=",
"int",
... | Crops the image `src` to the given `size` by trimming on all four
sides and preserving the center of the image. Upsamples if `src` is smaller
than `size`.
.. note:: This requires MXNet to be compiled with USE_OPENCV.
Parameters
----------
src : NDArray
Binary source image data.
siz... | [
"Crops",
"the",
"image",
"src",
"to",
"the",
"given",
"size",
"by",
"trimming",
"on",
"all",
"four",
"sides",
"and",
"preserving",
"the",
"center",
"of",
"the",
"image",
".",
"Upsamples",
"if",
"src",
"is",
"smaller",
"than",
"size",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/image.py#L477-L523 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.