Commits

Shuge Lee  committed a8b070e

fixed logs of bugs

  • Participants
  • Parent commits fae8fba

Comments (0)

Files changed (13)

File demos/demo_bot_daemon.py

 #!/usr/bin/env python
 import socket
 
+import commons
+
 from sipc_api import sipc
+from sipc import threadutils
 import demo_send_registration
 
 
         cmd = buf.strip()
 
         if cmd == "uname -a":
-            resp = sipc.commons.run(cmd)
+            resp = commons.run(cmd)
 
             from_uri = msg_obj.header.get_field_value("F")
             to_uri = from_uri
 ## un-comment to test auto add buddy by bot
 #sipc.add_buddy(user_obj, '1380013800')
 
-user_obj.reg_sock_keep_alive_t = sipc.commons.PeriodicExecutor(30, sipc.keep_alive, user_obj = user_obj)
+user_obj.reg_sock_keep_alive_t = threadutils.PeriodicExecutor(30, sipc.keep_alive, user_obj = user_obj)
 user_obj.reg_sock_keep_alive_t.start()
 
 

File demos/demo_periodic_executor.py

 def foo(*args, **kwargs):
     print time.time(), args, kwargs
 
-pt = sipc_api.sipc.commons.threadutils.PeriodicExecutor(2, foo, name='hello')
+pt = sipc_api.sipc.threadutils.PeriodicExecutor(2, foo, name='hello')
 pt.start()
 
 print 'foo'
+# TODO
+
+rm web.py dependencies
 
         packages = [
             "sipc",
-            "sipc.commons",
         ],
 
         install_requires = [

File sipc/captcha.py

         headers = {
             'Cookie' : 'ssic=%s' % self._ssi_cookie,
             "Connection" : "close",
-            "User-Agent" : "IIC2.0/PC %s" % sys_config.SysConfig.FETION_PROTOCOL_VERSION,
+            "User-Agent" : "IIC2.0/PC %s" % sys_config.SysConfig.FETION_CLIENT_VERSION,
             }
 
         httplib.HTTPConnection.response_class = http.HTTPResponse
 import os
 import sys
 import config
-import commons
+import utils
 
 logging.getLogger().setLevel(logging.DEBUG)
 LOGGING_FORMAT = '[%(asctime)10s] %(message)s'
 logging.basicConfig(format = LOGGING_FORMAT, datefmt = "%Y-%m-%d %H:%M:%S")
 
 
-app_path_prefix = os.path.join(commons.get_app_data_path(config.APP_NAME))
+app_path_prefix = os.path.join(utils.get_app_data_path(config.APP_NAME))
 log_file_path = os.path.join(app_path_prefix, "debug.log")
 file_ch = logging.FileHandler(log_file_path)
 file_ch.setLevel(logging.DEBUG)

File sipc/sipc_msg_customer.py

 import sipc_message
 import sipc_register
 import commons
+import xmlutils
 
 
 __all__ = [
         "d" : lambda key, val : ("presence_desc", val),
         "dt" : lambda key, val : ("device_type", val),
     }
-    d = commons.mapping_lxml_node_attrs_to_dict(pr_node, attr_name_list, kv_filters)
+    d = xmlutils.mapping_lxml_node_attrs_to_dict(pr_node, attr_name_list, kv_filters)
     return d
 
 def _parse_m_bn_p_node(p_node):
         "n" : lambda key, val : ("nickname", val),
         "su" : lambda key, val : ("uri", val),
     }
-    d = commons.mapping_lxml_node_attrs_to_dict(p_node, attr_name_list, kv_filters)
+    d = xmlutils.mapping_lxml_node_attrs_to_dict(p_node, attr_name_list, kv_filters)
     return d
 
 def _contact_list_data_need_save(contact_obj, new_contact_d):
             "relation-status" : lambda key, val : ("relation_status", int(val)),
             }
 
