�yFirebird�z�X�֔ԍ���DB�̍쐬(3) conf_section_items in mire.std (original) (raw)
�@�X�֔ԍ���DB�̍쐬���s�Ȃ��u./dl_ZipCodeJp.py�v�ł�14�s�ڂŁufrom mire.std import conf_section_items�v�Ƃ��āA���̗l�Ȋ���import���Ă���B�{�e�ł́A���̊���悸�͐������悤�B
�@�g�����́A__doc__ ����Sample�t�ŏ����Ă���̂ŁA��������������������B���̊����̂�Python�̕W�����W���[���uConfigParser�v��P���Ƀ��b�v���������̂��̂ŁA�ߋ�Windows���ł悭�p�����Ă����u�`.ini�v�`���̃t�@�C����ǂ݁A���̎w��Z�N�V�����̒l�������`���œn������������㕨�ł���B�C���I�ɂ́Ahttpd.conf��xml�`���A���邢�͏�����DB�őΏ��������C�������邪�A�抸��������Ƃ葁���ݒ�l�ƃX�N���v�g���o����̂ō���͍̗p�����B
INI�n�ݒ�t�@�C���̎w��Z�N�V�������̐ݒ���e�������ŕԂ�
def conf_section_items(file_name, section, debug=0):
"""
##########################################################################################
#INI�n�ݒ�t�@�C���̎w��Z�N�V�������̐ݒ���e�������ŕԂ� #
#2010-04-20 #
# #
#USAGE: #
# #
#/usr/local/etc/configure.ini: #
# [SECTION NAME1] #
# item1 = value1 #
# item2 = valie2 #
# [SECTION NAME2] #
# item1 = value3 #
# item2 = valie4 #
# #
#Sample.py: #
# from mire.std import conf_section_items #
# file_name = '/usr/local/etc/configure.ini' #
# section = 'SECTION NAME' #
# items = conf_sections(file_name=file_name, section=section) #
# print items #
# #
#$ python Sample.py #
# {"item1":"value1", "items2":"value2"} #
#$ #
##########################################################################################
"""
import ConfigParser
conf = ConfigParser.SafeConfigParser()
conf.read(file_name)
try:
items = conf.items(section)
item_dic = {}
if len(items)>0: #�v�f����������A�����������
for item in items:
item_dic[item[0]] = item[1]
return item_dic #�v�f���Ȃ��Ȃ�A{}��Ԃ����ƂɂȂ�
except:
if debug>0:
display_err(locals(),title='Error! conf_section_items()')
print conf
else:
print 'Please, Contact Your System Administrator.'
raise
�@�ȉ��ɁA�����_�ł�mire.std�̃\�[�X���f�ڂ��Ă����B
#!c:/Python26/python
-- coding: UTF8 --
�� Windows �̏ꍇ1�s�ڂ�dummy�ł��B
u"""
######################################################################
#�W�����o�͊W�̊��Q
01. str2unicode(s,charset) :�������unicode�������݂܂�
02. file2utf8list(file_name :file��Ǎ���unicode��list��Ԃ��܂�
,stdin_charset) :
03. display_err(local,title) :��O�G���[���
04. dsp_hex(s) :��O�����ӏ��R�����g�̕��������h�~�p
05. conf_section_items(file_name :INI�n�ݒ�t�@�C���̎w��Z�N�V������
,section):�̐ݒ���e�������ŕԂ�
"""
author = "Mire in Japan"
version = '0.0.1'
copyright = 'Copyright (c) 2009-2010 Mire'
license = 'GPL'
url = 'http://pythonlife.seesaa.net/article/148099776.html'
�������unicode�������݂܂�
def str2unicode(s,charset='UTF-8',charsets=['Shift_JIS','EUC-JP','iso-2022-jp','UTF-8'],debug=0):
u"""
�������unicode�������݂܂�
"""
charsets.insert(0, charset)
for c in charsets:
try:
u = u'%s' % (unicode(s,c))
if debug>0 and not c==charset:
print u'�w���charset"%s"�łȂ�"%s"��unicode�����܂����B'
return u
except:
if debug>1: print u'�������%s�ł̋L�q�ł͂���܂���' % (c)
pass
if debug>0:
print u'charset���̉�����Y�����Ȃ��ו���������̂܂ܕԂ��܂���'
print u'��������ɈقȂ�charset�����݂��Ă���\�����^���ĉ�����'
print u'���݂̏ꍇ��ascii�����ȊO�̃u���b�N��T���ČʂɑΉ��ł�'
return s
file�̓Ǎ���codecs���g��unicode��list��Ԃ��܂�
def file2utf8list(file_name,stdin_charset,stdout_charset):
u"""
file�̓Ǎ���codecs���g��unicode��list��Ԃ��܂�
"""
from sys import stdin,stdout
from codecs import getwriter,getreader,open
stdout = getwriter(stdout_charset)(stdout) #�v��Ȃ��C������
stdin = getreader(stdin_charset)(stdin) #�v��Ȃ��C������
fpi=open(file_name,'r',stdin_charset)
lines=fpi.readlines()
fpi.close()
return lines
def utf8list2file(file_name,stdin_charset):
u"""
comming later. :-)
"""
pass
waiting = 0 # �@�����display_err() ���s����WAIT��u���A
# thread���s���̃G���[���\���̎��n����
# �h���ׂ�global�ϐ�
�G���[�\����(�R�����g�s����������+thread���s���̃G���[���\���̎��n���y��)
def display_err(local, title = u'\n\n#### EXCEPTION ERROR ####'):
"""
##########################################################################################
#�G���[�\����(�R�����g�s���������� + thread���s���̃G���[���\���̎��n���y��) #
#USAGE: �������Ɂulocals()�v���w�肷�邱�ƂŁA�������̕ϐ��l��\�����܂��B #
# waiting��thread���s���̃G���[���\���̎��n���y���ׂ̈�WAIT�����ł��B #
# waiting = 0 #
# def foo(): #
# global waiting #
# sleep(waiting) #
# try: #
# ���� #
# waiting = 0 #
# except: #
# display_err(locals(),'<��O�����̏ꏊ��\���^�C�g��>')# locals()�w��͕K�{ #
# waiting = 1 #
# foo() #
##########################################################################################
"""
import traceback
from time import sleep
if local is None:
local =locals()
global waiting
frame0 = u'\n*******************************************************************************'
frame1 = u'******************************************************************************\n\n'
errs = [frame0, title]
errs.append(u'%s' % (dsp_hex(traceback.format_exc()))) #> dsp_hex(s): �R�����g����������
sleep(waiting)
ls = local
keys = ls.keys()
keys.sort()
errs.append(u'')
for key in keys: # display_err()�W�̕ϐ��̕\�����Ȃ�
# if not key in ['v', 'ls', 'keys', 'key', 'errs', 'txt', 'er', 'sleep']:
er = u' %s: %s' % (repr(key).ljust(24),repr(ls[key]))
errs.append(er)
errs.append(frame1)
txt = u'\n'.join(errs)
print txt
�R�����g����������
def dsp_hex(s):
from re import search
charsets=['UTF-8','Shift_JIS','EUC-JP'] # �ǂ�ł������̂ŁAcharset�ŁA
for charset in charsets: # unicode�����A�R�����g������
try: # ����������h��
return unicode(s,charset)
except:
print u'%s�ł͕ϊ��s�\�ł���' % (charset)
pass
sss=u''
for ss in s: # �z��O��charset�̂Ƃ���16�i���\�L��
if (ord(ss)>=32 and ord(ss)<=126) or ss.isspace(): # Windows�ɂ�curses.ascii.isprint()��
sss=sss+ss # �Ȃ��̂�curses/ascii.py�̒��g��W�J
else:
sss=sss+'\'+hex(ord(ss))[2:].upper()
return sss
INI�n�ݒ�t�@�C���̎w��Z�N�V�������̐ݒ���e�������ŕԂ�
def conf_section_items(file_name, section, debug=0):
"""
##########################################################################################
#INI�n�ݒ�t�@�C���̎w��Z�N�V�������̐ݒ���e�������ŕԂ� #
#2010-04-20 #
# #
#USAGE: #
# #
#/usr/local/etc/configure.ini: #
# [SECTION NAME1] #
# item1 = value1 #
# item2 = valie2 #
# [SECTION NAME2] #
# item1 = value3 #
# item2 = valie4 #
# #
#Sample.py: #
# from mire.std import conf_section_items #
# file_name = '/usr/local/etc/configure.ini' #
# section = 'SECTION NAME' #
# items = conf_sections(file_name=file_name, section=section) #
# print items #
# #
#$ python Sample.py #
# {"item1":"value1", "items2":"value2"} #
#$ #
##########################################################################################
"""
import ConfigParser
conf = ConfigParser.SafeConfigParser()
conf.read(file_name)
try:
items = conf.items(section)
item_dic = {}
if len(items)>0: #�v�f����������A�����������
for item in items:
item_dic[item[0]] = item[1]
return item_dic #�v�f���Ȃ��Ȃ�A{}��Ԃ����ƂɂȂ�
except:
if debug>0:
display_err(locals(),title='Error! conf_section_items()')
print conf
else:
print 'Please, Contact Your System Administrator.'
raise
def str_diff(a, b):
mx = max(len(a), len(b), length=80)
ov = 0
r0 = ''
r1 = ''
r2 = ''
h = ''
for c in range(length):
h = h + '%d' % (c-c/10*10)
for c in range(mx):
try:
a0 = a[c]
except:
a0 = ' '
ov = 1
try:
b0 = b[c]
except:
b0 = ' '
ov = 1
if ov==0:
if a0==b0:
r0 = r0 + 'o'
else:
r0 = r0 + 'x'
r1 = r1 + a0
r2 = r2 + b0
ns = int((mx+length)/length)
#for n in ns:
print r0
print r1
print r2
if name == 'main': # ���ڎ��s���݈̂ȉ������s
import mire.std
help(mire.std)
�@���Amire.fd, mire.std����mire�Q���̃��W���[���Ƃ��ė��p����ɂ́Asite-packages����mire�f�B���N�g�������Afd.py, std.py��[�߂�Ƌ��ɁA����__init__.py������Ē������Ƃœ����Ɠ������ɂȂ�Bpath�𑵂��Ahelp()�@�\���g���ꍇ�ɂ͂�������Ɨǂ����낤�B�A���APython2.x��help()�͊�{�I��ASCII�����ɂ����Ή����Ă��Ȃ������Ȃ̂ŁAOS���̕����R�[�h�Ɠ���̃\�[�X�R�[�h�łȂ��Ɠ��{��͕����������邱�ƂɂȂ�̂ŁAUTF8�œ��ꗘ�p�������Ȃ�Linux�ɓ���teraterm�ӂ�ő��삵�ė~�����B
#!c:/Python26/python
-- coding: UTF8 --
�� Windows �̏ꍇ1�s�ڂ�dummy�ł�
doc = u"""
######################################################################
mire module
######################################################################
std :�W�����o��+��O����
htm :HTML���Q
html :HTML�N���X
fb :Firebird SQL/Interbase��
user_mng:���[�U�Ǘ�
"""
from sys import version
if version[0]=='2':
import std
doc=doc+'\n'+std.name+std.doc
import htm
doc=doc+'\n'+htm.name+htm.doc
import html
doc=doc+'\n'+html.name+html.doc
import net
doc=doc+'\n'+net.name+net.doc
import fb
doc=doc+'\n'+fb.name+fb.doc
import user_mng
doc=doc+'\n'+user_mng.name+user_mng.doc
elif version[0]=='3': # python3�p. �S�Ė��쐬�ł�
import std3 as std
doc=doc+'\n'+std.name+std.doc
import htm3 as htm
doc=doc+'\n'+htm.name+htm.doc
import html3 as html
doc=doc+'\n'+html.name+html.doc
import net3 as net
doc=doc+'\n'+net.name+net.doc
import fb3 as fb
doc=doc+'\n'+fb.name+fb.doc
else:
pass
�@���āA���e�ł́A�ȒP�ȗX�֔ԍ��댟���t�H�[�����f�ڂ��ADB�ɕ��������Ȃ��f�[�^�o�^����o�͏o���邱�Ƃ��m�F����B
| |
|
| ------------------------------------------------------------------------------------- |
�yFIREBIRD �֘A���e�z
- SQL RDBMS FIREBIRD��b ������ (��)
- SQL RDBMS FIREBIRD�ƃf�[�g ���ʗ�����
- SQL RDBMS FIREBIRD��2.5�Ŏn�߂悤 +�ڑ���Q�ؕ���
- Firebird-2.5.0.RC2 ��Install
- �yCentOS�zFirebird-2.5.0.RC2 ��Superclassic�N����
- �yFirebird�zDB/TABLE�쐬�pPython���W���[��
- �yFirebird�zDB/TABLE�쐬�pPython���W���[��2
- �yFirebird�z�X�֔ԍ���DB�̍쐬 ./dl_ZipCodeJp.py
- �yFirebird�z�X�֔ԍ���DB�̍쐬(2) ���p���W���[�� mire.fb
- �yFirebird�z�X�֔ԍ���DB�̍쐬(3) conf_section_items in mire.std
- �yFirebird�z�X�֔ԍ���DB�̍쐬(4) �����t�H�[���Ŋm�F
- �yFirebird�z�X�֔ԍ���DB�̍쐬(5) mire.htm �� str_input_form()