Ejemplo n.º 1
0
 def listen(self, address, port):
     # Language negotiation
     init_language_selector(select_language)
     # Add handlers
     super(WebServer, self).listen(address, port)
     self.add_handler('*', self.star_callback)
     # Say hello
     address = address if address is not None else '*'
     print 'Listen %s:%d' % (address, port)
Ejemplo n.º 2
0
 def listen(self, address, port):
     # Language negotiation
     init_language_selector(select_language)
     # Add handlers
     super(WebServer, self).listen(address, port)
     self.add_handler('*', self.star_callback)
     # Say hello
     address = address if address is not None else '*'
     print 'Listen %s:%d' % (address, port)
Ejemplo n.º 3
0
    def start(self):
        # Language negotiation
        from itools.web import select_language
        init_language_selector(select_language)

        # Graceful stop
        signal(SIGINT, self.stop_gracefully)
        signal(SIGTERM, self.zap)
        if self.pid_file:
            pid = getpid()
            open(self.pid_file, 'w').write(str(pid))

        # Run
        SoupServer.start(self)
        print 'Listen %s:%d' % (self.address, self.port)
        if self.profile:
            runctx("self.main_loop.run()", globals(), locals(), self.profile)
        else:
            self.main_loop.run()
Ejemplo n.º 4
0
    def start(self):
        # Language negotiation
        from itools.web import select_language
        init_language_selector(select_language)

        # Graceful stop
        signal(SIGINT, self.stop_gracefully)
        signal(SIGTERM, self.zap)
        if self.pid_file:
            pid = getpid()
            open(self.pid_file, 'w').write(str(pid))

        # Run
        SoupServer.start(self)
        print 'Listen %s:%d' % (self.address, self.port)
        if self.profile:
            runctx("self.main_loop.run()", globals(), locals(), self.profile)
        else:
            self.main_loop.run()
Ejemplo n.º 5
0
 def listen(self, address, port):
     # Language negotiation
     init_language_selector(select_language)
     # Say hello
     address = address if address is not None else '*'
     print 'Listen %s:%d' % (address, port)
     msg = 'Listing at port %s' % port
     log_info(msg)
     self.port = port
     # Say hello
     address = address if address is not None else '*'
     msg = 'Listen %s:%d' % (address, port)
     log_info(msg)
     self.port = port
     self.wsgi_server = WSGIServer(
         ('', port), application,
         handler_class=ServerHandler,
         log=self.access_log)
     gevent_signal(SIGTERM, self.stop)
     gevent_signal(SIGINT, self.stop)
     if self.profile:
         runctx("self.wsgi_server.serve_forever()", globals(), locals(), self.profile)
     else:
         self.wsgi_server.serve_forever()
Ejemplo n.º 6
0
    the list of available languages. Returns the first user pref.  language
    that is available, if none is available returns None.
    """
    request = get_request()
    if request is None:
        return None

    try:
        accept = request['AcceptLanguage']
    except KeyError:
        return None

    return accept.select_language(available_languages)


init_language_selector(lang_negotiator)


###########################################################################
# Provide an API to access translations stored as MO files in the 'locale'
# directory.
###########################################################################
class DomainAware(object):

    def __init__(self, namespace):
        mname = namespace['__name__']
        domain = get_abspath('locale', mname=mname)
        self.class_domain = domain
        register_domain(domain, domain)

Ejemplo n.º 7
0
    the list of available languages. Returns the first user pref.  language
    that is available, if none is available returns None.
    """
    request = get_request()
    if request is None:
        return None

    try:
        accept = request['AcceptLanguage']
    except KeyError:
        return None

    return accept.select_language(available_languages)


init_language_selector(lang_negotiator)


###########################################################################
# Provide an API to access translations stored as MO files in the 'locale'
# directory.
###########################################################################
class DomainAware(object):
    def __init__(self, namespace):
        mname = namespace['__name__']
        domain = get_abspath('locale', mname=mname)
        self.class_domain = domain
        register_domain(domain, domain)

    def gettext(self, message, language=None):
        domain = get_domain(self.class_domain)