Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print new line in Google app engine

self.response.out.write("\n")

When i upload a data of multiline using text property and then printing it back it prints in a single line.... i upload the ascii hexa code .... so carriage return is 0x10 but when pringing it in ascii from datastore the new line is not inserted... instead it prints as a single line

import cgi
#import codecs
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

import operator

class Vault(db.Model):
    username=db.StringProperty()
    filename=db.StringProperty()
    data=db.TextProperty()

op=""
op1=""
username=""
filename=""


class MainPage(webapp.RequestHandler):
    def get(self):
        stri=""
        global username
        global filename
        stri=""
        username = self.request.get("name")
        filename=self.request.get("filename")
        mac=self.request.get("mac")
        mac=mac.replace(':','')
        q=db.GqlQuery("SELECT * FROM Vault WHERE filename=:1",filename)
        for vault in q:
            stri=cgi.escape(vault.data)
        s=0
        e=12
        cycle=len(stri)/12
        z=""
        for j in range(cycle):
            plain=stri[s:e]
            #print plain
            s1=0
            s2=2
            for i in range(6):
                x=int(plain[s1:s2],16)
                y=int(mac[s1:s2],16)
                s1=s1+2
                s2=s2+2
                z+=chr(operator.xor(x,y))
            mac=plain
            s=s+12
            e=e+12
        print z

application = webapp.WSGIApplication([('/dec', MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
like image 895
HariHaraSudhan Avatar asked Dec 17 '22 17:12

HariHaraSudhan


2 Answers

Where are you printing that data back out to? If it's inside of HTML (well, unless it's surrounded by <pre> tags), the newlines will be ignored regardless of whether the EOL is indicated by \n or \r\n.

If that's what's going on, you can just do

self.response.out.write(myString.replace("\n", "<br />"))
like image 56
bgporter Avatar answered Dec 27 '22 10:12

bgporter


In your web browser, try looking at the result using 'View page source'.

If the line-breaks look correct there, then @bgporter has the correct solution.

like image 21
Hugh Bothwell Avatar answered Dec 27 '22 10:12

Hugh Bothwell