Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replace demo php scripts with python/gae versions

  • Loading branch information...
commit 8247b9e90aa7c0bd0e0feeec52fd8e8bd8df7d6d 1 parent 45ac515
@IgorMinar IgorMinar authored
Showing with 36 additions and 71 deletions.
  1. +3 −0  app.yaml
  2. +33 −0 demos.py
  3. +0 −15 generatePassword.php
  4. +0 −56 greet.php
View
3  app.yaml
@@ -32,6 +32,9 @@ handlers:
- url: /js
static_dir: js
+- url: /(greet|generatePassword)(\.php)?
+ script: demos.app
+
- url: /.*
static_files: index.html
upload: index.html
View
33 demos.py
@@ -0,0 +1,33 @@
+# coding: utf-8
+
+import webapp2, random, json, string
+
+SALUTATIONS = [ "Adab", "Ahoj", "An-nyeong-ha-se-yo", "Apa khabar", "Barev Dzez", u"Buenos días".encode('utf-8'), "Bula Vinaka",
+ "Chào", "Ciao", "Dia Duit", "Hallo", "Hallå", "Halló", "Halo", "Haye", "Hei", "Hej", "Hello",
+ "Helo", "Hola", "Kamusta", "Konnichiwa", "Merhaba", "Mingalarba", "Namaskar", "Namaste", "Olá",
+ "Pryvit", "Pryvitannie", "Përshëndetje", "Salam", "Salut", "Sat Sri Akal", "Sholem aleikhem",
+ "Sveiki", "Szia", "Tere", "Zdraveĭte", "Zdravo" ]
+
+
+class GreetHandler(webapp2.RequestHandler):
+ def get(self):
+ name = self.request.get('name')
+ callback = self.request.get('callback')
+ salutation = SALUTATIONS[random.randint(0, len(SALUTATIONS) - 1)].encode('string_escape')
+ greeting = json.dumps([name, salutation, salutation + ' ' + name + '!'])
+
+ self.response.headers['Content-Type'] = 'application/javascript'
+ self.response.out.write(callback + '(' + greeting + ')')
+
+
+class GeneratePasswordHandler(webapp2.RequestHandler):
+ def get(self):
+ callback = self.request.get('callback')
+ password = ''.join(random.choice(string.hexdigits) for x in range(random.randint(3, 10)))
+ password = json.dumps({'password': password})
+ self.response.headers['Content-Type'] = 'application/javascript'
+ self.response.out.write(callback + '(' + password + ')')
+
+
+app = webapp2.WSGIApplication([('/greet.*', GreetHandler),
+ ('/generatePassword.*', GeneratePasswordHandler)])
View
15 generatePassword.php
@@ -1,15 +0,0 @@
-<?php
-$callback = $_GET['callback'];
-$password = '';
-for($counter = rand(3,10); $counter > 0; $counter --) {
- $password = $password . chr(rand(33, 126));
-}
-$data = array(
- "password" => $password );
-$json = json_encode($data);
-header("Content-type: text/javascript");
-if ($callback)
- echo $callback .' (' . $json . ');';
-else
- echo $json;
-?>
View
56 greet.php
@@ -1,56 +0,0 @@
-<?php
-$name = $_GET['name'];
-$callback = $_GET['callback'];
-$salutations = array(
- "Adab",
- "Ahoj",
- "An-nyeong-ha-se-yo",
- "Apa khabar",
- "Barev Dzez",
- "Buenos días",
- "Bula Vinaka",
- "Chào",
- "Ciao",
- "Dia Duit",
- "Hallo",
- "Hallå",
- "Halló",
- "Halo",
- "Haye",
- "Hei",
- "Hej",
- "Hello",
- "Helo",
- "Hola",
- "Kamusta",
- "Konnichiwa",
- "Merhaba",
- "Mingalarba",
- "Namaskar",
- "Namaste",
- "Olá",
- "Pryvit",
- "Pryvitannie",
- "Përshëndetje",
- "Salam",
- "Salut",
- "Sat Sri Akal",
- "Sholem aleikhem",
- "Sveiki",
- "Szia",
- "Tere",
- "Zdraveĭte",
- "Zdravo" );
-$salutation = $salutations[rand(0, count($salutations) - 1)];
-$greeting = $salutation . ' ' . $name . '!';
-$data = array(
- "name" => $name,
- "salutation" => $salutation,
- "greeting" => $greeting );
-$json = json_encode($data);
-header("Content-type: text/javascript");
-if ($callback)
- echo $callback .' (' . $json . ');';
-else
- echo $json;
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.