FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix demo stream reading by matthid · Pull Request #225 · pythonnet/pythonnet · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions demo/wordpad.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,13 @@ def OpenDocument(self):
stream = File.OpenRead(filename)

buff = System.Array.CreateInstance(System.Byte, 1024)
buff.Initialize()
data = []
read = 1

while stream.Position < stream.Length:
buff.Initialize()
stream.Read(buff, 0, 1024)
temp = Encoding.ASCII.GetString(buff, 0, 1024)
while read > 0:
read, _ = stream.Read(buff, 0, 1024)
temp = Encoding.ASCII.GetString(buff, 0, read)
data.append(temp)

data = ''.join(data)
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_method.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,28 @@ def test():

self.assertRaises(TypeError, test)

def testWeCanBindToEncodingGetString(self):
"""Check that we can bind to the Encoding.GetString method with variables."""

from System.Text import Encoding
from System.IO import MemoryStream
myBytes = Encoding.UTF8.GetBytes('Some testing string')
stream = MemoryStream()
stream.Write(myBytes, 0, myBytes.Length)
stream.Position = 0

buff = System.Array.CreateInstance(System.Byte, 3)
buff.Initialize()
data = []
read = 1

while read > 0:
read, _ = stream.Read(buff, 0, buff.Length)
temp = Encoding.UTF8.GetString(buff, 0, read)
data.append(temp)

data = ''.join(data)
self.assertEqual(data, 'Some testing string')

def test_suite():
return unittest.makeSuite(MethodTests)
Expand Down

Back | FazBrowse Home | New Git URL