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


Python configparser.ConfigParser类代码示例

本文整理汇总了Python中exe.engine.configparser.ConfigParser的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser类的具体用法?Python ConfigParser怎么用?Python ConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testUnicodeFileName

 def testUnicodeFileName(self):
     """
     Should be able to write to unicode filenames
     """
     # Invent a unicode filename
     dirName = unicode('\xc4\x80\xc4\x900', 'utf8')
     fn = os.path.join(dirName, dirName)
     fn += '.ini'
     if not os.path.exists(dirName):
         os.mkdir(dirName)
     # Write some test data to our unicode file
     file_ = open(fn, 'wb')
     file_.write(TEST_TEXT)
     file_.close()
     # See if we can read and write it
     self.c.read(fn)
     self.assertEquals(self.c.main.power, 'on')
     self.c.main.power = 'off'
     self.c.write()
     # Check that it was written ok
     c2 = ConfigParser()
     c2.read(fn)
     self.assertEquals(c2.main.power, 'off')
     # Clean up
     os.remove(fn)
     os.rmdir(dirName)
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: testCreation

 def testCreation(self):
     """
     When one creates a section with the same name
     as an existing section the existing section should
     just be returned
     """
     mysec = Section('main', self.c)
     assert mysec is self.c.main
     othersec = Section('main', self.c)
     assert othersec is mysec is self.c.main is self.c._sections['main']
     newsec = Section('newsection', self.c)
     assert newsec is \
            self.c.addSection('newsection') is \
            self.c.newsection is \
            self.c._sections['newsection']
     newsec2 = self.c.addSection('newsection2')
     assert newsec2 is \
            self.c.addSection('newsection2') is \
            Section('newsection2', self.c) is \
            self.c.newsection2 is \
            self.c._sections['newsection2'] and \
            newsec2 is not newsec
     # Different parent should create new object
     otherConf = ConfigParser()
     sec1 = otherConf.addSection('x')
     sec2 = self.c.addSection('x')
     assert sec1 is not sec2
开发者ID:,项目名称:,代码行数:27,代码来源:

