<s> __author__ = '<STR_LIT>' <EOL> import os . path <EOL> from server . utils . bcolors import bcolors <EOL> import config <EOL> from server . utils import fileExtensions <EOL> from server . handlers import errorHandler <EOL> def in_directory ( file , directory ) : <EOL> directory = os . path . join ( os . path . realpath ( directory ) , '<STR_LIT>' ) <EOL> file = os . path . realpath ( file ) <EOL> return os . path . commonprefix ( [ file , directory ] ) == directory <EOL> def is_directory ( file , directory ) : <EOL> directory = os . path . join ( os . path . realpath ( directory ) , '<STR_LIT>' ) <EOL> file = os . path . realpath ( file ) <EOL> return os . path . dirname ( file ) + '<STR_LIT:/>' == directory <EOL> def verify_in_directory ( file ) : <EOL> if len ( config . __ALLOWED_DIRS_AND_SUB__ ) < <NUM_LIT:1> : <EOL> errorHandler . handle ( "<STR_LIT>" , color = bcolors . WARNING , level = <NUM_LIT:4> ) <EOL> return False <EOL> for koopa in config . __ALLOWED_DIRS_AND_SUB__ : <EOL> if in_directory ( file , koopa ) == False : <EOL> errorHandler . handle ( "<STR_LIT>" , color = bcolors . WARNING , level = <NUM_LIT:8> ) <EOL> return False <EOL> return True <EOL> def verify_is_directory ( file ) : <EOL> if len ( config . __ALLOWED_DIRS__ ) < <NUM_LIT:1> : <EOL> errorHandler . handle ( "<STR_LIT>" , color = bcolors . WARNING , level = <NUM_LIT:4> ) <EOL> return False <EOL> for koopa in config . __ALLOWED_DIRS__ : <EOL> if is_directory ( file , koopa ) == False : <EOL> errorHandler . handle ( "<STR_LIT>" , color = bcolors . WARNING , level = <NUM_LIT:8> ) <EOL> return False <EOL> return True <EOL> def verify_all ( file ) : <EOL> if verify_in_directory ( file ) and fileExtensions . check_allowed ( file ) and fileExtensions . check_denied ( file ) == True : <EOL> return True <EOL> if verify_is_directory ( file ) and fileExtensions . check_allowed ( file ) and fileExtensions . check_denied ( file ) == True : <EOL> return True <EOL> return False </s>
