当前位置: 首页>>代码示例>>Python>>正文


Python Response.success方法代码示例

本文整理汇总了Python中explorer.utils.misc.Response.success方法的典型用法代码示例。如果您正苦于以下问题:Python Response.success方法的具体用法?Python Response.success怎么用?Python Response.success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在explorer.utils.misc.Response的用法示例。


在下文中一共展示了Response.success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: request_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def request_handler(request):
    """ HTTP Request handler function to handle actions on collections """

    if not request.user.is_authenticated():
        return HttpResponse(Response.error(None, 'User must be logged in'))

    mode = request.GET.get('mode', '')
    reply_xml = None

    logger.info('request_handler: Received Request: (%s)' % mode)

    if mode == 'get-collection-list':
        reply_xml = Collection.list()

    elif mode == 'load-collection':
        metadata = request.GET.get('metadata', '')
        reply_xml = Collection.load(request.user.username, metadata)

        if reply_xml is None:
            return HttpResponse(Response.error(mode, 'Failed'))

        if isinstance(reply_xml, str):
            return HttpResponse(Response.success(mode, reply_xml))

    elif mode == 'add-collection':
        metadata = request.GET.get('metadata', '')
        payload = request.GET.get('payload', '')
        logger.debug('metadata: ' + metadata)
        logger.debug('payload: ' + payload)
        if not Collection.add(metadata, payload):
            return HttpResponse(Response.error(mode, 'Failed'))

        reply_xml = Collection.list()
        mode = 'get-collection-list'

    elif mode == 'delete-collection':
        metadata = request.GET.get('metadata', '')
        if not Collection.remove(metadata):
            return HttpResponse(Response.error(mode, 'Failed'))

        reply_xml = Collection.list()
        mode = 'get-collection-list'

    elif mode == 'rpc':
        req = request.GET.get('payload', '')
        reply_xml = Adapter.gen_rpc(request.user.username, req)
        if isinstance(reply_xml, str):
            return HttpResponse(Response.success(mode, reply_xml))
    elif mode == 'gen-script':
        req = request.GET.get('payload', '')
        reply_xml = Adapter.gen_script(request.user.username, req)
        if isinstance(reply_xml, str):
            return HttpResponse(Response.success(mode, reply_xml))

    elif mode in ['get-cap', 'run-rpc', 'run-edit-commit', 'run-commit']:
        payload = request.GET.get('payload', '')
        logger.debug('run: ' + payload)
        reply_xml = Adapter.run_request(request.user.username, payload)

    return HttpResponse(Response.success(mode, 'ok', reply_xml))
开发者ID:sachinsr099,项目名称:yang-explorer,代码行数:62,代码来源:views.py

示例2: upload_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def upload_handler(request):
    """ HTTP Request handler function to upload yang models """

    mode = request.GET.get('mode', '')
    logging.debug(request.method + ':Received upload request .. ' + mode)

    if not request.user.is_authenticated():
        logging.warning('User must be logged in !!')
        return HttpResponse(Response.error(mode, 'Unauthorized'))

    if not ServerSettings.user_aware():
        if not request.user.has_perm('explorer.delete_yangmodel') or \
                not request.user.has_perm('explorer.change_yangmodel'):
            logging.warning('Unauthorized upload request .. ')
            return HttpResponse(Response.error(mode, 'User does not have permission to upload !!'))

    if request.method == 'POST':
        # create a temporary storage for this session
        directory = ServerSettings.session_path(request.session.session_key)
        _file = Uploader.upload_file(request.FILES['Filedata'], directory)
        if _file is not None:
            module = ET.Element('module')
            module.text = _file
            rval = Response.success('upload', 'ok', xml=module)
            logging.debug(rval)
            return HttpResponse(rval)
        return HttpResponse(Response.error('upload', 'Failed to upload'))
    elif request.method == 'GET':
        if mode == 'sync':
            filename = request.GET.get('file', '')
            index = request.GET.get('index', '')
            logging.info('Received sync request for ' + filename + ', index ' + index)
            success, response = Uploader.sync_file(request.user.username,
                                                   request.session.session_key,
                                                   filename, index)
            if success:
                return HttpResponse(Response.success(mode, 'ok'))
            return HttpResponse(Response.error(mode, 'compilation failed', xml=response))

        elif mode == 'commit':
            success, modules = Uploader.commit_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success('commit', 'ok', modules))

        elif mode == 'init':
            success, modules = Uploader.get_upload_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success(mode, 'ok', modules))

        elif mode == 'clear':
            success, modules = Uploader.clear_upload_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success(mode, 'ok', modules))
        return HttpResponse(Response.error(mode, 'failed'))

    return render_to_response('upload.html')
