Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def log(self, what):
- "Save a line in the log file."
- if not self.log_file:
- f = 'worklog.log'
- self.log_file = \
- codecs.open(f, encoding='utf-8', mode="a")
- self.log_file.write(what+'\r\n')
- self.log_file.flush()
- # Pa onda jedna od metoda:
- def set_encoding(self, in_enc):
- """Sets the encoding.
- in_enc is passed from the user.
- """
- # Encoding
- # - if not specified, use default OS settings
- self.log("Checking the encoding...")
- if in_enc == None or in_enc.lower() == 'default':
- if 'win' in sys.platform:
- self.ENC = 'utf-16'
- else:
- self.ENC = 'utf-8'
- mode = 'OS detection'
- else:
- self.ENC = in_enc
- mode = 'user'
- self.log("Encoding was set to %s by %s." % (self.ENC, mode))
- # Check files for encoding and see if all is OK
- try:
- self.log('Attempting to load file with %s...' % self.ENC)
- tmp = codecs.open(self.gloss_in, encoding = self.ENC).readlines()
- self.log('OK. File loaded correctly. Encodind is %s.' % self.ENC)
- except:
- msg = "Error: Encoding was set to %s by %s, " % (mode, self.ENC)
- msg = msg + 'but it did not load corretly.'
- self.log(msg)
- self.log('Inspecting the BOF...')
- self.ENC = self.bof_check(self.gloss_in)
- self.log('Discovered encoding is %s' % self.ENC)
- if self.ENC == None:
- self.log('Encoding cannot be None. Is this a text file? Exiting.')
- sys.exit(0)
- msg = ('Now it is detected by program and set to %s' % self.ENC)
- self.log(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement