Commit 3744ce99 authored by Yoann Pigné's avatar Yoann Pigné

Merge pull request #4 from hhromic/master

Made python sender work with newer gs-core version
parents 5d8c3adf 02e5f69e
# Created by https://www.gitignore.io
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
from gs_netstream.sender import NetStreamProxyGraph, NetStreamSender, Base64NetStreamTransport
import logging
from gs_netstream.sender import NetStreamProxyGraph, NetStreamSender
transport = Base64NetStreamTransport("default","localhost",2001)
sender = NetStreamSender(transport)
logging.basicConfig(level=logging.DEBUG)
sender = NetStreamSender(2012)
proxy = NetStreamProxyGraph(sender)
style = "node{fill-mode:plain;fill-color:gray;size:1px;}"
proxy.addAttribute("stylesheet", style)
proxy.add_attribute("stylesheet", style)
proxy.addAttribute("ui.antialias", True)
proxy.addAttribute("layout.stabilization-limit", 0)
proxy.add_attribute("ui.antialias", True)
proxy.add_attribute("layout.stabilization-limit", 0)
for i in range(0,500):
proxy.addNode(str(i))
if(i>0):
proxy.addEdge(str(i)+"_"+str(i-1), str(i), str(i-1),False)
proxy.addEdge(str(i)+"__"+str(i/2), str(i), str(i/2), False)
\ No newline at end of file
proxy.add_node(str(i))
if i > 0:
proxy.add_edge(str(i) + "_" + str(i-1), str(i), str(i-1), False)
proxy.add_edge(str(i) + "__" + str(i/2), str(i), str(i/2), False)
......@@ -9,54 +9,50 @@ Copyright (c) 2011 University of Luxembourg. All rights reserved.
import sys
import os
import unittest
class AttributeSink(object):
def graphAttributeAdded(self, source_id, time_id, attribute, value):
raise NotImplementedError
def graphAttributeChanged(self, source_id, time_id, attribute, old_value, new_value):
raise NotImplementedError
def graphAttributeRemoved(self, source_id, time_id, attribute):
raise NotImplementedError
def nodeAttributeAdded(self, source_id, time_id, node_id, attribute, value):
raise NotImplementedError
def nodeAttributeChanged(self, source_id, time_id, node_id, attribute, old_value, new_value):
raise NotImplementedError
def nodeAttributeRemoved(self, source_id, time_id, node_id, attribute):
raise NotImplementedError
def edgeAttributeAdded(self, source_id, time_id, edge_id, attribute, value):
raise NotImplementedError
def edgeAttributeChanged(self, source_id, time_id, edge_id, attribute, old_value, new_value):
raise NotImplementedError
def edgeAttributeRemoved(self, source_id, time_id, edge_id, attribute):
raise NotImplementedError
def graph_attribute_added(self, source_id, time_id, attribute, value):
raise NotImplementedError
def graph_attribute_changed(self, source_id, time_id, attribute, old_value, new_value):
raise NotImplementedError
def graph_attribute_removed(self, source_id, time_id, attribute):
raise NotImplementedError
def node_attribute_added(self, source_id, time_id, node_id, attribute, value):
raise NotImplementedError
def node_attribute_changed(self, source_id, time_id, node_id, attribute, old_value, new_value):
raise NotImplementedError
def node_attribute_removed(self, source_id, time_id, node_id, attribute):
raise NotImplementedError
def edge_attribute_added(self, source_id, time_id, edge_id, attribute, value):
raise NotImplementedError
def edge_attribute_changed(self, source_id, time_id, edge_id, attribute, old_value, new_value):
raise NotImplementedError
def edge_attribute_removed(self, source_id, time_id, edge_id, attribute):
raise NotImplementedError
class ElementSink(object):
def nodeAdded(self, source_id, time_id, node_id):
raise NotImplementedError
def nodeRemoved(self, source_id, time_id, node_id):
raise NotImplementedError
def edgeAdded(self, source_id, time_id, edge_id, from_node, to_node, directed):
raise NotImplementedError
def edgeRemoved(self, source_id, time_id, edge_id):
raise NotImplementedError
def graphCleared(self):
raise NotImplementedError
def stepBegins(self, source_id, time_id, timestamp):
raise NotImplementedError
def node_added(self, source_id, time_id, node_id):
raise NotImplementedError
def node_removed(self, source_id, time_id, node_id):
raise NotImplementedError
def edge_added(self, source_id, time_id, edge_id, from_node, to_node, directed):
raise NotImplementedError
def edge_removed(self, source_id, time_id, edge_id):
raise NotImplementedError
def step_begun(self, source_id, time_id, timestamp):
raise NotImplementedError
def graph_cleared(self, source_id, time_id):
raise NotImplementedError
"""
the NetStream constants module.
the NetStream constants module.
Contains the constant bytes used in the protocol to identifie data types and events.
Contains the constant bytes used in the protocol to identifie data types and events.
"""
"""Followed by an 32-bit signed integer for this protocol version. Certainly useless."""
......@@ -13,113 +13,104 @@ EVENT_START = 0x01
"""Not used."""
EVENT_END = 0x02
# ==============================
# = GraphStream's graph events =
# ==============================
"""Followed by a node id (TYPE_STRING format)"""
EVENT_ADD_NODE = 0x10
"""Followed by a node id (TYPE_STRING format)"""
EVENT_DEL_NODE = 0x11
"""
Followed by
- an edge id (TYPE_STRING format),
- an source node id (TYPE_STRING format),
Followed by
- an edge id (TYPE_STRING format),
- an source node id (TYPE_STRING format),
- a target node id (TYPE_STRING format
- a boolean indicating if directed (TYPE_BOOLEAN format)
- a boolean indicating if directed (TYPE_BOOLEAN format)
"""
EVENT_ADD_EDGE = 0x12
"""Followed by an edge id (TYPE_STRING format) """
EVENT_DEL_EDGE = 0x13
"""Followed by double (TYPE_DOUBLE format) """
EVENT_STEP = 0x14
EVENT_CLEARED = 0x15
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute value
- the attribute value
"""
EVENT_ADD_GRAPH_ATTR = 0x16
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute old value
- the attribute new value
- the attribute new value
"""
EVENT_CHG_GRAPH_ATTR = 0x17
"""
Followed by
Followed by
- the attribute id (TYPE_STRING format)
"""
EVENT_DEL_GRAPH_ATTR = 0x18
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute value
- the attribute value
"""
EVENT_ADD_NODE_ATTR = 0x19
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute old value
- the attribute new value
- the attribute new value
"""
EVENT_CHG_NODE_ATTR = 0x1a
"""
Followed by
Followed by
- the node id (TYPE_STRING format)
- the attribute id (TYPE_STRING format)
"""
EVENT_DEL_NODE_ATTR = 0x1b
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute value
- the attribute value
"""
EVENT_ADD_EDGE_ATTR = 0x1c
"""
Followed by
Followed by
- an attribute id (TYPE_STRING format)
- the attribute TYPE
- the attribute old value
- the attribute new value
- the attribute new value
"""
EVENT_CHG_EDGE_ATTR = 0x1d
"""
Followed by
Followed by
- the edge id (TYPE_STRING format)
- the attribute id (TYPE_STRING format)
"""
EVENT_DEL_EDGE_ATTR = 0x1e
# ===============
# = Value Types =
# ===============
......@@ -128,14 +119,14 @@ EVENT_DEL_EDGE_ATTR = 0x1e
Followed by a byte who's value is 0 or 1
"""
TYPE_BOOLEAN = 0x50
"""
An array of booleans. Followed by first, a 16-bits integer for the number
of booleans and then, a list of bytes who's value is 0 or 1
"""
TYPE_BOOLEAN_ARRAY = 0x51
"""Followed by a signed byte [-127,127]"""
"""Followed by a signed byte [-127,127]"""
TYPE_BYTE = 0x52
"""
......@@ -169,7 +160,7 @@ TYPE_LONG = 0x58
"""
An array of longs. Followed by first, a 16-bits integer for the number of
longs and then, a list of 62-bit signed integers
longs and then, a list of 64-bit signed integers
"""
TYPE_LONG_ARRAY = 0x59
......@@ -187,7 +178,6 @@ TYPE_FLOAT_ARRAY = 0x5b
"""Followed by a double precision 64-bits floating point number"""
TYPE_DOUBLE = 0x5c
"""
Array of double. Followed by first, a 16-bits integer for the number of
doubles and then, a list of 64-bit doubles
......@@ -206,11 +196,10 @@ Raw data, good for serialization. Followed by first, a 16-bits integer
indicating the length in bytes of the dataset, and then the data itself.
"""
TYPE_RAW = 0x5f
"""
An type-unspecified array. Followed by first, a
16-bits integer indicating the number of elements, and then, the elements
themselves. The elements themselves have to give their type.
"""
TYPE_ARRAY = 0x60
This diff is collapsed.
#!/usr/bin/env python
"""Implementation for encoding unsigned varints."""
def encoding_size(value):
"""Computes the encoding size of a value."""
if value < (1L << 7):
return 1
if value < (1L << 14):
return 2
if value < (1L << 21):
return 3
if value < (1L << 28):
return 4
if value < (1L << 35):
return 5
if value < (1L << 42):
return 6
if value < (1L << 49):
return 7
if value < (1L << 56):
return 8
return 9
def encode_unsigned(value):
"""Encodes a Python integer into its varint representation."""
if not isinstance(value, int) or value < 0:
raise TypeError("value argument is not an integer or is negative")
size = encoding_size(value)
buff = bytearray(size)
for i in xrange(size):
head = 128
if i == size - 1:
head = 0
buff[i] = (((value >> (7 * i)) & 127) ^ head) & 255
return buff
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment