Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Ip2region
提交
561cdd83
I
Ip2region
项目概览
int
/
Ip2region
上一次同步 12 个月
通知
19
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Ip2region
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
561cdd83
编写于
2月 01, 2023
作者:
狮
狮子的魂
提交者:
GitHub
2月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #286 from leolin49/master
raise the error for python maker
上级
187ed333
4be7192c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
21 deletion
+13
-21
maker/python/xdb/maker.py
maker/python/xdb/maker.py
+13
-21
未找到文件。
maker/python/xdb/maker.py
浏览文件 @
561cdd83
...
...
@@ -114,7 +114,7 @@ class Maker:
# Write header buffer to file
self
.
dst_handle
.
write
(
header
)
def
load_segments
(
self
)
->
list
:
def
load_segments
(
self
):
"""
Load the segments [start ip|end ip|region] from source ip text file.
:return: the list of Segment
...
...
@@ -128,41 +128,37 @@ class Maker:
logging
.
info
(
"load segment: `{}`"
.
format
(
line
))
ps
=
line
.
split
(
"|"
,
maxsplit
=
2
)
if
len
(
ps
)
!=
3
:
logging
.
error
(
"invalid ip segment line `{}`"
.
format
(
line
))
return
[]
raise
Exception
(
"invalid ip segment line `{}`"
.
format
(
line
))
sip
=
util
.
check_ip
(
ps
[
0
])
if
sip
==
-
1
:
logging
.
error
(
raise
Exception
(
"invalid ip address `{}` in line `{}`"
.
format
(
ps
[
0
],
line
)
)
return
[]
eip
=
util
.
check_ip
(
ps
[
1
])
if
eip
==
-
1
:
logging
.
error
(
raise
Exception
(
"invalid ip address `{}` in line `{}`"
.
format
(
ps
[
1
],
line
)
)
return
[]
if
sip
>
eip
:
logging
.
error
(
raise
Exception
(
"start ip({}) should not be greater than end ip({})"
.
format
(
ps
[
0
],
ps
[
1
]
)
)
return
[]
if
len
(
ps
[
2
])
<
1
:
logging
.
error
(
"empty region info in segment line `{}`"
.
format
(
line
))
return
[]
raise
Exception
(
"empty region info in segment line `{}`"
.
format
(
line
))
segment
=
seg
.
Segment
(
sip
=
sip
,
eip
=
eip
,
reg
=
ps
[
2
])
# Check the continuity of data segment
if
last
is
not
None
:
if
last
.
end_ip
+
1
!=
segment
.
start_ip
:
logging
.
error
(
raise
Exception
(
"discontinuous data segment: last.eip+1({})!=seg.sip({}, {})"
.
format
(
sip
,
eip
,
ps
[
0
]
)
)
return
[]
self
.
segments
.
append
(
segment
)
last
=
segment
logging
.
info
(
...
...
@@ -189,8 +185,7 @@ class Maker:
Start to make the 'xdb' binary file.
"""
if
len
(
self
.
segments
)
<
1
:
logging
.
error
(
"empty segment list"
)
return
raise
Exception
(
"empty segment list"
)
# 1. Write all the region/data to the binary file
self
.
dst_handle
.
seek
(
Header_Info_Length
+
Vector_Index_Length
,
0
)
...
...
@@ -205,12 +200,11 @@ class Maker:
continue
region
=
bytes
(
s
.
region
,
encoding
=
"utf-8"
)
if
len
(
region
)
>
0xFFFF
:
logging
.
error
(
raise
Exception
(
"too long region info `{}`: should be less than {} bytes"
.
format
(
s
.
region
,
0xFFFF
)
)
return
# Get the first ptr of the next region
pos
=
self
.
dst_handle
.
seek
(
0
,
1
)
logging
.
info
(
"{} {} {}"
.
format
(
pos
,
region
,
s
.
region
))
...
...
@@ -222,12 +216,10 @@ class Maker:
counter
,
start_index_ptr
,
end_index_ptr
=
0
,
-
1
,
-
1
for
sg
in
self
.
segments
:
if
sg
.
region
not
in
self
.
region_pool
:
logging
.
error
(
"missing ptr cache for region `{}`"
.
format
(
sg
.
region
))
return
raise
Exception
(
"missing ptr cache for region `{}`"
.
format
(
sg
.
region
))
data_len
=
len
(
bytes
(
sg
.
region
,
encoding
=
"utf-8"
))
if
data_len
<
1
:
logging
.
error
(
"empty region info for segment '{}'"
.
format
(
sg
.
region
))
return
raise
Exception
(
"empty region info for segment '{}'"
.
format
(
sg
.
region
))
seg_list
=
sg
.
split
()
logging
.
info
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录