~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wlms/db/flatfile.py

  • Committer: Holger Rapp
  • Date: 2009-02-26 22:38:49 UTC
  • Revision ID: sirver@kallisto.local-20090226223849-1563ij0uuw0lz0zu
First version of widelands online help

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# encoding: utf-8
3
 
 
4
 
class FlatFileDatabase(object):
5
 
    def __init__(self, text):
6
 
        """
7
 
        A database that can be read from a flat file. Mainly for testing. text
8
 
        is the complete text inside the definition file.
9
 
        """
10
 
        self._users = {}
11
 
        for line in text.splitlines():
12
 
            line = line.strip()
13
 
            if not line: continue
14
 
            elems = line.split("\t")
15
 
            self._users[elems[0]] = elems[1], elems[2]
16
 
 
17
 
    def check_user(self, user, password):
18
 
        if not user in self._users:
19
 
            return False
20
 
        u = self._users[user]
21
 
        if u[0] == password:
22
 
            return u[1]
23
 
        return False
24
 
 
25
 
    def user_exists(self, user):
26
 
        return user in self._users
27