批量打標籤 在合約函式自動插入內容,使結果可編譯

2021-10-03 19:58:03 字數 2249 閱讀 8807

import random

import os

from solc import compile_files,compile_source,link_code

msg = [

"""for (i = 0; i < size -1; i++)}}

""",

"""bool bswaped = true;

for (i= 0; i< size -1; i++)

}if (!bswaped)

break;

} """,

"""for (i = 0; i < size - 1; i++)

}break;

}"""]

# function 起始位置

newlist=

# contract 起始位置

newlistbegin=

# contract 終止位置

newlistend=

# txt內容暫存

lines=

def insertcontent():

if newlist!=:

# 在function後插入變數

lines.insert(newlist[0] + 1, """

uint memory a = new uint(8);

uint size=a.length;

for(uint i=0;i= 2:

# 乙個合約的迴圈

for q in range(newlistbegin[l]+1,newlistend[l]-1):

# 有可插入函式

if q< len(lines) and len(lines)!=0:

if lines[q].find('function') != -1 and lines[q].find(';') == -1:

# 直到找到"{"

while lines[q].find("{") == -1 and q < len(lines)-1:

q = q + 1

if q < len(lines):

# 無可插入函式

else:

# 遍歷完該合約

if q == len(newlistbegin) - 1:

break

# 遍歷完全部合約

if l==len(newlistbegin)-1:

break

# 清空合約內容

newlistbegin.clear()

newlistend.clear()

# 插入內容

insertcontent()

# 開啟檔案,將lines內容寫入,關閉檔案

file1 = open(dire, "w", encoding="utf-8")

file1.write("".join(lines))

file1.close()

# 開啟檔案獲取檔案內容,關閉檔案

file1 = open(dire, "r", encoding="utf-8")

lines = [dire for dire in file1]

file1.close()

# 對檔案內容進行編譯,編譯失敗的檔案被命名為error

context = "".join(lines)

try:

test = compile_source(context)

# 編譯成功的話,清空存放contract和function的資料

newlist.clear()

newlistbegin.clear()

newlistend.clear()

except exception as e:

# 清空存放內容的陣列

lines.clear()

# **復原

for p in range(len(lines)):

# 將不可以插入的function 位置刪除

if len(newlist)!=0:

del newlist[0]

insertcontent()

else:

# 全部插入失敗後輸出錯誤

print("error==>", e)

# 更改失敗**的檔案名字

new = "d:/py**/未完成/" + 'error' + i

os.rename(dire, new)

continue

print("finish!")

autoplay標籤在chrome中失效的問題

此時,肯定是需要js 來實現,其實在這裡用 實現也就一行 而已 document.queryselector music play 運氣好,就直接成功了,想手動暫停 可以使用下面的一行 document.queryselector music muted true 詳細細節場景可以參看前端五子棋 但...

iframe標籤在PC端的使用

隨著前端框架的崛起 各種元件化 模組化開發 然而我發現在pc端要考慮相容 自己琢磨著 在pc端怎麼吧乙個頁面做成乙個公共的部分 發現有個iframe標籤可以在頁面中巢狀 用法就是這麼簡單 需要乙個需要乙個src頁面位址 frameborder設定iframe邊框為空 scrolling清除滾動條 我...

mybatis中標籤在Mysql中的使用

mybatis中標籤在 mysql 中的使用 foreach屬性 屬性描述 item 迴圈體中的具體物件。支援屬性的點路徑訪問,如item.age,item.info.details。具體說明 在list和陣列中是其中的物件,在map中是value。該引數為必選。collection 要做forea...