-        data = commons.mapping_lxml_node_attrs_to_dict(buddy_node, attr_name_list, kv_filters)
+        data = xmlutils.mapping_lxml_node_attrs_to_dict(buddy_node, attr_name_list, kv_filters)
 
         uri = data.get('uri')
         if uri:
 
         app_node = t[0]
         attr_name_list = ("user-id", "uri", "reason")
-        data = commons.mapping_lxml_node_attrs_to_dict(app_node, attr_name_list)
+        data = xmlutils.mapping_lxml_node_attrs_to_dict(app_node, attr_name_list)
         # ...
 
         return True
         kv_filters = {
             "desc" : lambda key, val: ("from_who", val),
             }
-        data = commons.mapping_lxml_node_attrs_to_dict(application_node, attr_name_list, kv_filters)
+        data = xmlutils.mapping_lxml_node_attrs_to_dict(application_node, attr_name_list, kv_filters)
         # ...
 
         return True
         if status != core.SIPCMessage.MSG_IS_COMPLETE:
             return remain
         
-        return ""
+        return ""

File sipc/sipc_register.py

     ]
 
 
-def _get_mac_addr():
-    """ Return the first network interface MAC address with format 'aa:bb:cc:dd:ee:ff'.
-
-    http://stackoverflow.com/questions/159137/getting-mac-address
-
-    Test environment:
-        - Linux 2.6.39.1-x86_64
-        - Darwin 10.8.0
-    """
-    resp = hex(uuid.getnode())[2:14]
-    buf = [resp[i : i + 2] for i in xrange(0, len(resp), 2)]
-    return ":".join(buf)
-
 def _generate_registration_req_resp(user_obj, digest):
     nonce = commons.cut(digest, 'nonce="', '"')
     key = commons.cut(digest, 'key="', '"')
     """ Download contact list from server if ignore_local_version is True,
     it seems there is a bug that contact list could not auto update,
     ignore_local_version option could fix it in quick and dirty way. """
-#    mac_addr = _get_mac_addr().replace(":", "")
-    mac_addr = "f81edfef3ca1"
+    mac_addr = commons.get_mac_addr().replace(":", "")
 
     if not user_obj.force_update_contact_list:
         personal_version = user_obj.personal["version"] or "0"
 
 def _get_digest(user_obj):
     sock = socket.socket()
+    
+    try:
+        sock.connect(("221.176.31.225", 8080))
+    except socket.error:
+        msg = "connect to SIP-C proxy server %s:%d failed" % (ip, port)
+        logging.error(msg)
+        return 
 
+    """
     sipc_proxy = getattr(user_obj.sys_config, "sipc_proxy", core.SIPC_PROXY)
     splits = sipc_proxy.split(":")
     ip, port = splits[0], int(splits[1])
+    print "sipc_proxy:", sipc_proxy
 
     try:
         sock.connect((ip, port))
         logging.warn(msg)
 
         sock.connect((ip, int(port)))
-
+        """
 
     user_obj.reg_sock = sock
     from_sid = user_obj.sid
         "F" : from_sid,
         "I" : call_id,
         "Q" : cseq,
