• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python http.ok函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中restish.http.ok函数的典型用法代码示例。如果您正苦于以下问题:Python ok函数的具体用法?Python ok怎么用?Python ok使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: post

    def post(self, request):
	data = request.POST
	try:
		print "uname:" , data['uName']
		print "uPin:" , data['uPin']
		print "MSISDN:" , data['MSISDN']
		print "messageString:" , data['messageString']
		#print "Display:", data['Display']
		#print "udh:", data['udh']
		#print "mwi:", data['mwi']
		#print "coding:", data['coding']
		if str.isdigit(data['MSISDN']) == False:
			print "Bad MSISDN : " , data['MSISDN']
			callback(data['uName'], "STRATLOC")
			return http.ok([('Content-Type', 'text/html')], "<return>501</return>")
		print "----------------------------------------"
		#wait until modem becomes available
		print "Lock : " , gsmlock		
		if (gsmlock == True):
			print "waiting for modem to become available"
			while (gsmlock == True):
				pass
		modem_sendmsg(data['MSISDN'] , data['messageString'])
        	return http.ok([('Content-Type', 'text/html')], "<return>201</return>")
	except:
		return http.ok([('Content-Type', 'text/html')], "<return>506</return>")
开发者ID:abbyyacat,项目名称:StratLoc-GSM-Api,代码行数:26,代码来源:root.py


示例2: all

 def all(self, request):
     if request.method == "DELETE":
         return http.ok([('Content-Type', 'text/plain')],
                        "THERE IS NO DELETE")
     else:
         return http.ok([('Content-Type', 'text/plain')],
                        request.method)
开发者ID:greut,项目名称:restish,代码行数:7,代码来源:test_resource.py


示例3: render_response

def render_response(request, page, template, args={},
                    type='text/html', encoding='utf-8',
                    headers=[]):
    """
    Render a page, using the template and args, and return a '200 OK'
    response.  The response's Content-Type header will be constructed from
    the type and encoding.

    :arg request:
        Request instance.
    :arg page:
        Page being rendered (hint, it's often self).
    :arg template:
        Name of the template file.
    :arg args:
        Dictionary of args to pass to the template renderer.
    :arg type:
        Optional mime type of content, defaults to 'text/html'
    :arg encoding:
        Optional encoding of output, default to 'utf-8'.
    :arg headers:
        Optional extra HTTP headers for the output, default to []
    """
    # Copy the headers to avoid changing the arg default or the list passed by
    # the caller.
    headers = list(headers)
    headers.extend([('Content-Type', '%s; charset=%s' % (type, encoding))])
    return http.ok(headers,
                   render_page(request, page, template, args,
                               encoding=encoding))
开发者ID:aregee,项目名称:Mailman,代码行数:30,代码来源:templating.py


示例4: index

    def index(self, request, segments):
        def g():
            if isinstance(self.metadata, dict):
                for k,v in sorted(self.metadata.iteritems()):
                    if isinstance(v, dict):
                        yield '{0}/\n'.format(k)
                    elif isinstance(v, list):
                        yield '{0}/\n'.format(k)
                    else:
                        yield '{0}\n'.format(k)
            elif isinstance(self.metadata, list):
                for i, v in enumerate(self.metadata):
                    # it always needs some name (or cloud-init will
                    # write "0=" into ssh authorized_keys), so provide
                    # the index as a default
                    name = '{0}'.format(i)
                    if isinstance(v, Named):
                        name = v.name
                    yield '{0}={1}\n'.format(i, name)
            else:
                raise RuntimeError('Cannot index weird metadata: %r' % self.metadata)

        return http.ok(
            [('Content-Type', 'text/plain')],
            g(),
            )
开发者ID:tv42,项目名称:cheesy2,代码行数:26,代码来源:web.py


示例5: resource

 def resource(request):
     def gen():
         yield "Three ... "
         yield "two ... "
         yield "one ... "
         yield "BANG!"
     return http.ok([('Content-Type', 'text/plain')], gen())
开发者ID:ish,项目名称:restish,代码行数:7,代码来源:test_app.py


示例6: serve

 def serve(self, request):
     if isinstance(self.metadata, (dict, list)):
         return http.not_found()
     else:
         return http.ok(
             [('Content-Type', 'text/plain')],
             [self.metadata],
             )
开发者ID:tv42,项目名称:cheesy2,代码行数:8,代码来源:web.py


示例7: GET

 def GET(self, request):
     C = request.environ["couchish"]
     with C.session() as S:
         users = list(S.view("user/all", include_docs=True))
     users = [p.doc for p in users]
     users.sort(key=itemgetter("last_name"))
     out = dictwriter(users, CSVUSERKEYS)
     return http.ok([("Content-Type", "text/csv")], out)
