text stringlengths 0 828 |
|---|
:param prefix_removed: prefix of the removed line |
:param suffix_removed: suffix of the removed line |
:param prefix_added: prefix of the added line |
:param suffix_added: suffix of the added line |
:return: string with the comparison of the records |
:rtype: string |
"""""" |
import difflib |
differ = difflib.Differ() |
result = [prefix] |
for line in differ.compare(modified.splitlines(), original.splitlines()): |
if line[0] == ' ': |
# Mark as unchanged |
result.append( |
prefix_unchanged + line[2:].strip() + suffix_unchanged) |
elif line[0] == '-': |
# Mark as removed |
result.append(prefix_removed + line[2:].strip() + suffix_removed) |
elif line[0] == '+': |
# Mark as added/modified |
result.append(prefix_added + line[2:].strip() + suffix_added) |
result.append(suffix) |
return '\n'.join(result)" |
4216,"def escape_latex(text): |
r""""""Escape characters of given text. |
This function takes the given text and escapes characters |
that have a special meaning in LaTeX: # $ % ^ & _ { } ~ \ |
"""""" |
text = unicode(text.decode('utf-8')) |
CHARS = { |
'&': r'\&', |
'%': r'\%', |
'$': r'\$', |
'#': r'\#', |
'_': r'\_', |
'{': r'\{', |
'}': r'\}', |
'~': r'\~{}', |
'^': r'\^{}', |
'\\': r'\textbackslash{}', |
} |
escaped = """".join([CHARS.get(char, char) for char in text]) |
return escaped.encode('utf-8')" |
4217,"def _copy_attr(self, module, varname, cls, attrname=None): |
"""""" |
Copies attribute from module object to self. Raises if object not of expected class |
Args: |
module: module object |
varname: variable name |
cls: expected class of variable |
attrname: attribute name of self. Falls back to varname |
"""""" |
if not hasattr(module, varname): |
raise RuntimeError(""Variable '{}' not found"".format(varname)) |
obj = getattr(module, varname) |
if not isinstance(obj, cls): |
raise RuntimeError( |
""Expecting fobj to be a {}, not a '{}'"".format(cls.__name__, obj.__class__.__name__)) |
if attrname is None: |
attrname = varname |
setattr(self, attrname, obj)" |
4218,"def __check_to_permit(self, entry_type, entry_filename): |
""""""Applying the filter rules."""""" |
rules = self.__filter_rules[entry_type] |
# Should explicitly include? |
for pattern in rules[fss.constants.FILTER_INCLUDE]: |
if fnmatch.fnmatch(entry_filename, pattern): |
_LOGGER_FILTER.debug(""Entry explicitly INCLUDED: [%s] [%s] "" |
""[%s]"", |
entry_type, pattern, entry_filename) |
return True |
# Should explicitly exclude? |
for pattern in rules[fss.constants.FILTER_EXCLUDE]: |
if fnmatch.fnmatch(entry_filename, pattern): |
_LOGGER_FILTER.debug(""Entry explicitly EXCLUDED: [%s] [%s] "" |
""[%s]"", |
entry_type, pattern, entry_filename) |
return False |
# Implicitly include. |
_LOGGER_FILTER.debug(""Entry IMPLICITLY included: [%s] [%s]"", |
entry_type, entry_filename) |
return True" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.