Python 2.7 embedded with Marmalade C++ middle ware
I've embedded python 2.7 into my mobile program using Marmalade C++ middle ware (arm gcc). I can run most of the standard modules and 3rd party libraries.
- ( some source here: https://github.com/guyburton/python-loves-marmalade )
- (I'll upload my changes when this is fixed)
- ( module attribute dump script here: http://code.activestate.com/recipes/137951-dump-all-the-attributes-of-an-object/ )
When I try to import socket.py ( making sure not to run in the home directory) it says _socket is missing methods:
socket:
>>> import socket
File "/pythonHome/Lib/socket.py", line 229, in <module>
[0xfa0] FILE: s3eFileOpen('/pythonHome/Lib/socket.py', 'rb') succeeded
p.__doc__ = getattr(_realsocket,_m).__doc__
AttributeError: type object '_socket.socket' has no attribute 'getpeername'
>>> import os
>>> os.chdir("/tmp")
[0xfa0] IWCRT: chdir: '/' -> '/tmp'
>>> import socket
AttributeError: type object '_socket.socket' has no attribute 'getpeername'
>>> from socket import *
AttributeError: type object '_socket.socket' has no attribute 'getpeername'
After many problems with the socket module, it finally compiles and I can import the _socket c module (displays all methods available):
_socket:
>>> import _socket
>>> print (os.path.dirname(_socket.__file__))
AttributeError: 'module' object has no attribute '__file__'
>>> print (dir("_socket"))
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> dumpMod.dumpObj(_socket)
Documentation string: """Implementation module for socket operations. See
the socket module for documentation."""
Built-in Methods: fromfd, getaddrinfo, getdefaulttimeout, gethostbyaddr
gethostbyname, gethostbyname_ex, gethostname
getnameinfo, getprotobyname, getservbyname
getservbyport, htonl, htons, inet_aton, inet_ntoa
inet_ntop, inet_pton, ntohl, ntohs, setdefaulttimeout
__name__ _socket
__package__ None
EDIT :: Here's a link that compares normal _socket attributes to my compiled _socket version: http://www.diffchecker.com/di6k3fsc
EDIT I've isolated the function throwing the error from socket.py ( I subtracted getpeername to check all the other functions, they're fine):
import _socket
_socketmethods = (
'bind', 'connect', 'connect_ex', 'fileno', 'listen', 'getsockname','getsockopt','setsockopt','sendall', 'setblocking','settimeout', 'gettimeout', 'shutdown')
for _m in _socketmethods:
print(getattr(_socket.socket,_m).__doc__)
= output ( minus 'getpeername' method)
bind(address)
Bind the socket to a local address. For IP sockets, the address is a
pair (host, port); the host must refer to the local host. For raw packet
sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])
connect(address)
Connect the socket to a remote address. For IP sockets, the address
is a pair (host, port).
connect_ex(address) -> errno
This is like connect(address), but returns an error code (the errno value)
instead of raising an exception when an error occurs.
fileno() -> integer
Return the integer file descriptor of the socket.
listen(backlog)
Enable a server to accept connections. The backlog argument must be at
least 1; it specifies the number of unaccepted connection that the system
will allow before refusing new connections.
getsockname() -> address info
Return the address of the local endpoint. For IP sockets, the address
info is a pair (hostaddr, port).
getsockopt(level, option[, buffersize]) -> value
Get a socket option. See the Unix manual for level and option.
If a nonzero buffersize argument is given, the return value is a
string of that length; otherwise it is an integer.
setsockopt(level, option, value)
Set a socket option. See the Unix manual for level and option.
The value argument can either be an integer or a string.
sendall(data[, flags])
Send a data string to the socket. For the optional flags
argument, see the Unix manual. This calls send() repeatedly
until all data is sent. If an error occurs, it's impossible
to tell how much data has been sent.
setblocking(flag)
Set the socket to blocking (flag is true) or non-blocking (false).
setblocking(True) is equivalent to settimeout(None);
setblocking(False) is equivalent to settimeout(0.0).
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
gettimeout() -> timeout
Returns the timeout in floating seconds associated with socket
operations. A timeout of None indicates that timeouts on socket
operations are disabled.
shutdown(flag)
Shut down the reading side of the socket (flag == SHUT_RD), the writing side
of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).
Added getpeername, the only one with a problem
>>> import _socket
>>> print(getattr(_socket.socket,'getpeername').__doc__)
AttributeError: type object '_socket.socket' has no attribute 'getpeername'
Thoughts?
Could it still be a python path issue?
setenv in c++
Another missing dependent module? ( selectmodule.c is also included)
Since The compiled module is embedded in a libary containing the enterpreter aswell, and there is no file. do I need to modify socket.py...?problems with getaddrinfo.c? getnameinfo.c ? >> problems with socketmodule.c?