开发者ID:timparkin,项目名称:examplesite,代码行数:8,代码来源:admin_additions.py


示例8: __call__

    def __call__(self, request):
        log.debug('formish.FileResource: in File Resource')
        if not self.segments:    
            return None

        # This is our input filepath
        requested_filepath = self._get_requested_filepath()
        log.debug('formish.FileResource: requested_filepath=%s',requested_filepath)
 
        # Get the raw cache file path and mtime
        raw_cached_filepath = self._get_cachefile_path(requested_filepath)
        log.debug('formish.FileResource: raw_cached_filepath=%s',raw_cached_filepath)
        raw_cached_mtime = self._get_file_mtime(raw_cached_filepath)

        # Check to see if fa and temp exist
        tempfile_path = self._get_tempfile_path(requested_filepath)
        log.debug('formish.FileResource: tempfile_path=%s',tempfile_path)

        # work out which has changed most recently (if either is newer than cache)
        fileaccessor_mtime = self._get_fileaccessor_mtime(requested_filepath)
        tempfile_mtime = self._get_file_mtime(tempfile_path)
        source_mtime = max(fileaccessor_mtime, tempfile_mtime)

        # unfound files return a 1970 timestamp for simplicity, if we don't have files newer than 1971, bugout
        if source_mtime < datetime(1971,1,1,0,0):
            return None

        if source_mtime > raw_cached_mtime:
            if fileaccessor_mtime > tempfile_mtime:
                log.debug('formish.FileResource: fileaccessor resource is newer. rebuild raw cache')
                filedata = self.fileaccessor.get_file(requested_filepath)
                mimetype = self.fileaccessor.get_mimetype(requested_filepath)
            else:
                log.debug('formish.FileResource: tempfile resource is newer. rebuilding raw cache')
                filedata = open(tempfile_path).read()
                mimetype = get_mimetype(tempfile_path)
            open(raw_cached_filepath,'w').write(filedata)
        else:
            log.debug('formish.FileResource: raw cache file is valid')
            mimetype = get_mimetype(raw_cached_filepath)

        # If we're trying to resize, check mtime on resized_cache
        size_suffix = self._get_size_suffix(request)
        if size_suffix:
            log.debug('formish.FileResource: size_suffix=%s',size_suffix)
            cached_filepath = self._get_cachefile_path(requested_filepath, size_suffix)
            cached_mtime = self._get_file_mtime(cached_filepath)
            log.debug('formish.FileResource: cached_filepath=%s',cached_filepath)

            if not os.path.exists(cached_filepath) or source_mtime > cached_mtime:
                width, height = get_size_from_dict(request.GET)
                log.debug('formish.FileResource: cache invalid. resizing image')
                resize_image(raw_cached_filepath, cached_filepath, width, height)
        else:
            log.debug('formish.FileResource: resized cache file is valid.')
            cached_filepath = raw_cached_filepath

        return http.ok([('content-type', mimetype )], open(cached_filepath, 'rb').read())
开发者ID:zvoase,项目名称:formish,代码行数:58,代码来源:fileresource.py


示例9: status

    def status(self, request):
        session = models.Session.get_by_key_name(self.name)
        if session is None:
            return http.not_found([], '')

        return http.ok(
            [('Content-Type', 'application/json')],
            json.dumps({'created_at': str(session.created_at)})
        )
开发者ID:daevaorn,项目名称:scraperasaservice.appspot.com,代码行数:9,代码来源:views.py


示例10: user_data

 def user_data(self, request, segments):
     if segments:
         return None
     data = request.environ['cheesy2.userdata'](request)
     if data is not None:
         return http.ok(
             [('Content-Type', 'text/plain')],
             [data],
             )
开发者ID:tv42,项目名称:cheesy2,代码行数:9,代码来源:web.py


示例11: details

 def details(self, request):
     try:
         request_id = int(self._request_id)
     except ValueError:
         return http.bad_request()
     resource = self._make_resource(request_id)
     if resource is None:
         return http.not_found()
     return http.ok([], etag(resource))
开发者ID:aregee,项目名称:Mailman,代码行数:9,代码来源:moderation.py


示例12: serve

 def serve(self, request):
     f = pkg_resources.resource_stream(
         'teuthology.html',
         'root.html',
         )
     return http.ok(
         [('Content-Type', 'text/html')],
         f,
         )
开发者ID:ceph,项目名称:ceph-autotests,代码行数:9,代码来源:web.py


示例13: html

 def html(self, request):
     C = request.environ['couchish']
     with C.session() as S:
         results = list(S.view('page/by_url',key='/',include_docs=True))
         news = S.docs_by_view('newsitem/homepage_news')
     news = [n for n in news if n.get('date') and n['date'] < date.today()]
     page = results[0].doc
     sitemap = navigation.get_navigation(request)
     data = {'page': page, 'request': request, 'sitemap': sitemap, 'news':news}
     out = templating.render(request, page['pagetype'], data, encoding='utf-8')
     return http.ok([('Content-Type', 'text/html')], out)
