Пример #1
0
    def __init__(self, options=None):
        """Mamba constructor"""

        super(Mamba, self).__init__()

        if hasattr(self, 'initialized') and self.initialized is True:
            return

        self.monkey_patched = False
        self.development = False
        self.already_logging = False
        self._mamba_ver = _mamba_version.version.short()
        self._ver = _app_ver.short()
        self._port = 1936
        self._log_file = None
        self._project_ver = _app_project_ver.short()

        self.name = 'Mamba Webservice v%s' % _mamba_version.version.short()
        self.description = (
            'Mamba %s is a Web applications framework that works '
            'over Twisted using Jinja2 as GUI enhancement '
            'Mamba has been developed by Oscar Campos '
            '<*****@*****.**>' % _mamba_version.version.short()
        )

        self.language = os.environ.get('LANG', 'en_EN').split('_')[0]
        self.lessjs = False

        self._parse_options(options)

        # monkey patch twisted
        self._monkey_patch()

        # register log file if any
        self._handle_logging()

        # PyPy does not implement set_debug method in gc object
        if getattr(options, 'debug', False):
            if hasattr(gc, 'set_debug'):
                gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_INSTANCES)
            else:
                log.msg(
                    'Debug is set as True but gc object is laking '
                    'set_debug method'
                )

        self._header = headers.Headers()
        self._header.language = self.language
        self._header.description = self.description

        self.managers = {
            'controller': controller.ControllerManager(),
            'model': model.ModelManager()
        }

        self.initialized = True
Пример #2
0
 def __init__(
         self, env=None, controller=None, size=50, template=None, **kargs):
     self.env = env
     self.controller = controller
     self.cache_size = size
     self.template = template
     self.options = kargs
     self._header = headers.Headers()
     self.search_paths = [
         'application/view/templates',
         '{}/templates/jinja'.format(
             os.path.dirname(__file__).rsplit(os.sep, 1)[0]
         )
     ]
     if controller is not None:
         self.search_paths.append(
             'application/view/{}'.format(controller.name)
         )
Пример #3
0
    def __init__(self):
        TwistedResource.__init__(self)

        config = Application()

        # headers and render keys for root_page and index templates
        header = headers.Headers()
        self.render_keys = {
            'doctype': header.get_doctype(),
            'header': {
                'title': config.name,
                'content_type': header.content_type,
                'generator_content': header.get_generator_content(),
                'description_content': header.get_description_content(),
                'language_content': header.get_language_content(),
                'mamba_content': header.get_mamba_content(),
                'media': header.get_favicon_content('assets'),
                'styles': self._styles_manager.get_styles().values(),
                'scripts': self._scripts_manager.get_scripts().values(),
                'lessjs': Application().lessjs
            }
        }
Пример #4
0
    def __init__(self, template_paths=None, cache_size=50):
        TwistedResource.__init__(self)

        sep = filepath.os.sep
        self._templates = {}
        self.cache_size = cache_size
        self.template_paths = [
            'application/view/templates', '{}/templates/jinja'.format(
                filepath.os.path.dirname(__file__).rsplit(sep, 1)[0])
        ]
        if template_paths is not None:
            if type(template_paths) is str:
                self.template_paths.append(template_paths)
            elif type(template_paths) is list:
                self.template_paths + template_paths
            elif type(template_paths) is tuple:
                self.template_paths + list(template_paths)

        self.config = Application()

        # set resources managers
        self._styles_manager = appstyles.AppStyles()
        self._scripts_manager = scripts.Scripts()

        # headers and render keys for root_page and index templates
        header = headers.Headers()
        self.render_keys = {
            'doctype': header.get_doctype(),
            'header': {
                'title': self.config.name,
                'content_type': header.content_type,
                'generator_content': header.get_generator_content(),
                'description_content': header.get_description_content(),
                'language_content': header.get_language_content(),
                'mamba_content': header.get_mamba_content(),
                'media': header.get_favicon_content('assets'),
                'styles': self._styles_manager.get_styles().values(),
                'scripts': self._scripts_manager.get_scripts().values()
            }
        }

        # containers
        self.containers = {
            'styles': static.Data('', 'text/css'),
            'scripts': static.Data('', 'text/javascript')
        }

        # register containers
        self.putChild('styles', self.containers['styles'])
        self.putChild('scripts', self.containers['scripts'])

        # insert stylesheets
        self.insert_stylesheets()

        # insert scripts
        self.insert_scripts()

        # static accessible data (scripts, css, images, and others)
        self.putChild('assets', static.File(filepath.os.getcwd() + '/static'))

        # template environment
        self.environment = templating.Environment(
            autoescape=lambda name: (name.rsplit('.', 1)[1] == 'html'
                                     if name is not None else False),
            cache_size=self.cache_size,
            loader=templating.FileSystemLoader(self.template_paths))
Пример #5
0
 def setUp(self):
     self.headers = headers.Headers()