Extending & Embedding Python

2006-01-12 Thread Marco Meoni
Hi all! I've a problem with a C++ class that has to be included in a
python application. One way to do it is Extending and Embedding the
Python Interpreter
Now i have 2 questions
1) Is there a one-file version of this tutorial?
2) Is there anyone that can help me with this problem? The class is
attached.

Thanks all.
Marco

Attached files:
--
#ifndef _PACKETMANAGER_H_
#define _PACKETMANAGER_H_
#include "Cipher/Cipher.h"

#define PAYLOAD_LENGHT 5000

//the our defined packe over the UDP datagram
struct packet {
int lenght; // sizeof(payload) = sizeof(int) + strlen(payload)
unsigned char payload[PAYLOAD_LENGHT]; // the xml string
} __attribute__ ((packed));


//! manage the send and receive of udp packet
/*! by default: send message non-cripted */
class PacketManager
{
private:
struct packet packet_to_send;
Cipher * pc;
int s;  //socket descriptor
public:
PacketManager();
virtual ~PacketManager();

///Network member function
bool send(char * IPdest , int port_to);
unsigned char * receive (char * IPdest, int timeout);  
//non-blocking
unsigned char * waitMessage(char * IPfrom); //blocking

///Packet Builder member function
bool build_Packet();
bool setCipher(Cipher * c);
Cipher * getCipher();

///Set and Get function on all attributes

bool set_Payload(unsigned char * c, int lenght);
unsigned char  * get_Payload();

bool set_packet_lenght(unsigned int lenght);
unsigned int get_packet_lenght();

void set_Socket(int socket);
int get_Socket();
bool buildPacket();
void setSocket(int socket);
packet getPacket();
bool setPacket(unsigned char * c,int lenght);
void closeSocket();
};

#endif //_PACKETMANAGER_H_
---
#include "Cipher/Cipher.h"
#include "Cipher/NullCipher.h"

#include "PacketManager.h"

#include "messages.h"

#define PORT_FROM 40004

//! manage the send and receive of udp packet
/*! by default: send message non-cripted */
PacketManager::PacketManager()
{

pc =  new NullCipher();

s = create_UDP_socket(PORT_FROM);

}

PacketManager::~PacketManager()
{
close (s);
delete pc;
}

void PacketManager::setSocket(int socket)
{
s = socket;
}

bool PacketManager::buildPacket()
{
pc->encrypt();  
//! ciphering
return true;

}

Cipher * PacketManager::getCipher()
{
return pc;
}

bool PacketManager::setCipher(Cipher * c)
{
pc=c;
return true;
}

//! send payload + header to IPdest at port_to
/*! send payload + header in an UDP packet
\param IPdest address to witch send the packet
\param port_to port to witch send the packet
 */
bool PacketManager::send(char *IPdest,int port_to)

{


//unsigned char * message_to_send = new unsigned
char(packet_to_send.lenght * sizeof(unsigned char));
unsigned char message_to_send[5000];

 memcpy (message_to_send, &(packet_to_send.lenght) ,
sizeof(int));

 unsigned char * tmp_payload = message_to_send;
 tmp_payload+=sizeof(int);

memcpy(tmp_payload,packet_to_send.payload,strlen((char*)packet_to_send.payload));

  // memcpy (message_to_send + sizeof(int), packet_to_send.payload,
packet_to_send.lenght - sizeof(int));//! mess =
[int][payload]



//memcpy (message_to_send, &packet_to_send ,sizeof (struct
packet));   //! mess = [packet_to_send]

 packet_to_send.payload[packet_to_send.lenght-4]='\0';

 printf ("Sto per inviare:  \nlenght = \t%d \nPayload = \t%s\n",
packet_to_send.lenght , packet_to_send.payload);

message_to(s,port_to,IPdest, message_to_send , packet_to_send.lenght
);

//delete message_to_send;

//return 0;

return true;
}

//! wait for a packet, non blocking, don't check for IP
/*! wait for a packet, non blocking, don't check for IP
 * param IPdest should be the IP from witch receive files
 * param timeout should be the seconds to wait until a message was
received
 */
unsigned char * PacketManager::receive(char *IPdest, int timeout)
{
info risposta;
risposta  = wait_message(s);

//!have to check if the message return from 
IPdest
return risposta.message;

}

//! wait for a packet from IPfrom, blocking
/*! wait fo

Re: Extending & Embedding Python

2006-01-12 Thread Marco Meoni
> i'm not sure what tutorial you mean. are you talking about the
> Extending and Embedding section of the python manual?
>
>  http://docs.python.org/ext/ext.html

Yes, this section. Is there in one-file version? (pdf, ps, dvi, all in
1 html, etc...)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending & Embedding Python

2006-01-12 Thread Marco Meoni
About SWIG:
This program has a lot of commands...
In your opinion what is the best settings for my use?
Thanks...
Marco

-- 
http://mail.python.org/mailman/listinfo/python-list


XML Writer in wxPython

2006-01-12 Thread Marco Meoni
Have you ever write an XML Writer in wxPython? A Writer that from a GUI
can compose XML Files.
Thanks.
Marco.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Writer in wxPython

2006-01-16 Thread Marco Meoni
Could you post an example please?
Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Socket Programming HOWTO example

2006-01-16 Thread Marco Meoni
Hi. I read the Gordon McMillan's "Socket Programming Howto".
I tried to use the example in this howto but this doesn't work.
The code is class mysocket:
'''classe solamente dimostrativa
  - codificata per chiarezza, non per efficenza'''
def __init__(self, sock=None):
if sock is None:
self.sock = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
else:
self.sock = sock
def connect(host, port):
self.sock.connect((host, port))
def mysend(msg):
totalsent = 0
while totalsent < MSGLEN:
sent = self.sock.send(msg[totalsent:])
if sent == 0:
raise RuntimeError, \\
"connessione socket interrotta"
totalsent = totalsent + sent
def myreceive():
msg = ''
while len(msg) < MSGLEN:
chunk = self.sock.recv(MSGLEN-len(msg))
if chunk == '':
raise RuntimeError, \\
"connessione socket interrotta"
msg = msg + chunk
return msg
 
How can i use this?
Thanks all!
Marco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Writer in wxPython

2006-01-18 Thread Marco Meoni
i have to put the XML in a string. Is there a module with the XML
writing funcion?

-- 
http://mail.python.org/mailman/listinfo/python-list