Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commitd58b338

Browse files
matthidtonyroberts
authored andcommitted
fix demo stream reading (pythonnet#225)
1 parent6139989 commitd58b338

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

‎demo/wordpad.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,13 @@ def OpenDocument(self):
293293
stream=File.OpenRead(filename)
294294

295295
buff=System.Array.CreateInstance(System.Byte,1024)
296+
buff.Initialize()
296297
data= []
298+
read=1
297299

298-
whilestream.Position<stream.Length:
299-
buff.Initialize()
300-
stream.Read(buff,0,1024)
301-
temp=Encoding.ASCII.GetString(buff,0,1024)
300+
whileread>0:
301+
read,_=stream.Read(buff,0,1024)
302+
temp=Encoding.ASCII.GetString(buff,0,read)
302303
data.append(temp)
303304

304305
data=''.join(data)

‎src/tests/test_method.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,28 @@ def test():
759759

760760
self.assertRaises(TypeError,test)
761761

762+
deftestWeCanBindToEncodingGetString(self):
763+
"""Check that we can bind to the Encoding.GetString method with variables."""
764+
765+
fromSystem.TextimportEncoding
766+
fromSystem.IOimportMemoryStream
767+
myBytes=Encoding.UTF8.GetBytes('Some testing string')
768+
stream=MemoryStream()
769+
stream.Write(myBytes,0,myBytes.Length)
770+
stream.Position=0
771+
772+
buff=System.Array.CreateInstance(System.Byte,3)
773+
buff.Initialize()
774+
data= []
775+
read=1
776+
777+
whileread>0:
778+
read,_=stream.Read(buff,0,buff.Length)
779+
temp=Encoding.UTF8.GetString(buff,0,read)
780+
data.append(temp)
781+
782+
data=''.join(data)
783+
self.assertEqual(data,'Some testing string')
762784

763785
deftest_suite():
764786
returnunittest.makeSuite(MethodTests)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp