Re: [Tutor] Obssfurcatedpuytthonlessons nneeded

2008-01-20 Thread Alan Gauld
"Kirk Bailey" <[EMAIL PROTECTED]> wrote

>I  aam  writing some software which calls for some  unreadable code 
>in
> it to let me secretly  set a registration key- it is to be 
> shareware.

You don;t need to use a registration key for shareware.
Other much easier options are:
1) Rely on the honesty of your users.
2) Provide good quality documentation in pa[per only
format to buyers

Of course nothing is foolproof and whatever you do will be
hacked and free copies will become available so ultimately
you will always rely on honesty. That is the nature of
shareware...

> I know this can be done, but have not the foggiest clue of how todo 
> it.

There are lots of options, some dont even require you to
distribute a key since the key can be an encrypted form of
the users email address or user name (which is usually
obtainable via an environent variable...). Another option
is to use the checksum of the file itself, or the MAC id
of the computer.

Another option is to have an open key in the distribution and
your web site generate a secondary key based on the open
key and the users download credentials (a sequence number
and time usually). This is somewhat similar to public key
encryption protocols like RSA...

But there are many ways to do it which do not involve
writing obscure code which is probably the least secure
technique. But ultimately they can all be bypassed its
only a matter of time and effort..


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] Pointers in python ??

2008-01-20 Thread Alan Gauld
"Varsha Purohit" <[EMAIL PROTECTED]> wrote

>Does python has concept of pointers like c/cpp ?? If yes 
> how.. can
> anyone give me a small example to how we can use pointers in python.

No, not really.

It does have the concept of C++ references however and in fact
thats how Pyhon variables work. They are all references. But
there is no real concept of a poibnter to a specific memory
location, and especially one that can be manipulated
arithmetically.

OTOH there is in practice little need for such a low level
approach in Python. What did you have in mind thast you
thought might need a pointer?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [tutor] Calling python from a c program

2008-01-20 Thread Varsha Purohit
Hi,
   I just read about how to call python from a c program. This is the
function for that

int main()
{
 Py_Initialize();
PyRun_SampleString("print 76");
Py_Finalize();

return 0;
}


But i am getting an error of header file. python.h not found. Can anybody
tell me where can i get this header file ?? And how can i call the python
interpreter screen from c program ??

-- 
Varsha Purohit,
Graduate Student
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] Calling python from a c program

2008-01-20 Thread Varsha Purohit
I got the python.h file but i am getting linking errors for my program

On Jan 20, 2008 1:18 AM, Varsha Purohit <[EMAIL PROTECTED]> wrote:

> Hi,
>I just read about how to call python from a c program. This is the
> function for that
>
> int main()
> {
>  Py_Initialize();
> PyRun_SampleString("print 76");
> Py_Finalize();
>
> return 0;
> }
>
>
> But i am getting an error of header file. python.h not found. Can anybody
> tell me where can i get this header file ?? And how can i call the python
> interpreter screen from c program ??
>
> --
> Varsha Purohit,
> Graduate Student




-- 
Varsha Purohit,
Graduate Student
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] Calling python from a c program

2008-01-20 Thread Kent Johnson
Varsha Purohit wrote:
> I got the python.h file but i am getting linking errors for my program

It might help to tell us
- what platform you are using
- what compiler
- what link errors

Kent

> 
> On Jan 20, 2008 1:18 AM, Varsha Purohit <[EMAIL PROTECTED] 
> > wrote:
> 
> Hi,
>I just read about how to call python from a c program. This is
> the function for that
> 
> int main()
> {
>  Py_Initialize();
> PyRun_SampleString("print 76");
> Py_Finalize();
>
> return 0;
> }
> 
> 
> But i am getting an error of header file. python.h not found. Can
> anybody tell me where can i get this header file ?? And how can i
> call the python interpreter screen from c program ??
> 
> -- 
> Varsha Purohit,
> Graduate Student 
> 
> 
> 
> 
> -- 
> Varsha Purohit,
> Graduate Student
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] Calling python from a c program

2008-01-20 Thread Alan Gauld

"Varsha Purohit" <[EMAIL PROTECTED]> wrote

>   I just read about how to call python from a c program. 

Where did you read it? There are several sources of info 
on embedding Python in C, some better than others.

> And how can i call the python interpreter screen 
> from c program ??

You don't call the python interpreter screen
(ie the >>> prompt) from C you call the interpreter itself.
The interactive interpreter is a C program in its own right.

You could write your own fairly easily or you could use 
the PyShell GUI component that is part of the wxPython 
package.

But usually you just want to interpret some Python 
commands much as you did in your example.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Obssfurcatedpuytthonlessons nneeded

2008-01-20 Thread Michael Langford
This is one of the few things I suggest going with a professional
software library for.

I remember reading about one in the sub $200 range you could also get
source for a little extra...but I've looked for 45 minutes and can't
find it.

They are called "License Managers" and many of them can just drop in
and handle all the forms of licenses you're used to.

 --Michael



