<s> """<STR_LIT>""" <EOL> import re <EOL> import uuid <EOL> from codalab . common import ( <EOL> precondition , <EOL> UsageError , <EOL> ) <EOL> DASHBOARD_WORKSHEET = '<STR_LIT>' <EOL> UUID_STR = '<STR_LIT>' <EOL> UUID_REGEX = re . compile ( '<STR_LIT>' + UUID_STR + '<STR_LIT:$>' ) <EOL> UUID_PREFIX_REGEX = re . compile ( '<STR_LIT>' ) <EOL> BEGIN_NAME_STR = '<STR_LIT>' <EOL> NAME_STR = '<STR_LIT>' <EOL> NAME_PATTERN_STR = '<STR_LIT>' <EOL> NAME_REGEX = re . compile ( '<STR_LIT>' + NAME_STR + '<STR_LIT:$>' ) <EOL> NAME_PATTERN_REGEX = re . compile ( '<STR_LIT>' + NAME_PATTERN_STR + '<STR_LIT>' ) <EOL> NAME_PATTERN_HISTORY_REGEX = re . compile ( '<STR_LIT>' + NAME_PATTERN_STR + '<STR_LIT>' ) <EOL> HISTORY_REGEX = re . compile ( '<STR_LIT>' ) <EOL> ID_REGEX = re . compile ( '<STR_LIT>' ) <EOL> NOT_NAME_CHAR_REGEX = re . compile ( '<STR_LIT>' ) <EOL> HISTORY_RANGE_REGEX = re . compile ( '<STR_LIT>' ) <EOL> BASIC_EMAIL_REGEX = re . compile ( r'<STR_LIT>' ) <EOL> def expand_specs ( specs ) : <EOL> """<STR_LIT>""" <EOL> new_specs = [ ] <EOL> for spec in specs : <EOL> m = HISTORY_RANGE_REGEX . match ( spec ) <EOL> if m : <EOL> a , b = int ( m . group ( <NUM_LIT:2> ) ) , int ( m . group ( <NUM_LIT:3> ) ) <EOL> for i in range ( a , b + <NUM_LIT:1> ) if a <= b else range ( a , b - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> new_specs . append ( m . group ( <NUM_LIT:1> ) + str ( i ) ) <EOL> else : <EOL> new_specs . append ( spec ) <EOL> return new_specs <EOL> def generate_uuid ( ) : <EOL> return '<STR_LIT>' % ( uuid . uuid4 ( ) . hex , ) <EOL> def check_uuid ( uuid_str ) : <EOL> """<STR_LIT>""" <EOL> message = '<STR_LIT>' % ( UUID_REGEX . pattern , uuid_str ) <EOL> precondition ( UUID_REGEX . match ( uuid_str ) , message ) <EOL> def check_name ( name ) : <EOL> if not NAME_REGEX . match ( name ) : <EOL> raise UsageError ( '<STR_LIT>' % ( NAME_REGEX . pattern , name ) ) <EOL> def check_id ( owner_id ) : <EOL> if owner_id is not None and type ( owner_id ) != int : <EOL> raise UsageError ( '<STR_LIT>' ) <EOL> def shorten_name ( name , n = <NUM_LIT:32> ) : <EOL> if len ( name ) <= <NUM_LIT:32> : <EOL> return name <EOL> else : <EOL> return name [ <NUM_LIT:0> : n / <NUM_LIT:2> - <NUM_LIT:1> ] + '<STR_LIT:..>' + name [ len ( name ) - n / <NUM_LIT:2> + <NUM_LIT:1> : ] <EOL> def create_default_name ( bundle_type , raw_material ) : <EOL> """<STR_LIT>""" <EOL> if bundle_type == '<STR_LIT>' : <EOL> raw_material = raw_material . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] <EOL> name = ( bundle_type + '<STR_LIT:->' if bundle_type else '<STR_LIT>' ) + NOT_NAME_CHAR_REGEX . sub ( '<STR_LIT:->' , raw_material ) <EOL> name = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT:->' , name ) <EOL> if not re . match ( BEGIN_NAME_STR , name ) : <EOL> name = '<STR_LIT:_>' + name <EOL> name = shorten_name ( name ) <EOL> return name <EOL> def client_is_explicit ( spec ) : <EOL> return '<STR_LIT>' in spec <EOL> def home_worksheet ( username ) : <EOL> return '<STR_LIT>' + username <EOL> def is_home_worksheet ( name ) : <EOL> return name . startswith ( '<STR_LIT>' ) <EOL> def is_dashboard ( name ) : <EOL> return name == DASHBOARD_WORKSHEET </s>
