MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _read_password_file

Function _read_password_file

asyncpg/connect_utils.py:100–140  ·  view source on GitHub ↗
(passfile: pathlib.Path)

Source from the content-addressed store, hash-verified

98
99
100def _read_password_file(passfile: pathlib.Path) \
101 -> typing.List[typing.Tuple[str, ...]]:
102
103 passtab = []
104
105 try:
106 if not passfile.exists():
107 return []
108
109 if not passfile.is_file():
110 warnings.warn(
111 'password file {!r} is not a plain file'.format(passfile))
112
113 return []
114
115 if _system != 'Windows':
116 if passfile.stat().st_mode & (stat.S_IRWXG | stat.S_IRWXO):
117 warnings.warn(
118 'password file {!r} has group or world access; '
119 'permissions should be u=rw (0600) or less'.format(
120 passfile))
121
122 return []
123
124 with passfile.open('rt') as f:
125 for line in f:
126 line = line.strip()
127 if not line or line.startswith('#'):
128 # Skip empty lines and comments.
129 continue
130 # Backslash escapes both itself and the colon,
131 # which is a record separator.
132 line = line.replace(R'\\', '\n')
133 passtab.append(tuple(
134 p.replace('\n', R'\\')
135 for p in re.split(r'(?<!\\):', line, maxsplit=4)
136 ))
137 except IOError:
138 pass
139
140 return passtab
141
142
143def _read_password_from_pgpass(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected