|
@@ -0,0 +1,131 @@
|
|
|
+import urllib
|
|
|
+import urllib2
|
|
|
+import json
|
|
|
+
|
|
|
+# Helper functions
|
|
|
+taskname = "test"
|
|
|
+address = "http://localhost:8001"
|
|
|
+last_output = None
|
|
|
+
|
|
|
+def _input(value):
|
|
|
+ # Ugly json encoding of primitives
|
|
|
+ value = '"%s"' if type(value) == str else value
|
|
|
+ urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": value, "taskname": taskname})))
|
|
|
+
|
|
|
+def _output():
|
|
|
+ try:
|
|
|
+ global last_output
|
|
|
+ last_output = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "taskname": taskname})))
|
|
|
+ return last_output
|
|
|
+ except:
|
|
|
+ raise UnknownError()
|
|
|
+
|
|
|
+def _output_last():
|
|
|
+ return last_output
|
|
|
+
|
|
|
+# Exceptions
|
|
|
+class UnknownError(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+class UnknownIdentifier(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+class UnknownType(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+class UnsupportedValue(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+class CompilationError(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+class NoSuchAttribute(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+# Actual functions to use for the wrapper
|
|
|
+def list():
|
|
|
+ """Return a list of all IDs and the type of the element"""
|
|
|
+ pass
|
|
|
+ # return [(name1, type1), (name2, type2), ...]
|
|
|
+ # raises UnknownError
|
|
|
+
|
|
|
+def types():
|
|
|
+ """Return a list of all types usable in the model"""
|
|
|
+ pass
|
|
|
+ # return [type1, type2, ...]
|
|
|
+ # raises UnknownError
|
|
|
+
|
|
|
+def read(ID):
|
|
|
+ """Return a tuple of information on the element: its type and source/target (None if not an edge)"""
|
|
|
+ pass
|
|
|
+ # return (type, (source, target))
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+
|
|
|
+def read_attrs(ID):
|
|
|
+ """Return a dictionary of attribute value pairs"""
|
|
|
+ pass
|
|
|
+ # return {attr1: value1, attr2: value2, ...}
|
|
|
+ # raises UnknownError
|
|
|
+
|
|
|
+def verify():
|
|
|
+ """Return the result of conformance checking (OK = conforms, otherwise error message)"""
|
|
|
+ pass
|
|
|
+ # return "OK"
|
|
|
+ # raises UnknownError
|
|
|
+
|
|
|
+def instantiate(typename, edge=None, ID=""):
|
|
|
+ """Create a new instance of the specified typename, between the selected elements (if not None), and with the provided ID (if any)"""
|
|
|
+ pass
|
|
|
+ # return instantiated_ID
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownType
|
|
|
+ # raises UnknownIdentifier
|
|
|
+
|
|
|
+def delete(ID):
|
|
|
+ """Delete the element with the given ID"""
|
|
|
+ pass
|
|
|
+ # return None
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+
|
|
|
+def attr_assign(ID, attr, value):
|
|
|
+ """Assign a value to an attribute"""
|
|
|
+ pass
|
|
|
+ # return None
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+ # raises NoSuchAttribute
|
|
|
+ # raises UnsupportedValue
|
|
|
+
|
|
|
+def attr_assign_code(ID, attr, code):
|
|
|
+ """Assign a piece of Action Language code to the attribute"""
|
|
|
+ pass
|
|
|
+ # return None
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+ # raises NoSuchAttribute
|
|
|
+ # raises UnsupportedValue
|
|
|
+
|
|
|
+def upload(new_model):
|
|
|
+ """Overwrite the current model with the provided model"""
|
|
|
+ pass
|
|
|
+ # return None
|
|
|
+ # raises UnknownError
|
|
|
+ # raises CompilationError
|
|
|
+
|
|
|
+def read_outgoing(ID, typename):
|
|
|
+ """Returns a list of all outgoing associations of a specific type ("" = all)"""
|
|
|
+ pass
|
|
|
+ # return [name1, name2, ...]
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+ # raises UnknownType
|
|
|
+
|
|
|
+def read_incoming(ID, typename):
|
|
|
+ """Returns a list of all incoming associations of a specific type ("" = all)"""
|
|
|
+ pass
|
|
|
+ # return [name1, name2, ...]
|
|
|
+ # raises UnknownError
|
|
|
+ # raises UnknownIdentifier
|
|
|
+ # raises UnknownType
|