예제 #1
0
def admin():
    '''
    Takes path from the route and tells Apache to server the file.
    
    @param path: The path to the file relative to root.
    @type path: str
    '''
    
    return dict(user_data=Server.get_user_data(), site_data=Server.get_site_data())
예제 #2
0
def get_application(**kargs):
    '''
    Takes configuration params for creating middleware app. 
    @return: middleware app
    '''

    Server.initialize(app=bottle.default_app(), **kargs)
    logging.debug('Main Web Service Started')
    return Server.get_application()
예제 #3
0
def run_replacer(val):
    '''
    If list given calls run_replacer on each element of string.
    
    If string replaces the match_pattern given in config with wrapping_links given in config.
    
    Otherwise calls recursive_wrap if it is a list of dict.
    '''
    if isinstance(val, list):
        new_val = map(run_replacer, val)
        return new_val
    elif isinstance(val, str) or isinstance(val, unicode):
        val = val.replace(Server.get_config()["Search"]["match_pattern"], Server.get_config()["Search"]["replace_with"])
        return Server.get_config()["Search"]["wrapping_link"] + val
    else:
        return recursive_wrap(val)
예제 #4
0
def recursive_wrap(data):
    '''
    Recursively goes through the whole structure(dict or list), searching for the keys specified in link_fields in the config.
    If found calls run_replacer.
    
    If data is neither list nor dict returns the data.
    '''
    if isinstance(data, dict):
        for key, value in data.iteritems():
            data[key] = run_replacer(value) if key in Server.get_config()["Search"]["link_fields"] else recursive_wrap(value)  
        return data
    elif isinstance(data, list):
        new_data = map(recursive_wrap, data)
        return new_data
    else:
        return data
예제 #5
0
def userdata(user=None):
    '''
    Takes path from the route and tells Apache to server the file.
    
    @param path: The path to the file relative to root.
    @type path: str
    '''    
    confirm, user_data = Server.get_user_data(user)
    
    if confirm:
        ret = []
        for key, val in user_data.iteritems():
            for v in val:
                ret.append( { key : v })
            ret.sort(cmp=time_sort)
        return dict(user = confirm, user_data = ret)
    else:
        ret = user_data.keys()
        return dict(user_data = ret)
예제 #6
0
def sitedata(url=None):
    '''
    Takes path from the route and tells Apache to server the file.
    
    @param path: The path to the file relative to root.
    @type path: str
    '''
    if url:
        url = url.replace('__slashslash__', '//')
    logging.debug("URL Recieved: %s", url)
    confirm, site_data = Server.get_site_data(url)
    logging.debug("confirm: %s,site_data: %s", confirm, site_data)
    if confirm:
        ret = site_data
        ret.sort(cmp=url_time_sort)
        return dict(url=confirm, site_data = ret)
    else:
        ret = []
        for key, val in site_data.iteritems():
            ret.append( { key : len(val) })
            ret.sort(cmp=value_sort)
        return dict(site_data = ret)
예제 #7
0
 def update_data(user, url):
     Server.update_user_data(user, url, "inc")
     Server.update_site_data(user, url, "inc")
     logging.debug("Unique click detected.New data entry made.")
     return random.randint(1, 10000)
예제 #8
0
 def wrapper(*args, **kargs):
     url = bottle.request.GET.get('url', '#') #@UndefinedVariable
     logging.debug("URL:%s",url)
     url = url.replace(Server.get_config()["Search"]["replace_with"], Server.get_config()["Search"]["match_pattern"])
     return func(*args, url=url, **kargs)