On Jan 19, 2008 9:40 PM, Kirk Bailey <[EMAIL PROTECTED]> wrote:
> I  aam  writing some software which calls for some  unreadable code in
> it to let me secretly  set a registration key- it is to be shareware.
>
> I know this can be done, but have not the foggiest clue of how todo it.
> Any links, articles, pointers?
>
> --
> Salute!
> -Kirk Bailey
>Think
>   +-+
>   | BOX |
>   +-+
>knihT
>
> Fnord.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pointers in python ??

2008-01-20 Thread Michael H. Goldwasser

On Sunday January 20, 2008, Alan Gauld wrote: 

>"Varsha Purohit" <[EMAIL PROTECTED]> wrote
>
>>Does python has concept of pointers like c/cpp ?? If yes 
>> how.. can
>> anyone give me a small example to how we can use pointers in python.
>
>No, not really.
>
>It does have the concept of C++ references however and in fact
>thats how Pyhon variables work. They are all references. But
>there is no real concept of a poibnter to a specific memory
>location, and especially one that can be manipulated
>arithmetically.

You are correct in that Python has no concept of pointer arithmetic or
any direct access of memory based on a pointer value.

However I strongly disagree with your suggestion that Python's
variables work like C++ reference variables.  The issue is that a C++
reference variable must be initially bound to an existing object and
that association cannot henceforth be changed.  Consider the following
C++ example, presuming that we have a basic Point class (not shown
here).

Point a(0,0);
Point b(5,7);
Point& c = a; // C++ reference variable

At this point there are two instances.  The names a and c are bound to
the same underlying instance and b is bound to a second instance.
Consider the following

c = b;   // reassigns the VALUE of c (aka a) to 5,7 but c is still bound to 
a
c.setX(3);   // notice that this has no effect on b;  c is not bound to b
cout << a;   // would output <3,7>
cout << b;   // would output <5,7>
cout << c;   // would output <3,7>

Translating these same seven command into Python would produce
different results, most notably because of the c=b assignment.

C++ When passing a parameter as a C++ reference, similar semantics are
used. The formal parameter is bound to the actual parameter upon
invocation of a function and from that point on assignments within the
body do not rebind the name but instead alter the value of the
underlying instance.

bool clear(Point& p) {
  p = Point(0,0);// changes the actual parameter's value
}

As a final issue, notice that a C++ pointer can be assigned to null,
just as a Python variable can be assigned to None.  (C++ reference
variable cannot be null).

I should say that the SYNTAX of C++ pointers are different, as you
need to explicitly dereference them to access the underlying instance,
as in c->setX(3) rather than c.setX(3).

If you are comfortable with Java's syntax and semantics, it is easy to
explain.  The model for all data types in Python is the same as the
model used for non-primitive types in Java.

With regard,
Michael


   +---
   | Michael Goldwasser
   | Associate Professor
   | Dept. Mathematics and Computer Science
   | Saint Louis University
   | 220 North Grand Blvd.
   | St. Louis, MO 63103-2007

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pointers in python ??

2008-01-20 Thread Alan Gauld
"Michael H. Goldwasser" <[EMAIL PROTECTED]> wrote

>>It does have the concept of C++ references however and in fact
>>thats how Pyhon variables work. They are all references.

> However I strongly disagree with your suggestion that Python's
> variables work like C++ reference variables.

You are quite correct, I overstated the similarity, especially
in saying that they "work like" C++ references. I was really
only refering to the fact that in both cases the references
are to other variables/objects rather than to memory
locations. But the underlying semantics are quite different.

> reference variable must be initially bound to an existing object and
> that association cannot henceforth be changed.

But I had actually forgotten that references could not be reassigned.
My C++ is pretty rusty, I haven't used C++ much in the last 7
or 8 years! :-)

Thanks for the clarification Michael.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] Calling python from a c program

2008-01-20 Thread Varsha Purohit
I am gettng following linking errors

  [Linker error] undefined reference to `_imp__Py_Initialize'
  [Linker error] undefined reference to `PyRun_SampleString'
  [Linker error] undefined reference to `_imp__Py_Finalize'

I think i need to set the path to the linker... may be i need to pass
linking options of python to the c compiler... but wat are those options :(
??

On Jan 20, 2008 7:16 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:

>
> "Varsha Purohit" <[EMAIL PROTECTED]> wrote
>
> >   I just read about how to call python from a c program.
>
> Where did you read it? There are several sources of info
> on embedding Python in C, some better than others.
>
> > And how can i call the python interpreter screen
> > from c program ??
>
> You don't call the python interpreter screen
> (ie the >>> prompt) from C you call the interpreter itself.
> The interactive interpreter is a C program in its own right.
>
> You could write your own fairly easily or you could use
> the PyShell GUI component that is part of the wxPython
> package.
>
> But usually you just want to interpret some Python
> commands much as you did in your example.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Varsha Purohit,
Graduate Student
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Program Review: startup_user script -and- TimedMultiChoiceDialog class

2008-01-20 Thread ethan s
Hi folks. I'd love some feedback for two scripts.

  -startup_user: Intended to be called from a users logon script to
present a list of apps to launch. List items can be set to default on or
off. I run it from my system logon script like this:
if exist "c:\_utils\scripts\logon_%USERNAME%.py" pythonw
"c:\_utils\scripts\logon_%USERNAME%.py"

  -timedmultichoicedialog: A derivative of wx.MultiChoiceDialog. Added:
Timeout, statusbar countdown, default selected status of list items.

Prerequisites: wxPython
OS: Tested WinXP. Since only imports basically are wx.MultiChoiceDialog
and subprocess.Popen it they may/should work on on *nix.

Questions/Notes:

Left startup_user as simple script in line with simple nature of logon
scripts rather than do 'if __name__ == '__main__': Does that choice make
sense?

Script prints result info to stdout on theory that will run from pythonw or
redirect to NUL if want quiet. Could control with command line switch if
  implement a main. Again, good choice or does in rankle?

Could not get to/change message on dialog after setting it, so update
the dialogs titlebar instead. Acceptable? Better ideas? Know how to
change the message on a wx.MultiChoiceDialog when after ShowModal()?

Are these (after any fixes suggested) of use enough to submit wxPython
list for comment or otherwise publish?

start startup_user.py
#!/usr/bin/env python
# startup_user.py - default programs launcher GUI
# Author:  Ethan Shames - my.first.name NatO SPdogdiniAM.com
# Created: 2007-12-19
# last edit:   2008-01-19
# Version: .8

# lessons learned:
#   Event incantations:
#  (D'oh)Event Binds must be to function w/o '()'s or function will
#  be __called__ when mentioned.
#  No parameter passing when Binding. (use self)
#  Event functions must be of form "def (self, event):" or they don't
work right.
#  Don't try to guess the event, get it from the docs.
#   Since this is a wx derived modal dialog, these changes to behavior
#   work. Not necessarily so if system derived like MessageBox

# TODO runas domain/user as LST parameter. Encode password.
# TODO 'save selections' button to remember on/off status of list item
# TODO program list maintenance

from wx import App, ID_OK
from subprocess import Popen
from timedmultichoicedialog import TimedMultiChoiceDialog

def launch(apps):
 #Launch a list of targets, return results
 results = []
 for app in apps:
 try:
 results.append(Popen(app))
 except WindowsError, e: # Not sure what error raised if *nix
 results.append(" subprocess.Popen: %s\n Starting File: %s" %
(e, app))
 continue
 return results

# List of items to launch. True/False flag sets default
# checked/unchecked status of item on list.
LST = [[True, r"C:\WINDOWS\system32\notepad.exe"],
[True, r"C:\WINDOWS\system32\calc.exe"],
[False, r"C:\you have fail.test"],
]

SELECTED = []
DELAY = 5000
MESSAGE = "Starting these in %s seconds. Click any item to stop timer" %
(DELAY/1000)
TITLE = "startup manager"

app = App()
dlg = TimedMultiChoiceDialog(message=MESSAGE, title=TITLE, lst=LST,
delay=DELAY)

# Clever idiom: ()calling ShowModal, which blocks processing until the
dialog dismissed,
# then check the return value for OK (vs. CANCEL)
if (dlg.ShowModal() == ID_OK):
 selections = dlg.GetSelections ()
 SELECTED = [LST[x][1] for x in selections]
 ##print("Selections: %s --> %s" % (selections, SELECTED))#uncomment
to test

# Destroy dialog before moving on to launch selected items.
dlg.Destroy()#Breakpoint here to test

results = launch(SELECTED)

for r in results:
 try:
 print(r.__dict__)
 except AttributeError:
 print(r)

end startup_user.py

start timedmultichoicedialog.py
#!/usr/bin/env python
# timedmultchoicedialog.py - multi-choice dialog box with timeout
# Author:  Ethan Shames - my.first.name NatO SPdogdiniAM.com
# Created: 2007-12-19
# last edit:   2008-01-19
# Version: .8

# TODO Add group as parameter to lst; Create button for each unique
#  group to deselect/select group.
# TODO click anywhere to stop timer

import wx

class TimedMultiChoiceDialog(wx.MultiChoiceDialog):
 """
 MultiChoiceDialog with added timeout delay and countdown in titlebar.
Timer stops on change.

 lst: [[True|False, item], ...] True/False flag sets default
  checked/unchecked status of item on list.
 message: Message on header of dialog.
 title: Titlebar text.
 delay: Delay before timeout. Default value 1ms.
 tic: Update titlebar text interval.
 """

 def __init__(self, message, lst, title=None, parent=None, delay=1,
tic=1000):
 self.tic = tic  # timer tick interval
 self.timeout = delay# init timeout for countdown
 if title == None: title = "TimedMultiChoiceDialog"
 self.title = title
 mytitle = '%s