Пример #1
0
def set_defaults(vars):
    """Sets the default_vars from the configuration for templates, useful when
    need to execute code and a YAML file is not enough.
    """
    templates_config = configs.get('templates')
    if templates_config.get('default_vars', False):
        if hasattr(templates_config, 'update_recursive'):
            templates_config.update_recursive({
                'default_vars': vars,
            })
        else:
            templates_config.get('default_vars').update(vars)
    else:
        configs.get('templates')['default_vars'] = vars
Пример #2
0
def set_defaults(vars):
    """Sets the default_vars from the configuration for templates, useful when
    need to execute code and a YAML file is not enough.
    """
    templates_config = configs.get('templates')
    if templates_config.get('default_vars', False):
        if hasattr(templates_config, 'update_recursive'):
            templates_config.update_recursive({
                'default_vars': vars,
            })
        else:
            templates_config.get('default_vars').update(vars)
    else:
        configs.get('templates')['default_vars'] = vars
Пример #3
0
    def __init__(self, country_code, telco_code, short_number, phone_number,
                 message, channel_key, app_id=None, use_country_code=True,
                 tracker=None, config=None, formatter=Formatter, clean=clean):

        self._config = self.default_configuration
        self._config.update(configs.get('sms', {})) 
        if config:
            self._config.update(config)

        self.telco_code = telco_code
        self.short_number = short_number
        self.phone_number = phone_number
        self.country_code = country_code
        self.message = message
        self.channel_key = channel_key
        self.app_id = app_id or self._config.get('app_id')

        self.tracker = tracker
        if tracker is not None:
            self._tracker = '<tracker>%s</tracker>\n' % tracker
        else:
            self._tracker = ''

        self._clean = clean
        self._use_country_code = use_country_code
        self._formatter = formatter
        self._serialized = None
        self._tokens = None
        self._message_clean = None
Пример #4
0
	def register_templates(self):
		if configs.get('templates') is None:
			configs['templates'] = {}

		if configs['templates'].get('directories') is None:
			configs['templates']['directories'] = []

		app_templates = os.path.join(conf('project_path'), 'templates')
		configs['templates']['directories'].append(app_templates)
Пример #5
0
 def __init__(self, config=None):
     self.config = self.default_configuration
     self.config.update_recursive(configs.get('mysql', {}))
     if config:
         self.config.update_recursive(config)
     self.metadatas = {}
     self.engines = {}
     self.sessions = {}
     self.models = {}
Пример #6
0
 def __init__(self, config=None):
     self.config = self.default_configuration
     self.config.update_recursive(configs.get('mysql', {}))
     if config:
         self.config.update_recursive(config)
     self.metadatas = {}
     self.engines = {}
     self.sessions = {}
     self.models = {}
Пример #7
0
    def __init__(self,
                 template_name,
                 template_vars=None,
                 config=None,
                 _format='html',
                 template_lookup_class=TemplateLookup,
                 layout={}):

        self.config = self.default_configuration
        self.config.update_recursive(configs.get('templates', {}))
        if config:
            self.config.update_recursive(config)

        self.template_name = template_name

        # add project path templates
        project_templates = os.path.join(get_project_path(), 'templates')
        if not project_templates in self.config['directories']:
            self.config['directories'].insert(0, project_templates)

        template_lookup = TemplateLookup(
            directories=self.config.get('directories'),
            input_encoding=self.config.get('input_encoding'),
            output_encoding=self.config.get('output_encoding'),
            encoding_errors=self.config.get('encoding_errors'),
            strict_undefined=self.config.get('strict_undefined'),
            default_filters=self.config.get(
                'default_filters', self.config.get('default_filters')))

        self.template_format = _format

        self.template_inherit = None
        self.template_sections = None
        self.template_layout = None

        if layout:
            self.template_inherit = ".".join(
                [layout.get("master"),
                 layout.get("format")])
            self.template_layout = ".".join(
                [layout.get("layout"),
                 layout.get("format")])
            self.template_name = ".".join(
                ["/" + self.template_name,
                 layout.get("format")])
        else:
            self._check_for_layout()

        self.template = template_lookup.get_template(self.template_name)
        self.template_vars = self.config.get('default_vars')
        self.template_vars.update_recursive(template_vars or {})

        self.rendered = None
Пример #8
0
 def __init__(self, queue, persistent=True, wait=False, host='127.0.0.1',
              priority=6, port=61613, config=None):
     self.config = self.default_configuration.copy()
     self.config.update(configs.get('activemq', {}))
     if config:
         self.config.update(config)
     # XXX get host and port from config
     self.host = host
     self.port = port
     self.queue = queue
     self.persistent = persistent
     self.wait = wait
     self.priority = priority
