Exemplo n.º 1
0
import os
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

def setconf(name, default_value):
    value = getattr(settings, name, default_value)
    setattr(settings, name, value)

setconf('MFW_EMOJI_TRANSLATION_FILENAME', os.path.join(os.path.dirname(__file__), 'data', 'emoji4unicode.xml'))
setconf('MFW_EMOJI_DEFAULT_CARRIER', 'kddi_img')
setconf('MFW_EMOJI_DEFAULT_ENCODING', 'utf-8')

# Load e4u
import e4u
e4u.load(filename=settings.MFW_EMOJI_TRANSLATION_FILENAME)

# Validation
if 'mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware' in settings.MIDDLEWARE_CLASSES:
    found = False
    for middleware in settings.MIDDLEWARE_CLASSES:
        if middleware == 'mfw.middleware.encoding.DeviceEncodingMiddleware':
            found = True
        elif middleware == 'mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware' and not found:
            raise ImproperlyConfigured("``mfw.middleware.encoding.DeviceEncodingMiddleware`` must be in ``MIDDLEWARE_CLASSES`` before the ``mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware``")
Exemplo n.º 2
0
# Arguments
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true')
parser.add_argument('--host', type=str, required=True)
parser.add_argument('--port', type=int, required=True)
parser.add_argument('--service.backend_id', metavar="ID", type=int, required=True)
parser.add_argument('config', type=str)

args, unknown = parser.parse_known_args()

# Logging
logging.basicConfig( \
	format = "%(asctime)-15s %(levelname)s %(name)s: %(message)s", \
	level = logging.DEBUG if args.debug else logging.INFO \
)

# Handler
def handleTransportData(data):
	plugin.handleDataRead(data)

e4u.load()

# Main
db = MySQLdb.connect(DB_HOST, DB_USER, DB_PASS, DB_TABLE)
io = IOChannel(args.host, args.port, handleTransportData)

plugin = WhatsAppBackend(io, db)

asyncore.loop(1)
Exemplo n.º 3
0
 level = logging.DEBUG if args.debug else logging.INFO \
)


# Handler
def handleTransportData(data):
    try:
        plugin.handleDataRead(data)
    except SystemExit as e:
        raise e
    except:
        logger = logging.getLogger('transwhat')
        logger.error(traceback.format_exc())


e4u.load()

closed = False


def connectionClosed():
    global closed
    closed = True


# Main
io = IOChannel(args.host, args.port, handleTransportData, connectionClosed)

plugin = WhatsAppBackend(io, args.j)

plugin.handleBackendConfig({
Exemplo n.º 4
0
import os
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured


def setconf(name, default_value):
    value = getattr(settings, name, default_value)
    setattr(settings, name, value)


setconf('MFW_EMOJI_TRANSLATION_FILENAME',
        os.path.join(os.path.dirname(__file__), 'data', 'emoji4unicode.xml'))
setconf('MFW_EMOJI_DEFAULT_CARRIER', 'kddi_img')
setconf('MFW_EMOJI_DEFAULT_ENCODING', 'utf-8')

# Load e4u
import e4u

e4u.load(filename=settings.MFW_EMOJI_TRANSLATION_FILENAME)

# Validation
if 'mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware' in settings.MIDDLEWARE_CLASSES:
    found = False
    for middleware in settings.MIDDLEWARE_CLASSES:
        if middleware == 'mfw.middleware.encoding.DeviceEncodingMiddleware':
            found = True
        elif middleware == 'mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware' and not found:
            raise ImproperlyConfigured(
                "``mfw.middleware.encoding.DeviceEncodingMiddleware`` must be in ``MIDDLEWARE_CLASSES`` before the ``mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware``"
            )