开发者ID:center3d,项目名称:yang-explorer,代码行数:58,代码来源:views.py

示例3: upload_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def upload_handler(request):
    """ HTTP Request handler function to upload yang models """
    if not request.user.is_authenticated():
        logging.debug('Unauthorized upload request .. ')
        return HttpResponse(Response.error('upload', 'Unauthorized'))

    mode = request.GET.get('mode', '')
    logging.debug(request.method + ':Received upload request .. ' + mode)
   
    if request.method == 'POST':
        # create a temporary storage for this session
        directory = os.path.join('data', 'session', request.session.session_key)
        _file = upload_file(request.FILES['Filedata'], directory)
        if _file is not None:
            module = ET.Element('module')
            module.text = _file
            rval = Response.success('upload', 'ok', xml=module)
            logging.debug(rval)
            return HttpResponse(rval)
        return HttpResponse(Response.error('upload', 'Failed to upload'))
    elif request.method == 'GET':
        if mode == 'sync':
            filename = request.GET.get('file', '')
            index = request.GET.get('index', '')
            logging.debug('Received sync request for ' + filename + ', index ' + index)
            success, response = sync_file(request.user.username, request.session.session_key,
                                          filename, index)
            if success:
                return HttpResponse(Response.success(mode, 'ok'))
            return HttpResponse(Response.error(mode, 'compilation failed', xml=response))
        
        elif mode == 'commit':
            success, modules = commit_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success('commit', 'ok', modules))
        
        elif mode == 'init':
            success, modules = get_upload_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success(mode, 'ok', modules))

        elif mode == 'clear':
            success, modules = clear_upload_files(request.user.username, request.session.session_key)
            if success:
                return HttpResponse(Response.success(mode, 'ok', modules))
        return HttpResponse(Response.error(mode, 'failed'))       

    return render_to_response('upload.html')
开发者ID:janlindblad,项目名称:yang-explorer,代码行数:50,代码来源:views.py

示例4: add_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def add_schema(request, req):
    """
    This API download yang schema from device
    """
    logger.debug("Add Schemas")
    modules = download_yang(request, req)
    return HttpResponse(Response.success("add", "ok", xml=modules))
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:9,代码来源:schema.py

示例5: download_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def download_schema(request, req):
    """
    This API download yang schema from device and bundle it
    """
    logger.debug("Download Schemas")

    modules = download_yang(request, req)

    session_dir = ServerSettings.schema_path(request.session.session_key)
    http_host = request.META["HTTP_HOST"]
    current = str(datetime.now())
    current = current.replace(" ", "-")
    current = current[: current.rindex(".")]
    zfname = "schema-" + current + ".zip"
    zfile = session_dir + "/" + zfname

    homedir = os.getcwd()
    os.chdir(session_dir)
    with ZipFile(zfile, "w") as lz:
        for f in glob.glob("*.yang"):
            lz.write(f)
            os.remove(f)
    if not lz.namelist():
        os.remove(zfile)
    os.chdir(homedir)

    url = "\nhttp://" + http_host + "/" + "download/session/"
    url += request.session.session_key + "/" + zfname
    return HttpResponse(Response.success("download", msg=url))
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:31,代码来源:schema.py

示例6: login_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def login_handler(request):
    """ HTTP Request handler function for user login / logout requests """
    if request.POST:
        action = request.POST['action']
        if action == 'login':
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                # Correct password, and the user is marked "active"
                login(request, user)
            else:
                return HttpResponse(Response.error('login', 'Authentication Failed'))
        else:
            username = ''
            try:
                if request.session.session_key is not None and request.session.session_key != '':
                    session_dir = ServerSettings.session_path(request.session.session_key)
                    if os.path.exists(session_dir):
                        logger.debug('Cleaning ' + session_dir)
                        shutil.rmtree(session_dir)
                logout(request)
            except:
                logger.exception("Failed")
            else:
                logger.debug('Logout success!!')
        session = get_session_config(username)
        return HttpResponse(Response.success(action, 'ok', session))
    return HttpResponse(Response.error('unknown', 'Invalid request!!'))
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:31,代码来源:views.py

示例7: download_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def download_schema(request, req):
    '''
    This API download yang schema from device and bundle it
    '''
    logging.debug('Download Schemas')

    modules = download_yang(request, req)    

    session_dir = ServerSettings.schema_path(request.session.session_key)
    http_host = request.META['HTTP_HOST']
    current = str(datetime.now())
    current = current.replace(' ', '-')
    current = current[:current.rindex('.')]
    zfname = 'schema-' + current + '.zip'
    zfile = session_dir + '/' + zfname

    homedir = os.getcwd()
    os.chdir(session_dir)
    with ZipFile(zfile, "w") as lz:
        for f in glob.glob("*.yang"):
            lz.write(f)
            os.remove(f)
    if not lz.namelist():
        os.remove(zfile)
    os.chdir(homedir)

    url = '\nhttp://' + http_host + '/' + 'download/session/' + request.session.session_key + '/' + zfname
    return HttpResponse(Response.success('download', msg=url))
开发者ID:center3d,项目名称:yang-explorer,代码行数:30,代码来源:schema.py

示例8: login_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def login_handler(request):
    """ HTTP Request handler function for user login / logout requests """
    session = ET.Element('session')
    if request.POST:
        action = request.POST['action']
        if action == 'login':
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                # Correct password, and the user is marked "active"
                login(request, user)
                session.text = username
            else:
                return HttpResponse(Response.error('login', 'Authentication Failed'))
        else:
            try:
                if request.session.session_key is not None and request.session.session_key != '':
                    session_dir = ServerSettings.session_path(request.session.session_key)
                    if os.path.exists(session_dir):
                        logging.debug('Cleaning ' + session_dir)
                        shutil.rmtree(session_dir)
                logout(request)
            except Exception as ex:
                print(ex.__doc__)
                print(ex.message)
        logging.debug('Login success')
        return HttpResponse(Response.success(action, 'ok', session))
    return HttpResponse(Response.error(action, 'Invalid Request'))
开发者ID:MFALHI,项目名称:yang-explorer,代码行数:31,代码来源:views.py

示例9: add_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def add_schema(request, req):
    '''
    This API download yang schema from device 
    '''
    logging.debug('Add Schemas')
    modules = download_yang(request, req)
    return HttpResponse(Response.success('add', 'ok', xml=modules))
开发者ID:center3d,项目名称:yang-explorer,代码行数:9,代码来源:schema.py

示例10: session_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def session_handler(request):
    """ HTTP Request handler function to check if user session exists """

    if request.user.is_authenticated():
        session = get_session_config(request.user.username)
    else:
        session = get_session_config('')
    return HttpResponse(Response.success('session', 'ok', session))
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:10,代码来源:views.py

示例11: admin_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def admin_handler(request):
    """ HTTP Request handler function to handle actions on yang modules """

    if not request.user.is_authenticated():
        return HttpResponse(Response.error(None, 'User must be logged in'))

    if request.method != 'GET':
        return HttpResponse(Response.error(None, 'Invalid admin Request'))

    action = request.GET.get('action', '')
    logging.debug('Received admin request %s for user %s' % (action, request.user.username))

    if action in ['subscribe', 'unsubscribe', 'delete', 'graph']:
        payload = request.GET.get('payload', None)
        print(str(payload))
        (rc, msg) = ModuleAdmin.admin_action(request.user.username, payload, action)
        if not rc:
            return HttpResponse(Response.error(action, msg))

    if action == 'graph':
        return HttpResponse(Response.success(action, msg))

    modules = ModuleAdmin.get_modules(request.user.username)
    return HttpResponse(Response.success(action, 'ok', xml=modules))
开发者ID:MFALHI,项目名称:yang-explorer,代码行数:26,代码来源:views.py

示例12: profile_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def profile_handler(request):
    """ HTTP request handler for profile request """

    profiles = ET.Element('profiles')
    if request.user.is_authenticated():
        uid = request.user.id
        logging.debug("User Authenticated (%s)" % request.user.username)
        entries = DeviceProfile.objects.filter(Q(user=uid) | Q(shared=True))
        for e in entries:
            profile = _build_device_profile(e)
            profiles.append(profile)

        entries = Collection.objects.all()
        for e in entries:
            profile = _build_collection_profile(e)
            profiles.append(profile)
    return HttpResponse(Response.success('profile', 'ok', xml=profiles))
开发者ID:MFALHI,项目名称:yang-explorer,代码行数:19,代码来源:profile_view.py

示例13: get_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def get_schema(request, req, all=True):
    """
    This API get yang schema from device
    """
    logger.debug("Get Yang Schema")

    req = req.replace("<metadata>", "")
    req = req.replace("</metadata>", "")

    protocol, device, fmt, _, payload = Adapter.parse_request(req)
    if device.get("host", None) is None:
        return HttpResponse(Response.error("get", "no host info"))

    rpc_xml = ET.fromstring(get_schema_list_rpc)
    xml = Adapter.run_netconf(request.user.username, device, rpc_xml)
    if xml is None:
        return HttpResponse(Response.error("get", "failed to get schema"))

    if xml.text is not None:
        if xml.text.find("error"):
            return HttpResponse(Response.error("get", xml.text))

    sclist = xml[0][0][0][0]
    schemas = ET.Element("schemas")
    for sc in sclist:
        schema = ET.Element("schema")
        id = sc[0].text
        ver = sc[1].text
        if all == False:
            if id.isupper() or "-MIB" in id or "SNMP" in id:
                continue
        schema.set("name", id)
        if ver is None:
            schema.set("version", "")
        else:
            schema.set("version", ver)
        unmatched = validate_schema(request.user.username, id, ver)
        if unmatched is not None:
            schema.set("unmatched", unmatched)

        schemas.append(schema)

    return HttpResponse(Response.success("get", "ok", xml=schemas))
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:45,代码来源:schema.py

示例14: get_schema

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def get_schema(request, req, all=False):
    '''
    This API get yang schema from device
    '''
    logging.debug('Get Yang Schema')

    req = req.replace('<metadata>', '')
    req = req.replace('</metadata>', '')

    protocol, device, fmt, payload = Adapter.parse_request(req)
    if device.get('host', None) is None:
        return HttpResponse(Response.error('get', 'no host info'))

    rpc_xml= ET.fromstring(get_schema_rpc)
    xml = Adapter.run_netconf(request.user.username, device, rpc_xml) 
    if xml is None:
        return HttpResponse(Response.error('get', 'failed to get schema'))
 
    if xml.text is not None:
        if xml.text.find('error'):
            return HttpResponse(Response.error('get', xml.text))

    sclist = xml[0][0][0][0]
    schemas = ET.Element('schemas')
    for sc in sclist:
        schema = ET.Element('schema')
        id  = sc[0].text
        ver = sc[1].text
        if all == False:
            if id.isupper() or '-MIB' in id or 'SNMP' in id:
                continue
        schema.set('name', id)
        if ver is None:
            schema.set('version', '')
        else:
            schema.set('version', ver)
        unmatched = validate_schema(request.user.username, id, ver)
        if unmatched is not None:
            schema.set('unmatched', unmatched)

        schemas.append(schema) 

    return HttpResponse(Response.success('get', 'ok', xml=schemas))
开发者ID:center3d,项目名称:yang-explorer,代码行数:45,代码来源:schema.py

示例15: search_handler

# 需要导入模块: from explorer.utils.misc import Response [as 别名]
# 或者: from explorer.utils.misc.Response import success [as 别名]
def search_handler(request):
    """
    Args:
        request: Django HTTP request header

    Returns: HTTP response with search results
    """
    if not request.user.is_authenticated():
        return HttpResponse(Response.error(None, 'User must be logged in'))

    query = request.GET.get('query', '')
    mode = request.GET.get('mode', '')
    if not query:
        rc, result = False, 'Invalid or empty query'
    else:
        rc, result = Search.search(request.user.username, query)

    if not rc:
        return HttpResponse(Response.error(mode, result))

    return HttpResponse(Response.success(mode, 'ok', xml=result))
开发者ID:danhut,项目名称:yang-explorer,代码行数:23,代码来源:views.py


注:本文中的explorer.utils.misc.Response.success方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。