반응형
반응형

 

escape , encodeURIComponent 차이

 

 

escape()와 encodeURIComponent()는 모두 문자열을 인코딩하는 JavaScript 함수이지만, 사용 목적과 인코딩 방식에서 중요한 차이가 있습니다. 웹 환경에서 데이터를 안전하게 전송하기 위해 주로 encodeURIComponent()를 사용하고, escape()는 더 이상 권장되지 않습니다.

 

주요 차이점 요약표

특징 escape() encodeURIComponent()
목적 HTML 문자열 인코딩 (구식, 비권장) URL 컴포넌트 (값, 경로) 인코딩 (권장)
공백 인코딩 + 또는 %20 (브라우저마다 다름, 비일관적) 항상 %20 (표준)
한글/유니코드 %uxxxx (비표준, UTF-8과 호환 안 됨) UTF-8 기반 %xx (표준, 대부분의 웹 환경과 호환)
특수 문자 /, @, *, + 등을 인코딩하지 않음 &, =, ?, #, / 등 URL 특수 문자도 인코딩
현재 상태 더 이상 사용 권장되지 않음 표준이며 널리 사용됨
반응형
반응형

https://pypi.org/project/chardet/

 

Project description

Chardet: The Universal Character Encoding Detector

 
 
 
Detects
  • ASCII, UTF-8, UTF-16 (2 variants), UTF-32 (4 variants)
  • Big5, GB2312, EUC-TW, HZ-GB-2312, ISO-2022-CN (Traditional and Simplified Chinese)
  • EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP (Japanese)
  • EUC-KR, ISO-2022-KR, Johab (Korean)
  • KOI8-R, MacCyrillic, IBM855, IBM866, ISO-8859-5, windows-1251 (Cyrillic)
  • ISO-8859-5, windows-1251 (Bulgarian)
  • ISO-8859-1, windows-1252, MacRoman (Western European languages)
  • ISO-8859-7, windows-1253 (Greek)
  • ISO-8859-8, windows-1255 (Visual and Logical Hebrew)
  • TIS-620 (Thai)

Note

Our ISO-8859-2 and windows-1250 (Hungarian) probers have been temporarily disabled until we can retrain the models.

Requires Python 3.7+.

반응형
반응형

[VS Code] 인코딩 변경

VS Code 사용하다보면 웹페이지 특성상  UTF-8 또는 EUC-KR 이 있는데, 

자동으로 되어 있어도 페이지와 맞지 않는 인코딩이 선택될때가 있다. 

 

F1 키를 입력하거나, 오른쪽 하단의 인코딩 정보를 클릭하면 아래 이미지처럼 Reopne with Encoding 이 나온다. 

그러면 그 중에 맞는 인코딩을 선택하면 된다. 

반응형
반응형

[PYTHON] 파일 인코딩 관련

 

UTF-8

UTF-8-SIG

""" 
    인코딩 정보
"""
import os
import sys 
 
 
#작업하는 경로(위치)가 어디인지 확인
#print(os.getcwd())
prePath_in = "./Project/" 
prePath_out = "./Project/" 



#1. 기본 내용적기

# 기본 텍스트 신규 입력
file = open("test.txt", "w")
file.write("내용입력")
file.close()

# 한글깨짐 방지 ENCODING UTF-8
file = open("test.txt", "w", encoding="UTF-8")
file.write("내용입력")
file.close()

# 한글깨짐 방지2 ENCODING UTF-8
# txt는 UTF-8로도 충분한데 csv는 UTF-8로만 하면 읽을땐 다른걸로 읽을 경우 깨짐 현상 발생
file = open("test.csv", "w", encoding="UTF-8-sig")
file.write("test,test,test\n")
file.write("잘되나,안된다,오된다\n")
file.close()

# 참고
# Permission denied: 'test.csv' 가 나온다
# 파일 열고 있어서 수정할 수 없다는거다. 꺼주자.

# 추가 입력
file = open("test.txt", "a")
file.write("추가 내용입력")
file.close()


# 읽기
file = open("test.txt", "r", encoding="UTF-8")
print(file.read())
file.close()

# with 함수 : open & close 포함 
with open("test.txt", "w", encoding="UTF-8") as file:
    file.write("내용입력")
with open("test.txt", "r", encoding="UTF-8") as file:
    print(file.read())
 

 

