<s> import platform <EOL> import re <EOL> from awscli . compat import urlopen , URLError <EOL> from awscli . customizations . codedeploy . systems import System , Ubuntu , Windows , RHEL <EOL> from socket import timeout <EOL> MAX_INSTANCE_NAME_LENGTH = <NUM_LIT:100> <EOL> MAX_TAGS_PER_INSTANCE = <NUM_LIT:10> <EOL> MAX_TAG_KEY_LENGTH = <NUM_LIT> <EOL> MAX_TAG_VALUE_LENGTH = <NUM_LIT> <EOL> INSTANCE_NAME_PATTERN = r'<STR_LIT>' <EOL> IAM_USER_ARN_PATTERN = r'<STR_LIT>' <EOL> INSTANCE_NAME_ARG = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> ) <EOL> } <EOL> IAM_USER_ARN_ARG = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> ) <EOL> } <EOL> def validate_region ( params , parsed_globals ) : <EOL> if parsed_globals . region : <EOL> params . region = parsed_globals . region <EOL> else : <EOL> params . region = params . session . get_config_variable ( '<STR_LIT>' ) <EOL> if not params . region : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def validate_instance_name ( params ) : <EOL> if params . instance_name : <EOL> if not re . match ( INSTANCE_NAME_PATTERN , params . instance_name ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if params . instance_name . startswith ( '<STR_LIT>' ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if len ( params . instance_name ) > MAX_INSTANCE_NAME_LENGTH : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( <EOL> MAX_INSTANCE_NAME_LENGTH <EOL> ) <EOL> ) <EOL> def validate_tags ( params ) : <EOL> if params . tags : <EOL> if len ( params . tags ) > MAX_TAGS_PER_INSTANCE : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( <EOL> MAX_TAGS_PER_INSTANCE <EOL> ) <EOL> ) <EOL> for tag in params . tags : <EOL> if len ( tag [ '<STR_LIT>' ] ) > MAX_TAG_KEY_LENGTH : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( <EOL> MAX_TAG_KEY_LENGTH <EOL> ) <EOL> ) <EOL> if len ( tag [ '<STR_LIT>' ] ) > MAX_TAG_KEY_LENGTH : <EOL> raise ValueError ( <EOL> '<STR_LIT>' . format ( <EOL> MAX_TAG_VALUE_LENGTH <EOL> ) <EOL> ) <EOL> def validate_iam_user_arn ( params ) : <EOL> if params . iam_user_arn and not re . match ( IAM_USER_ARN_PATTERN , params . iam_user_arn ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> def validate_instance ( params ) : <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> if '<STR_LIT>' in platform . linux_distribution ( ) [ <NUM_LIT:0> ] : <EOL> params . system = Ubuntu ( params ) <EOL> if '<STR_LIT>' in platform . linux_distribution ( ) [ <NUM_LIT:0> ] : <EOL> params . system = RHEL ( params ) <EOL> elif platform . system ( ) == '<STR_LIT>' : <EOL> params . system = Windows ( params ) <EOL> if '<STR_LIT>' not in params : <EOL> raise RuntimeError ( <EOL> System . UNSUPPORTED_SYSTEM_MSG <EOL> ) <EOL> try : <EOL> urlopen ( '<STR_LIT>' , timeout = <NUM_LIT:1> ) <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> except ( URLError , timeout ) : <EOL> pass <EOL> def validate_s3_location ( params , arg_name ) : <EOL> arg_name = arg_name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> if arg_name in params : <EOL> s3_location = getattr ( params , arg_name ) <EOL> if s3_location : <EOL> matcher = re . match ( '<STR_LIT>' , str ( s3_location ) ) <EOL> if matcher : <EOL> params . bucket = matcher . group ( <NUM_LIT:1> ) <EOL> params . key = matcher . group ( <NUM_LIT:2> ) <EOL> else : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> arg_name . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> ) <EOL> ) </s>
