[Tutor] How to obfuscate a database password.

2005-04-19 Thread David Driver
Is there a convention for obfuscating database passwords? I think that
in the end there will be a script that boot-straps to zipped modules
but I don't think that that is secure enough. I was thinking about
asking  the database lists but I think that this is more of a general
question.
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to obfuscate a database password.

2005-04-20 Thread David Driver
So I could do the folowing:
Create a DB logon for each user that has permissions to just about
everything.
Have them log on each time.
This would require an application that they could manage their passwords.
I already needed an application for managing permissions within
the application so I could just add a reset password to it, and adapt
it to using the database users for validation and keep my own tables
to track where the users can go in the app.


I guess that I was just thinking along the wrong lines for the design
of the login.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Building application namespaces.

2005-04-22 Thread David Driver
I have generally used python for tasks that are scripty and not
appish. I have found that I don't know the language very well even
though I have been scripting with it for about two years. To remedy
this I am in the process of laying out a mock up for an accounting
system (GL, AR, AP). This is the first time I have done modules inside
packages and I am confused about namespaces.

What I have is a folder structure that looks like this:
root
++ Common
++ AP
++ AR
++ GL

Each subfolder looks like:
++ Common
 __init__.py
 sobjs.py (this contains sqlobjects for the domain)
 validators.py (contains formencode validators for the sqlobjects
for the domain)
 exceptions.py
 folder: view (this will be templates)
 folder: search (this will contain controllers for lookups)
 folder: transact (this will contain controllers for creating transactions)
 folder: maintain (contains folders for maintaining domain objects
(ie customer maintenance or anything that isn't a busness transaction)

In the __init__ file I import sobjs, exceptions, validators and I will
eventually check to see that the user is supposed to be in that
domain.

You may laready see what the problem is. When I import Common from the
script running in the root folder and it runs init all of themodules
in the  domain (common, GL) package that get imported by __init__have
no ancesters in their name spaces (is that the correct term?). What I
wanted was root/common/sobjs.py as common.sobjs not just sobjs.

Am I totally confused here?

Is there some place that I could go that has better doccumentation on
settig up namespaces for large python projects?

Thanks tutors!

-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building application namespaces.

2005-04-23 Thread David Driver
In the root script I import Common. Inside of Common's __init__.py I
import the basic domain modules. Is this correct?


>If I understand the setup correctly it should work. How are you
importing Common? If you say
>import Common
>you should be able to refer to Common.sobjs. If you say
>from Common import *
>then sobjs will be imported into the main module namespace.
>
>Kent
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Name spaces again

2005-04-24 Thread David Driver
I have read the essay at
 and I am still having
problems understanding what I need to do. Here is the structure that I
am looking at:

Root folder
StartHere.py
Common folder
__init__.py
sobj.py
exceptions.py
validators.py
View folder (keeps cheetah and sxl templates)
Search folder (will be namespace for lookup operations)
Maintain folder (for creating and altering base domain objects)
Transact folder (namespace for creating transaction operations)
AR folder
__init__.py
sobj.py
exceptions.py
validators.py
View folder 
Search folder 
Maintain folder
Transact folder
AP folder
__init__.py
sobj.py
exceptions.py
validators.py
View folder 
Search folder 
Maintain folder
Transact folder
GL folder
__init__.py
sobj.py
exceptions.py
validators.py
View folder 
Search folder 
Maintain folder
Transact folder

StartHere.py contains:
import Common
import AR
import AP

Each subpackage __init__.py contains:
import exceptions
import validators
import sobjs
import Maintain
import Transact
import Search
import View


In AR.sobjs I have a class that is inherited from
Common.sobjs.baseDomObj. When I run StartHere.py Common imports just
fine. It starts to import AR and AR. __init__.py imports AR.sobjs.py
and it throws the following error:

Traceback (most recent call last):
  File "C:\foo\doinit\starthere.py", line 3, in ?
import AR
  File "C:\foo\doinit\AR\__init__.py", line 3, in ?
import sobjs
  File "C:\foo\doinit\AR\sobjs.py", line 1, in ?
class custAddress(Common.address):
NameError: name 'Common' is not defined

Do I need to import Common in each sub package to have access to it?
Does it consume more memory? What about Sub Sub packages? shouldn't
you be able to Import DateTime in StartHere and have all sub
modules/packages that are imported into StartHere.py use it? Am I
making a big deal out of nothing?

This entire project is more or less of a mock up of a project. I am
just trying to learn more about python and I am basing it on the VB
based accounting package I currently maintain. It isn't that I would
normally organize an app this way if I were building a new one.

-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Debian install problems.

2005-05-11 Thread David Driver
I don't know is this is the proper place to post this but I need some help.

I am running Damn Small Linux at the moment. I enabled apt-get and
adjusted the list file to use the testing branch so I could install
python2.4. The apt-get went fine, I think. I didn't get and errors.
When I went to install quixote from a distutils package I received the
following error:

[EMAIL PROTECTED]:~# cd /home/dsl/Quixote-2.0
[EMAIL PROTECTED]:~/Quixote-2.0# python2.4 setup.py install
running install
error: invalid Python installation: unable to open
/usr/lib/python2.4/config/Makefile (No such file or directory)


Does anyone have any Idea where I should go from here? I have tried
other distutills installs with the same results. Any help is
appreciated. Thanks!


-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Debian install problems.

2005-05-11 Thread David Driver
Thank you John and Ziyad. That is exactly what I needed to know.
Thanks for the Debian resources. I didn't know that there was a list
for python on Debian.

On 5/11/05, John Purser <[EMAIL PROTECTED]> wrote:
> David,
> 
> If you don't get an answer here on tutor.python.org then you might want to
> try:
> http://www.debian.org/MailingLists/ - where you'll find a link to
> http://lists.debian.org/debian-python/  - the mailing list for
> debian-python.
> 
> Don't forget to search the archives.
> 
> John Purser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] who called the class method?

2005-06-21 Thread David Driver
Is there a way to test if a class method was called from an instance? 

What I am trying to do is if a method is called from the class return
a commanding proxy with an mock or stub type object as the proxied
object. If it is called from the instance I want to return a proxy for
the instance.

Does what I am trying to do make sense?

Thanks!
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] who called the class method?

2005-06-21 Thread David Driver
Ketn

You are correct.

What I will do is an instance method that calls the class method with
an optional parameter.

I don't know what I was thinking, I was just messing around with
nested classes for the first time and kind of forgot how to program.


On 6/21/05, David Driver <[EMAIL PROTECTED]> wrote:
> Is there a way to test if a class method was called from an instance?
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] who called the class method?

2005-06-21 Thread David Driver
You are right to be confused because I was as well. I was shooting for:

> OR do you mean you will have an actual class method
> (ie static in C++/Java speak) and want to know if the
> activating message was sent to the class object or to
> an instance of the class?

The easiest solution was to do a class method 'GetDefaultProxy' that
creates the default object (a stub with initial values) and creates
the proxy with it and an instance method 'GetInstanceProxy' that
creates the proxy for the already instanced object.

I am working on integrating sqlobject with formencode's validators and
a commanding proxy. Partly as an academic exercise. It is the biggest
OO project that I have ever tried in any language and it has turned
out to be pretty neat. There are a few details to work out but in the
end I think that I will have something special.

On 6/21/05, Alan G <[EMAIL PROTECTED]> wrote:
> 
> > Is there a way to test if a class method was called from an
> instance?
> 
> I think you'll need to override the __getattr__ method.
> It will pick up the call and you can test whether its a
> class mrethod being called. I think...
> 
> > What I am trying to do is if a method is called from the
> > class return a commanding proxy with an mock or stub type
> > object as the proxied object. If it is called from the
> > instance I want to return a proxy for the instance.
> 
> I'm not quite sure I understand because you are mixing object
> oriented terminology with procedural programming terminology.
> 
> I think you mean you want to have a class with various methods.
> You may or may not have instances of the class.
> You want to know when a method is invoked whether this was via
> a direct call of the class's method or via a message being
> sent to an instance?
> 
> OR do you mean you will have an actual class method
> (ie static in C++/Java speak) and want to know if the
> activating message was sent to the class object or to
> an instance of the class?
> 
> Or do you want to know if the class method was invoked
> from within another method of the same class or invoked
> by a message sent from an instance of another class?
> 
> Those are all different scenarios which could be described
> by your paragraph above, which do you mean?
> Or is it something different again?
> 
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 


