zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Python3.9的http.client.py下的HTTPMessage类中的方法getallmatchingheaders的bug修复建议详解编程语言

BUGPython3.9方法HTTP编程语言 详解 修复 建议
2023-06-13 09:11:52 时间

在官方网站已经提交相关issue,不过目前看好像还没有修复。具体的bug位置为:

http文件夹下的client.py文件,代码位置为:类HTTPMessage下的方法getallmatchingheaders

源代码如下:

 def getallmatchingheaders(self, name): 

 """Find all header lines matching a given header name. 

 Look through the list of headers and find all lines matching a given 

 header name (and their continuation lines). A list of the lines is 

 returned, without interpretation. If the header does not occur, an 

 empty list is returned. If the header occurs multiple times, all 

 occurrences are returned. Case is not important in the header name. 

 """ 

 name = name.lower() + : 

 n = len(name) 

 lst = [] 

 hit = 0 

 for line in self.keys(): 

 if line[:n].lower() == name: 

 hit = 1 

 elif not line[:1].isspace(): 

 hit = 0 

 if hit: 

 lst.append(line) 

 return lst 

修改后代码如下:

 1 def getallmatchingheaders(self, name): 

 2 """Find all header lines matching a given header name. 

 4 Look through the list of headers and find all lines matching a given 

 5 header name (and their continuation lines). A list of the lines is 

 6 returned, without interpretation. If the header does not occur, an 

 7 empty list is returned. If the header occurs multiple times, all 

 8 occurrences are returned. Case is not important in the header name. 

10 """ 

11 name = name.lower() 

12 n = len(name) 

13 lst = [] 

14 hit = 0 

15 for line,value in self.items(): 

16 if line[:n].lower() == name: 

17 hit = 1 

18 elif not line[:1].isspace(): 

19 hit = 0 

20 if hit: 

21 lst.append(line+:+value) 

22 return lst

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19728.html

cjavapython