bool PyDumpVisitor::VisitList( const PyList* rep )
{
    if( rep->empty() )
        _print( "%sList: Empty", _pfx() );
    else
    {
        _print( "%sList: %lu elements", _pfx(), rep->size() );

        PyList::const_iterator cur, _end;
        cur = rep->begin();
        _end = rep->end();
        for( uint32 i = 0; cur != _end; cur++, i++ )
        {
            if( i > 200 && !fullNested() )
            {
                _print( "%s  ... truncated ...", _pfx() );
                break;
            }

            _pfxExtend( "  [%2u] ", i );
            bool res = (*cur)->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;
        }
    }
    return true;
}
bool PyDumpVisitor::VisitPackedRow( const PyPackedRow* rep )
{
    _print( "%sPacked Row:", _pfx() );
    _print( "%s column_count=%u", _pfx(), rep->header()->ColumnCount() );

    PyPackedRow::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for( uint32 i = 0; cur != end; cur++, i++ )
    {
        _pfxExtend( "  [%2u] %s: ", i, rep->header()->GetColumnName( i )->content().c_str() );

        bool res = true;
        if( (*cur) == NULL )
            _print( "%s(None)", _pfx() );
        else
            res = (*cur)->visit( *this );

        _pfxWithdraw();

        if( !res )
            return false;
    }

    return true;
}
bool PyDumpVisitor::VisitString( const PyString *rep )
{
    if( IsPrintable( rep ) )
        _print( "%sString: '%s'", _pfx(), rep->content().c_str() );
    else
        _print( "%sString: '<binary, len=%lu>'", _pfx(), rep->content().length() );

    return true;
}
bool PyDumpVisitor::VisitBuffer( const PyBuffer* rep )
{
    _print( "%sBuffer of length %lu:", _pfx(), rep->content().size() );

    _pfxExtend( "  " );
    _dump( _pfx(), &rep->content()[ 0 ], rep->content().size() );
    _pfxWithdraw();

    return true;
}
bool PyDumpVisitor::VisitWString( const PyWString* rep )
{
    // how to do it correctly?
    if( IsPrintable( rep ) )
        _print( "%sWString: '%s'", _pfx(), rep->content().c_str() );
    else
        _print( "%sWstring: '<binary, len=%lu>'", _pfx(), rep->content().length() );

    return true;
}
Example #6
0
bool PyXMLGenerator::VisitObject( const PyObject* rep )
{
    fprintf( mInto, "%s<objectInline>\n", _pfx() );

    _pfxExtend( "    " );
    bool res = PyPfxVisitor::VisitObject( rep );
    _pfxWithdraw();

    fprintf( mInto, "%s</objectInline>\n", _pfx() );

    return res;
}
Example #7
0
bool PyXMLGenerator::VisitSubStream( const PySubStream* rep )
{
    fprintf( mInto, "%s<substreamInline>\n", _pfx() );

    _pfxExtend( "    " );
    bool res = PyVisitor::VisitSubStream( rep );
    _pfxWithdraw();

    fprintf( mInto, "%s</substreamInline>\n", _pfx() );

    return res;
}
bool PyDumpVisitor::VisitSubStruct( const PySubStruct* rep )
{
    _print( "%sSubstruct:", _pfx() );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitSubStruct( rep );
    _pfxWithdraw();

    return res;
}
bool PyDumpVisitor::VisitChecksumedStream( const PyChecksumedStream* rep )
{
    _print( "%sStream With Checksum: 0x%08x", _pfx(), rep->checksum() );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitChecksumedStream( rep );
    _pfxWithdraw();

    return res;
}
bool PyDumpVisitor::VisitSubStream( const PySubStream* rep )
{
    _print( "%sSubstream: %s", _pfx(), ( rep->decoded() == NULL ) ? "from data" : "from rep" );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitSubStream( rep );
    _pfxWithdraw();

    return res;
}
Example #11
0
bool PyLookupDumpVisitor::VisitString( const PyString* rep )
{
    if( !PyLogDumpVisitor::VisitString( rep ) )
        return false;

    const char* look = resolver()->LookupString( rep->content().c_str() );
    if( look != NULL )
        _print( "%s    %s", _pfx(), look );

    return true;
}
Example #12
0
bool PyLookupDumpVisitor::VisitInteger( const PyInt* rep )
{
    if( !PyLogDumpVisitor::VisitInteger( rep ) )
        return false;

    const char* look = resolver()->LookupInt( rep->value() );
    if( look != NULL )
        _print( "%s    %s", _pfx(), look );

    return true;
}
Example #13
0
bool PyXMLGenerator::VisitTuple( const PyTuple* rep )
{
    fprintf( mInto, "%s<tupleInline>\n", _pfx() );

    _pfxExtend( "    " );

    //! visits the tuple elements.
    PyTuple::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for(uint32 i = 0; cur != end; ++cur, ++i)
    {
        fprintf( mInto, "%s<!-- %d -->\n", _pfx(), i );
        (*cur)->visit( *this );
    }

    _pfxWithdraw();

    fprintf( mInto, "%s</tupleInline>\n", _pfx() );

    return true;
}
bool PyDumpVisitor::VisitDict( const PyDict* rep )
{
    if( rep->empty() )
        _print( "%sDictionary: Empty", _pfx() );
    else
    {
        _print( "%sDictionary: %lu entries", _pfx(), rep->size() );

        PyDict::const_iterator cur, _end;
        cur = rep->begin();
        _end = rep->end();
        for( uint32 i = 0; cur != _end; cur++, i++ )
        {
            if( i > 200 && !fullNested() )
            {
                _print( "%s  ... truncated ...", _pfx() );
                break;
            }

            _pfxExtend( "  [%2u] Key: ", i );
            bool res = cur->first->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;

            _pfxExtend( "  [%2u] Value: ", i );
            res = cur->second->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;
        }
    }
    return true;
}
Example #15
0
void PyPfxVisitor::_pfxExtend( const char* fmt, ... )
{
    va_list ap;
    va_start( ap, fmt );

    char* res;
    vasprintf( &res, fmt, ap );

    va_end( ap );

    std::string p( _pfx() );
    p += res;
    mPfxStack.push( p );

    SafeFree( res );
}
bool PyDumpVisitor::VisitObject( const PyObject* rep )
{
    _print( "%sObject:", _pfx() );

    _pfxExtend( "  Type: " );
    bool res = rep->type()->visit( *this );
    _pfxWithdraw();

    if( !res )
        return false;

    _pfxExtend( "  Args: " );
    res = rep->arguments()->visit( *this );
    _pfxWithdraw();

    if( !res )
        return false;

    return true;
}
Example #17
0
bool PyXMLGenerator::VisitChecksumedStream( const PyChecksumedStream* rep )
{
    fprintf( mInto, "%s<!-- PyChecksumedStream stub -->\n", _pfx() );

    return true;
}
Example #18
0
bool PyXMLGenerator::VisitString( const PyString* rep )
{
    fprintf( mInto, "%s<string name=\"string%u\" />\n", _pfx(), mItem++ );

    return true;
}
Example #19
0
bool PyXMLGenerator::VisitPackedRow( const PyPackedRow* rep )
{
    fprintf( mInto, "%s<!-- PyPackedRow stub -->\n", _pfx() );

    return true;
}
Example #20
0
bool PyXMLGenerator::VisitNone( const PyNone* rep )
{
    fprintf( mInto, "%s<none />\n", _pfx() );

    return true;
}
Example #21
0
bool PyXMLGenerator::VisitBuffer( const PyBuffer* rep )
{
    fprintf( mInto, "%s<buffer name=\"buffer%u\" />\n", _pfx(), mItem++ );

    return true;
}
Example #22
0
bool PyXMLGenerator::VisitReal( const PyFloat* rep )
{
    fprintf( mInto, "%s<real name=\"real%u\" />\n", _pfx(), mItem++ );

    return true;
}
Example #23
0
bool PyXMLGenerator::VisitBoolean( const PyBool* rep )
{
    fprintf( mInto, "%s<bool name=\"bool%u\" />\n", _pfx(), mItem++ );

    return true;
}
Example #24
0
bool PyXMLGenerator::VisitInteger( const PyInt* rep )
{
    fprintf( mInto, "%s<int name=\"integer%u\" />\n", _pfx(), mItem++ );

    return true;
}
bool PyDumpVisitor::VisitReal( const PyFloat* rep )
{
    _print( "%sReal field: %f", _pfx(), rep->value() );
    return true;
}
Example #26
0
bool PyXMLGenerator::VisitList( const PyList* rep )
{
    //for now presume we cant do anything useful with lists that contain
    //more than a few things...
    if( rep->size() < 5 )
    {
        fprintf( mInto, "%s<listInline>\n", _pfx() );

        _pfxExtend( "    " );

        //! visit the list elements.
        PyList::const_iterator cur, end;
        cur = rep->begin();
        end = rep->end();
        for( uint32 i = 0; cur != end; ++cur, ++i )
        {
            fprintf( mInto, "%s<!-- %u -->\n", _pfx(), i );
            (*cur)->visit( *this );
        }

        _pfxWithdraw();

        fprintf( mInto, "%s</listInline>\n", _pfx() );
    }
    else
    {
        enum
        {
            TypeUnknown,
            TypeString,
            TypeInteger,
            TypeReal,
            TypeMixed
        } eletype;
        eletype = TypeUnknown;

        //scan the list to see if we can classify the contents.
        PyList::const_iterator cur, end;
        cur = rep->begin();
        end = rep->end();
        for(; cur != end; cur++)
        {
            if( (*cur)->IsString() )
            {
                if( eletype == TypeInteger || eletype == TypeReal )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeString;
            }
            else if( (*cur)->IsInt() )
            {
                if( eletype == TypeString || eletype == TypeReal )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeInteger;
            }
            else if( (*cur)->IsFloat() )
            {
                if( eletype == TypeString || eletype == TypeInteger )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeReal;
            }
            else
            {
                eletype = TypeMixed;
                break;
            }
        }

        switch( eletype )
        {
        case TypeString:
            fprintf( mInto, "%s<listStr name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeInteger:
            fprintf( mInto, "%s<listInt name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeReal:
            fprintf( mInto, "%s<listReal name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeUnknown:
        case TypeMixed:
            fprintf( mInto, "%s<list name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        }
    }

    return true;
}
Example #27
0
bool PyXMLGenerator::VisitDict( const PyDict* rep )
{
    enum
    {
        DictInline,
        DictStringKey,
        DictIntKey,
        DictRaw
    } ktype;

    enum
    {
        ValueUnknown,
        ValueString,
        ValueInt,
        ValueReal,
        ValueMixed
    } vtype;

    ktype = DictInline;
    vtype = ValueUnknown;

    //this is kinda a hack, but we want to try and classify the contents of this dict:
    PyDict::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for(; cur != end; ++cur)
    {
        if( cur->first->IsString() )
        {
            if( ktype == DictIntKey )
            {
                //we have varying key types, raw dict it is.
                ktype = DictRaw;
                break;
            }
            else if( ktype == DictInline )
                ktype = DictStringKey;
        }
        else if( cur->first->IsInt() )
        {
            if( ktype == DictStringKey )
            {
                //we have varying key types, raw dict it is.
                ktype = DictRaw;
                break;
            }
            else if( ktype == DictInline )
                ktype = DictIntKey;
        }
        else
        {
            //anything but those key types is more than we can think about, keep it raw.
            ktype = DictRaw;
            break;
        }

        if( cur->second->IsString() )
        {
            if( vtype == ValueInt || vtype == ValueReal )
                vtype = ValueMixed;
            else if( vtype == ValueUnknown )
                vtype = ValueString;
        }
        else if(cur->second->IsInt())
        {
            if( vtype == ValueString || vtype == ValueReal )
                vtype = ValueMixed;
            else if( vtype == ValueUnknown )
                vtype = ValueInt;
        }
        else if( cur->second->IsFloat() )
        {
            if( vtype == ValueString || vtype == ValueInt )
                vtype = ValueMixed;
            else if(vtype == ValueUnknown)
                vtype = ValueReal;
        }
        else
            vtype = ValueMixed;
    }

    if( ktype == DictRaw )
    {
        fprintf( mInto, "%s<dict name=\"dict%u\" />\n", _pfx(), mItem++ );
        return true;
    }
    else if( ktype == DictIntKey )
    {
        //cant do an inline dict, but can try a vector
        switch( vtype )
        {
        case ValueString:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"string\" />\n", _pfx(), mItem++ );
            break;
        case ValueInt:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"int\" />\n", _pfx(), mItem++ );
            break;
        case ValueReal:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"real\" />\n", _pfx(), mItem++ );
            break;
        case ValueUnknown:
        case ValueMixed:
            fprintf( mInto, "%s<dictRaw name=\"dict%u\" />\n", _pfx(), mItem++ );
            break;
        }

        return true;
    }

    fprintf( mInto, "%s<dictInline>\n", _pfx() );

    _pfxExtend( "    " );

    //! visit dict elements.
    cur = rep->begin();
    end = rep->end();
    for(; cur != end; ++cur)
    {
        if( !cur->first->IsString() )
        {
            fprintf( mInto, "%s<!-- non-string dict key of type %s -->\n", _pfx(), cur->first->TypeString() );
            return false;
        }
        PyString* str = cur->first->AsString();

        fprintf( mInto, "%s<dictInlineEntry key=\"%s\">\n", _pfx(), str->content().c_str() );

        _pfxExtend( "    " );
        cur->second->visit( *this );
        _pfxWithdraw();

        fprintf( mInto, "%s</dictInlineEntry>\n", _pfx() );
    }

    _pfxWithdraw();

    fprintf( mInto, "%s</dictInline>\n", _pfx() );

    return true;
}
bool PyDumpVisitor::VisitBoolean( const PyBool* rep )
{
    _print( "%sBoolean field: %s", _pfx(), rep->value() ? "true" : "false" );
    return true;
}
bool PyDumpVisitor::VisitNone( const PyNone* rep )
{
    _print( "%s(None)", _pfx() );
    return true;
}
Example #30
0
bool PyXMLGenerator::VisitObjectEx( const PyObjectEx* rep )
{
    fprintf( mInto, "%s<!-- PyObjectEx stub -->\n", _pfx() );

    return true;
}