<s> '''<STR_LIT>''' <EOL> import datetime , re <EOL> from arelle import ( XPathContext , ModelValue ) <EOL> from arelle . FunctionUtil import ( anytypeArg , atomicArg , stringArg , numericArg , qnameArg , nodeArg ) <EOL> from arelle . XPathParser import ProgHeader <EOL> from math import isnan , fabs , isinf <EOL> from decimal import Decimal , InvalidOperation <EOL> class FORG0001 ( Exception ) : <EOL> def __init__ ( self , message = None ) : <EOL> self . message = message <EOL> self . args = ( self . __repr__ ( ) , ) <EOL> def __repr__ ( self ) : <EOL> return _ ( "<STR_LIT>" ) <EOL> class FONS0004 ( Exception ) : <EOL> def __init__ ( self , message = None ) : <EOL> self . message = message <EOL> self . args = ( self . __repr__ ( ) , ) <EOL> def __repr__ ( self ) : <EOL> return _ ( "<STR_LIT>" ) <EOL> class xsFunctionNotAvailable ( Exception ) : <EOL> def __init__ ( self ) : <EOL> self . args = ( _ ( "<STR_LIT>" ) , ) <EOL> def __repr__ ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] <EOL> def call ( xc , p , localname , args ) : <EOL> source = atomicArg ( xc , p , args , <NUM_LIT:0> , "<STR_LIT>" , missingArgFallback = ( ) ) <EOL> if source == ( ) : return source <EOL> try : <EOL> if localname not in xsFunctions : raise xsFunctionNotAvailable <EOL> return xsFunctions [ localname ] ( xc , p , source ) <EOL> except ( FORG0001 , ValueError , TypeError ) as ex : <EOL> if hasattr ( ex , "<STR_LIT:message>" ) and ex . message : <EOL> exMsg = "<STR_LIT:U+002CU+0020>" + ex . message <EOL> else : <EOL> exMsg = "<STR_LIT>" <EOL> raise XPathContext . XPathException ( p , '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) . format ( <EOL> type ( source ) . __name__ , <EOL> localname , <EOL> exMsg ) ) <EOL> except xsFunctionNotAvailable : <EOL> raise XPathContext . FunctionNotAvailable ( "<STR_LIT>" . format ( localname ) ) <EOL> objtype = { <EOL> '<STR_LIT>' : ModelValue . DateTime , <EOL> '<STR_LIT:date>' : ModelValue . DateTime , <EOL> '<STR_LIT:time>' : ModelValue . Time , <EOL> '<STR_LIT>' : ModelValue . YearMonthDuration , <EOL> '<STR_LIT>' : ModelValue . DayTimeDuration , <EOL> '<STR_LIT:float>' : float , <EOL> '<STR_LIT>' : float , <EOL> '<STR_LIT>' : Decimal , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT:int>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT>' : _INT , <EOL> '<STR_LIT:string>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT:Name>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : bool , <EOL> '<STR_LIT>' : ModelValue . AnyURI , <EOL> '<STR_LIT>' : ModelValue . QName , <EOL> '<STR_LIT>' : str , <EOL> } <EOL> def isXsType ( localName ) : <EOL> if localName [ - <NUM_LIT:1> ] in ( '<STR_LIT:?>' , '<STR_LIT:+>' , '<STR_LIT:*>' ) : <EOL> return localName [ : - <NUM_LIT:1> ] in xsFunctions <EOL> return localName in xsFunctions <EOL> def untypedAtomic ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def anyType ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def anyAtomicType ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def dateTime ( xc , p , source ) : <EOL> if isinstance ( source , datetime . datetime ) : return source <EOL> return ModelValue . dateTime ( source , type = ModelValue . DATETIME , castException = FORG0001 ) <EOL> def dateTimeInstantEnd ( xc , p , source ) : <EOL> if isinstance ( source , datetime . datetime ) : return source <EOL> return ModelValue . dateTime ( source , addOneDay = True , type = ModelValue . DATETIME , castException = FORG0001 ) <EOL> def xbrliDateUnion ( xc , p , source ) : <EOL> if isinstance ( source , datetime . date ) : return source <EOL> return ModelValue . dateTime ( source , type = ModelValue . DATEUNION , castException = FORG0001 ) <EOL> def date ( xc , p , source ) : <EOL> return ModelValue . dateTime ( source , type = ModelValue . DATE , castException = FORG0001 ) <EOL> def time ( xc , p , source ) : <EOL> return ModelValue . time ( source , castException = FORG0001 ) <EOL> def duration ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def yearMonthDuration ( xc , p , source ) : <EOL> return ModelValue . yearMonthDuration ( source ) <EOL> def dayTimeDuration ( xc , p , source ) : <EOL> return ModelValue . dayTimeDuration ( source ) <EOL> def xs_float ( xc , p , source ) : <EOL> try : <EOL> return float ( source ) <EOL> except ValueError : <EOL> raise FORG0001 <EOL> def double ( xc , p , source ) : <EOL> try : <EOL> return float ( source ) <EOL> except ValueError : <EOL> raise FORG0001 <EOL> def decimal ( xc , p , source ) : <EOL> try : <EOL> return Decimal ( source ) <EOL> except InvalidOperation : <EOL> raise FORG0001 <EOL> def integer ( xc , p , source ) : <EOL> try : <EOL> return _INT ( source ) <EOL> except ValueError : <EOL> raise FORG0001 <EOL> def nonPositiveInteger ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def negativeInteger ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i < <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def long ( xc , p , source ) : <EOL> try : <EOL> return _INT ( source ) <EOL> except ValueError : <EOL> raise FORG0001 <EOL> def xs_int ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT> and i >= - <NUM_LIT> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def short ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT> and i >= - <NUM_LIT> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def byte ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT> and i >= - <NUM_LIT> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def nonNegativeInteger ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i >= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def unsignedLong ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i >= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def unsignedInt ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT> and i >= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def unsignedShort ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT> and i >= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def unsignedByte ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i <= <NUM_LIT:255> and i >= <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def positiveInteger ( xc , p , source ) : <EOL> try : <EOL> i = _INT ( source ) <EOL> if i > <NUM_LIT:0> : return i <EOL> except ValueError : <EOL> pass <EOL> raise FORG0001 <EOL> def gYearMonth ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def gYear ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def gMonthDay ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def gDay ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def gMonth ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def xsString ( xc , p , source ) : <EOL> if isinstance ( source , bool ) : <EOL> return '<STR_LIT:true>' if source else '<STR_LIT:false>' <EOL> elif isinstance ( source , float ) : <EOL> if isnan ( source ) : <EOL> return "<STR_LIT>" <EOL> elif isinf ( source ) : <EOL> return "<STR_LIT>" if source < <NUM_LIT:0> else "<STR_LIT>" <EOL> '''<STR_LIT>''' <EOL> s = str ( source ) <EOL> if s . endswith ( "<STR_LIT>" ) : <EOL> s = s [ : - <NUM_LIT:2> ] <EOL> return s <EOL> elif isinstance ( source , Decimal ) : <EOL> if isnan ( source ) : <EOL> return "<STR_LIT>" <EOL> elif isinf ( source ) : <EOL> return "<STR_LIT>" if source < <NUM_LIT:0> else "<STR_LIT>" <EOL> return str ( source ) <EOL> elif isinstance ( source , ModelValue . DateTime ) : <EOL> return ( '<STR_LIT>' if source . dateOnly else '<STR_LIT>' ) . format ( source ) <EOL> return str ( source ) <EOL> def normalizedString ( xc , p , source ) : <EOL> return str ( source ) <EOL> tokenPattern = re . compile ( r"<STR_LIT>" ) <EOL> def token ( xc , p , source ) : <EOL> s = str ( source ) <EOL> if tokenPattern . match ( s ) : return s <EOL> raise FORG0001 <EOL> languagePattern = re . compile ( "<STR_LIT>" ) <EOL> def language ( xc , p , source ) : <EOL> s = str ( source ) <EOL> if languagePattern . match ( s ) : return s <EOL> raise FORG0001 <EOL> def NMTOKEN ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def Name ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def NCName ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def ID ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def IDREF ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def ENTITY ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def boolean ( xc , p , source ) : <EOL> if isinstance ( source , bool ) : <EOL> return source <EOL> elif isinstance ( source , _NUM_TYPES ) : <EOL> if source == <NUM_LIT:1> : <EOL> return True <EOL> elif source == <NUM_LIT:0> : <EOL> return False <EOL> elif isinstance ( source , str ) : <EOL> b = source . lower ( ) <EOL> if b in ( '<STR_LIT:true>' , '<STR_LIT:yes>' ) : <EOL> return True <EOL> elif b in ( '<STR_LIT:false>' , '<STR_LIT>' ) : <EOL> return False <EOL> raise FORG0001 <EOL> def base64Binary ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def hexBinary ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> def anyURI ( xc , p , source ) : <EOL> return ModelValue . anyURI ( source ) <EOL> def QName ( xc , p , source ) : <EOL> if isinstance ( p , ProgHeader ) : <EOL> element = p . element <EOL> elif xc . progHeader : <EOL> element = xc . progHeader . element <EOL> else : <EOL> element = xc . sourceElement <EOL> return ModelValue . qname ( element , source , castException = FORG0001 , prefixException = FONS0004 ) <EOL> def NOTATION ( xc , p , source ) : <EOL> raise xsFunctionNotAvailable ( ) <EOL> xsFunctions = { <EOL> '<STR_LIT>' : untypedAtomic , <EOL> '<STR_LIT>' : anyType , <EOL> '<STR_LIT>' : anyAtomicType , <EOL> '<STR_LIT>' : dateTime , <EOL> '<STR_LIT>' : dateTime , <EOL> '<STR_LIT>' : dateTimeInstantEnd , <EOL> '<STR_LIT>' : xbrliDateUnion , <EOL> '<STR_LIT:date>' : date , <EOL> '<STR_LIT:time>' : time , <EOL> '<STR_LIT>' : duration , <EOL> '<STR_LIT>' : yearMonthDuration , <EOL> '<STR_LIT>' : dayTimeDuration , <EOL> '<STR_LIT:float>' : xs_float , <EOL> '<STR_LIT>' : double , <EOL> '<STR_LIT>' : decimal , <EOL> '<STR_LIT>' : integer , <EOL> '<STR_LIT>' : nonPositiveInteger , <EOL> '<STR_LIT>' : negativeInteger , <EOL> '<STR_LIT>' : long , <EOL> '<STR_LIT:int>' : xs_int , <EOL> '<STR_LIT>' : short , <EOL> '<STR_LIT>' : byte , <EOL> '<STR_LIT>' : nonNegativeInteger , <EOL> '<STR_LIT>' : unsignedLong , <EOL> '<STR_LIT>' : unsignedInt , <EOL> '<STR_LIT>' : unsignedShort , <EOL> '<STR_LIT>' : unsignedByte , <EOL> '<STR_LIT>' : positiveInteger , <EOL> '<STR_LIT>' : gYearMonth , <EOL> '<STR_LIT>' : gYear , <EOL> '<STR_LIT>' : gMonthDay , <EOL> '<STR_LIT>' : gDay , <EOL> '<STR_LIT>' : gMonth , <EOL> '<STR_LIT:string>' : xsString , <EOL> '<STR_LIT>' : normalizedString , <EOL> '<STR_LIT>' : token , <EOL> '<STR_LIT>' : language , <EOL> '<STR_LIT>' : NMTOKEN , <EOL> '<STR_LIT:Name>' : Name , <EOL> '<STR_LIT>' : NCName , <EOL> '<STR_LIT>' : ID , <EOL> '<STR_LIT>' : IDREF , <EOL> '<STR_LIT>' : ENTITY , <EOL> '<STR_LIT>' : boolean , <EOL> '<STR_LIT>' : base64Binary , <EOL> '<STR_LIT>' : hexBinary , <EOL> '<STR_LIT>' : anyURI , <EOL> '<STR_LIT>' : QName , <EOL> '<STR_LIT>' : NOTATION , <EOL> } </s>
