コード例 #1
0
def make_replacements(replace):
    retval=[]
    for repl_line in replace.splitlines():
        line=repl_line
        try:
            (metakeys,regexp,replacement,condkey,condregexp)=(None,None,None,None,None)
            if "&&" in line:
                (line,conditional) = line.split("&&")
                (condkey,condregexp) = conditional.split("=>")
            if "=>" in line:
                parts = line.split("=>")
                if len(parts) > 2:
                    metakeys = map( lambda x: x.strip(), parts[0].split(",") )
                    (regexp,replacement)=parts[1:]
                else:
                    (regexp,replacement)=parts

            if regexp:
                regexp = re_compile(regexp,line)
                if condregexp:
                    condregexp = re_compile(condregexp,line)
                # A way to explicitly include spaces in the
                # replacement string.  The .ini parser eats any
                # trailing spaces.
                replacement=replacement.replace(SPACE_REPLACE,' ')
                retval.append([repl_line,metakeys,regexp,replacement,condkey,condregexp])
        except Exception as e:
            logger.error("Problem with Replacement Line:%s"%repl_line)
            raise exceptions.PersonalIniFailed(e,'replace_metadata unpacking failed',repl_line)
#            raise
    # print("replace lines:%s"%len(retval))
    return retval
コード例 #2
0
ファイル: story.py プロジェクト: PlushBeaver/FanFicFare
def make_replacements(replace):
    retval = []
    for repl_line in replace.splitlines():
        line = repl_line
        try:
            (metakeys, regexp, replacement, condkey, condregexp) = (None, None, None, None, None)
            if "&&" in line:
                (line, conditional) = line.split("&&")
                (condkey, condregexp) = conditional.split("=>")
            if "=>" in line:
                parts = line.split("=>")
                if len(parts) > 2:
                    metakeys = map(lambda x: x.strip(), parts[0].split(","))
                    (regexp, replacement) = parts[1:]
                else:
                    (regexp, replacement) = parts

            if regexp:
                regexp = re_compile(regexp, line)
                if condregexp:
                    condregexp = re_compile(condregexp, line)
                # A way to explicitly include spaces in the
                # replacement string.  The .ini parser eats any
                # trailing spaces.
                replacement = replacement.replace(SPACE_REPLACE, " ")
                retval.append([repl_line, metakeys, regexp, replacement, condkey, condregexp])
        except Exception as e:
            logger.error("Problem with Replacement Line:%s" % repl_line)
            raise exceptions.PersonalIniFailed(e, "replace_metadata unpacking failed", repl_line)
    #            raise
    return retval
コード例 #3
0
ファイル: story.py プロジェクト: iceshipping/FanFicFare
def make_replacements(replace):
    retval=[]
    for line in replace.splitlines():
        # print("replacement line:%s"%line)
        (metakeys,regexp,replacement,condkey,condregexp)=(None,None,None,None,None)
        if "&&" in line:
            (line,conditional) = line.split("&&")
            (condkey,condregexp) = conditional.split("=>")
        if "=>" in line:
            parts = line.split("=>")
            if len(parts) > 2:
                metakeys = map( lambda x: x.strip(), parts[0].split(",") )
                (regexp,replacement)=parts[1:]
            else:
                (regexp,replacement)=parts

        if regexp:
            regexp = re_compile(regexp,line)
            if condregexp:
                condregexp = re_compile(condregexp,line)
            # A way to explicitly include spaces in the
            # replacement string.  The .ini parser eats any
            # trailing spaces.
            replacement=replacement.replace(SPACE_REPLACE,' ')
            retval.append([metakeys,regexp,replacement,condkey,condregexp])
    return retval
コード例 #4
0
def make_replacements(replace):
    retval = []
    for line in replace.splitlines():
        # print("replacement line:%s"%line)
        (metakeys, regexp, replacement, condkey,
         condregexp) = (None, None, None, None, None)
        if "&&" in line:
            (line, conditional) = line.split("&&")
            (condkey, condregexp) = conditional.split("=>")
        if "=>" in line:
            parts = line.split("=>")
            if len(parts) > 2:
                metakeys = map(lambda x: x.strip(), parts[0].split(","))
                (regexp, replacement) = parts[1:]
            else:
                (regexp, replacement) = parts

        if regexp:
            regexp = re_compile(regexp, line)
            if condregexp:
                condregexp = re_compile(condregexp, line)
            # A way to explicitly include spaces in the
            # replacement string.  The .ini parser eats any
            # trailing spaces.
            replacement = replacement.replace(SPACE_REPLACE, ' ')
            retval.append([metakeys, regexp, replacement, condkey, condregexp])
    return retval
コード例 #5
0
 def __init__(self, line):
     if "=~" in line:
         (self.keys, self.match) = line.split("=~")
         self.match = self.match.replace(SPACE_REPLACE, ' ')
         self.regex = re_compile(self.match, line)
     elif "!~" in line:
         (self.keys, self.match) = line.split("!~")
         self.match = self.match.replace(SPACE_REPLACE, ' ')
         self.regex = re_compile(self.match, line)
         self.negate = True
     elif "==" in line:
         (self.keys, self.match) = line.split("==")
         self.match = self.match.replace(SPACE_REPLACE, ' ')
     elif "!=" in line:
         (self.keys, self.match) = line.split("!=")
         self.match = self.match.replace(SPACE_REPLACE, ' ')
         self.negate = True
     self.keys = map(lambda x: x.strip(), self.keys.split(","))
コード例 #6
0
ファイル: story.py プロジェクト: PlushBeaver/FanFicFare
 def __init__(self, line):
     if "=~" in line:
         (self.keys, self.match) = line.split("=~")
         self.match = self.match.replace(SPACE_REPLACE, " ")
         self.regex = re_compile(self.match, line)
     elif "!~" in line:
         (self.keys, self.match) = line.split("!~")
         self.match = self.match.replace(SPACE_REPLACE, " ")
         self.regex = re_compile(self.match, line)
         self.negate = True
     elif "==" in line:
         (self.keys, self.match) = line.split("==")
         self.match = self.match.replace(SPACE_REPLACE, " ")
     elif "!=" in line:
         (self.keys, self.match) = line.split("!=")
         self.match = self.match.replace(SPACE_REPLACE, " ")
         self.negate = True
     self.keys = map(lambda x: x.strip(), self.keys.split(","))
コード例 #7
0
 def get_filename_safe_metadata(self,pattern=None):
     origvalues = self.getAllMetadata()
     values={}
     if not pattern:
         pattern = re_compile(self.getConfig("output_filename_safepattern",
                                             r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),
                              "output_filename_safepattern")
     for k in origvalues.keys():
         if k == 'formatext': # don't do file extension--we set it anyway.
             values[k]=self.getMetadata(k)
         else:
             values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))
     return values
コード例 #8
0
ファイル: story.py プロジェクト: gcomyn/FanFicFare
 def get_filename_safe_metadata(self,pattern=None):
     origvalues = self.getAllMetadata()
     values={}
     if not pattern:
         pattern = re_compile(self.getConfig("output_filename_safepattern",
                                             r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),
                              "output_filename_safepattern")
     for k in origvalues.keys():
         if k == 'formatext': # don't do file extension--we set it anyway.
             values[k]=self.getMetadata(k)
         else:
             values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))
     return values
コード例 #9
0
ファイル: story.py プロジェクト: iceshipping/FanFicFare
    def formatFileName(self,template,allowunsafefilename=True):
        values = origvalues = self.getAllMetadata()
        # fall back default:
        if not template:
            template="${title}-${siteabbrev}_${storyId}${formatext}"

        if not allowunsafefilename:
            values={}
            pattern = re_compile(self.getConfig("output_filename_safepattern",r"[^a-zA-Z0-9_\. \[\]\(\)&'-]+"),"output_filename_safepattern")
            for k in origvalues.keys():
                values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))

        return string.Template(template).substitute(values).encode('utf8')
コード例 #10
0
    def formatFileName(self,template,allowunsafefilename=True):
        values = origvalues = self.getAllMetadata()
        # fall back default:
        if not template:
            template="${title}-${siteabbrev}_${storyId}${formatext}"

        if not allowunsafefilename:
            values={}
            pattern = re_compile(self.getConfig("output_filename_safepattern",r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),"output_filename_safepattern")
            for k in origvalues.keys():
                if k == 'formatext': # don't do file extension--we set it anyway.
                    values[k]=self.getMetadata(k)
                else:
                    values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))

        return string.Template(template).substitute(values).encode('utf8')
コード例 #11
0
ファイル: story.py プロジェクト: PlushBeaver/FanFicFare
    def formatFileName(self, template, allowunsafefilename=True):
        values = origvalues = self.getAllMetadata()
        # fall back default:
        if not template:
            template = "${title}-${siteabbrev}_${storyId}${formatext}"

        if not allowunsafefilename:
            values = {}
            pattern = re_compile(
                self.getConfig("output_filename_safepattern", r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),
                "output_filename_safepattern",
            )
            for k in origvalues.keys():
                if k == "formatext":  # don't do file extension--we set it anyway.
                    values[k] = self.getMetadata(k)
                else:
                    values[k] = re.sub(pattern, "_", removeAllEntities(self.getMetadata(k)))

        return string.Template(template).substitute(values).encode("utf8")