示例#1
0
def compile_validation(target):
    if not isinstance(target, dict):
        logging.error("validation.json invalid, target is {}".format(target))
        raise ValueError("Invalid target type")
    for k, v in target.iteritems():
        if type(v) in [str, unicode]:
            target[k] = re.compile(v)
        else:
            target[k] = compile_validation(v)
    return target


_validation = None
try:
    with open("validation.json") as f:
        _validation = compile_validation(json.load(f))
except ValueError:
    logging.error("validation.json is not a valid json document.")
except IOError:
    logging.info(
        "validation.json doesn't exist no model validation will be performed.")

EXPORTED_JAVASCRIPT = compile_js(
    ["tailbone/restful/models.js"],
    ["Model", "User", "FILTER", "ORDER", "AND", "OR"])

app = webapp2.WSGIApplication([
    (r"{}([^/]+)/?(.*)".format(PREFIX), RestfulHandler),
],
                              debug=DEBUG)
示例#2
0
    def delete(self, name):
        if not config.is_current_user_admin():
            raise AppError("Unauthorized.")
        if not name:
            raise AppError("Must provide name.")


EXPORTED_JAVASCRIPT = compile_js(
    [
        # "tailbone/mesh/js/msgpack.js",
        "tailbone/mesh/js/EventDispatcher.js",
        "tailbone/mesh/js/StateDrive.js",
        "tailbone/mesh/js/Channel.js",
        "tailbone/mesh/js/ChannelChannel.js",
        "tailbone/mesh/js/ChannelMultiplexer.js",
        "tailbone/mesh/js/SocketChannel.js",
        "tailbone/mesh/js/SocketMultiplexer.js",
        "tailbone/mesh/js/NetChannel.js",
        "tailbone/mesh/js/RTCChannel.js",
        "tailbone/mesh/js/Node.js",
        "tailbone/mesh/js/Peers.js",
        "tailbone/mesh/js/Mesh.js",
    ],
    ["Mesh"])

app = webapp2.WSGIApplication([
    (r"{}mesh/?(.*)".format(PREFIX), MeshHandler),
],
                              debug=DEBUG)

# Gibberish generator modified from: https://github.com/greghaskins/gibberish
示例#3
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tailbone import DEBUG, PREFIX, compile_js, as_json, BaseHandler

import time
import webapp2


class ClockSyncHandler(BaseHandler):
  def head(self):
    self.response.headers['Last-Modified'] = "{:f}".format(time.time()*1000)

  @as_json
  def get(self):
    return time.time()*1000

EXPORTED_JAVASCRIPT = compile_js([
  "tailbone/clocksync/clocksync.js",
], ["clocksync"])

app = webapp2.WSGIApplication([
  (r"{}clocksync/?.*".format(PREFIX), ClockSyncHandler),
], debug=DEBUG)
  @as_json
  def delete(self, name):
    if not config.is_current_user_admin():
      raise AppError("Unauthorized.")
    if not name:
      raise AppError("Must provide name.")

EXPORTED_JAVASCRIPT = compile_js([
  # "tailbone/mesh/js/msgpack.js",
  "tailbone/mesh/js/EventDispatcher.js",
  "tailbone/mesh/js/StateDrive.js",
  "tailbone/mesh/js/Channel.js",
  "tailbone/mesh/js/ChannelChannel.js",
  "tailbone/mesh/js/ChannelMultiplexer.js",
  "tailbone/mesh/js/SocketChannel.js",
  "tailbone/mesh/js/SocketMultiplexer.js",
  "tailbone/mesh/js/NetChannel.js",
  "tailbone/mesh/js/RTCChannel.js",
  "tailbone/mesh/js/Node.js",
  "tailbone/mesh/js/Peers.js",
  "tailbone/mesh/js/Mesh.js",
], ["Mesh"])

app = webapp2.WSGIApplication([
  (r"{}mesh/?(.*)".format(PREFIX), MeshHandler),
], debug=DEBUG)


# Gibberish generator modified from: https://github.com/greghaskins/gibberish
VOWELS = "aeiou"
# Load an optional validation.json
# --------------------------------
def compile_validation(target):
  if not isinstance(target, dict):
    logging.error("validation.json invalid, target is {}".format(target))
    raise ValueError("Invalid target type")
  for k, v in target.iteritems():
    if type(v) in [str, unicode]:
      target[k] = re.compile(v)
    else:
      target[k] = compile_validation(v)
  return target

_validation = None
try:
  with open("validation.json") as f:
    _validation = compile_validation(json.load(f))
except ValueError:
  logging.error("validation.json is not a valid json document.")
except IOError:
  logging.info("validation.json doesn't exist no model validation will be performed.")


EXPORTED_JAVASCRIPT = compile_js([
  "tailbone/restful/models.js"
], ["Model", "User", "FILTER", "ORDER", "AND", "OR"])

app = webapp2.WSGIApplication([
  (r"{}([^/]+)/?(.*)".format(PREFIX), RestfulHandler),
], debug=DEBUG)