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


Python properties.Properties类代码示例

本文整理汇总了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
开发者ID:Seegnify,项目名称:Elasticcrawler,代码行数:60,代码来源:elasticcrawler.py

示例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()
开发者ID:nuka1195,项目名称:lyrics.xbmc_lyrics,代码行数:25,代码来源:player.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:7,代码来源:propertiestest.py

示例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
开发者ID:steventclarke,项目名称:dead-properties-finder,代码行数:33,代码来源:dead-property-finder.py

示例5: testEmptyProperty3

 def testEmptyProperty3(self):
   lb = LineBuffer()
   lb.append("x=       \n")
   dict = { "x" : "" }
   p = Properties()
   p.load(lb)
   self.assertTrue(p.equalsDict(dict))
开发者ID:kimballa,项目名称:stitch,代码行数:7,代码来源:propertiestest.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:7,代码来源:propertiestest.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:7,代码来源:propertiestest.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:8,代码来源:propertiestest.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:8,代码来源:propertiestest.py

示例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))
开发者ID:kimballa,项目名称:stitch,代码行数:10,代码来源:propertiestest.py

示例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
开发者ID:amirgeva,项目名称:coide,代码行数:10,代码来源:genmake.py

示例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)
开发者ID:jfx2006,项目名称:OpenSesame,代码行数:12,代码来源:openvpnclient.py

示例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)
开发者ID:jfx2006,项目名称:OpenSesame,代码行数:12,代码来源:openvpnclient.py

示例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)
开发者ID:hayderimran7,项目名称:grabbit,代码行数:7,代码来源:frame.py

示例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
开发者ID:daviddao,项目名称:cpa-multiclass,代码行数:29,代码来源:trainingset.py


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