Debian Codegraph @

nixio/util/names.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Copyright © 2016, German Neuroinformatics Node (G-Node)
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted under the terms of the BSD License. See
8 # LICENSE file in the root of the Project.
9
10
11 def sanitizer(name):
12 """
13 Sanitizes a string supposed to be an entity name. That is,
14 invalid characters like slashes are substituted with underscores.
15
16 :param name: A string representing the name.
17
18 :returns: The sanitized name.
19 :rtype: str
20 """
21 return name.replace("/", "_")
22
23
24 def check(name):
25 """
26 Checks a string whether is needs to be sanitized.
27
28 :param name: The name.
29
30 :returns: True if the name is valid, false otherwise.
31 :rtype: bool
32 """
33 if isinstance(name, bytes):
34 name = name.decode()
35 return "/" not in name