#2. print 한거 txt 파일에 넣기

# sys.stdout 함수 사용하여 log 저장하기
f = open('test.txt','w', encoding='utf-8') # 로그 저장할 file open
sys.stdout = f
print("내용입력")
sys.stdout = sys.__stdout__   # 원래의 stdout으로 복구
f.close()                     # 로그 파일 닫기

#이렇게 해도 되긴 하는데.. 프로그램이 종료 안되면 문제가 생길듯?
sys.stdout = open('test.txt','w', encoding='utf-8')
print("내용입력")
반응형
반응형

[JEUS 8] response charset 변경하기 페이지 인코딩 변경

webApplication/WEB-INF/jeus-web-dd.xml 을 만듭니다.

 
<?xml version="1.0" encoding="UTF-8"?> 
<jeus-web-dd xmlns="http://www.tmaxsoft.com/xml/ns/jeus"> 
<context-path>/euckr</context-path> 
<encoding> 
<response-encoding> 
<default>EUC-KR</default> 
</response-encoding> 
</encoding> 
</jeus-web-dd>
 

 

자 이렇게 되면
받는 쪽 body 로 제우스는 EUC-KR의 인코딩 형태로 html 을 던져 줍니다.

출처:https://ipex.tistory.com/entry/JEUS-8-response-charset-변경하기-페이지-인코딩-변경[깍돌이]

----------------------------------------------------------------------------------------------------------------------------
 http://blog.naver.com/hwanwhat81/221181267297 
ja 로 jeus admin(관리자 모드 접속)하여

applist 하면 container 정보들이 출력..
jeus 홈디렉토리 config 파일에 가보면 서비스 디렉토리 안에 container list 가 존재한다.
한글깨짐 현상이 발생하는 컨테이너로 가보면
WEBmain.xml 이 존재.

vi 로 들어가서 편집해 준다.  

<context-group>
        <group-name>MyGroup</group-name>
        <encoding>
            <request-url-encoding>
                <default>utf-8</default>
                <forced>utf-8</forced>
            </request-url-encoding>
            <request-encoding>
                <default>utf-8</default>
                <forced>utf-8</forced>
            </request-encoding>
            <response-encoding>
                <default>utf-8</default>
                <forced>utf-8</forced>
            </response-encoding>
        </encoding>
생략 ....
</context-group> 



----------------------------------------------------------------------------------------------------------------------------
file.encoding ansi_x3.4-1968

분명히 utf-8로 셋팅 되었는데 Jeus는 가끔 미쳐서 파일 인코딩을 제대로 인지 못하는 경우가 있다.

String fileEncoding=System.getProperty("file.encoding");

이럴 경우 Jeus의 설정 파일에서( JEUSMain.xml ) 컨테이너 설정에 -Dfile.encoding=UTF-8 를 추가 해야 한다.

출처: https://lahuman.jabsiri.co.kr/57 [lahuman & jabsiri 노트]

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

https://waspro.tistory.com/183

 

[JEUS] Encoding 설정에 따른 출력 Test

본 포스팅은 Encoding 관련 우선순위 테스트입니다. Request Encoding, Response Encoding 각각 우선순위에 대한 테스트를 수행할 예정입니다. 먼저 Request Encoding 우선순위 테스트입니다. JEUS의 Encoding JEU..

waspro.tistory.com

 

반응형
반응형

https://www.tensorflow.org/api_docs/python/tf/compat


Module: tf.compat

Module tf.compat

Functions for Python 2 vs. 3 compatibility.

Conversion routines

In addition to the functions below, as_str converts an object to a str.

Types

The compatibility module also provides the following types:

  • bytes_or_text_types
  • complex_types
  • integral_types
  • real_types

Members

as_bytes(...): 바이트 또는 유니 코드를 bytesutf-8 인코딩을 사용하여 텍스트 로 변환합니다 .

as_str(...): 바이트 또는 유니 코드를 bytesutf-8 인코딩을 사용하여 텍스트 로 변환합니다 .

as_str_any(...)str와 같이 변환 str(value)하지만 as_strfor를 사용 합니다 bytes.

as_text(...): 주어진 인수를 유니 코드 문자열로 반환합니다.


Constant bytes_or_text_types

Constant complex_types

Constant integral_types

Constant real_types

Defined in tensorflow/python/util/compat.py.


반응형

+ Recent posts