filters.py :  » Business-Application » hylaPEx » hylapex » library » ftp » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » hylaPEx 
hylaPEx » hylapex » library » ftp » filters.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import read_conf

FILTER_TYPE_FILE = 1
FILTER_TYPE_SQL = 2

#View
DONE_VIEW = 0
RCV_VIEW = 1
SEND_VIEW  = 2

LSTSTRVIEW = ("done", "recv", "send")

class HylapexFilters(object):
    """ Filter object interface
    """
    def __init__(self, filter_type, *args, **kw):
        """
        """
        super(HylapexFilters, self).__init__()
        
        self._alreadyClose = False

        if filter_type == FILTER_TYPE_FILE:
            self._StartFilterFile(*args, **kw)
        elif filter_type == FILTER_TYPE_SQL:
            self._StartFilterSQL(*args, **kw)
        else:
            raise ValueError

    #
    # Init 
    #
    
    #File methods
    def _StartFilterFile(self, *args, **kw):
        """
        """
        file_path = kw.get("file_path")
        self._opt_file = read_conf.conf_parser(file_path,'filters')
        if self._opt_file.exist():
            def_dict = {"filter_list_send": "","filter_list_done": "",
                        "filter_list_recv": "",
                        "case_sensitive": "0"}
            self._opt_file.init_vals(def_dict)
        
    #SQL methods
    def _StartFilterSQL(self, *args, **kw):
        raise NotImplementedError
    
    #
    # Return methods
    #
    
    #File methods
    
    def GetFiltersOnlyView(self):
        """ Return the dict with the data that can view
        """
        return self._GetFilterByType("only_view")
        
    def GetFiltersNotView(self):
        """ Return the dict with the data that cannot view
        """
        return self._GetFilterByType("not_view")

    def GetFiltersOnlyViewByCol(self, view, col):
        """ Return the dict with the data that can view
        """
        return self._GetFilterByType("only_view")[view][col]
        
    def GetFiltersNotViewByCol(self, view, col):
        """ Return the dict with the data that cannot view
        """
        return self._GetFilterByType("not_view")[view][col]
    
    def _GetFilterByType(self, typ):
        all_dict = {}
        dRet = {}
        for view, list_view in enumerate(LSTSTRVIEW):
            lst = self._opt_file.getList("filter_list_" + list_view)
            if lst == ['']: lst = []
            for col in lst:
                curr_f = "%s_%s" % (list_view, col)
                
                if not typ in self._opt_file.options(curr_f): 
                    print typ, self._opt_file.options(curr_f)
                    print "no option not_view for filter %s at %s" % (col, list_view)
                    lstView = []
                else:
                    lstView = self._opt_file.getList(typ, curr_f)
                dRet[int(col)] = lstView
            
            all_dict[view] = dRet
            dRet = {}
        return all_dict
    
    def GetCaseSensitive(self):
        """ Return if I'm case sensitive
        """
        return self._opt_file.getint("case_sensitive")
    
    def Close(self):
        if self._alreadyClose: return
        self._opt_file.exit()
        self._alreadyClose = True
    
    def __del__(self):
        if self._alreadyClose: return
        self._opt_file.exit()
        self._alreadyClose = True
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.