Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jharms
Created August 16, 2017 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jharms/219660807fc1b103c4235d1565c3e768 to your computer and use it in GitHub Desktop.
Save jharms/219660807fc1b103c4235d1565c3e768 to your computer and use it in GitHub Desktop.
Working Jython and Python Slack Client
# /opt/jython/Lib/_socket.py
SOCK_DGRAM = 1
SOCK_STREAM = 2
SOCK_RAW = 3 # not supported
SOCK_RDM = 4 # not supported
SOCK_SEQPACKET = 5 # not supported
SOL_SOCKET = 0xFFFF
IPPROTO_AH = 51 # not supported
IPPROTO_DSTOPTS = 60 # not supported
IPPROTO_ESP = 50 # not supported
IPPROTO_FRAGMENT = 44 # not supported
IPPROTO_GGP = 3 # not supported
IPPROTO_HOPOPTS = 0 # not supported
IPPROTO_ICMP = 1 # not supported
IPPROTO_ICMPV6 = 58 # not supported
IPPROTO_IDP = 22 # not supported
IPPROTO_IGMP = 2 # not supported
IPPROTO_IP = 0
IPPROTO_IPV4 = 4 # not supported
IPPROTO_IPV6 = 41 # not supported
IPPROTO_MAX = 256 # not supported
IPPROTO_ND = 77 # not supported
IPPROTO_NONE = 59 # not supported
IPPROTO_PUP = 12 # not supported
IPPROTO_RAW = 255 # not supported
IPPROTO_ROUTING = 43 # not supported
IPPROTO_TCP = 6
IPPROTO_UDP = 17
SOL_TCP = 6 # Jonathan Harms
class SlackRequest(object):
def __init__(self, proxies=None):
# __name__ returns 'slackclient.slackrequest', we only want 'slackclient'
client_name = __name__.split('.')[0]
client_version = __version__ # Version is returned from version.py
# Construct the user-agent header with the package info, Python version and OS version.
self.default_user_agent = {
"client": "{0}/{1}".format(client_name, client_version),
"python": "Jython/Jonathan Harms",
"system": "{0}/{1}".format(platform.system(), platform.release())
}
self.custom_user_agent = None
self.proxies = proxies
# /opt/jython/Lib/socket.py
from _socket import (
socket, error, herror, gaierror, timeout, has_ipv6,
create_connection,
getdefaulttimeout,
setdefaulttimeout,
getfqdn,
gethostbyaddr,
gethostbyname,
gethostbyname_ex,
gethostname,
getprotobyname,
getservbyname,
getservbyport,
AF_UNSPEC,
AF_INET,
AF_INET6,
AI_PASSIVE,
AI_CANONNAME,
AI_NUMERICHOST,
AI_V4MAPPED,
AI_ALL,
AI_ADDRCONFIG,
AI_NUMERICSERV,
EAI_NONAME,
EAI_SERVICE,
EAI_ADDRFAMILY,
NI_NUMERICHOST,
NI_NUMERICSERV,
NI_NOFQDN,
NI_NAMEREQD,
NI_DGRAM,
NI_MAXSERV,
NI_IDN,
NI_IDN_ALLOW_UNASSIGNED,
NI_IDN_USE_STD3_ASCII_RULES,
NI_MAXHOST,
SHUT_RD,
SHUT_WR,
SHUT_RDWR,
SOCK_DGRAM,
SOCK_STREAM,
SOCK_RAW,
SOCK_RDM,
SOCK_SEQPACKET,
SOCK_RDM,
SOCK_SEQPACKET,
SOL_SOCKET,
# not supported, but here for apparent completeness
IPPROTO_AH,
IPPROTO_DSTOPTS,
IPPROTO_ESP,
IPPROTO_FRAGMENT,
IPPROTO_GGP,
IPPROTO_HOPOPTS,
IPPROTO_ICMP,
IPPROTO_ICMPV6,
IPPROTO_IDP,
IPPROTO_IGMP,
IPPROTO_IP, # supported
# not supported
IPPROTO_IPV4,
IPPROTO_IPV6,
IPPROTO_MAX,
IPPROTO_ND,
IPPROTO_NONE,
IPPROTO_PUP,
IPPROTO_RAW,
IPPROTO_ROUTING,
IPPROTO_TCP, # supported
IPPROTO_UDP, # supported
SOL_TCP, # Jonathan Harms
# supported
SO_BROADCAST,
SO_KEEPALIVE,
SO_LINGER,
SO_RCVBUF,
SO_REUSEADDR,
SO_SNDBUF,
SO_TIMEOUT,
TCP_NODELAY,
# pseudo options
@jharms
Copy link
Author

jharms commented Aug 16, 2017

To get Slack working under Jython 2.7.0 you need to fix 3 things:

  1. set the constant SOL_TCP to 6 in _socket.py
  2. import SOL_TCP from _socket.py in socket.py
  3. change the user-agent header so it's not trying to use the version module in the slackrequest module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment