<s> """<STR_LIT>""" <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import ast <EOL> import os <EOL> import platform <EOL> import sys <EOL> import weakref <EOL> _builtin_compile = compile <EOL> try : <EOL> from platform import python_implementation <EOL> except ImportError : <EOL> if os . name == "<STR_LIT>" : <EOL> def python_implementation ( ) : <EOL> return "<STR_LIT>" <EOL> else : <EOL> raise <EOL> _VARS = { '<STR_LIT>' : sys . platform , <EOL> '<STR_LIT>' : '<STR_LIT>' % sys . version_info [ : <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : sys . version . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : os . name , <EOL> '<STR_LIT>' : platform . version ( ) , <EOL> '<STR_LIT>' : platform . machine ( ) , <EOL> '<STR_LIT>' : python_implementation ( ) , <EOL> '<STR_LIT>' : None <EOL> } <EOL> for var in list ( _VARS . keys ( ) ) : <EOL> if '<STR_LIT:.>' in var : <EOL> _VARS [ var . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) ] = _VARS [ var ] <EOL> def default_environment ( ) : <EOL> """<STR_LIT>""" <EOL> return dict ( _VARS ) <EOL> class ASTWhitelist ( ast . NodeTransformer ) : <EOL> def __init__ ( self , statement ) : <EOL> self . statement = statement <EOL> ALLOWED = ( ast . Compare , ast . BoolOp , ast . Attribute , ast . Name , ast . Load , ast . Str ) <EOL> ALLOWED += ( ast . And , ast . Or ) <EOL> ALLOWED += ( ast . Eq , ast . Gt , ast . GtE , ast . In , ast . Is , ast . IsNot , ast . Lt , ast . LtE , ast . NotEq , ast . NotIn ) <EOL> def visit ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( node , self . ALLOWED ) : <EOL> raise SyntaxError ( '<STR_LIT>' % <EOL> ( self . statement , <EOL> ( '<STR_LIT:U+0020>' * node . col_offset ) + '<STR_LIT>' ) ) <EOL> return ast . NodeTransformer . visit ( self , node ) <EOL> def visit_Attribute ( self , node ) : <EOL> """<STR_LIT>""" <EOL> new_node = ast . Name ( "<STR_LIT>" % ( node . value . id , node . attr ) , node . ctx ) <EOL> return ast . copy_location ( new_node , node ) <EOL> def parse_marker ( marker ) : <EOL> tree = ast . parse ( marker , mode = '<STR_LIT>' ) <EOL> new_tree = ASTWhitelist ( marker ) . generic_visit ( tree ) <EOL> return new_tree <EOL> def compile_marker ( parsed_marker ) : <EOL> return _builtin_compile ( parsed_marker , '<STR_LIT>' , '<STR_LIT>' , <EOL> dont_inherit = True ) <EOL> _cache = weakref . WeakValueDictionary ( ) <EOL> def compile ( marker ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return _cache [ marker ] <EOL> except KeyError : <EOL> pass <EOL> if not marker . strip ( ) : <EOL> def marker_fn ( environment = None , override = None ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> else : <EOL> compiled_marker = compile_marker ( parse_marker ( marker ) ) <EOL> def marker_fn ( environment = None , override = None ) : <EOL> """<STR_LIT>""" <EOL> if override is None : <EOL> override = { } <EOL> if environment is None : <EOL> environment = default_environment ( ) <EOL> environment . update ( override ) <EOL> return eval ( compiled_marker , environment ) <EOL> marker_fn . __doc__ = marker <EOL> _cache [ marker ] = marker_fn <EOL> return _cache [ marker ] <EOL> def interpret ( marker , environment = None ) : <EOL> return compile ( marker ) ( environment ) </s>
