Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
wendelin
Commits
66b96bf1
Commit
66b96bf1
authored
Nov 18, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: use io.BytesIO instead of cStringIO
parent
de0b6658
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
19 deletions
+20
-19
bt5/erp5_mqtt/TestTemplateItem/portal_components/test.erp5.testMQTTMessage.py
...mplateItem/portal_components/test.erp5.testMQTTMessage.py
+4
-3
bt5/erp5_wendelin/DocumentTemplateItem/portal_components/document.erp5.IngestionPolicyTool.py
...em/portal_components/document.erp5.IngestionPolicyTool.py
+3
-3
bt5/erp5_wendelin/SkinTemplateItem/portal_skins/erp5_wendelin/Base_numpyToWendelinData.py
...em/portal_skins/erp5_wendelin/Base_numpyToWendelinData.py
+2
-2
bt5/erp5_wendelin/SkinTemplateItem/portal_skins/erp5_wendelin/Base_wendelinDataToNumpy.py
...em/portal_skins/erp5_wendelin/Base_wendelinDataToNumpy.py
+2
-2
bt5/erp5_wendelin/TestTemplateItem/portal_components/test.erp5.testWendelin.py
...tTemplateItem/portal_components/test.erp5.testWendelin.py
+3
-3
bt5/erp5_wendelin_examples_keras/ExtensionTemplateItem/portal_components/extension.erp5.keras_train_model.py
...tem/portal_components/extension.erp5.keras_train_model.py
+4
-4
bt5/erp5_wendelin_examples_keras/ExtensionTemplateItem/portal_components/extension.erp5.keras_vgg16_predict.py
...m/portal_components/extension.erp5.keras_vgg16_predict.py
+2
-2
No files found.
bt5/erp5_mqtt/TestTemplateItem/portal_components/test.erp5.testMQTTMessage.py
View file @
66b96bf1
...
...
@@ -31,8 +31,9 @@ import urllib
import
msgpack
from
httplib
import
NO_CONTENT
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
from
App.version_txt
import
getZopeVersion
from
Products.ERP5Type.Utils
import
str2bytes
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
...
...
@@ -65,7 +66,7 @@ class TestDataIngestion(ERP5TypeTestCase):
body
=
msgpack
.
packb
([
0
,
data_chunk
],
use_bin_type
=
True
)
env
=
{
"CONTENT_TYPE"
:
"application/x-www-form-urlencoded"
}
body
=
urllib
.
urlencode
({
"data_chunk"
:
body
}
)
body
=
str2bytes
(
urllib
.
urlencode
({
"data_chunk"
:
body
})
)
if
not
isinstance
(
ingestion_policy
,
str
):
ingestion_policy
=
ingestion_policy
.
getPath
()
...
...
@@ -77,7 +78,7 @@ class TestDataIngestion(ERP5TypeTestCase):
data_product
=
data_product
.
getReference
()
path
=
ingestion_policy
+
"/ingest?reference="
+
data_supply
+
"."
+
data_product
publish_kw
=
dict
(
user
=
"ERP5TypeTestCase"
,
env
=
env
,
request_method
=
"POST"
,
stdin
=
String
IO
(
body
))
publish_kw
=
dict
(
user
=
"ERP5TypeTestCase"
,
env
=
env
,
request_method
=
"POST"
,
stdin
=
Bytes
IO
(
body
))
response
=
self
.
publish
(
path
,
**
publish_kw
)
return
response
...
...
bt5/erp5_wendelin/DocumentTemplateItem/portal_components/document.erp5.IngestionPolicyTool.py
View file @
66b96bf1
...
...
@@ -23,7 +23,7 @@
##############################################################################
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type.Core.Folder
import
Folder
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
import
msgpack
from
warnings
import
warn
...
...
@@ -55,7 +55,7 @@ class IngestionPolicyTool(Folder):
XXX: use a simple deterministic approach to detect type of data using
https://github.com/fluent/fluentd/blob/master/lib/fluent/plugin/in_forward.rb#L205
"""
data_file
=
String
IO
(
data
)
data_file
=
Bytes
IO
(
data
)
msgpack_list
=
msgpack
.
Unpacker
(
data_file
)
# we need pure primitive list so we avoid zope security in restricted
# script environment, but we loose lazyness
...
...
@@ -73,5 +73,5 @@ class IngestionPolicyTool(Folder):
Lazy unpack data, usable in restructed environment
Setting use_list=False uses tuples instead of lists which is faster
"""
data_file
=
String
IO
(
data
)
data_file
=
Bytes
IO
(
data
)
return
(
x
for
x
in
msgpack
.
Unpacker
(
data_file
,
use_list
=
use_list
))
\ No newline at end of file
bt5/erp5_wendelin/SkinTemplateItem/portal_skins/erp5_wendelin/Base_numpyToWendelinData.py
View file @
66b96bf1
import
binascii
import
numpy
as
np
import
struct
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
MAGIC_HEADER
=
b'
\
x92
WEN
\
x00
\
x01
'
io
=
String
IO
()
io
=
Bytes
IO
()
np
.
save
(
io
,
array
)
io
.
seek
(
0
)
npy_data
=
io
.
read
()
...
...
bt5/erp5_wendelin/SkinTemplateItem/portal_skins/erp5_wendelin/Base_wendelinDataToNumpy.py
View file @
66b96bf1
import
binascii
import
struct
import
numpy
as
np
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
MAGIC_PREFIX
=
b'
\
x92
WEN'
MAGIC_LEN
=
len
(
MAGIC_PREFIX
)
+
2
...
...
@@ -18,7 +18,7 @@ assert major == 0 and minor == 1
# verify crc32 checksum
checksum
=
struct
.
unpack
(
'<i'
,
data
[
MAGIC_LEN
:
HEADER_LEN
])[
0
]
assert
checksum
==
binascii
.
crc32
(
data
[
HEADER_LEN
:])
io
=
String
IO
()
io
=
Bytes
IO
()
io
.
write
(
data
[
HEADER_LEN
:])
io
.
seek
(
0
)
array
=
np
.
load
(
io
,
allow_pickle
=
False
)
...
...
bt5/erp5_wendelin/TestTemplateItem/portal_components/test.erp5.testWendelin.py
View file @
66b96bf1
...
...
@@ -20,7 +20,7 @@
#
##############################################################################
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
import
base64
import
binascii
from
httplib
import
NO_CONTENT
...
...
@@ -105,7 +105,7 @@ class Test(ERP5TypeTestCase):
env
=
{
'CONTENT_TYPE'
:
'application/octet-stream'
}
path
=
ingestion_policy
.
getPath
()
+
'/ingest?reference='
+
reference
publish_kw
=
dict
(
user
=
'ERP5TypeTestCase'
,
env
=
env
,
request_method
=
'POST'
,
stdin
=
String
IO
(
body
))
request_method
=
'POST'
,
stdin
=
Bytes
IO
(
body
))
response
=
self
.
publish
(
path
,
**
publish_kw
)
self
.
assertEqual
(
NO_CONTENT
,
response
.
getStatus
())
# at every ingestion if no specialised Data Ingestion exists it is created
...
...
@@ -391,7 +391,7 @@ class Test(ERP5TypeTestCase):
path
=
ingestion_policy
.
getPath
()
+
'/ingest?reference='
+
reference
publish_kw
=
dict
(
user
=
'ERP5TypeTestCase'
,
env
=
env
,
request_method
=
'POST'
,
stdin
=
String
IO
(
body
))
request_method
=
'POST'
,
stdin
=
Bytes
IO
(
body
))
response
=
self
.
publish
(
path
,
**
publish_kw
)
self
.
assertEqual
(
NO_CONTENT
,
response
.
getStatus
())
...
...
bt5/erp5_wendelin_examples_keras/ExtensionTemplateItem/portal_components/extension.erp5.keras_train_model.py
View file @
66b96bf1
...
...
@@ -149,11 +149,11 @@ class ProgbarLogger(OriginalProgbarLogger):
seed
=
7
np
.
random
.
seed
(
seed
)
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
import
cPickle
def
save
(
portal
,
value
):
data_stream
=
portal
.
data_stream_module
.
wendelin_examples_keras_nn
data_stream
.
edit
(
file
=
String
IO
(
cPickle
.
dumps
(
value
)))
data_stream
.
edit
(
file
=
Bytes
IO
(
cPickle
.
dumps
(
value
)))
def
load
(
portal
):
data_stream
=
portal
.
data_stream_module
.
wendelin_examples_keras_nn
...
...
@@ -168,7 +168,7 @@ def train(portal):
# 1. you can use keras.
# 2. you can save trained model.
# 3. you can load trained model.
# from
cStringIO import String
IO
# from
io import Bytes
IO
import
tensorflow
as
tf
# pylint:disable=import-error
sess
=
tf
.
Session
()
from
keras
import
backend
as
K
# pylint:disable=import-error
...
...
@@ -190,7 +190,7 @@ def train(portal):
model
.
add
(
Dense
(
1
,
init
=
'uniform'
,
activation
=
'sigmoid'
))
model
.
compile
(
loss
=
'binary_crossentropy'
,
optimizer
=
'adam'
,
metrics
=
[
'accuracy'
])
dataset
=
np
.
loadtxt
(
StringIO
(
str
(
portal
.
portal_skins
.
erp5_wendelin_examples_keras
[
'pima.csv'
])),
delimiter
=
','
)
dataset
=
np
.
loadtxt
(
BytesIO
(
bytes
(
portal
.
portal_skins
.
erp5_wendelin_examples_keras
[
'pima.csv'
])),
delimiter
=
','
)
X
=
dataset
[:,
0
:
8
]
Y
=
dataset
[:,
8
]
...
...
bt5/erp5_wendelin_examples_keras/ExtensionTemplateItem/portal_components/extension.erp5.keras_vgg16_predict.py
View file @
66b96bf1
from
keras.applications.vgg16
import
VGG16
,
preprocess_input
,
decode_predictions
# pylint:disable=import-error
from
keras.preprocessing
import
image
# pylint:disable=import-error
import
numpy
as
np
from
cStringIO
import
String
IO
from
io
import
Bytes
IO
import
PIL.Image
model
=
VGG16
(
weights
=
'imagenet'
)
def
predict
(
image_document
):
img
=
PIL
.
Image
.
open
(
StringIO
(
image_document
.
getData
(
)))
img
=
PIL
.
Image
.
open
(
BytesIO
(
bytes
(
image_document
.
getData
()
)))
img
=
img
.
resize
((
224
,
224
))
x
=
image
.
img_to_array
(
img
)
x
=
np
.
expand_dims
(
x
,
axis
=
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment