Back to index

moin  1.9.0~rc2
Functions
fckutil Namespace Reference

Functions

def removeExtension
def getExtension
def removeFromStart
def removeFromEnd
def combinePaths
def getFileName
def sanitizeFolderName
def sanitizeFileName
def getCurrentFolder
def mapServerPath
def mapServerFolder
def getRootPath

Function Documentation

def fckutil.combinePaths (   basePath,
  folder 
)

Definition at line 51 of file fckutil.py.

00051 
00052 def combinePaths( basePath, folder ):
00053        return removeFromEnd( basePath, '/' ) + '/' + removeFromStart( folder, '/' )

Here is the call graph for this function:

Here is the caller graph for this function:

def fckutil.getCurrentFolder (   currentFolder)

Definition at line 77 of file fckutil.py.

00077 
00078 def getCurrentFolder(currentFolder):
00079        if not currentFolder:
00080               currentFolder = '/'
00081 
00082        # Check the current folder syntax (must begin and end with a slash).
00083        if (currentFolder[-1] <> "/"):
00084               currentFolder += "/"
00085        if (currentFolder[0] <> "/"):
00086               currentFolder = "/" + currentFolder
00087 
00088        # Ensure the folder path has no double-slashes
00089        while '//' in currentFolder:
00090               currentFolder = currentFolder.replace('//','/')
00091 
00092        # Check for invalid folder paths (..)
00093        if '..' in currentFolder or '\\' in currentFolder:
00094               return None
00095 
00096        # Check for invalid folder paths (..)
00097        if re.search( '(/\\.)|(//)|([\\\\:\\*\\?\\""\\<\\>\\|]|[\x00-\x1F]|[\x7f-\x9f])', currentFolder ):
00098               return None
00099 
00100        return currentFolder

Here is the caller graph for this function:

def fckutil.getExtension (   fileName)

Definition at line 38 of file fckutil.py.

00038 
00039 def getExtension(fileName):
00040        index = fileName.rindex(".") + 1
00041        fileExtension = fileName[index:]
00042        return fileExtension

Here is the caller graph for this function:

def fckutil.getFileName (   filename)

Definition at line 54 of file fckutil.py.

00054 
00055 def getFileName(filename):
00056        " Purpose: helper function to extrapolate the filename "
00057        for splitChar in ["/", "\\"]:
00058               array = filename.split(splitChar)
00059               if (len(array) > 1):
00060                      filename = array[-1]
00061        return filename

def fckutil.getRootPath (   environ)

Definition at line 110 of file fckutil.py.

00110 
00111 def getRootPath(environ):
00112        "Purpose: returns the root path on the server"
00113        # WARNING: this may not be thread safe, and doesn't work w/ VirtualServer/mod_python
00114        # Use Config.UserFilesAbsolutePath instead
00115 
00116        if environ.has_key('DOCUMENT_ROOT'):
00117               return environ['DOCUMENT_ROOT']
00118        else:
00119               realPath = os.path.realpath( './' )
00120               selfPath = environ['SCRIPT_FILENAME']
00121               selfPath = selfPath [ :  selfPath.rfind( '/'  ) ]
00122               selfPath = selfPath.replace( '/', os.path.sep)
00123 
00124               position = realPath.find(selfPath)
00125 
00126               # This can check only that this script isn't run from a virtual dir
00127               # But it avoids the problems that arise if it isn't checked
00128               raise realPath
00129               if ( position < 0 or position <> len(realPath) - len(selfPath) or realPath[ : position ]==''):
00130                      raise Exception('Sorry, can\'t map "UserFilesPath" to a physical path. You must set the "UserFilesAbsolutePath" value in "editor/filemanager/connectors/py/config.py".')
00131               return realPath[ : position ]

Here is the caller graph for this function:

def fckutil.mapServerFolder (   resourceTypePath,
  folderPath 
)

Definition at line 107 of file fckutil.py.

00107 
00108 def mapServerFolder(resourceTypePath, folderPath):
00109        return combinePaths ( resourceTypePath  , folderPath )

Here is the caller graph for this function:

def fckutil.mapServerPath (   environ,
  url 
)

Definition at line 101 of file fckutil.py.

00101 
00102 def mapServerPath( environ, url):
00103        " Emulate the asp Server.mapPath function. Given an url path return the physical directory that it corresponds to "
00104        # This isn't correct but for the moment there's no other solution
00105        # If this script is under a virtual directory or symlink it will detect the problem and stop
00106        return combinePaths( getRootPath(environ), url )

Here is the call graph for this function:

def fckutil.removeExtension (   fileName)

Definition at line 33 of file fckutil.py.

00033 
00034 def removeExtension(fileName):
00035        index = fileName.rindex(".")
00036        newFileName = fileName[0:index]
00037        return newFileName

Here is the caller graph for this function:

def fckutil.removeFromEnd (   string,
  char 
)

Definition at line 46 of file fckutil.py.

00046 
00047 def removeFromEnd(string, char):
00048        return string.rstrip(char)
00049 
00050 # Path functions

Here is the caller graph for this function:

def fckutil.removeFromStart (   string,
  char 
)

Definition at line 43 of file fckutil.py.

00043 
00044 def removeFromStart(string, char):
00045        return string.lstrip(char)

Here is the caller graph for this function:

def fckutil.sanitizeFileName (   newFileName)

Definition at line 67 of file fckutil.py.

00067 
00068 def sanitizeFileName( newFileName ):
00069        "Do a cleanup of the file name to avoid possible problems"
00070        # Replace dots in the name with underscores (only one dot can be there... security issue).
00071        if ( Config.ForceSingleExtension ): # remove dots
00072               newFileName = re.sub ( '\\.(?![^.]*$)', '_', newFileName ) ;
00073        newFileName = newFileName.replace('\\','/')             # convert windows to unix path
00074        newFileName = os.path.basename (newFileName)     # strip directories
00075        # Remove \ / | : ? *
00076        return re.sub ( '\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[\x00-\x1f\x7f-\x9f]/', '_', newFileName )

Here is the caller graph for this function:

def fckutil.sanitizeFolderName (   newFolderName)

Definition at line 62 of file fckutil.py.

00062 
00063 def sanitizeFolderName( newFolderName ):
00064        "Do a cleanup of the folder name to avoid possible problems"
00065        # Remove . \ / | : ? * " < > and control characters
00066        return re.sub( '\\.|\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[\x00-\x1f\x7f-\x9f]', '_', newFolderName )