コード例 #1
0
ファイル: api.py プロジェクト: mgwilliams/jsongit
def init(path=None, repo=None, **kwargs):
    """Obtain a :class:`Repository`.  Either a path to a repo or an
    existing `pygit2.Repository` must be provided.  If the path exists, it will
    be interpreted as the path to an existing repository; if it does not, a new
    bare repository will be created there.

    >>> repo = jsongit.init('path/to/repo')

    Or, if you want to take advantage of special `pygit2` options:

    >>> import pygit2
    >>> pygit_repo = pygit2.init_repository('path/to/repo', False)
    >>> jsongit_repo = jsongit.init(repo=pygit_repo)

    :param path:
        The path to a repository. If it is a path that does not exist, a new
        bare git repository will be initialized there.  If it is a path that
        does exist, then the directory will be used as a repository.
    :type path: string
    :param repo: An existing repository object.
    :type repo: :class:`pygit2.Repository`
    :param dumps:
        (optional) An alternate function to use when dumping data.  Defaults
        to :func:`json.dumps`.
    :type dumps: func
    :param loads:
        (optional) An alternate function to use when loading data.  Defaults
        to :func:`json.loads`.
    :type loads: func

    :returns: A repository reference
    :rtype: :class:`Repository <jsongit.models.Repository>`
    """
    if repo and path:
        raise TypeError("Cannot define repo and path")
    if path:
        if os.path.isdir(path):
            repo = pygit2.Repository(path)
        else:
            bare = kwargs.pop('bare', True) # bare repo by default
            repo = pygit2.init_repository(path, bare)
    if not repo:
        raise TypeError("Missing repo or path")
    dumps = kwargs.pop('dumps', utils.import_json().dumps)
    loads = kwargs.pop('loads', utils.import_json().loads)
    return Repository(repo, dumps, loads)
コード例 #2
0
ファイル: api.py プロジェクト: mgwilliams/jsongit
def init(path=None, repo=None, **kwargs):
    """Obtain a :class:`Repository`.  Either a path to a repo or an
    existing `pygit2.Repository` must be provided.  If the path exists, it will
    be interpreted as the path to an existing repository; if it does not, a new
    bare repository will be created there.

    >>> repo = jsongit.init('path/to/repo')

    Or, if you want to take advantage of special `pygit2` options:

    >>> import pygit2
    >>> pygit_repo = pygit2.init_repository('path/to/repo', False)
    >>> jsongit_repo = jsongit.init(repo=pygit_repo)

    :param path:
        The path to a repository. If it is a path that does not exist, a new
        bare git repository will be initialized there.  If it is a path that
        does exist, then the directory will be used as a repository.
    :type path: string
    :param repo: An existing repository object.
    :type repo: :class:`pygit2.Repository`
    :param dumps:
        (optional) An alternate function to use when dumping data.  Defaults
        to :func:`json.dumps`.
    :type dumps: func
    :param loads:
        (optional) An alternate function to use when loading data.  Defaults
        to :func:`json.loads`.
    :type loads: func

    :returns: A repository reference
    :rtype: :class:`Repository <jsongit.models.Repository>`
    """
    if repo and path:
        raise TypeError("Cannot define repo and path")
    if path:
        if os.path.isdir(path):
            repo = pygit2.Repository(path)
        else:
            bare = kwargs.pop('bare', True)  # bare repo by default
            repo = pygit2.init_repository(path, bare)
    if not repo:
        raise TypeError("Missing repo or path")
    dumps = kwargs.pop('dumps', utils.import_json().dumps)
    loads = kwargs.pop('loads', utils.import_json().loads)
    return Repository(repo, dumps, loads)
コード例 #3
0
ファイル: service.py プロジェクト: MiCHiLU/pyahooapis-ndb
#coding: utf-8

import os
import re
import urllib
import urllib2
from xml.dom import minidom

import utils

json = utils.import_json()


newline_sub = re.compile('\n').sub
property_match = re.compile('[a-zA-Z].*').match

class Service(object):
    url = 'http://yahoo.co.jp'
    
    def __init__(self, appid, encoding=None):
        self.appid = appid
        if os.environ.has_key('PYAHOOAPIS_ENCODING'):
            if encoding is not None:
                os.environ['PYAHOOAPIS_ENCODING'] = encoding
        else:
            os.environ['PYAHOOAPIS_ENCODING'] = encoding or 'utf8'

    def _encode_to_utf8(self, text):
        if not isinstance(text, unicode):
            text = unicode(text, os.environ.get('PYAHOOAPIS_ENCODING', 'utf8'))
        return text.encode('utf8')