Hoist Literals

This transform replaces string and bytes literals with references to module level variables. It may also introduce new names for some builtin constants (True, False, None). This will only be done if multiple literals can be replaced with a single variable referenced in multiple locations (and the resulting code is smaller).

If the rename_globals transform is disabled, the newly introduced names have an underscore prefix.

This transform is always safe to use and enabled by default. Disable this source transformation by passing the hoist_literals=False argument to the python_minifier.minify() function, or passing --no-hoist-literals to the pyminify command.

Example

Input

def validate(arn, props):
    if 'ValidationMethod' in props and props['ValidationMethod'] == 'DNS':

        all_records_created = False
        while not all_records_created:
            all_records_created = True

            certificate = acm.describe_certificate(CertificateArn=arn)['Certificate']

            if certificate['Status'] != 'PENDING_VALIDATION':
                return

            for v in certificate['DomainValidationOptions']:

                if 'ValidationStatus' not in v or 'ResourceRecord' not in v:
                    all_records_created = False
                    continue

                records = []
                if v['ValidationStatus'] == 'PENDING_VALIDATION':
                    records.append({
                        'Action': 'UPSERT',
                        'ResourceRecordSet': {
                            'Name': v['ResourceRecord']['Name'],
                            'Type': v['ResourceRecord']['Type'],
                            'TTL': 60,
                            'ResourceRecords': [{
                                'Value': v['ResourceRecord']['Value']
                            }]
                        }
                    })

                if records:
                    response = boto3.client('route53').change_resource_record_sets(
                        HostedZoneId=get_zone_for(v['DomainName'], props),
                        ChangeBatch={
                            'Comment': 'Domain validation for %s' % arn,
                            'Changes': records
                        }
                    )

Output

def validate(arn,props):
	H='Value';G='Type';F='Name';E='ValidationStatus';D='PENDING_VALIDATION';C=False;B='ValidationMethod';A='ResourceRecord'
	if B in props and props[B]=='DNS':
		all_records_created=C
		while not all_records_created:
			all_records_created=True;certificate=acm.describe_certificate(CertificateArn=arn)['Certificate']
			if certificate['Status']!=D:return
			for v in certificate['DomainValidationOptions']:
				if E not in v or A not in v:all_records_created=C;continue
				records=[]
				if v[E]==D:records.append({'Action':'UPSERT','ResourceRecordSet':{F:v[A][F],G:v[A][G],'TTL':60,'ResourceRecords':[{H:v[A][H]}]}})
				if records:response=boto3.client('route53').change_resource_record_sets(HostedZoneId=get_zone_for(v['DomainName'],props),ChangeBatch={'Comment':'Domain validation for %s'%arn,'Changes':records})