Skip to content

Commit

Permalink
Merge pull request #129 from tk0miya/dont_hack_codecs.getreader
Browse files Browse the repository at this point in the history
Fix #126: '_io.BufferedRandom' object has no attribute 'buffer'
  • Loading branch information
tk0miya committed Feb 1, 2020
2 parents 4eeaab3 + 14893db commit 3daa472
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

2.0.0 (unreleased)
------------------
* Fix a bug

- Fix #126: '_io.BufferedRandom' object has no attribute 'buffer'

2.0.0 (2020-01-26)
------------------
* Drop python2 and python3.4 support
Expand Down
7 changes: 4 additions & 3 deletions src/blockdiag/utils/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import codecs
import os
import re
import sys
Expand All @@ -21,7 +22,6 @@

from blockdiag import imagedraw, plugins
from blockdiag.utils import images
from blockdiag.utils.compat import codecs
from blockdiag.utils.config import ConfigParser
from blockdiag.utils.fontmap import FontMap, parse_fontpath
from blockdiag.utils.logging import error, warning
Expand Down Expand Up @@ -78,8 +78,9 @@ def setup(self):

def parse_diagram(self):
if self.options.input == '-':
stream = codecs.getreader('utf-8-sig')(sys.stdin)
self.code = stream.read()
self.code = sys.stdin.read()
if self.code.startswith('\ufeff'): # strip BOM
self.code = self.code[1:]
else:
fp = codecs.open(self.options.input, 'r', 'utf-8-sig')
self.code = fp.read()
Expand Down
12 changes: 0 additions & 12 deletions src/blockdiag/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import codecs
import sys

# replace codecs.getreader
if sys.version_info[0] == 3:
getreader = codecs.getreader

def py3_getreader(encoding):
return lambda stream, *args: getreader(encoding)(stream.buffer, *args)

codecs.getreader = py3_getreader


def cmp_to_key(mycmp):
"""Convert a cmp= function into a key= function"""
Expand Down

0 comments on commit 3daa472

Please sign in to comment.