ports/173195: Tools/scripts/getpatch: fix runtime in a case when patch contains non-ascii chars

Ruslan Mahmatkhanov rm at FreeBSD.org
Mon Oct 29 18:30:01 UTC 2012


>Number:         173195
>Category:       ports
>Synopsis:       Tools/scripts/getpatch: fix runtime in a case when patch contains non-ascii chars
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 29 18:30:01 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Ruslan Mahmatkhanov
>Release:        10.0-CURRENT
>Organization:
>Environment:
10.0-CURRENT amd64
>Description:
Sofian (sbz, author of this script) is already aware of it. I filing this pr to make sure it will not lost. 

Example session:
"""
# /usr/ports/Tools/scripts/getpatch ports/172280
[+] Fetching patch for pr ports/172280
Traceback (most recent call last):
  File "/usr/ports/Tools/scripts/getpatch", line 192, in <module>
    main()
  File "/usr/ports/Tools/scripts/getpatch", line 189, in main
    gp.get(only_last=args.last, output_stdout=args.stdout)
  File "/usr/ports/Tools/scripts/getpatch", line 84, in get
    self.write(p, data)
  File "/usr/ports/Tools/scripts/getpatch", line 60, in write
    f.write(data.decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 99: ordinal not in range(128) 
"""

Attached patch fixing the issue.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- getpatch.orig	2012-10-16 15:13:36.000000000 +0400
+++ getpatch	2012-10-16 15:23:31.000000000 +0400
@@ -29,6 +29,7 @@
 # MAINTAINER=   sbz at FreeBSD.org
 
 import argparse
+import codecs
 import re
 import sys
 if sys.version_info.major == 3:
@@ -56,8 +57,8 @@
     def write(self, filename, data):
         if filename.endswith(('.patch', '.txt')):
             filename = filename[:filename.rindex('.')]+'.diff'
-        f=open(filename, 'w')
-        f.write(data.decode())
+        f = codecs.open(filename, encoding='utf-8', mode='w')
+        f.write(data.decode('utf-8'))
         f.close()
         self.out("[+] %s created" % filename)
 


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-ports-bugs mailing list