示例3: setUp

 def setUp(self):
     """
     Creates an application and
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     sys.argv[0] = 'exe/exe'
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     if G.application is None:
         G.application = Application()
         
     self.app = G.application
     G.application = self.app
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.session = FakeSession()
     self.app.webServer.root.bindNewPackage(self.package, self.session)
     self.mainpage = self.app.webServer.root.mainpages[self.session.uid]['temp']
     self.mainpage.idevicePane.client = self.client
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:29,代码来源:utils.py

示例4: testFromScratch

 def testFromScratch(self):
     """
     Tests adding stuff from nothing
     """
     x = ConfigParser()
     testing = x.addSection('testing')
     assert x.testing is testing
     testing.myval = 4
     self.assertEquals(x.get('testing', 'myval'), '4')
开发者ID:,项目名称:,代码行数:9,代码来源:

示例5: testStringIO

 def testStringIO(self):
     file_ = testFile()
     c = ConfigParser()
     c.read(file_)
     c.autoWrite = True
     assert 'Matthew' not in self.getVal(file_)
     c.main.name = 'Matthew'
     assert 'name = Matthew' in self.getVal(file_), self.getVal(file_)
     del c.main.name
     assert 'Matthew' not in self.getVal(file_)
开发者ID:,项目名称:,代码行数:10,代码来源:

示例6: __init__

 def __init__(self):
     """
     Initialise
     """
     self.configPath = None
     self.configParser = ConfigParser()
     self.exePath = Path(sys.argv[0]).abspath()
     self.webDir = self.exePath.dirname()
     self.xulDir = self.exePath.dirname()
     self.localeDir = self.exePath.dirname() / "locale"
     self.port = 51235
     self.dataDir = Path(".")
     self.configDir = Path(".")
     self.browserPath = Path("firefox")
     self.locale = chooseDefaultLocale(self.localeDir)
     self.styles = []
     self._overrideDefaultVals()
     self.webDir = Path(self.webDir)
     if not (self.webDir / "scripts").isdir() and (self.webDir / "webui").isdir():
         self.webDir /= "webui"
     self.xulDir = Path(self.xulDir)
     if not (self.xulDir / "scripts").isdir() and (self.xulDir / "xului").isdir():
         self.xulDir /= "xului"
     self.__setConfigPath()
     self._writeDefaultConfigFile()
     self.loadSettings()
     self.setupLogging()
     self.loadStyles()
     self.loadLocales()
开发者ID:,项目名称:,代码行数:29,代码来源:

示例7: testReadFileName

 def testReadFileName(self):
     """Can read text"""
     goodDict = {'second': 
                     {'good': 'yes',
                      'bad': 'no',
                       'available': 'yes',
                       'funny-name_mate': 'crusty the clown'}, 
                 'main': 
                     {'running': u'on\t\u0100\u01100',
                      'testing': 'false',
                      'two words': 'are better than one',
                      'no_value': '',
                      'power': 'on',
                      'level': '5'}}
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     assert self.c._sections == goodDict, self.c._sections
     # Can read unicode filenames
     self.c = ConfigParser()
     self.c.read(u'temp.ini')
     assert self.c._sections == goodDict, self.c._sections
     # Can read funny string object filenames
     class MyStr(str):
         """Simply overrides string to make it a different type"""
     self.c.read(MyStr('temp.ini'))
     assert self.c._sections == goodDict, self.c._sections
开发者ID:,项目名称:,代码行数:28,代码来源:

示例8: setUp

 def setUp(self):
     """
     Creates a ConfigParser to play with and
     reads in the test text
     """
     self.c = ConfigParser()
     file_ = testFile()
     self.c.read(file_)
开发者ID:,项目名称:,代码行数:8,代码来源:

示例9: testUpgradeAppDir

 def testUpgradeAppDir(self):
     """
     Tests that config files with
     'appDataDir' are upgraded to 'configDir'
     """
     # Write the old style config file
     configPath = Path(u'test.exe.conf')
     if configPath.exists():
         configPath.remove()
     oldParser = ConfigParser()
     system = oldParser.addSection('system')
     system.appDataDir = 'my old app data dir'
     oldParser.write(configPath)
     del system
     del oldParser
     # Make the config instance load it
     Config._getConfigPathOptions = lambda self: ['test.exe.conf']
     myconfig = Config()
     myconfig.loadSettings()
     # Check if it reads the old value into the new variable
     assert not hasattr(myconfig, 'appDataDir')
     self.assertEquals(myconfig.configPath, 'test.exe.conf')
     self.assertEquals(myconfig.configDir, 'my old app data dir')
     # Check if it has upgraded the file and added in some nice default values
     newParser = ConfigParser()
     newParser.read(configPath)
     self.assertEquals(newParser.system.configDir, 'my old app data dir')
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:27,代码来源:testconfig.py

示例10: check_application_for_test

 def check_application_for_test(cls):
     logFileName = Path('tmp/app data/test.conf')
     sys.argv[0] = 'exe/exe'
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     SuperTestCase.update_config_parser(confParser)
     confParser.write(logFileName)
     
     if G.application is None:
         G.application = Application()
     
         G.application.loadConfiguration()
         SuperTestCase.update_config_parser(G.application.config.configParser)
         G.application.config.loadSettings()
         
         G.application.preLaunch()
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:18,代码来源:utils.py

示例11: testUnicodeSet

 def testUnicodeSet(self):
     """
     Should be able to set unicode option values
     with both python internal unicode strings
     or raw string containing utf8 encoded data
     """
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('main', 'power', '\xc4\x80\xc4\x900')
     self.c.set('main', 'name', unicode('\xc4\x80\xc4\x900', 'utf8'))
     self.c.set('newSecy', 'unicode', unicode('\xc4\x80\xc4\x900', 'utf8'))
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     val = unicode('\xc4\x80\xc4\x900', 'utf8')
     self.assertEquals(c2.main.power, val)
     self.assertEquals(c2.main.name, val)
     self.assertEquals(c2.newSecy.unicode, val)
开发者ID:,项目名称:,代码行数:20,代码来源:

示例12: setUp

 def setUp(self):
     """
     Creates an application and 
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     self.app = Application()
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.app.webServer.root.bindNewPackage(self.package)
     self.mainpage = self.app.webServer.root.children['temp']
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:22,代码来源:utils.py

示例13: testShortening

 def testShortening(self):
     """There was a bug (Issue 66) where when a longer name was read
     and a shorter name was written, the extra characters of the 
     longer name would remain in the entry"""
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('second', 'available', 'abcdefghijklmnop')
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     c2.set('second', 'available', 'short')
     c2.write('temp.ini')
     self.c.read('temp.ini')
     assert self.c.get('second', 'available', '') == 'short', \
         self.c.get('second', 'available', '')
