summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-29 18:58:02 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-05-29 18:58:02 +0000
commitc04a8621abde66c598569c0e1177b10fdbfe52eb (patch)
treec379c3f0c5248e86a656d9c05536f6617e6a7264
parent279f51e960b0716098add300fb66d3be0a76c6d1 (diff)
downloadomegle-c04a8621abde66c598569c0e1177b10fdbfe52eb.tar.gz
omegle-c04a8621abde66c598569c0e1177b10fdbfe52eb.zip
cleanup
git-svn-id: http://xapek.org/svn/common/omegle@1048 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
-rw-r--r--injector.py (renamed from gui.py)6
-rw-r--r--omegle.py28
-rw-r--r--proxy.py11
3 files changed, 30 insertions, 15 deletions
diff --git a/gui.py b/injector.py
index 2af9f62..0934b1b 100644
--- a/gui.py
+++ b/injector.py
@@ -2,7 +2,7 @@ import urwid.curses_display
import urwid
import sys,time
-class Conversation(object):
+class InjectorWindow(object):
def __init__(self):
self.column1_edit = urwid.Edit(caption="Send: ")
self.column1_check = urwid.CheckBox("Link to other",state=True,on_state_change=self.on_link1_changed)
@@ -117,4 +117,6 @@ class Conversation(object):
def on_column2_disconnect(self,*args):
self.add_message("DEBUG: on_column2_disconnect")
-Conversation().main()
+class Injector(InjectorWindow):
+ pass
+Injector().main()
diff --git a/omegle.py b/omegle.py
index a5a07c1..ab64c09 100644
--- a/omegle.py
+++ b/omegle.py
@@ -37,6 +37,7 @@ class Timer(Thread):
self.event.set()
class RESTClient(object):
+ """Some routines used for calling the webservice"""
headers = {
"Host" : "omegle.com",
"Content-type": "application/x-www-form-urlencoded; charset=utf-8",
@@ -52,20 +53,21 @@ class RESTClient(object):
self.conn.request(method,path,params,RESTClient.headers)
resp = self.conn.getresponse()
self.conn_lock.release()
-
return resp
class OmegleChat(RESTClient):
def __init__(self,poll_interval=0.5,name=""):
RESTClient.__init__(self,'www.omegle.com')
- self.timer = Timer(self.events, poll_interval)
+ self.timer = Timer(self._events, poll_interval)
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__ + name)
self.is_confirmed = False #after getting a connection confirm
self.is_connected = False #after having self.id
def start(self):
+ """Starts a chat session. You have to wait until
+ is_confirmed is set (or use on_connect)"""
self.logger.debug("/start")
if self.is_connected:
self.logger.error("Already connected")
@@ -76,7 +78,7 @@ class OmegleChat(RESTClient):
if id.__len__() == 3:
self.id = id[1]
self.logger.info("Connected id=%s" % self.id)
- #Poll events
+ #start /events polling
self.timer.start()
self.is_connected = True
else:
@@ -84,11 +86,13 @@ class OmegleChat(RESTClient):
raise Exception("Bad response: %s" % body)
def disconnect(self):
+ """Close a chat session."""
self.logger.debug("disconnect()")
self.is_connected = False
self.timer.stop()
if self.is_confirmed:
self.is_confirmed = False
+ self.id = None
r = RESTClient.request(self,"POST", "/disconnect", urllib.urlencode({'id': self.id}))
body = r.read()
self.logger.debug("/disconnect sent. Read: %s" % body)
@@ -99,7 +103,7 @@ class OmegleChat(RESTClient):
self.is_confirmed = True
raise Exception("/disconnect; Bad response: %s" % body)
- def events(self):
+ def _events(self):
"""does use its own "HTTPConnection" because its called async from a thread"""
conn = httplib.HTTPConnection('www.omegle.com')
conn.request("POST",
@@ -108,10 +112,14 @@ class OmegleChat(RESTClient):
OmegleChat.headers)
r=conn.getresponse()
body=r.read()
- self.dispatch_event(conn,body)
+ self._dispatch_event(conn,body)
conn.close()
def send(self,msg):
+ """Send a message to the Stranger
+ Arguments:
+ msg -- the message - in utf8
+ """
#if a raw string given, assume its utf8
if msg.__class__ == str:
msg = msg.decode("utf8")
@@ -125,6 +133,7 @@ class OmegleChat(RESTClient):
raise Exception("/send; Bad response %s" % body)
def typing(self):
+ """Notify the Stranger that youre typing a message"""
r = RESTClient.request(self, "POST", "/typing", urllib.urlencode({'id':self.id}))
body = r.read()
if body != "win":
@@ -132,13 +141,14 @@ class OmegleChat(RESTClient):
raise Exception("/typing; Bad response %s" % body)
def stopped_typing(self):
+ """Notify the Stranger that youre stopped typing"""
r = RESTClient.request(self, "POST", "/stoppedtyping", urllib.urlencode({'id':self.id}))
body = r.read()
if body != "win":
self.logger.error("/stoppedtyping; Bad response %s" % body)
raise Exception("/stoppedtyping; Bad response %s" % body)
- def dispatch_event(self,conn,body):
+ def _dispatch_event(self,conn,body):
try:
data_set=json.read(body.decode("utf8"))
if not data_set:
@@ -167,16 +177,22 @@ class OmegleChat(RESTClient):
self.logger.error("Json ReadException. Body: %s" % body)
def on_message(self,message):
+ """To be overwritten"""
self.logger.info("<<< %s" % message)
def on_connect(self):
+ """To be overwritten"""
self.logger.info("Connection confirmed")
def on_typing(self):
+ """To be overwritten"""
self.logger.info("Stranger is typing")
def on_stopped_typing(self):
+ """To be overwritten"""
self.logger.info("Stranger stopped typing")
def on_disconnect(self):
+ """To be overwritten"""
self.logger.info("Stranger Disconnectet")
def on_wait(self):
+ """To be overwritten"""
self.logger.info("Server sent [\"waiting\"]")
def get_count():
diff --git a/proxy.py b/proxy.py
index 957b116..2ea2798 100644
--- a/proxy.py
+++ b/proxy.py
@@ -8,12 +8,6 @@ from omegle import OmegleChat
__all__ = ['OmegleProxyChat']
-colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33,
- "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, "black":39}
-
-
-
-
class OmegleProxyChat(OmegleChat):
"""Omegle class with link to other "partner" instance"""
def __init__(self,disconnect_event,name,color=0):
@@ -58,8 +52,11 @@ class OmegleProxyChat(OmegleChat):
if __name__ == "__main__":
+ colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33,
+ "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, "black":39}
+
logging.basicConfig(level=logging.DEBUG)
- print "press ctrl-c to abort"
+ logging.getLogger().info("press ctrl-c to abort")
event = Event()
A=OmegleProxyChat(event,"A",colors['red'])