本文整理汇总了Python中properties.Properties类的典型用法代码示例。如果您正苦于以下问题:Python Properties类的具体用法?Python Properties怎么用?Python Properties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Properties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_client_access_allowed
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
示例2: __init__
def __init__(self, *args, **kwargs):
# set addon object
self.m_addon = kwargs["addon"]
# passing "<windowId>" from RunScript() means run in background
self.use_gui = kwargs["gui"]
# initialize our super classes
XBMCPlayer.__init__(self)
Properties.__init__(self)
# initialize timers
self._lyric_timer = None
self._fetch_timer = None
# log started action
self._log_addon_action("started")
# initialize our Song class
self.song = Song(addon=self.m_addon)
# initialize our prefetched Song class
# TODO: remove the self.isPlayingAudio() check when/if XBMC supports offset for player
self.prefetched_song = None
if (self.m_addon.getSetting("prefetch_lyrics") and self.isPlayingAudio()):
self.prefetched_song = Song(addon=self.m_addon, prefetch=True)
# start
if (self.use_gui):
self._start_gui()
else:
self._start_background()
示例3: testEscape1
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))
示例4: main
def main() :
"""
This is a simple script used to parse a .properties file
and recurslively examine a body of code to identify properties
which are no longer referenced.
Usage :
>> python dead-properties-finder.py propFile searchRootDir
Where propFile is the properties file
and searchRootDir is the root directory of the body of code to search through
If a property is not found in the code base, the name of the property is
printed to stdout
Note : If the body of code you are searching contains the properties file you
are parsing, it won't work! That file will contain all properties which are
being searched for and thus the script will not flag any properties as unreferenced.
It may be best to remove ALL properties files from the project temporarily
before running the script to ensure there are no false negatives.
Also, the class used to parse the properties file assumes property value pairs
are "=" delimited. Using ":" may be accepted by other properties parsers, but
the properties file class used by this script currently only accepts "="
"""
propFile = sys.argv[1]
searchRoot = sys.argv[2]
props = Properties(propFile)
for prop in props.keySet() :
retCode = os.system("grep -rq %s %s" % (prop, searchRoot))
if retCode > 0 :
print prop
示例5: testEmptyProperty3
def testEmptyProperty3(self):
lb = LineBuffer()
lb.append("x= \n")
dict = { "x" : "" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例6: testWhitespace3
def testWhitespace3(self):
lb = LineBuffer()
lb.append("x=42\n")
dict = { "x" : "42" }
p = Properties()
p.load(lb)
self.assertTrue(p.equalsDict(dict))
示例7: testKeyEscape2
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))
示例8: testLineContinue
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))
示例9: testOverwrite
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))
示例10: testIgnoreBlanks
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))
示例11: mkProps
def mkProps(props, dir):
path=os.path.join(dir,'mk.cfg')
if os.path.exists(path):
p=Properties(path)
for name in p.keys():
value=p.get(name)
if value.startswith('\\'):
value=props.get(name)+' '+value[1:]
props.assign(name,value)
return props
示例12: on_actionNew_triggered
def on_actionNew_triggered(self):
"""
Create a new config
"""
propDialog = Properties(self.config, parent=self)
if propDialog.exec_():
ovconfig = propDialog.getconfig()
self.addconnection(ovconfig)
ovconfig.copycerts()
filename = ovconfig.writeconfig()
settingkey = "connections/%s" % ovconfig.getname()
self.settings.setValue(settingkey, filename)
示例13: doProperties
def doProperties(self, row):
if row >= 0:
ovconfig = self.tableConnections.configs[row]
propDialog = Properties(self.config, ovconfig, self)
if propDialog.exec_():
ovconfig = propDialog.getconfig()
self.editconnection(ovconfig, row)
ovconfig.copycerts()
filename = ovconfig.writeconfig()
settingkey = "connections/%s" % ovconfig.getname()
self.settings.setValue(settingkey, filename)
示例14: unpack
def unpack(cls, data):
# we special-case as we need properties unpack class to change according to method_class
method_class, data = Octet.unpack(data)
weight, data = Octet.unpack(data)
body_size, data = LongLong.unpack(data)
properties, data = Properties.get_by_class(method_class).unpack(data)
return cls(method_class, body_size, properties)
示例15: Save
def Save(self, filename):
# check cache freshness
try:
self.cache.clear_if_objects_modified()
except:
logging.info("Couldn't check cache freshness, DB connection lost?")
f = open(filename, 'w')
try:
from properties import Properties
p = Properties.getInstance()
f.write('# Training set created while using properties: %s\n'%(p._filename))
f.write('label '+' '.join(self.labels)+'\n')
i = 0
for label, obKey in self.entries:
line = '%s %s %s\n'%(label, ' '.join([str(int(k)) for k in obKey]), ' '.join([str(int(k)) for k in self.coordinates[i]]))
f.write(line)
i += 1 # increase counter to keep track of the coordinates positions
try:
f.write('# ' + self.cache.save_to_string([k[1] for k in self.entries]) + '\n')
except:
logging.error("No DB connection, couldn't save cached image strings")
except:
logging.error("Error saving training set %s" % (filename))
f.close()
raise
f.close()
logging.info('Training set saved to %s'%filename)
self.saved = True