Example #1
0
    def generate_service_html(self,
                              service,
                              client_path,
                              charset,
                              languages,
                              skin=None):
        def get_ladontype(typ):
            if type(typ) == list:
                if typ[0] in service.typemanager.type_dict:
                    return typ[0].__name__
                else:
                    return False
            else:
                if typ in service.typemanager.type_dict:
                    return typ.__name__
                else:
                    return False

        def type_to_string(typ):
            paramtype = typ
            if type(paramtype) == list:
                paramtype = paramtype[0]
                if paramtype in service.typemanager.type_dict:
                    paramtype_str = '[ %s ]' % paramtype.__name__
                else:
                    paramtype_str = '[ %s ]' % type_to_jsontype[paramtype]
            else:
                if paramtype in service.typemanager.type_dict:
                    paramtype_str = paramtype.__name__
                elif paramtype in type_to_jsontype:
                    paramtype_str = type_to_jsontype[paramtype]
                else:
                    paramtype_str = paramtype.__name__
            return paramtype_str

        fix_path = urlparse(client_path)
        css_path = 'service.css'
        template_path = 'service.template'
        self.update_static('skins/service-extra.css')
        if skin:
            css_path = 'skins/%s/service.css' % skin
            template_path = 'skins/%s/service.template' % skin
            if not self.update_static(template_path):
                css_path = 'service.css'
                template_path = 'service.template'
                self.update_static(template_path)
                self.update_static(css_path)
            self.update_static(css_path)
        else:
            self.update_static(template_path)
            self.update_static(css_path)

        service_info = {
            'servicename': service.servicename,
            'doc_lines': service.doc_lines,
            'doc': publish_doc(service.doc_lines),
            'interfaces': _interfaces.keys(),
            'methods': [],
            'types': [],
            'css': self.staticfiles.get(css_path, {}).get('data', None),
            'extra_css': self.staticfiles['skins/service-extra.css']['data'],
            'client_path': client_path,
            'query_string': fix_path.query,
            'charset': charset,
            'languages': languages,
            'skins': list(self.skins.keys()),
            'current_skin': skin
        }
        for method in service.method_list():
            method_info = {
                'methodname': method.name(),
                'params': [],
                'doc': publish_doc(method._method_doc),
                'returns': {
                    'type': type_to_string(method._rtype),
                    'ladontype': get_ladontype(method._rtype),
                    'doc': publish_doc(method._rtype_doc),
                    'doc_lines': method._rtype_doc
                }
            }
            for param in method.args():
                param_info = {
                    'name': param['name'],
                    'type': type_to_string(param['type']),
                    'ladontype': get_ladontype(param['type']),
                    'optional': param['optional'],
                    'doc': publish_doc(param['doc']),
                    'doc_lines': param['doc']
                }
                if 'default' in param:
                    default_type = param['default']
                    if param['type'] in PORTABLE_STRING_TYPES:
                        param_info['default'] = '"%s"' % param['default']
                    else:
                        param_info['default'] = str(param['default'])
                method_info['params'] += [param_info]
            service_info['methods'] += [method_info]

        types = service_info['types']
        type_order = service.typemanager.type_order
        for typ in type_order:
            if type(typ) == dict:
                desc_type = {}
                desc_type['name'] = typ['name']
                desc_type['attributes'] = {}
                for k, v, props in typ['attributes']:
                    desc_type_val = type_to_string(v)
                    desc_type['attributes'][k] = {
                        'type': desc_type_val,
                        'props': props,
                        'ladontype': get_ladontype(v)
                    }
                types += [desc_type]

        template = Template(self.staticfiles[template_path]['data'])
        return template.render(service_info).encode(charset)
