Commit bf2cd357 authored by qsr's avatar qsr Committed by Commit bot

mojo: Update python API

Update python API to use mixed case identifier for method to conform to
the chromium python style guide.

R=pkl@chromium.org

Review URL: https://codereview.chromium.org/522483006

Cr-Commit-Position: refs/heads/master@{#292961}
parent 08735d6a
...@@ -15,7 +15,7 @@ from cpython.buffer cimport PyObject_GetBuffer ...@@ -15,7 +15,7 @@ from cpython.buffer cimport PyObject_GetBuffer
from cpython.mem cimport PyMem_Malloc, PyMem_Free from cpython.mem cimport PyMem_Malloc, PyMem_Free
from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t
def set_system_thunks(system_thunks_as_object): def SetSystemThunks(system_thunks_as_object):
"""Bind the basic Mojo Core functions. """Bind the basic Mojo Core functions.
This should only be used by the embedder. This should only be used by the embedder.
...@@ -58,7 +58,7 @@ READ_DATA_FLAG_DISCARD = c_core.MOJO_READ_DATA_FLAG_DISCARD ...@@ -58,7 +58,7 @@ READ_DATA_FLAG_DISCARD = c_core.MOJO_READ_DATA_FLAG_DISCARD
READ_DATA_FLAG_QUERY = c_core.MOJO_READ_DATA_FLAG_QUERY READ_DATA_FLAG_QUERY = c_core.MOJO_READ_DATA_FLAG_QUERY
MAP_BUFFER_FLAG_NONE = c_core.MOJO_MAP_BUFFER_FLAG_NONE MAP_BUFFER_FLAG_NONE = c_core.MOJO_MAP_BUFFER_FLAG_NONE
def get_time_ticks_now(): def GetTimeTicksNow():
"""Monotonically increasing tick count representing "right now." """Monotonically increasing tick count representing "right now."
See mojo/public/c/system/functions.h See mojo/public/c/system/functions.h
...@@ -95,7 +95,7 @@ cdef class _ScopedBuffer: ...@@ -95,7 +95,7 @@ cdef class _ScopedBuffer:
if self.buf: if self.buf:
PyBuffer_Release(&self._buf) PyBuffer_Release(&self._buf)
def _slice_buffer(buffer, size): def _SliceBuffer(buffer, size):
"""Slice the given buffer, reducing it to the given size. """Slice the given buffer, reducing it to the given size.
Return None if None is passed in. Return None if None is passed in.
...@@ -124,7 +124,7 @@ cdef class _NativeMemoryView(object): ...@@ -124,7 +124,7 @@ cdef class _NativeMemoryView(object):
self._read_only = True self._read_only = True
self._wrapped = False self._wrapped = False
cdef wrap(self, cdef Wrap(self,
const void* memory, const void* memory,
uint32_t size, uint32_t size,
read_only=True): read_only=True):
...@@ -183,7 +183,7 @@ class MojoException(Exception): ...@@ -183,7 +183,7 @@ class MojoException(Exception):
def __init__(self, mojo_result): def __init__(self, mojo_result):
self.mojo_result = mojo_result self.mojo_result = mojo_result
def wait_many(handles_and_signals, deadline): def WaitMany(handles_and_signals, deadline):
"""Waits on a list of handles. """Waits on a list of handles.
Args: Args:
...@@ -227,7 +227,7 @@ cdef class DataPipeTwoPhaseBuffer(object): ...@@ -227,7 +227,7 @@ cdef class DataPipeTwoPhaseBuffer(object):
self._handle = handle self._handle = handle
self._read = read self._read = read
def end(self, num_bytes): def End(self, num_bytes):
self._buffer = None self._buffer = None
cdef c_core.MojoResult result cdef c_core.MojoResult result
if self._read: if self._read:
...@@ -260,7 +260,7 @@ cdef class MappedBuffer(object): ...@@ -260,7 +260,7 @@ cdef class MappedBuffer(object):
self._handle = handle self._handle = handle
self._cleanup = cleanup self._cleanup = cleanup
def unmap(self): def UnMap(self):
self._buffer = None self._buffer = None
cdef c_core.MojoResult result = self._cleanup() cdef c_core.MojoResult result = self._cleanup()
self._cleanup = None self._cleanup = None
...@@ -273,7 +273,7 @@ cdef class MappedBuffer(object): ...@@ -273,7 +273,7 @@ cdef class MappedBuffer(object):
def __dealloc__(self): def __dealloc__(self):
if self._buffer: if self._buffer:
self.unmap() self.UnMap()
cdef class Handle(object): cdef class Handle(object):
"""A mojo object.""" """A mojo object."""
...@@ -283,7 +283,7 @@ cdef class Handle(object): ...@@ -283,7 +283,7 @@ cdef class Handle(object):
def __init__(self, mojo_handle=c_core.MOJO_HANDLE_INVALID): def __init__(self, mojo_handle=c_core.MOJO_HANDLE_INVALID):
self._mojo_handle = mojo_handle self._mojo_handle = mojo_handle
def _invalidate(self): def _Invalidate(self):
"""Invalidate the current handle. """Invalidate the current handle.
The close operation is not called. It is the responsability of the caller to The close operation is not called. It is the responsability of the caller to
...@@ -291,25 +291,25 @@ cdef class Handle(object): ...@@ -291,25 +291,25 @@ cdef class Handle(object):
""" """
self._mojo_handle = c_core.MOJO_HANDLE_INVALID self._mojo_handle = c_core.MOJO_HANDLE_INVALID
def is_valid(self): def IsValid(self):
"""Returns whether this handle is valid.""" """Returns whether this handle is valid."""
return self._mojo_handle != c_core.MOJO_HANDLE_INVALID return self._mojo_handle != c_core.MOJO_HANDLE_INVALID
def close(self): def Close(self):
"""Closes this handle. """Closes this handle.
See mojo/public/c/system/functions.h See mojo/public/c/system/functions.h
""" """
cdef c_core.MojoResult result = c_core.MOJO_RESULT_OK cdef c_core.MojoResult result = c_core.MOJO_RESULT_OK
if self.is_valid(): if self.IsValid():
result = c_core.MojoClose(self._mojo_handle) result = c_core.MojoClose(self._mojo_handle)
self._invalidate() self._Invalidate()
return result return result
def __dealloc__(self): def __dealloc__(self):
self.close() self.Close()
def wait(self, signals, deadline): def Wait(self, signals, deadline):
"""Waits on the given handle. """Waits on the given handle.
See mojo/public/c/system/functions.h See mojo/public/c/system/functions.h
...@@ -322,7 +322,7 @@ cdef class Handle(object): ...@@ -322,7 +322,7 @@ cdef class Handle(object):
result = c_core.MojoWait(handle, csignals, cdeadline) result = c_core.MojoWait(handle, csignals, cdeadline)
return result return result
def write_message(self, def WriteMessage(self,
buffer=None, buffer=None,
handles=None, handles=None,
flags=WRITE_MESSAGE_FLAG_NONE): flags=WRITE_MESSAGE_FLAG_NONE):
...@@ -353,10 +353,10 @@ cdef class Handle(object): ...@@ -353,10 +353,10 @@ cdef class Handle(object):
if res == c_core.MOJO_RESULT_OK and handles: if res == c_core.MOJO_RESULT_OK and handles:
# Handles have been transferred. Let's invalidate those. # Handles have been transferred. Let's invalidate those.
for handle in handles: for handle in handles:
handle._invalidate() handle._Invalidate()
return res return res
def read_message(self, def ReadMessage(self,
buffer=None, buffer=None,
max_number_of_handles=0, max_number_of_handles=0,
flags=READ_MESSAGE_FLAG_NONE): flags=READ_MESSAGE_FLAG_NONE):
...@@ -398,11 +398,11 @@ cdef class Handle(object): ...@@ -398,11 +398,11 @@ cdef class Handle(object):
returned_handles = [Handle(input_handles[i]) returned_handles = [Handle(input_handles[i])
for i in xrange(input_handles_length)] for i in xrange(input_handles_length)]
return (res, return (res,
(_slice_buffer(buffer, input_buffer_length), returned_handles), (_SliceBuffer(buffer, input_buffer_length), returned_handles),
None) None)
return (res, None, None) return (res, None, None)
def write_data(self, buffer=None, flags=WRITE_DATA_FLAG_NONE): def WriteData(self, buffer=None, flags=WRITE_DATA_FLAG_NONE):
""" """
Writes the given data to the data pipe producer. Writes the given data to the data pipe producer.
...@@ -425,7 +425,7 @@ cdef class Handle(object): ...@@ -425,7 +425,7 @@ cdef class Handle(object):
return (res, input_buffer_length) return (res, input_buffer_length)
return (res, None) return (res, None)
def begin_write_data(self, def BeginWriteData(self,
min_size=None, min_size=None,
flags=WRITE_DATA_FLAG_NONE): flags=WRITE_DATA_FLAG_NONE):
""" """
...@@ -453,10 +453,10 @@ cdef class Handle(object): ...@@ -453,10 +453,10 @@ cdef class Handle(object):
if res != c_core.MOJO_RESULT_OK: if res != c_core.MOJO_RESULT_OK:
return (res, None) return (res, None)
cdef _NativeMemoryView view_buffer = _NativeMemoryView(self) cdef _NativeMemoryView view_buffer = _NativeMemoryView(self)
view_buffer.wrap(out_buffer, out_size, read_only=False) view_buffer.Wrap(out_buffer, out_size, read_only=False)
return (res, DataPipeTwoPhaseBuffer(self, memoryview(view_buffer), False)) return (res, DataPipeTwoPhaseBuffer(self, memoryview(view_buffer), False))
def read_data(self, buffer=None, flags=READ_DATA_FLAG_NONE): def ReadData(self, buffer=None, flags=READ_DATA_FLAG_NONE):
"""Reads data from the data pipe consumer. """Reads data from the data pipe consumer.
This method can only be used on a consumer handle obtained from This method can only be used on a consumer handle obtained from
...@@ -476,10 +476,10 @@ cdef class Handle(object): ...@@ -476,10 +476,10 @@ cdef class Handle(object):
&input_buffer_length, &input_buffer_length,
flags) flags)
if res == c_core.MOJO_RESULT_OK: if res == c_core.MOJO_RESULT_OK:
return (res, _slice_buffer(buffer, input_buffer_length)) return (res, _SliceBuffer(buffer, input_buffer_length))
return (res, None) return (res, None)
def query_data(self, flags=READ_DATA_FLAG_NONE): def QueryData(self, flags=READ_DATA_FLAG_NONE):
"""Queries the amount of data available on the data pipe consumer. """Queries the amount of data available on the data pipe consumer.
This method can only be used on a consumer handle obtained from This method can only be used on a consumer handle obtained from
...@@ -500,7 +500,7 @@ cdef class Handle(object): ...@@ -500,7 +500,7 @@ cdef class Handle(object):
flags|c_core.MOJO_READ_DATA_FLAG_QUERY) flags|c_core.MOJO_READ_DATA_FLAG_QUERY)
return (res, num_bytes) return (res, num_bytes)
def begin_read_data(self, min_size=None, flags=READ_DATA_FLAG_NONE): def BeginReadData(self, min_size=None, flags=READ_DATA_FLAG_NONE):
""" """
Begins a two-phase read to the data pipe consumer. Begins a two-phase read to the data pipe consumer.
...@@ -526,14 +526,14 @@ cdef class Handle(object): ...@@ -526,14 +526,14 @@ cdef class Handle(object):
if res != c_core.MOJO_RESULT_OK: if res != c_core.MOJO_RESULT_OK:
return (res, None) return (res, None)
cdef _NativeMemoryView view_buffer = _NativeMemoryView(self) cdef _NativeMemoryView view_buffer = _NativeMemoryView(self)
view_buffer.wrap(out_buffer, out_size, read_only=True) view_buffer.Wrap(out_buffer, out_size, read_only=True)
return (res, DataPipeTwoPhaseBuffer(self, memoryview(view_buffer), True)) return (res, DataPipeTwoPhaseBuffer(self, memoryview(view_buffer), True))
def duplicate(self, options=None): def Duplicate(self, options=None):
"""Duplicate the shared buffer handle. """Duplicate the shared buffer handle.
This method can only be used on a handle obtained from This method can only be used on a handle obtained from
|create_shared_buffer()| or |duplicate()|. |CreateSharedBuffer()| or |Duplicate()|.
See mojo/public/c/system/buffer.h See mojo/public/c/system/buffer.h
""" """
...@@ -551,11 +551,11 @@ cdef class Handle(object): ...@@ -551,11 +551,11 @@ cdef class Handle(object):
raise MojoException(result) raise MojoException(result)
return new_handle return new_handle
def map(self, offset, num_bytes, flags=MAP_BUFFER_FLAG_NONE): def Map(self, offset, num_bytes, flags=MAP_BUFFER_FLAG_NONE):
"""Maps the part (at offset |offset| of length |num_bytes|) of the buffer. """Maps the part (at offset |offset| of length |num_bytes|) of the buffer.
This method can only be used on a handle obtained from This method can only be used on a handle obtained from
|create_shared_buffer()| or |duplicate()|. |CreateSharedBuffer()| or |Duplicate()|.
This method returns a tuple (code, mapped_buffer). This method returns a tuple (code, mapped_buffer).
- If code is RESULT_OK, mapped_buffer is a readable/writable - If code is RESULT_OK, mapped_buffer is a readable/writable
...@@ -573,7 +573,7 @@ cdef class Handle(object): ...@@ -573,7 +573,7 @@ cdef class Handle(object):
if res != c_core.MOJO_RESULT_OK: if res != c_core.MOJO_RESULT_OK:
return (res, None) return (res, None)
cdef _NativeMemoryView view_buffer = _NativeMemoryView(self) cdef _NativeMemoryView view_buffer = _NativeMemoryView(self)
view_buffer.wrap(buffer, num_bytes, read_only=False) view_buffer.Wrap(buffer, num_bytes, read_only=False)
return (res, MappedBuffer(self, return (res, MappedBuffer(self,
memoryview(view_buffer), memoryview(view_buffer),
lambda: c_core.MojoUnmapBuffer(buffer))) lambda: c_core.MojoUnmapBuffer(buffer)))
...@@ -665,7 +665,7 @@ class CreateSharedBufferOptions(object): ...@@ -665,7 +665,7 @@ class CreateSharedBufferOptions(object):
def __init__(self): def __init__(self):
self.flags = CreateSharedBufferOptions.FLAG_NONE self.flags = CreateSharedBufferOptions.FLAG_NONE
def create_shared_buffer(num_bytes, options=None): def CreateSharedBuffer(num_bytes, options=None):
"""Creates a buffer of size |num_bytes| bytes that can be shared. """Creates a buffer of size |num_bytes| bytes that can be shared.
See mojo/public/c/system/buffer.h See mojo/public/c/system/buffer.h
......
...@@ -34,8 +34,8 @@ cdef extern from "mojo/public/platform/native/system_thunks.h" nogil: ...@@ -34,8 +34,8 @@ cdef extern from "mojo/public/platform/native/system_thunks.h" nogil:
pass pass
cdef MojoSystemThunks MojoMakeSystemThunks() cdef MojoSystemThunks MojoMakeSystemThunks()
def init(): def Init():
InitCEmbedder(scoped_ptr[PlatformSupport]( InitCEmbedder(scoped_ptr[PlatformSupport](
new SimplePlatformSupport())) new SimplePlatformSupport()))
cdef MojoSystemThunks thunks = MojoMakeSystemThunks() cdef MojoSystemThunks thunks = MojoMakeSystemThunks()
system.set_system_thunks(<uintptr_t>(&thunks)) system.SetSystemThunks(<uintptr_t>(&thunks))
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment