only add api methods to API instance
This commit is contained in:
parent
2abe99c89f
commit
575549ae33
1 changed files with 3 additions and 4 deletions
|
@ -7,6 +7,7 @@ import cookielib
|
||||||
import gzip
|
import gzip
|
||||||
import StringIO
|
import StringIO
|
||||||
import urllib2
|
import urllib2
|
||||||
|
from types import MethodType
|
||||||
|
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from .utils import json
|
from .utils import json
|
||||||
|
@ -15,9 +16,7 @@ from .form import MultiPartForm
|
||||||
__all__ = ['getAPI', 'API']
|
__all__ = ['getAPI', 'API']
|
||||||
|
|
||||||
def getAPI(url, cj=None):
|
def getAPI(url, cj=None):
|
||||||
class A(API):
|
return API(url, cj)
|
||||||
pass
|
|
||||||
return A(url, cj)
|
|
||||||
|
|
||||||
class API(object):
|
class API(object):
|
||||||
__version__ = __version__
|
__version__ = __version__
|
||||||
|
@ -46,7 +45,7 @@ class API(object):
|
||||||
def _add_method(self, method, name):
|
def _add_method(self, method, name):
|
||||||
if name is None:
|
if name is None:
|
||||||
name = method.func_name
|
name = method.func_name
|
||||||
setattr(self.__class__, name, method)
|
setattr(self, name, MethodType(method, self, type(self)))
|
||||||
|
|
||||||
def _add_action(self, action):
|
def _add_action(self, action):
|
||||||
def method(self, *args, **kw):
|
def method(self, *args, **kw):
|
||||||
|
|
Loading…
Reference in a new issue