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

Python resource.Resource类代码示例

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

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



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

示例1: test_02_request_package_name

 def test_02_request_package_name(self):
   """ 2: Test request_package_name method from Resource class
       Check if returns a value, which is not NULL """
   resource = Resource(self.testid)
   resource.unpack_object_to_self(resource.load_from_ckan())
   package_name = resource.request_package_name()
   self.failUnless(package_name, 'package name is NULL!')
开发者ID:AKSW,项目名称:CSV2RDF-WIKI,代码行数:7,代码来源:test_resource.py


示例2: __init__

    def __init__(self, request):
        """Box"""
        resource_provider = ResourceProvider()
        resource = Resource(resource_provider)
        self.charts = []
        self.chart_type = None
        self.layout = Layout(request)
        self.body = ''
        self.javascript = ''
        self.chart_name = request.matchdict['box_name']
        chart_format = os.path.splitext(request.environ['PATH_INFO'])[1]
        # Go through the registry, and find the resource for this box
        # XXX This should be a dictionary
        for res in RESOURCES_REGISTRY:
            if res[0] == self.chart_name:
                self.resources = [res]

        if chart_format == '.html':
            self.render_html(request)
        elif chart_format == '.csv':
            self.body = resource.get(self.chart_name, CSV, request.matchdict)
        elif chart_format == '.json':
            self.body = resource.get(self.chart_name, JSON, request.matchdict)
        else:
            print "Format not supported %s" % chart_format
            raise AttributeError
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:26,代码来源:box.py


示例3: test_should_load_resource

	def test_should_load_resource(self):
		content = "Content"
		web = TestWeb()
		web.response = FakeResponse(content, "text/html")
		resource = Resource("Link", "Target", web)
		loaded_content = resource.load()
		self.assertEqual(loaded_content, content)
开发者ID:cessor,项目名称:scrape,代码行数:7,代码来源:test_resource.py


示例4: add_file

 def add_file(self, resource_list=None, dir=None, file=None):
     """Add a single file to resource_list
     
     Follows object settings of set_path, set_md5 and set_length.
     """
     try:
         if self.exclude_file(file):
             self.logger.debug("Excluding file %s" % (file))
             return
         # get abs filename and also URL
         if (dir is not None):
             file = os.path.join(dir,file)
         if (not os.path.isfile(file) or not (self.include_symlinks or not os.path.islink(file))):
             return
         uri = self.mapper.dst_to_src(file)
         if (uri is None):
             raise Exception("Internal error, mapping failed")
         file_stat=os.stat(file)
     except OSError as e:
         sys.stderr.write("Ignoring file %s (error: %s)" % (file,str(e)))
         return
     timestamp = file_stat.st_mtime #UTC
     r = Resource(uri=uri,timestamp=timestamp)
     if (self.set_path):
         # add full local path
         r.path=file
     if (self.set_md5):
         # add md5
         r.md5=compute_md5_for_file(file)
     if (self.set_length):
         # add length
         r.length=file_stat.st_size
     resource_list.add(r)
开发者ID:EHRI,项目名称:resync,代码行数:33,代码来源:resource_list_builder.py


示例5: assemble

 def assemble(section_name, items):
     # 将配置文件的数据组装成对象
     resource = Resource()
     resource.flag = section_name
     for item in items:
         setattr(resource, item[0], item[1])
     return resource
开发者ID:hiyouth,项目名称:SpiderMan,代码行数:7,代码来源:supplier.py


示例6: traverse

        def traverse(dct, parent=None):
            resources = {}

            for name, res in dct.items():
                host = url_to_host(self.base_url)
                apidoc_url = urljoin(host, res.get('apidoc'))
                schema_url = urljoin(host, res.get('schema'))

                resource = Resource(
                    self,
                    name,
                    res.get('relativePath'),
                    schema_url,
                    apidoc_url,
                    parent=parent,
                )
                self._resources[name] = resource
                resources[name] = resource

                child_resources = {}
                for att, val in res.items():
                    if att == 'children':
                        child_resources.update(
                            traverse(val, parent=resource)
                        )

                resource.children = child_resources

            return resources
开发者ID:oxilion,项目名称:zarafa-zsm,代码行数:29,代码来源:api.py


示例7: get_user_resource_tags

def get_user_resource_tags(username, collectionid, resourceid):
    rsrc = Resource()
    rsrc.create()
    result = rsrc.get(username, collectionid, resourceid)
    if not result:
        return [{'No tags'}]
    else:
        return [{'TagText': result[0]['tags']}]
开发者ID:gopakumarce,项目名称:photostore,代码行数:8,代码来源:photostore.py


示例8: __init__

 def __init__(self, manager, id):
     Resource.__init__(self, manager, id)
     self.data = None
     self.size = None
     self.hash = None
     self.controllers = []
     self.remaining_controllers = None
     logging.debug("New buffer: %s", self)
开发者ID:spirali,项目名称:aislinn,代码行数:8,代码来源:controller.py


示例9: test_08_load_mapping

  def test_08_load_mapping(self):
    """ 8: Test fetching the wiki page and parsing together """
    resource = Resource(self.testid)
    resource.wiki_site = wikitools.Wiki(config.wiki_api_url)
    resource.wiki_site.login(config.wiki_username, password=config.wiki_password)

    mappings = resource.load_mappings()
    self.failUnless(mappings, 'No mappings exists!')
开发者ID:AKSW,项目名称:CSV2RDF-WIKI,代码行数:8,代码来源:test_resource.py


示例10: test_06_request_wiki_page

  def test_06_request_wiki_page(self):
    """ 6: Test if wiki page for this Resource exists """
    resource = Resource(self.testid)
    resource.wiki_site = wikitools.Wiki(config.wiki_api_url)
    resource.wiki_site.login(config.wiki_username, password=config.wiki_password)

    wiki_page = resource._request_wiki_page()
    self.failUnless(wiki_page, "Wiki page does not exist or empty!")
开发者ID:AKSW,项目名称:CSV2RDF-WIKI,代码行数:8,代码来源:test_resource.py


示例11: DistributionTestCase

class DistributionTestCase(unittest.TestCase):
    
    def setUp(self):
        self.job = Job()
        self.batch = Batch()
        self.resource = Resource()
        
        rootDir = os.environ['BOLT_DIR']
        self.batch.readConfig(rootDir + configDir + "/" + batchConfig)
        self.resource.readConfig(rootDir + configDir + "/" + resourceConfig)

    def testParallelTaskDitributionPureMPI(self):
        """Pure MPI task distribution (fully populated)."""
        
        # Set the parallel distribution
        self.job.setTasks(1024)
        self.job.setTasksPerNode(self.resource.numCoresPerNode())
        self.job.setThreads(1)
        self.job.setParallelDistribution(self.resource, self.batch)
        
        correct = "aprun -n 1024 -N 32 -S 8 -d 1"
        self.assertEqual(self.job.runLine, correct, "Value= '{0}', Expected= '{1}'".format(self.job.runLine, correct))
        
    def testParallelTaskDitributionHalfPopulate(self):
        """Pure MPI task distribution (half populated)."""
        
        # Set the parallel distribution
        self.job.setTasks(1024)
        self.job.setTasksPerNode(16)
        self.job.setThreads(1)
        self.job.setParallelDistribution(self.resource, self.batch)
        
        correct = "aprun -n 1024 -N 16 -S 4 -d 2"
        self.assertEqual(self.job.runLine, correct, "Value= '{0}', Expected= '{1}'".format(self.job.runLine, correct))

    def testParallelTaskDitributionTwoThreads(self):
        """Hybrid MPI/OpenMP task distribution (2 OpenMP threads)."""
        
        # Set the parallel distribution
        self.job.setTasks(1024)
        self.job.setTasksPerNode(16)
        self.job.setThreads(2)
        self.job.setParallelDistribution(self.resource, self.batch)
        
        correct = "export OMP_NUM_THREADS=2\naprun -n 1024 -N 16 -S 4 -d 2"
        self.assertEqual(self.job.runLine, correct, "Value= '{0}', Expected= '{1}'".format(self.job.runLine, correct))

    def testParallelTaskDitributionThreeThreads(self):
        """Hybrid MPI/OpenMP task distribution (3 OpenMP threads)."""
        
        # Set the parallel distribution
        self.job.setTasks(1024)
        self.job.setTasksPerNode(10)
        self.job.setThreads(3)
        self.job.setParallelDistribution(self.resource, self.batch)
        
        correct = "export OMP_NUM_THREADS=3\naprun -n 1024 -N 10 -d 3"
        self.assertEqual(self.job.runLine, correct, "Value= '{0}', Expected= '{1}'".format(self.job.runLine, correct))
开发者ID:ebreitmo,项目名称:bolt,代码行数:58,代码来源:testDistribution.py


示例12: get

 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     resources = Resource.getResources()
     resources = Resource.getResourcesFor6Through8(resources)
     values = {
         "title": "Middle School",
         "curr_url": self.request.url,
     }
     self.response.out.write(template.render('html/middle.html', values))
开发者ID:besdhs,项目名称:hsfoye,代码行数:9,代码来源:hsf_oye.py


示例13: test_01_load_from_ckan

 def test_01_load_from_ckan (self):
   """ 1: Test load_from_ckan method from Resource class
       Check if attributes of the Resource object fetched from CKAN exist:
       -- revision_id - used for fetching package_id
       -- url - used for downloading the data file """
   resource = Resource(self.testid)
   object = resource.load_from_ckan()
   self.failUnless('url' in object, 'Tested object has no url attribute.')
   self.failUnless('revision_id' in object, 'Tested object has no revision_id attribute.')
开发者ID:AKSW,项目名称:CSV2RDF-WIKI,代码行数:9,代码来源:test_resource.py


示例14: put_resource

def put_resource(data):
    rsrc = Resource(True)
    if 'resourceid' in data:
        rsrcid = data['resourceid']
    else:
        rsrcid = str(time.time())
    # the last param None is the photo data which we will fill in later
    rsrc.put(data['user'], data['collectionid'], data['description'], rsrcid, None)
    return rsrcid
