# Path: xml2dict.py
# class XML2Dict(object):
#     @classmethod
#     def _parse_node(self, node):
#         node_tree = object_dict()
#         # Save attrs and text, hope there will not be a child with same name
#         if node.text:
#             node_tree.value = node.text
#         for (k, v) in node.attrib.items():
#             k, v = self._namespace_split(k, object_dict({'value':v}))
#             node_tree[k] = v
#         # Save childrens
#         for child in iter(node):
#             tag, tree = self._namespace_split(child.tag, self._parse_node(child))
#             if  tag not in node_tree:  # the first time, so store it in dict
#                 node_tree[tag] = tree
#                 continue
#             old = node_tree[tag]
#             if not isinstance(old, list):
#                 node_tree.pop(tag)
#                 node_tree[tag] = [old]  # multi times, so change old dict to a list
#             node_tree[tag].append(tree)  # add the new one
# 
#         return  node_tree
# 
#     @classmethod
#     def _namespace_split(self, tag, value):
#         """
#            Split the tag  '{http://cs.sfsu.edu/csc867/myscheduler}patients'
#              ns = http://cs.sfsu.edu/csc867/myscheduler
#              name = patients
#         """
#         result = re.compile("\{(.*)\}(.*)").search(tag)
#         if result:
#             # print(tag)
#             value.namespace, tag = result.groups()
#         return (tag, value)
# 
#     @classmethod
#     def parse(self, file):
#         """parse a xml file to a dict"""
#         f = open(file, 'r')
#         return self.fromstring(f.read())
# 
#     @classmethod
#     def fromstring(self, s):
#         """parse a string"""
#         t = ET.fromstring(s)
#         root_tag, root_tree = self._namespace_split(t.tag, self._parse_node(t))
#         return object_dict({root_tag: root_tree})


from _prototype import plugin_prototype
from cross_platform import *
from xml2dict import XML2Dict
import random
import time
import sys
import os
import sys
import string
import httplib2
import maclient_network

        cnt = 0
        _prt = lambda x: print(du8(x)) if reg_cnt != -0xe9 else None
        #logger.warning('如果连续注册遇到code 500\n请明天再试\n或者使用VPN或代理连接(MAClient会在启动时自动读取IE代理)')
        _prt('招待码 = %s' % invid)
        while True:
            po.cookie = ''
            po.post('check_inspection')
            if loc not in ['jp', 'my']:
                po.post('notification/post_devicetoken', postdata = 'S=nosessionid&login_id=&password=&app=and&token=')
            # s=raw_input('session: ').lstrip('S=').strip()
            # print po.cookie
            while True:
                uname, pwd = '', ''
                if reg_cnt > 0 or reg_cnt == -0xe9:#auto_mode or ubw mode
                    uname = ''.join([random.choice(string.letters + string.digits) for i in range(random.randrange(4,14))])
                    pwd = ''.join([random.choice(string.letters + string.digits) for i in range(random.randrange(8,14))])
                while len(uname) < 4 or len(uname) > 14:
                    uname = raw_input('user-name: ')
                while len(pwd) < 8 or len(pwd) > 14:
                    pwd = raw_input('password: ')
                if loc == 'sg':
                    p = 'email=%s@%s&invitation_id=%s&login_id=%s&param=&password=%s&password_confirm=%s&platform=1&param=%s' % (
                        uname, random.choice(['google.com', 'yahoo.com', 'live.com']), invid, uname, pwd, pwd, 
                        '35' + (''.join([str(random.randint(0, 9)) for i in range(10)]))
                        )
                else:
                    p = 'invitation_id=%s&login_id=%s&password=%s&param=%s' % (invid, uname, pwd, '35' + (''.join([str(random.randint(0, 9)) for i in range(10)])))
                # print maclient_network.encode_param(p)
                print(p)
                r, d = po.post('regist', postdata = p, extraheader = {'X-Forwarded-For':'.'.join([str(random.randrange(0,256)) for i in range(4)])})

# Path: xml2dict.py
# class XML2Dict(object):
#     @classmethod
#     def _parse_node(self, node):
#         node_tree = object_dict()
#         # Save attrs and text, hope there will not be a child with same name
#         if node.text:
#             node_tree.value = node.text
#         for (k, v) in node.attrib.items():
#             k, v = self._namespace_split(k, object_dict({'value':v}))
#             node_tree[k] = v
#         # Save childrens
#         for child in iter(node):
#             tag, tree = self._namespace_split(child.tag, self._parse_node(child))
#             if  tag not in node_tree:  # the first time, so store it in dict
#                 node_tree[tag] = tree
#                 continue
#             old = node_tree[tag]
#             if not isinstance(old, list):
#                 node_tree.pop(tag)
#                 node_tree[tag] = [old]  # multi times, so change old dict to a list
#             node_tree[tag].append(tree)  # add the new one
# 
#         return  node_tree
# 
#     @classmethod
#     def _namespace_split(self, tag, value):
#         """
#            Split the tag  '{http://cs.sfsu.edu/csc867/myscheduler}patients'
#              ns = http://cs.sfsu.edu/csc867/myscheduler
#              name = patients
#         """
#         result = re.compile("\{(.*)\}(.*)").search(tag)
#         if result:
#             # print(tag)
#             value.namespace, tag = result.groups()
#         return (tag, value)
# 
#     @classmethod
#     def parse(self, file):
#         """parse a xml file to a dict"""
#         f = open(file, 'r')
#         return self.fromstring(f.read())
# 
#     @classmethod
#     def fromstring(self, s):
#         """parse a string"""
#         t = ET.fromstring(s)
#         root_tag, root_tree = self._namespace_split(t.tag, self._parse_node(t))
#         return object_dict({root_tag: root_tree})


# Path: plugins/reg_gen.py
from _prototype import plugin_prototype
from cross_platform import *
from xml2dict import XML2Dict
import random
import time
import sys
import os
import sys
import string
import httplib2
import maclient_network

        cnt = 0
        _prt = lambda x: print(du8(x)) if reg_cnt != -0xe9 else None
        #logger.warning('如果连续注册遇到code 500\n请明天再试\n或者使用VPN或代理连接(MAClient会在启动时自动读取IE代理)')
        _prt('招待码 = %s' % invid)
        while True:
            po.cookie = ''
            po.post('check_inspection')
            if loc not in ['jp', 'my']:
                po.post('notification/post_devicetoken', postdata = 'S=nosessionid&login_id=&password=&app=and&token=')
            # s=raw_input('session: ').lstrip('S=').strip()
            # print po.cookie
            while True:
                uname, pwd = '', ''
                if reg_cnt > 0 or reg_cnt == -0xe9:#auto_mode or ubw mode
                    uname = ''.join([random.choice(string.letters + string.digits) for i in range(random.randrange(4,14))])
                    pwd = ''.join([random.choice(string.letters + string.digits) for i in range(random.randrange(8,14))])
                while len(uname) < 4 or len(uname) > 14:
                    uname = raw_input('user-name: ')
                while len(pwd) < 8 or len(pwd) > 14:
                    pwd = raw_input('password: ')
                if loc == 'sg':
                    p = 'email=%s@%s&invitation_id=%s&login_id=%s&param=&password=%s&password_confirm=%s&platform=1&param=%s' % (
                        uname, random.choice(['google.com', 'yahoo.com', 'live.com']), invid, uname, pwd, pwd, 
                        '35' + (''.join([str(random.randint(0, 9)) for i in range(10)]))
                        )
                else:
                    p = 'invitation_id=%s&login_id=%s&password=%s&param=%s' % (invid, uname, pwd, '35' + (''.join([str(random.randint(0, 9)) for i in range(10)])))
                # print maclient_network.encode_param(p)
                print(p)
                r, d = po.post('regist', postdata = p, extraheader = {'X-Forwarded-For':'.'.join([str(random.randrange(0,256)) for i in range(4)])})

                if(XML2Dict.fromstring(d).response.header.error.code != '0'):
