Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coolamqp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
coolamqp
Commits
eca8716c
Commit
eca8716c
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
move much of utilies to compile_definitions package
parent
5af8eb98
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compile_definitions/__main__.py
+3
-2
3 additions, 2 deletions
compile_definitions/__main__.py
compile_definitions/utilities.py
+111
-0
111 additions, 0 deletions
compile_definitions/utilities.py
coolamqp/framing/compilation/utilities.py
+0
-115
0 additions, 115 deletions
coolamqp/framing/compilation/utilities.py
with
114 additions
and
117 deletions
compile_definitions/__main__.py
+
3
−
2
View file @
eca8716c
...
...
@@ -8,8 +8,9 @@ from xml.etree import ElementTree
import
math
import
six
from
coolamqp.framing.compilation.utilities
import
name_class
,
format_method_class_name
,
\
format_field_name
,
ffmt
,
to_docstring
,
pythonify_name
,
to_code_binary
,
frepr
,
get_size
from
compile_definitions.utilities
import
ffmt
,
to_docstring
,
pythonify_name
,
to_code_binary
,
frepr
,
\
format_method_class_name
,
name_class
,
get_size
from
coolamqp.framing.compilation.utilities
import
format_field_name
from
.xml_tags
import
Constant
,
Class
,
Domain
TYPE_TRANSLATOR
=
{
...
...
This diff is collapsed.
Click to expand it.
compile_definitions/utilities.py
0 → 100644
+
111
−
0
View file @
eca8716c
# coding=UTF-8
from
__future__
import
division
,
absolute_import
,
print_function
import
math
import
six
from
coolamqp.framing.base
import
BASIC_TYPES
from
coolamqp.framing.compilation.utilities
import
as_unicode
def
ffmt
(
data
,
*
args
,
**
kwargs
):
for
arg
in
args
:
op
=
str
if
kwargs
.
get
(
'
sane
'
,
True
)
else
frepr
data
=
data
.
replace
(
'
%s
'
,
op
(
arg
),
1
)
data
=
data
.
replace
(
'
%S
'
,
'
%s
'
)
return
data
def
to_docstring
(
label
,
doc
,
prefix
=
4
,
blank
=
True
):
# output a full docstring section
label
=
[]
if
label
is
None
else
[
label
]
doc
=
[]
if
doc
is
None
else
[
q
.
strip
()
for
q
in
doc
.
split
(
u
'
\n
'
)
if
len
(
q
.
strip
())
>
0
]
pre
=
u
'
'
*
prefix
doc
=
label
+
doc
if
len
(
doc
)
==
0
:
return
u
''
doc
[
0
]
=
doc
[
0
].
capitalize
()
if
len
(
doc
)
==
1
:
return
doc
[
0
]
doc
=
[
p
for
p
in
doc
if
len
(
p
.
strip
())
>
0
]
if
blank
:
doc
=
[
doc
[
0
],
u
''
]
+
doc
[
1
:]
f
=
(
u
'
\n
'
.
join
(
pre
+
lin
for
lin
in
doc
))[
prefix
:]
return
f
def
pythonify_name
(
p
):
return
p
.
strip
().
replace
(
'
-
'
,
'
_
'
).
upper
()
def
to_code_binary
(
p
):
body
=
[]
for
q
in
p
:
if
isinstance
(
q
,
int
):
q
=
six
.
int2byte
(
q
)
z
=
(
hex
(
ord
(
q
))[
2
:].
upper
())
if
len
(
z
)
==
1
:
z
=
u
'
0
'
+
z
body
.
append
(
u
'
\\
x
'
+
z
)
return
u
"
b
'"
+
(
u
''
.
join
(
body
))
+
u
"'"
def
frepr
(
p
,
sop
=
six
.
text_type
):
if
isinstance
(
p
,
(
six
.
binary_type
,
six
.
text_type
)):
p
=
sop
(
p
)
s
=
repr
(
p
)
if
isinstance
(
p
,
(
six
.
binary_type
,
six
.
text_type
))
and
not
s
.
startswith
(
'
u
'
):
return
(
'
u
'
if
sop
==
six
.
text_type
else
'
b
'
)
+
s
else
:
return
s
@as_unicode
def
format_method_class_name
(
methodname
):
if
'
-
'
in
methodname
:
i
=
methodname
.
find
(
'
-
'
)
return
methodname
[
0
:
i
].
capitalize
()
+
methodname
[
i
+
1
].
upper
()
+
methodname
[
i
+
2
:]
else
:
return
methodname
.
capitalize
()
@as_unicode
def
name_class
(
classname
):
"""
Change AMQP class name to Python class name
"""
return
classname
.
capitalize
()
def
get_size
(
fields
):
# assume all fields have static length
"""
Assuming all fields have static length, return their length together. Supports bits
"""
size
=
0
bits
=
0
for
field
in
fields
:
if
(
bits
>
0
)
and
(
field
.
basic_type
!=
'
bit
'
):
# sync bits
size
+=
int
(
math
.
ceil
(
bits
/
8
))
bits
=
0
if
BASIC_TYPES
[
field
.
basic_type
][
0
]
is
None
:
if
field
.
basic_type
==
'
bit
'
:
bits
+=
1
else
:
size
+=
len
(
BASIC_TYPES
[
field
.
basic_type
][
2
])
# default minimum entry
else
:
size
+=
BASIC_TYPES
[
field
.
basic_type
][
0
]
if
bits
>
0
:
# sync bits
size
+=
int
(
math
.
ceil
(
bits
/
8
))
return
size
This diff is collapsed.
Click to expand it.
coolamqp/framing/compilation/utilities.py
+
0
−
115
View file @
eca8716c
# coding=UTF-8
from
__future__
import
absolute_import
,
division
,
print_function
import
math
import
six
from
coolamqp.framing.base
import
BASIC_TYPES
# docs may be None
def
get_size
(
fields
):
# assume all fields have static length
"""
Assuming all fields have static length, return their length together. Supports bits
"""
size
=
0
bits
=
0
for
field
in
fields
:
if
(
bits
>
0
)
and
(
field
.
basic_type
!=
'
bit
'
):
# sync bits
size
+=
int
(
math
.
ceil
(
bits
/
8
))
bits
=
0
if
BASIC_TYPES
[
field
.
basic_type
][
0
]
is
None
:
if
field
.
basic_type
==
'
bit
'
:
bits
+=
1
else
:
size
+=
len
(
BASIC_TYPES
[
field
.
basic_type
][
2
])
# default minimum entry
else
:
size
+=
BASIC_TYPES
[
field
.
basic_type
][
0
]
if
bits
>
0
:
# sync bits
size
+=
int
(
math
.
ceil
(
bits
/
8
))
return
size
def
as_unicode
(
callable
):
def
roll
(
*
args
,
**
kwargs
):
...
...
@@ -40,27 +13,6 @@ def as_unicode(callable):
return
roll
def
to_dict_by_name
(
list_of_things
):
return
dict
((
a
.
name
,
a
)
for
a
in
list_of_things
)
@as_unicode
def
name_class
(
classname
):
"""
Change AMQP class name to Python class name
"""
return
classname
.
capitalize
()
@as_unicode
def
format_method_class_name
(
methodname
):
if
'
-
'
in
methodname
:
i
=
methodname
.
find
(
'
-
'
)
return
methodname
[
0
:
i
].
capitalize
()
+
methodname
[
i
+
1
].
upper
()
+
methodname
[
i
+
2
:]
else
:
return
methodname
.
capitalize
()
@as_unicode
def
format_field_name
(
field
):
if
field
in
(
u
'
global
'
,
u
'
type
'
):
...
...
@@ -68,70 +20,3 @@ def format_field_name(field):
return
field
.
replace
(
'
-
'
,
'
_
'
)
def
frepr
(
p
,
sop
=
six
.
text_type
):
if
isinstance
(
p
,
(
six
.
binary_type
,
six
.
text_type
)):
p
=
sop
(
p
)
s
=
repr
(
p
)
if
isinstance
(
p
,
(
six
.
binary_type
,
six
.
text_type
))
and
not
s
.
startswith
(
'
u
'
):
return
(
'
u
'
if
sop
==
six
.
text_type
else
'
b
'
)
+
s
else
:
return
s
def
to_code_binary
(
p
):
body
=
[]
for
q
in
p
:
if
isinstance
(
q
,
int
):
q
=
six
.
int2byte
(
q
)
z
=
(
hex
(
ord
(
q
))[
2
:].
upper
())
if
len
(
z
)
==
1
:
z
=
u
'
0
'
+
z
body
.
append
(
u
'
\\
x
'
+
z
)
return
u
"
b
'"
+
(
u
''
.
join
(
body
))
+
u
"'"
def
pythonify_name
(
p
):
return
p
.
strip
().
replace
(
'
-
'
,
'
_
'
).
upper
()
def
try_to_int
(
p
):
try
:
return
int
(
p
)
except
ValueError
:
return
p
def
to_docstring
(
label
,
doc
,
prefix
=
4
,
blank
=
True
):
# output a full docstring section
label
=
[]
if
label
is
None
else
[
label
]
doc
=
[]
if
doc
is
None
else
[
q
.
strip
()
for
q
in
doc
.
split
(
u
'
\n
'
)
if
len
(
q
.
strip
())
>
0
]
pre
=
u
'
'
*
prefix
doc
=
label
+
doc
if
len
(
doc
)
==
0
:
return
u
''
doc
[
0
]
=
doc
[
0
].
capitalize
()
if
len
(
doc
)
==
1
:
return
doc
[
0
]
doc
=
[
p
for
p
in
doc
if
len
(
p
.
strip
())
>
0
]
if
blank
:
doc
=
[
doc
[
0
],
u
''
]
+
doc
[
1
:]
f
=
(
u
'
\n
'
.
join
(
pre
+
lin
for
lin
in
doc
))[
prefix
:]
return
f
def
ffmt
(
data
,
*
args
,
**
kwargs
):
for
arg
in
args
:
op
=
str
if
kwargs
.
get
(
'
sane
'
,
True
)
else
frepr
data
=
data
.
replace
(
'
%s
'
,
op
(
arg
),
1
)
data
=
data
.
replace
(
'
%S
'
,
'
%s
'
)
return
data
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment