<s> from collections import namedtuple <EOL> import re <EOL> from conans . errors import ConanException , InvalidNameException <EOL> from conans . model . version import Version <EOL> def validate_conan_name ( name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if name == '<STR_LIT:*>' and ConanFileReference . wildcard_is_allowed : <EOL> return name <EOL> if ConanFileReference . validation_pattern . match ( name ) is None : <EOL> if len ( name ) > ConanFileReference . max_chars : <EOL> message = "<STR_LIT>" "<STR_LIT>" % ( name , <EOL> ConanFileReference . max_chars ) <EOL> elif len ( name ) < ConanFileReference . min_chars : <EOL> message = "<STR_LIT>" "<STR_LIT>" % ( name , ConanFileReference . min_chars ) <EOL> else : <EOL> message = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( name , ConanFileReference . min_chars , <EOL> ConanFileReference . max_chars ) <EOL> raise InvalidNameException ( message ) <EOL> return name <EOL> except AttributeError : <EOL> raise InvalidNameException ( '<STR_LIT>' , None ) <EOL> class ConanFileReference ( namedtuple ( "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> """<STR_LIT>""" <EOL> max_chars = <NUM_LIT> <EOL> min_chars = <NUM_LIT:2> <EOL> base_er = "<STR_LIT>" % ( min_chars - <NUM_LIT:1> , max_chars ) <EOL> regular_expression = "<STR_LIT>" % base_er <EOL> validation_pattern = re . compile ( regular_expression ) <EOL> whitespace_pattern = re . compile ( r"<STR_LIT>" ) <EOL> sep_pattern = re . compile ( "<STR_LIT>" ) <EOL> wildcard_is_allowed = True <EOL> def __new__ ( cls , name , version , user , channel , validate = True ) : <EOL> """<STR_LIT>""" <EOL> if validate : <EOL> name = validate_conan_name ( name ) <EOL> version = validate_conan_name ( version ) <EOL> user = validate_conan_name ( user ) <EOL> channel = validate_conan_name ( channel ) <EOL> version = Version ( version ) <EOL> return super ( cls , ConanFileReference ) . __new__ ( cls , name , version , user , channel ) <EOL> @ staticmethod <EOL> def loads ( text , validate = True ) : <EOL> """<STR_LIT>""" <EOL> text = ConanFileReference . whitespace_pattern . sub ( "<STR_LIT>" , text ) <EOL> tokens = ConanFileReference . sep_pattern . split ( text ) <EOL> try : <EOL> name = tokens [ <NUM_LIT:0> ] <EOL> version = tokens [ <NUM_LIT:1> ] <EOL> user = tokens [ <NUM_LIT:2> ] <EOL> channel = tokens [ <NUM_LIT:3> ] <EOL> except IndexError : <EOL> raise ConanException ( "<STR_LIT>" <EOL> "<STR_LIT>" % text ) <EOL> return ConanFileReference ( name , version , user , channel , validate ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . name , self . version , self . user , self . channel ) <EOL> def package_ref ( self , conan_info ) : <EOL> package_id = conan_info . package_id ( self ) <EOL> return PackageReference ( self , package_id ) <EOL> class PackageReference ( namedtuple ( "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def loads ( text ) : <EOL> text = text . strip ( ) <EOL> tmp = text . split ( "<STR_LIT::>" ) <EOL> try : <EOL> conan = ConanFileReference . loads ( tmp [ <NUM_LIT:0> ] . strip ( ) ) <EOL> package_id = tmp [ <NUM_LIT:1> ] . strip ( ) <EOL> except IndexError : <EOL> raise ConanException ( "<STR_LIT>" % text ) <EOL> return PackageReference ( conan , package_id ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . conan , self . package_id ) </s>
