~vomun-developers/anonplus/vomun-trunk

« back to all changes in this revision

Viewing changes to src/libs/morado/morado.py

  • Committer: AJ00200
  • Date: 2011-11-25 20:47:13 UTC
  • Revision ID: git-v1:aafa60861564423d56571a2d573eeabf1967afbe
Minor PEP8 fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import asynchat
3
3
import socket
4
4
import json
5
 
import SocketServer
 
5
# import SocketServer
6
6
import traceback
7
7
import os
8
8
import sys
27
27
 
28
28
 
29
29
class APIHandler(asynchat.async_chat):
30
 
    def __init__(self,sock):
31
 
        asynchat.async_chat.__init__(self,sock)
 
30
    def __init__(self, sock):
 
31
        asynchat.async_chat.__init__(self, sock)
32
32
        self.data = 0
33
33
        self.buffer = ""
34
34
        self.size = -1
35
35
        self.set_terminator(4)
36
36
 
37
 
    def read(self,size):
 
37
    def read(self, size):
38
38
        size = int(size)
39
39
        datareturn = ""
40
40
        
59
59
            try:
60
60
                data =  self.buffer
61
61
                retdata = self.handle_api(data)
62
 
                retjson = json.dumps(retdata,cls=ComplexEncoder)
 
62
                retjson = json.dumps(retdata, cls=ComplexEncoder)
63
63
                length = len(retjson)
64
 
                self.push("%4i%s" % (length,retjson))
 
64
                self.push("%4i%s" % (length, retjson))
65
65
 
66
66
                print "api returned", retjson
67
67
                self.data = 0
75
75
 
76
76
 
77
77
    
78
 
    def handle_api(self,data):
 
78
    def handle_api(self, data):
79
79
 
80
80
 
81
81
        request = json.loads(data)
84
84
 
85
85
        try:
86
86
            ret =  libs.globals.global_vars["apifunctions"][function](*args)
87
 
            if isinstance(ret,dict):
 
87
            if isinstance(ret, dict):
88
88
                return ret
89
89
            else:
90
90
                return {"returnvalue": ret} # if a function doesnt return a dict,