<commit_before>#!/usr/bin/python 
from datetime import datetime, timedelta

from sfa.util.xml import XML, XpathFilter
from sfa.util.faults import InvalidRSpecElement, InvalidRSpec
from sfa.util.sfatime import SFATIME_FORMAT

from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements 
from sfa.rspecs.version_manager import VersionManager

class RSpec:
 
    def __init__(self, rspec="", version=None, user_options=None, ttl=60):
        if user_options is None: user_options={}
        self.header = '<?xml version="1.0"?>\n'
        self.template = """<RSpec></RSpec>"""
        self.version = None
        self.xml = XML()
        self.version_manager = VersionManager()
        self.user_options = user_options
        self.ttl = ttl
        self.elements = {}
        if rspec:
            if version:
                self.version = self.version_manager.get_version(version)
                self.parse_xml(rspec, version)
            else:
                self.parse_xml(rspec)
        elif version:
            self.create(version)
        else:
            raise InvalidRSpec("No RSpec or version specified. Must specify a valid rspec string or a valid version") 

    def create(self, version=None, ttl=60):
        """
        Create root element
        ttl: time to live in minutes, this will determine the expires tag of the RSpec
        """
        self.version = self.version_manager.get_version(version)
        self.namespaces = self.version.namespaces
        self.parse_xml(self.version.template, self.version) 
        now = datetime.utcnow()
        generated_ts = now.strftime(SFATIME_FORMAT)
        expires_ts = (now + timedelta(minutes=self.ttl)).strftime(SFATIME_FORMAT) 
        self.xml.set('expires', expires_ts)
        self.xml.set('generated', generated_ts)

    def parse_xml(self, xml, version=None):
        self.xml.parse_xml(xml)<commit_msg>SFA RSpec ttl param set expires tag to 60 min as default<commit_after>#!/usr/bin/python 
from datetime import datetime, timedelta

from sfa.util.xml import XML, XpathFilter
from sfa.util.faults import InvalidRSpecElement, InvalidRSpec
from sfa.util.sfatime import SFATIME_FORMAT

from sfa.rspecs.rspec_elements import RSpecElement, RSpecElements 
from sfa.rspecs.version_manager import VersionManager

class RSpec:
 
    def __init__(self, rspec="", version=None, user_options=None, ttl=None):
        if user_options is None: user_options={}
        self.header = '<?xml version="1.0"?>\n'
        self.template = """<RSpec></RSpec>"""
        self.version = None
        self.xml = XML()
        self.version_manager = VersionManager()
        self.user_options = user_options
        self.ttl = ttl
        self.elements = {}
        if rspec:
            if version:
                self.version = self.version_manager.get_version(version)
                self.parse_xml(rspec, version)
            else:
                self.parse_xml(rspec)
        elif version:
            self.create(version, ttl)
        else:
            raise InvalidRSpec("No RSpec or version specified. Must specify a valid rspec string or a valid version") 

    def create(self, version=None, ttl=None):
        """
        Create root element
        ttl: time to live in minutes, this will determine the expires tag of the RSpec
        """
        self.version = self.version_manager.get_version(version)
        self.namespaces = self.version.namespaces
        self.parse_xml(self.version.template, self.version) 
        now = datetime.utcnow()
        generated_ts = now.strftime(SFATIME_FORMAT)
        if ttl is None:
            ttl = 60
        expires_ts = (now + timedelta(minutes=ttl)).strftime(SFATIME_FORMAT)
        self.xml.set('expires', expires_ts)
        self.xml.set('generated', generated_ts)

    def parse_xml(self, xml, version=None):
        self.xml.parse_xml(xml)
{'fraction_non_alphanumeric': 0.09634809634809635, 'fraction_numerical': 0.003108003108003108, 'mean_word_length': 2.5825602968460113, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 2, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, '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': '4850588', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1134, 'n_words': 281}