This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
data = {u'title': u'ほげ'} | |
json_data = json.dumps(data, ensure_ascii=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from unittest import TestCase | |
import unittestclass JSONSerializable(object): | |
"""Serialize to json. """ def to_json(self, exclude=tuple()): | |
""" | |
exclude: List or tuple of attributes that is excluded to serialize. | |
""" | |
data = self.to_serializable_dict(exclude=exclude) | |
return json.dumps(data, ensure_ascii=False) def to_serializable_dict(self, exclude=tuple()): | |
"""Convert to dict that is json serializable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
import mox | |
from unittest import TestCasedef cached_property(f): | |
prefix = '_cached_property_' | |
@wraps(f) | |
def _cached_property(self): | |
key = prefix + f.__name__ | |
if hasattr(self, key): | |
return getattr(self, key) | |
value = f(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
from unittest import TestCase | |
import unittest | |
from mongoengine import connect, Document, EmbeddedDocument, StringField, IntField, \ | |
FloatField, BooleanField, DateTimeField, EmbeddedDocumentField, ListField, \ | |
DictField, ObjectIdField, ReferenceField, MapField, DecimalField, \ | |
ComplexDateTimeField, URLField, GenericReferenceField, FileField, BinaryField, \ | |
SortedListField, EmailField, GeoPointField, ImageField, SequenceField, UUIDField, \ | |
GenericEmbeddedDocumentField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
from unittest import TestCase | |
import unittest | |
from mongoengine import connect, Document, StringField, IntField, FloatField, \ | |
ComplexDateTimeField | |
import datetime | |
class Test(TestCase): | |
def setUp(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
# This code doesn't work correctly. | |
# Reproduced on Python 2.7, Mongodb 1.8.4, pymongo 2.0.1 and mongoengine 0.5 | |
from mongoengine import Document, FileField, connect | |
import pymongo | |
db = 'my_test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
from paste.httpserver import serve | |
from pyramid.configuration import Configurator | |
from pyramid.response import Response | |
from pyramid.events import subscriber, ApplicationCreated, NewRequest | |
from pyramid.session import UnencryptedCookieSessionFactoryConfig | |
from pyramid.exceptions import NotFound | |
from pyramid.httpexceptions import HTTPFound | |
from mongoengine import connect, Document, StringField, \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
from unittest import TestCase | |
class PatchManager(object): | |
def __init__(self): | |
self._storage = {} | |
def attach(self, target, name, patch): | |
key = '%s.%s'%(target.__name__, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(add-hook 'c-mode-common-hook | |
'(lambda() | |
(c-set-style "cc-mode") | |
(setq-default tab-width 4) | |
(setq-default indent-tabs-mode nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def obj-map {(class {}) :map (class []) :vector (class '()) :list (class '(nil)) :list}) | |
(defn collection-type [col] (obj-map (class col))) |
OlderNewer