#! /usr/bin/env python
# $Header$
'''Faults.
'''

from pysphere.ZSI import _get_idstr, _seqtypes, SoapWriter, ZSIException

from pysphere.ZSI.TCcompound import Struct
from pysphere.ZSI.TC import QName, URI, String, AnyElement, UNBOUNDED

from pysphere.ZSI.wstools.Namespaces import SOAP, ZSI_SCHEMA_URI
from pysphere.ZSI.TC import ElementDeclaration

import traceback


class Detail:
    def __init__(self, _any=None):
        self.any = _any

Detail.typecode = Struct(Detail, [AnyElement(aname='any',minOccurs=0, maxOccurs="unbounded",processContents="lax")], pname='detail', minOccurs=0)

class FaultType:
    def __init__(self, faultcode=None, faultstring=None, faultactor=None, detail=None):
        self.faultcode = faultcode
        self.faultstring= faultstring
        self.faultactor = faultactor
        self.detail = detail

FaultType.typecode = \
    Struct(FaultType,
        [QName(pname='faultcode'),
         String(pname='faultstring'),
         URI(pname=(SOAP.ENV,'faultactor'), minOccurs=0),
         Detail.typecode,
         AnyElement(aname='any',minOccurs=0, maxOccurs=UNBOUNDED, processContents="lax"),
        ],
        pname=(SOAP.ENV,'Fault'),
        inline=True,
        hasextras=0,
    )

class ZSIHeaderDetail:
    def __init__(self, detail):
        self.any = detail

ZSIHeaderDetail.typecode =\
    Struct(ZSIHeaderDetail,
           [AnyElement(aname='any', minOccurs=0, maxOccurs=UNBOUNDED, processContents="lax")],
           pname=(ZSI_SCHEMA_URI, 'detail'))


class ZSIFaultDetailTypeCode(ElementDeclaration, Struct):
    '''<ZSI:FaultDetail>
           <ZSI:string>%s</ZSI:string>
           <ZSI:trace>%s</ZSI:trace>
       </ZSI:FaultDetail>
    '''
    schema = ZSI_SCHEMA_URI
    literal = 'FaultDetail'
    def __init__(self, **kw):
        Struct.__init__(self, ZSIFaultDetail, [String(pname=(ZSI_SCHEMA_URI, 'string')),
            String(pname=(ZSI_SCHEMA_URI, 'trace'),minOccurs=0),],
            pname=(ZSI_SCHEMA_URI, 'FaultDetail'), **kw
        )

class ZSIFaultDetail:
    def __init__(self, string=None, trace=None):
        self.string = string
        self.trace = trace

    def __str__(self):
        if self.trace:
            return self.string + '\n[trace: ' + self.trace + ']'
        return self.string

    def __repr__(self):
        return "<%s.ZSIFaultDetail %s>" % (__name__, _get_idstr(self))
ZSIFaultDetail.typecode = ZSIFaultDetailTypeCode()


class URIFaultDetailTypeCode(ElementDeclaration, Struct):
    '''
    <ZSI:URIFaultDetail>
        <ZSI:URI>uri</ZSI:URI>
        <ZSI:localname>localname</ZSI:localname>
    </ZSI:URIFaultDetail>
    '''
    schema = ZSI_SCHEMA_URI
    literal = 'URIFaultDetail'
    def __init__(self, **kw):
        Struct.__init__(self, URIFaultDetail,
           [String(pname=(ZSI_SCHEMA_URI, 'URI')), String(pname=(ZSI_SCHEMA_URI, 'localname')),],
            pname=(ZSI_SCHEMA_URI, 'URIFaultDetail'), **kw
        )

class URIFaultDetail:
    def __init__(self, uri=None, localname=None):
        self.URI = uri
        self.localname = localname
URIFaultDetail.typecode = URIFaultDetailTypeCode()


class ActorFaultDetailTypeCode(ElementDeclaration, Struct):
    '''
    <ZSI:ActorFaultDetail>