__init__.py :  » Development » SnapLogic » snaplogic » cc » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » SnapLogic 
SnapLogic » snaplogic » cc » __init__.py
# $SnapHashLicense:
# 
# SnapLogic - Open source data services
# 
# Copyright (C) 2008 - 2009, SnapLogic, Inc.  All rights reserved.
# 
# See http://www.snaplogic.org for more information about
# the SnapLogic project. 
# 
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
# 
# "SnapLogic" is a trademark of SnapLogic, Inc.
# 
# 
# $

# $Id: __init__.py 9868 2009-11-21 17:50:45Z dhiraj $
""" The Component Container  package """

from snaplogic.common import snap_log,uri_prefix,headers,snap_http_lib
from snaplogic import snapi_base
from snaplogic.snapi_base.exceptions import SnapiHttpException

my_process_uri = None
"URI of this process."

config = None
logger = None
log = None
elog = None
rlog = None
log_level = None
stats = None
stats_group = None
cc_token = None
PLACE_HOLDER_CC_TOKEN = "99999"
cc_name = None
"""Name given to the CC."""
cc_username = None
"""User ID used in the credentials provided to the CC."""
server_uri = None
"""Main process server's official URI."""

def init_loggers(cc_name, log_dir, level, to_console, disable_logging, max_log_size, log_backup_count):
    # Initialize log
    global logger, log, elog, rlog, log_level
    logger = snap_log.SnapLog(cc_name, log_dir, to_console, disable_logging, level, max_log_size, log_backup_count)
    (log, elog, rlog) = logger.make_specific_loggers(snap_log.LOG_CC)
    log_level = level
    

def is_my_server_uri(target_uri):
    """
    Check if the URI specified points to my server.
    
    @param target_uri: URI to be checked.
    @type target_uri:  str
    
    @return: True if URI does belong to my server, else False
    @rtype:  bool
    
    """
    
    if target_uri.startswith('/'):
        # Got a relative URI here.
        return True
    
    u = snap_http_lib.concat_paths(server_uri, uri_prefix.URI_CHECK)
    custom_hdr = {}
    # Never send None value in header, it gets stringified to the string "None"
    if cc_token is not None:
        custom_hdr[headers.CC_TOKEN_HEADER] = cc_token
    else:
        custom_hdr[headers.CC_TOKEN_HEADER] = PLACE_HOLDER_CC_TOKEN
    if cc_username is not None:
        custom_hdr[headers.INVOKER_HEADER] = cc_username

    try:
        resp = snapi_base.send_req("POST", u, target_uri, custom_hdr)
    except SnapiHttpException, e:
        if e.status == 404:
            return False
        else:
            raise
    
    return True
    
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.