开发者ID:,项目名称:,代码行数:17,代码来源:

示例14: __init__

class Config:
    """
    The Config class contains the configuration information for eXe.
    """

    # Class attributes
    optionNames = {
        'system': ('webDir', 'xulDir', 'port', 'dataDir', 
                   'configDir', 'localeDir', 'browserPath', ),
        'user': ('locale', 'latexpath'),
    }

    def __init__(self):
        """
        Initialise
        """
        self.configPath = None
        self.configParser = ConfigParser(self.onWrite)
        # Set default values
        # exePath is the whole path and filename of the exe executable
        self.exePath     = Path(sys.argv[0]).abspath()
        # webDir is the parent directory for styles,scripts and templates
        self.webDir      = self.exePath.dirname()
        # xulDir is the parent directory for styles,scripts and templates
        self.xulDir      = self.exePath.dirname()
        # localeDir is the base directory where all the locales are stored
        self.localeDir   = self.exePath.dirname()/"locale"
        # port is the port the exe webserver will listen on 
        # (previous default, which earlier users might still use, was 8081)
        self.port        = 51235
        # dataDir is the default directory that is shown to the user
        # to save packages and exports in
        self.dataDir     = Path(".")
        # configDir is the dir for storing user profiles
        # and user made idevices and the config file
        self.configDir   = Path(".")
        # browserPath is the entire pathname to firefox
        self.browserPath = Path("firefox")
        # locale is the language of the user
        self.locale = chooseDefaultLocale(self.localeDir)
        # internalAnchors indicate which exe_tmp_anchor tags to generate for each tinyMCE field
        # available values = "enable_all", "disable_autotop", or "disable_all"
        self.internalAnchors = "enable_all"
        # styles is the list of style names available for loading
        self.styles      = []
        # The documents that we've recently looked at
        self.recentProjects = []
        # canonical (English) names of iDevices not to show in the iDevice pane
        self.hiddeniDevices = []
        # likewise, a canonical (English) names of iDevices not to show in the
        # iDevice pane but, contrary to the hiddens, these are ones that the 
        # configuration can specify to turn ON:
        self.deprecatediDevices = [ "flash with text", "flash movie", "mp3", \
                                    "attachment"]
        # by default, only allow embedding of media types for which a 
        # browser plugin is found:
        self.assumeMediaPlugins = False;
        # Let our children override our defaults depending
        # on the OS that we're running on
        self._overrideDefaultVals()
        # Try to make the defaults a little intelligent
        # Under devel trees, webui is the default webdir
        self.webDir = Path(self.webDir)
        if not (self.webDir/'scripts').isdir() \
           and (self.webDir/'webui').isdir():
            self.webDir /= 'webui'
        # Under devel trees, xului is the default xuldir
        self.xulDir = Path(self.xulDir)
        if not (self.xulDir/'scripts').isdir() \
           and (self.xulDir/'xului').isdir():
            self.xulDir /= 'xului'
        # Latex distribution path if environment wasn't set properly
        self.latexpath = ""
        # Find where the config file will be saved
        self.__setConfigPath()
        # Fill in any undefined config options with our defaults
        self._writeDefaultConfigFile()
        # Now we are ready to serve the application
        self.loadSettings()
        self.setupLogging()
        self.loadStyles()
        self.loadLocales()


    def _overrideDefaultVals(self):
        """
        Override this to override the
        default config values
        """

    def _getConfigPathOptions(self):
        """
        Override this to give a list of
        possible config filenames
        in order of preference
        """
        return ['exe.conf']


    def _writeDefaultConfigFile(self):
#.........这里部分代码省略.........
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:101,代码来源:config.py

示例15: Config