-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Dict operation question.

2005-07-07 Thread David Driver
I have a function

def updateit(self,**mydict):

which is intended to update a dictionary self.somedict. 

If there are keys in mydict that are not in self.somedict I want them
returned in a new dict.

here is what i am doing now:

errdict = dict([(a,b) for a,b in mydict.items() if not a in self.somedict])

I then test (if errdict) and raise an exception that contains errdict
as an attribute. Else i update self.somedict.

Is there something other than a list comprehension in a dict function
that can do this?

Thanks!
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dict operation question.

2005-07-08 Thread David Driver
Really I was just wondering if this was a bad practice or if there was
some way to get the same result.

So if the list  comprehension isn't a bad way to to it then I will
stick with it.

I am at the point where I have used python for simple stuff for a few
years and I am attempting to get past a novice's understanding.

Thanks for the suggestions! I do appreciate the input. the python
community is probably the best on the Internet.

On 7/7/05, David Driver <[EMAIL PROTECTED]> wrote:
> I have a function
> 
...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] domain logic and avoiding setters and setters.

2005-07-11 Thread David Driver
So I have been trying to figure out how to get around doing getters
and setters and still have an oo way to inherit and apply business
rules. This is what I have some up with so far. Is there any better
way?


class RuleViolationError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return 'Rule violated in rule object: %s' %self.msg

class someObject(object):
def __init__(self,a):
self._voilatedRules = {}
self._rules = [self.aRuleForA]
self.a = a

def applyRules(self):
self._voilatedRules.clear()
for rule in self._rules:
try:
rule()
except RuleViolationError, err:
self._voilatedRules[rule.__name__] = err.msg
if self._voilatedRules:
# do something dramatic to deal with all of the
# voilated business rules
print 'error(s): '
print self._voilatedRules

def aRuleForA(self):
try:
self.a = int(self.a)
except ValueError:
raise RuleViolationError('a is not an integer')

class someObjectChild(someObject):
def __init__(self, a,b):
someObject.__init__(self,a)
self.b = b
self._rules.extend((self.aRuleForB,
   self.anotherRuleForB))

def aRuleForB(self):
# apply some business logic for d
# check that it starts with b, very silly
if not self.b.startswith('b'):
raise RuleViolationError('b does not start with b')

def anotherRuleForB(self):
#test string for length constraints
min,max,l=2,15,len(self.b)
print min,max,l
if not(l>=min and l<=max):
raise RuleViolationError('b is out of min or max')

class someObjectChild2(someObjectChild):
#j ust change one of the rules for b
def aRuleForB(self):
# apply some business logic for d
# check that it starts with d, very silly
if not self.b.startswith('d'):
raise RuleViolationError('b does not start with d')


x = someObjectChild(123,'bob jones')

# this should return nothing
x.applyRules()
x.b = 'obladiobladalifegoeson'

# this should fail twice on b
x.applyRules()

y = someObjectChild2(123,'bob jones')
y.applyRules()

z = someObjectChild('happydance','bob jones')
z.applyRules()

This isn't near complete, but I think it gets the idea across.
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] domain logic and avoiding setters and setters.

2005-07-12 Thread David Driver
I appreciate your input. You are correct. I read a bunch of LoD stuff
Northeastern website. It codified a bunch of things that I had been
working through.

But what you are not seeing (I must be terrible at this, always hard
to tell how much code to post) is this chunk of code represents an
idea about ways to hang business rules in an inheritable way onto a
persisted (sqlobject) object. It is really in the model. This is a
sketch of what I am trying to accomplish.

Application (Output)
Presenter (renders HTML or other UI)
Persisted object/default generator
Editor (what we are looking at, is specific to the persisted
object, holds the rules and updates/creates persisted object)
Application (Input)

