text
stringlengths
0
828
line = line.strip()
nb_indent = 0
while True:
if line.startswith(indent_txt):
nb_indent += 1
line = line[len(indent_txt):]
else:
break
output += (nb_indent * indent_txt) + washer.wash(line,
render_unallowed_tags=True) + linebreak_txt
nb_indent = 0
return output[:-1]"
4639,"def _print(self, text, color=None, **kwargs):
""""""print text with given color to terminal
""""""
COLORS = {
'red': '\033[91m{}\033[00m',
'green': '\033[92m{}\033[00m',
'yellow': '\033[93m{}\033[00m',
'cyan': '\033[96m{}\033[00m'
}
_ = COLORS[color]
six.print_(_.format(text), **kwargs)"
4640,"def _is_unique(self, name, path):
""""""verify if there is a project with given name or path
on the database
""""""
project = None
try:
project = Project.select().where(
(Project.name == name) |
(Project.path == path)
)[0]
except:
pass
return project is None"
4641,"def _path_is_valid(self, path):
""""""validates if a given path is:
- absolute,
- exists on current machine
- is a directory
""""""
VALIDATORS = [
(os.path.isabs, self._ERROR_PATH_NOT_ABSOLUTE),
(os.path.exists, self._ERROR_PATH_DOESNT_EXISTS),
(os.path.isdir, self._ERROR_PATH_NOT_A_DIR),
]
for validator in VALIDATORS:
func, str_err = validator
if not func(path):
self._print(str_err.format(path), 'red')
return
return True"
4642,"def add(self, name, path=None, **kwargs):
""""""add new project with given name and path to database
if the path is not given, current working directory will be taken
...as default
""""""
path = path or kwargs.pop('default_path', None)
if not self._path_is_valid(path):
return
if not self._is_unique(name, path):
p = Project.select().where(
(Project.name == name) |
(Project.path == path)
)[0]
self._print(self._ERROR_PROJECT_EXISTS.format(name, p.path), 'red')
return
Project.create(name=name, path=path)
self._print(self._SUCCESS_PROJECT_ADDED.format(name), 'green')"
4643,"def list(self, **kwargs):
""""""displays all projects on database
""""""
projects = Project.select().order_by(Project.name)
if len(projects) == 0:
self._print('No projects available', 'yellow')
return
for project in projects:
project_repr = self._PROJECT_ITEM.format(project.name, project.path)
row = '- {}'.format(self._PROJECT_ITEM.format(project.name, project.path))
six.print_(row)"
4644,"def parent_tags(self):
""""""Provides tags of all parent HTML elements.""""""
tags = set()
for addr in self._addresses:
if addr.attr == 'text':
tags.add(addr.element.tag)
tags.update(el.tag for el in addr.element.iterancestors())
tags.discard(HTMLFragment._root_tag)
return frozenset(tags)"
4645,"def involved_tags(self):
""""""Provides all HTML tags directly involved in this string.""""""