コード例 #1
0
ファイル: chat.py プロジェクト: openlabs/nereid-chat
    def stream_via_token(cls, token):
        '''
        Set token user to online and publish presence of this user to all
        friends.
        '''
        NereidUser = Pool().get('nereid.user')

        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(
                CONFIG.get('redis_host', 'localhost'),
                int(CONFIG.get('redis_port', 6379))
            )

        key = 'chat:token:%s' % token
        if not redis_client.exists(key):
            abort(404)

        nereid_user = NereidUser(int(redis_client.get(key)))
        nereid_user.broadcast_presence()

        return Response(
            cls.generate_event_stream(
                nereid_user.id,
                Transaction().cursor.dbname
            ),
            mimetype='text/event-stream'
        )
コード例 #2
0
 def _get_es_connection():
     """
     Return a PYES connection
     """
     return ES(
         CONFIG.get('elastic_search_server', 'localhost:9200').split(',')
     )
コード例 #3
0
ファイル: chat.py プロジェクト: openlabs/nereid-chat
    def token(cls):
        '''
        Generate token for current_user with TTL of 1 hr.
        '''
        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(
                CONFIG.get('redis_host', 'localhost'),
                int(CONFIG.get('redis_port', 6379))
            )

        token = unicode(uuid.uuid4())
        key = 'chat:token:%s' % token
        # Save token to redis and set TTL of 1 hr.
        redis_client.set(key, current_user.id)
        redis_client.expire(key, 3600)

        return jsonify({
            'token': token
        })
コード例 #4
0
    def stream_via_token(cls, token):
        '''
        Set token user to online and publish presence of this user to all
        friends.
        '''
        NereidUser = Pool().get('nereid.user')

        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(CONFIG.get('redis_host', 'localhost'),
                                 int(CONFIG.get('redis_port', 6379)))

        key = 'chat:token:%s' % token
        if not redis_client.exists(key):
            abort(404)

        nereid_user = NereidUser(int(redis_client.get(key)))
        nereid_user.broadcast_presence()

        return Response(cls.generate_event_stream(nereid_user.id,
                                                  Transaction().cursor.dbname),
                        mimetype='text/event-stream')
コード例 #5
0
ファイル: server.py プロジェクト: silpol/tryton-bef
    def start_servers(self):
        # Launch Server
        for proto, _class in protocols.PROTOCOLS.iteritems():
            if proto not in CONFIG.options or not CONFIG[proto]:
                continue
            ssl_config = CONFIG.get('ssl_%s' % proto, False)
            for hostname, port in CONFIG[proto]:
                self.servers[proto].append(_class(hostname, port, ssl_config))
                self.logger.info("starting %s%s protocol on %s:%d" %
                    (proto.upper(), ssl_config and ' SSL' or '', hostname or '*',
                        port))

        for proto, servers in self.servers.iteritems():
            for server in servers:
                server.start()
コード例 #6
0
ファイル: party.py プロジェクト: PritishC/nereid-webshop
from trytond.pool import PoolMeta, Pool
from trytond.modules.nereid.party import AddressForm
from trytond.config import CONFIG
from nereid import request, current_app

__metaclass__ = PoolMeta
__all__ = ['Address']

geoip = None
try:
    from pygeoip import GeoIP
except ImportError:
    logging.error("pygeoip is not installed")
else:
    path = os.environ.get('GEOIP_DATA_PATH', CONFIG.get('geoip_data_path'))
    if path:
        geoip = GeoIP(path)


class WebshopAddressForm(AddressForm):
    """Custom address form for webshop
    """
    def get_default_country(self):
        """Get the default country based on geoip data.
        """
        if not geoip:
            return None

        Country = Pool().get('country.country')
        try:
コード例 #7
0
 def default_servers():
     """
     Find the server from config and return
     """
     return CONFIG.get('elastic_search_server', 'localhost:9200')
コード例 #8
0
 def default_servers():
     """
     Find the server from config and return
     """
     return CONFIG.get('elastic_search_server', 'localhost:9200')
コード例 #9
0
from trytond.pool import PoolMeta, Pool
from trytond.modules.nereid.party import AddressForm
from trytond.config import CONFIG
from nereid import request, current_app

__metaclass__ = PoolMeta
__all__ = ['Address']

geoip = None
try:
    from pygeoip import GeoIP
except ImportError:
    logging.error("pygeoip is not installed")
else:
    path = os.environ.get('GEOIP_DATA_PATH', CONFIG.get('geoip_data_path'))
    if path:
        geoip = GeoIP(path)


class WebshopAddressForm(AddressForm):
    """Custom address form for webshop
    """
    def get_default_country(self):
        """Get the default country based on geoip data.
        """
        if not geoip:
            return None

        Country = Pool().get('country.country')
        try: