python

Christian Harms's picture

Escaping examples and the worst test data

After the fine and long article about escaping from Matthias here some examples for special characters in a simple web application. This article should be only an inspiration, I will describe some code samples with python/javascript and explain why [<"@%'&_\?/:;,>কী €] is the ultimate input to test input in web applications.

The demo application offers a simple form with name and message field for an one-line guest book.Read more

Christian Harms's picture

TOP 7 Exceptions in my google app engine described

After running the IP-geolocation application in the google app engine some weeks I gained some experience while fetching data and saving into the storage. Looking at the logs with the dash board some interesting errors appeared and that's why I write this article as a notepad for me (or for other python developers). If possible python snipplets will solve the problem cases of errors like "ApplicationError: 5" or "CapabilityDisabledError".Read more

Christian Harms's picture

IP address regex example - not in java

Finding an IP address in text or string with python is a simpler task than in java. Only the regex is not shorter than in the java regex example!

First an example with python: build a RegExp-Object for faster matching and than loop over the result iterator.

  1. import re
  2. logText =  'asdfesgewg 215.2.125.32 alkejo 234 oij8982jldkja.lkjwech . 24.33.125.234 kadfjeladfjeladkj'
  3. bytePattern = "([01]?\d\d?|2[0-4]\d|25[0-5])"
  4. regObj = re.compile("\.".join([bytePattern]*4))
  5. for match in regObj.finditer(logText):
  6.     print match.group()

A regex like /\d+\.\d+\.\d+\.\d+/ wont work, because there match "999.999.111.000" too. But for the usage in python - that is it! Using a regular expression is more native in python than in java. Or in javascript or in perl or asp.net... Read more

Christian Harms's picture

Combining HTTP and JavaScript APIs with python on google appengine

In this part I will introduce the python implementation of the ip to geolocation script. It's more object oriented and hopefully better to read. In the first part of this article I willdescribe the solution to read http resources and parse the content. The second part is the same like the php version. As conclusion I will compare the results of all five APIs with the data from the cache.Read more

Christian Harms's picture

Functional programming with Python

To work with lists many c/c++ programmer use a simple for-loop. I will try to explain how this can be made a little bit easier. For that I use the self-explaining script language python.

Here is a simple example to filter all odd integers from a list in simple python 2.x syntax.

def filter_odd(myList):  
   result = []               # initialize the result list  
   for num in myList:               # iterate over the list  
     if num % 2 == 1:        # modulo 2 return 1 for odd integers
        result.append(num)   # add to the result
   return result                
Read more

Syndicate content