-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
executable file
·59 lines (46 loc) · 1.44 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# encoding: utf-8
# Revisión 2019 (a Python 3 y base64): Pablo Ventura
# Revisiones 2013-2014 Carlos Bederián
# Revisión 2011 Nicolás Wolovick
# Copyright 2008-2010 Natalia Bidart y Daniel Moisset
# $Id: constants.py 388 2011-03-22 14:20:06Z nicolasw $
DEFAULT_DIR = 'testdata'
DEFAULT_ADDR = '0.0.0.0' # 0.0.0.0 representa todas las IPv4 del server
DEFAULT_PORT = 19500
MAX_CLIENT = 5
CMD_TIMEOUT = 5000
NEWLINE = '\n'
EOL = '\r\n'
CODE_OK = 0
BAD_EOL = 100
BAD_REQUEST = 101
INTERNAL_ERROR = 199
INVALID_COMMAND = 200
INVALID_ARGUMENTS = 201
FILE_NOT_FOUND = 202
BAD_OFFSET = 203
error_messages = {
CODE_OK: "OK",
# 1xx: Errores fatales (no se pueden atender más pedidos)
BAD_EOL: "BAD EOL",
BAD_REQUEST: "BAD REQUEST",
INTERNAL_ERROR: "INTERNAL SERVER ERROR",
# 2xx: Errores no fatales (no se pudo atender este pedido)
INVALID_COMMAND: "NO SUCH COMMAND",
INVALID_ARGUMENTS: "INVALID ARGUMENTS FOR COMMAND",
FILE_NOT_FOUND: "FILE NOT FOUND",
BAD_OFFSET: "OFFSET EXCEEDS FILE SIZE",
}
def valid_status(s):
return s in list(error_messages.keys())
def fatal_status(s):
assert valid_status(s)
return 100 <= s < 200
VALID_CHARS = set(".-_")
for i in range(ord('A'), ord('Z') + 1):
VALID_CHARS.add(chr(i))
for i in range(ord('a'), ord('z') + 1):
VALID_CHARS.add(chr(i))
for i in range(ord('0'), ord('9') + 1):
VALID_CHARS.add(chr(i))
COMMANDS = ["get_file_listing", "get_metadata", "get_slice", "quit"]