# 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 subprocess import Popen, PIPE
from cross_platform import *
from xml2dict import XML2Dict
import sys
import os
import re

# coding:utf-8
# start meta
__plugin_name__ = 'scratch carddeck from REAL client'
__author = 'fffonion'
__version__ = 0.42
hooks = {}
extra_cmd = {'scratch_carddeck':'scratch_carddeck', 'scc':'scratch_carddeck','check_debug':'check_debug','cd':'check_debug',
'read_decks':'read_decks','rd':'read_decks'}
# end meta
def tolist(obj):
    if not isinstance(obj, list):
        return [obj]
    else:
        return obj

def iter_printer(l, sep = '\n'):
    cnt = 1
    str = ''
    for e in l:
        str += '%d.%-10s%s' % (cnt, e.strip('\n'), (cnt % 3 and '' or sep))
        cnt += 1
    return str.decode('utf-8')

def read_decks(plugin_vals):
    def do(*args):
        if plugin_vals['loc'] == 'jp':

# 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/carddeck_edit.py
from _prototype import plugin_prototype
from subprocess import Popen, PIPE
from cross_platform import *
from xml2dict import XML2Dict
import sys
import os
import re

# coding:utf-8
# start meta
__plugin_name__ = 'scratch carddeck from REAL client'
__author = 'fffonion'
__version__ = 0.42
hooks = {}
extra_cmd = {'scratch_carddeck':'scratch_carddeck', 'scc':'scratch_carddeck','check_debug':'check_debug','cd':'check_debug',
'read_decks':'read_decks','rd':'read_decks'}
# end meta
def tolist(obj):
    if not isinstance(obj, list):
        return [obj]
    else:
        return obj

def iter_printer(l, sep = '\n'):
    cnt = 1
    str = ''
    for e in l:
        str += '%d.%-10s%s' % (cnt, e.strip('\n'), (cnt % 3 and '' or sep))
        cnt += 1
    return str.decode('utf-8')

def read_decks(plugin_vals):
    def do(*args):
        if plugin_vals['loc'] == 'jp':

            get=lambda x, y:XML2Dict.fromstring(x).response.body.roundtable_edit.deck[y - 1].deck_cards
