0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python 掲示板 などの参考資料

Last updated at Posted at 2023-12-06

一応、まとめて記録として。
pyton は起動時に-X utf8 を付けると使えるようになるから

#!C:/Python3/python_3_12_0_embed_amd64/python -X utf8
# coding=utf-8

print ('Content-type:text/html'+'\n'+'\n')
print ('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"><title>pyton_v3</title></head><BODY BGCOLOR="#ffffff"><h1>test decoder3</h1>'+'\n')
print ('<p>日本語を話せる、システムです。「This is a system that allows you to speak Japanese.」<br>\n')
print ('カンニングペーパー「コピペオンライン英和翻訳 『Multilingal Online Translation』」はMicrosoftストアーで。<br>\n')
print ('The cheat sheet \"Copy and Paste Online English-Japanese Translation 『Multilingal Online Translation』\" is available at the Microsoft Store.<br>\n')
print ('ブラウザ、拡張機能もお忘れなく。わからない時は、質問AIですよ。「Don\'t forget your browser and extensions. When you don\'t understand, there is a question AI.」</p><br>\n')

# import re

# mydisp = re.sub(r'\x','%', 'abcIt let1def<br>\n')
# print (mydisp)
#decode()
#def decode():
my_hash = {}
my_hash['name'] = ''
my_hash['subm'] = ''
my_hash['comment'] = ''
my_hash['url'] = ''


in_d = {}
in_d['apple'] = '100'
in_d['banana'] = '150'
in_d['cherry'] = '200'
print ('it let2<br>\n')
print ('aplle to '+in_d['apple']+'yen<br>\n')
in_d['apple'] = '110'
print ('pey applo to '+in_d['apple']+'yen<br>\n')

#return
import os
import re
import sys

req_met = os.environ.get('REQUEST_METHOD')
print ('it let2_1<br>\n')
if req_met == 'POST' : 
    for query in sys.stdin:
        os.environ.get('CONTENT_LENGTH')
        pass

else :
    query = os.environ.get('QUERY_STRING')
    
if len(query) > 10 :
    language = len(query)
    print (f'largebyte: 10 {language}<br>\n') #test message after get out;F(x)Qestit??

print ('it let2_2<br>\n')

print (query+' buf <br>\n')

buf_arrey = query.split("&")

print (buf_arrey)
print ('<br>\n')
print ('it let2_3<br>\n')
separator = '<br>'
#tmp_arrey = separator.join(buf_arrey)
#print (tmp_arrey)
#print ('<br>\n')





n_n = 0
print ('it let2_4<br>\n')
if "" not in buf_arrey :
    for my_buf in buf_arrey :
        print (f'{n_n}kai<br>\n')
        (key0, value0) = my_buf.split("=")
        if "%" in key0 :
            my_key = key0
        #    pass
    
        #    def replace_hex_k(key0):
        #        return re.sub(r'%([0-9a-fA-F][0-9a-fA-F])', lambda x: bytes.fromhex(x.group(1)).decode('utf-8'), key0)
        #    my_key = replace_hex_k
        else :
            my_key = key0
    
        if "%" in value0 :
            my_val = 'In English, please'
        #    pass
    
        #    def replace_hex_v(value0):
        #        return re.sub(r'%([0-9a-fA-F][0-9a-fA-F])', lambda x: bytes.fromhex(x.group(1)).decode('utf-8'), value0)
        #    my_val = replace_hex_v
        else :
            my_val = value0
        
        #I can't get around to it, so I'll try putting it out.
        my_hash[my_key] = my_val
        n_n += 1
        print (f'key={my_key} value={my_val}<br>\n')
    
   
key_list0 = list(my_hash.keys())
print(key_list0)
print ('<br>\n')
for i, val0 in enumerate(key_list0):
    if i == len(key_list0) - 1:
        print('last: '+val0+' '+my_hash[val0]+'<br>\n')
    else:
        print('middle '+val0+' '+my_hash[val0]+'<br>\n')


# def validate_buf(query):
#    pattern = r"\x"

#    if len(query) != len(re.findall(pattern, query)):
#        print('buf is \\x include.<br>\n')

print ('it let2_5<br>\n')

#form()


#def form():
print ('it let3<br>\n')


print ('<form action=\"http://127.0.0.1/my_python/python_test3.cgi\" method=\"POST\">\n')
print ('<table border=0 cellspacing=1>\n')
#in_d['name'] = ''
print ('<tr><td><b>name</b></td><td><input type=text name=name size=28 value=\"'+my_hash['name']+'\" maxlength=\"12\" class=f></td></tr>\n')
#in_d['subm'] = ''
print ('<tr><td><b>submit</b></td><td><input type=text name=subm size=36 value=\"'+my_hash['subm']+'\" maxlength=\"36\"class=f></td></tr>'+'\n')
#in_d['comment'] = ''
print ('<tr><td colspan=2><b>comment</b><br><textarea cols=70 rows=7 name=comment wrap=\"soft\" class=f>'+my_hash['comment']+'</textarea></td></tr>'+'\n')
#in_d['url'] = ''
print ('<tr><td><b>url</b></td><td><input type=text size=52 name=url value=\"'+my_hash['url']+'\" maxlength=\"60\" class=f></td></tr>'+'\n')

print ('<tr><td><input type=submit value=\"submit\"></td><td><input type=reset value=\"reset\"></td></tr>\n')
print ('</form></table><br>\n')
come = ''
print ('name='+in_d['name']+'<br>'+come+'<br>It OK?<br>\n')

#return

#
key_list = list(in_d.keys())
print(key_list)
print ('<br>\n')
for i, val in enumerate(key_list):
    if i == len(key_list) - 1:
        print('last: '+val+' '+in_d[val]+'<br>\n')
    else:
        print('middle '+val+' '+in_d[val]+'<br>\n')

print ('<br><a href="python_html.html">index</a><br>\n')   
print ('</body></html>\n')
exit()

参考動画
Animation_python5.gif
サンプルコードです
動く範囲内において。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?