예제 #1
0
from __future__ import unicode_literals
from functools import wraps

from prosodypy import lua

assert lua

import os
config = lua.require("core.configmanager")
settings_module = config.get("*", "django_settings_module")
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
import django
django.setup()

from django.db import connections


def db_connect(func, using='default'):
    @wraps(func)
    def inner(*args, **kwargs):
        connection = connections[using]
        connection.close_if_unusable_or_obsolete()
        connection.ensure_connection()
        return func(*args, **kwargs)

    return inner
예제 #2
0
xmlstream = FakeStream()

def parse_string(stanza):
    xmlstream.dataReceived(stanza.encode('utf-8'))
    result = xmlstream.resulted_element
    assert result is not None
    xmlstream.resulted_element = None
    return result

def parse_prosody_stanza(stanza):
    assert lua is not None
    return parse_string(lua.eval('tostring(...)', stanza))

if lua:
    Stanza = lua.require("util.stanza").stanza
def build_prosody_stanza(element, current_ns=None, current_tag=None):
    name = element.name
    attrs = copy(element.attributes)
    if element.uri != current_ns:
        attrs['xmlns'] = element.uri
        current_ns = element.uri
    added_tag = False
    if current_tag is None:
        current_tag = Stanza(name, lua.table_from(attrs))
    else:
        current_tag.tag(current_tag, name, lua.table_from(attrs))
        added_tag = True
    for child in element.children:
        if isinstance(child, unicode):
            current_tag.text(current_tag, child)
예제 #3
0
def parse_string(stanza):
    xmlstream = FakeStream()
    xmlstream.dataReceived(stanza.encode('utf-8'))
    result = xmlstream.resulted_element
    assert result is not None
    xmlstream.resulted_element = None
    xmlstream.connectionLost('')
    return result


def parse_prosody_stanza(stanza):
    assert lua is not None
    return parse_string(lua.eval('tostring(...)', stanza))

if lua:
    Stanza = lua.require("util.stanza").stanza


def build_prosody_stanza(element, current_ns=None, current_tag=None):
    name = element.name
    attrs = copy(element.attributes)
    if element.uri != current_ns:
        attrs['xmlns'] = element.uri
        current_ns = element.uri
    added_tag = False
    if current_tag is None:
        current_tag = Stanza(name, lua.table_from(attrs))
    else:
        current_tag.tag(current_tag, name, lua.table_from(attrs))
        added_tag = True
    for child in element.children:
예제 #4
0
from functools import wraps

from prosodypy import lua

assert lua

import os
config = lua.require("core.configmanager")
settings_module = config.get("*", "django_settings_module")
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
import django
django.setup()

from django.db import connections

def db_connect(func, using='default'):
    @wraps(func)
    def inner(*args, **kwargs):
        connection = connections[using]
        connection.close_if_unusable_or_obsolete()
        connection.ensure_connection()
        return func(*args, **kwargs)
    return inner