'''
    
References & Background Reading: 
* https://en.wikipedia.org/wiki/UTF-8
* https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)
* https://en.wikipedia.org/wiki/Windows-1252

* http://www.ietf.org/rfc/rfc3629.txt

* http://www.unicode.org/faq/
* http://unicode.org/faq/utf_bom.html

* https://unicodebook.readthedocs.io/guess_encoding.html

* https://www.cl.cam.ac.uk/~mgk25/ucs/man-utf-8.html
* https://www.cl.cam.ac.uk/~mgk25/ucs/utf-8-history.txt
* https://www.cl.cam.ac.uk/~mgk25/unicode.html

* https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/

* http://kunststube.net/encoding/


* https://www.w3.org/International/questions/qa-what-is-encoding
* https://www.w3.org/International/questions/qa-choosing-encodings

* https://www.w3schools.com/charsets/ref_html_utf8.asp

* http://xmlsoft.org/encoding.html


* https://docs.python.org/3/howto/unicode.html
* https://docs.python.org/3/library/codecs.html
* https://docs.python.org/3/c-api/unicode.html

'''

import codecs
try:
    f = codecs.open("test.txt", encoding='utf-8', errors='strict')
    for line in f:
        pass
    print("Valid utf-8")
except UnicodeDecodeError:
    print("invalid utf-8")
