コード例 #1
0
ファイル: validator.py プロジェクト: petrvanblokland/Xierpa3
    def arg2Arg(cls, value):
        """
            Expand the argument if it contains keywords.
            These keywords cannot be tested because the value will change in time:

            v.arg2Arg('today')
            2006/3/4
            v.arg2Arg('thisday')
            11
            v.arg2Arg('thismonth')
            2
            v.arg2Arg('lastyear')
            2004
            v.arg2Arg('thisyear')
            2005
            v.arg2Arg('nextyear')
            2006
            
            >>> v = Validator()
            >>> v.arg2Arg('1234')
            '1234'
            >>> v.arg2Arg('  1234  ')
            '1234'
            >>> v.arg2Arg('infinite')
            '10.0e99'
        """
        if isinstance(value, basestring):
            value = value.strip()    # Remove trailing whitespace
            if value in ('today', 'now'):
                # Answer (year, month, day) tuple
                d = DateTime(date=value)
                return d.date2s(d.getdate(), 'dd/mm/yyyy')
            if value == 'thisday':
                return strftime("%d",localtime())
            if value == 'thismonth':
                return strftime("%m",localtime())
            if value == 'lastyear':
                return repr(int(strftime("%Y",localtime())) - 1)
            if value == 'thisyear':
                return strftime("%Y",localtime())
            if value == 'nextyear':
                return repr(int(strftime("%Y",localtime())) + 1)
            if value == 'infinite':
                return '10.0e99'
        return value
コード例 #2
0
ファイル: validator.py プロジェクト: thongnv/Xierpa3
    def arg2Arg(cls, value):
        """
            Expand the argument if it contains keywords.
            These keywords cannot be tested because the value will change in time:

            v.arg2Arg('today')
            2006/3/4
            v.arg2Arg('thisday')
            11
            v.arg2Arg('thismonth')
            2
            v.arg2Arg('lastyear')
            2004
            v.arg2Arg('thisyear')
            2005
            v.arg2Arg('nextyear')
            2006
            
            >>> v = Validator()
            >>> v.arg2Arg('1234')
            '1234'
            >>> v.arg2Arg('  1234  ')
            '1234'
            >>> v.arg2Arg('infinite')
            '10.0e99'
        """
        if isinstance(value, basestring):
            value = value.strip()  # Remove trailing whitespace
            if value in ('today', 'now'):
                # Answer (year, month, day) tuple
                d = DateTime(date=value)
                return d.date2s(d.getdate(), 'dd/mm/yyyy')
            if value == 'thisday':
                return strftime("%d", localtime())
            if value == 'thismonth':
                return strftime("%m", localtime())
            if value == 'lastyear':
                return repr(int(strftime("%Y", localtime())) - 1)
            if value == 'thisyear':
                return strftime("%Y", localtime())
            if value == 'nextyear':
                return repr(int(strftime("%Y", localtime())) + 1)
            if value == 'infinite':
                return '10.0e99'
        return value
コード例 #3
0
ファイル: baseclient.py プロジェクト: simons-design/Xierpa3
    def showStartLabel(self, port):
        u"""
        The <code>showStartLabel</code> method is used by the client to show the server information at startup.
        
        """
        print self.LINE
        date = str(DateTime(date='now'))
        print u'... Start %s on [%s:%s] %s' % (self, 'localhost', port, date)
        print self.LINE

        for siteName, theme in self.getThemes().items():
            siteName = siteName.encode('utf-8')
            print u'... %s "%s"' % (siteName, theme.title)
        print self.LINE
コード例 #4
0
# -*- coding: UTF-8 -*-
# -----------------------------------------------------------------------------
#    xierpa server
#    Copyright (c) 2014+  [email protected], www.petr.com, www.xierpa.com
#
#    X I E R P A  3
#    Distribution by the MIT License.
#
# -----------------------------------------------------------------------------
#
#    Contributed by Erik van Blokland and Jonathan Hoefler
#    Original from filibuster.
#
"""
        history
        Generally useful stuff should go here, see content for ideas
--------------------------------------------------------------------
3.0.0    - split all the content into babycontents
evb        - note: only one dictionary named 'content' allowed per module
        this limitation is to speed up loading
"""
from xierpa3.toolbox.dating import DateTime
__version__ = '3.0.0'
__author__ = "someone"
content = {
    'alphabet_caps': [
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
        'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    ],
    'alphabet_lc': [
コード例 #5
0
ファイル: validator.py プロジェクト: petrvanblokland/Xierpa3
    def isRange(cls, value, minrange, maxrange):
        """
        Range testing is inclusive on the margins
        minrange <= value <= maxrange
        So minrange == 10 and value == 10 is true
        Float values can be defined with comma's or periods.
        
        Minrange and maxrange are dates or numbers.
        Note that minrange is the relative number of days from today, if defined as number
        The maxrange is the relative number of days if defined as number.
        
            >>> v = Validator()
            >>> v.isRange('today', -2, 2)
            True
            >>> v.isRange('today', -100, 200)
            True
            >>> v.isRange('today', 100, 200)
            False
            >>> v.isRange('today', '3/3/2002', '3/12/2030')
            True
            >>> v.isRange('today', 'today', 'today')
            False
            >>> v.isRange('5/11/1988', '4/11/1988', '6/11/1988')
            True
            >>> v.isRange('5/11/1988', '4/11/2004', '6/11/2004')
            False
            >>> v.isRange('10/10/2015', 'today', '7200')
            True
            >>> v.isRange('10/10/2015', 'today', '720')
            False
            >>> v.isRange('50', '0', '100')
            True
            >>> v.isRange(50, 0, 100)
            True
            >>> v.isRange(-100, 50, 100)
            False
            >>> v.isRange(10,30,100)
            False
            >>> v.isRange('0.4',0,1)
            True
            >>> v.isRange('0,4','0,3','0,8')
            True
            >>> v.isRange('','0,3','0,8')
            False
            >>> v.isRange(None, None, None)
            False
        """
        if not value:
            return False
        value = cls.arg2Arg(value)
        minrange = cls.arg2Arg(minrange)                            # Allow conversion of 'today' or 'infinite'
        maxrange = cls.arg2Arg(maxrange)        
        
        if cls.isDate(value):                                        # Format is date string?

            d = DateTime(date=value)
            thisyear, thismonth, thisday = d.s2date(cls.arg2Arg('today'))    # Get totay for relative calculation
            year, month, day = d.s2date(value)
            
            if cls.isDate(minrange):                                # Minrange is defined as date?
                minyear, minmonth, minday = d.s2date(minrange)
            else:                                                    # Else it be relative number of days instead
                minyear, minmonth, minday = d.futureday(thisyear, thismonth, thisday, number=int(minrange))        

            if cls.isDate(maxrange):
                maxyear, maxmonth, maxday = d.s2date(maxrange)
            else:
                maxyear, maxmonth, maxday = d.futureday(thisyear, thismonth, thisday, number=int(maxrange))        

            if minyear < year < maxyear:                            # Precheck, to avoid the limit in 1970 < mktime < 2040
                return True
            if not (1970 < year < 2040):                            # Can't check other than this interval when using mktime in dating
                return False                                        # when on of the limits is same as range years. False to be sure
                
            # Now we have to check the dates, but still one of the ranges can be outside the 1970 < mktime < 2040 range
            # so we'll crop them on both limits, which is safe because we know that thisyear is already within the limits.
            
            return d.dates2difference((min(2040, max(1970, minyear)), minmonth, minday), (year, month, day)) > 0 and\
                   d.dates2difference((min(2040, max(1970, maxyear)), maxmonth, maxday), (year, month, day)) < 0
        else:
            try:
                if isinstance(minrange, basestring):
                    minrange = float(minrange.replace(',','.'))
                if isinstance(maxrange, basestring):
                    maxrange = float(maxrange.replace(',','.'))
                if isinstance(value, basestring):
                    value = float(value.replace(',','.'))
            except:
                return False  # Any error as with None or string, aswer false

        result = minrange <= value <= maxrange
        return result
コード例 #6
0
ファイル: validator.py プロジェクト: thongnv/Xierpa3
    def isRange(cls, value, minrange, maxrange):
        """
        Range testing is inclusive on the margins
        minrange <= value <= maxrange
        So minrange == 10 and value == 10 is true
        Float values can be defined with comma's or periods.
        
        Minrange and maxrange are dates or numbers.
        Note that minrange is the relative number of days from today, if defined as number
        The maxrange is the relative number of days if defined as number.
        
            >>> v = Validator()
            >>> v.isRange('today', -2, 2)
            True
            >>> v.isRange('today', -100, 200)
            True
            >>> v.isRange('today', 100, 200)
            False
            >>> v.isRange('today', '3/3/2002', '3/12/2030')
            True
            >>> v.isRange('today', 'today', 'today')
            False
            >>> v.isRange('5/11/1988', '4/11/1988', '6/11/1988')
            True
            >>> v.isRange('5/11/1988', '4/11/2004', '6/11/2004')
            False
            >>> v.isRange('10/10/2015', 'today', '7200')
            True
            >>> v.isRange('10/10/2015', 'today', '720')
            False
            >>> v.isRange('50', '0', '100')
            True
            >>> v.isRange(50, 0, 100)
            True
            >>> v.isRange(-100, 50, 100)
            False
            >>> v.isRange(10,30,100)
            False
            >>> v.isRange('0.4',0,1)
            True
            >>> v.isRange('0,4','0,3','0,8')
            True
            >>> v.isRange('','0,3','0,8')
            False
            >>> v.isRange(None, None, None)
            False
        """
        if not value:
            return False
        value = cls.arg2Arg(value)
        minrange = cls.arg2Arg(
            minrange)  # Allow conversion of 'today' or 'infinite'
        maxrange = cls.arg2Arg(maxrange)

        if cls.isDate(value):  # Format is date string?

            d = DateTime(date=value)
            thisyear, thismonth, thisday = d.s2date(
                cls.arg2Arg('today'))  # Get totay for relative calculation
            year, month, day = d.s2date(value)

            if cls.isDate(minrange):  # Minrange is defined as date?
                minyear, minmonth, minday = d.s2date(minrange)
            else:  # Else it be relative number of days instead
                minyear, minmonth, minday = d.futureday(thisyear,
                                                        thismonth,
                                                        thisday,
                                                        number=int(minrange))

            if cls.isDate(maxrange):
                maxyear, maxmonth, maxday = d.s2date(maxrange)
            else:
                maxyear, maxmonth, maxday = d.futureday(thisyear,
                                                        thismonth,
                                                        thisday,
                                                        number=int(maxrange))

            if minyear < year < maxyear:  # Precheck, to avoid the limit in 1970 < mktime < 2040
                return True
            if not (
                    1970 < year < 2040
            ):  # Can't check other than this interval when using mktime in dating
                return False  # when on of the limits is same as range years. False to be sure

            # Now we have to check the dates, but still one of the ranges can be outside the 1970 < mktime < 2040 range
            # so we'll crop them on both limits, which is safe because we know that thisyear is already within the limits.

            return d.dates2difference((min(2040, max(1970, minyear)), minmonth, minday), (year, month, day)) > 0 and\
                   d.dates2difference((min(2040, max(1970, maxyear)), maxmonth, maxday), (year, month, day)) < 0
        else:
            try:
                if isinstance(minrange, basestring):
                    minrange = float(minrange.replace(',', '.'))
                if isinstance(maxrange, basestring):
                    maxrange = float(maxrange.replace(',', '.'))
                if isinstance(value, basestring):
                    value = float(value.replace(',', '.'))
            except:
                return False  # Any error as with None or string, aswer false

        result = minrange <= value <= maxrange
        return result