# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):
# 
# Path: pyas2/as2utils.py
# def senderrorreport(message, errortext):
# def txtexc(mention_exception_type=True):
# def safe_unicode(value):
#     def __init__(self, msg, *args, **kwargs):
#     def __unicode__(self):
#     def __str__(self):
# def join(*paths):
# def dirshouldbethere(path):
# def opendata(filename, mode, charset=None, errors='strict'):
# def readdata(filename, charset=None, errors='strict'):
# def storefile(targetdir, filename, content, archive):
# def unescape_as2name(ename):
# def escape_as2name(uename):
# def extractpayload(message, **kwargs):
# def mimetostring(msg, headerlen):
# def extractpayload_fromstring1(msg, boundary):
# def extractpayload_fromstring2(msg, boundary):
# def canonicalize2(msg):
# def canonicalize(msg):
# def compress_payload(payload):
# def decompress_payload(payload):
# def encrypt_payload(payload, key, cipher):
# def decrypt_payload(payload, key, passphrase):
# def sign_payload(data, key, passphrase):
# def verify_payload(msg, raw_sig, cert, ca_cert, verify_cert):
# def get_key_passphrase(self):
# def check_binary_sig(signature, boundary, content):
# class AS2Error(Exception):
# class As2Exception(AS2Error):
# class As2DuplicateDocument(AS2Error):
# class As2PartnerNotFound(AS2Error):
# class As2InsufficientSecurity(AS2Error):
# class As2DecompressionFailed(AS2Error):
# class As2DecryptionFailed(AS2Error):
# class As2InvalidSignature(AS2Error):
# class CompressedDataAttr(univ.Sequence):
# class Content(univ.OctetString):
# class CompressedDataPayload(univ.Sequence):
# class CompressedData(univ.Sequence):
# class CompressedDataMain(univ.Sequence):


from django.db import models
from django.core.files.storage import FileSystemStorage
from django.utils.translation import ugettext as _
from django.db.models.signals import post_save
from django.dispatch import receiver
from pyas2 import pyas2init
from pyas2 import as2utils
import os

@receiver(post_save, sender=Organization)
def check_odirs(sender, instance, created, **kwargs):
    partners = Partner.objects.all()
    for partner in partners:
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', instance.as2_name, 'inbox', partner.as2_name))
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', partner.as2_name, 'outbox', instance.as2_name))


@receiver(post_save, sender=Partner)
def check_pdirs(sender, instance, created, **kwargs):
    orgs = Organization.objects.all()
    for org in orgs:
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', org.as2_name, 'inbox', instance.as2_name))
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', instance.as2_name, 'outbox', org.as2_name))


def update_dirs():
    partners = Partner.objects.all()
    orgs = Organization.objects.all()
    for partner in partners:
        for org in orgs:
            as2utils.dirshouldbethere(
                as2utils.join(pyas2init.gsettings['root_dir'], 'messages', org.as2_name, 'inbox', partner.as2_name))
    for org in orgs:
        for partner in partners:

# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):
# 
# Path: pyas2/as2utils.py
# def senderrorreport(message, errortext):
# def txtexc(mention_exception_type=True):
# def safe_unicode(value):
#     def __init__(self, msg, *args, **kwargs):
#     def __unicode__(self):
#     def __str__(self):
# def join(*paths):
# def dirshouldbethere(path):
# def opendata(filename, mode, charset=None, errors='strict'):
# def readdata(filename, charset=None, errors='strict'):
# def storefile(targetdir, filename, content, archive):
# def unescape_as2name(ename):
# def escape_as2name(uename):
# def extractpayload(message, **kwargs):
# def mimetostring(msg, headerlen):
# def extractpayload_fromstring1(msg, boundary):
# def extractpayload_fromstring2(msg, boundary):
# def canonicalize2(msg):
# def canonicalize(msg):
# def compress_payload(payload):
# def decompress_payload(payload):
# def encrypt_payload(payload, key, cipher):
# def decrypt_payload(payload, key, passphrase):
# def sign_payload(data, key, passphrase):
# def verify_payload(msg, raw_sig, cert, ca_cert, verify_cert):
# def get_key_passphrase(self):
# def check_binary_sig(signature, boundary, content):
# class AS2Error(Exception):
# class As2Exception(AS2Error):
# class As2DuplicateDocument(AS2Error):
# class As2PartnerNotFound(AS2Error):
# class As2InsufficientSecurity(AS2Error):
# class As2DecompressionFailed(AS2Error):
# class As2DecryptionFailed(AS2Error):
# class As2InvalidSignature(AS2Error):
# class CompressedDataAttr(univ.Sequence):
# class Content(univ.OctetString):
# class CompressedDataPayload(univ.Sequence):
# class CompressedData(univ.Sequence):
# class CompressedDataMain(univ.Sequence):


# Path: pyas2/models.py
from django.db import models
from django.core.files.storage import FileSystemStorage
from django.utils.translation import ugettext as _
from django.db.models.signals import post_save
from django.dispatch import receiver
from pyas2 import pyas2init
from pyas2 import as2utils
import os


@receiver(post_save, sender=Organization)
def check_odirs(sender, instance, created, **kwargs):
    partners = Partner.objects.all()
    for partner in partners:
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', instance.as2_name, 'inbox', partner.as2_name))
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', partner.as2_name, 'outbox', instance.as2_name))


@receiver(post_save, sender=Partner)
def check_pdirs(sender, instance, created, **kwargs):
    orgs = Organization.objects.all()
    for org in orgs:
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', org.as2_name, 'inbox', instance.as2_name))
        as2utils.dirshouldbethere(
            as2utils.join(pyas2init.gsettings['root_dir'], 'messages', instance.as2_name, 'outbox', org.as2_name))


def update_dirs():
    partners = Partner.objects.all()
    orgs = Organization.objects.all()
    for partner in partners:
        for org in orgs:
            as2utils.dirshouldbethere(
                as2utils.join(pyas2init.gsettings['root_dir'], 'messages', org.as2_name, 'inbox', partner.as2_name))
    for org in orgs:
        for partner in partners:

            as2utils.dirshouldbethere(