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


Python Cache.clear方法代码示例

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


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

示例1: TestCache

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import clear [as 别名]
class TestCache(unittest.TestCase):
    
    def setUp(self):
        self.cache = Cache()
        self.cache.clear()


    def testGetGame(self):
        game = self.cache.getGame({'id': '105600'})
        self.assertIsNone(game)
        
        self.cache.putGame({'id': '105600', 'name': 'Terraria', 'features': ['Single-player', 'Multi-player', 'Co-op']})
        game = self.cache.getGame('105600')
        self.assertIsNotNone(game)
        self.assertEqual(game['id'], '105600')
        self.assertEqual(game['name'], 'Terraria')
        self.assertItemsEqual(game['features'], ['Single-player', 'Multi-player', 'Co-op'])
        
        
    def testUpdateGame(self):
        game = self.cache.getGame({'id': '105600'})
        self.assertIsNone(game)
        
        self.cache.putGame({'id': '105600', 'name': 'Terraria', 'features': ['Single-player', 'Multi-player', 'Co-op'], 'test': 'test'})
        self.cache.putGame({'id': '105600', 'name': 'Terraria2', 'features': []})
        game = self.cache.getGame('105600')
        self.assertIsNotNone(game)
        self.assertEqual(game['id'], '105600')
        self.assertEqual(game['name'], 'Terraria2')
        self.assertItemsEqual(game['features'], [])
        self.assertFalse('test' in game)
        self.assertFalse('_id' in game)
        self.assertEqual(self.cache.games.count(), 1)
开发者ID:underkround,项目名称:steam-dissector,代码行数:35,代码来源:steam_dissector_acceptance_tests.py

示例2: Merge

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import clear [as 别名]
class Merge(object):
	def get_file_name(self, s):
		"""remove the first "file: " and blanl
		"""
		return s.partition("file:")[2].strip()

	def open_file(self, file_name):
		"""open file
		"""
		try:
			fp_code = open(file_name)
			return fp_code
		except IOError:
			return self.perror(self.whole_line_num, \
					self.current_name, "can't open code file: \""\
					+file_name+"\"")
	def perror(self, line_num,  name, msg):
		"""print error
		"""
		sys.stderr.write("merge "+str(line_num)+": error: "\
				+msg+"\n")
		sys.stderr.write("merge: skip the program: "+name[0]+"\n")
		return -2

	def output(self, fp, s):
		fp.write(s)

	def move_in_comment(self, fp, in_comment):
		"""start print comments
		"""
		if not in_comment:
			in_comment = True
			self.output(fp, "/*\n")
		return in_comment

	def move_out_comment(self, fp, in_comment):
		"""stop print comments
		"""
		if in_comment:
			in_comment = False
			self.output(fp, "*/\n")
		return in_comment

	def output_code(self, fp, file_name, cache, print_flag = True):
		"""open code file and print it to fp
		"""
		fp_code = self.open_file(file_name);
		if fp_code == -2:
			return -2
		if not print_flag:
			return 0
		code = fp_code.readlines()
		print_code = False
		fp.write(cache.get())
		for line_code in code:
			if line_code.strip() == "/*codebook start*/":
				print_code = True
			elif line_code.strip() == "/*codebook end*/":
				print_code = False
			elif print_code:
				fp.write(line_code)
		fp_code.close()
		return 1

	def run(self, list_file_name = "list", output_file_name \
			= "codebook"):
		"""main function
		"""
		fp_index = open(list_file_name)
		index = fp_index.readlines()
		fp_index.close()
		fp_code = 0
		cnt = 0
		part_line_num = -1
		self.whole_line_num = 0
		self.current_name = []
		self.lib = {}
		in_comment = False

		fp_output = open(output_file_name , "w")
		self.cache = Cache()

		for line in index:
			self.whole_line_num += 1
			line = line.strip()
			if part_line_num == -1 and line == "":
				#escape the blank
				continue
			elif part_line_num == -1:
				#start
				self.cache.clear()
				in_comment = self.move_in_comment(self.cache, \
						in_comment)
				self.output(self.cache, line+"\n")
				part_line_num += 1
				self.current_name = line, self.whole_line_num
			elif part_line_num == 0:
				#get the file name and open it
				if "file:" not in line:
					part_line_num = self.perror(\
#.........这里部分代码省略.........
开发者ID:owenwater,项目名称:codebook,代码行数:103,代码来源:merge.py


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