本文整理汇总了Python中properties.Properties.load方法的典型用法代码示例。如果您正苦于以下问题:Python Properties.load方法的具体用法?Python Properties.load怎么用?Python Properties.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类properties.Properties
的用法示例。
在下文中一共展示了Properties.load方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEscape1
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testEscape1(self):
lb = LineBuffer()
lb.append("x=4\\t2\n")
dict = { "x" : "4\t2" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例2: is_client_access_allowed
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def is_client_access_allowed(url, config, allowed, excluded):
# get url blocks
url_parsed = urlparse(url)
protocol = url_parsed.scheme
hostname = url_parsed.hostname
path = url_parsed.path
# read config variables
conf = Properties()
with open(config) as f:
conf.load(f)
# check allowed protocols
allowed_protocols = conf['ALLOWED_PROTOCOLS'].replace(' ', '').split(',')
if url_parsed.scheme not in allowed_protocols:
return False
# check excluded file types
exluded_types = conf['EXCLUDE_FILE_TYPES'].replace(' ', '').split(',')
dot_index = path.rfind('.', 0)
if dot_index > 0 and path[dot_index+1:].lower() in exluded_types:
return False
# get host groups flags
exclude_privates = True if conf['EXCLUDE_PRIVATE_HOSTS'] == 'true' else False
exclude_singles = True if conf['EXCLUDE_SINGLE_HOSTS'] == 'true' else False
# read exluded hosts
with open(excluded) as f:
excluded_hosts = [host.strip() for host in f.readlines()]
# read allowed hosts
with open(allowed) as f:
allowed_hosts = [host.strip() for host in f.readlines()]
# validate address
if hostname == None or len(hostname) == 0:
return False;
# check excluded hosts
if hostname in excluded_hosts:
return False
# check allowed hosts
if len(allowed_hosts) > 0 and (hostname not in allowed_hosts):
return False
# exclude private hosts
if exclude_privates == True:
if is_ip_address_private(hostname):
return False
# exclude single hosts
if exclude_singles == True:
if len(hostname.split('.')) == 1:
return False
# now we can confirm positive
return True
示例3: testEmptyProperty3
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testEmptyProperty3(self):
lb = LineBuffer()
lb.append("x= \n")
dict = { "x" : "" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例4: testWhitespace3
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testWhitespace3(self):
lb = LineBuffer()
lb.append("x=42\n")
dict = { "x" : "42" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例5: testKeyEscape2
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testKeyEscape2(self):
lb = LineBuffer()
lb.append("x\\ y=42\n")
dict = { "x y" : "42" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例6: testLineContinue
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testLineContinue(self):
lb = LineBuffer()
lb.append("x=42 \\\n")
lb.append(" boo\n")
dict = { "x" : "42 boo" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例7: testOverwrite
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testOverwrite(self):
lb = LineBuffer()
lb.append("x=42\n")
lb.append("x=44\n")
dict = { "x" : "44" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例8: testIgnoreBlanks
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def testIgnoreBlanks(self):
lb = LineBuffer()
lb.append("\n")
lb.append("x=42\n")
lb.append(" \n")
lb.append(" # comment\n")
dict = { "x" : "42" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例9: range
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
size = comm.Get_size()
rank_images = images_count / size
#-------------------Wyslanie do innych watkow
for send_rank in range(1, size):
send_images = []
for part_image in range(0, rank_images):
send_images.append(images[0])
images.remove(images[0])
comm.send(send_images, dest=send_rank, tag=111)
#-------------------Policzenie na watku zerowym
rank0_images = images.__len__()
images_for_properties = get_images_for_properties(images)
p = Properties()
p.load(images_for_properties)
properties = p.get_properties()
trait = properties[0] * rank0_images
dynamic = properties[1] * rank0_images
colors = [x * rank0_images for x in properties[2]]
#-------------------Zebranie wynikow
for recv_rank in range(1, size):
properties = comm.recv(source=recv_rank, tag=111)
trait += properties[0] * rank_images
dynamic += properties[1] * rank_images
map(add, colors, [x * rank_images for x in properties[2]])
colors_map = [(0.125, "red"), (0.25, "orange"), (0.375, "yellow"),
(0.5, "green"), (0.625, "teal"), (0.75, "blue"),
(0.875, "purple"), (1., "pink")]
示例10: main
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument('--type', action="store", dest="type")
argparser.add_argument('-n', action="store", dest="n", type=int)
argparser.add_argument('--width', action="store", dest="width", type=int)
argparser.add_argument('--height', action="store", dest="height", type=int)
argparser.add_argument('--fontsize', action="store", dest="fontsize", type=int)
argparser.add_argument('-l', action="store", dest="length", type=int)
options = argparser.parse_args()
if options.type == None and options.n == None and options.width == None and options.height == None and options.fontsize == None and options.length == None:
print "No params given, i will use settings.ini"
props = Properties("settings.ini")
props.load()
count = props.getNumber()
rand_word = RandomWord()
rand_str = RandomString(int(props.getWordLength()))
word_type = props.getWordType()
if word_type == "natural":
i = 0
while (i < int(count)):
i = i+1
print (rand_word.getFixedLengthWord(int(props.getWordLength())))
captcha=Captcha(rand_word.getFixedLengthWord(int(props.getWordLength())), int(props.getFontSize()), int(props.getImageWidth()), int(props.getImageHeight()))
captcha.saveImage()
elif word_type == "random":
i = 0
while (i < int(count)):
i = i+1
print (rand_str.shuffle(int(props.getWordLength())))
captcha=Captcha(rand_str.shuffle(int(props.getWordLength())), int(props.getFontSize()), int(props.getImageWidth()), int(props.getImageHeight()))
captcha.saveImage()
else :
print ("word type must be random or natural")
print ("Done, generated "+props.getNumber()+" captchas")
#TODO: сделать возможность часть параматров брать из settings.ini а часть из консоли
else:
rand_word = RandomWord()
rand_str = RandomString(options.length)
word_type = options.type
if word_type == "natural":
i = 0
while (i < int(count)):
i = i+1
print (rand_word.getFixedLengthWord(options.length))
captcha=Captcha(rand_word.getFixedLengthWord(options.length, options.fontsize, options.width, options.height))
captcha.saveImage()
elif word_type == "random":
i = 0
while (i < int(count)):
i = i+1
print (rand_str.shuffle(options.length))
captcha=Captcha(rand_str.shuffle(options.length, options.fontsize, options.width, options.height))
captcha.saveImage()
else :
print ("word type must be random or natural")
print ("Done, generated "+props.getNumber()+" captchas")
示例11: ResourceBundle
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
class ResourceBundle(PyWebMvcObject):
"""Extends a L{Properties<properties.Properties>} file to allow for
parameterized substitution and property references (terms). Parameters are in
the form C{{N}} where N is an zero-based index of the paramters to the
getMessage function. Terms take the form C{${resourcekey}} and allow a
resource entry to refer to another resource entry. It is not recommended that
you place parameters in your terms, but it is allowed since parameter
substitution is performed after term expansion. Example::
term.foo=Foo
term.idea=idea
term.modifiedIdea={1} ${term.idea}
message.bar=This is my {0} ${term.foo}.
message.badIdea=This is a {0} ${term.modifiedIdea}.
message.fineIdea=This is a {0} {1}.
message.goodIdea=This is a {0} {1} ${term.idea}.
>>> bundle["term.foo"]
'Foo'
>>> bundle["term.modifiedIdea"]
'{1} idea'
>>> bundle.getMessage("message.bar","Silly")
'This is my Silly Foo.'
>>> bundle.getMessage("message.badIdea","really", "bad")
'This is a really bad idea.'
>>> bundle.getMessage("message.fineIdea","perfectly",
... bundle.getMessage("term.modifiedIdea","fine"))
'This is a perfectly fine idea.'
>>> bundle.getMessage("message.goodIdea","much", "better")
'This is a much better idea.'
"""
def __init__(self, propertiesFile = None):
self.props = Properties()
if propertiesFile:
self.addPropertiesFile(propertiesFile)
def addPropertiesFile(self, propertiesFile):
if isinstance(propertiesFile, types.StringTypes):
self.props.read(propertiesFile)
else:
self.props.load(propertiesFile)
self.resolve_terms()
def addPropertiesFiles(self, propertiesFiles):
for f in propertiesFiles:
self.addPropertiesFile(f)
def resolve_terms(self):
for key in self.props.keys():
self.props[key] = self.replaceTerms(self.props[key])
def has_term(self,msg):
idx = msg.find("${")
if idx < 0:
return False
else:
return msg.find("}",idx) >= 0
def get_term(self,msg,all=False):
tokens = re.split("(\\$\\{|\\})",msg)
startCount = 0
term = ""
terms = []
for token in tokens:
if token == "${":
startCount += 1
if startCount > 1:
term += token
elif token == "}" and startCount > 0:
startCount -= 1
if startCount == 0:
if all:
terms.append(term)
term = ""
else:
return term
else:
term += token
elif startCount > 0:
term += token
if startCount > 0:
raise ValueError("Malformed term found in message resource: "+msg)
if all:
return terms
else:
return None
def replaceTerms(self, msg, paramMap = {}):
terms = self.get_term(msg,all=True)
for term in terms:
origTerm = term
try:
if self.has_term(term):
term = self.replaceTerms(term, paramMap)
if paramMap.has_key(term):
termVal = paramMap[term]
else:
termVal = self.getMessage(term,paramMap)
msg = msg.replace("${"+origTerm+"}",termVal)
except KeyError:
pass
return msg
def keys(self):
return self.props.keys()
def has_key(self, key):
return self.props.has_key(key)
#.........这里部分代码省略.........
示例12: reset
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
def reset(self, type=common_pb2.CACHE_ALL):
# 던전정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_DUNGEON:
self._lock_dungeons.acquire()
self._clear_dungeons()
self._load_dungeons()
self._load_stages()
self._load_stage_waves()
self._load_monsters()
self._load_survival_waves()
self._lock_dungeons.release()
# 의상정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_COSTUME:
self._lock_costumes.acquire()
self._clear_costumes()
self._load_costumes()
self._lock_costumes.release()
# 스킬정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_SKILL:
self._lock_skills.acquire()
self._clear_skills()
self._load_skills()
self._load_skill_costs()
self._lock_skills.release()
# 아이템정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_ITEM:
self._lock_items.acquire()
self._clear_items()
self._load_items()
self._load_combinations()
self._load_blueprints()
self._lock_items.release()
# 레벨정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_LEVEL:
self._lock_levels.acquire()
self._clear_levels()
self._load_levels()
self._lock_levels.release()
# 게임설정
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_PROPERTIES:
from properties import Properties
Properties.load()
# 뽑기정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_LOTTERY:
self._lock_lotterys.acquire()
self._clear_lotterys()
self._load_lotterys()
self._load_lottery_items()
self._load_lottery_tiers()
self._lock_lotterys.release()
# 보물상자
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_TREASURE_BOX:
self._lock_treasures.acquire()
self._clear_treasures()
self._load_treasures()
self._lock_treasures.release()
# 상점정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_SHOP:
self._lock_shops.acquire()
self._clear_shops()
self._load_eshops()
self._load_cash_shops()
self._lock_shops.release()
# 선물함정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_GIFT_BOX:
self._lock_gifts.acquire()
self._clear_gifts()
self._load_gifts()
self._lock_gifts.release()
# 이벤트정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_EVENT:
self._lock_events.acquire()
self._clear_events()
self._lock_events.release()
# 일일보상
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_DAILYSTAMP:
self._lock_dailystamps.acquire()
self._clear_dailystamps()
self._load_dailystamps()
self._lock_dailystamps.release()
# 업적정보
if type == common_pb2.CACHE_ALL or type == common_pb2.CACHE_ACHIVEMENT:
self._lock_achivements.acquire()
self._clear_achivements()
self._load_achivements()
self._load_daily_achivements()
self._lock_achivements.release()
#.........这里部分代码省略.........
示例13: int
# 需要导入模块: from properties import Properties [as 别名]
# 或者: from properties.Properties import load [as 别名]
BULK_SIZE = int(sys.argv[3])
# validate input arguments
if not STEP_NAME in ['INIT', 'DIST', 'RANK', 'PUBL'] or BULK_SIZE <= 0:
syntax()
sys.exit(2)
# add ElasticCrawler lib to system path
sys.path.append("%s/lib" % EC_HOME)
from properties import Properties
from elasticsearch import ElasticSearch
from elasticcrawler import get_url_id
# load ElasticCrawler configuarion
conf = Properties()
conf.load(open("%s/conf/elasticcrawler.conf" % EC_HOME))
ES_HOST = conf['ES_HOST']
ES_PORT = conf['ES_PORT']
ES_INDEX = conf['ES_INDEX']
ES_BASE = "http://%s:%s/%s" % (ES_HOST, ES_PORT, ES_INDEX)
# load ElasticSearch REST API module
es = ElasticSearch()
# create batch update container
update_list = list()
# create fetch doc id container
fetch_list = list()