Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
CMFPlone.URLTool.URLTool Class Reference
Inheritance diagram for CMFPlone.URLTool.URLTool:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.URLTool.URLTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def isURLInPortal

Static Public Attributes

 meta_type = ToolNames.URLTool
tuple security = ClassSecurityInfo()
string toolicon = 'skins/plone_images/link_icon.gif'

Static Private Attributes

tuple __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )

Detailed Description

Definition at line 9 of file URLTool.py.


Member Function Documentation

def CMFPlone.URLTool.URLTool.isURLInPortal (   self,
  url,
  context = None 
)
Check if a given url is on the same host and contains the portal
    path.  Used to ensure that login forms can determine relevant
    referrers (i.e. in portal).  Also return true for some relative urls
    if context is passed in to allow for url parsing. When context is
    not provided, assume that relative urls are in the portal. It is
    assumed that http://portal is the same portal as https://portal.

Definition at line 18 of file URLTool.py.

00018 
00019     def isURLInPortal(self, url, context=None):
00020         """ Check if a given url is on the same host and contains the portal
00021             path.  Used to ensure that login forms can determine relevant
00022             referrers (i.e. in portal).  Also return true for some relative urls
00023             if context is passed in to allow for url parsing. When context is
00024             not provided, assume that relative urls are in the portal. It is
00025             assumed that http://portal is the same portal as https://portal.
00026         """
00027         p_url = self()
00028         portal_path = urlparse(p_url)[0:3]
00029         url_path = urlparse(url)[0:3]
00030         p = {#'protocol':portal_path[0],
00031              'host':portal_path[1],
00032              'path':portal_path[2]}
00033         u = {#'protocol':url_path[0],
00034              'host':url_path[1],
00035              'path':url_path[2]}
00036         # check for urls without protocol (i.e. relative urls), or urls with
00037         # the same host and path.
00038         
00039         if not u['host'] and not u['path'].startswith('/'): #relatively relative url!
00040             #url is a relative path that needs to be checked. URLs that start with / can be quickly checked
00041             #urls that start with ../ need to have a bit of traversal
00042             if u['path'].startswith('.'):
00043                 if context is None:
00044                     return True #old behavior
00045                 else: #gentlemen, start your parsing engines
00046                     if not context.isPrincipiaFolderish:
00047                         useurl = context.aq_parent.absolute_url()
00048                     else:
00049                         useurl = context.absolute_url()
00050                     currpath = urlparse(useurl)[2].split('/') #just the path
00051                     for node in u['path'].split('/'): #path is something like "../../target"
00052                         if node == '..':
00053                             if currpath:
00054                                 currpath.pop()
00055                             else: #we have more ../ than in the current context, we can't be in the portal
00056                                 return False
00057                         elif node == '.':
00058                             continue
00059                         else: #We shouldn't have to deal with crazy urls like ../../somefolder/../otherfolder/../content
00060                             #add the current node to give us a bit more breathing room, in case somone was silly and used the name of the portal in the relative path
00061                             return ('/'.join(currpath)+'/'+node).startswith(p['path']) 
00062             else: #url is in the form: path/to/another/object.jpg
00063                 return True 
00064         else:
00065             return (p['host'] == u['host'] or not u['host']) and u['path'].startswith(p['path'])
00066 
00067 URLTool.__doc__ = BaseTool.__doc__
00068 
00069 InitializeClass(URLTool)

Here is the call graph for this function:


Member Data Documentation

tuple CMFPlone.URLTool.URLTool.__implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, ) [static, private]

Definition at line 15 of file URLTool.py.

Definition at line 11 of file URLTool.py.

tuple CMFPlone.URLTool.URLTool.security = ClassSecurityInfo() [static]

Definition at line 12 of file URLTool.py.

string CMFPlone.URLTool.URLTool.toolicon = 'skins/plone_images/link_icon.gif' [static]

Definition at line 13 of file URLTool.py.


The documentation for this class was generated from the following file: