本文整理汇总了Python中resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Python Resource类的具体用法?Python Resource怎么用?Python Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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!')
示例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
示例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)
示例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)
示例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
示例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
示例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']}]
示例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)
示例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!')
示例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!")
示例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))
示例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))
示例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.')
示例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
示例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")