<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import sys <EOL> import math <EOL> import warnings <EOL> from numbers import Number <EOL> from . plugins import Plugin <EOL> from . types . matching import TypeMatcher , MatchAny <EOL> from . types . system import TypeSystem <EOL> from . utils import indent , expand_default_args , isclassdesc , isfuncdesc , isvardesc , newoverwrite , sortedbytype , _lang_exts , Arg <EOL> from . version import cython_version , cython_version_info <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> basestring = str <EOL> MATCH_REF = TypeMatcher ( ( MatchAny , '<STR_LIT:&>' ) ) <EOL> AUTOGEN_WARNING = """<STR_LIT>""" <EOL> def gencpppxd ( env , exceptions = True , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> cpppxds = { } <EOL> for name , mod in env . items ( ) : <EOL> if mod [ '<STR_LIT>' ] is None : <EOL> continue <EOL> cpppxds [ name ] = modcpppxd ( mod , exceptions , ts = ts ) <EOL> return cpppxds <EOL> def _addotherclsnames ( t , classes , name , others , ts ) : <EOL> if t is None or t == ( None , '<STR_LIT:*>' ) : <EOL> return <EOL> spt = ts . strip_predicates ( t ) <EOL> if spt in classes : <EOL> others [ name ] . add ( spt ) <EOL> elif ts . isfunctionpointer ( spt ) : <EOL> for subt in spt [ <NUM_LIT:1> : ] : <EOL> spsubt = ts . strip_predicates ( subt ) <EOL> if spsubt in classes : <EOL> others [ name ] . add ( spsubt ) <EOL> def cpppxd_sorted_names ( mod , ts ) : <EOL> """<STR_LIT>""" <EOL> classes = set ( [ name for name , desc in mod . items ( ) if isclassdesc ( desc ) ] ) <EOL> clssort = sorted ( c for c in classes if isinstance ( c , basestring ) ) <EOL> clssort += sorted ( c for c in classes if not isinstance ( c , basestring ) ) <EOL> othercls = { } <EOL> for name in clssort : <EOL> desc = mod [ name ] <EOL> othercls [ name ] = set ( ) <EOL> for pitem in desc [ '<STR_LIT>' ] : <EOL> _addotherclsnames ( pitem , classes , name , othercls , ts ) <EOL> for aname , atype in desc [ '<STR_LIT>' ] . items ( ) : <EOL> _addotherclsnames ( atype , classes , name , othercls , ts ) <EOL> for mkey , mval in desc [ '<STR_LIT>' ] . items ( ) : <EOL> mname , margs = mkey [ <NUM_LIT:0> ] , mkey [ <NUM_LIT:1> : ] <EOL> _addotherclsnames ( mval [ '<STR_LIT>' ] , classes , name , othercls , ts ) <EOL> for marg in margs : <EOL> _addotherclsnames ( marg [ <NUM_LIT:1> ] , classes , name , othercls , ts ) <EOL> clssort . sort ( key = lambda x : len ( othercls [ x ] ) ) <EOL> names = clssort [ : <NUM_LIT:1> ] <EOL> for name in clssort [ <NUM_LIT:1> : ] : <EOL> if name in names : <EOL> continue <EOL> for i , n in enumerate ( names [ : ] ) : <EOL> if name in othercls [ n ] : <EOL> names . insert ( i , name ) <EOL> break <EOL> if othercls [ name ] <= set ( names [ : i + <NUM_LIT:1> ] + [ name ] ) : <EOL> names . insert ( i + <NUM_LIT:1> , name ) <EOL> break <EOL> else : <EOL> names . append ( name ) <EOL> names += sortedbytype ( [ name for name , desc in mod . items ( ) if isvardesc ( desc ) ] ) <EOL> names += sortedbytype ( [ name for name , desc in mod . items ( ) if isfuncdesc ( desc ) ] ) <EOL> return names <EOL> def modcpppxd ( mod , exceptions = True , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> m = { '<STR_LIT>' : mod . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> "<STR_LIT>" : mod . get ( "<STR_LIT>" , "<STR_LIT>" ) } <EOL> attrs = [ ] <EOL> cimport_tups = set ( ) <EOL> classnames = _classnames_in_mod ( mod , ts ) <EOL> with ts . local_classes ( classnames , frozenset ( [ '<STR_LIT:c>' ] ) ) : <EOL> for name in cpppxd_sorted_names ( mod , ts ) : <EOL> desc = mod [ name ] <EOL> incfiles = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> if <NUM_LIT:0> == len ( incfiles ) : <EOL> msg = "<STR_LIT>" <EOL> raise ValueError ( msg . format ( name ) ) <EOL> elif <NUM_LIT:1> < len ( incfiles ) : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg . format ( name , incfiles [ <NUM_LIT:0> ] ) , RuntimeWarning ) <EOL> if isvardesc ( desc ) : <EOL> ci_tup , attr_str = varcpppxd ( desc , exceptions , ts ) <EOL> elif isfuncdesc ( desc ) : <EOL> ci_tup , attr_str = funccpppxd ( desc , exceptions , ts ) <EOL> elif isclassdesc ( desc ) : <EOL> ci_tup , attr_str = classcpppxd ( desc , exceptions , ts ) <EOL> else : <EOL> continue <EOL> cimport_tups |= ci_tup <EOL> attrs . append ( attr_str ) <EOL> if mod . get ( '<STR_LIT>' , None ) == '<STR_LIT:c>' : <EOL> cimport_tups . discard ( ( ts . stlcontainers , ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( sorted ( ts . cython_cimport_lines ( cimport_tups ) ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( attrs ) <EOL> t = '<STR_LIT>' . join ( [ AUTOGEN_WARNING , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> cpppxd = t . format ( ** m ) <EOL> return cpppxd <EOL> _cpppxd_var_template = """<STR_LIT>""" <EOL> def varcpppxd ( desc , exceptions = True , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> t = ts . canon ( desc [ '<STR_LIT:type>' ] ) <EOL> d = { '<STR_LIT:name>' : desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : _format_ns ( desc ) , <EOL> } <EOL> inc = set ( [ '<STR_LIT:c>' ] ) <EOL> cimport_tups = set ( ) <EOL> ts . cython_cimport_tuples ( t , cimport_tups , inc ) <EOL> vlines = [ ] <EOL> if ts . isenum ( t ) : <EOL> vlines . append ( "<STR_LIT>" . format ( d [ '<STR_LIT:name>' ] ) ) <EOL> enames = [ name for name , val in t [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] [ <NUM_LIT:2> ] ] <EOL> vlines += indent ( enames , <NUM_LIT:4> , join = False ) <EOL> else : <EOL> ct = ts . cython_ctype ( t ) <EOL> vlines . append ( "<STR_LIT>" . format ( ct , d [ '<STR_LIT:name>' ] ) ) <EOL> d [ '<STR_LIT>' ] = indent ( vlines , <NUM_LIT:4> ) <EOL> if <NUM_LIT:0> == len ( d [ '<STR_LIT>' ] . strip ( ) ) : <EOL> return set ( ) , '<STR_LIT>' <EOL> d [ '<STR_LIT>' ] = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> cpppxd = _cpppxd_var_template . format ( ** d ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in extra : <EOL> ext = _lang_exts [ name . language ] <EOL> extra [ '<STR_LIT>' ] = '<STR_LIT>' . format ( ext , d [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> return cimport_tups , cpppxd <EOL> _cpppxd_func_template = """<STR_LIT>""" <EOL> def funccpppxd ( desc , exceptions = True , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> d = { '<STR_LIT:name>' : desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : _format_ns ( desc ) , <EOL> } <EOL> inc = set ( [ '<STR_LIT:c>' ] ) <EOL> cimport_tups = set ( ) <EOL> flines = [ ] <EOL> funcitems = sorted ( expand_default_args ( desc [ '<STR_LIT>' ] . items ( ) ) ) <EOL> for fkey , frtn in funcitems : <EOL> fname , fargs = fkey [ <NUM_LIT:0> ] , fkey [ <NUM_LIT:1> : ] <EOL> fbasename = fname if isinstance ( fname , basestring ) else fname [ <NUM_LIT:0> ] <EOL> cppname = ts . cpp_funcname ( fname ) <EOL> cyname = ts . cython_funcname ( fname ) <EOL> if fbasename . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> if any ( [ a [ <NUM_LIT:1> ] is None or a [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] is None for a in fargs + ( frtn , ) ] ) : <EOL> continue <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( [ ts . cython_ctype ( a [ <NUM_LIT:1> ] ) for a in fargs ] ) <EOL> for a in fargs : <EOL> ts . cython_cimport_tuples ( a [ <NUM_LIT:1> ] , cimport_tups , inc ) <EOL> estr = _exception_str ( exceptions , desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] , frtn , ts ) <EOL> if fname == cppname == cyname : <EOL> line = "<STR_LIT>" . format ( fname , argfill , estr ) <EOL> else : <EOL> line = '<STR_LIT>' . format ( cyname , cppname , argfill , estr ) <EOL> rtype = ts . cython_ctype ( frtn ) <EOL> ts . cython_cimport_tuples ( frtn , cimport_tups , inc ) <EOL> line = rtype + "<STR_LIT:U+0020>" + line <EOL> if line not in flines : <EOL> flines . append ( line ) <EOL> d [ '<STR_LIT>' ] = indent ( flines , <NUM_LIT:4> ) <EOL> if <NUM_LIT:0> == len ( d [ '<STR_LIT>' ] . strip ( ) ) : <EOL> return set ( ) , '<STR_LIT>' <EOL> d [ '<STR_LIT>' ] = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> cpppxd = _cpppxd_func_template . format ( ** d ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in extra : <EOL> extra [ '<STR_LIT>' ] = '<STR_LIT>' . format ( d [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> return cimport_tups , cpppxd <EOL> _cpppxd_class_template = """<STR_LIT>""" <EOL> def classcpppxd ( desc , exceptions = True , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> src_lang = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> pars = '<STR_LIT:U+002CU+0020>' . join ( [ ts . cython_ctype ( p ) for p in desc [ '<STR_LIT>' ] ] ) <EOL> d = { '<STR_LIT>' : '<STR_LIT:(>' + pars + '<STR_LIT:)>' if pars else '<STR_LIT>' , <EOL> '<STR_LIT>' : desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , } <EOL> d [ '<STR_LIT>' ] = _format_ns ( desc ) <EOL> name = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> if isinstance ( desc [ '<STR_LIT:type>' ] , basestring ) : <EOL> d [ '<STR_LIT:name>' ] = ts . cython_ctype ( name ) <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> d [ '<STR_LIT:name>' ] = ts . cython_classname ( name ) [ <NUM_LIT:1> ] <EOL> d [ '<STR_LIT>' ] = '<STR_LIT:U+0020>' + _format_alias ( desc , ts ) <EOL> construct_kinds = { '<STR_LIT>' : '<STR_LIT>' } <EOL> if src_lang == '<STR_LIT>' : <EOL> construct_kinds . update ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> d [ '<STR_LIT>' ] = construct_kinds [ desc . get ( '<STR_LIT>' , '<STR_LIT:class>' ) ] <EOL> else : <EOL> construct_kinds . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> d [ '<STR_LIT>' ] = construct_kinds [ desc . get ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> inc = set ( [ '<STR_LIT:c>' ] ) <EOL> cimport_tups = set ( ) <EOL> for parent in desc [ '<STR_LIT>' ] : <EOL> ts . cython_cimport_tuples ( parent , cimport_tups , inc ) <EOL> alines = [ ] <EOL> attritems = sorted ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> for aname , atype in attritems : <EOL> if aname . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> actype = ts . cython_ctype ( atype ) <EOL> if '<STR_LIT>' in actype : <EOL> aline = actype . format ( type_name = aname ) <EOL> else : <EOL> aline = "<STR_LIT>" . format ( actype , aname ) <EOL> alines . append ( aline ) <EOL> ts . cython_cimport_tuples ( atype , cimport_tups , inc ) <EOL> d [ '<STR_LIT>' ] = indent ( alines , <NUM_LIT:8> ) <EOL> mlines = [ ] <EOL> clines = [ ] <EOL> dargs = expand_default_args ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> methitems = sorted ( x for x in dargs if isinstance ( x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , basestring ) ) <EOL> methitems += sorted ( x for x in dargs if not isinstance ( x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , basestring ) ) <EOL> default_constructor = ( ( d [ '<STR_LIT:name>' ] , ) , None ) <EOL> if d [ '<STR_LIT>' ] == '<STR_LIT>' and default_constructor not in methitems : <EOL> methitems . insert ( <NUM_LIT:0> , default_constructor ) <EOL> for mkey , mrtn in methitems : <EOL> mname , margs = mkey [ <NUM_LIT:0> ] , mkey [ <NUM_LIT:1> : ] <EOL> mbasename = mname if isinstance ( mname , basestring ) else mname [ <NUM_LIT:0> ] <EOL> mcppname = ts . cpp_funcname ( mname ) <EOL> mcyname = ts . cython_funcname ( mname ) <EOL> if mbasename . startswith ( '<STR_LIT:_>' ) or mbasename . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( [ ts . cython_ctype ( a [ <NUM_LIT:1> ] ) for a in margs ] ) <EOL> for a in margs : <EOL> ts . cython_cimport_tuples ( a [ <NUM_LIT:1> ] , cimport_tups , inc ) <EOL> estr = _exception_str ( exceptions , src_lang , mrtn , ts ) <EOL> if mname == mcppname == mcyname : <EOL> line = "<STR_LIT>" . format ( mname , argfill , estr ) <EOL> else : <EOL> line = '<STR_LIT>' . format ( mcyname , mcppname , argfill , estr ) <EOL> if mrtn is None : <EOL> line = "<STR_LIT>" . format ( d [ '<STR_LIT:name>' ] , argfill , estr ) <EOL> if line not in clines : <EOL> clines . append ( line ) <EOL> else : <EOL> if MATCH_REF . matches ( mrtn ) : <EOL> mrtn = mrtn [ <NUM_LIT:0> ] <EOL> rtype = ts . cython_ctype ( mrtn ) <EOL> ts . cython_cimport_tuples ( mrtn , cimport_tups , inc ) <EOL> line = rtype + "<STR_LIT:U+0020>" + line <EOL> if line not in mlines : <EOL> mlines . append ( line ) <EOL> d [ '<STR_LIT>' ] = indent ( mlines , <NUM_LIT:8> ) <EOL> d [ '<STR_LIT>' ] = indent ( clines , <NUM_LIT:8> ) if src_lang == '<STR_LIT>' else '<STR_LIT>' <EOL> d [ '<STR_LIT>' ] = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> cpppxd = _cpppxd_class_template . format ( ** d ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in desc : <EOL> desc [ '<STR_LIT>' ] = extra [ '<STR_LIT>' ] <EOL> return cimport_tups , cpppxd <EOL> def genpxd ( env , classes = ( ) , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> pxds = { } <EOL> for name , mod in env . items ( ) : <EOL> if mod [ '<STR_LIT>' ] is None : <EOL> continue <EOL> pxds [ name ] = modpxd ( mod , classes , ts = ts , max_callbacks = max_callbacks ) <EOL> return pxds <EOL> def pxd_sorted_names ( mod ) : <EOL> """<STR_LIT>""" <EOL> classnames = [ ] <EOL> othernames = [ ] <EOL> for name , desc in mod . items ( ) : <EOL> if isclassdesc ( desc ) : <EOL> if name in classnames : <EOL> continue <EOL> parents = desc [ '<STR_LIT>' ] <EOL> if not parents : <EOL> classnames . insert ( <NUM_LIT:0> , name ) <EOL> continue <EOL> for parent in parents : <EOL> if parent not in classnames and parent in mod : <EOL> classnames . append ( parent ) <EOL> classnames . append ( name ) <EOL> else : <EOL> othernames . append ( name ) <EOL> names = classnames + sortedbytype ( othernames ) <EOL> return names <EOL> def modpxd ( mod , classes = ( ) , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> m = { '<STR_LIT>' : mod . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> "<STR_LIT>" : mod . get ( "<STR_LIT>" , "<STR_LIT>" ) } <EOL> attrs = [ ] <EOL> cimport_tups = set ( ) <EOL> classnames = _classnames_in_mod ( mod , ts ) <EOL> with ts . local_classes ( classnames ) : <EOL> for name in pxd_sorted_names ( mod ) : <EOL> desc = mod [ name ] <EOL> if isclassdesc ( desc ) : <EOL> ci_tup , attr_str = classpxd ( desc , classes , ts = ts , <EOL> max_callbacks = max_callbacks ) <EOL> else : <EOL> continue <EOL> cimport_tups |= ci_tup <EOL> attrs . append ( attr_str ) <EOL> cimport_tups . discard ( ( mod [ "<STR_LIT:name>" ] , ) ) <EOL> if mod . get ( '<STR_LIT>' , None ) == '<STR_LIT:c>' : <EOL> cimport_tups . discard ( ( ts . stlcontainers , ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( sorted ( ts . cython_cimport_lines ( cimport_tups ) ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( attrs ) <EOL> t = '<STR_LIT>' . join ( [ AUTOGEN_WARNING , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> pxd = t . format ( ** m ) <EOL> return pxd <EOL> _pxd_class_template = """<STR_LIT>""" <EOL> def classpxd ( desc , classes = ( ) , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in extra : <EOL> extra [ '<STR_LIT>' ] = '<STR_LIT>' . format ( desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> pars = '<STR_LIT:U+002CU+0020>' . join ( [ ts . cython_cytype ( p ) for p in desc [ '<STR_LIT>' ] ] ) <EOL> d = { '<STR_LIT>' : '<STR_LIT:(>' + pars + '<STR_LIT:)>' if pars else '<STR_LIT>' } <EOL> name = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> d [ '<STR_LIT:name>' ] = ts . cython_classname ( name ) [ <NUM_LIT:1> ] <EOL> max_callbacks = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , max_callbacks ) <EOL> mczeropad = int ( math . log10 ( max_callbacks ) ) + <NUM_LIT:1> <EOL> cimport_tups = set ( ) <EOL> for parent in desc [ '<STR_LIT>' ] : <EOL> ts . cython_cimport_tuples ( parent , cimport_tups , set ( [ '<STR_LIT>' ] ) ) <EOL> from_cpppxd = desc [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> tarname = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> d [ '<STR_LIT>' ] = ts . cython_ctype ( tarname ) <EOL> ts . cython_cimport_tuples ( tarname , cimport_tups , set ( [ '<STR_LIT:c>' ] ) ) <EOL> body = [ ] if desc [ '<STR_LIT>' ] else [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> attritems = sorted ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> fplines = [ ] <EOL> for aname , atype in attritems : <EOL> if aname . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> _ , _ , cachename , iscached = ts . cython_c2py ( aname , atype , cache_prefix = None ) <EOL> if iscached : <EOL> ts . cython_cimport_tuples ( atype , cimport_tups ) <EOL> if _isclassptr ( atype , classes ) : <EOL> atype_nopred = ts . strip_predicates ( atype ) <EOL> cyt = ts . cython_cytype ( atype_nopred ) <EOL> elif _isclassdblptr ( atype , classes ) : <EOL> cyt = '<STR_LIT:list>' <EOL> else : <EOL> cyt = ts . cython_cytype ( atype ) <EOL> decl = "<STR_LIT>" . format ( cyt , cachename ) <EOL> body . append ( decl ) <EOL> if ts . isfunctionpointer ( atype ) : <EOL> apyname , acname = _mangle_function_pointer_name ( aname , name ) <EOL> acdecl = "<STR_LIT>" + ts . cython_ctype ( ( '<STR_LIT>' , ) + atype [ <NUM_LIT:1> : ] ) <EOL> for i in range ( max_callbacks ) : <EOL> suffix = "<STR_LIT>" . format ( i , mczeropad ) <EOL> apyname_i , acname_i = apyname + suffix , acname + suffix <EOL> fplines . append ( "<STR_LIT>" + apyname_i ) <EOL> fplines . append ( acdecl . format ( type_name = acname_i ) ) <EOL> body . append ( "<STR_LIT>" . format ( aname ) ) <EOL> fplines . append ( "<STR_LIT>" . format ( apyname ) ) <EOL> if len ( fplines ) > <NUM_LIT:0> : <EOL> fplines . append ( "<STR_LIT>" + d [ '<STR_LIT:name>' ] ) <EOL> d [ '<STR_LIT:body>' ] = indent ( body or [ '<STR_LIT>' ] ) <EOL> d [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( fplines ) <EOL> d [ '<STR_LIT>' ] = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pxd = _pxd_class_template . format ( ** d ) <EOL> return cimport_tups , pxd <EOL> def genpyx ( env , classes = None , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> if classes is None : <EOL> classes = { } <EOL> for envname , mod in env . items ( ) : <EOL> for modname , desc in mod . items ( ) : <EOL> if isclassdesc ( desc ) : <EOL> classes [ desc [ '<STR_LIT:name>' ] ] = desc <EOL> pyxs = { } <EOL> for name , mod in env . items ( ) : <EOL> if mod [ '<STR_LIT>' ] is None : <EOL> continue <EOL> pyxs [ name ] = modpyx ( mod , classes = classes , ts = ts , max_callbacks = max_callbacks ) <EOL> return pyxs <EOL> _pyx_mod_template = AUTOGEN_WARNING + '''<STR_LIT>''' <EOL> def modpyx ( mod , classes = None , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> m = { '<STR_LIT>' : mod . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : mod . get ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : mod . get ( "<STR_LIT>" , "<STR_LIT>" ) } <EOL> attrs = [ ] <EOL> import_tups = set ( ) <EOL> cimport_tups = set ( ) <EOL> classnames = _classnames_in_mod ( mod , ts ) <EOL> with ts . local_classes ( classnames ) : <EOL> for name , desc in mod . items ( ) : <EOL> if isvardesc ( desc ) : <EOL> i_tup , ci_tup , attr_str = varpyx ( desc , ts = ts ) <EOL> elif isfuncdesc ( desc ) : <EOL> i_tup , ci_tup , attr_str = funcpyx ( desc , ts = ts ) <EOL> elif isclassdesc ( desc ) : <EOL> i_tup , ci_tup , attr_str = classpyx ( desc , classes = classes , ts = ts , <EOL> max_callbacks = max_callbacks ) <EOL> else : <EOL> continue <EOL> import_tups |= i_tup <EOL> cimport_tups |= ci_tup <EOL> attrs . append ( attr_str ) <EOL> template_funcs = _template_funcnames_in_mod ( mod ) <EOL> template_dispatcher = _gen_template_func_dispatcher ( template_funcs , ts ) <EOL> attrs . append ( template_dispatcher ) <EOL> template_classes = _template_classnames_in_mod ( mod ) <EOL> template_dispatcher = _gen_template_class_dispatcher ( template_classes , ts ) <EOL> attrs . append ( template_dispatcher ) <EOL> import_tups . discard ( ( mod [ "<STR_LIT:name>" ] , ) ) <EOL> if mod . get ( '<STR_LIT>' , None ) == '<STR_LIT:c>' : <EOL> import_tups . discard ( ( ts . stlcontainers , ) ) <EOL> cimport_tups . discard ( ( ts . stlcontainers , ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( sorted ( ts . cython_import_lines ( import_tups ) ) ) <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( sorted ( ts . cython_cimport_lines ( cimport_tups ) ) ) <EOL> if '<STR_LIT>' in m [ '<STR_LIT>' ] : <EOL> m [ '<STR_LIT>' ] += "<STR_LIT>" <EOL> m [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( attrs ) <EOL> t = '<STR_LIT>' . join ( [ AUTOGEN_WARNING , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> pyx = _pyx_mod_template . format ( ** m ) <EOL> return pyx <EOL> def _gen_template_pyfill ( arg , kind , ts ) : <EOL> """<STR_LIT>""" <EOL> if kind is Arg . TYPE : <EOL> rtn = ts . cython_pytype ( arg ) <EOL> elif kind is Arg . LIT : <EOL> rnt = str ( arg ) <EOL> elif kind is Arg . VAR : <EOL> rtn = arg <EOL> elif isinstance ( arg , Number ) : <EOL> rtn = str ( arg ) <EOL> elif isinstance ( arg , basestring ) : <EOL> try : <EOL> rtn = ts . cython_pytype ( arg ) <EOL> except TypeError : <EOL> rtn = arg <EOL> return rtn <EOL> def _gen_template_func_dispatcher ( templates , ts ) : <EOL> """<STR_LIT>""" <EOL> if <NUM_LIT:0> == len ( templates ) : <EOL> return "<STR_LIT>" <EOL> templates = sorted ( templates ) <EOL> disp = [ '<STR_LIT>' , "<STR_LIT:#>" , "<STR_LIT>" , "<STR_LIT:#>" , ] <EOL> alreadyinitd = set ( ) <EOL> for t in templates : <EOL> initline = "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] ) <EOL> if initline not in alreadyinitd : <EOL> disp . append ( "<STR_LIT>" ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] ) ) <EOL> disp . append ( initline ) <EOL> alreadyinitd . add ( initline ) <EOL> args = t [ <NUM_LIT:1> : ] <EOL> pytype = ts . cython_funcname ( t ) <EOL> kinds = ts . argument_kinds . get ( t , ( ( Arg . NONE , ) ) * ( len ( t ) - <NUM_LIT:1> ) ) <EOL> if <NUM_LIT:0> == len ( args ) : <EOL> raise ValueError ( "<STR_LIT>" . format ( t ) ) <EOL> elif <NUM_LIT:1> == len ( args ) : <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , t [ <NUM_LIT:1> ] , pytype ) ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , <EOL> _gen_template_pyfill ( t [ <NUM_LIT:1> ] , kinds [ <NUM_LIT:0> ] , ts ) , pytype ) ) <EOL> else : <EOL> rs = [ repr ( _ ) for _ in t [ <NUM_LIT:1> : ] ] <EOL> pyts = [ _gen_template_pyfill ( x , k , ts ) for x , k in zip ( t [ <NUM_LIT:1> : ] , kinds ) ] <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , "<STR_LIT:U+002CU+0020>" . join ( rs ) , pytype ) ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , "<STR_LIT:U+002CU+0020>" . join ( pyts ) , pytype ) ) <EOL> return "<STR_LIT:\n>" . join ( disp ) <EOL> def _gen_template_class_dispatcher ( templates , ts ) : <EOL> """<STR_LIT>""" <EOL> if <NUM_LIT:0> == len ( templates ) : <EOL> return "<STR_LIT>" <EOL> templates = sorted ( templates ) <EOL> disp = [ '<STR_LIT>' , "<STR_LIT:#>" , "<STR_LIT>" , "<STR_LIT:#>" , ] <EOL> alreadyinitd = set ( ) <EOL> for t in templates : <EOL> initline = "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] ) <EOL> if initline not in alreadyinitd : <EOL> disp . append ( "<STR_LIT>" ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] ) ) <EOL> disp . append ( initline ) <EOL> alreadyinitd . add ( initline ) <EOL> args = t [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> pytype = ts . cython_pytype ( t ) <EOL> kinds = ts . argument_kinds . get ( t , ( ( Arg . NONE , ) ) * ( len ( t ) - <NUM_LIT:1> ) ) <EOL> if <NUM_LIT:0> == len ( args ) : <EOL> raise ValueError ( "<STR_LIT>" . format ( t ) ) <EOL> elif <NUM_LIT:1> == len ( args ) : <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , t [ <NUM_LIT:1> ] , pytype ) ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , <EOL> _gen_template_pyfill ( t [ <NUM_LIT:1> ] , kinds [ <NUM_LIT:0> ] , ts ) , pytype ) ) <EOL> else : <EOL> rs = [ repr ( _ ) for _ in t [ <NUM_LIT:1> : - <NUM_LIT:1> ] ] <EOL> pyts = [ _gen_template_pyfill ( x , k , ts ) for x , k in zip ( t [ <NUM_LIT:1> : ] , kinds ) ] <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , "<STR_LIT:U+002CU+0020>" . join ( rs ) , pytype ) ) <EOL> disp . append ( "<STR_LIT>" . format ( t [ <NUM_LIT:0> ] , "<STR_LIT:U+002CU+0020>" . join ( pyts ) , pytype ) ) <EOL> return "<STR_LIT:\n>" . join ( disp ) <EOL> def _gen_property_get ( name , t , ts , cached_names = None , inst_name = "<STR_LIT>" , <EOL> classes = ( ) ) : <EOL> """<STR_LIT>""" <EOL> lines = [ '<STR_LIT>' ] <EOL> decl , body , rtn , iscached = ts . cython_c2py ( name , t , inst_name = inst_name ) <EOL> if decl is not None : <EOL> if _isclassptr ( t , classes ) : <EOL> decl , _ , _ , _ = ts . cython_c2py ( name , t [ <NUM_LIT:0> ] , inst_name = inst_name ) <EOL> lines += indent ( decl , join = False ) <EOL> if body is not None : <EOL> lines += indent ( body , join = False ) <EOL> if iscached and cached_names is not None : <EOL> cached_names . append ( rtn ) <EOL> lines += indent ( "<STR_LIT>" . format ( rtn ) , join = False ) <EOL> return lines <EOL> def _gen_property_set ( name , t , ts , inst_name = "<STR_LIT>" , cached_name = None , <EOL> classes = ( ) ) : <EOL> """<STR_LIT>""" <EOL> lines = [ '<STR_LIT>' ] <EOL> decl , body , rtn = ts . cython_py2c ( '<STR_LIT:value>' , t ) <EOL> if decl is not None : <EOL> lines += indent ( decl , join = False ) <EOL> if body is not None : <EOL> lines += indent ( body , join = False ) <EOL> lines += indent ( "<STR_LIT>" . format ( inst_name , name , rtn ) , join = False ) <EOL> if cached_name is not None : <EOL> lines += indent ( "<STR_LIT>" . format ( cached_name ) , join = False ) <EOL> return lines <EOL> def _gen_property ( name , t , ts , doc = None , cached_names = None , inst_name = "<STR_LIT>" , <EOL> classes = ( ) ) : <EOL> """<STR_LIT>""" <EOL> lines = [ '<STR_LIT>' . format ( name ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> oldcnlen = <NUM_LIT:0> if cached_names is None else len ( cached_names ) <EOL> lines += indent ( _gen_property_get ( name , t , ts , cached_names = cached_names , <EOL> inst_name = inst_name , classes = classes ) , join = False ) <EOL> lines += [ '<STR_LIT>' ] <EOL> newcnlen = <NUM_LIT:0> if cached_names is None else len ( cached_names ) <EOL> cached_name = cached_names [ - <NUM_LIT:1> ] if newcnlen == <NUM_LIT:1> + oldcnlen else None <EOL> lines += indent ( _gen_property_set ( name , t , ts , inst_name = inst_name , <EOL> cached_name = cached_name , classes = classes ) , join = False ) <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_function_pointer_property ( name , t , ts , doc = None , cached_names = None , <EOL> inst_name = "<STR_LIT>" , classname = '<STR_LIT>' , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> lines = [ '<STR_LIT>' . format ( name ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> oldcnlen = <NUM_LIT:0> if cached_names is None else len ( cached_names ) <EOL> lines += indent ( _gen_property_get ( name , t , ts , cached_names = cached_names , <EOL> inst_name = inst_name ) , join = False ) <EOL> mczeropad = int ( math . log10 ( max_callbacks ) ) + <NUM_LIT:1> <EOL> lines += [ "<STR_LIT>" ] <EOL> newcnlen = <NUM_LIT:0> if cached_names is None else len ( cached_names ) <EOL> cached_name = cached_names [ - <NUM_LIT:1> ] if newcnlen == <NUM_LIT:1> + oldcnlen else None <EOL> setlines = indent ( _gen_property_set ( name , ( '<STR_LIT>' , '<STR_LIT:*>' ) , ts , inst_name = inst_name , <EOL> cached_name = cached_name ) , join = False ) <EOL> lines += setlines [ : <NUM_LIT:1> ] <EOL> lines += indent ( indent ( [ '<STR_LIT>' , <EOL> ( '<STR_LIT>' + classname + <EOL> '<STR_LIT:.>' + name + '<STR_LIT>' ) ] , <EOL> join = False ) , join = False ) <EOL> pyname , cname = _mangle_function_pointer_name ( name , classname ) <EOL> pynames = [ pyname + "<STR_LIT>" . format ( i , mczeropad ) for i in range ( max_callbacks ) ] <EOL> cnames = [ cname + "<STR_LIT>" . format ( i , mczeropad ) for i in range ( max_callbacks ) ] <EOL> if max_callbacks == <NUM_LIT:1> : <EOL> suffix = '<STR_LIT:0>' <EOL> extraset = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( name = name , pyname = pyname + suffix , cname = cname + suffix , <EOL> cached_name = cached_name , inst_name = inst_name ) <EOL> elif max_callbacks > <NUM_LIT:1> : <EOL> extraset = [ '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( cached_name = cached_name ) , <EOL> "<STR_LIT>" + '<STR_LIT:U+002CU+0020>' . join ( pynames ) + '<STR_LIT>' . format ( pyname ) , ] <EOL> selectlines = [ ] <EOL> for i , pyname_i in enumerate ( pynames ) : <EOL> selectlines . append ( "<STR_LIT>" . format ( pyname_i ) ) <EOL> selectlines . append ( "<STR_LIT>" . format ( i ) ) <EOL> selectlines [ <NUM_LIT:0> ] = selectlines [ <NUM_LIT:0> ] [ <NUM_LIT:2> : ] <EOL> extraset += selectlines <EOL> extraset += [ '<STR_LIT>' , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) . format ( classname , name ) , <EOL> '<STR_LIT>' . format ( pyname ) , <EOL> '<STR_LIT>' . format ( <EOL> pyname , max_callbacks ) , <EOL> '<STR_LIT>' . format ( name ) , ] <EOL> setvallines = [ ] <EOL> for i , ( pyname_i , cname_i ) in enumerate ( zip ( pynames , cnames ) ) : <EOL> setvallines . append ( "<STR_LIT>" . format ( i ) ) <EOL> setvallines . append ( "<STR_LIT>" . format ( pyname = pyname_i ) ) <EOL> setvallines . append ( "<STR_LIT>" . format ( <EOL> inst_name = inst_name , name = name , cname = cname_i ) ) <EOL> setvallines [ <NUM_LIT:0> ] = setvallines [ <NUM_LIT:0> ] [ <NUM_LIT:2> : ] <EOL> extraset += setvallines <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> raise RuntimeError ( msg . format ( classname , max_callbacks ) ) <EOL> lines += indent ( indent ( extraset , join = False ) , join = False ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> lines += [ "<STR_LIT>" . format ( name ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( cached_name = cached_name ) , <EOL> "<STR_LIT>" . format ( name , max_callbacks + <NUM_LIT:1> ) , <EOL> '<STR_LIT>' . format ( name ) , <EOL> "<STR_LIT>" . format ( name , max_callbacks + <NUM_LIT:1> ) , ] <EOL> dereflines = [ ] <EOL> for i , pyname_i in enumerate ( pynames ) : <EOL> dereflines . append ( "<STR_LIT>" . format ( i ) ) <EOL> dereflines . append ( "<STR_LIT>" . format ( pyname_i ) ) <EOL> dereflines . append ( "<STR_LIT>" . format ( pyname_i ) ) <EOL> dereflines [ <NUM_LIT:0> ] = dereflines [ <NUM_LIT:0> ] [ <NUM_LIT:2> : ] <EOL> lines += indent ( indent ( dereflines , join = False ) , join = False ) <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_function_pointer_wrapper ( name , t , ts , classname = '<STR_LIT>' , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> pyname , cname = _mangle_function_pointer_name ( name , classname ) <EOL> mczeropad = int ( math . log10 ( max_callbacks ) ) + <NUM_LIT:1> <EOL> lines = [ "<STR_LIT>" . format ( name , classname ) , <EOL> "<STR_LIT>" . format ( pyname ) , "<STR_LIT>" ] <EOL> for i in range ( max_callbacks ) : <EOL> suffix = "<STR_LIT>" . format ( i , mczeropad ) <EOL> pyname_i , cname_i = pyname + suffix , cname + suffix <EOL> decl , body , rtn = ts . cython_py2c ( pyname_i , t , proxy_name = cname_i ) <EOL> lines += [ pyname_i + "<STR_LIT>" , '<STR_LIT>' ] <EOL> lines += rtn . splitlines ( ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_argfill ( args , defaults ) : <EOL> """<STR_LIT>""" <EOL> counter = <NUM_LIT:0> <EOL> taken = frozenset ( a [ <NUM_LIT:0> ] for a in args ) <EOL> names = [ ] <EOL> afill = [ ] <EOL> for ( name , t ) , ( kind , default ) in zip ( args , defaults ) : <EOL> if not name : <EOL> while <NUM_LIT:1> : <EOL> name = '<STR_LIT>' % counter <EOL> counter += <NUM_LIT:1> <EOL> if name not in taken : <EOL> break <EOL> names . append ( name ) <EOL> if kind is Arg . NONE : <EOL> afillval = name <EOL> elif kind is Arg . LIT : <EOL> afillval = "<STR_LIT>" . format ( name , default ) <EOL> elif kind is Arg . VAR : <EOL> afillval = "<STR_LIT>" . format ( name , default ) <EOL> elif kind is Arg . TYPE : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( name ) ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( name ) ) <EOL> afill . append ( afillval ) <EOL> return "<STR_LIT:U+002CU+0020>" . join ( afill ) , names <EOL> def _gen_function ( name , name_mangled , args , rtn , defaults , ts , doc = None , <EOL> inst_name = "<STR_LIT>" , is_method = False ) : <EOL> argfill , names = _gen_argfill ( args , defaults ) <EOL> if is_method : <EOL> argfill = "<STR_LIT>" + argfill <EOL> lines = [ '<STR_LIT>' . format ( name_mangled , argfill ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> decls = [ ] <EOL> argbodies = [ ] <EOL> argrtns = { } <EOL> for n , a in zip ( names , args ) : <EOL> adecl , abody , artn = ts . cython_py2c ( n , a [ <NUM_LIT:1> ] ) <EOL> if adecl is not None : <EOL> decls += indent ( adecl , join = False ) <EOL> if abody is not None : <EOL> argbodies += indent ( abody , join = False ) <EOL> argrtns [ n ] = artn <EOL> rtype_orig = ts . cython_ctype ( rtn ) <EOL> rtype = rtype_orig . replace ( '<STR_LIT>' , "<STR_LIT>" ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> hasrtn = rtype not in set ( [ '<STR_LIT:None>' , None , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> argvals = '<STR_LIT:U+002CU+0020>' . join ( argrtns [ n ] for n in names ) <EOL> fcall = '<STR_LIT>' . format ( inst_name , name , argvals ) <EOL> if hasrtn : <EOL> fcdecl , fcbody , fcrtn , fccached = ts . cython_c2py ( '<STR_LIT>' , rtn , cached = False , view = False ) <EOL> decls += indent ( "<STR_LIT>" . format ( rtype , '<STR_LIT>' ) , join = False ) <EOL> if '<STR_LIT>' in rtype_orig : <EOL> func_call = indent ( '<STR_LIT>' . format ( rtype , fcall ) , join = False ) <EOL> else : <EOL> func_call = indent ( '<STR_LIT>' . format ( fcall ) , join = False ) <EOL> if fcdecl is not None : <EOL> decls += indent ( fcdecl , join = False ) <EOL> if fcbody is not None : <EOL> func_call += indent ( fcbody , join = False ) <EOL> func_rtn = indent ( "<STR_LIT>" . format ( fcrtn ) , join = False ) <EOL> else : <EOL> func_call = indent ( fcall , join = False ) <EOL> func_rtn = [ ] <EOL> lines += decls <EOL> lines += argbodies <EOL> lines += func_call <EOL> lines += func_rtn <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_default_constructor ( desc , attrs , ts , doc = None , srcpxd_filename = None ) : <EOL> src_lang = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> args = [ '<STR_LIT>' ] + [ a + "<STR_LIT>" for a , _ in attrs ] + [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( args ) <EOL> lines = [ '<STR_LIT>' . format ( argfill ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> ct = ts . cython_ctype ( desc [ '<STR_LIT:type>' ] ) <EOL> if desc [ '<STR_LIT>' ] == '<STR_LIT:class>' : <EOL> fcall = '<STR_LIT>' . format ( ct ) <EOL> elif desc [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> construct_template = '<STR_LIT>' <EOL> if src_lang == '<STR_LIT>' and desc [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> construct_template += '<STR_LIT>' <EOL> fcall = construct_template . format ( ct ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> lines . extend ( indent ( fcall , join = False ) ) <EOL> for a , _ in attrs : <EOL> lines . append ( indent ( "<STR_LIT>" . format ( a ) ) ) <EOL> lines . append ( indent ( "<STR_LIT>" . format ( a ) , <NUM_LIT:8> ) ) <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_constructor ( name , name_mangled , classname , args , defaults , ts , <EOL> doc = None , srcpxd_filename = None , inst_name = "<STR_LIT>" , <EOL> construct = "<STR_LIT:class>" , src_lang = '<STR_LIT>' ) : <EOL> argfill , names = _gen_argfill ( args , defaults ) <EOL> lines = [ '<STR_LIT>' . format ( name_mangled , argfill ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> decls = [ ] <EOL> argbodies = [ ] <EOL> argrtns = { } <EOL> for n , a in zip ( names , args ) : <EOL> adecl , abody , artn = ts . cython_py2c ( n , a [ <NUM_LIT:1> ] ) <EOL> if adecl is not None : <EOL> decls += indent ( adecl , join = False ) <EOL> if abody is not None : <EOL> argbodies += indent ( abody , join = False ) <EOL> argrtns [ n ] = artn <EOL> argvals = '<STR_LIT:U+002CU+0020>' . join ( argrtns [ n ] for n in names ) <EOL> classname = classname if srcpxd_filename is None else "<STR_LIT>" . format ( srcpxd_filename . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] , classname ) <EOL> if construct == '<STR_LIT:class>' : <EOL> fcall = '<STR_LIT>' . format ( classname , argvals ) <EOL> elif construct in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> construct_template = '<STR_LIT>' <EOL> if src_lang == '<STR_LIT>' and construct == '<STR_LIT>' : <EOL> construct_template += '<STR_LIT>' <EOL> fcall = construct_template . format ( classname , argvals ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> func_call = indent ( fcall , join = False ) <EOL> lines += decls <EOL> lines += argbodies <EOL> lines += func_call <EOL> lines += [ '<STR_LIT>' , "<STR_LIT>" ] <EOL> return lines <EOL> def _gen_dispatcher ( name , name_mangled , ts , doc = None , hasrtn = True , is_method = True ) : <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if is_method is True : <EOL> arg_chk_str = "<STR_LIT>" <EOL> dispatch_str_ret = "<STR_LIT>" <EOL> dispatch_str_no_ret = "<STR_LIT>" <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> else : <EOL> arg_chk_str = "<STR_LIT>" <EOL> dispatch_str_ret = "<STR_LIT>" <EOL> dispatch_str_no_ret = "<STR_LIT>" <EOL> argfill = "<STR_LIT:U+002CU+0020>" . join ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> lines = [ '<STR_LIT>' . format ( name , argfill ) ] <EOL> lines += [ ] if doc is None else indent ( '<STR_LIT>' . format ( doc ) , join = False ) <EOL> types = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , ] <EOL> lines += indent ( types , join = False ) <EOL> refinenum = lambda x : ( sum ( [ int ( ts . isrefinement ( a [ <NUM_LIT:1> ] ) ) for a in x [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] ] ) , <EOL> len ( x [ <NUM_LIT:0> ] ) , x [ <NUM_LIT:1> ] ) <EOL> mangitems = sorted ( name_mangled . items ( ) , key = refinenum ) <EOL> mtypeslines = [ ] <EOL> lines += indent ( "<STR_LIT>" , join = False ) <EOL> for key , mangled_name in mangitems : <EOL> cargs = key [ <NUM_LIT:1> : ] <EOL> arang = range ( len ( cargs ) ) <EOL> anames = [ ca [ <NUM_LIT:0> ] for ca in cargs ] <EOL> pytypes = [ ts . cython_pytype ( ca [ <NUM_LIT:1> ] ) for ca in cargs ] <EOL> mtypes = "<STR_LIT:U+002CU+0020>" . join ( <EOL> [ "<STR_LIT>" . format ( i , pyt ) for i , pyt in zip ( arang , pytypes ) ] + [ '<STR_LIT>' . format ( n , pyt ) for n , pyt in zip ( anames , pytypes ) ] ) <EOL> mtups = '<STR_LIT:(>' + mtypes + '<STR_LIT:)>' if <NUM_LIT:0> < len ( mtypes ) else mtypes <EOL> mtypeslines . append ( mangled_name + "<STR_LIT>" + mtups + "<STR_LIT:)>" ) <EOL> cond = [ arg_chk_str . format ( mangled_name ) , ] <EOL> if hasrtn : <EOL> rline = dispatch_str_ret . format ( mangled_name ) <EOL> else : <EOL> rline = [ dispatch_str_no_ret . format ( mangled_name ) , "<STR_LIT>" ] <EOL> cond += indent ( rline , join = False ) <EOL> lines += indent ( cond , join = False ) <EOL> lines = sorted ( mtypeslines ) + [ '<STR_LIT>' ] + lines <EOL> lines += indent ( "<STR_LIT>" , join = False ) <EOL> refineopp = lambda x : ( - <NUM_LIT:1> * sum ( [ int ( ts . isrefinement ( a [ <NUM_LIT:1> ] ) ) for a in x [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] ] ) , len ( x [ <NUM_LIT:0> ] ) , x [ <NUM_LIT:1> ] ) <EOL> mangitems = sorted ( name_mangled . items ( ) , key = refineopp ) <EOL> for key , mangled_name in mangitems : <EOL> lines += indent ( '<STR_LIT>' , join = False ) <EOL> if hasrtn : <EOL> rline = dispatch_str_ret . format ( mangled_name ) <EOL> else : <EOL> rline = [ dispatch_str_no_ret . format ( mangled_name ) , "<STR_LIT>" ] <EOL> lines += indent ( indent ( rline , join = False ) , join = False ) <EOL> lines += indent ( [ "<STR_LIT>" , <EOL> indent ( "<STR_LIT>" , join = False ) [ <NUM_LIT:0> ] , ] , join = False ) <EOL> errmsg = "<STR_LIT>" . format ( name ) <EOL> lines += indent ( errmsg , join = False ) <EOL> lines += [ '<STR_LIT>' ] <EOL> return lines <EOL> def _class_heirarchy ( cls , ch , classes ) : <EOL> if not classes [ cls ] [ '<STR_LIT>' ] : <EOL> return <EOL> if <NUM_LIT:0> == len ( ch ) or ch [ <NUM_LIT:0> ] != cls : <EOL> ch . insert ( <NUM_LIT:0> , cls ) <EOL> for p in classes [ cls ] [ '<STR_LIT>' ] [ : : - <NUM_LIT:1> ] : <EOL> ch . insert ( <NUM_LIT:0> , p ) <EOL> _class_heirarchy ( p , ch , classes ) <EOL> def _method_instance_names ( desc , classes , key , rtn , ts ) : <EOL> classnames = [ ] <EOL> _class_heirarchy ( desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] , classnames , classes ) <EOL> for classname in classnames : <EOL> classrtn = classes . get ( classname , { } ) . get ( '<STR_LIT>' , { } ) . get ( key , { } ) . get ( '<STR_LIT>' , NotImplemented ) <EOL> if rtn != classrtn : <EOL> continue <EOL> class_ctype = ts . cython_ctype ( classname ) <EOL> inst_name = "<STR_LIT>" . format ( class_ctype ) <EOL> return inst_name , classname <EOL> tarname = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> return "<STR_LIT>" . format ( ts . cython_ctype ( tarname ) ) , tarname <EOL> def _count0 ( x ) : <EOL> c = { } <EOL> for v in x : <EOL> v0 = v [ <NUM_LIT:0> ] <EOL> c [ v0 ] = c . get ( v0 , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> return c <EOL> def _doc_add_sig ( doc , name , args , defaults , ismethod = True ) : <EOL> if doc . startswith ( name ) : <EOL> return doc <EOL> sig = [ '<STR_LIT>' ] if ismethod else [ ] <EOL> sig . append ( _gen_argfill ( args , defaults ) [ <NUM_LIT:0> ] ) <EOL> newdoc = "<STR_LIT>" . format ( name , "<STR_LIT:U+002CU+0020>" . join ( sig ) , doc ) <EOL> return newdoc <EOL> _pyx_class_template = '''<STR_LIT>''' <EOL> def classpyx ( desc , classes = None , ts = None , max_callbacks = <NUM_LIT:8> ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> if classes is None : <EOL> classes = { desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] : desc } <EOL> src_lang = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> nodocmsg = "<STR_LIT>" <EOL> pars = '<STR_LIT:U+002CU+0020>' . join ( [ ts . cython_cytype ( p ) for p in desc [ '<STR_LIT>' ] ] ) <EOL> d = { '<STR_LIT>' : '<STR_LIT:(>' + pars + '<STR_LIT:)>' if pars else '<STR_LIT>' , <EOL> '<STR_LIT>' : desc [ '<STR_LIT>' ] , <EOL> } <EOL> srcname = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> name = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> d [ '<STR_LIT:name>' ] = ts . cython_classname ( name ) [ <NUM_LIT:1> ] <EOL> class_doc = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT:class>' , nodocmsg . format ( desc [ '<STR_LIT:name>' ] ) ) <EOL> d [ '<STR_LIT>' ] = indent ( '<STR_LIT>' . format ( class_doc ) ) <EOL> class_ctype = ts . cython_ctype ( name ) <EOL> inst_name = "<STR_LIT>" . format ( class_ctype ) <EOL> import_tups = set ( ) <EOL> cimport_tups = set ( ) <EOL> for parent in desc [ '<STR_LIT>' ] : <EOL> ts . cython_import_tuples ( parent , import_tups ) <EOL> ts . cython_cimport_tuples ( parent , cimport_tups ) <EOL> cdefattrs = [ ] <EOL> mc = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , max_callbacks ) <EOL> alines = [ ] <EOL> pdlines = [ ] <EOL> fplines = [ ] <EOL> cached_names = [ ] <EOL> attritems = sorted ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> for aname , atype in attritems : <EOL> if aname . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> adoc = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) . get ( aname , nodocmsg . format ( aname ) ) <EOL> if ts . isfunctionpointer ( atype ) : <EOL> alines += _gen_function_pointer_property ( aname , atype , ts , adoc , <EOL> cached_names = cached_names , inst_name = inst_name , <EOL> classname = name , max_callbacks = mc ) <EOL> fplines += _gen_function_pointer_wrapper ( aname , atype , ts , <EOL> max_callbacks = mc , classname = name ) <EOL> pdlines . append ( "<STR_LIT>" . format ( aname , mc + <NUM_LIT:1> ) ) <EOL> else : <EOL> alines += _gen_property ( aname , atype , ts , adoc , cached_names = cached_names , <EOL> inst_name = inst_name , classes = classes ) <EOL> ts . cython_import_tuples ( atype , import_tups ) <EOL> ts . cython_cimport_tuples ( atype , cimport_tups ) <EOL> if len ( fplines ) > <NUM_LIT:0> : <EOL> fplines . append ( "<STR_LIT>" . format ( name , mc ) ) <EOL> d [ '<STR_LIT>' ] = indent ( alines ) <EOL> d [ '<STR_LIT>' ] = "<STR_LIT:\n>" . join ( fplines ) <EOL> pdlines += [ "<STR_LIT>" . format ( n ) for n in cached_names ] <EOL> d [ '<STR_LIT>' ] = indent ( indent ( pdlines , join = False ) ) <EOL> mlines = [ ] <EOL> clines = [ ] <EOL> methcounts = _count0 ( desc [ '<STR_LIT>' ] ) <EOL> currcounts = dict ( [ ( k , <NUM_LIT:0> ) for k in methcounts ] ) <EOL> mangled_mnames = { } <EOL> mitems = list ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> methitems = sorted ( x for x in mitems if isinstance ( x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , basestring ) ) <EOL> methitems += sorted ( x for x in mitems if not isinstance ( x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , basestring ) ) <EOL> for mkey , mval in methitems : <EOL> mname , margs = mkey [ <NUM_LIT:0> ] , mkey [ <NUM_LIT:1> : ] <EOL> mrtn = mval [ '<STR_LIT>' ] <EOL> mdefs = mval [ '<STR_LIT>' ] <EOL> mbasename = mname if isinstance ( mname , basestring ) else mname [ <NUM_LIT:0> ] <EOL> mcyname = ts . cython_funcname ( mname ) <EOL> if mbasename . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> if any ( [ a [ <NUM_LIT:1> ] is None or a [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] is None for a in margs ] ) : <EOL> continue <EOL> if <NUM_LIT:1> < methcounts [ mname ] : <EOL> mname_mangled = "<STR_LIT>" . format ( d [ '<STR_LIT:name>' ] , mcyname , <EOL> currcounts [ mname ] , int ( math . log ( methcounts [ mname ] , <NUM_LIT:10> ) + <NUM_LIT:1> ) ) . lower ( ) <EOL> else : <EOL> mname_mangled = mcyname <EOL> currcounts [ mname ] += <NUM_LIT:1> <EOL> mangled_mnames [ mkey ] = mname_mangled <EOL> for a in margs : <EOL> ts . cython_import_tuples ( a [ <NUM_LIT:1> ] , import_tups ) <EOL> ts . cython_cimport_tuples ( a [ <NUM_LIT:1> ] , cimport_tups ) <EOL> minst_name , mcname = _method_instance_names ( desc , classes , mkey , mrtn , ts ) <EOL> if mcname != d [ '<STR_LIT:name>' ] : <EOL> ts . cython_import_tuples ( mcname , import_tups ) <EOL> ts . cython_cimport_tuples ( mcname , cimport_tups ) <EOL> if mrtn is None : <EOL> if mname not in ( d [ '<STR_LIT:name>' ] , '<STR_LIT>' , <EOL> srcname if isinstance ( srcname , basestring ) else srcname [ : - <NUM_LIT:1> ] ) : <EOL> continue <EOL> if <NUM_LIT:1> == methcounts [ mname ] : <EOL> mname_mangled = '<STR_LIT>' <EOL> mangled_mnames [ mkey ] = mname_mangled <EOL> mdoc = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) . get ( mname , '<STR_LIT>' ) <EOL> mdoc = _doc_add_sig ( mdoc , mcyname , margs , mdefs ) <EOL> construct = desc [ '<STR_LIT>' ] <EOL> if construct in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> cimport_tups . add ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> clines += _gen_constructor ( mcyname , mname_mangled , d [ '<STR_LIT:name>' ] , margs , <EOL> mdefs , ts , doc = mdoc , <EOL> srcpxd_filename = desc [ '<STR_LIT>' ] , <EOL> inst_name = minst_name , construct = construct , <EOL> src_lang = src_lang ) <EOL> if <NUM_LIT:1> < methcounts [ mname ] and currcounts [ mname ] == methcounts [ mname ] : <EOL> nm = { } <EOL> for k , v in mangled_mnames . items ( ) : <EOL> if isinstance ( k [ <NUM_LIT:0> ] , basestring ) and k [ <NUM_LIT:0> ] == mbasename : <EOL> nm [ k ] = v <EOL> elif k [ <NUM_LIT:0> ] == srcname [ : - <NUM_LIT:1> ] : <EOL> nm [ k ] = v <EOL> clines += _gen_dispatcher ( '<STR_LIT>' , nm , ts , doc = mdoc , hasrtn = False ) <EOL> else : <EOL> ts . cython_import_tuples ( mrtn , import_tups ) <EOL> ts . cython_cimport_tuples ( mrtn , cimport_tups ) <EOL> mdoc = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) . get ( mname , nodocmsg . format ( mname ) ) <EOL> mdoc = _doc_add_sig ( mdoc , mcyname , margs , mdefs ) <EOL> mlines += _gen_function ( mcyname , mname_mangled , margs , mrtn , mdefs , <EOL> ts , mdoc , inst_name = minst_name , <EOL> is_method = True ) <EOL> if <NUM_LIT:1> < methcounts [ mname ] and currcounts [ mname ] == methcounts [ mname ] : <EOL> nm = dict ( [ ( k , v ) for k , v in mangled_mnames . items ( ) if k [ <NUM_LIT:0> ] == mbasename ] ) <EOL> mlines += _gen_dispatcher ( mcyname , nm , ts , doc = mdoc ) <EOL> if <NUM_LIT:0> == len ( desc [ '<STR_LIT>' ] ) or <NUM_LIT:0> == len ( clines ) : <EOL> mdocs = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , { } ) <EOL> mdoc = mdocs . get ( desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] , False ) or mdocs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> attrsargs = [ ( Arg . LIT , "<STR_LIT:None>" ) ] * len ( attritems ) <EOL> mdoc = _doc_add_sig ( mdoc , '<STR_LIT>' , attritems , attrsargs ) <EOL> clines += _gen_default_constructor ( desc , attritems , ts , doc = mdoc ) <EOL> cimport_tups . add ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not desc [ '<STR_LIT>' ] : <EOL> clines += [ "<STR_LIT>" ] <EOL> clines += indent ( "<STR_LIT>" , join = False ) <EOL> clines += indent ( indent ( "<STR_LIT>" , join = False ) , join = False ) <EOL> cimport_tups . add ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> template_meths = _template_method_names ( desc [ '<STR_LIT>' ] ) <EOL> template_dispatcher = _gen_template_func_dispatcher ( template_meths , ts ) <EOL> mlines . append ( indent ( template_dispatcher ) ) <EOL> d [ '<STR_LIT>' ] = indent ( mlines ) <EOL> d [ '<STR_LIT>' ] = indent ( clines ) <EOL> d [ '<STR_LIT>' ] = desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> d [ '<STR_LIT>' ] = indent ( cdefattrs ) <EOL> pyx = _pyx_class_template . format ( ** d ) <EOL> if '<STR_LIT>' not in desc : <EOL> desc [ '<STR_LIT>' ] = '<STR_LIT>' . format ( d [ '<STR_LIT:name>' ] . lower ( ) ) <EOL> return import_tups , cimport_tups , pyx <EOL> def varpyx ( desc , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> nodocmsg = "<STR_LIT>" <EOL> inst_name = desc [ '<STR_LIT>' ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> import_tups = set ( ) <EOL> cimport_tups = set ( ( ( inst_name , ) , ) ) <EOL> name = desc [ '<STR_LIT:name>' ] <EOL> t = ts . canon ( desc [ '<STR_LIT:type>' ] ) <EOL> vlines = [ ] <EOL> if ts . isenum ( t ) : <EOL> doc = '<STR_LIT:">' * <NUM_LIT:3> + "<STR_LIT>" + '<STR_LIT:">' * <NUM_LIT:3> <EOL> for ename , val in t [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] [ <NUM_LIT:2> ] : <EOL> vlines . append ( "<STR_LIT>" . format ( ename , inst_name ) ) <EOL> vlines . append ( doc . format ( ename , val , name ) ) <EOL> vlines . append ( "<STR_LIT>" ) <EOL> else : <EOL> decl , body , rtn , iscached = ts . cython_c2py ( name , t , view = False , cached = False , <EOL> inst_name = inst_name ) <EOL> vlines . append ( decl ) <EOL> vlines . append ( body ) <EOL> vlines . append ( name + "<STR_LIT>" + rtn ) <EOL> docstring = desc . get ( '<STR_LIT>' , None ) <EOL> if docstring is None : <EOL> docstring = '<STR_LIT:">' * <NUM_LIT:3> + nodocmsg . format ( name ) + '<STR_LIT:">' * <NUM_LIT:3> <EOL> vlines . append ( docstring ) <EOL> vlines . append ( desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> pyx = '<STR_LIT:\n>' . join ( vlines ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in extra : <EOL> extra [ '<STR_LIT>' ] = '<STR_LIT>' . format ( desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> return import_tups , cimport_tups , pyx <EOL> def funcpyx ( desc , ts = None ) : <EOL> """<STR_LIT>""" <EOL> ts = ts or TypeSystem ( ) <EOL> nodocmsg = "<STR_LIT>" <EOL> inst_name = desc [ '<STR_LIT>' ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> import_tups = set ( ) <EOL> cimport_tups = set ( ( ( inst_name , ) , ) ) <EOL> ftopname = desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] <EOL> fcytopname = ts . cython_funcname ( ftopname ) <EOL> flines = [ ] <EOL> funccounts = _count0 ( desc [ '<STR_LIT>' ] ) <EOL> currcounts = dict ( [ ( k , <NUM_LIT:0> ) for k in funccounts ] ) <EOL> mangled_fnames = { } <EOL> funcitems = sorted ( desc [ '<STR_LIT>' ] . items ( ) ) <EOL> for fkey , fval in funcitems : <EOL> fname , fargs = fkey [ <NUM_LIT:0> ] , fkey [ <NUM_LIT:1> : ] <EOL> frtn = fval [ '<STR_LIT>' ] <EOL> fdefs = fval [ '<STR_LIT>' ] <EOL> fbasename = fname if isinstance ( fname , basestring ) else fname [ <NUM_LIT:0> ] <EOL> fcyname = ts . cython_funcname ( fname ) <EOL> if fbasename . startswith ( '<STR_LIT:_>' ) : <EOL> continue <EOL> if any ( [ a [ <NUM_LIT:1> ] is None or a [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] is None for a in fargs + ( frtn , ) ] ) : <EOL> continue <EOL> if <NUM_LIT:1> < funccounts [ fname ] : <EOL> fname_mangled = "<STR_LIT>" . format ( fcytopname , currcounts [ fname ] , <EOL> int ( math . log ( funccounts [ fname ] , <NUM_LIT:10> ) + <NUM_LIT:1> ) ) . lower ( ) <EOL> else : <EOL> fname_mangled = fcytopname <EOL> currcounts [ fname ] += <NUM_LIT:1> <EOL> mangled_fnames [ fkey ] = fname_mangled <EOL> for a in fargs : <EOL> ts . cython_import_tuples ( a [ <NUM_LIT:1> ] , import_tups ) <EOL> ts . cython_cimport_tuples ( a [ <NUM_LIT:1> ] , cimport_tups ) <EOL> ts . cython_import_tuples ( frtn , import_tups ) <EOL> ts . cython_cimport_tuples ( frtn , cimport_tups ) <EOL> fdoc = desc . get ( '<STR_LIT>' , nodocmsg . format ( fcyname ) ) <EOL> fdoc = _doc_add_sig ( fdoc , fcyname , fargs , fdefs , ismethod = False ) <EOL> flines += _gen_function ( fcyname , fname_mangled , fargs , frtn , fdefs , ts , <EOL> fdoc , inst_name = inst_name , is_method = False ) <EOL> if <NUM_LIT:1> < funccounts [ fname ] and currcounts [ fname ] == funccounts [ fname ] : <EOL> nm = dict ( [ ( k , v ) for k , v in mangled_fnames . items ( ) if k [ <NUM_LIT:0> ] == fname ] ) <EOL> flines += _gen_dispatcher ( fcytopname , nm , ts , doc = fdoc , is_method = False ) <EOL> flines . append ( desc . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> pyx = '<STR_LIT:\n>' . join ( flines ) <EOL> extra = desc [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in extra : <EOL> extra [ '<STR_LIT>' ] = '<STR_LIT>' . format ( extra [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> return import_tups , cimport_tups , pyx <EOL> class XDressPlugin ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> requires = ( '<STR_LIT>' , ) <EOL> """<STR_LIT>""" <EOL> defaultrc = { '<STR_LIT>' : <NUM_LIT:8> } <EOL> rcdocs = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def update_argparser ( self , parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , type = int , dest = "<STR_LIT>" , <EOL> help = self . rcdocs [ "<STR_LIT>" ] ) <EOL> def setup ( self , rc ) : <EOL> if rc . max_callbacks < <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if cython_version is None : <EOL> warnings . warn ( '<STR_LIT>' , RuntimeWarning ) <EOL> elif cython_version_info [ : <NUM_LIT:2> ] <= ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( cython_version ) , <EOL> RuntimeWarning ) <EOL> def execute ( self , rc ) : <EOL> print ( "<STR_LIT>" ) <EOL> env = rc . env <EOL> classes = { } <EOL> for modname , mod in env . items ( ) : <EOL> for name , desc in mod . items ( ) : <EOL> if isclassdesc ( desc ) : <EOL> classes [ name ] = desc <EOL> cpppxds = gencpppxd ( env , ts = rc . ts ) <EOL> pxds = genpxd ( env , classes , ts = rc . ts , max_callbacks = rc . max_callbacks ) <EOL> pyxs = genpyx ( env , classes , ts = rc . ts , max_callbacks = rc . max_callbacks ) <EOL> for key , cpppxd in cpppxds . items ( ) : <EOL> newoverwrite ( cpppxd , os . path . join ( rc . packagedir , <EOL> env [ key ] [ '<STR_LIT>' ] ) , rc . verbose ) <EOL> for key , pxd in pxds . items ( ) : <EOL> newoverwrite ( pxd , os . path . join ( rc . packagedir , <EOL> env [ key ] [ '<STR_LIT>' ] ) , rc . verbose ) <EOL> for key , pyx in pyxs . items ( ) : <EOL> newoverwrite ( pyx , os . path . join ( rc . packagedir , <EOL> env [ key ] [ '<STR_LIT>' ] ) , rc . verbose ) <EOL> def _format_ns ( desc ) : <EOL> ns = desc . get ( '<STR_LIT>' , None ) <EOL> if ns is None : <EOL> return "<STR_LIT>" <EOL> elif len ( ns ) == <NUM_LIT:0> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return '<STR_LIT>' . format ( ns ) <EOL> def _format_alias ( desc , ts ) : <EOL> ns = desc . get ( '<STR_LIT>' , None ) <EOL> cpp_name = ts . cpp_type ( desc [ '<STR_LIT:name>' ] [ '<STR_LIT>' ] ) <EOL> if ns is None or len ( ns ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' . format ( cpp_name ) <EOL> else : <EOL> return '<STR_LIT>' . format ( ns , cpp_name ) <EOL> def _mangle_function_pointer_name ( name , classname ) : <EOL> pyref = "<STR_LIT>" . format ( classname , name ) <EOL> cref = pyref + "<STR_LIT>" <EOL> return pyref , cref <EOL> def _isclassptr ( t , classes ) : <EOL> return ( not isinstance ( t , basestring ) and t [ <NUM_LIT:1> ] == '<STR_LIT:*>' and <EOL> isinstance ( t [ <NUM_LIT:0> ] , basestring ) and t [ <NUM_LIT:0> ] in classes ) <EOL> def _isclassdblptr ( t , classes ) : <EOL> if <NUM_LIT:2> != len ( t ) : <EOL> return False <EOL> return _isclassptr ( t [ <NUM_LIT:0> ] , classes ) and t [ <NUM_LIT:1> ] == '<STR_LIT:*>' <EOL> _exc_c_base = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> _exc_ptr_matcher = TypeMatcher ( ( MatchAny , '<STR_LIT:*>' ) ) <EOL> def _exception_str ( exceptions , lang , rtntype , ts ) : <EOL> if not exceptions : <EOL> return "<STR_LIT>" <EOL> if isinstance ( exceptions , basestring ) : <EOL> return "<STR_LIT>" + exceptions <EOL> if lang == '<STR_LIT:c>' : <EOL> if rtntype is None : <EOL> return "<STR_LIT>" <EOL> rtntype = ts . canon ( rtntype ) <EOL> return "<STR_LIT>" <EOL> elif lang == '<STR_LIT>' : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def _template_method_names ( methods ) : <EOL> methnames = set ( ) <EOL> for sig , val in methods . items ( ) : <EOL> name = sig [ <NUM_LIT:0> ] <EOL> if isinstance ( name , basestring ) : <EOL> continue <EOL> elif val [ '<STR_LIT>' ] is None : <EOL> continue <EOL> methnames . add ( name ) <EOL> return methnames <EOL> def _template_funcnames_in_mod ( mod ) : <EOL> funcnames = set ( ) <EOL> for name , desc in mod . items ( ) : <EOL> if isinstance ( name , basestring ) or not isfuncdesc ( desc ) : <EOL> continue <EOL> funcnames . add ( name ) <EOL> return funcnames <EOL> def _classnames_in_mod ( mod , ts ) : <EOL> classnames = set ( ) <EOL> for name , desc in mod . items ( ) : <EOL> if not isclassdesc ( desc ) : <EOL> continue <EOL> classnames . add ( name ) <EOL> classnames . add ( ts . basename ( name ) ) <EOL> classnames . add ( desc [ '<STR_LIT:type>' ] ) <EOL> return classnames <EOL> def _template_classnames_in_mod ( mod ) : <EOL> classnames = set ( ) <EOL> for name , desc in mod . items ( ) : <EOL> if isinstance ( name , basestring ) or not isclassdesc ( desc ) : <EOL> continue <EOL> classnames . add ( name ) <EOL> return classnames </s>