Пример #9
0
    def __init__(self,
                 query,
                 params=None,
                 from_file=True,
                 model_class=None,
                 database='default',
                 sessions=sessions,
                 cached=False,
                 replace=None,
                 config=None,
                 cache_timeout=3600 * 12):

        self.config = self.default_configuration
        self.config.update_recursive(configs.get('mysql', {}))
        if config:
            self.config.update_recursive(config)

        # add project path queries directory if not already configured
        project_queries = os.path.join(get_project_path(), 'queries')
        if not project_queries in self.config['query_directories']:
            self.config['query_directories'].append(project_queries)

        if from_file:
            if query in file_queries:
                logger.debug('Getting query file from query files cache %s' %
                             query)
                self.query = file_queries[query]
            else:
                logger.debug('Getting query file %s' % query)
                file_queries[query] = self._get_from_file(query)
                self.query = file_queries[query]
        else:
            self.query = query

        if replace:
            self.query = self.query % replace

        self.params = params
        self.session = sessions.get(database)
        self.result = None
        self.model_class = model_class
        self.cached = cached
        self.query_cache = MemcachedCache(['127.0.0.1:11211'])
        self.cache_timeout = cache_timeout
        self.database = database
Пример #10
0
 def __init__(self,
              queue,
              persistent=True,
              wait=False,
              host='127.0.0.1',
              priority=6,
              port=61613,
              config=None):
     self.config = self.default_configuration.copy()
     self.config.update(configs.get('activemq', {}))
     if config:
         self.config.update(config)
     # XXX get host and port from config
     self.host = host
     self.port = port
     self.queue = queue
     self.persistent = persistent
     self.wait = wait
     self.priority = priority
Пример #11
0
    def __init__(self, template_name, template_vars=None, config=None,
            _format='html', template_lookup_class=TemplateLookup, layout={}):

        self.config = self.default_configuration
        self.config.update_recursive(configs.get('templates', {}))
        if config:
            self.config.update_recursive(config)

        self.template_name = template_name

        # add project path templates
        project_templates = os.path.join(get_project_path(), 'templates')
        if not project_templates in self.config['directories']:
            self.config['directories'].insert(0,project_templates)
            
        template_lookup = TemplateLookup(
            directories=self.config.get('directories'),
            input_encoding=self.config.get('input_encoding'),
            output_encoding=self.config.get('output_encoding'),
            encoding_errors=self.config.get('encoding_errors'),
            strict_undefined=self.config.get('strict_undefined'),
            default_filters=self.config.get('default_filters', self.config.get('default_filters'))
        )

        self.template_format = _format

        self.template_inherit = None
        self.template_sections = None
        self.template_layout = None

        if layout:
            self.template_inherit = ".".join([layout.get("master"),layout.get("format")])
            self.template_layout = ".".join([layout.get("layout"),layout.get("format")])
            self.template_name = ".".join(["/" + self.template_name,layout.get("format")])
        else:
            self._check_for_layout()
        
        self.template = template_lookup.get_template(self.template_name)
        self.template_vars = self.config.get('default_vars')
        self.template_vars.update_recursive(template_vars or {})

        self.rendered = None
Пример #12
0
    def __init__(self,
                 country_code,
                 telco_code,
                 short_number,
                 phone_number,
                 message,
                 channel_key,
                 app_id=None,
                 use_country_code=True,
                 tracker=None,
                 config=None,
                 formatter=Formatter,
                 clean=clean):

        self._config = self.default_configuration
        self._config.update(configs.get('sms', {}))
        if config:
            self._config.update(config)

        self.telco_code = telco_code
        self.short_number = short_number
        self.phone_number = phone_number
        self.country_code = country_code
        self.message = message
        self.channel_key = channel_key
        self.app_id = app_id or self._config.get('app_id')

        self.tracker = tracker
        if tracker is not None:
            self._tracker = '<tracker>%s</tracker>\n' % tracker
        else:
            self._tracker = ''

        self._clean = clean
        self._use_country_code = use_country_code
        self._formatter = formatter
        self._serialized = None
        self._tokens = None
        self._message_clean = None
Пример #13
0
    def __init__(self, query, params=None, from_file=True, model_class=None,
                 database='default', sessions=sessions, cached=False,
                 replace=None, config=None, cache_timeout=3600*12):

        self.config = self.default_configuration
        self.config.update_recursive(configs.get('mysql', {}))
        if config:
            self.config.update_recursive(config)

        # add project path queries directory if not already configured
        project_queries = os.path.join(get_project_path(), 'queries')
        if not project_queries in self.config['query_directories']:
            self.config['query_directories'].append(project_queries)

        if from_file:
            if query in file_queries:
                logger.debug('Getting query file from query files cache %s' %
                             query)
                self.query = file_queries[query]
            else:
                logger.debug('Getting query file %s' % query)
                file_queries[query] = self._get_from_file(query)
                self.query = file_queries[query]
        else:
            self.query = query

        if replace:
            self.query = self.query % replace

        self.params = params
        self.session = sessions.get(database)
        self.result = None
        self.model_class = model_class
        self.cached = cached
        self.query_cache = MemcachedCache(['127.0.0.1:11211'])
        self.cache_timeout = cache_timeout
        self.database = database
Пример #14
0
 def __init__(self, config=None):
     self.config = self.default_configuration
     self.config.update_recursive(configs.get("werkzeug", {}))
     if config:
         self.config.update_recursive(config)