本文整理汇总了Python中iniparse.RawConfigParser.readfp方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.readfp方法的具体用法?Python RawConfigParser.readfp怎么用?Python RawConfigParser.readfp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iniparse.RawConfigParser
的用法示例。
在下文中一共展示了RawConfigParser.readfp方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import readfp [as 别名]
#.........这里部分代码省略.........
if not self.get('outdir') or not isdir(self.get('outdir')):
buf = ctypes.create_unicode_buffer(MAX_PATH)
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PERSONAL, 0)
self.set('outdir', buf.value)
def get(self, key):
typ = DWORD()
size = DWORD()
if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), None, ctypes.byref(size)) or typ.value != REG_SZ:
return None
buf = ctypes.create_unicode_buffer(size.value / 2)
if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), buf, ctypes.byref(size)):
return None
else:
return buf.value
def getint(self, key):
typ = DWORD()
size = DWORD(4)
val = DWORD()
if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), ctypes.byref(val), ctypes.byref(size)) or typ.value != REG_DWORD:
return 0
else:
return val.value
def set(self, key, val):
if isinstance(val, basestring):
buf = ctypes.create_unicode_buffer(val)
RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2)
elif isinstance(val, numbers.Integral):
RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4)
else:
raise NotImplementedError()
def save(self):
pass # Redundant since registry keys are written immediately
def close(self):
RegCloseKey(self.hkey)
self.hkey = None
elif platform=='linux2':
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.plugin_dir = join(self.app_dir, 'plugins')
if not isdir(self.plugin_dir):
mkdir(self.plugin_dir)
self.home = expanduser('~')
self.respath = dirname(__file__)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, 'r', 'utf-8'))
except:
self.config.add_section('config')
if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', expanduser('~'))
def set(self, key, val):
assert isinstance(val, basestring) or isinstance(val, numbers.Integral), type(val)
self.config.set('config', key, val)
def get(self, key):
try:
return self.config.get('config', key) # all values are stored as strings
except:
return None
def getint(self, key):
try:
return int(self.config.get('config', key)) # all values are stored as strings
except:
return 0
def save(self):
h = codecs.open(self.filename, 'w', 'utf-8')
h.write(unicode(self.config.data))
h.close()
def close(self):
self.save()
self.config = None
else: # ???
def __init__(self):
raise NotImplementedError('Implement me')
示例2: __init__
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import readfp [as 别名]
#.........这里部分代码省略.........
return 0
else:
return val.value
def set(self, key, val):
if isinstance(val, basestring):
buf = ctypes.create_unicode_buffer(val)
RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2)
elif isinstance(val, numbers.Integral):
RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4)
elif hasattr(val, '__iter__'): # iterable
stringval = u'\x00'.join([unicode(x) or u' ' for x in val] + [u'']) # null terminated non-empty strings
buf = ctypes.create_unicode_buffer(stringval)
RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2)
else:
raise NotImplementedError()
def delete(self, key):
RegDeleteValue(self.hkey, key)
def save(self):
pass # Redundant since registry keys are written immediately
def close(self):
RegCloseKey(self.hkey)
self.hkey = None
elif platform=='linux2':
SECTION = 'config'
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.plugin_dir = join(self.app_dir, 'plugins')
if not isdir(self.plugin_dir):
mkdir(self.plugin_dir)
self.default_journal_dir = None
self.home = expanduser('~')
self.respath = dirname(__file__)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, 'r', 'utf-8'))
except:
self.config.add_section(self.SECTION)
if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', expanduser('~'))
def get(self, key):
try:
val = self.config.get(self.SECTION, key)
if u'\n' in val:
return val.split(u'\n')
else:
return val
except:
return None
def getint(self, key):
try:
return self.config.getint(self.SECTION, key)
except:
return 0
def set(self, key, val):
if isinstance(val, basestring) or isinstance(val, numbers.Integral):
self.config.set(self.SECTION, key, val)
elif hasattr(val, '__iter__'): # iterable
self.config.set(self.SECTION, key, u'\n'.join([unicode(x) for x in val]))
else:
raise NotImplementedError()
def delete(self, key):
self.config.remove_option(self.SECTION, key)
def save(self):
with codecs.open(self.filename, 'w', 'utf-8') as h:
h.write(unicode(self.config.data))
def close(self):
self.save()
self.config = None
else: # ???
def __init__(self):
raise NotImplementedError('Implement me')
示例3: __init__
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import readfp [as 别名]
#.........这里部分代码省略.........
0,
KEY_ALL_ACCESS,
None,
ctypes.byref(sparklekey),
ctypes.byref(disposition),
):
if disposition.value == REG_CREATED_NEW_KEY:
buf = ctypes.create_unicode_buffer("1")
RegSetValueEx(sparklekey, "CheckForUpdates", 0, 1, buf, len(buf) * 2)
buf = ctypes.create_unicode_buffer(unicode(47 * 60 * 60))
RegSetValueEx(sparklekey, "UpdateInterval", 0, 1, buf, len(buf) * 2)
RegCloseKey(sparklekey)
if not self.get("outdir") or not isdir(self.get("outdir")):
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PERSONAL, 0)
self.set("outdir", buf.value)
def get(self, key):
typ = DWORD()
size = DWORD()
if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), None, ctypes.byref(size)) or typ.value != REG_SZ:
return None
buf = ctypes.create_unicode_buffer(size.value / 2)
if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), buf, ctypes.byref(size)):
return None
else:
return buf.value
def getint(self, key):
typ = DWORD()
size = DWORD(4)
val = DWORD()
if (
RegQueryValueEx(self.hkey, key, 0, ctypes.byref(typ), ctypes.byref(val), ctypes.byref(size))
or typ.value != REG_DWORD
):
return 0
else:
return val.value
def set(self, key, val):
if isinstance(val, basestring):
buf = ctypes.create_unicode_buffer(val)
RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf) * 2)
elif isinstance(val, numbers.Integral):
RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4)
else:
raise NotImplementedError()
def close(self):
RegCloseKey(self.hkey)
self.hkey = None
elif platform == "linux2":
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv("XDG_DATA_HOME", expanduser("~/.local/share")), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.filename = join(getenv("XDG_CONFIG_HOME", expanduser("~/.config")), appname, "%s.ini" % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, "r", "utf-8"))
except:
self.config.add_section("config")
if not self.get("outdir") or not isdir(self.get("outdir")):
self.set("outdir", expanduser("~"))
def set(self, key, val):
self.config.set("config", key, val)
def get(self, key):
try:
return self.config.get("config", key) # all values are stored as strings
except:
return None
def getint(self, key):
try:
return int(self.config.get("config", key)) # all values are stored as strings
except:
return 0
def close(self):
h = codecs.open(self.filename, "w", "utf-8")
h.write(unicode(self.config.data))
h.close()
self.config = None
else: # ???
def __init__(self):
raise NotImplementedError("Implement me")
示例4: __init__
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import readfp [as 别名]
class Config:
OUT_EDDN = 1
OUT_BPC = 2
OUT_TD = 4
OUT_CSV = 8
if platform=='darwin':
def __init__(self):
self.app_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname)
if not isdir(self.app_dir):
mkdir(self.app_dir)
self.bundle = getattr(sys, 'frozen', False) and NSBundle.mainBundle().bundleIdentifier() or 'uk.org.marginal.%s' % appname.lower() # Don't use Python's settings if interactive
self.defaults = NSUserDefaults.standardUserDefaults()
settings = self.defaults.persistentDomainForName_(self.bundle) or {}
self.settings = dict(settings)
# Check out_dir exists
if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0])
def get(self, key):
return self.settings.get(key)
def getint(self, key):
try:
return int(self.settings.get(key, 0)) # should already be int, but check by casting
except:
return 0
def set(self, key, val):
self.settings[key] = val
def close(self):
self.defaults.setPersistentDomain_forName_(self.settings, self.bundle)
self.defaults.synchronize()
self.defaults = None
elif platform=='win32':
def __init__(self):
CSIDL_PERSONAL = 0x0005
CSIDL_LOCAL_APPDATA = 0x001C
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_LOCAL_APPDATA, 0)
self.app_dir = join(buf.value, appname)
if not isdir(self.app_dir):
mkdir(self.app_dir)
self.handle = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, r'Software\%s' % appname)
if not self.get('outdir') or not isdir(self.get('outdir')):
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PERSONAL, 0)
self.set('outdir', buf.value)
def get(self, key):
try:
return _winreg.QueryValueEx(self.handle, key)[0]
except:
return None
def getint(self, key):
try:
return int(_winreg.QueryValueEx(self.handle, key)[0]) # should already be int, but check by casting
except:
return 0
def set(self, key, val):
if isinstance(val, basestring):
_winreg.SetValueEx(self.handle, key, 0, _winreg.REG_SZ, val)
elif isinstance(val, numbers.Integral):
_winreg.SetValueEx(self.handle, key, 0, _winreg.REG_DWORD, val)
else:
raise NotImplementedError()
def close(self):
_winreg.CloseKey(self.handle)
self.handle = None
elif platform=='linux2':
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, 'r', 'utf-8'))
# XXX handle missing?
except:
self.config.add_section('DEFAULT')
#.........这里部分代码省略.........