PyNDN: Adding python exception handing inside callback. Fixing nre
Also, this version makes sure that verification always succeeds
diff --git a/PyNDN/Data.py b/PyNDN/Data.py
index 6d36dc9..48c54da 100644
--- a/PyNDN/Data.py
+++ b/PyNDN/Data.py
@@ -65,7 +65,8 @@
def verify_signature (self, key):
"""There is no actual signing in ndnSIM for now, but we will check if signature matches the key"""
- return self._data.GetSignature () == key.fakeKey
+ return True
+ # return self._data.GetSignature () == key.fakeKey
def __getattr__ (self, name):
if name == "_data":
diff --git a/PyNDN/Face.py b/PyNDN/Face.py
index 3a905fa..d63550f 100644
--- a/PyNDN/Face.py
+++ b/PyNDN/Face.py
@@ -24,8 +24,8 @@
from Interest import Interest
from Name import Name
-import time
import functools
+import traceback
deleteList = []
@@ -99,7 +99,10 @@
raise TypeError ("Unsupported type to publish data [%s]" % type (data))
def removeFromDeleteList (object):
- deleteList.remove (object)
+ try:
+ deleteList.remove (object)
+ except:
+ pass
class ExpressInterestConverter:
def __init__ (self, onData, onTimeout):
@@ -108,18 +111,27 @@
def handleOnData (self, interest, data):
ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
- if self.onData:
- return self.onData (Interest (interest=interest), Data (data = data))
+ try:
+ if self.onData:
+ return self.onData (Interest (interest=interest), Data (data = data))
+ except Exception, e:
+ traceback.print_exc()
def handleOnTimeout (self, interest):
ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
- if self.onTimeout:
- self.onTimeout (Interest (interest=interest))
+ try:
+ if self.onTimeout:
+ self.onTimeout (Interest (interest=interest))
+ except Exception, e:
+ traceback.print_exc()
class OnInterestConvert (object):
def __init__ (self, onInterest):
self.onInterest = onInterest
def __call__ (self, name, interest):
ns.core.Simulator.ScheduleNow (removeFromDeleteList, self)
- if self.onInterest:
- self.onInterest (Name (name = name), Interest (interest = interest))
+ try:
+ if self.onInterest:
+ self.onInterest (Name (name = name), Interest (interest = interest))
+ except Exception, e:
+ traceback.print_exc()
diff --git a/PyNDN/Name.py b/PyNDN/Name.py
index 60ac68d..b760213 100644
--- a/PyNDN/Name.py
+++ b/PyNDN/Name.py
@@ -25,7 +25,7 @@
def __init__ (self,
value = None,
name = None):
- if name:
+ if name is not None:
if isinstance (name, ns.ndnSIM.ndn.Name):
self._name = name
elif isinstance (name, Name):
@@ -33,8 +33,15 @@
else:
raise TypeError ("Incorrect type for 'name' parameter [%s]" % type (name))
else:
- if value:
- self._name = ns.ndnSIM.ndn.Name (value)
+ if value is not None:
+ if isinstance (value, Name):
+ self._name = ns.ndnSIM.ndn.Name (value._name)
+ elif isinstance (value, ns.ndnSIM.ndn.Name):
+ self._name = ns.ndnSIM.ndn.Name (value)
+ elif isinstance (value, str):
+ self._name = ns.ndnSIM.ndn.Name (value)
+ else:
+ raise TypeError ("Not support tyupe [%s]" % type (value))
else:
self._name = ns.ndnSIM.ndn.Name ()
@@ -80,3 +87,7 @@
def isPrefixOf (self, other):
return self[:] == other[:len(self)]
+
+ @property
+ def keyName (self):
+ return self
diff --git a/PyNDN/nre.py b/PyNDN/nre.py
index 669a712..6a41948 100644
--- a/PyNDN/nre.py
+++ b/PyNDN/nre.py
@@ -138,14 +138,14 @@
matcher = re.compile(self.expr)
if self.exact:
- res = matcher.match(name[offset])
+ res = matcher.match(str(name[offset]))
if res:
self._appendBackRef(res)
self.matchResult.append(name[offset])
_LOG.debug("Succeed " + self.__class__.__name__ + ".match() ")
return True
else:
- res = matcher.search(name[offset])
+ res = matcher.search(str(name[offset]))
if res:
self._appendBackRef(res)
self.matchResult.append(name[offset])