-        "CN" : _generate_cnouce(),
-        "CL" : 'type="%s" ,version="%s"' % (device_type, sys_config.SysConfig.FETION_PROTOCOL_VERSION),
+        "CN" : _generate_cnouce().lower(),
+        "CL" : 'type="%s",version="%s"' % (device_type.lower(), sys_config.SysConfig.FETION_CLIENT_VERSION),
         }
 
     req_first_line = "%s fetion.com.cn SIP-C/4.0" % core.SIPC_METHOD_REGISTER
     CSeq header field, http://tools.ietf.org/html/rfc3261#section-8.1.1.5
     """
     msg_obj = _get_digest(user_obj)
-    # print "status ", msg_obj.status
-    # assert msg_obj.status == core.UNAUTHORIZED
+    assert msg_obj.status == core.UNAUTHORIZED
 
     digest = msg_obj.header.get_field_value("W")
     response = _generate_registration_req_resp(user_obj, digest)
     req = "GET %s?%s %s" % (parses.path, query, CRLF)
 
     headers = {
-        "User-Agent" : "IIC2.0/pc %s" % sys_config.SysConfig.FETION_PROTOCOL_VERSION,
+        "User-Agent" : "IIC2.0/pc %s" % sys_config.SysConfig.FETION_CLIENT_VERSION,
         "Host" : parses.netloc,
         }
 

File sipc/sys_config.py

 
 
 class SysConfig(commons.ooputils.DictLike):
-    FETION_PROTOCOL_VERSION = "4.0.2510"
+    FETION_CLIENT_VERSION = "4.7.3800"
     URL = "http://nav.fetion.com.cn/nav/getsystemconfig.aspx"
 
     LATEST_SYS_CONFIG_FILE_PATH = os.path.join(commons.get_app_data_path(config.APP_NAME), "latest_sys_config.json")
                 (self.servers_version or "",
                  self.parameters_version or "",
                  self.hints_version or "",
-                 "PC", SysConfig.FETION_PROTOCOL_VERSION, WINDOWS_NT_5_1)
+                 "PC", SysConfig.FETION_CLIENT_VERSION, WINDOWS_NT_5_1)
 
         headers = {
             "Accept-Encoding" : "compress, gzip",

File sipc/user_info.py

 
 import contact
 import commons
+import xmlutils
 
 __all__ = [
     'parse_client_node',
     client_node = t[0]
     attr_name_list = ("public-ip", "login-place", "last-login-ip",
                       "last-login-place", "last-login-time", "current-login-time")
-    d = commons.mapping_lxml_node_attrs_to_dict(client_node, attr_name_list)
+    d = xmlutils.mapping_lxml_node_attrs_to_dict(client_node, attr_name_list)
     client.update(**d)
 
     return client
         "impresa" : lambda key, val : ("impression", val),
     }
 
-    personal_d = commons.mapping_lxml_node_attrs_to_dict(personal_node, attr_name_list, kv_filters)
+    personal_d = xmlutils.mapping_lxml_node_attrs_to_dict(personal_node, attr_name_list, kv_filters)
     return personal_d
 
 
             "p" : lambda key, val : ("permission", val),
             "r" : lambda key, val : ("relation_status", int(val)),
         }
-        data = commons.mapping_lxml_node_attrs_to_dict(b_node, attr_name_list, kv_filters)
+        data = xmlutils.mapping_lxml_node_attrs_to_dict(b_node, attr_name_list, kv_filters)
         uri = data["uri"]
 
         # if contact A not only belongs to a buddy group, but also blacklist
             "u" : lambda key, val : ("uri", val),
             "i" : lambda key, val : ("user_id", val),
         }
-        d = commons.mapping_lxml_node_attrs_to_dict(i, attr_name_list, kv_filters)
+        d = xmlutils.mapping_lxml_node_attrs_to_dict(i, attr_name_list, kv_filters)
         uri = d["uri"]
 
         stranger = old_strangers.get(uri)
             "u" : lambda key, val : ("uri", val),
             "n" : lambda key, val : ("nickname", val),
         }
-        d = commons.mapping_lxml_node_attrs_to_dict(i, attr_name_list, kv_filters)
+        d = xmlutils.mapping_lxml_node_attrs_to_dict(i, attr_name_list, kv_filters)
         uri = d["uri"]
 
         bad_guy = old_bad_guys.get(uri)
 
     score_node = t[0]
     attr_name_list = ("value", "level", "level-score")
-    d = commons.mapping_lxml_node_attrs_to_dict(score_node, attr_name_list)
+    d = xmlutils.mapping_lxml_node_attrs_to_dict(score_node, attr_name_list)
     score.__dict__.update(**d)
 
     return score
             "month_limit" : lambda key, val: ("send_sms_%s" % key, int(val)),
             "month_count" : lambda key, val: ("send_sms_%s" % key, int(val)),
         }
-        d = commons.mapping_lxml_node_attrs_to_dict(frequency_node, attr_name_list, kv_filters)
+        d = xmlutils.mapping_lxml_node_attrs_to_dict(frequency_node, attr_name_list, kv_filters)
         quotas.update(**d)
 
     return quotas
 
     capability_list_node = t[0]
     attr_name_list = ("basic-caps", "contact-caps", "extended-caps")
-    d = commons.mapping_lxml_node_attrs_to_dict(capability_list_node, attr_name_list)
+    d = xmlutils.mapping_lxml_node_attrs_to_dict(capability_list_node, attr_name_list)
     cl_obj.__dict__.update(**d)
 
 
     contact_nodes = tree.xpath("/results/user-info/capability-list/contact")
     attr_name_list = ("carrier", "contact-caps")
     for i in contact_nodes:
-        d = commons.mapping_lxml_node_attrs_to_dict(i, attr_name_list)
+        d = xmlutils.mapping_lxml_node_attrs_to_dict(i, attr_name_list)
         cc_obj = CapabilityContact()
         cc_obj.__dict__.update(**d)
         cl_obj.contacts.append(cc_obj)
 def update_user_info_from_sipc_reg_resp_tree(tree, user_obj):
     parse_user_info_node(tree, user_obj)
 
-    user_obj.set_force_update_contact_list_at_next_time(False)
+    user_obj.set_force_update_contact_list_at_next_time(False)

File sipc/utils.py

     home = os.path.expandvars("$HOME")
     os_name = sys.platform
     if os_name in ('darwin', 'linux2'):
-        path = os.path.join(home, "Documents", "app_name")
+        path = os.path.join(home, "Documents", app_name)
     else:
         raise NotImplemented
 

File sipc/xmlutils.py

 import StringIO
 from lxml import etree
 from BeautifulSoup import BeautifulStoneSoup
-import web
-
+import commons
 
 __all__ = [
     "mapping_lxml_node_children_to_a_dict",
 
         val = element.text
         if val is not None:
-            val = web.safeunicode(element.text)
+            val = commons.strutils.safeunicode(element.text)
             val = val.strip()
-#            val = web.utils.strips(val, "\r\n")
-#            val = web.utils.strips(val, "\t")
-#            val = web.utils.strips(val, "\n")
+#            val = commons.strutils.strips(val, "\r\n")
+#            val = commons.strutils.strips(val, "\t")
+#            val = commons.strutils.strips(val, "\n")
 
             if val == "false":
                 val = False
         for item in items:
             key, val = item[0].replace("-", "_"), item[1]
 
-            val = web.safeunicode(val)
+            val = commons.strutils.safeunicode(val)
 
             if kv_filters and key in kv_filters:
                 key, val = kv_filters[key](key, val)
 
             key = name
             val = attrs[name]
-            val = web.safeunicode(val)
+            val = commons.strutils.safeunicode(val)
 
             if kv_filters and key in kv_filters:
                 key, val = kv_filters[key](key, val)
     except Exception:
         # We do use BeautifulStoneSoup here,
         # because of it throw exception about `ExpatError: not well-formed` sometimes.
-        buf = web.safeunicode(buf)
-#        buf = web.htmlunquote(buf)
+        buf = commons.strutils.safeunicode(buf)
+#        buf = commons.strutils.htmlunquote(buf)
         buf = BeautifulStoneSoup(''.join(buf)).prettify()
-        buf = web.safestr(buf)
+        buf = commons.strutils.safestr(buf)
 
         f = StringIO.StringIO(buf)
         tree = etree.parse(f)
 
 if __name__ == "__main__":
     import doctest
-    doctest.testmod()
+    doctest.testmod()