Home > Life > uuidを取得するCGI

uuidを取得するCGI

大量のユニークIDが必要が必要になったときに。RFC 4122で定義されたUUIDを返すCGI。単にPython2.5のuuidモジュールを使っているだけでね。uuid.uuid4()の戻り値です。これでダブらないフシギ。

受け取るパラメータは、count=件数のみ。countは最大1000まで。

戻りは改行で区切られたテキスト。

例)

ローカル環境で動かせばなんてことないけれど、何かあったときのバックアップ用にでも。

#!/usr/bin/env python2.5
import cgi,uuid
__MAX_COUNT=1000
print "Content-type: text/plain\n"
try:
    form = cgi.FieldStorage()
    try:
        count = int(form.getfirst("count",1))
        if count>__MAX_COUNT: count=__MAX_COUNT
    except:
        count = 1
    for i in range(count): print uuid.uuid4()
except Exception,msg:
    print "error occured"

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://www.fabrice.co.jp/blog/archives/404/trackback
Listed below are links to weblogs that reference
uuidを取得するCGI from Fabrice Co. weblog

Home > Life > uuidを取得するCGI

Return to page top