需求格式:GET /users/:user/repos
程序:
class Chain(object):
def __init__(self,path=''):
self._path=path
def __getattr__(self, path):
return Chain( '%s/%s' %(self._path,path))
def __str__(self):
return self._path
def __call__(self, user):
return Chain('%s/%s' %(self._path,user))
__repr__=__str__
实例:
1 print('GET',Chain().users('michael').repos) 2 print('GET',Chain().status.user.timeline.list)
结果:
1 GET /users/michael/repos 2 GET /status/user/timeline/list