class Config(object):
    """
    The Config class contains the configuration information for eXe.
    """

    # To build link to git revision
    baseGitWebURL = 'https://forja.cenatic.es/plugins/scmgit/cgi-bin/gitweb.cgi?p=iteexe/iteexe.git'

    # Class attributes
    optionNames = {
        'system': ('webDir', 'jsDir', 'port', 'dataDir',
                   'configDir', 'localeDir', 'browser', 'mediaProfilePath',
                   'videoMediaConverter_ogv', 'videoMediaConverter_3gp',
                   'videoMediaConverter_mpg',
                   'videoMediaConverter_avi', 'audioMediaConverter_ogg',
                   'audioMediaConverter_au', 'audioMediaConverter_mp3',
                   'audioMediaConverter_wav', 'ffmpegPath'),
        'user': ('locale', 'lastDir', 'showPreferencesOnStart','defaultStyle', 'showIdevicesGrouped','docType','editorMode'),
    }

    idevicesCategories = {
        'activity': [x_('Non-Interactive Activities')],
        'reading activity': [x_('Non-Interactive Activities')],
        'dropdown activity': [x_('Interactive Activities')],
        'java applet': [x_('Non-Textual Information')],
        'wiki article': [x_('Non-Textual Information')],
        'case study': [x_('Non-Interactive Activities')],
        'preknowledge': [x_('Textual Information')],
        'scorm quiz': [x_('Interactive Activities')],
        'fpd - multi choice activity': [x_('FPD')],
        'fpd - cloze activity': [x_('FPD')],
        'fpd - cloze activity (modified)': [x_('FPD')],
        'fpd - multi select activity': [x_('FPD')],
        'fpd - true/false activity': [x_('FPD')],
        'fpd - situation': [x_('FPD')],
        'fpd - quotation': [x_('FPD')],
        'fpd - you should know': [x_('FPD')],
        'fpd - highlighted': [x_('FPD')],
        'fpd - translation': [x_('FPD')],
        'fpd - guidelines students': [x_('FPD')],
        'fpd - guidelines teacher': [x_('FPD')],
        'fpd - a step ahead': [x_('FPD')],
        'fpd - a piece of advice': [x_('FPD')],
        'fpd - think about it (with feedback)': [x_('FPD')],
        'fpd - think about it (without feedback)': [x_('FPD')],
        'fpd - free text': [x_('FPD')],
        'image gallery': [x_('Non-Textual Information')],
        'image magnifier': [x_('Non-Textual Information')],
        'note': [x_('Textual Information')],
        'objectives': [x_('Textual Information')],
        'multi-choice': [x_('Interactive Activities')],
        'multi-select': [x_('Interactive Activities')],
        'true-false question': [x_('Interactive Activities')],
        'reflection': [x_('Non-Interactive Activities')],
        'cloze activity': [x_('Interactive Activities')],
        'rss': [x_('Non-Textual Information')],
        'external web site': [x_('Non-Textual Information')],
        'free text': [x_('Textual Information')],
        'click in order game': [x_('Experimental')],
        'hangman game': [x_('Experimental')],
        'place the objects': [x_('Interactive Activities')],
        'memory match game': [x_('Experimental')],
        'file attachments': [x_('Non-Textual Information')],
        'sort items': [x_('Experimental')],
        'sort items': [x_('Interactive Activities')],
        'scorm test cloze': [x_('Interactive Activities')],
        'scorm test cloze (multiple options)': [x_('Interactive Activities')],
        'scorm test dropdown': [x_('Interactive Activities')],
        'scorm test multiple choice': [x_('Interactive Activities')]
    }
    
    @classmethod
    def getConfigPath(cls):
        obj = cls.__new__(cls)
        obj.configParser = ConfigParser()
        obj._overrideDefaultVals()
        obj.__setConfigPath()
        return obj.configPath

    def __init__(self):
        """
        Initialise
        """
        self.configPath = None
        self.configParser = ConfigParser(self.onWrite)
        # Set default values
        # exePath is the whole path and filename of the exe executable
        self.exePath     = Path(sys.argv[0]).abspath()
        # webDir is the parent directory for styles,scripts and templates
        self.webDir      = self.exePath.dirname()
        self.jsDir       = self.exePath.dirname()
        # localeDir is the base directory where all the locales are stored
        self.localeDir   = self.exePath.dirname()/"locale"
        # port is the port the exe webserver will listen on 
        # (previous default, which earlier users might still use, was 8081)
        self.port        = 51235
        # dataDir is the default directory that is shown to the user
        # to save packages and exports in
        self.dataDir     = Path(".")
        # configDir is the dir for storing user profiles
#.........这里部分代码省略.........
开发者ID:kohnle-lernmodule,项目名称:exe201based,代码行数:101,代码来源:config.py


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