开发者ID:gopakumarce,项目名称:photostore,代码行数:9,代码来源:photostore.py


示例15: test_should_update_the_resource_when_it_attempts_a_redirect

	def test_should_update_the_resource_when_it_attempts_a_redirect(self):
		web = TestWeb()
		url = "http://localhost:5000/redirect"
		web.head = self.redirect
		resource = Resource('Page', 'http://localhost:5000', web)
		resource.isAPage()
		web.head = lambda x: FakeResponse('Content', 'application/pdf')

		self.assertEqual(resource.name, "redirect.pdf")
		self.assertEqual(resource.url, "http://localhost:5000/redirect.pdf")
开发者ID:cessor,项目名称:scrape,代码行数:10,代码来源:test_resource.py


示例16: test_04_get_wiki_url

  def test_04_get_wiki_url(self):
    """ 4: Test if get_wiki_url method from Resource class
        returns URI string.
        The result depends on config.py file."""
    resource = Resource(self.testid)

    parsed_url = urlparse(resource.get_wiki_url())
    self.failUnless(parsed_url.scheme, "Scheme is missing.")
    self.failUnless(parsed_url.netloc, "Net Location (e.g. publicdata.eu) is missing.")
    self.failUnless(parsed_url.path, "Path is missing.")
开发者ID:AKSW,项目名称:CSV2RDF-WIKI,代码行数:10,代码来源:test_resource.py


示例17: post

 def post(self):
     lang = self.request.get("lang")
     resources = Resource.getResources()
     if lang:
         resources = Resource.getResourcesForSpanish(resources, True)
     resources = Resource.getResourcesFor9Through12(resources)
     values = {
         "title": "High School",
         "curr_url": self.request.url,
         "resources": resources    
     }
     self.response.out.write(template.render('html/highschool.html', values))
开发者ID:besdhs,项目名称:hsfoye,代码行数:12,代码来源:hsf_oye.py


示例18: get_user_resource_details

def get_user_resource_details(username, collectionid, resourceid):
    rsrc = Resource()
    rsrc.create()
    result = rsrc.get(username, collectionid, resourceid)
    if not result:
        return {'Not found'}
    else:
        return {
                'FileSource': result[0]['hires_url'],
                'Description' : 'Powered by PhotoStore Technology',
                'Location': 'Palo Alto'
               }
开发者ID:gopakumarce,项目名称:photostore,代码行数:12,代码来源:photostore.py


示例19: get_resource

def get_resource(data):
    if not data:
        return {'NOTFOUND'}
    rsrc = Resource(True)
    if 'collectionid' in data:
        collectionid = data['collectionid']
    else:
        collectionid = None
    if 'resourceid' in data:
        resourceid = data['resourceid']
    else:
        resourceid = None
    return rsrc.get(data['user'], collectionid, resourceid)
开发者ID:gopakumarce,项目名称:photostore,代码行数:13,代码来源:photostore.py


示例20: from_disk

    def from_disk(self,path,url_prefix,inventory=None):
        """Create or extend inventory with resources from disk scan

        Assumes very simple disk path to URL mapping: chop path and
        replace with url_path. Returns the new or extended Inventory
        object.

        If a inventory is specified then items are added to that rather
        than creating a new one.

        mb = InventoryBuilder()
        m = inventory_from_disk('/path/to/files','http://example.org/path')
        """
        num=0
        # Either use inventory passed in or make a new one
        if (inventory is None):
            inventory = Inventory()
        # for each file: create Resource object, add, increment counter
        for dirpath, dirs, files in os.walk(path,topdown=True):
            for file_in_dirpath in files:
                try:
                    if self.exclude_file(file_in_dirpath):
                        continue
                    # get abs filename and also URL
                    file = os.path.join(dirpath,file_in_dirpath)
                    if (not os.path.isfile(file) or not (self.include_symlinks or not os.path.islink(file))):
                        continue
                    rel_path=os.path.relpath(file,start=path)
                    if (os.sep != '/'):
                        # if directory path sep isn't / then translate for URI
                        rel_path=rel_path.replace(os.sep,'/')
                    url = url_prefix+'/'+rel_path
                    file_stat=os.stat(file)
                except OSError as e:
                    sys.stderr.write("Ignoring file %s (error: %s)" % (file,str(e)))
                    continue
                mtime = file_stat.st_mtime
                lastmod = datetime.fromtimestamp(mtime).isoformat()
                r = Resource(uri=url,lastmod=lastmod)
                if (self.do_md5):
                    # add md5
                    r.md5=compute_md5_for_file(file)
                if (self.do_size):
                    # add size
                    r.size=file_stat.st_size
                inventory.add(r)
            # prune list of dirs based on self.exclude_dirs
            for exclude in self.exclude_dirs:
                if exclude in dirs:
                    dirs.remove(exclude)
        return(inventory)
开发者ID:edsu,项目名称:resync-simulator,代码行数:51,代码来源:inventory_builder.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python environment.Environment类代码示例发布时间:2022-05-26
下一篇:
Python resource.Popen类代码示例发布时间: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