<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> import logging <EOL> try : <EOL> import ldap <EOL> except ImportError : <EOL> ldap = None <EOL> from pyramid . settings import asbool <EOL> import cryptacular . bcrypt <EOL> import transaction <EOL> from pkg_resources import parse_version <EOL> from sqlalchemy import ( Table , Column , ForeignKey , Index , <EOL> Integer , Boolean , Unicode , UnicodeText , <EOL> DateTime , Enum ) <EOL> from sqlalchemy . orm import relationship , synonym , backref <EOL> from sqlalchemy . sql . expression import func , or_ , and_ <EOL> from sqlalchemy . ext . declarative import declared_attr <EOL> from pyshop . compat import unicode <EOL> from . helpers . sqla import ( Database , SessionFactory , ModelError , <EOL> create_engine as create_engine_base , <EOL> dispose_engine as dispose_engine_base <EOL> ) <EOL> log = logging . getLogger ( __file__ ) <EOL> crypt = cryptacular . bcrypt . BCRYPTPasswordManager ( ) <EOL> Base = Database . register ( '<STR_LIT>' ) <EOL> DBSession = lambda : SessionFactory . get ( '<STR_LIT>' ) ( ) <EOL> re_email = re . compile ( r'<STR_LIT>' , re . I ) <EOL> def _whlify ( filename ) : <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> pkg = filename [ : - <NUM_LIT:7> ] <EOL> elif filename . endswith ( '<STR_LIT>' ) : <EOL> pkg = filename [ : - <NUM_LIT:8> ] <EOL> elif filename . endswith ( '<STR_LIT>' ) : <EOL> pkg = filename [ : - <NUM_LIT:4> ] <EOL> else : <EOL> raise NotImplementedError ( '<STR_LIT>' % filename ) <EOL> return u'<STR_LIT>' '<STR_LIT>' . format ( pkg = pkg , <EOL> platform = '<STR_LIT>' , <EOL> pyvermax = sys . version_info [ <NUM_LIT:0> ] , <EOL> pyvermin = sys . version_info [ <NUM_LIT:1> ] , <EOL> ) <EOL> def create_engine ( settings , prefix = '<STR_LIT>' , scoped = False ) : <EOL> """<STR_LIT>""" <EOL> return create_engine_base ( '<STR_LIT>' , settings , prefix , scoped ) <EOL> def dispose_engine ( ) : <EOL> """<STR_LIT>""" <EOL> dispose_engine_base ( '<STR_LIT>' ) <EOL> class Permission ( Base ) : <EOL> """<STR_LIT>""" <EOL> name = Column ( Unicode ( <NUM_LIT:255> ) , nullable = False , unique = True ) <EOL> group__permission = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class Group ( Base ) : <EOL> """<STR_LIT>""" <EOL> name = Column ( Unicode ( <NUM_LIT:255> ) , nullable = False , unique = True ) <EOL> permissions = relationship ( Permission , secondary = group__permission , <EOL> lazy = '<STR_LIT>' ) <EOL> @ classmethod <EOL> def by_name ( cls , session , name ) : <EOL> """<STR_LIT>""" <EOL> return cls . first ( session , where = ( cls . name == name , ) ) <EOL> user__group = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class User ( Base ) : <EOL> """<STR_LIT>""" <EOL> @ declared_attr <EOL> def __table_args__ ( cls ) : <EOL> return ( Index ( '<STR_LIT>' % cls . __tablename__ , <EOL> '<STR_LIT>' , '<STR_LIT>' , unique = True ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> } <EOL> ) <EOL> login = Column ( Unicode ( <NUM_LIT:255> ) , nullable = False ) <EOL> _password = Column ( '<STR_LIT:password>' , Unicode ( <NUM_LIT> ) , nullable = True ) <EOL> firstname = Column ( Unicode ( <NUM_LIT:255> ) , nullable = True ) <EOL> lastname = Column ( Unicode ( <NUM_LIT:255> ) , nullable = True ) <EOL> email = Column ( Unicode ( <NUM_LIT:255> ) , nullable = True ) <EOL> groups = relationship ( Group , secondary = user__group , lazy = '<STR_LIT>' , <EOL> backref = '<STR_LIT>' ) <EOL> local = Column ( Boolean , nullable = False , default = True ) <EOL> @ property <EOL> def name ( self ) : <EOL> return u'<STR_LIT>' % ( self . firstname , self . lastname ) if self . firstname and self . lastname else self . login <EOL> def _get_password ( self ) : <EOL> return self . _password <EOL> def _set_password ( self , password ) : <EOL> self . _password = unicode ( crypt . encode ( password ) ) <EOL> password = property ( _get_password , _set_password ) <EOL> password = synonym ( '<STR_LIT>' , descriptor = password ) <EOL> @ property <EOL> def permissions ( self ) : <EOL> result = set ( ) <EOL> for group in self . groups : <EOL> result = result . union ( [ perm . name for perm in group . permissions ] ) <EOL> return list ( result ) <EOL> @ classmethod <EOL> def by_login ( cls , session , login , local = True ) : <EOL> """<STR_LIT>""" <EOL> user = cls . first ( session , <EOL> where = ( ( cls . login == login ) , <EOL> ( cls . local == local ) , ) <EOL> ) <EOL> return user if user and user . login == login else None <EOL> @ classmethod <EOL> def by_credentials ( cls , session , login , password ) : <EOL> """<STR_LIT>""" <EOL> user = cls . by_login ( session , login , local = True ) <EOL> if not user : <EOL> return None <EOL> if crypt . check ( user . password , password ) : <EOL> return user <EOL> @ classmethod <EOL> def by_ldap_credentials ( cls , session , login , password , settings ) : <EOL> """<STR_LIT>""" <EOL> if not asbool ( settings . get ( '<STR_LIT>' , '<STR_LIT:False>' ) ) : <EOL> return None <EOL> if ldap is None : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> try : <EOL> if hasattr ( ldap , '<STR_LIT>' ) : <EOL> ldap . set_option ( ldap . OPT_X_TLS_CACERTDIR , '<STR_LIT>' ) <EOL> ldap . set_option ( ldap . OPT_REFERRALS , ldap . OPT_OFF ) <EOL> ldap . set_option ( ldap . OPT_RESTART , ldap . OPT_ON ) <EOL> ldap . set_option ( ldap . OPT_TIMEOUT , <NUM_LIT:20> ) <EOL> ldap . set_option ( ldap . OPT_NETWORK_TIMEOUT , <NUM_LIT:10> ) <EOL> ldap . set_option ( ldap . OPT_TIMELIMIT , <NUM_LIT:15> ) <EOL> ldap_server_type = settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> host = settings [ '<STR_LIT>' ] . strip ( ) <EOL> port = settings . get ( '<STR_LIT>' , None ) . strip ( ) <EOL> if ldap_server_type in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> port = port or <NUM_LIT> <EOL> ldap_type = "<STR_LIT>" <EOL> certreq = settings . get ( '<STR_LIT>' , '<STR_LIT>' ) . strip ( ) <EOL> if certreq not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> certreq = '<STR_LIT>' <EOL> tls_cert = getattr ( ldap , '<STR_LIT>' % certreq ) <EOL> ldap . set_option ( ldap . OPT_X_TLS_REQUIRE_CERT , tls_cert ) <EOL> else : <EOL> port = port or <NUM_LIT> <EOL> ldap_type = '<STR_LIT>' <EOL> server_url = "<STR_LIT>" . format ( ldap_type = ldap_type , <EOL> host = host , <EOL> port = port ) <EOL> server = ldap . initialize ( server_url ) <EOL> if ldap_server_type == "<STR_LIT>" : <EOL> server . start_tls_s ( ) <EOL> server . protocol = ldap . VERSION3 <EOL> if settings [ '<STR_LIT>' ] and settings [ '<STR_LIT>' ] : <EOL> server . simple_bind_s ( settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> filter_ = settings [ '<STR_LIT>' ] . format ( username = login ) <EOL> results = server . search_ext_s ( settings [ '<STR_LIT>' ] , <EOL> getattr ( ldap , "<STR_LIT>" % settings [ '<STR_LIT>' ] ) , <EOL> filter_ ) <EOL> if results is None : <EOL> log . debug ( "<STR_LIT>" % ( login ) ) <EOL> return None <EOL> for ( dn , _attrs ) in results : <EOL> if dn is None : <EOL> continue <EOL> log . debug ( '<STR_LIT>' % dn ) <EOL> server . simple_bind_s ( dn , password ) <EOL> attrs = server . search_ext_s ( dn , ldap . SCOPE_BASE , '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> break <EOL> else : <EOL> log . debug ( "<STR_LIT>" , login ) <EOL> return None <EOL> log . debug ( '<STR_LIT>' ) <EOL> user_ldap = User . by_login ( session , login ) <EOL> if user_ldap is None : <EOL> log . debug ( '<STR_LIT>' % login ) <EOL> user_ldap = User ( ) <EOL> user_ldap . login = login <EOL> user_ldap . password = password <EOL> user_ldap . local = True <EOL> user_ldap . firstname = attrs [ settings [ '<STR_LIT>' ] ] [ <NUM_LIT:0> ] <EOL> user_ldap . lastname = attrs [ settings [ '<STR_LIT>' ] ] [ <NUM_LIT:0> ] <EOL> user_ldap . email = attrs [ settings [ '<STR_LIT>' ] ] [ <NUM_LIT:0> ] <EOL> for groupname in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> user_ldap . groups . append ( Group . by_name ( session , groupname ) ) <EOL> if user_ldap . validate ( session ) : <EOL> session . add ( user_ldap ) <EOL> log . debug ( '<STR_LIT>' . format ( login ) ) <EOL> transaction . commit ( ) <EOL> return user_ldap <EOL> except ldap . NO_SUCH_OBJECT : <EOL> log . debug ( "<STR_LIT>" % ( login ) ) <EOL> except ldap . SERVER_DOWN : <EOL> log . error ( "<STR_LIT>" ) <EOL> except ldap . LDAPError : <EOL> log . error ( '<STR_LIT>' ) <EOL> except Exception as exc : <EOL> log . error ( '<STR_LIT>' % exc , exc_info = True ) <EOL> return None <EOL> @ classmethod <EOL> def get_locals ( cls , session , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> where = ( cls . local == True , ) , <EOL> order_by = cls . login , <EOL> ** kwargs ) <EOL> def has_permission ( self , permission ) : <EOL> return permission in self . permissions <EOL> def validate ( self , session ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> if not self . login : <EOL> errors . append ( u'<STR_LIT>' ) <EOL> else : <EOL> other = User . by_login ( session , self . login ) <EOL> if other and other . id != self . id : <EOL> errors . append ( u'<STR_LIT>' % self . login ) <EOL> if not self . password : <EOL> errors . append ( u'<STR_LIT>' ) <EOL> if not self . email : <EOL> errors . append ( u'<STR_LIT>' ) <EOL> elif not re_email . match ( self . email ) : <EOL> errors . append ( u'<STR_LIT>' % self . email ) <EOL> if len ( errors ) : <EOL> raise ModelError ( errors ) <EOL> return True <EOL> class Classifier ( Base ) : <EOL> """<STR_LIT>""" <EOL> @ declared_attr <EOL> def __table_args__ ( cls ) : <EOL> return ( Index ( '<STR_LIT>' % cls . __tablename__ , <EOL> '<STR_LIT>' , '<STR_LIT:name>' , unique = True ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> } <EOL> ) <EOL> name = Column ( Unicode ( <NUM_LIT:255> ) , nullable = False , unique = True ) <EOL> parent_id = Column ( Integer , ForeignKey ( u'<STR_LIT>' ) ) <EOL> category = Column ( Unicode ( <NUM_LIT> ) , nullable = False ) <EOL> parent = relationship ( u'<STR_LIT>' , remote_side = u'<STR_LIT>' , <EOL> backref = u'<STR_LIT>' ) <EOL> @ property <EOL> def shortname ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . name . rsplit ( u'<STR_LIT>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] . strip ( ) <EOL> @ classmethod <EOL> def by_name ( cls , session , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> classifier = cls . first ( session , where = ( cls . name == name , ) ) <EOL> if not kwargs . get ( '<STR_LIT>' , False ) : <EOL> return classifier <EOL> if not classifier : <EOL> splitted_names = [ n . strip ( ) for n in name . split ( u'<STR_LIT>' ) ] <EOL> classifiers = [ u'<STR_LIT>' . join ( splitted_names [ : i + <NUM_LIT:1> ] ) <EOL> for i in range ( len ( splitted_names ) ) ] <EOL> parent_id = None <EOL> category = splitted_names [ <NUM_LIT:0> ] <EOL> for c in classifiers : <EOL> classifier = cls . first ( session , where = ( cls . name == c , ) ) <EOL> if not classifier : <EOL> classifier = Classifier ( name = c , parent_id = parent_id , <EOL> category = category ) <EOL> session . add ( classifier ) <EOL> session . flush ( ) <EOL> parent_id = classifier . id <EOL> return classifier <EOL> package__owner = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> package__maintainer = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> classifier__package = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class Package ( Base ) : <EOL> """<STR_LIT>""" <EOL> update_at = Column ( DateTime , default = func . now ( ) ) <EOL> name = Column ( Unicode ( <NUM_LIT:200> ) , unique = True ) <EOL> local = Column ( Boolean , nullable = False , default = False ) <EOL> owners = relationship ( User , secondary = package__owner , <EOL> backref = '<STR_LIT>' ) <EOL> downloads = Column ( Integer , default = <NUM_LIT:0> ) <EOL> maintainers = relationship ( User , secondary = package__maintainer , <EOL> backref = '<STR_LIT>' ) <EOL> classifiers = relationship ( Classifier , secondary = classifier__package , <EOL> lazy = '<STR_LIT>' , backref = '<STR_LIT>' ) <EOL> @ property <EOL> def versions ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ r . version for r in self . sorted_releases ] <EOL> @ property <EOL> def sorted_releases ( self ) : <EOL> """<STR_LIT>""" <EOL> releases = [ ( parse_version ( release . version ) , release ) <EOL> for release in self . releases ] <EOL> releases . sort ( reverse = True ) <EOL> return [ release [ <NUM_LIT:1> ] for release in releases ] <EOL> @ classmethod <EOL> def by_name ( cls , session , name ) : <EOL> """<STR_LIT>""" <EOL> pkg = cls . first ( session , where = ( cls . name . like ( name ) , ) ) <EOL> if not pkg : <EOL> name = name . replace ( u'<STR_LIT:->' , u'<STR_LIT:_>' ) . upper ( ) <EOL> pkg = cls . first ( session , <EOL> where = ( cls . name . like ( name ) , ) ) <EOL> if pkg and pkg . name . upper ( ) . replace ( u'<STR_LIT:->' , u'<STR_LIT:_>' ) != name : <EOL> pkg = None <EOL> return pkg <EOL> @ classmethod <EOL> def by_filter ( cls , session , opts , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> where = [ ] <EOL> if opts . get ( '<STR_LIT>' ) : <EOL> where . append ( cls . local == True ) <EOL> if opts . get ( '<STR_LIT>' ) : <EOL> where . append ( cls . name . in_ ( opts [ '<STR_LIT>' ] ) ) <EOL> if opts . get ( '<STR_LIT>' ) : <EOL> ids = [ c . id for c in opts . get ( '<STR_LIT>' ) ] <EOL> cls_pkg = classifier__package <EOL> qry = session . query ( cls_pkg . c . package_id , <EOL> func . count ( '<STR_LIT:*>' ) ) <EOL> qry = qry . filter ( cls_pkg . c . classifier_id . in_ ( ids ) ) <EOL> qry = qry . group_by ( cls_pkg . c . package_id ) <EOL> qry = qry . having ( func . count ( '<STR_LIT:*>' ) >= len ( ids ) ) <EOL> where . append ( cls . id . in_ ( [ r [ <NUM_LIT:0> ] for r in qry . all ( ) ] ) ) <EOL> return cls . find ( session , where = where , ** kwargs ) <EOL> @ classmethod <EOL> def by_owner ( cls , session , owner_name ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> join = ( cls . owners ) , <EOL> where = ( User . login == owner_name , ) , <EOL> order_by = cls . name ) <EOL> @ classmethod <EOL> def by_maintainer ( cls , session , maintainer_name ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> join = ( cls . maintainers ) , <EOL> where = ( User . login == maintainer_name , ) , <EOL> order_by = cls . name ) <EOL> @ classmethod <EOL> def get_locals ( cls , session ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> where = ( cls . local == True , ) ) <EOL> @ classmethod <EOL> def get_mirrored ( cls , session ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> where = ( cls . local == False , ) ) <EOL> classifier__release = Table ( '<STR_LIT>' , Base . metadata , <EOL> Column ( '<STR_LIT>' , Integer , <EOL> ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , <EOL> Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> class Release ( Base ) : <EOL> """<STR_LIT>""" <EOL> @ declared_attr <EOL> def __table_args__ ( cls ) : <EOL> return ( Index ( '<STR_LIT>' % cls . __tablename__ , <EOL> '<STR_LIT>' , '<STR_LIT:version>' , unique = True ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:utf8>' , <EOL> } <EOL> ) <EOL> version = Column ( Unicode ( <NUM_LIT> ) , nullable = False ) <EOL> summary = Column ( Unicode ( <NUM_LIT:255> ) ) <EOL> downloads = Column ( Integer , default = <NUM_LIT:0> ) <EOL> package_id = Column ( Integer , ForeignKey ( Package . id ) , <EOL> nullable = False ) <EOL> author_id = Column ( Integer , ForeignKey ( User . id ) ) <EOL> maintainer_id = Column ( Integer , ForeignKey ( User . id ) ) <EOL> stable_version = Column ( Unicode ( <NUM_LIT> ) ) <EOL> home_page = Column ( Unicode ( <NUM_LIT:255> ) ) <EOL> license = Column ( UnicodeText ( ) ) <EOL> description = Column ( UnicodeText ( ) ) <EOL> keywords = Column ( Unicode ( <NUM_LIT:255> ) ) <EOL> platform = Column ( Unicode ( <NUM_LIT> ) ) <EOL> download_url = Column ( Unicode ( <NUM_LIT> ) ) <EOL> bugtrack_url = Column ( Unicode ( <NUM_LIT> ) ) <EOL> docs_url = Column ( Unicode ( <NUM_LIT> ) ) <EOL> classifiers = relationship ( Classifier , secondary = classifier__release , <EOL> lazy = '<STR_LIT>' , cascade = '<STR_LIT>' ) <EOL> package = relationship ( Package , lazy = '<STR_LIT>' , <EOL> backref = backref ( '<STR_LIT>' , <EOL> cascade = '<STR_LIT>' ) ) <EOL> author = relationship ( User , primaryjoin = author_id == User . id ) <EOL> maintainer = relationship ( User , primaryjoin = maintainer_id == User . id ) <EOL> @ property <EOL> def download_url_file ( self ) : <EOL> """<STR_LIT>""" <EOL> url = self . download_url <EOL> return url . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) . pop ( ) if url else None <EOL> @ property <EOL> def can_download_url_whl ( self ) : <EOL> filename = self . download_url_file . split ( '<STR_LIT:#>' ) . pop ( <NUM_LIT:0> ) <EOL> return ( self . filename . endswith ( '<STR_LIT>' ) or <EOL> self . filename . endswith ( '<STR_LIT>' ) or <EOL> self . filename . endswith ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def whlify_download_url_file ( self ) : <EOL> return _whlify ( self . download_url_file . split ( '<STR_LIT:#>' ) . pop ( <NUM_LIT:0> ) ) <EOL> @ classmethod <EOL> def by_version ( cls , session , package_name , version ) : <EOL> """<STR_LIT>""" <EOL> return cls . first ( session , <EOL> join = ( Package , ) , <EOL> where = ( ( Package . name == package_name ) , <EOL> ( cls . version == version ) ) ) <EOL> @ classmethod <EOL> def by_classifiers ( cls , session , classifiers ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> join = ( cls . classifiers , ) , <EOL> where = ( Classifier . name . in_ ( classifiers ) , ) , <EOL> ) <EOL> @ classmethod <EOL> def search ( cls , session , opts , operator ) : <EOL> """<STR_LIT>""" <EOL> available = { '<STR_LIT:name>' : Package . name , <EOL> '<STR_LIT:version>' : cls . version , <EOL> '<STR_LIT>' : User . login , <EOL> '<STR_LIT>' : User . email , <EOL> '<STR_LIT>' : User . login , <EOL> '<STR_LIT>' : User . email , <EOL> '<STR_LIT>' : cls . home_page , <EOL> '<STR_LIT>' : cls . license , <EOL> '<STR_LIT>' : cls . summary , <EOL> '<STR_LIT:description>' : cls . description , <EOL> '<STR_LIT>' : cls . keywords , <EOL> '<STR_LIT>' : cls . platform , <EOL> '<STR_LIT>' : cls . download_url <EOL> } <EOL> oper = { '<STR_LIT>' : or_ , '<STR_LIT>' : and_ } <EOL> join_map = { '<STR_LIT:name>' : Package , <EOL> '<STR_LIT>' : cls . author , <EOL> '<STR_LIT>' : cls . author , <EOL> '<STR_LIT>' : cls . maintainer , <EOL> '<STR_LIT>' : cls . maintainer , <EOL> } <EOL> where = [ ] <EOL> join = [ ] <EOL> for opt , val in opts . items ( ) : <EOL> field = available [ opt ] <EOL> if hasattr ( val , '<STR_LIT>' ) and len ( val ) > <NUM_LIT:1> : <EOL> stmt = or_ ( * [ field . like ( u'<STR_LIT>' % v ) for v in val ] ) <EOL> else : <EOL> stmt = field . like ( u'<STR_LIT>' % val ) <EOL> where . append ( stmt ) <EOL> if opt in join_map : <EOL> join . append ( join_map [ opt ] ) <EOL> return cls . find ( session , join = join , <EOL> where = ( oper [ operator ] ( * where ) , ) ) <EOL> class ReleaseFile ( Base ) : <EOL> """<STR_LIT>""" <EOL> release_id = Column ( Integer , ForeignKey ( Release . id ) , <EOL> nullable = False ) <EOL> filename = Column ( Unicode ( <NUM_LIT:200> ) , unique = True , nullable = False ) <EOL> md5_digest = Column ( Unicode ( <NUM_LIT:50> ) ) <EOL> size = Column ( Integer ) <EOL> package_type = Column ( Enum ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' , <EOL> name = '<STR_LIT>' ) , <EOL> nullable = False ) <EOL> python_version = Column ( Unicode ( <NUM_LIT> ) ) <EOL> url = Column ( Unicode ( <NUM_LIT> ) ) <EOL> downloads = Column ( Integer , default = <NUM_LIT:0> ) <EOL> has_sig = Column ( Boolean , default = False ) <EOL> comment_text = Column ( UnicodeText ( ) ) <EOL> release = relationship ( Release , lazy = '<STR_LIT>' , <EOL> backref = backref ( '<STR_LIT>' , <EOL> cascade = '<STR_LIT>' ) ) <EOL> @ property <EOL> def filename_whlified ( self ) : <EOL> assert self . package_type == '<STR_LIT>' <EOL> return _whlify ( self . filename ) <EOL> @ classmethod <EOL> def by_release ( cls , session , package_name , version ) : <EOL> """<STR_LIT>""" <EOL> return cls . find ( session , <EOL> join = ( Release , Package ) , <EOL> where = ( Package . name == package_name , <EOL> Release . version == version , <EOL> ) ) <EOL> @ classmethod <EOL> def by_filename ( cls , session , release , filename ) : <EOL> """<STR_LIT>""" <EOL> return cls . first ( session , <EOL> where = ( ReleaseFile . release_id == release . id , <EOL> ReleaseFile . filename == filename , <EOL> ) ) </s>
