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()
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 />"))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With