123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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
|