Example #2
0
	def generate_service_html(self,service,client_path,charset,skin=None):
		def get_ladontype(typ):
			if type(typ)==list:
				if typ[0] in service.typemanager.type_dict:
					return typ[0].__name__
				else:
					return False
			else:
				if typ in service.typemanager.type_dict:
					return typ.__name__
				else:
					return False
			
		def type_to_string(typ):
			paramtype = typ
			if type(paramtype)==list:
				paramtype = paramtype[0]
				if paramtype in service.typemanager.type_dict:
					paramtype_str = '[ %s ]' % paramtype.__name__
				else:
					paramtype_str = '[ %s ]' % type_to_jsontype[paramtype]
			else:
				if paramtype in service.typemanager.type_dict:
					paramtype_str = paramtype.__name__
				elif paramtype in type_to_jsontype:
					paramtype_str = type_to_jsontype[paramtype]
				else:
					paramtype_str = paramtype.__name__
			return paramtype_str

		css_path = 'service.css'
		template_path = 'service.template'
		fix_path = urlparse(client_path)
		if skin:
			css_path = 'skins/%s/service.css' % skin
			template_path = 'skins/%s/service.template' % skin
			if not self.update_static(template_path) or not self.update_static(css_path):
				css_path = 'service.css'
				template_path = 'service.template'
				self.update_static(template_path)
				self.update_static(css_path)
		else:
			self.update_static(template_path)
			self.update_static(css_path)

		service_info = {
			'servicename': service.servicename,
			'doc_lines': service.doc_lines,
			'interfaces': _interfaces.keys(),
			'methods': [],
			'types': [],
			'css': self.staticfiles[css_path]['data'],
			'client_path': client_path,
			'query_string': fix_path.query,
			'charset': charset,
			'skins': list(self.skins.keys()),
			'current_skin': skin
		}
		for method in service.method_list():
			method_info = {
				'methodname': method.name(),
				'params': [],
				'doc_lines': method._method_doc,
				'returns': {
					'type': type_to_string(method._rtype),
					'ladontype': get_ladontype(method._rtype),
					'doc_lines': method._rtype_doc } }
			for param in method.args():
				param_info = {
					'name': param['name'],
					'type': type_to_string(param['type']),
					'ladontype': get_ladontype(param['type']),
					'optional': param['optional'],
					'doc_lines': param['doc'] }
				if 'default' in param:
					default_type = param['default']
					if param['type'] in PORTABLE_STRING_TYPES:
						param_info['default'] = '"%s"' % param['default']
					else:
						param_info['default'] = str(param['default'])
				method_info['params'] += [ param_info ]
			service_info['methods'] += [method_info]

		types = service_info['types']
		type_order = service.typemanager.type_order
		for typ in type_order:
			if type(typ)==dict:
				desc_type = {}
				desc_type['name'] = typ['name']
				desc_type['attributes'] = {}
				for k,v,props in typ['attributes']:
					desc_type_val = type_to_string(v)
					desc_type['attributes'][k] = {
						'type': desc_type_val,
						'props': props,
						'ladontype': get_ladontype(v) }
				types += [desc_type]

		template = Template(self.staticfiles[template_path]['data'])
		return template.render(service_info).encode(charset)
Example #3
0
def generate_service(service):
    '''
    service实例结构
    '''
    from ladon.interfaces import _interfaces
    from ladon.compat import type_to_jsontype, PORTABLE_STRING_TYPES

    def get_ladontype(typ):
        if type(typ) == list:
            if typ[0] in service.typemanager.type_dict:
                return typ[0].__name__
            else:
                return False
        else:
            if typ in service.typemanager.type_dict:
                return typ.__name__
            else:
                return False

    def type_to_string(typ):
        paramtype = typ
        if type(paramtype) == list:
            paramtype = paramtype[0]
            if paramtype in service.typemanager.type_dict:
                paramtype_str = '[ %s ]' % paramtype.__name__
            else:
                paramtype_str = '[ %s ]' % type_to_jsontype[paramtype]
        else:
            if paramtype in service.typemanager.type_dict:
                paramtype_str = paramtype.__name__
            elif paramtype in type_to_jsontype:
                paramtype_str = type_to_jsontype[paramtype]
            else:
                paramtype_str = paramtype.__name__
        return paramtype_str

    service_info = {
        'servicename': service.servicename,
        'doc_lines': service.doc_lines,
        'interfaces': _interfaces.keys(),
        'methods': [],
        'types': [],
        'charset': 'utf-8',
    }
    '''获取所有可用接口方法的信息'''
    for method in service.method_list():
        method_info = {
            'methodname': method.name(),
            'params': [],
            'doc_lines': method._method_doc,
            'returns': {
                'type': type_to_string(method._rtype),
                'ladontype': get_ladontype(method._rtype),
                'doc_lines': method._rtype_doc
            }
        }
        for param in method.args():
            param_info = {
                'name': param['name'],
                'type': type_to_string(param['type']),
                'ladontype': get_ladontype(param['type']),
                'optional': param['optional'],
                'doc_lines': param['doc']
            }
            if 'default' in param:
                default_type = param['default']
                if param['type'] in PORTABLE_STRING_TYPES:
                    param_info['default'] = '"%s"' % param['default']
                else:
                    param_info['default'] = str(param['default'])
            method_info['params'] += [param_info]
        service_info['methods'] += [method_info]
    ''''获取所有可用类型的信息￐ᅪ샤￐ᅤᅬᄁ '''
    types = service_info['types']
    type_order = service.typemanager.type_order
    for typ in type_order:
        if type(typ) == dict:
            desc_type = {}
            desc_type['name'] = typ['name']
            desc_type['attributes'] = {}
            for k, v, props in typ['attributes']:
                desc_type_val = type_to_string(v)
                desc_type['attributes'][k] = {
                    'type': desc_type_val,
                    'props': props,
                    'ladontype': get_ladontype(v)
                }
            types += [desc_type]
    return service_info
