def fetch (token): """ Constructs sample object by fetching myfxbook. """ url = "http://www.myfxbook.com/api/get-community-outlook.json?session=%s" % token data = urlfetch.fetch (url, headers = {'Cache-Control': 'max-age=30'}).content return MyFXCommunitySample (datetime.datetime.utcnow (), json.JsonReader ().read (data))
def main(): """Generates Gl bindings""" with open(IN_FILE, 'r') as f: text_out = [] data = f.read() try: # Try the python 2.6 json module first. json_in = json.loads(data) except AttributeError: # Fall back to json-py. reader = json.JsonReader() json_in = reader.read(data) constants, functions = [], [] for obj in json_in: if not re.search(EXCLUDE, obj['name']): try: if obj['type'] == 'c': constants.append(obj['name']) else: text_out.append(generate_function(obj)) functions.append(obj['name']) except Exception, e: #probably an unhandled type print e pass
def authorize (name, password): """ Performs login to MyFXBook server to obtain token. Saves name and token for future usage (password won't be saved). Returns True if login successfull, False if an error occured. """ url = "https://www.myfxbook.com/api/login.json?email=%s&password=%s" % (name, password) data = urlfetch.fetch (url).content data = json.JsonReader ().read (data) if data['error']: return False MyFXToken (login = name, token = data['session']).put () return True
def ajax(self): postData = cherrypy.request.body.read() request = json.JsonReader().read(postData) print request if not 'rootPassword' in request: return json.JsonWriter().write({"error": "No password specified."}) try: self._ensureConfigFileExists() self._validatePassword(request['rootPassword']) if 'adminUsername' in request: self._setAdminUser(request['adminUsername'], request['adminPassword'], request['adminConfirmPassword']) if 'adminRoot' in request: self._setAdminRoot(request['adminUsername'], request['adminRoot']) except ValueError, error: return json.JsonWriter().write({"error": str(error)})
def _send(request): import socket, json dumps = None loads = None sock = None dist = None try: dist = __n__['platform'] except: pass if dist == 'openwrt': dumps = json.JsonWriter().write loads = json.JsonReader().read sock = '/var/run/db.sock' else: dumps = json.dumps loads = json.loads sock = '/var/run/openvswitch/db.sock' s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(sock) pdu = dumps(request) s.send(pdu) response = s.recv(4096) #__n__['logger'].debug(_logstr('... JSON-RPC request ...', str(pdu), '... JSON-RPC response ...', response)) #transaction = '--json-rpc:{"request":%s, "response":%s}' % (str(pdu),response) transaction = '{"request":%s, "response":%s}' % (str(pdu), response) __n__['logger2'].debug(transaction, extra={'content_type': 'application/json'}) return loads(response)
import os, socket, json DIST = 'debian' dumps = None loads = None sock = None if DIST == 'debian': dumps = json.dumps loads = json.loads sock = '/var/run/openvswitch/db.sock' elif DIST == 'openwrt': dumps = json.JsonWriter().write loads = json.JsonReader().read sock = '/var/run/db.sock' s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(sock) rpc = { "method": "transact", "params": ["Open_vSwitch", { "op": "insert", "table": "NLAN", "row": {} }], "id": 0 }
def json_decode(data): return json.JsonReader().read(data)