Presenter and Editor will have some knowledge of the persisted object.
They will directly access attributes in the persisted object. They
will not directly unveil attributes to the application (or any layers
that may be in between). So conceptually the domain object is just
split into three classes and Demeter  is
observed everywhere else, at least as far as I understand it's
principles.


On 7/12/05, Alan G <[EMAIL PROTECTED]> wrote:
> I think you are missing the point a wee bit.
> 
> The object should not allow you to access its internal data.
> 
> You should not *need* to access its internal data.
> 
> The object has responsibilities in the form of behaviours.
> The internal data is only there to support those behaviours,
> it should be of no interest to external objects, therefore
> you do not need setters and getters. Its not the setXXX getXXX
> thing thats wromg its the very idea that users of the object
> would want to access the internal data that is wrong.
> 
> In the words of Peter Coad, "Objects do it to themselves"
> 
> Now in some applications you do need the internal values,
> but usually its as a group. For example an Address class
> might have a method to return the full address content,
> but rather than provide individuual set/get methods per
> field it would return the whole address as a string or
> a tuple.(Note that both of these are immutable types!)
> 
> In some cases you may actually choose to expose one
> particular attribute, in which case a get/set pair for that
> one attribute is OK - they represent a genuine responsibility
> of the class. (Making it a property might be better still...)
> Its providing get/set pairs for *every attribute* that breaks
> good OOP practice.
> 
> PS. For a more formal description of the above principle
> look up "The Law of Demeter" on Google.
> 
> HTH,
> 
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Decorators, I am confused.

2005-07-14 Thread David Driver
What I would like to do is something like this:

class testObj(object):
_rules = list()
def evalRules(self):
for r in _rules:
r()
def rule(func):
if not func in func.__class__._rules:
func.__class__._rules.append(func)
print testis._rules
return func
@rule
def arule(self):
print a

Of course it doesn't work. Is there a way to make it work? What I am
trying to do is make a collection of validation rules that can be
iterated and capture raised exceptions to be returned at the end of
eval rules.

I am trying to replace somethng that looks like this:

class testObj(object):
def _init__(self):
self._rules = list((self.arule,
self.anotherrule))
def evalRules(self):
for r in self._rules:
r()

It would be too easy to add a rule twice or forget to add the rule to
the list in a subclass. I thought that using a decorator would make it
obvious.



Thanks!
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dictionary question

2005-07-28 Thread David Driver
The following code:

print str(dict(a=1,b=2,c=-1))
print str(dict(a=1,c=-1,b=2))
print str(dict(c=-1,a=1,b=2))
print str(dict(b=2,a=1,c=-1))
print str(dict(b=2,c=-1,a=1))
print
print str(dict(a=1,b=2,c=23))
print str(dict(a=1,c=23,b=2))
print str(dict(c=23,a=1,b=2))
print str(dict(b=2,a=1,c=23))
print str(dict(b=2,c=23,a=1))
print
print str(dict(a=1,b=2,c='booga'))
print str(dict(a=1,c='booga',b=2))
print str(dict(c='booga',a=1,b=2))
print str(dict(b=2,a=1,c='booga'))
print str(dict(b=2,c='booga',a=1))

Produces:

{'a': 1, 'c': -1, 'b': 2}
{'a': 1, 'c': -1, 'b': 2}
{'a': 1, 'c': -1, 'b': 2}
{'a': 1, 'c': -1, 'b': 2}
{'a': 1, 'c': -1, 'b': 2}

{'a': 1, 'c': 23, 'b': 2}
{'a': 1, 'c': 23, 'b': 2}
{'a': 1, 'c': 23, 'b': 2}
{'a': 1, 'c': 23, 'b': 2}
{'a': 1, 'c': 23, 'b': 2}

{'a': 1, 'c': 'booga', 'b': 2}
{'a': 1, 'c': 'booga', 'b': 2}
{'a': 1, 'c': 'booga', 'b': 2}
{'a': 1, 'c': 'booga', 'b': 2}
{'a': 1, 'c': 'booga', 'b': 2}

Could I rely on creating hashes to use as keys in bsddb this way? If I
create a dictionary with the same keys, will it str the same way?

Thanks!
-- 

***
See there, that wasn't so bad.
***
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor