How to use the replication.share.yidl.src.yidl.py_target.PyPrimitiveType function in replication

To help you get started, we’ve selected a few replication examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtreemfs / babudb / replication / share / yidl / src / yidl / py_target.py View on Github external
if name.endswith( "_t" ): name = name[:-2]
        return "".join( ["".join( ( space_part[0].upper(), space_part[1:] ) ) for space_part in name.split( " " )] )


class PyOperation(Operation):
    def __repr__( self ):
        name = self.getName()        
        param_decls = ["self"]
        for param in self.getParameters():
            assert not param.isOutbound()
            param_decls.append( param.getIdentifier() )            
        param_decls = pad( " ", ", ".join( param_decls ), " " )
        return "def %(name)s(%(param_decls)s): raise NotImplementedError" % locals()

    
class PyPointerType(PointerType, PyPrimitiveType):
    def getBoxedTypeName( self ): return "buffer"
    def getCast( self, var_name ): return var_name
    def getDefaultValue( self ): return "\"\""
       
    
class PySequenceType(SequenceType, PyCompoundType):
    def __repr__( self ):
        name = self.getName()
        value_new = self.getValueType().getBoxedTypeName()
        value_cast = self.getValueType().getCast( "value" )
        value_write = self.getValueType().getMarshalCall( "( *this )[i]", "value" )
        value_read = self.getValueType().getUnmarshalCall( "( *this )[i]", "self[i]" )
        return """
class %(name)s(list):
    def __init__( self, init_list=[] ):
        list.__init__( self )
github xtreemfs / babudb / replication / share / yidl / src / yidl / py_target.py View on Github external
return """\
class %(name)s(object):
%(operations)s
""" % locals()
   

class PyMapType(MapType, PyCompoundType):
    def __repr__( self ):
        name = self.getName()
        return """
class %(name)s(dict): pass
""" % locals()
        
    
class PyNumericType(NumericType, PyPrimitiveType):    
    def getBoxedTypeName( self ):
        if self.getName() == "float" or self.getName() == "double": return "float"
        elif self.getName().endswith( "int64_t" ): return "long" 
        else: return "int"

    def getCast( self, var_name ):
        if self.getName() == "float" or self.getName() == "double": return "type( %(var_name)s ) == float and %(var_name)s or float( %(var_name)s )" % locals()
        else: return "( type( %(var_name)s ) == int or type( %(var_name)s ) == long ) and %(var_name)s or long( %(var_name)s )" % locals()

    def getDefaultValue( self ): return "0"
    
    def getMarshallerTypeName( self ):
        name = self.getName()
        if name.endswith( "_t" ): name = name[:-2]
        return "".join( ["".join( ( space_part[0].upper(), space_part[1:] ) ) for space_part in name.split( " " )] )
github xtreemfs / babudb / replication / share / yidl / src / yidl / py_target.py View on Github external
# Constants
INDENT_SPACES = "    "


class PyType:
    def getMarshalCall( self, var_name, qualified_var_name ): return "marshaller.write%s( \"%s\", %s )" % ( self.getMarshallerTypeName(), var_name, qualified_var_name )
    def getUnmarshalCall( self, var_name, qualified_var_name ): return qualified_var_name + " = unmarshaller.read%s( \"%s\" )" % ( self.getMarshallerTypeName(), var_name )

    
class PyPrimitiveType(PyType):
    def getConstantValue( self, value ): return value


class PyBoolType(BoolType, PyPrimitiveType):
    def getBoxedTypeName( self ): return "bool"
    def getCast( self, var_name ): return var_name
    def getConstantValue( self, value ): return ( ( "true" in value.lower() ) and "True" or "False" )
    def getDefaultValue( self ): return "False"


class PyCompoundType(PyType):
    def getCast( self, var_name ): name = self.getName(); return """( %(var_name)s is not None and ( isinstance( %(var_name)s, %(name)s ) and %(var_name)s or %(name)s( %(var_name)s ) ) or %(name)s() )""" % locals()
    def getDefaultValue( self ): return "None"


class PyConstant(Constant):
    def __repr__( self ):
        return self.getIdentifier() + " = " + self.getType().getConstantValue( self.getValue() )
github xtreemfs / babudb / replication / share / yidl / src / yidl / py_target.py View on Github external
def append( self, value ): list.append( self, %(value_cast)s )
    def __setvalue__( self, key, value ): list.__setvalue__( self, key, %(value_cast)s )

    def marshal( self, marshaller ):
        for value in self:
            %(value_write)s

    def unmarshal( self, marshaller ):
        for i in xrange( len( self ) ):
            %(value_read)s
        return self
             
""" % locals()


class PyStringType(StringType, PyPrimitiveType):
    def getBoxedTypeName( self ): return "str"
    def getCast( self, var_name ): return """isinstance( %(var_name)s, str ) and %(var_name)s or str( %(var_name)s )""" % locals()
    def getDefaultValue( self ): return "\"\""
    def getConstantValue( self, value ): return "\"" + value + "\""
    
    
class PyStructType(StructType, PyCompoundType):
    def __repr__( self ):
        name = self.getName()
        parent_type_names = ", ".join( self.getParentTypeNames() )
        other_methods = lpad( "\n\n", indent( self.getOtherMethods(), INDENT_SPACES ) )

        if len( self.getMembers() ) > 0:
            init_vars = ", ".join( [member.getIdentifier() + "=" + member.getType().getDefaultValue() for member in self.getMembers()] )
            init_statements =  ( "\n" + INDENT_SPACES * 2 ).join( ["self." + member.getIdentifier() + " = " + member.getType().getCast( member.getIdentifier() ) for member in self.getMembers()] )
            marshal_statements = ( "\n" + INDENT_SPACES * 2 ).join( [member.getIdentifier() + " = " + member.getType().getCast( "self." + member.getIdentifier() ) + "; " + member.getType().getMarshalCall( member.getIdentifier(), member.getIdentifier() ) for member in self.getMembers()] )