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


Python requests.RequestHelper类代码示例

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


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

示例1: post

    def post(self, **kw):
        helper = RequestHelper(self)
        results = {}
        source_q = ArtifactSource.all()
        for s in source_q:
            artifact_q = ArtifactInfo.find_by_source(s)
            count = len([a for a in artifact_q])
            counter = Counters.source_counter(s.name)
            old_count = counter.count()
            counter.set(count)
            
            source_result = { 'old': old_count }
            
            # if source is linked to a feed, I can't delete it
            feed = Feed.get_by_source(s, return_none=True)
            if feed:
                source_result['feed'] = feed.url

            if not count and not feed:
                s.delete()
                source_result['deleted'] = True
            
            if count:
                source_result['new'] = count
                
            results[s.name] = source_result
        helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:27,代码来源:sources.py

示例2: delete

    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,代码行数:30,代码来源:artifacts.py

示例3: get

    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,代码行数:35,代码来源:artifacts.py

示例4: put

    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,代码行数:34,代码来源:feeds.py

示例5: get

 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,代码行数:7,代码来源:sources.py

示例6: get

    def get(self, **kw):
        helper = RequestHelper(self)

        # read actions from queue; return as json
        q = get_activity_queue()
        items = q.items()

        helper.write_json(items)
开发者ID:mhawthorne,项目名称:antonym,代码行数:8,代码来源:activity.py

示例7: delete

 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,代码行数:8,代码来源:sources.py

示例8: get

 def get(self):
     helper = RequestHelper(self)
     results = []
     for s in db.stats.KindStat.all():
         results.append({'kind': s.kind_name,
             'count': s.count,
             'bytes': s.bytes})
     helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:8,代码来源:da.py

示例9: put

 def put(self, name, **kw):
     helper = RequestHelper(self)
     source = ArtifactSourceAccessor.get_by_name(name, return_none=True)
     if source:
         helper.set_status(409, "duplicate ArtifactSouce")
         return
     ArtifactSourceAccessor.create(name)
     helper.set_status(204)
开发者ID:mhawthorne,项目名称:antonym,代码行数:8,代码来源:sources.py

示例10: get

 def get(self, page):
     page = int(page) if page else 0
     
     helper = RequestHelper(self)
     results = []
     for u in UrlResource.all().fetch(self.BATCH_SIZE, page * self.BATCH_SIZE):
         results.append(resource_hash(u))
     helper.write_json(results)
开发者ID:mhawthorne,项目名称:antonym,代码行数:8,代码来源:resources.py

示例11: args_call

 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,代码行数:8,代码来源:google_auth.py

示例12: get

 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,代码行数:8,代码来源:feeds.py

示例13: args_call

 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,代码行数:8,代码来源:biggie.py

示例14: get

 def get(self, path):
     helper = RequestHelper(self)
     t_api = TwitterConnector.new_api()
     try:
         result_hash = t_api.FetchResource("%s" % path)
         logging.debug("result_hash: %s" % result_hash)
         helper.write_json(result_hash)
     except twitter.TwitterError, e:
         helper.write(e)
开发者ID:mhawthorne,项目名称:antonym,代码行数:9,代码来源:tweeter.py

示例15: delete

 def delete(self):
     helper = RequestHelper(self)
     search_results = self.__search(helper)
     if search_results:
         keys = [u.key() for u in search_results]
         db.delete(keys)
         helper.write_json([k.name() for k in keys])
     else:
         helper.set_status(204)
开发者ID:mhawthorne,项目名称:antonym,代码行数:9,代码来源:resources.py


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