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


Python RequestHelper.error方法代码示例

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


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

示例1: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def get(self, name, **kw):
     helper = RequestHelper(self)
     source = ArtifactSourceAccessor.get_by_name(name, return_none=True)
     if not source:
         helper.error(404)
         return
     helper.write_json(source_hash(source))
开发者ID:mhawthorne,项目名称:antonym,代码行数:9,代码来源:sources.py

示例2: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
    def get(self, **kw):
        helper = RequestHelper(self)
        q = self.request.get("q", None)
        output = self.request.get("o", None)
        max_results = int(self.request.get("max", -1))
        
        if not q:
            helper.error(400, "q not provided.")
            return

        q_results = ArtifactContent.all().search(q)

        json_results = None
        if output == "short":
            json_results = {}
            json_results["count"] = q_results.count()
        elif output == "id":
            json_results = {}
            count = q_results.count()
            if max_results > 0 and max_results < q_results.count():
                count = max_results
                
            json_results["count"] = count
            ids = []
            json_results["ids"] = ids
            results = q_results.fetch(1000) if max_results == -1 else q_results.fetch(max_results)
            for c in results:
                ids.append(c.guid)
        else:
            json_results = []
            if q_results.count():
                for content in q_results.fetch(10):
                    info = ArtifactInfo.get_by_guid(content.guid)
                    json_results.append(ArtifactsHelper.artifact_to_hash(info, content))
        helper.write_json(json_results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:37,代码来源:artifacts.py

示例3: delete

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
    def delete(self, **kw):
      helper = RequestHelper(self)
      q = self.request.get("q", None)
      if not q:
        helper.error(400, "q not provided.")
        return

      results = {}
      deleted_guids = []
      results["deleted"] = deleted_guids
      errors = 0
      q_results = ArtifactContent.all().search(q)
      
      infos = []
      batch_size = 50
      q_count = q_results.count()
      batches = (q_count / batch_size) + 1
      count = 0
      for i in range(0, batches):
        for c in q_results.fetch(batch_size, i * batch_size):
          try:
            logging.debug("deleting guid:%s" % c.guid)
            c.delete()
            count += 1
            deleted_guids.append(c.guid)
            if c.info is not None:
              c.info.delete()              
          except Exception, ex:
            logging.error(ex)
            errors += 1
开发者ID:mhawthorne,项目名称:antonym,代码行数:32,代码来源:artifacts.py

示例4: put

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
    def put(self, source_name):
        helper = RequestHelper(self)
        
        source_name = urllib.unquote(source_name)
        success, values = read_json_fields(helper, "url", "active", logger=logging)
        if not success:
            return
        url, active = values
        
        # a Feed must be sole owner of an ArtifactSource;
        # fails if source already exists and is already linked to a feed
        source = ArtifactSourceAccessor.get_by_name(source_name, return_none=True)
        if source:
            source_feed_key = Feed.get_by_source(source, keys_only=True, return_none=True)
            if source_feed_key:
                msg = "source '%s' is referenced by feed %s" % (source_name, source_feed_key.name())
                helper.error(409, msg)
        else:
            source = ArtifactSourceAccessor.create(source_name)
        
        # creates UrlResource if necessary
        resource = UrlResourceAccessor.get_by_url(url, return_none=True)
        if not resource:
            resource = UrlResourceAccessor.create(url)

        # create or update Feed
        feed = Feed.get_by_source_name(source_name, return_none=True)
        if feed:
            feed.artifact_source = source
            feed.url_resource = resource
            feed.put()
        else:
            Feed.create(source_name, artifact_source=source, url=url, url_resource=resource, active=bool(active))
        helper.set_status(204)
开发者ID:mhawthorne,项目名称:antonym,代码行数:36,代码来源:feeds.py

示例5: delete

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def delete(self, name, **kw):
     helper = RequestHelper(self)
     try:
         ArtifactSourceAccessor.delete_by_name(name)
         helper.set_status(204)
     except NotFoundException, ex:
         helper.error(404)
         return
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:sources.py

示例6: args_call

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def args_call(*args, **kw):
     handler = args[0]
     helper = RequestHelper(handler)
     if not Authenticator.is_authenticated(handler.request.path, handler.request.method, helper):
         helper.header(error_header, error_message)
         helper.error(403)
     else:
         f(*args, **kw)
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:biggie.py

示例7: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def get(self, source_name):
     helper = RequestHelper(self)
     source_name = urllib.unquote(source_name)
     f = Feed.get_by_source_name(source_name, return_none=True)
     if not f:
         helper.error(404)
         return
     helper.write_json(build_feed_hash(f))
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:feeds.py

示例8: args_call

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def args_call(*args, **kw):
     handler = args[0]
     helper = RequestHelper(handler)
     if not users.is_current_user_admin():
         helper.header(error_header, error_msg)
         helper.error(403)
     else:
         f(*args, **kw)
开发者ID:mhawthorne,项目名称:antonym,代码行数:10,代码来源:google_auth.py

示例9: delete

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def delete(self, source_name):
     helper = RequestHelper(self)
     source_name = urllib.unquote(source_name)
     feed = Feed.get_by_source_name(source_name, return_none=True)
     if not feed:
         helper.error(404)
         return
     feed.delete()
     helper.set_status(204)
开发者ID:mhawthorne,项目名称:antonym,代码行数:11,代码来源:feeds.py

示例10: post

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def post(self):
     helper = RequestHelper(self)
     
     if not len(self.request.body):
         helper.error(400, "body required")
         return
         
     decoded_body = urllib.unquote(self.request.body)
     t_api = TwitterConnector.new_api()
     status = t_api.PostUpdate(decoded_body)
     helper.write_json(status.asDict())
开发者ID:mhawthorne,项目名称:antonym,代码行数:13,代码来源:tweeter.py

示例11: put

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def put(self, key):
     helper = RequestHelper(self)
     if not self.request.body:
         helper.error(400, "body required")
         return
         
     value = self.request.body
     logging.info("%s=%s" % (key, value))
     try:
         ConfigurationAccessor.update(**{key: value})
     except IllegalArgumentException, e:
         helper.error(400, "invalid key")
         return
开发者ID:mhawthorne,项目名称:antonym,代码行数:15,代码来源:config.py

示例12: args_call

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def args_call(*args, **kw):
     handler = args[0]
     helper = RequestHelper(handler)
     auth_header = handler.request.headers.get(Headers.AUTHORIZATION, "")
     code, headers, user = DigestAuth(realm, users).authenticate(handler.request.method, 
         handler.request.path,
         auth_header)
     if code >= 400 and code < 499:
         for k, v in headers:
             helper.header(k, v)
         helper.error(code)
     else:
         kw['username'] = user
         return f(*args, **kw)
开发者ID:mhawthorne,项目名称:antonym,代码行数:16,代码来源:digest.py

示例13: ingest

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def ingest(cls, handler, source_name):
     helper = RequestHelper(handler)
     source_name = urllib.unquote(source_name)
     
     keep = handler.request.get("keep")
     if keep:
         keep = int(keep)
     else:
         keep = 50
     
     # TODO: get from cache
     f = Feed.get_by_source_name(source_name, return_none=True)
     if not f:
         helper.error(404)
         return
 
     results = {}
     entries = []
     results['created'] = entries
 
     # TODO: use etag from previous ingest
     error_call = lambda entry, ex: logging.error(Exceptions.format_last())
 
     user = users.get_current_user()
     if not user:
         # there is no logged in user for cron requests
         user = User(Services.API_USER)
         
     try:
         for artifact_guid, entry, created in model.ingest_feed_entries(f, user, error_call=error_call):
             entries.append({ "artifact-guid": artifact_guid,
                 "url": entry.link,
                 "title": entry.title,
                 "created": created })
     finally:
         # delete oldest feed entries
         # TODO: shouldn't I be deleting ArtifactContent instances also?
         def delete_info(c):
           try:
             i = c.info
             if i:
               i.delete()
           except Exception, e:
             pass
             
         deleted_key_names = ArtifactContent.delete_oldest_by_source(f.artifact_source, keep, pre_call=delete_info)
         
         results['deleted'] = deleted_key_names
         Counters.source_counter(f.artifact_source.name).decrement(len(deleted_key_names))
开发者ID:mhawthorne,项目名称:antonym,代码行数:51,代码来源:ingest.py

示例14: get

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def get(self, **kw):
     helper = RequestHelper(self)
     message = self.request.get("q", None)
     if not message:
         helper.error(400, "q must be provided")
         return
     message = urllib.unquote(message)
     try:
         sources, response = Mixer(new_speaker()).mix_response(message)
         logging.debug("sources:%s, response:%s" % (sources, response))
         result = dict(response=response)
         helper.write_json(result)
     except DataException, ex:
         helper.error(503, Exceptions.format(ex))
         logging.error(ex)
开发者ID:mhawthorne,项目名称:antonym,代码行数:17,代码来源:mixtures.py

示例15: put

# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import error [as 别名]
 def put(cls, rhandler, guid, **kw):
     helper = RequestHelper(rhandler)
     
     artifact = ArtifactInfo.get_by_guid(guid)
     if not artifact:
         helper.error(404)
         return
         
     # removes existing properties
     props = ArtifactInfo.properties().keys()
     for prop in props:
         delattr(artifact, prop)
     
     # save artifact
     ArtifactInfo.save(artifact)
开发者ID:mhawthorne,项目名称:antonym,代码行数:17,代码来源:artifacts.py


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