Print a new line in a Google application

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

When I load data from multiline text using the text property and then print it, it prints on one line .... I load the ascii hexa code .... so the carriage return is 0x10, but when assigning it to ascii from the datastore, it’s new no line inserted ... instead it prints as one 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()
+3
source share
2 answers

Where do you print this data? If it is inside HTML (well, if it is not surrounded by tags <pre>), newlines will be ignored regardless of whether EOL is specified with \nor \r\n.

If this happens, you can simply do

self.response.out.write(myString.replace("\n", "<br />"))
+8
source

- " ".

, @bgporter .

+3

Source: https://habr.com/ru/post/1790011/


All Articles