<commit_before>###########################################################
#
# Copyright (c) 2005, Southpaw Technology
#                     All Rights Reserved
#
# PROPRIETARY INFORMATION.  This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ["HashPanelWdg"]

import os, types, re
from pyasm.common import Xml, XmlException, Common, TacticException, Environment, jsondumps
from pyasm.biz import Project
from pyasm.security import Security
from pyasm.search import Search, SearchType
from pyasm.web import WebEnvironment, DivWdg

from tactic.ui.common import BaseRefreshWdg, WidgetClassHandler


class HashPanelWdg(BaseRefreshWdg):

    def get_args_keys(cls):
        return {
        'hash': 'hash used to build a widget'
        }
    get_args_keys = classmethod(get_args_keys)



    def get_display(my):

        hash = my.kwargs.get("hash")

        top = my.top
        widget = my.get_widget_from_hash(hash, kwargs=my.kwargs)
        top.add(widget)
        return top




    def build_widget(cls, options):
        class_name = options.get('class_name')
        if not class_name:
            class_name = 'tactic.ui.panel.ViewPanelWdg'
        else:
            del(options['class_name'])

        widget = Common.create_from_class_path(class_name, kwargs=options)
        return widget
    build_widget = classmethod(build_widget)



    def get_url_from_hash(cls, hash):

        import re
        p = re.compile("^/(\w+)")
        m = p.search(hash)
        if not m:
            print "Cannot parse hash[%s]" % hash
            return None
        key = m.groups()[0]

        # skip links because it is reserved
        if key == 'link':
            return None

        # look up the expression
        search = Search("config/url")
        search.add_filter("url", "/%s/%%"%key, "like")
        search.add_filter("url", "/%s"%key)
        search.add_where("or")
        sobject = search.get_sobject()

        return sobject

    get_url_from_hash = classmethod(get_url_from_hash)



    def _get_flags(cls, xml, sobject=None, force_no_index=False, kwargs={}):
        use_index = kwargs.get("use_index")
        if use_index in [True, 'true']:
            use_index = True
        elif use_index in [False, 'false']:
            use_index = False

        use_admin = kwargs.get("use_admin")
        if use_admin in [True, 'true']:
            use_admin = True
        elif use_admin in [False, 'false']:
            use_admin = False


        use_sidebar = kwargs.get("use_sidebar")
        if use_sidebar in [False, 'false']:
            use_sidebar = False
        elif use_admin in [True, 'true']:
            use_sidebar = True


        if use_index is not None or use_admin is not None:
            pass

        elif force_no_index in [True, 'true']:
            use_index = False
        else:
            use_index = sobject.get_value("index", no_exception=True)
            if not use_index:
                use_index = xml.get_value("/element/@index");
                if use_index in ['true', True]:
                    use_index = True
                else:
                    use_index = False

            use_admin = sobject.get_value("admin", no_exception=True)
            if not use_admin:
                use_admin = xml.get_value("/element/@admin");
                if use_admin in ['true', True]:
                    use_admin = True
                else:
                    use_admin = False

                use_sidebar = xml.get_value("/element/@sidebar");
                if use_sidebar in ['false', False]:
                    use_sidebar = False
                else:
                    use_sidebar = True

        return use_index, use_admin, use_sidebar

    _get_flags = classmethod(_get_flags)




    def _get_predefined_url(cls, key, hash):
 
        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")
            
            if not link:
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                '''For usernames with at most one period
                # you can only see your personal links
                user = Environment.get_user_name()
                if user == parts[0]:
                    personal = True
                elif parts[1]:
                    if user == "%s.%s" % (parts[0], parts[1]):    
                        personal = True
                '''

                ''' Checking for username when user
                    has any number of periods in username ''' 
                user = Environment.get_user_name()
                
                def is_personal(user, parts):
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        
                        if user == acc:
                            return  True
                    return False
<commit_msg>Removed unnessary code.<commit_after>###########################################################
#
# Copyright (c) 2005, Southpaw Technology
#                     All Rights Reserved
#
# PROPRIETARY INFORMATION.  This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ["HashPanelWdg"]

import os, types, re
from pyasm.common import Xml, XmlException, Common, TacticException, Environment, jsondumps
from pyasm.biz import Project
from pyasm.security import Security
from pyasm.search import Search, SearchType
from pyasm.web import WebEnvironment, DivWdg

from tactic.ui.common import BaseRefreshWdg, WidgetClassHandler


class HashPanelWdg(BaseRefreshWdg):

    def get_args_keys(cls):
        return {
        'hash': 'hash used to build a widget'
        }
    get_args_keys = classmethod(get_args_keys)



    def get_display(my):

        hash = my.kwargs.get("hash")

        top = my.top
        widget = my.get_widget_from_hash(hash, kwargs=my.kwargs)
        top.add(widget)
        return top




    def build_widget(cls, options):
        class_name = options.get('class_name')
        if not class_name:
            class_name = 'tactic.ui.panel.ViewPanelWdg'
        else:
            del(options['class_name'])

        widget = Common.create_from_class_path(class_name, kwargs=options)
        return widget
    build_widget = classmethod(build_widget)



    def get_url_from_hash(cls, hash):

        import re
        p = re.compile("^/(\w+)")
        m = p.search(hash)
        if not m:
            print "Cannot parse hash[%s]" % hash
            return None
        key = m.groups()[0]

        # skip links because it is reserved
        if key == 'link':
            return None

        # look up the expression
        search = Search("config/url")
        search.add_filter("url", "/%s/%%"%key, "like")
        search.add_filter("url", "/%s"%key)
        search.add_where("or")
        sobject = search.get_sobject()

        return sobject

    get_url_from_hash = classmethod(get_url_from_hash)



    def _get_flags(cls, xml, sobject=None, force_no_index=False, kwargs={}):
        use_index = kwargs.get("use_index")
        if use_index in [True, 'true']:
            use_index = True
        elif use_index in [False, 'false']:
            use_index = False

        use_admin = kwargs.get("use_admin")
        if use_admin in [True, 'true']:
            use_admin = True
        elif use_admin in [False, 'false']:
            use_admin = False


        use_sidebar = kwargs.get("use_sidebar")
        if use_sidebar in [False, 'false']:
            use_sidebar = False
        elif use_admin in [True, 'true']:
            use_sidebar = True


        if use_index is not None or use_admin is not None:
            pass

        elif force_no_index in [True, 'true']:
            use_index = False
        else:
            use_index = sobject.get_value("index", no_exception=True)
            if not use_index:
                use_index = xml.get_value("/element/@index");
                if use_index in ['true', True]:
                    use_index = True
                else:
                    use_index = False

            use_admin = sobject.get_value("admin", no_exception=True)
            if not use_admin:
                use_admin = xml.get_value("/element/@admin");
                if use_admin in ['true', True]:
                    use_admin = True
                else:
                    use_admin = False

                use_sidebar = xml.get_value("/element/@sidebar");
                if use_sidebar in ['false', False]:
                    use_sidebar = False
                else:
                    use_sidebar = True

        return use_index, use_admin, use_sidebar

    _get_flags = classmethod(_get_flags)




    def _get_predefined_url(cls, key, hash):
 
        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")
            
            if not link:
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()
                
                def is_personal(user, parts):
                    '''See if parts contains period
                       seperated form of username.'''
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

{'fraction_non_alphanumeric': 0.10156395457084341, 'fraction_numerical': 0.0013032954757028485, 'mean_word_length': 1.606891531181752, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597626', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2815, 'n_words': 813}