def register_credentials(self, credentials=None, user=None, user_file=None, password=None, password_file=None):
<EOL>if credentials is not None:<EOL><INDENT>self.credentials = credentials<EOL><DEDENT>else:<EOL><INDENT>self.credentials = {}<EOL>if user:<EOL><INDENT>self.credentials["<STR_LIT:user>"] = user<EOL><DEDENT>elif user_file:<EOL><INDENT>with open(user_file, "<STR_LIT:r>") as of:<EOL><INDENT>pattern = re.compile("<STR_LIT>")<EOL>for l in of:<EOL><INDENT>if re.match(pattern, l):<EOL><INDENT>l = l[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL>self.credentials["<STR_LIT:user>"] = re.sub(pattern, "<STR_LIT>", l)<EOL><DEDENT><DEDENT><DEDENT>if self.credentials["<STR_LIT:user>"][<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:">' andself.credentials["<STR_LIT:user>"][-<NUM_LIT:1>:] == '<STR_LIT:">':<EOL><INDENT>self.credentials["<STR_LIT:user>"] = self.credentials["<STR_LIT:user>"][<NUM_LIT:1>:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if password:<EOL><INDENT>self.credentials["<STR_LIT:password>"] = password<EOL><DEDENT>elif password_file:<EOL><INDENT>with open(password_file, "<STR_LIT:r>") as of:<EOL><INDENT>pattern = re.compile("<STR_LIT>")<EOL>for l in of:<EOL><INDENT>if re.match(pattern, l):<EOL><INDENT>l = l[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL>self.credentials["<STR_LIT:password>"] =re.sub(pattern, "<STR_LIT>", l)<EOL><DEDENT><DEDENT><DEDENT>if self.credentials["<STR_LIT:password>"][<NUM_LIT:0>:<NUM_LIT:1>] == '<STR_LIT:">' andself.credentials["<STR_LIT:password>"][-<NUM_LIT:1>:] == '<STR_LIT:">':<EOL><INDENT>self.credentials["<STR_LIT:password>"] =self.credentials["<STR_LIT:password>"][<NUM_LIT:1>:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if "<STR_LIT:user>" in self.credentials and "<STR_LIT:password>" in self.credentials:<EOL><INDENT>c = self.credentials["<STR_LIT:user>"] + "<STR_LIT::>" + self.credentials["<STR_LIT:password>"]<EOL>self.credentials["<STR_LIT>"] = b64encode(c.encode()).decode("<STR_LIT:ascii>")<EOL><DEDENT><DEDENT>
Helper method to store username and password