# Path: pymicro/external/StarFile.py
# class StarList(list):
#     def __getitem__(self,args):
#         if isinstance(args,(int,slice)):
#             return super(StarList,self).__getitem__(args)
#         elif isinstance(args,tuple) and len(args)>1:   #extended comma notation
#             return super(StarList,self).__getitem__(args[0]).__getitem__(args[1:])
#         else:
#             return super(StarList,self).__getitem__(args[0])
# 
#     def __str__(self):
#         return "SL("+super(StarList,self).__str__() + ")"


    from cStringIO import StringIO
    from io import StringIO
    from urllib import urlopen         # for arbitrary opening
    from urlparse import urlparse, urljoin
    from urllib.request import urlopen
    from urllib.parse import urlparse, urljoin
from . import StarFile
from .StarFile import StarList  #put in global scope for exec statement
    from .drel import drel_runtime  #put in global scope for exec statement
from copy import copy          #must be in global scope for exec statement
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
    from . import TypeContentsParser as t
import re,sys
    import numpy                   #put in global scope for exec statement
        import traceback
        import numpy
                        self[f].overwrite = False
                    # remove the old head
                    del self[from_cat_head]
                    print('Semantic merge: %d defs reparented from %s to %s' % (len(child_frames),from_cat_head,merging_cat))
                else:  #imported category is only child
                    from_frame = import_from[target_key]['_definition.id'] #so we can find it
                    child_frame = [d for d in self.keys() if self[d]['_definition.id']==from_frame][0]
                    self[child_frame]['_name.category_id'] = merging_cat
                    print('Semantic merge: category for %s : now %s' % (from_frame,merging_cat))
            # it will never happen again...
            del self[parent_block]["_import.get"]

    def resolve_path(self,file_loc):
        url_comps = urlparse(file_loc)
        if url_comps[0]: return file_loc    #already full URI
        new_url = urljoin(self.my_uri,file_loc)
        #print("Transformed %s to %s for import " % (file_loc,new_url))
        return new_url

    def ddlm_import_light(self,parent_block,import_from,import_target,target_key,file_loc,mode='All'):
        """Register the imported dictionaries but do not alter any definitions. `parent_block`
        contains the id of the block that is importing. `import_target` is the block that
        should be imported. `import_from` is the CifFile that contains the definitions."""
        if mode == 'contents':   #merge attributes only
            self[parent_block].add_dict_cache(file_loc,import_from)
        elif mode =="full":
             # Check for Head merging Head
            if self[parent_block].get('_definition.class','Datum')=='Head' and \
               import_target.get('_definition.class','Datum')=='Head':
                   head_to_head = True

# Path: pymicro/external/StarFile.py
# class StarList(list):
#     def __getitem__(self,args):
#         if isinstance(args,(int,slice)):
#             return super(StarList,self).__getitem__(args)
#         elif isinstance(args,tuple) and len(args)>1:   #extended comma notation
#             return super(StarList,self).__getitem__(args[0]).__getitem__(args[1:])
#         else:
#             return super(StarList,self).__getitem__(args[0])
# 
#     def __str__(self):
#         return "SL("+super(StarList,self).__str__() + ")"


# Path: pymicro/external/CifFile_module.py
    from cStringIO import StringIO
    from io import StringIO
    from urllib import urlopen         # for arbitrary opening
    from urlparse import urlparse, urljoin
    from urllib.request import urlopen
    from urllib.parse import urlparse, urljoin
from . import StarFile
from .StarFile import StarList  #put in global scope for exec statement
    from .drel import drel_runtime  #put in global scope for exec statement
from copy import copy          #must be in global scope for exec statement
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
        from .drel import drel_ast_yacc
        from .drel import py_from_ast
    from . import TypeContentsParser as t
import re,sys
    import numpy                   #put in global scope for exec statement
        import traceback
        import numpy

                        self[f].overwrite = False
                    # remove the old head
                    del self[from_cat_head]
                    print('Semantic merge: %d defs reparented from %s to %s' % (len(child_frames),from_cat_head,merging_cat))
                else:  #imported category is only child
                    from_frame = import_from[target_key]['_definition.id'] #so we can find it
                    child_frame = [d for d in self.keys() if self[d]['_definition.id']==from_frame][0]
                    self[child_frame]['_name.category_id'] = merging_cat
                    print('Semantic merge: category for %s : now %s' % (from_frame,merging_cat))
            # it will never happen again...
            del self[parent_block]["_import.get"]

    def resolve_path(self,file_loc):
        url_comps = urlparse(file_loc)
        if url_comps[0]: return file_loc    #already full URI
        new_url = urljoin(self.my_uri,file_loc)
        #print("Transformed %s to %s for import " % (file_loc,new_url))
        return new_url

    def ddlm_import_light(self,parent_block,import_from,import_target,target_key,file_loc,mode='All'):
        """Register the imported dictionaries but do not alter any definitions. `parent_block`
        contains the id of the block that is importing. `import_target` is the block that
        should be imported. `import_from` is the CifFile that contains the definitions."""
        if mode == 'contents':   #merge attributes only
            self[parent_block].add_dict_cache(file_loc,import_from)
        elif mode =="full":
             # Check for Head merging Head
            if self[parent_block].get('_definition.class','Datum')=='Head' and \
               import_target.get('_definition.class','Datum')=='Head':
                   head_to_head = True

            else: