Changeset 3478 in products


Ignore:
Timestamp:
Jul 27, 2012 2:35:19 PM (7 years ago)
Author:
potar
Message:

added urlFilter; rewrote code

File:
1 copied

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/branches/two_request/utils.py

    r3460 r3478  
    1111_marker = [] 
    1212 
    13  
     13     
    1414def searchAndReplace(string, what, withs): 
    1515    """Emulate sed command s/""" 
     16    #TODO: Better solution would be to compile 
     17    #'what' and 'withs' 
    1618    res = re.sub(what, withs, string) 
    1719    return res 
    1820OPERATORS = {'s': searchAndReplace, } 
    1921 
     22def urlFilter(url, operations): 
     23    """ Method dedicated to filter url according with operations """ 
     24    for operator, what, withs in operations: 
     25        url = OPERATORS[operator](url, what, withs.replace("\\", "")) 
     26    return url  
    2027 
    21 def applyOperations(objects, operations): 
    22     """Parse Operations """ 
    23     operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 
    24     result = {} 
     28def getUrlsObjects(objects): 
     29    """Method dedicated to get url for each object""" 
     30    results = set() 
    2531    for ob in objects: 
    2632        url = _marker 
     
    2935        if url in [Missing_Value, _marker]: 
    3036            url = ICanonicalLink(ob.getObject()).canonical_link 
    31         for operator, what, withs in operations: 
    32             url = OPERATORS[operator](url, what, withs.replace("\\", "")) 
    3337        #TODO: Remove or replace following condition 
    3438        #it is senseless in the case we need intelligent 
    3539        #result set. Better condition would be to place 
    3640        #freshest brain into result 
    37         if url in result.keys(): 
     41        if url in results: 
    3842            continue 
    3943        #TODO: replace brain with only data necessary to 
    4044        #generate sitemap 
     45        results.add(url) 
     46        yield url, ob 
     47 
     48def applyOperations(objects, operations): 
     49    """Parse Operations""" 
     50    operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 
     51    result = {} 
     52    for url, ob in getUrlsObjects(objects): 
     53        url = urlFilter(url, operations) 
    4154        result[url] = ob 
    4255    return result 
    43  
    4456 
    4557def additionalURLs(context): 
Note: See TracChangeset for help on using the changeset viewer.