<s> import re <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . core . urlresolvers import NoReverseMatch , resolve , reverse <EOL> from django . http import Http404 <EOL> from oscar . core . loading import AppNotFoundError , get_class <EOL> from oscar . views . decorators import check_permissions <EOL> class Node ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , label , url_name = None , url_args = None , url_kwargs = None , <EOL> access_fn = None , icon = None ) : <EOL> self . label = label <EOL> self . icon = icon <EOL> self . url_name = url_name <EOL> self . url_args = url_args <EOL> self . url_kwargs = url_kwargs <EOL> self . access_fn = access_fn <EOL> self . children = [ ] <EOL> @ property <EOL> def is_heading ( self ) : <EOL> return self . url_name is None <EOL> @ property <EOL> def url ( self ) : <EOL> return reverse ( self . url_name , args = self . url_args , <EOL> kwargs = self . url_kwargs ) <EOL> def add_child ( self , node ) : <EOL> self . children . append ( node ) <EOL> def is_visible ( self , user ) : <EOL> return self . access_fn is None or self . access_fn ( <EOL> user , self . url_name , self . url_args , self . url_kwargs ) <EOL> def filter ( self , user ) : <EOL> if not self . is_visible ( user ) : <EOL> return None <EOL> node = Node ( <EOL> label = self . label , url_name = self . url_name , url_args = self . url_args , <EOL> url_kwargs = self . url_kwargs , access_fn = self . access_fn , <EOL> icon = self . icon <EOL> ) <EOL> for child in self . children : <EOL> if child . is_visible ( user ) : <EOL> node . add_child ( child ) <EOL> return node <EOL> def has_children ( self ) : <EOL> return len ( self . children ) > <NUM_LIT:0> <EOL> def default_access_fn ( user , url_name , url_args = None , url_kwargs = None ) : <EOL> """<STR_LIT>""" <EOL> exception = ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if url_name is None : <EOL> return True <EOL> try : <EOL> url = reverse ( url_name , args = url_args , kwargs = url_kwargs ) <EOL> view_module = resolve ( url ) . func . __module__ <EOL> except ( NoReverseMatch , Http404 ) : <EOL> return False <EOL> match = re . search ( '<STR_LIT>' , view_module ) <EOL> if not match : <EOL> raise exception <EOL> app_label_str = match . groups ( ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> try : <EOL> app_instance = get_class ( app_label_str , '<STR_LIT>' ) <EOL> except AppNotFoundError : <EOL> raise exception <EOL> if '<STR_LIT::>' in url_name : <EOL> view_name = url_name . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> else : <EOL> view_name = url_name <EOL> permissions = app_instance . get_permissions ( view_name ) <EOL> return check_permissions ( user , permissions ) </s>