Example #4
0
def generate_service(service):
    '''
    service实例结构
    '''
    from ladon.interfaces import _interfaces
    from ladon.compat import type_to_jsontype,PORTABLE_STRING_TYPES
    def get_ladontype(typ):
        if type(typ)==list:
            if typ[0] in service.typemanager.type_dict:
                return typ[0].__name__
            else:
                return False
        else:
            if typ in service.typemanager.type_dict:
                return typ.__name__
            else:
                return False
        
    def type_to_string(typ):
        paramtype = typ
        if type(paramtype)==list:
            paramtype = paramtype[0]
            if paramtype in service.typemanager.type_dict:
                paramtype_str = '[ %s ]' % paramtype.__name__
            else:
                paramtype_str = '[ %s ]' % type_to_jsontype[paramtype]
        else:
            if paramtype in service.typemanager.type_dict:
                paramtype_str = paramtype.__name__
            elif paramtype in type_to_jsontype:
                paramtype_str = type_to_jsontype[paramtype]
            else:
                paramtype_str = paramtype.__name__
        return paramtype_str
    
    service_info = {
        'servicename': service.servicename,
        'doc_lines': service.doc_lines,
        'interfaces': _interfaces.keys(),
        'methods': [],
        'types': [],
        'charset': 'utf-8',
    }
    '''获取所有可用接口方法的信息'''
    for method in service.method_list():
        method_info = {
            'methodname': method.name(),
            'params': [],
            'doc_lines': method._method_doc,
            'returns': {
                'type': type_to_string(method._rtype),
                'ladontype': get_ladontype(method._rtype),
                'doc_lines': method._rtype_doc } }
        for param in method.args():
            param_info = {
                'name': param['name'],
                'type': type_to_string(param['type']),
                'ladontype': get_ladontype(param['type']),
                'optional': param['optional'],
                'doc_lines': param['doc'] }
            if 'default' in param:
                default_type = param['default']
                if param['type'] in PORTABLE_STRING_TYPES:
                    param_info['default'] = '"%s"' % param['default']
                else:
                    param_info['default'] = str(param['default'])
            method_info['params'] += [ param_info ]
        service_info['methods'] += [method_info]
    ''''获取所有可用类型的信息￐ᅪ샤￐ᅤᅬᄁ '''
    types = service_info['types']
    type_order = service.typemanager.type_order
    for typ in type_order:
        if type(typ)==dict:
            desc_type = {}
            desc_type['name'] = typ['name']
            desc_type['attributes'] = {}
            for k,v,props in typ['attributes']:
                desc_type_val = type_to_string(v)
                desc_type['attributes'][k] = {
                    'type': desc_type_val,
                    'props': props,
                    'ladontype': get_ladontype(v) }
            types += [desc_type]
    return service_info
	def generate_service_html(self,service,client_path,charset,skin=None):
		'''
		service实例视图
		'''
		def get_ladontype(typ):
			if type(typ)==list:
				if typ[0] in service.typemanager.type_dict:
					return typ[0].__name__
				else:
					return False
			else:
				if typ in service.typemanager.type_dict:
					return typ.__name__
				else:
					return False
			
		def type_to_string(typ):
			paramtype = typ
			if type(paramtype)==list:
				paramtype = paramtype[0]
				if paramtype in service.typemanager.type_dict:
					paramtype_str = '[ %s ]' % paramtype.__name__
				else:
					paramtype_str = '[ %s ]' % type_to_jsontype[paramtype]
			else:
				if paramtype in service.typemanager.type_dict:
					paramtype_str = paramtype.__name__
				elif paramtype in type_to_jsontype:
					paramtype_str = type_to_jsontype[paramtype]
				else:
					paramtype_str = paramtype.__name__
			return paramtype_str

		service_info = {
			'servicename': service.servicename,
			'doc_lines': service.doc_lines,
			'interfaces': _interfaces.keys(),
			'methods': [],
			'types': [],
			'charset': charset,
		}
		'''获取所有可用接口方法的信息'''
		for method in service.method_list():
			method_info = {
				'methodname': method.name(),
				'params': [],
				'doc_lines': method._method_doc,
				'returns': {
					'type': type_to_string(method._rtype),
					'ladontype': get_ladontype(method._rtype),
					'doc_lines': method._rtype_doc } }
			for param in method.args():
				param_info = {
					'name': param['name'],
					'type': type_to_string(param['type']),
					'ladontype': get_ladontype(param['type']),
					'optional': param['optional'],
					'doc_lines': param['doc'] }
				if 'default' in param:
					default_type = param['default']
					if param['type'] in PORTABLE_STRING_TYPES:
						param_info['default'] = '"%s"' % param['default']
					else:
						param_info['default'] = str(param['default'])
				method_info['params'] += [ param_info ]
			service_info['methods'] += [method_info]
		''''获取所有可用类型的信息 '''
		types = service_info['types']
		type_order = service.typemanager.type_order
		for typ in type_order:
			if type(typ)==dict:
				desc_type = {}
				desc_type['name'] = typ['name']
				desc_type['attributes'] = {}
				for k,v,props in typ['attributes']:
					desc_type_val = type_to_string(v)
					desc_type['attributes'][k] = {
						'type': desc_type_val,
						'props': props,
						'ladontype': get_ladontype(v) }
				types += [desc_type]

		template = 'service_index.html'
		return template.render(service_info).encode(charset)