I ended up working around the problem by making a hash of hashes of
only the values in the Ether object that could be converted to
strings, and passing that to packet_info.html.  I think it was choking
on some weird binary data fields.

If I were to make a request though, it would be great if the
TypeError: emit() error did not hide underlying errors.  Maybe before
calling emit, the script that calls emit could validate the code being
called first?  I'm not familiar with how it's architected so I'm
guessing at that suggestion.  I've run into issues before where I got
rid of that error by fixing other python typos in the template that
had nothing to do with emit() that I could see.

Here is the solution I used:
---
file #1
    def get_ether_info(self):
        layer = Ether(self.actual_packet.original_data)
        result = dict()
        layer_order = list()
        while layer is not None:
            temp_dict = dict()
            layer_order.append(layer.name)
            for key in layer.fields:
                try:
                    value = str(layer.fields[key])
                    temp_dict[key] = value
                except:
                    print "Exception on " + key
                    pass
            result[layer.name] = temp_dict
            if layer.payload is not None and len(layer.payload) > 0:
                layer = layer.payload
            else:
                layer = None
        return (layer_order, result)
--
file #2: packet_info.html (partial)
    <caption>Modified</caption>
    $for p in modified_list:
        <tr><td>
        $ (layer_order, layers) = p.get_ether_info()
        <table><tr>
        $for layer_name in layer_order:
            <td  valign="top">
            <table>
            <tr><th colspan="2">$layer_name</th></tr>
            $ layer = layers[layer_name]
            $for key in layer.keys():
                <tr><td>$key</td><td>$layer[key]</td></tr>
            </table>
            </td>
        </tr></table>
        </td></tr>

On Jul 16, 4:03 pm, Caden <[email protected]> wrote:
> Incidentally, I'm in freenode IRC #webpy channel for the next few
> hours (4:00 pm CST here) if anyone can help.
> Suggestions welcome.  :)
>
> On Jul 16, 3:50 pm, Caden <[email protected]> wrote:
>
> > Not sure I understand-- I'm not passing in HTML, but passing in a data
> > structure to this template.  Its an array of (my own) packet objects.
>
> > On Jul 16, 1:57 pm, Greg Milby <[email protected]> wrote:
>
> > > *how are you passing in the html?*
> > > *
> > > *
> > > *
> > > *
> > > -----------------------
> > > Visithttp://www.superantispyware.com/superantispyware.html?rid=3971RemoveAll
> > > The Spyware - Not Just The Easy Ones!http://1-4-u.info|Don't send 
> > > insanely long links!
> > > Need a Pick-Me-Up?http://quotes.feedtheguru.com
>
> > > On Fri, Jul 16, 2010 at 2:44 PM, Caden <[email protected]> wrote:
>
> > > > The calling statement looks like:
>
> > > > render.packet_info(modified)
>
> > > > Also, if I remove most of the HTML and just leave a few table tags, it
> > > > renders without error.  When I reintroduce my code (which is based on
> > > > code tested in a plain non-template python script) the error comes
> > > > back.
>
> > > > On Jul 16, 6:58 am, Greg Milby <[email protected]> wrote:
> > > > > *i'm sure branko will have a better answer :), but it usually means 
> > > > > you
> > > > are
> > > > > passing in 3 items in your RENDER statement,  template is looking for
> > > > two.
> > > > > *-----------------------
> > > > > Visithttp://
> > > >www.superantispyware.com/superantispyware.html?rid=3971RemoveAll
> > > > > The Spyware - Not Just The Easy Ones!http://1-4-u.info|Don't send
> > > > insanely long links!
> > > > > Need a Pick-Me-Up?http://quotes.feedtheguru.com
>
> > > > > On Fri, Jul 16, 2010 at 7:12 AM, C. Howell <[email protected]> wrote:
> > > > > > I'm wondering if anyone could offer me advice on debugging or fixing
> > > > this
> > > > > > code snippet.
>
> > > > > > In the code below, get_ether returns a Scapy ethernet object.  This 
> > > > > > is
> > > > an
> > > > > > html template.   I have other templates working on this same
> > > > > > project/environment which is web.py .34
>
> > > > > > I've been getting a lot of these errors:
>
> > > > > > TypeError: emit() takes exactly 2 arguments (3 given)
>
> > > > > > They're extremely difficult to debug, as they do not point to any
> > > > > > particular place in the template.  I've tried deleting sections of 
> > > > > > code
> > > > and
> > > > > > reintroducing them, but I have not been able to narrow down the 
> > > > > > problem
> > > > more
> > > > > > specifically than this section.
>
> > > > > > Thanks,
>
> > > > > > Caden
>
> > > > > > $def with (modified_list)
> > > > > > $# This is where the packet info is formatted for display
> > > > > > <table>
> > > > > >     <caption>Modified</caption>
> > > > > >     $for p in modified_list:
> > > > > >         <tr><td>
> > > > > >         $ temp = p.get_ether()
> > > > > >         <table><tr>
> > > > > >         $while temp is not None:
> > > > > >             <td>
> > > > > >             <table>
> > > > > >             $if temp.fields is not None:
> > > > > >                 $ fields = temp.fields
> > > > > >                 $for key in fields.keys():
> > > > > >                     $if isinstance(fields[key], list) or
> > > > > > isinstance(fields[key], dict) or isinstance(fields[key], tuple) or
> > > > > > isinstance(fields[key], types.NoneType):
> > > > > >                         $pass
> > > > > >                     $else:
>
> > > > <tr><td>$key</td><td>$str(fields[key])</td></tr>
> > > > > >             $if temp.payload is not None and len(temp.payload) > 0:
> > > > > >                 $temp = temp.payload
> > > > > >             $else:
> > > > > >                 $temp = None
> > > > > >             </table>
> > > > > >             </td>
> > > > > >         </tr></table>
> > > > > >         </td></tr>
> > > > > > </table>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to