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


Python http.ok函数代码示例

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


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


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