开发者ID:timparkin,项目名称:examplesite,代码行数:11,代码来源:root.py


示例14: json

 def json(self, req):
     filter_indexname = req.params.get('indexname', None)
     base_url = '/'.join(req.url.split('/')[:-2])
     indexes = []
     for x in self.pypi.get_indexes(self.distro.distro_id):
         if not filter_indexname:
             indexes.append(x)
             continue
         if filter_indexname == x:
             index = Index(self.pypi, self.distro, x)
             indexes.append(index.get_index_dict(base_url))
     return http.ok([], simplejson.dumps({'indexes': indexes}))
开发者ID:serverzen,项目名称:ClueReleaseManager,代码行数:12,代码来源:restmodel.py


示例15: scrape

    def scrape(self, request):
        session = models.Session.get_by_key_name(self.name)
        if session is None:
            return http.not_found([], '')

        data = json.loads(request.body)

        content, matched = session.scrape(data['url'], data['match'])

        return http.ok(
            [('Content-Type', 'application/json')],
            json.dumps({'content': content, 'matched': matched})
        )
开发者ID:daevaorn,项目名称:scraperasaservice.appspot.com,代码行数:13,代码来源:views.py


示例16: get_configuration

 def get_configuration(self, request):
     """Get a mailing list configuration."""
     resource = {}
     if self._attribute is None:
         # Return all readable attributes.
         for attribute in ATTRIBUTES:
             value = ATTRIBUTES[attribute].get(self._mlist, attribute)
             resource[attribute] = value
     elif self._attribute not in ATTRIBUTES:
         return http.bad_request([], b"Unknown attribute: {0}".format(self._attribute))
     else:
         attribute = self._attribute
         value = ATTRIBUTES[attribute].get(self._mlist, attribute)
         resource[attribute] = value
     return http.ok([], etag(resource))
开发者ID:mousadialo,项目名称:mailman,代码行数:15,代码来源:configuration.py


示例17: system

 def system(self, request, segments):
     """/<api>/system"""
     if len(segments) == 0:
         resource = dict(
             mailman_version=system.mailman_version,
             python_version=system.python_version,
             self_link=path_to('system'),
             )
     elif len(segments) > 1:
         return http.bad_request()
     elif segments[0] == 'preferences':
         return ReadOnlyPreferences(system_preferences, 'system'), []
     else:
         return http.bad_request()
     return http.ok([], etag(resource))
开发者ID:bksim,项目名称:mailman,代码行数:15,代码来源:root.py


示例18: find

 def find(self, request):
     """Find a member"""
     service = getUtility(ISubscriptionService)
     validator = Validator(
         list_id=unicode,
         subscriber=unicode,
         role=enum_validator(MemberRole),
         _optional=('list_id', 'subscriber', 'role'))
     members = service.find_members(**validator(request))
     # We can't just return the _FoundMembers instance, because
     # CollectionMixins have only a GET method, which is incompatible with
     # this POSTed resource.  IOW, without doing this here, restish would
     # throw a 405 Method Not Allowed.
     resource = _FoundMembers(members)._make_collection(request)
     return http.ok([], etag(resource))
开发者ID:bksim,项目名称:mailman,代码行数:15,代码来源:members.py


示例19: preferences

 def preferences(self, segments):
     resource = dict()
     for attr in PREFERENCES:
         # Handle this one specially.
         if attr == 'preferred_language':
             continue
         value = getattr(self._parent, attr, None)
         if value is not None:
             resource[attr] = value
     # Add the preferred language, if it's not missing.
     preferred_language = self._parent.preferred_language
     if preferred_language is not None:
         resource['preferred_language'] = preferred_language.code
     # Add the self link.
     resource['self_link'] = path_to(
         '{0}/preferences'.format(self._base_url))
     return http.ok([], etag(resource))
开发者ID:aregee,项目名称:Mailman,代码行数:17,代码来源:preferences.py


示例20: details

 def details(self, request):
     requests = IListRequests(self._mlist)
     try:
         request_id = int(self._request_id)
     except ValueError:
         return http.bad_request()
     results = requests.get_request(request_id, RequestType.held_message)
     if results is None:
         return http.not_found()
     key, data = results
     msg = getUtility(IMessageStore).get_message_by_id(key)
     resource = dict(
         key=key,
         data=data,
         msg=msg.as_string(),
         id=request_id,
         )
     return http.ok([], etag(resource))
开发者ID:bksim,项目名称:mailman,代码行数:18,代码来源:moderation.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python restkit.request函数代码示例发布时间:2022-05-26
下一篇:
Python http.not_found函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap