Skip to content

open() build-in function don't work as expected  #706

@Tungsteno74

Description

@Tungsteno74

Hello,
first of all sorry for my bad english, i do not use it often.

Said that, i found the following two possible bugs:

The first concerns the carriage return that on Android is recognizes only the LF and then when meets the other 2 types it give trouble.
So in practice, if you want to create a file directly from Android or on a Linux machine should be no problem, but when you create the file with an OS that uses another kind of carriage return and then transferred to Android system then you will have that problem.

The second problem concerns the special characters as, for example, the "copyright" © which returns the following error traceback:

04-12 23:48:21.160 25138-25158/? I/python: /data/data/opentest.test.opentest/files/page.html
04-12 23:48:21.160 25138-25158/? I/python: -----
04-12 23:48:21.180 25138-25158/? I/python:  Traceback (most recent call last):
04-12 23:48:21.180 25138-25158/? I/python:    File "main.py", line 15, in <module>
04-12 23:48:21.180 25138-25158/? I/python:      mainApp().run()
04-12 23:48:21.180 25138-25158/? I/python:    File "/data/data/opentest.test.opentest/files/lib/python2.7/site-packages/kivy/app.py", line 802, in run
04-12 23:48:21.190 25138-25158/? I/python:      root = self.build()
04-12 23:48:21.190 25138-25158/? I/python:    File "main.py", line 12, in build
04-12 23:48:21.190 25138-25158/? I/python:      open_test(filepath)
04-12 23:48:21.190 25138-25158/? I/python:    File "/data/data/opentest.test.opentest/files/opentest.py", line 20, in open_test
04-12 23:48:21.190 25138-25158/? I/python:      print fli
04-12 23:48:21.190 25138-25158/? I/python:    File "<string>", line 5, in write
04-12 23:48:21.190 25138-25158/? I/python:  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 70238: ordinal not in range(128)
04-12 23:48:21.220 25138-25158/? I/python: Python for android ended.

This problem may be related to this type of implementation of the code http://stackoverflow.com/a/5245904, but in this case the workarounds proposed do not solve (at least in my opinion) the compatibily problems.

Both of the above problems occur only in the Android platform, which instead in others Python implementation that i have tested (windows/linux) are all easily managed.

I used buildozer toolkit to build the following test code:

main.py

from kivy.app import App  
from kivy.uix.button import Button  
from opentest import *  

#filepath = "/home/valerio/PROGETTI/opentest/page.html" #test in xubuntu  
filepath = "/data/data/opentest.test.opentest/files/page.html" #test in android 4.4.2  
#filepath = "C:\Users\valerio\Desktop\open\testpage.html" #test in windows vista  

class mainApp(App):  
    def build(self):  
        open_test(filepath)  
        return Button(text='Hello World')  

mainApp().run()  

opentest.py

def open_test(filepath):  

    fli = ""  
    print filepath  
    print "-----"  
    with open(filepath,"rb") as file:  
#       print file.read()  
        fli = file.read()  
#       for f in file:  
#           fli += f  
#       while True:  
#           lin = file.readline()  
#           if lin != "":  
#               fli += lin  
#           else:  
#               break  
#   print open(filepath,"rb").read()  
    print fli  
    print "-----"  

page.html

<!DOCTYPE html>  
<!-- This file is needed for test the Android platform -->  
<html><head><title>test title</title></head><body>test body<div>©test div</div>  

<div>test div 2</div></body></html>  

It would be great if you could solve it in the upcoming milestone or at least in the dev branch.

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions